UNPKG

webdaw-modules

Version:

a set of modules for building a web-based DAW

56 lines (52 loc) 1.45 kB
import { Song } from "./createSong"; import { MIDINote } from "./createNotes"; type Args = { song: Song; index: number; millis: number; activeNotes: MIDINote[]; }; export const getActiveNotes = ({ song, index, millis, activeNotes }: Args) => { const { notes } = song; // const current = []; // let i = index; // console.log("highlighter", index); // while (i < notes.length) { // const note = notes[i]; // // console.log(index, millis, note.noteOn.millis, note.noteOff.millis); // if (millis >= note.noteOn.millis && millis <= note.noteOff.millis) { // i++; // current.push(note); // } // if (millis < note.noteOn.millis || millis > note.noteOff.millis) { // break; // } // } const current = notes.filter(n => { if (n.noteOn.millis && n.noteOff.millis) { return millis >= n.noteOn.millis && millis <= n.noteOff.millis; } return false; }); // console.log(millis, current); // console.log(activeNotes); const passiveNotes: MIDINote[] = activeNotes.filter(note => { const i = current.findIndex(n => { // console.log("C", n.id, "A", note.id); return n.id === note.id; }); // console.log(i); if (i === -1) { return true; } return false; }); // console.log("P", passiveNotes); // console.log("A", current); return { // index: i, index, // not in use activeNotes: current, passiveNotes, }; };