Build BeatHound sequencer app
This commit is contained in:
1 parent
226ababcf1
commit
e23825cdb1
49 files changed
+6455
-2
No files matched your search
@@ -0,0 +1,40 @@
|
||||
import type { SoundId } from './sounds';
|
||||
|
||||
export const STEPS_PER_BEAT = 4;
|
||||
export const PLAYBACK_SUBSTEPS_PER_STEP = 4;
|
||||
export const DEFAULT_BEATS_PER_BAR = 4;
|
||||
export const BEATS_PER_BAR_OPTIONS = [2, 3, 4, 5, 6, 7, 8] as const;
|
||||
export type BeatsPerBar = (typeof BEATS_PER_BAR_OPTIONS)[number];
|
||||
export const TOTAL_STEPS = DEFAULT_BEATS_PER_BAR * STEPS_PER_BEAT;
|
||||
export const TEMPO_BPM = 112;
|
||||
export const MIN_TEMPO_BPM = 60;
|
||||
export const MAX_TEMPO_BPM = 180;
|
||||
|
||||
export function getTotalSteps(beatsPerBar: BeatsPerBar): number {
|
||||
return beatsPerBar * STEPS_PER_BEAT;
|
||||
}
|
||||
|
||||
export function clampTempoBpm(tempoBpm: number): number {
|
||||
return Math.min(MAX_TEMPO_BPM, Math.max(MIN_TEMPO_BPM, Math.round(tempoBpm)));
|
||||
}
|
||||
|
||||
export function getPlaybackTickDurationMs(tempoBpm: number): number {
|
||||
return 60_000 / tempoBpm / STEPS_PER_BEAT / PLAYBACK_SUBSTEPS_PER_STEP;
|
||||
}
|
||||
|
||||
export interface BeatPoint {
|
||||
id: string;
|
||||
soundId: SoundId;
|
||||
/** Position in sixteenth-note steps; fractional values represent microtiming. */
|
||||
step: number;
|
||||
}
|
||||
|
||||
export function getNextAvailableStep(
|
||||
beats: readonly BeatPoint[],
|
||||
totalSteps = TOTAL_STEPS,
|
||||
): number {
|
||||
const occupiedSteps = new Set(beats.map((beat) => beat.step));
|
||||
const nextStep = Array.from({ length: totalSteps }, (_, step) => step)
|
||||
.find((step) => !occupiedSteps.has(step));
|
||||
return nextStep ?? 0;
|
||||
}
|
||||
Reference in new issue
Block a user