Add category rings and beat labels

This commit is contained in:
Ninosaurier committed 2026-11-15 14:35:36 +01:00
1 parent 9d8f277971
commit 4f221ea122
21 files changed
+752 -339

No files matched your search

+36 -1
View File
@@ -1,4 +1,5 @@
import type { InstrumentId } from './instruments';
import { INSTRUMENT_BY_ID } from './instruments';
import type { InstrumentCategoryId, InstrumentId } from './instruments';
export const STEPS_PER_BEAT = 4;
export const PLAYBACK_SUBSTEPS_PER_STEP = 4;
@@ -25,12 +26,46 @@ export function getPlaybackTickDurationMs(tempoBpm: number): number {
export interface BeatPoint {
id: string;
soundId: InstrumentId;
/** Short unique label within its instrument category, such as a, b, or c. */
letter: string;
/** 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 getAlphabeticLabel(index: number): string {
let value = Math.floor(index) + 1;
if (!Number.isSafeInteger(value) || value < 1) return '';
let label = '';
while (value > 0) {
value -= 1;
label = String.fromCharCode(65 + (value % 26)) + label;
value = Math.floor(value / 26);
}
return label;
}
export function getNextBeatLetter(
beats: readonly BeatPoint[],
categoryId: InstrumentCategoryId,
): string {
const usedLetters = new Set(
beats
.filter((beat) => INSTRUMENT_BY_ID[beat.soundId].categoryId === categoryId)
.map((beat) => beat.letter),
);
let index = 0;
let letter = getAlphabeticLabel(index).toLowerCase();
while (usedLetters.has(letter)) {
index += 1;
letter = getAlphabeticLabel(index).toLowerCase();
}
return letter;
}
export function getNextAvailableStep(
beats: readonly BeatPoint[],
totalSteps = TOTAL_STEPS,