Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve reset sounds #1294

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions gui/src/components/home/ResetButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
},
Expand All @@ -77,17 +81,22 @@ export function ResetButton({
return <FullResetIcon width={20} />;
};

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' ? (
<Button
icon={getIcon()}
onClick={() => {
startCountdown();
maybePlaySoundOnResetStarted(type);
maybePlaySoundOnResetStart();
}}
variant="primary"
disabled={isCounting || needsFullReset}
Expand All @@ -103,7 +112,7 @@ export function ResetButton({
icon={getIcon()}
onClick={() => {
startCountdown();
maybePlaySoundOnResetStarted(type);
maybePlaySoundOnResetStart();
}}
disabled={isCounting || needsFullReset}
></BigButton>
Expand Down
8 changes: 6 additions & 2 deletions gui/src/hooks/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
}
}
Expand Down
45 changes: 14 additions & 31 deletions gui/src/sounds/sounds.tsx → gui/src/sounds/sounds.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,12 @@
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 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')
);
Expand All @@ -41,23 +20,27 @@ function restartAndPlay(audio: HTMLAudioElement, volume: number) {
}
}

export function playSoundOnResetStarted(resetType: ResetType, volume = 1) {
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;
}
}
}

export function playSoundOnResetStarted(volume = 1) {
restartAndPlay(tapSetupSound1, volume);
}

let lastKnownVolume = 1;
/* Easter egg */
tapSetupSoundEnd.onended = () => {
Expand Down