refactor: split soundtrack chapter and drive commands
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import {
|
||||
computed,
|
||||
onMounted,
|
||||
onUnmounted,
|
||||
readonly,
|
||||
@@ -9,17 +8,22 @@ import {
|
||||
} from 'vue';
|
||||
import { createAudioController } from '@/audio/create-audio-controller';
|
||||
import { createBrowserSoundtrackEngine } from '@/audio/soundtrack-engine';
|
||||
import { resolveJourneyMusicState } from '@/audio/journey-music-state';
|
||||
import type { AudioController, AudioUiState, SoundtrackSources } from '@/audio/types';
|
||||
import type {
|
||||
AudioController,
|
||||
AudioUiState,
|
||||
ChapterIntent,
|
||||
DriveEnergySample,
|
||||
SoundtrackSources,
|
||||
} from '@/audio/types';
|
||||
|
||||
declare const __PORTFOLIO_TEST_BUILD__: boolean;
|
||||
const TEST_BUILD = typeof __PORTFOLIO_TEST_BUILD__ !== 'undefined' && __PORTFOLIO_TEST_BUILD__;
|
||||
|
||||
export interface AudioEngineSources {
|
||||
activeSectionId: Readonly<Ref<string>>;
|
||||
intensity: Readonly<Ref<number>>;
|
||||
soundtrack: Readonly<Ref<SoundtrackSources | null>>;
|
||||
volume: Readonly<Ref<number>>;
|
||||
readonly chapter: Readonly<Ref<ChapterIntent>>;
|
||||
readonly drive: Readonly<Ref<DriveEnergySample>>;
|
||||
readonly soundtrack: Readonly<Ref<SoundtrackSources | null>>;
|
||||
readonly volume: Readonly<Ref<number>>;
|
||||
setVolume(value: number): void;
|
||||
}
|
||||
|
||||
@@ -38,10 +42,6 @@ export function useAudioEngine(sources: AudioEngineSources): AudioEngineBinding
|
||||
let controller: AudioController | null = null;
|
||||
let removeSubscription = (): void => {};
|
||||
let removePageListeners = (): void => {};
|
||||
const journeyState = computed(() => resolveJourneyMusicState(
|
||||
sources.activeSectionId.value,
|
||||
sources.intensity.value,
|
||||
));
|
||||
|
||||
const ensureController = (): AudioController => {
|
||||
if (controller) return controller;
|
||||
@@ -53,13 +53,17 @@ export function useAudioEngine(sources: AudioEngineSources): AudioEngineBinding
|
||||
},
|
||||
initialVolume: sources.volume.value,
|
||||
initiallyVisible: document.visibilityState !== 'hidden',
|
||||
initialJourneyState: journeyState.value,
|
||||
initialState: {
|
||||
chapter: sources.chapter.value,
|
||||
drive: sources.drive.value,
|
||||
},
|
||||
});
|
||||
removeSubscription = controller.subscribe((next) => { state.value = next; });
|
||||
return controller;
|
||||
};
|
||||
|
||||
watch(journeyState, (state) => controller?.setJourneyState(state), { flush: 'sync' });
|
||||
watch(sources.chapter, (intent) => controller?.setChapterIntent(intent), { flush: 'sync' });
|
||||
watch(sources.drive, (sample) => controller?.setDriveEnergy(sample), { flush: 'sync' });
|
||||
watch(sources.volume, (value) => controller?.setVolume(value));
|
||||
|
||||
onMounted(() => {
|
||||
|
||||
Reference in New Issue
Block a user