How to use @tonejs/midi - 3 common examples

To help you get started, we’ve selected a few @tonejs/midi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ritz078 / raaga / components / RecordingModal.tsx View on Github external
function createMidi(name: string, notes: INote[], instrument: Instrument) {
  const midi = new MIDI();

  const tracks = midi.addTrack();
  const { name: instrumentName, group } = instrument;

  notes.forEach(_note => tracks.addNote(_note));

  const duration = tracks.duration;

  // @ts-ignore
  const midiJson: Midi = midi.toJSON();

  return {
    ...midiJson,
    header: {
      ...midiJson.header,
      name
github ritz078 / raaga / scripts / generateMidiMeta.js View on Github external
files.forEach(file => {
    const data = fs.readFileSync(
      path.resolve(__dirname, "../public/static/midi", file)
    );
    const { header, duration, tracks } = new Midi(data);
    meta.push({
      url: `/static/midi/${file}`,
      label: header.name || file.replace(".mid", ""),
      duration,
      tracks: tracks.length
    });
  });
github dawg / vusic / src / midi-parser.ts View on Github external
export const parse = (buffer: ArrayBuffer, bpm: number): INotes => {
  const json = new Midi(buffer);
  const bps = bpm / 60;

  const notes: INote[] = [];
  json.tracks.forEach((track) => {
    track.notes.forEach((note) => {
      notes.push({
        name: note.name,
        start: note.time * bps,
        duration: note.duration * bps,
        velocity: note.velocity,
      });
    });
  });

  return notes;
};

@tonejs/midi

Convert binary midi into JSON

MIT
Latest version published 3 years ago

Package Health Score

57 / 100
Full package analysis

Popular @tonejs/midi functions

Similar packages