Add app info and instrument controls
This commit is contained in:
1 parent
e23825cdb1
commit
9d8f277971
38 files changed
+4001
-257
No files matched your search
@@ -49,7 +49,9 @@ export function useBeatPlayback({
|
||||
beatsRef.current.forEach((beat) => {
|
||||
if (beat.step >= totalStepsRef.current) return;
|
||||
const beatTick = Math.round(beat.step * PLAYBACK_SUBSTEPS_PER_STEP) % totalPlaybackTicks;
|
||||
if (beatTick === playbackTick) audioEngineRef.current?.play(beat.soundId);
|
||||
if (beatTick === playbackTick) {
|
||||
audioEngineRef.current?.play(beat.soundId, beat.pitchSemitones ?? 0);
|
||||
}
|
||||
});
|
||||
|
||||
nextPlaybackTickRef.current = (playbackTick + 1) % totalPlaybackTicks;
|
||||
|
||||
@@ -6,7 +6,8 @@ import {
|
||||
} from '../domain/sequencer';
|
||||
import type { BeatsPerBar } from '../domain/sequencer';
|
||||
import type { BeatPoint } from '../domain/sequencer';
|
||||
import type { SoundId } from '../domain/sounds';
|
||||
import { DEFAULT_PITCH_SEMITONES } from '../domain/instruments';
|
||||
import type { InstrumentId } from '../domain/instruments';
|
||||
import { createInitialSequencerState, sequencerReducer } from '../domain/sequencerReducer';
|
||||
import { useBeatPlayback } from './useBeatPlayback';
|
||||
|
||||
@@ -19,12 +20,13 @@ export interface BeatSequencer {
|
||||
tempoBpm: number;
|
||||
beatsPerBar: BeatsPerBar;
|
||||
totalSteps: number;
|
||||
focusedSoundId: SoundId | null;
|
||||
focusedSoundId: InstrumentId | null;
|
||||
selectedBeat: BeatPoint | undefined;
|
||||
addBeat: (soundId: SoundId) => void;
|
||||
addBeat: (soundId: InstrumentId) => void;
|
||||
moveBeat: (beatId: string, step: number) => void;
|
||||
changeBeatPitch: (beatId: string, pitchSemitones: number) => void;
|
||||
selectBeat: (beatId: string) => void;
|
||||
selectSound: (soundId: SoundId) => void;
|
||||
selectSound: (soundId: InstrumentId) => void;
|
||||
removeSelectedBeat: () => void;
|
||||
removeFocusedSound: () => void;
|
||||
setTempoBpm: (tempoBpm: number) => void;
|
||||
@@ -55,11 +57,12 @@ export function useBeatSequencer(): BeatSequencer {
|
||||
const playback = useBeatPlayback({ beats: visibleBeats, tempoBpm, totalSteps });
|
||||
const resetPlayback = playback.resetPlayback;
|
||||
|
||||
const addBeat = useCallback((soundId: SoundId): void => {
|
||||
const addBeat = useCallback((soundId: InstrumentId): void => {
|
||||
const beat: BeatPoint = {
|
||||
id: `beat-${nextBeatIdRef.current}`,
|
||||
soundId,
|
||||
step: getNextAvailableStep(beats, totalSteps),
|
||||
pitchSemitones: DEFAULT_PITCH_SEMITONES,
|
||||
};
|
||||
nextBeatIdRef.current += 1;
|
||||
dispatch({ type: 'beat-added', beat });
|
||||
@@ -69,11 +72,15 @@ export function useBeatSequencer(): BeatSequencer {
|
||||
dispatch({ type: 'beat-moved', beatId, step });
|
||||
}, []);
|
||||
|
||||
const changeBeatPitch = useCallback((beatId: string, pitchSemitones: number): void => {
|
||||
dispatch({ type: 'beat-pitch-changed', beatId, pitchSemitones });
|
||||
}, []);
|
||||
|
||||
const selectBeat = useCallback((beatId: string): void => {
|
||||
dispatch({ type: 'beat-selected', beatId });
|
||||
}, []);
|
||||
|
||||
const selectSound = useCallback((soundId: SoundId): void => {
|
||||
const selectSound = useCallback((soundId: InstrumentId): void => {
|
||||
dispatch({ type: 'sound-selected', soundId });
|
||||
}, []);
|
||||
|
||||
@@ -98,6 +105,7 @@ export function useBeatSequencer(): BeatSequencer {
|
||||
const beat: BeatPoint = {
|
||||
id: `beat-${nextBeatIdRef.current}`,
|
||||
...templateBeat,
|
||||
pitchSemitones: templateBeat.pitchSemitones ?? DEFAULT_PITCH_SEMITONES,
|
||||
};
|
||||
nextBeatIdRef.current += 1;
|
||||
return beat;
|
||||
@@ -125,6 +133,7 @@ export function useBeatSequencer(): BeatSequencer {
|
||||
selectedBeat,
|
||||
addBeat,
|
||||
moveBeat,
|
||||
changeBeatPitch,
|
||||
selectBeat,
|
||||
selectSound,
|
||||
removeSelectedBeat,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useCallback } from 'react';
|
||||
import type { BeatTemplate } from '../domain/beatTemplates';
|
||||
import type { SoundId } from '../domain/sounds';
|
||||
import type { InstrumentId } from '../domain/instruments';
|
||||
import type { BeatSequencer } from './useBeatSequencer';
|
||||
import { useBeatSequencer } from './useBeatSequencer';
|
||||
import type { SoundPalette } from './useSoundPalette';
|
||||
@@ -9,7 +9,7 @@ import { useSoundPalette } from './useSoundPalette';
|
||||
export interface BeatStudio {
|
||||
sequencer: BeatSequencer;
|
||||
soundPalette: SoundPalette;
|
||||
addSound: (soundId: SoundId) => void;
|
||||
addSound: (soundId: InstrumentId) => void;
|
||||
applyTemplate: (template: BeatTemplate) => void;
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ export function useBeatStudio(): BeatStudio {
|
||||
const { addBeat, loadTemplate } = sequencer;
|
||||
const { activateSounds } = soundPalette;
|
||||
|
||||
const addSound = useCallback((soundId: SoundId): void => {
|
||||
const addSound = useCallback((soundId: InstrumentId): void => {
|
||||
activateSounds([soundId]);
|
||||
addBeat(soundId);
|
||||
}, [activateSounds, addBeat]);
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
import { useCallback, useMemo, useState } from 'react';
|
||||
import type { SoundId } from '../domain/sounds';
|
||||
import type { InstrumentId } from '../domain/instruments';
|
||||
import { generateUniqueSoundColor } from '../domain/soundColors';
|
||||
|
||||
export interface PaletteSound {
|
||||
id: SoundId;
|
||||
id: InstrumentId;
|
||||
color: string;
|
||||
}
|
||||
|
||||
export interface SoundPalette {
|
||||
activeSounds: PaletteSound[];
|
||||
colorBySoundId: Partial<Record<SoundId, string>>;
|
||||
activateSounds: (soundIds: readonly SoundId[]) => void;
|
||||
colorBySoundId: Partial<Record<InstrumentId, string>>;
|
||||
activateSounds: (soundIds: readonly InstrumentId[]) => void;
|
||||
}
|
||||
|
||||
export function useSoundPalette(): SoundPalette {
|
||||
const [activeSounds, setActiveSounds] = useState<PaletteSound[]>([]);
|
||||
|
||||
const activateSounds = useCallback((soundIds: readonly SoundId[]): void => {
|
||||
const activateSounds = useCallback((soundIds: readonly InstrumentId[]): void => {
|
||||
setActiveSounds((currentSounds) => {
|
||||
const nextSounds = [...currentSounds];
|
||||
const currentCount = nextSounds.length;
|
||||
@@ -33,7 +33,7 @@ export function useSoundPalette(): SoundPalette {
|
||||
}, []);
|
||||
|
||||
const colorBySoundId = useMemo(() => {
|
||||
const colors: Partial<Record<SoundId, string>> = {};
|
||||
const colors: Partial<Record<InstrumentId, string>> = {};
|
||||
activeSounds.forEach((sound) => {
|
||||
colors[sound.id] = sound.color;
|
||||
});
|
||||
|
||||
Reference in new issue
Block a user