From bff5c84bb58c1e2da01bb4d02e2e65040c839ff5 Mon Sep 17 00:00:00 2001 From: loucass003 Date: Mon, 3 Feb 2025 00:25:48 +0100 Subject: [PATCH 1/4] Change reset sounds so you have clues at the begining and end of the reset action --- gui/src/components/home/ResetButton.tsx | 19 ++++-- gui/src/hooks/app.ts | 8 ++- gui/src/sounds/sounds.ts | 77 +++++++++++++++++++++++++ 3 files changed, 97 insertions(+), 7 deletions(-) create mode 100644 gui/src/sounds/sounds.ts diff --git a/gui/src/components/home/ResetButton.tsx b/gui/src/components/home/ResetButton.tsx index 65c60ed4e7..237ba6e331 100644 --- a/gui/src/components/home/ResetButton.tsx +++ b/gui/src/components/home/ResetButton.tsx @@ -9,7 +9,10 @@ import { import { useConfig } from '@/hooks/config'; import { useCountdown } from '@/hooks/countdown'; import { useWebsocketAPI } from '@/hooks/websocket-api'; -import { playSoundOnResetStarted } from '@/sounds/sounds'; +import { + playSoundOnResetEnded, + playSoundOnResetStarted, +} from '@/sounds/sounds'; import { BigButton } from '@/components/commons/BigButton'; import { Button } from '@/components/commons/Button'; import { @@ -51,6 +54,7 @@ export function ResetButton({ const { isCounting, startCountdown, timer } = useCountdown({ duration: type === ResetType.Yaw ? 0.2 : undefined, onCountdownEnd: () => { + maybePlaySoundOnResetEnd(type); reset(); if (onReseted) onReseted(); }, @@ -77,9 +81,14 @@ export function ResetButton({ return ; }; - const maybePlaySoundOnResetStarted = (type: ResetType) => { + const maybePlaySoundOnResetEnd = (type: ResetType) => { + if (!config?.feedbackSound) return; + playSoundOnResetEnded(type, config?.feedbackSoundVolume); + }; + + const maybePlaySoundOnResetStart = () => { if (!config?.feedbackSound) return; - playSoundOnResetStarted(type, config?.feedbackSoundVolume); + playSoundOnResetStarted(config?.feedbackSoundVolume); }; return variant === 'small' ? ( @@ -87,7 +96,7 @@ export function ResetButton({ icon={getIcon()} onClick={() => { startCountdown(); - maybePlaySoundOnResetStarted(type); + maybePlaySoundOnResetStart(); }} variant="primary" disabled={isCounting || needsFullReset} @@ -103,7 +112,7 @@ export function ResetButton({ icon={getIcon()} onClick={() => { startCountdown(); - maybePlaySoundOnResetStarted(type); + maybePlaySoundOnResetStart(); }} disabled={isCounting || needsFullReset} > diff --git a/gui/src/hooks/app.ts b/gui/src/hooks/app.ts index 5421641d7d..ac6bd7de8a 100644 --- a/gui/src/hooks/app.ts +++ b/gui/src/hooks/app.ts @@ -19,7 +19,7 @@ import { StartDataFeedT, TrackerDataT, } from 'solarxr-protocol'; -import { playSoundOnResetStarted } from '@/sounds/sounds'; +import { playSoundOnResetEnded, playSoundOnResetStarted } from '@/sounds/sounds'; import { useConfig } from './config'; import { useDataFeedConfig } from './datafeed-config'; import { useWebsocketAPI } from './websocket-api'; @@ -118,7 +118,11 @@ export function useProvideAppContext(): AppContext { try { switch (status) { case ResetStatus.STARTED: { - playSoundOnResetStarted(resetType, config?.feedbackSoundVolume); + playSoundOnResetStarted(config?.feedbackSoundVolume); + break; + } + case ResetStatus.FINISHED: { + playSoundOnResetEnded(resetType, config?.feedbackSoundVolume); break; } } diff --git a/gui/src/sounds/sounds.ts b/gui/src/sounds/sounds.ts new file mode 100644 index 0000000000..49fb30b8b1 --- /dev/null +++ b/gui/src/sounds/sounds.ts @@ -0,0 +1,77 @@ +import { fetchResourceUrl } from '@/utils/tauri'; +import { ResetType } from 'solarxr-protocol'; + +const quickResetStartedSound = new Audio( + await fetchResourceUrl('/sounds/quick-reset-started-sound.mp3') +); +const fullResetStartedSound = new Audio( + await fetchResourceUrl('/sounds/full-reset-started-sound.mp3') +); +const mountingResetStartedSound = new Audio( + await fetchResourceUrl('/sounds/mounting-reset-started-sound.mp3') +); +const tapSetupSound1 = new Audio(await fetchResourceUrl('/sounds/first-tap.mp3')); +const tapSetupSound2 = new Audio(await fetchResourceUrl('/sounds/second-tap.mp3')); +const tapSetupSound3 = new Audio(await fetchResourceUrl('/sounds/third-tap.mp3')); +const tapSetupSound4 = new Audio(await fetchResourceUrl('/sounds/fourth-tap.mp3')); +const tapSetupSound5 = new Audio(await fetchResourceUrl('/sounds/fifth-tap.mp3')); +const tapSetupSoundEnd = new Audio(await fetchResourceUrl('/sounds/end-tap.mp3')); +const tapSetupExtraSound = new Audio( + await fetchResourceUrl('/sounds/tapextrasetup.mp3') +); + +function restartAndPlay(audio: HTMLAudioElement, volume: number) { + audio.volume = Math.min(1, Math.pow(volume, Math.E) + 0.05); + if (audio.paused) { + audio.play(); + } else { + audio.currentTime = 0; + } +} + +export function playSoundOnResetEnded(resetType: ResetType, volume = 1) { + switch (resetType) { + case ResetType.Yaw: { + restartAndPlay(quickResetStartedSound, volume); + break; + } + case ResetType.Full: { + restartAndPlay(fullResetStartedSound, volume); + break; + } + case ResetType.Mounting: { + restartAndPlay(mountingResetStartedSound, volume); + break; + } + } +} + +export function playSoundOnResetStarted(volume = 1) { + restartAndPlay(tapSetupSound1, volume); +} + +let lastKnownVolume = 1; +/* Easter egg */ +tapSetupSoundEnd.onended = () => { + if (Math.floor(Math.random() * 12000) !== 0) return; + restartAndPlay(tapSetupExtraSound, lastKnownVolume); +}; + +const order = [ + tapSetupSound1, + tapSetupSound2, + tapSetupSound3, + tapSetupSound4, + tapSetupSound5, + tapSetupSoundEnd, + tapSetupSoundEnd, + tapSetupSoundEnd, +]; +let lastTap = 0; +export function playTapSetupSound(volume = 1) { + lastKnownVolume = volume; + restartAndPlay(order[lastTap++], volume); + if (lastTap >= order.length) { + lastTap = 0; + } +} From a592ebe9a7f11f04d040e43606199a97064df2f5 Mon Sep 17 00:00:00 2001 From: loucass003 Date: Mon, 3 Feb 2025 00:49:48 +0100 Subject: [PATCH 2/4] Woops forgot to remove the old one --- gui/src/sounds/sounds.tsx | 85 --------------------------------------- 1 file changed, 85 deletions(-) delete mode 100644 gui/src/sounds/sounds.tsx diff --git a/gui/src/sounds/sounds.tsx b/gui/src/sounds/sounds.tsx deleted file mode 100644 index fbc6da1816..0000000000 --- a/gui/src/sounds/sounds.tsx +++ /dev/null @@ -1,85 +0,0 @@ -import { fetchResourceUrl } from '@/utils/tauri'; -import { ResetType } from 'solarxr-protocol'; - -const quickResetStartedSound = new Audio( - await fetchResourceUrl('/sounds/quick-reset-started-sound.mp3') -); -const fullResetStartedSound = new Audio( - await fetchResourceUrl('/sounds/full-reset-started-sound.mp3') -); -const mountingResetStartedSound = new Audio( - await fetchResourceUrl('/sounds/mounting-reset-started-sound.mp3') -); -const tapSetupSound1 = new Audio( - await fetchResourceUrl('/sounds/first-tap.mp3') -); -const tapSetupSound2 = new Audio( - await fetchResourceUrl('/sounds/second-tap.mp3') -); -const tapSetupSound3 = new Audio( - await fetchResourceUrl('/sounds/third-tap.mp3') -); -const tapSetupSound4 = new Audio( - await fetchResourceUrl('/sounds/fourth-tap.mp3') -); -const tapSetupSound5 = new Audio( - await fetchResourceUrl('/sounds/fifth-tap.mp3') -); -const tapSetupSoundEnd = new Audio( - await fetchResourceUrl('/sounds/end-tap.mp3') -); -const tapSetupExtraSound = new Audio( - await fetchResourceUrl('/sounds/tapextrasetup.mp3') -); - -function restartAndPlay(audio: HTMLAudioElement, volume: number) { - audio.volume = Math.min(1, Math.pow(volume, Math.E) + 0.05); - if (audio.paused) { - audio.play(); - } else { - audio.currentTime = 0; - } -} - -export function playSoundOnResetStarted(resetType: ResetType, volume = 1) { - switch (resetType) { - case ResetType.Yaw: { - restartAndPlay(quickResetStartedSound, volume); - break; - } - case ResetType.Full: { - restartAndPlay(fullResetStartedSound, volume); - break; - } - case ResetType.Mounting: { - restartAndPlay(mountingResetStartedSound, volume); - break; - } - } -} - -let lastKnownVolume = 1; -/* Easter egg */ -tapSetupSoundEnd.onended = () => { - if (Math.floor(Math.random() * 12000) !== 0) return; - restartAndPlay(tapSetupExtraSound, lastKnownVolume); -}; - -const order = [ - tapSetupSound1, - tapSetupSound2, - tapSetupSound3, - tapSetupSound4, - tapSetupSound5, - tapSetupSoundEnd, - tapSetupSoundEnd, - tapSetupSoundEnd, -]; -let lastTap = 0; -export function playTapSetupSound(volume = 1) { - lastKnownVolume = volume; - restartAndPlay(order[lastTap++], volume); - if (lastTap >= order.length) { - lastTap = 0; - } -} From e65eac8d2c56000abea1180a0784c878d4c036f2 Mon Sep 17 00:00:00 2001 From: loucass003 Date: Mon, 3 Feb 2025 13:07:09 +0100 Subject: [PATCH 3/4] Use only beeps --- gui/src/sounds/sounds.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/gui/src/sounds/sounds.ts b/gui/src/sounds/sounds.ts index 49fb30b8b1..decb46b319 100644 --- a/gui/src/sounds/sounds.ts +++ b/gui/src/sounds/sounds.ts @@ -32,15 +32,15 @@ function restartAndPlay(audio: HTMLAudioElement, volume: number) { export function playSoundOnResetEnded(resetType: ResetType, volume = 1) { switch (resetType) { case ResetType.Yaw: { - restartAndPlay(quickResetStartedSound, volume); + restartAndPlay(tapSetupSound2, volume); break; } case ResetType.Full: { - restartAndPlay(fullResetStartedSound, volume); + restartAndPlay(tapSetupSound3, volume); break; } case ResetType.Mounting: { - restartAndPlay(mountingResetStartedSound, volume); + restartAndPlay(tapSetupSound4, volume); break; } } From 994e8ec91f69087b1f8afe26d6c660bafef884b8 Mon Sep 17 00:00:00 2001 From: loucass003 Date: Mon, 3 Feb 2025 13:07:39 +0100 Subject: [PATCH 4/4] remove old sounds --- gui/src/sounds/sounds.ts | 9 --------- 1 file changed, 9 deletions(-) diff --git a/gui/src/sounds/sounds.ts b/gui/src/sounds/sounds.ts index decb46b319..1e2ef96784 100644 --- a/gui/src/sounds/sounds.ts +++ b/gui/src/sounds/sounds.ts @@ -1,15 +1,6 @@ import { fetchResourceUrl } from '@/utils/tauri'; import { ResetType } from 'solarxr-protocol'; -const quickResetStartedSound = new Audio( - await fetchResourceUrl('/sounds/quick-reset-started-sound.mp3') -); -const fullResetStartedSound = new Audio( - await fetchResourceUrl('/sounds/full-reset-started-sound.mp3') -); -const mountingResetStartedSound = new Audio( - await fetchResourceUrl('/sounds/mounting-reset-started-sound.mp3') -); const tapSetupSound1 = new Audio(await fetchResourceUrl('/sounds/first-tap.mp3')); const tapSetupSound2 = new Audio(await fetchResourceUrl('/sounds/second-tap.mp3')); const tapSetupSound3 = new Audio(await fetchResourceUrl('/sounds/third-tap.mp3'));