MidiWriterJS icon indicating copy to clipboard operation
MidiWriterJS copied to clipboard

Midi Reader Implementation

Open wileymc opened this issue 1 year ago • 2 comments

I've found a case where I need to take a URI generated by MidiWriterJS and modify it and output an updated URI. Is there a good way to do this with the existing library functionality? If not, I propose a new Reader class that accepts a URI or File as an input and generates the Track object from it. I can take a shot at the implementation.

wileymc avatar Feb 01 '24 18:02 wileymc

Hi @wileymc, there isn't currently a way to read a MIDI file into this library and modify its contents. Given the serial nature of adding events with MidiWriterJS I'm not sure how modifying an existing MIDI file would work exactly. Do you have any thoughts about how that would look?

grimmdude avatar Feb 04 '24 04:02 grimmdude

The way I imagine it being used would look something like this:

const write = new MidiWriter.Writer(track);
const uri = write.dataUri();

const track = new MidiWriter.Track().fromUri();
  track.addEvent(
    new MidiWriter.ProgramChangeEvent({ instrument: 5 })
  );

For the implementation, I think something similar to what tonejs has done here would be possible but may be difficult given MidiWriters current architecture.

wileymc avatar Feb 05 '24 01:02 wileymc