Add category rings and beat labels
This commit is contained in:
1 parent
9d8f277971
commit
4f221ea122
21 files changed
+752
-339
No files matched your search
+57
-21
@@ -11,11 +11,14 @@ import {
|
||||
INSTRUMENT_CATEGORIES,
|
||||
INSTRUMENT_CATALOG,
|
||||
INSTRUMENT_BY_ID,
|
||||
INSTRUMENT_CATEGORY_BY_ID,
|
||||
MAX_PITCH_SEMITONES,
|
||||
MIN_PITCH_SEMITONES,
|
||||
} from './domain/instruments';
|
||||
import { INSTRUMENT_VOICES } from './audio/soundVoices';
|
||||
import {
|
||||
getAlphabeticLabel,
|
||||
getNextBeatLetter,
|
||||
getNextAvailableStep,
|
||||
getPlaybackTickDurationMs,
|
||||
getLoopPositionPercent,
|
||||
@@ -30,6 +33,7 @@ import {
|
||||
TEMPO_BPM,
|
||||
} from './sequencer';
|
||||
import type { BeatPoint } from './sequencer';
|
||||
import { getStackedPosition } from './domain/timeline';
|
||||
|
||||
describe('circular step positions', () => {
|
||||
it('derives playback timing from tempo and fine-grained subdivisions', () => {
|
||||
@@ -72,6 +76,17 @@ describe('circular step positions', () => {
|
||||
expect(getStepFromPosition(point.x, point.y)).toBeCloseTo(fractionalStep, 8);
|
||||
});
|
||||
|
||||
it('visually separates same-category instruments at the same beat tick', () => {
|
||||
const beats: BeatPoint[] = [
|
||||
{ id: 'kick-a', soundId: 'kick', letter: 'a', step: 4 },
|
||||
{ id: 'snare-b', soundId: 'snare', letter: 'b', step: 4 },
|
||||
];
|
||||
const kickPosition = getStackedPosition(beats[0], beats, TOTAL_STEPS, 180);
|
||||
const snarePosition = getStackedPosition(beats[1], beats, TOTAL_STEPS, 180);
|
||||
|
||||
expect(kickPosition).not.toEqual(snarePosition);
|
||||
});
|
||||
|
||||
it('wraps fractional positions and reports loop percentages', () => {
|
||||
expect(wrapStepPosition(16.25, 16)).toBeCloseTo(0.25);
|
||||
expect(wrapStepPosition(-0.25, 16)).toBeCloseTo(15.75);
|
||||
@@ -80,8 +95,8 @@ describe('circular step positions', () => {
|
||||
|
||||
it('adds a sound at the next empty step', () => {
|
||||
const beats: BeatPoint[] = [
|
||||
{ id: 'first', soundId: 'kick', step: 0 },
|
||||
{ id: 'second', soundId: 'hi-hat', step: 1 },
|
||||
{ id: 'first', soundId: 'kick', letter: 'a', step: 0 },
|
||||
{ id: 'second', soundId: 'hi-hat', letter: 'b', step: 1 },
|
||||
];
|
||||
expect(getNextAvailableStep(beats)).toBe(2);
|
||||
});
|
||||
@@ -90,6 +105,7 @@ describe('circular step positions', () => {
|
||||
const beats: BeatPoint[] = Array.from({ length: TOTAL_STEPS }, (_, step) => ({
|
||||
id: `beat-${step}`,
|
||||
soundId: 'kick',
|
||||
letter: getAlphabeticLabel(step).toLowerCase(),
|
||||
step,
|
||||
}));
|
||||
expect(getNextAvailableStep(beats)).toBe(0);
|
||||
@@ -100,6 +116,7 @@ describe('circular step positions', () => {
|
||||
const beats: BeatPoint[] = Array.from({ length: totalSteps }, (_, step) => ({
|
||||
id: `beat-${step}`,
|
||||
soundId: 'kick',
|
||||
letter: getAlphabeticLabel(step).toLowerCase(),
|
||||
step,
|
||||
}));
|
||||
expect(getNextAvailableStep(beats, totalSteps)).toBe(0);
|
||||
@@ -125,6 +142,8 @@ describe('instrument catalog and pitch', () => {
|
||||
);
|
||||
|
||||
expect(new Set(categorizedInstruments).size).toBe(INSTRUMENT_CATALOG.length);
|
||||
expect(new Set(INSTRUMENT_CATEGORIES.map((category) => category.letter)).size)
|
||||
.toBe(INSTRUMENT_CATEGORIES.length);
|
||||
INSTRUMENT_CATALOG.forEach((instrument) => {
|
||||
expect(categorizedInstruments).toContain(instrument.id);
|
||||
expect(typeof INSTRUMENT_VOICES[instrument.id]).toBe('function');
|
||||
@@ -140,14 +159,27 @@ describe('instrument catalog and pitch', () => {
|
||||
expect(getPitchLabel(MAX_PITCH_SEMITONES)).toBe('C6');
|
||||
expect(getPitchLabel(0, INSTRUMENT_BY_ID.kick.pitchBaseMidi)).toBe('F3');
|
||||
});
|
||||
|
||||
it('assigns beat letters within their category and supports labels beyond Z', () => {
|
||||
const beats: BeatPoint[] = [
|
||||
{ id: 'kick-1', soundId: 'kick', letter: 'a', step: 0 },
|
||||
{ id: 'snare-1', soundId: 'snare', letter: 'b', step: 4 },
|
||||
{ id: 'piano-1', soundId: 'piano', letter: 'a', step: 8 },
|
||||
];
|
||||
|
||||
expect(getNextBeatLetter(beats, 'drums')).toBe('c');
|
||||
expect(getNextBeatLetter(beats, 'keys')).toBe('b');
|
||||
expect(getAlphabeticLabel(26)).toBe('AA');
|
||||
expect(INSTRUMENT_CATEGORY_BY_ID.drums.letter).toBe('A');
|
||||
});
|
||||
});
|
||||
|
||||
describe('sequencer state transitions', () => {
|
||||
it('loads a template with a focused first beat and removes a focused sound ring', () => {
|
||||
it('loads a template and removes every instrument in the focused category ring', () => {
|
||||
const templateBeats: BeatPoint[] = [
|
||||
{ id: 'kick-1', soundId: 'kick', step: 0 },
|
||||
{ id: 'kick-2', soundId: 'kick', step: 4 },
|
||||
{ id: 'hat-1', soundId: 'hi-hat', step: 8 },
|
||||
{ id: 'kick-1', soundId: 'kick', letter: 'a', step: 0 },
|
||||
{ id: 'snare-1', soundId: 'snare', letter: 'b', step: 4 },
|
||||
{ id: 'piano-1', soundId: 'piano', letter: 'a', step: 8 },
|
||||
];
|
||||
const loaded = sequencerReducer(createInitialSequencerState(), {
|
||||
type: 'template-loaded',
|
||||
@@ -157,18 +189,18 @@ describe('sequencer state transitions', () => {
|
||||
});
|
||||
|
||||
expect(loaded.selectedBeatId).toBe('kick-1');
|
||||
expect(loaded.focusedSoundId).toBe('kick');
|
||||
expect(loaded.focusedCategoryId).toBe('drums');
|
||||
|
||||
const afterRingRemoval = sequencerReducer(loaded, { type: 'focused-sound-removed' });
|
||||
const afterRingRemoval = sequencerReducer(loaded, { type: 'focused-category-removed' });
|
||||
expect(afterRingRemoval.beats).toEqual([templateBeats[2]]);
|
||||
expect(afterRingRemoval.selectedBeatId).toBeNull();
|
||||
expect(afterRingRemoval.focusedSoundId).toBe('hi-hat');
|
||||
expect(afterRingRemoval.focusedCategoryId).toBe('keys');
|
||||
});
|
||||
|
||||
it('clears out-of-range selections when the time signature gets shorter', () => {
|
||||
const beats: BeatPoint[] = [
|
||||
{ id: 'hat-1', soundId: 'hi-hat', step: 0 },
|
||||
{ id: 'kick-1', soundId: 'kick', step: 12 },
|
||||
{ id: 'hat-1', soundId: 'hi-hat', letter: 'a', step: 0 },
|
||||
{ id: 'kick-1', soundId: 'kick', letter: 'b', step: 12 },
|
||||
];
|
||||
const loaded = sequencerReducer(createInitialSequencerState(), {
|
||||
type: 'template-loaded',
|
||||
@@ -184,13 +216,14 @@ describe('sequencer state transitions', () => {
|
||||
|
||||
expect(shortened.beats).toEqual(beats);
|
||||
expect(shortened.selectedBeatId).toBeNull();
|
||||
expect(shortened.focusedSoundId).toBe('hi-hat');
|
||||
expect(shortened.focusedCategoryId).toBe('drums');
|
||||
});
|
||||
|
||||
it('removes a focused sound and keeps the remaining ring selected', () => {
|
||||
it('removes one category ring and focuses a remaining category', () => {
|
||||
const beats: BeatPoint[] = [
|
||||
{ id: 'kick-1', soundId: 'kick', step: 0 },
|
||||
{ id: 'hat-1', soundId: 'hi-hat', step: 4 },
|
||||
{ id: 'kick-1', soundId: 'kick', letter: 'a', step: 0 },
|
||||
{ id: 'hat-1', soundId: 'hi-hat', letter: 'b', step: 4 },
|
||||
{ id: 'bass-1', soundId: 'bass', letter: 'a', step: 8 },
|
||||
];
|
||||
const loaded = sequencerReducer(createInitialSequencerState(), {
|
||||
type: 'template-loaded',
|
||||
@@ -198,11 +231,14 @@ describe('sequencer state transitions', () => {
|
||||
tempoBpm: TEMPO_BPM,
|
||||
beatsPerBar: 4,
|
||||
});
|
||||
const hatSelected = sequencerReducer(loaded, { type: 'sound-selected', soundId: 'hi-hat' });
|
||||
const removed = sequencerReducer(hatSelected, { type: 'focused-sound-removed' });
|
||||
const bassSelected = sequencerReducer(loaded, {
|
||||
type: 'category-selected',
|
||||
categoryId: 'bass',
|
||||
});
|
||||
const removed = sequencerReducer(bassSelected, { type: 'focused-category-removed' });
|
||||
|
||||
expect(removed.beats).toEqual([beats[0]]);
|
||||
expect(removed.focusedSoundId).toBe('kick');
|
||||
expect(removed.beats).toEqual([beats[0], beats[1]]);
|
||||
expect(removed.focusedCategoryId).toBe('drums');
|
||||
expect(removed.selectedBeatId).toBeNull();
|
||||
});
|
||||
|
||||
@@ -217,8 +253,8 @@ describe('sequencer state transitions', () => {
|
||||
|
||||
it('changes pitch on one selected beat and clamps it to the supported range', () => {
|
||||
const beats: BeatPoint[] = [
|
||||
{ id: 'bass-1', soundId: 'bass', step: 0, pitchSemitones: 0 },
|
||||
{ id: 'piano-1', soundId: 'piano', step: 4, pitchSemitones: 0 },
|
||||
{ id: 'bass-1', soundId: 'bass', letter: 'a', step: 0, pitchSemitones: 0 },
|
||||
{ id: 'piano-1', soundId: 'piano', letter: 'a', step: 4, pitchSemitones: 0 },
|
||||
];
|
||||
const loaded = sequencerReducer(createInitialSequencerState(), {
|
||||
type: 'template-loaded',
|
||||
|
||||
Reference in new issue
Block a user