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

サウンド再生方法の変更に追従できていなかった所を修正 #12368

Merged
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

### Client
- fix: 「設定のバックアップ」で一部の項目がバックアップに含まれていなかった問題を修正
- Fix: ウィジェットのジョブキューにて音声の発音方法変更に追従できていなかったのを修正 #12367

### Server
-
Expand Down
20 changes: 10 additions & 10 deletions packages/frontend/src/scripts/sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const soundsTypes = [
'noizenecio/kick_gaba7',
] as const;

export async function getAudio(file: string, useCache = true) {
export async function loadAudio(file: string, useCache = true) {
if (useCache && cache.has(file)) {
return cache.get(file)!;
}
Expand All @@ -77,12 +77,6 @@ export async function getAudio(file: string, useCache = true) {
return audioBuffer;
}

export function setVolume(audio: HTMLAudioElement, volume: number): HTMLAudioElement {
const masterVolume = defaultStore.state.sound_masterVolume;
audio.volume = masterVolume - ((1 - volume) * masterVolume);
return audio;
}

export function play(type: 'noteMy' | 'note' | 'antenna' | 'channel' | 'notification') {
const sound = defaultStore.state[`sound_${type}`];
if (_DEV_) console.log('play', type, sound);
Expand All @@ -91,16 +85,22 @@ export function play(type: 'noteMy' | 'note' | 'antenna' | 'channel' | 'notifica
}

export async function playFile(file: string, volume: number) {
const buffer = await loadAudio(file);
createSourceNode(buffer, volume)?.start();
}

export function createSourceNode(buffer: AudioBuffer, volume: number) : AudioBufferSourceNode | null {
const masterVolume = defaultStore.state.sound_masterVolume;
if (masterVolume === 0 || volume === 0) {
return;
return null;
}

const gainNode = ctx.createGain();
gainNode.gain.value = masterVolume * volume;

const soundSource = ctx.createBufferSource();
soundSource.buffer = await getAudio(file);
soundSource.buffer = buffer;
soundSource.connect(gainNode).connect(ctx.destination);
soundSource.start();

return soundSource;
}
14 changes: 11 additions & 3 deletions packages/frontend/src/widgets/WidgetJobQueue.vue
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ const current = reactive({
},
});
const prev = reactive({} as typeof current);
const jammedSound = sound.setVolume(sound.getAudio('syuilo/queue-jammed'), 1);
let jammedAudioBuffer: AudioBuffer | null = $ref(null);
let jammedSoundNodePlaying: boolean = $ref(false);

sound.loadAudio('syuilo/queue-jammed').then(buf => jammedAudioBuffer = buf);

for (const domain of ['inbox', 'deliver']) {
prev[domain] = deepClone(current[domain]);
Expand All @@ -113,8 +116,13 @@ const onStats = (stats) => {
current[domain].waiting = stats[domain].waiting;
current[domain].delayed = stats[domain].delayed;

if (current[domain].waiting > 0 && widgetProps.sound && jammedSound.paused) {
jammedSound.play();
if (current[domain].waiting > 0 && widgetProps.sound && jammedAudioBuffer && !jammedSoundNodePlaying) {
const soundNode = sound.createSourceNode(jammedAudioBuffer, 1);
if (soundNode) {
jammedSoundNodePlaying = true;
soundNode.onended = () => jammedSoundNodePlaying = false;
soundNode.start();
}
}
}
};
Expand Down
Loading