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
@@ -1,10 +1,11 @@
|
||||
import { DEFAULT_BEATS_PER_BAR, TEMPO_BPM } from './sequencer';
|
||||
import type { BeatsPerBar } from './sequencer';
|
||||
import type { SoundId } from './sounds';
|
||||
import type { InstrumentId } from './instruments';
|
||||
|
||||
export interface TemplateBeat {
|
||||
soundId: SoundId;
|
||||
soundId: InstrumentId;
|
||||
step: number;
|
||||
pitchSemitones?: number;
|
||||
}
|
||||
|
||||
export type BeatTemplateId = 'empty' | 'bachata' | 'salsa' | 'lindy-hop';
|
||||
|
||||
@@ -0,0 +1,187 @@
|
||||
const INSTRUMENT_DEFINITIONS = {
|
||||
kick: {
|
||||
id: 'kick',
|
||||
label: 'Kick',
|
||||
description: 'Low drum pulse',
|
||||
categoryId: 'drums',
|
||||
supportsPitch: true,
|
||||
pitchBaseMidi: 53,
|
||||
},
|
||||
snare: {
|
||||
id: 'snare',
|
||||
label: 'Snare',
|
||||
description: 'Sharp drum hit',
|
||||
categoryId: 'drums',
|
||||
supportsPitch: false,
|
||||
pitchBaseMidi: 60,
|
||||
},
|
||||
'hi-hat': {
|
||||
id: 'hi-hat',
|
||||
label: 'Hi-hat',
|
||||
description: 'Bright tick',
|
||||
categoryId: 'drums',
|
||||
supportsPitch: false,
|
||||
pitchBaseMidi: 60,
|
||||
},
|
||||
toms: {
|
||||
id: 'toms',
|
||||
label: 'Toms',
|
||||
description: 'Tuned drum tones',
|
||||
categoryId: 'drums',
|
||||
supportsPitch: true,
|
||||
pitchBaseMidi: 51,
|
||||
},
|
||||
cymbals: {
|
||||
id: 'cymbals',
|
||||
label: 'Cymbals',
|
||||
description: 'Bright metallic wash',
|
||||
categoryId: 'drums',
|
||||
supportsPitch: false,
|
||||
pitchBaseMidi: 60,
|
||||
},
|
||||
clap: {
|
||||
id: 'clap',
|
||||
label: 'Clap',
|
||||
description: 'Short handclap',
|
||||
categoryId: 'percussion',
|
||||
supportsPitch: false,
|
||||
pitchBaseMidi: 60,
|
||||
},
|
||||
shaker: {
|
||||
id: 'shaker',
|
||||
label: 'Shaker',
|
||||
description: 'Soft rhythmic rattle',
|
||||
categoryId: 'percussion',
|
||||
supportsPitch: false,
|
||||
pitchBaseMidi: 60,
|
||||
},
|
||||
cowbell: {
|
||||
id: 'cowbell',
|
||||
label: 'Cowbell',
|
||||
description: 'Metallic bell tone',
|
||||
categoryId: 'percussion',
|
||||
supportsPitch: false,
|
||||
pitchBaseMidi: 60,
|
||||
},
|
||||
woodblock: {
|
||||
id: 'woodblock',
|
||||
label: 'Woodblock',
|
||||
description: 'Short wooden click',
|
||||
categoryId: 'percussion',
|
||||
supportsPitch: false,
|
||||
pitchBaseMidi: 60,
|
||||
},
|
||||
bongos: {
|
||||
id: 'bongos',
|
||||
label: 'Bongos',
|
||||
description: 'Tuned hand drums',
|
||||
categoryId: 'percussion',
|
||||
supportsPitch: true,
|
||||
pitchBaseMidi: 59,
|
||||
},
|
||||
bass: {
|
||||
id: 'bass',
|
||||
label: 'Bass',
|
||||
description: 'Low pitched tone',
|
||||
categoryId: 'bass',
|
||||
supportsPitch: true,
|
||||
pitchBaseMidi: 36,
|
||||
},
|
||||
piano: {
|
||||
id: 'piano',
|
||||
label: 'Piano',
|
||||
description: 'Short keyed tone',
|
||||
categoryId: 'keys',
|
||||
supportsPitch: true,
|
||||
pitchBaseMidi: 60,
|
||||
},
|
||||
organ: {
|
||||
id: 'organ',
|
||||
label: 'Organ',
|
||||
description: 'Sustained keyed tone',
|
||||
categoryId: 'keys',
|
||||
supportsPitch: true,
|
||||
pitchBaseMidi: 60,
|
||||
},
|
||||
strings: {
|
||||
id: 'strings',
|
||||
label: 'Strings',
|
||||
description: 'Warm sustained tone',
|
||||
categoryId: 'strings',
|
||||
supportsPitch: true,
|
||||
pitchBaseMidi: 60,
|
||||
},
|
||||
winds: {
|
||||
id: 'winds',
|
||||
label: 'Winds',
|
||||
description: 'Soft breath-like tone',
|
||||
categoryId: 'winds',
|
||||
supportsPitch: true,
|
||||
pitchBaseMidi: 60,
|
||||
},
|
||||
synth: {
|
||||
id: 'synth',
|
||||
label: 'Synth',
|
||||
description: 'Bright electronic tone',
|
||||
categoryId: 'synth',
|
||||
supportsPitch: true,
|
||||
pitchBaseMidi: 60,
|
||||
},
|
||||
} as const;
|
||||
|
||||
export type InstrumentId = keyof typeof INSTRUMENT_DEFINITIONS;
|
||||
export type InstrumentDefinition = (typeof INSTRUMENT_DEFINITIONS)[InstrumentId];
|
||||
export type InstrumentCategoryId = InstrumentDefinition['categoryId'];
|
||||
|
||||
export interface InstrumentCategory {
|
||||
id: InstrumentCategoryId;
|
||||
label: string;
|
||||
instrumentIds: readonly InstrumentId[];
|
||||
}
|
||||
|
||||
export const INSTRUMENT_BY_ID: Record<InstrumentId, InstrumentDefinition> = INSTRUMENT_DEFINITIONS;
|
||||
export const INSTRUMENT_CATALOG: readonly InstrumentDefinition[] = Object.values(INSTRUMENT_DEFINITIONS);
|
||||
const INSTRUMENT_ID_SET = new Set<string>(INSTRUMENT_CATALOG.map((instrument) => instrument.id));
|
||||
|
||||
export function isInstrumentId(value: unknown): value is InstrumentId {
|
||||
return typeof value === 'string' && INSTRUMENT_ID_SET.has(value);
|
||||
}
|
||||
|
||||
export const INSTRUMENT_CATEGORIES = [
|
||||
{ id: 'drums', label: 'Drums', instrumentIds: ['kick', 'snare', 'hi-hat', 'toms', 'cymbals'] },
|
||||
{
|
||||
id: 'percussion',
|
||||
label: 'Percussion',
|
||||
instrumentIds: ['clap', 'shaker', 'cowbell', 'woodblock', 'bongos'],
|
||||
},
|
||||
{ id: 'bass', label: 'Bass', instrumentIds: ['bass'] },
|
||||
{ id: 'keys', label: 'Keys', instrumentIds: ['piano', 'organ'] },
|
||||
{ id: 'strings', label: 'Strings', instrumentIds: ['strings'] },
|
||||
{ id: 'winds', label: 'Winds', instrumentIds: ['winds'] },
|
||||
{ id: 'synth', label: 'Synth', instrumentIds: ['synth'] },
|
||||
] as const satisfies readonly InstrumentCategory[];
|
||||
|
||||
export const DEFAULT_PITCH_SEMITONES = 0;
|
||||
export const MIN_PITCH_SEMITONES = -24;
|
||||
export const MAX_PITCH_SEMITONES = 24;
|
||||
|
||||
export function clampPitchSemitones(pitchSemitones: number): number {
|
||||
return Math.min(
|
||||
MAX_PITCH_SEMITONES,
|
||||
Math.max(MIN_PITCH_SEMITONES, Math.round(pitchSemitones)),
|
||||
);
|
||||
}
|
||||
|
||||
export function getPitchLabel(pitchSemitones: number, baseMidiNote = 60): string {
|
||||
const noteNames = ['C', 'C♯', 'D', 'D♯', 'E', 'F', 'F♯', 'G', 'G♯', 'A', 'A♯', 'B'];
|
||||
const midiNote = baseMidiNote + clampPitchSemitones(pitchSemitones);
|
||||
const noteName = noteNames[midiNote % 12];
|
||||
const octave = Math.floor(midiNote / 12) - 1;
|
||||
return `${noteName}${octave}`;
|
||||
}
|
||||
|
||||
// Keep the original names available for existing sequencer data and saved templates.
|
||||
export type SoundId = InstrumentId;
|
||||
export type SoundDefinition = InstrumentDefinition;
|
||||
export const SOUND_BY_ID = INSTRUMENT_BY_ID;
|
||||
export const SOUND_CATALOG = INSTRUMENT_CATALOG;
|
||||
@@ -1,4 +1,4 @@
|
||||
import type { SoundId } from './sounds';
|
||||
import type { InstrumentId } from './instruments';
|
||||
|
||||
export const STEPS_PER_BEAT = 4;
|
||||
export const PLAYBACK_SUBSTEPS_PER_STEP = 4;
|
||||
@@ -24,9 +24,11 @@ export function getPlaybackTickDurationMs(tempoBpm: number): number {
|
||||
|
||||
export interface BeatPoint {
|
||||
id: string;
|
||||
soundId: SoundId;
|
||||
soundId: InstrumentId;
|
||||
/** Position in sixteenth-note steps; fractional values represent microtiming. */
|
||||
step: number;
|
||||
/** Pitch offset from the instrument's base note in semitones. */
|
||||
pitchSemitones?: number;
|
||||
}
|
||||
|
||||
export function getNextAvailableStep(
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
import { clampTempoBpm, DEFAULT_BEATS_PER_BAR, getTotalSteps, TEMPO_BPM } from './sequencer';
|
||||
import {
|
||||
clampTempoBpm,
|
||||
DEFAULT_BEATS_PER_BAR,
|
||||
getTotalSteps,
|
||||
TEMPO_BPM,
|
||||
} from './sequencer';
|
||||
import type { BeatsPerBar, BeatPoint } from './sequencer';
|
||||
import type { SoundId } from './sounds';
|
||||
import { clampPitchSemitones } from './instruments';
|
||||
import type { InstrumentId } from './instruments';
|
||||
|
||||
export interface SequencerState {
|
||||
beats: BeatPoint[];
|
||||
selectedBeatId: string | null;
|
||||
focusedSoundId: SoundId | null;
|
||||
focusedSoundId: InstrumentId | null;
|
||||
tempoBpm: number;
|
||||
beatsPerBar: BeatsPerBar;
|
||||
}
|
||||
@@ -13,8 +19,9 @@ export interface SequencerState {
|
||||
export type SequencerAction =
|
||||
| { type: 'beat-added'; beat: BeatPoint }
|
||||
| { type: 'beat-moved'; beatId: string; step: number }
|
||||
| { type: 'beat-pitch-changed'; beatId: string; pitchSemitones: number }
|
||||
| { type: 'beat-selected'; beatId: string }
|
||||
| { type: 'sound-selected'; soundId: SoundId }
|
||||
| { type: 'sound-selected'; soundId: InstrumentId }
|
||||
| { type: 'selected-beat-removed' }
|
||||
| { type: 'focused-sound-removed' }
|
||||
| { type: 'tempo-changed'; tempoBpm: number }
|
||||
@@ -51,6 +58,15 @@ export function sequencerReducer(state: SequencerState, action: SequencerAction)
|
||||
beat.id === action.beatId ? { ...beat, step: action.step } : beat
|
||||
)),
|
||||
};
|
||||
case 'beat-pitch-changed':
|
||||
return {
|
||||
...state,
|
||||
beats: state.beats.map((beat) => (
|
||||
beat.id === action.beatId
|
||||
? { ...beat, pitchSemitones: clampPitchSemitones(action.pitchSemitones) }
|
||||
: beat
|
||||
)),
|
||||
};
|
||||
case 'beat-selected': {
|
||||
const beat = state.beats.find((candidate) => candidate.id === action.beatId);
|
||||
if (!beat) return state;
|
||||
|
||||
+1
-10
@@ -1,10 +1 @@
|
||||
const SOUND_DEFINITIONS = {
|
||||
'hi-hat': { id: 'hi-hat', label: 'Hi-hat', description: 'Bright tick' },
|
||||
kick: { id: 'kick', label: 'Kick', description: 'Low pulse' },
|
||||
} as const;
|
||||
|
||||
export type SoundId = keyof typeof SOUND_DEFINITIONS;
|
||||
export type SoundDefinition = (typeof SOUND_DEFINITIONS)[SoundId];
|
||||
|
||||
export const SOUND_BY_ID: Record<SoundId, SoundDefinition> = SOUND_DEFINITIONS;
|
||||
export const SOUND_CATALOG: readonly SoundDefinition[] = Object.values(SOUND_DEFINITIONS);
|
||||
export * from './instruments';
|
||||
Reference in new issue
Block a user