Restore sound-specific rings and refine studio UI

This commit is contained in:
Ninosaurier committed 2026-11-17 17:04:02 +01:00
1 parent 02eb8911e8
commit e7b6c0bb3e
16 files changed
+318 -524

No files matched your search

+24 -29
View File
@@ -5,13 +5,13 @@ import {
TEMPO_BPM,
} from './sequencer';
import type { BeatsPerBar, BeatPoint } from './sequencer';
import { clampPitchSemitones, INSTRUMENT_BY_ID } from './instruments';
import type { InstrumentCategoryId } from './instruments';
import { clampPitchSemitones } from './instruments';
import type { InstrumentId } from './instruments';
export interface SequencerState {
beats: BeatPoint[];
selectedBeatId: string | null;
focusedCategoryId: InstrumentCategoryId | null;
focusedSoundId: InstrumentId | null;
tempoBpm: number;
beatsPerBar: BeatsPerBar;
}
@@ -21,9 +21,9 @@ export type SequencerAction =
| { type: 'beat-moved'; beatId: string; step: number }
| { type: 'beat-pitch-changed'; beatId: string; pitchSemitones: number }
| { type: 'beat-selected'; beatId: string }
| { type: 'category-selected'; categoryId: InstrumentCategoryId }
| { type: 'sound-selected'; soundId: InstrumentId }
| { type: 'selected-beat-removed' }
| { type: 'focused-category-removed' }
| { type: 'focused-sound-removed' }
| { type: 'tempo-changed'; tempoBpm: number }
| { type: 'time-signature-changed'; beatsPerBar: BeatsPerBar }
| { type: 'template-loaded'; beats: BeatPoint[]; tempoBpm: number; beatsPerBar: BeatsPerBar };
@@ -32,7 +32,7 @@ export function createInitialSequencerState(): SequencerState {
return {
beats: [],
selectedBeatId: null,
focusedCategoryId: null,
focusedSoundId: null,
tempoBpm: TEMPO_BPM,
beatsPerBar: DEFAULT_BEATS_PER_BAR,
};
@@ -49,7 +49,7 @@ export function sequencerReducer(state: SequencerState, action: SequencerAction)
...state,
beats: [...state.beats, action.beat],
selectedBeatId: action.beat.id,
focusedCategoryId: INSTRUMENT_BY_ID[action.beat.soundId].categoryId,
focusedSoundId: action.beat.soundId,
};
case 'beat-moved':
return {
@@ -73,40 +73,35 @@ export function sequencerReducer(state: SequencerState, action: SequencerAction)
return {
...state,
selectedBeatId: beat.id,
focusedCategoryId: INSTRUMENT_BY_ID[beat.soundId].categoryId,
focusedSoundId: beat.soundId,
};
}
case 'category-selected':
return { ...state, focusedCategoryId: action.categoryId, selectedBeatId: null };
case 'sound-selected':
return { ...state, focusedSoundId: action.soundId, selectedBeatId: null };
case 'selected-beat-removed': {
if (!state.selectedBeatId) return state;
const removedBeat = state.beats.find((beat) => beat.id === state.selectedBeatId);
if (!removedBeat) return { ...state, selectedBeatId: null };
const beats = state.beats.filter((beat) => beat.id !== removedBeat.id);
const removedCategoryId = INSTRUMENT_BY_ID[removedBeat.soundId].categoryId;
const categoryRemains = beats.some(
(beat) => INSTRUMENT_BY_ID[beat.soundId].categoryId === removedCategoryId,
);
const soundRemains = beats.some((beat) => beat.soundId === removedBeat.soundId);
return {
...state,
beats,
selectedBeatId: null,
focusedCategoryId: state.focusedCategoryId === removedCategoryId && !categoryRemains
? beats[0] ? INSTRUMENT_BY_ID[beats[0].soundId].categoryId : null
: state.focusedCategoryId,
focusedSoundId: state.focusedSoundId === removedBeat.soundId && !soundRemains
? beats[0]?.soundId ?? null
: state.focusedSoundId,
};
}
case 'focused-category-removed': {
if (!state.focusedCategoryId) return state;
const beats = state.beats.filter(
(beat) => INSTRUMENT_BY_ID[beat.soundId].categoryId !== state.focusedCategoryId,
);
case 'focused-sound-removed': {
if (!state.focusedSoundId) return state;
const beats = state.beats.filter((beat) => beat.soundId !== state.focusedSoundId);
return {
...state,
beats,
selectedBeatId: null,
focusedCategoryId: beats[0] ? INSTRUMENT_BY_ID[beats[0].soundId].categoryId : null,
focusedSoundId: beats[0]?.soundId ?? null,
};
}
case 'tempo-changed':
@@ -115,16 +110,16 @@ export function sequencerReducer(state: SequencerState, action: SequencerAction)
const totalSteps = getTotalSteps(action.beatsPerBar);
const visibleBeats = state.beats.filter((beat) => beat.step < totalSteps);
const selectedBeat = visibleBeats.find((beat) => beat.id === state.selectedBeatId);
const focusedCategoryRemains = visibleBeats.some(
(beat) => INSTRUMENT_BY_ID[beat.soundId].categoryId === state.focusedCategoryId,
const focusedSoundRemains = visibleBeats.some(
(beat) => beat.soundId === state.focusedSoundId,
);
return {
...state,
beatsPerBar: action.beatsPerBar,
selectedBeatId: selectedBeat?.id ?? null,
focusedCategoryId: focusedCategoryRemains
? state.focusedCategoryId
: visibleBeats[0] ? INSTRUMENT_BY_ID[visibleBeats[0].soundId].categoryId : null,
focusedSoundId: focusedSoundRemains
? state.focusedSoundId
: visibleBeats[0]?.soundId ?? null,
};
}
case 'template-loaded': {
@@ -133,7 +128,7 @@ export function sequencerReducer(state: SequencerState, action: SequencerAction)
...state,
beats: action.beats,
selectedBeatId: firstBeat?.id ?? null,
focusedCategoryId: firstBeat ? INSTRUMENT_BY_ID[firstBeat.soundId].categoryId : null,
focusedSoundId: firstBeat?.soundId ?? null,
tempoBpm: clampTempoBpm(action.tempoBpm),
beatsPerBar: action.beatsPerBar,
};
+3 -7
View File
@@ -1,5 +1,4 @@
import type { BeatPoint } from './sequencer';
import { INSTRUMENT_BY_ID } from './instruments';
import {
PLAYBACK_SUBSTEPS_PER_STEP,
TOTAL_STEPS,
@@ -48,12 +47,10 @@ export function wrapStepPosition(step: number, totalSteps: number): number {
return ((step % totalSteps) + totalSteps) % totalSteps;
}
export function getCategoryOrbitRadius(categoryIndex: number, categoryCount: number): number {
return ORBIT_RADIUS * (categoryCount + 1 - categoryIndex) / (categoryCount + 1);
export function getSoundOrbitRadius(soundIndex: number, soundCount: number): number {
return ORBIT_RADIUS * (soundCount + 1 - soundIndex) / (soundCount + 1);
}
export const getSoundOrbitRadius = getCategoryOrbitRadius;
export function getPlaybackTick(step: number, totalSteps: number): number {
const totalPlaybackTicks = totalSteps * PLAYBACK_SUBSTEPS_PER_STEP;
return Math.round(step * PLAYBACK_SUBSTEPS_PER_STEP) % totalPlaybackTicks;
@@ -67,8 +64,7 @@ export function getStackedPosition(
): CirclePoint {
const siblings = beats
.filter((candidate) => (
INSTRUMENT_BY_ID[candidate.soundId].categoryId
=== INSTRUMENT_BY_ID[beat.soundId].categoryId
candidate.soundId === beat.soundId
&& getPlaybackTick(candidate.step, totalSteps) === getPlaybackTick(beat.step, totalSteps)
))
.sort((first, second) => first.id.localeCompare(second.id));