1// Layout constants and small pure helpers for the piano roll canvas.
3export const PITCH_MIN = 21; // A0
4export const PITCH_MAX = 108; // C8
5export const KEY_H = 12; // px per semitone row
6export const RULER_H = 26;
7export const KEYS_W = 56;
8export const VEL_H = 72;
10export function isBlackKey(pitch: number): boolean {
11 const pc = ((pitch % 12) + 12) % 12;
12 return pc === 1 || pc === 3 || pc === 6 || pc === 8 || pc === 10;
13}
15export function snapValue(tick: number, grid: number, mode: 'round' | 'floor' | 'ceil'): number {
16 if (grid <= 0) return Math.round(tick);
17 const q = tick / grid;
18 const k = mode === 'round' ? Math.round(q) : mode === 'floor' ? Math.floor(q) : Math.ceil(q);
19 return k * grid;
20}