Skip to content

Commit

Permalink
feat(audio): New sound set and option to change sounds (#372)
Browse files Browse the repository at this point in the history
* feat(audio): Add 'Sharp' sound set with loud and short beeps

* fix(audio): Watch sound set changes and load new ones
  • Loading branch information
Hanziness authored Sep 15, 2024
1 parent 9f04d1b commit 7b652da
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 9 deletions.
1 change: 1 addition & 0 deletions components/settings/settingsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ notificationsStore.updateEnabled()
}
}"
/>
<SettingsItem :type="Control.Option" :choices="{musical: SoundSet.Musical, sharp: SoundSet.Sharp}" path="audio.soundSet" />
</template>

<template v-if="isMobile">
Expand Down
8 changes: 5 additions & 3 deletions i18n/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,14 @@
},
"soundSet": {
"_title": "Sound set",
"_description": "Sounds used for notifications",
"_description": "Sounds played at the end of each session",
"_values": {
"musical": "Musical"
"musical": "Musical",
"sharp": "Sharp"
},
"_valueDescription": {
"musical": "The default sounds"
"musical": "The default sounds",
"sharp": "Shorter, beep-like sounds better for training"
}
}
},
Expand Down
10 changes: 7 additions & 3 deletions platforms/web.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ export function useWeb () {
}
})

watch(() => settingsStore.audio.soundSet, (newSoundSet) => {
loadSoundSet(newSoundSet)
})

eventsStore.$subscribe(() => {
if (eventsStore.lastEvent !== null && eventsStore.lastEvent._event === EventType.NOTIFICATIONS_ENABLED && window.Notification && window.Notification.permission === 'default') {
window.Notification.requestPermission().then((newNotificationPermission) => {
Expand Down Expand Up @@ -75,7 +79,7 @@ export function useWeb () {

// check if timer is already running
if (scheduleStore.timerState === 1) {
loadSoundSet()
loadSoundSet(settingsStore.audio.soundSet)
}

// Check Visibility and register in store
Expand Down Expand Up @@ -118,7 +122,7 @@ export function useWeb () {

state.currentSoundSet = setName
} catch (err) {
// console.warn(err)
console.warn(err)
}
}

Expand All @@ -129,7 +133,7 @@ export function useWeb () {
const playSound = (key: keyof typeof state.sounds) => {
// load sound set if not already loaded
if (!state.currentSoundSet) {
loadSoundSet()
loadSoundSet(settingsStore.audio.soundSet)
}

if (state.sounds[key] !== null && settingsStore.permissions.audio) {
Expand Down
Binary file added public/audio/sharp/longpause.mp3
Binary file not shown.
Binary file added public/audio/sharp/shortpause.mp3
Binary file not shown.
Binary file added public/audio/sharp/work.mp3
Binary file not shown.
5 changes: 2 additions & 3 deletions stores/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export enum SectionEndAction {
}

export enum SoundSet {
Musical = 'musical'
Musical = 'musical',
Sharp = 'sharp'
}

export enum Section {
Expand Down Expand Up @@ -73,7 +74,6 @@ export interface Settings {
},
audio: {
volume: number,
repeatTimes: number,
soundSet: SoundSet
},
timerControls: {
Expand Down Expand Up @@ -154,7 +154,6 @@ export const useSettings = defineStore('settings', {
},
audio: {
volume: 0.9,
repeatTimes: 2,
soundSet: SoundSet.Musical
},
timerControls: {
Expand Down

0 comments on commit 7b652da

Please sign in to comment.