Skip to content

Commit 1829eb1

Browse files
committed
feat(stage-tamagotchi,stage-pages,stage-shared): show alert when there is no audio input for troubleshooting
1 parent ee9576f commit 1829eb1

File tree

3 files changed

+37
-6
lines changed
  • apps/stage-tamagotchi/src/main/windows/beat-sync
  • packages

3 files changed

+37
-6
lines changed

apps/stage-tamagotchi/src/main/windows/beat-sync/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export async function setupBeatSync() {
3333
})
3434
const context = createContext(ipcMain, window).context
3535

36-
// TODO(Makito): Revisit and improve
36+
// TODO(Makito): Bypass here with the broadcast channel-based transport when it is released.
3737
// [main] -> [renderer] beat-sync
3838
const toggle = defineInvoke(context, beatSyncElectronToggle) as (enabled: boolean) => Promise<void> // TODO: Better type
3939
const getState = defineInvoke(context, beatSyncElectronGetState)

packages/stage-pages/src/pages/settings/modules/beat-sync.vue

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,16 @@ import {
1111
toggleBeatSync,
1212
updateBeatSyncParameters,
1313
} from '@proj-airi/stage-shared/beat-sync/browser'
14-
import { AudioSpectrumVisualizer } from '@proj-airi/stage-ui/components'
14+
import { Alert, AudioSpectrumVisualizer } from '@proj-airi/stage-ui/components'
1515
import { Button, FieldCheckbox, FieldRange } from '@proj-airi/ui'
1616
import { createTimeline } from 'animejs'
1717
import { nanoid } from 'nanoid'
18-
import { onMounted, onUnmounted, ref, toRaw, watch } from 'vue'
18+
import { computed, onMounted, onUnmounted, ref, toRaw, watch } from 'vue'
1919
import { useI18n } from 'vue-i18n'
2020
2121
const state = ref<BeatSyncDetectorState>()
2222
const frequencies = ref<number[]>([])
23+
const totalFreqHistory = ref<number[]>([])
2324
const isUpdatingFrequencies = ref(false)
2425
2526
const { t } = useI18n()
@@ -72,13 +73,30 @@ function resetDefaultParameters() {
7273
7374
async function updateFrequencies() {
7475
frequencies.value = Array.from(await getBeatSyncInputByteFrequencyData())
76+
totalFreqHistory.value.push(frequencies.value.reduce((a, b) => a + b, 0))
7577
76-
if (isUpdatingFrequencies.value)
78+
while (totalFreqHistory.value.length > 50)
79+
totalFreqHistory.value.shift()
80+
81+
if (isUpdatingFrequencies.value) {
7782
requestAnimationFrame(updateFrequencies)
78-
else
79-
frequencies.value = [0]
83+
}
84+
else {
85+
frequencies.value = frequencies.value.map(() => 0)
86+
totalFreqHistory.value = []
87+
}
8088
}
8189
90+
const noAudioDetected = computed(() => {
91+
if (!isUpdatingFrequencies.value)
92+
return false
93+
94+
if (totalFreqHistory.value.length < 50)
95+
return false
96+
97+
return totalFreqHistory.value.reduce((a, b) => a + b, 0) === 0
98+
})
99+
82100
watch(state, async (newState) => {
83101
if (newState?.isActive) {
84102
if (!isUpdatingFrequencies.value) {
@@ -145,6 +163,18 @@ onUnmounted(() => {
145163
</div>
146164
</div>
147165

166+
<Alert
167+
v-if="noAudioDetected"
168+
type="warning"
169+
>
170+
<template #title>
171+
No audio detected
172+
</template>
173+
<template #content>
174+
Please make sure that the correct permissions are granted and the audio source is playing sound.
175+
</template>
176+
</Alert>
177+
148178
<div flex="~ col gap-4">
149179
<div flex="~ row" items-center justify-between>
150180
<div>

packages/stage-shared/src/beat-sync/browser/eventa.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { isElectronWindow } from '@proj-airi/stage-shared'
44

55
export function createContext() {
66
if (isElectronWindow(window)) {
7+
// TODO(Makito): Replace this with the broadcast channel-based transport when it is released.
78
return createElectronRendererContext(window.electron.ipcRenderer).context
89
}
910
else {

0 commit comments

Comments
 (0)