/ proof-of-concept / midiboot
Sign in
proof-of-concept / midiboot
midiboot / src / midi / ops.ts
21 lines · 749 BBlameHistoryRaw
1import type { Note } from '../types.ts';
3// Pure note-list operations used by the editor; kept free of DOM and state
4// so the node test harness can exercise them directly.
6export function quantizeNotes(notes: Note[], gridTicks: number, ids?: Set<string>): Note[] {
7 if (gridTicks <= 0) return notes;
8 return notes.map((n) => {
9 if (ids && !ids.has(n.id)) return n;
10 const tick = Math.max(0, Math.round(n.tick / gridTicks) * gridTicks);
11 return { ...n, tick };
12 });
15export function transposeNotes(notes: Note[], semitones: number, ids?: Set<string>): Note[] {
16 return notes.map((n) => {
17 if (ids && !ids.has(n.id)) return n;
18 const pitch = Math.max(0, Math.min(127, n.pitch + semitones));
19 return { ...n, pitch };
20 });
↑↓ move↵openescclose