craffel / pretty-midi

Utility functions for handling MIDI data in a nice/intuitive way.
MIT License
874 stars 152 forks source link

Some of the data sanitization applied in write() should be usable when reading #85

Open douglaseck opened 8 years ago

douglaseck commented 8 years ago

pretty_midi.py write() function does a lot of nice sanity checking and normalization of the data. For example, it sorts note onsets by time, pitch and velocity. It also checks for note-on and note-off ordering. And some other nice stuff (default time signature, etc).

Much of this sanitization should be available without having to write the file and read it back in. It would mean pulling a bunch of code out of write() into a sanitize_instruments() function. It would have to be slightly rewritten to operate over instruments rather than tracks. I guess we'd want it to be non-destructive so that it would be optional to use at the time of reading in.

craffel commented 8 years ago

Sounds useful to me!

It also checks for note-on and note-off ordering

I don't think this particular distinction exists in pretty_midi, unless you mean checking that a given Note has start < end; that's covered by Instrument.remove_invalid_notes.

douglaseck commented 8 years ago

I mean https://github.com/craffel/pretty-midi/blob/master/pretty_midi/pretty_midi.py#L1340

On Thu, Sep 1, 2016 at 10:12 AM, Colin Raffel notifications@github.com wrote:

Sounds useful to me!

It also checks for note-on and note-off ordering

I don't think this particular distinction exists in pretty_midi, unless you mean checking that a given Note has start < end; that's covered by Instrument.remove_invalid_notes https://github.com/craffel/pretty-midi/blob/master/pretty_midi/instrument.py#L292 .

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/craffel/pretty-midi/issues/85#issuecomment-244147075, or mute the thread https://github.com/notifications/unsubscribe-auth/APQ6Qh9t09v3wHA-iNvv0D_25gja6KSGks5qlweVgaJpZM4JyLTc .

craffel commented 8 years ago

I don't think that part is not relevant for pretty_midi's representation of MIDI data, because all notes are independent. That is, all notes in pretty_midi include an explicit correspondence between note on and note off, which isn't true in MIDI (hence the need for that code).