craffel / pretty-midi

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

Write Type 0 & Type 1 MIDI Files #144

Open gburlet opened 6 years ago

gburlet commented 6 years ago

Currently the write function only writes Type 1 MIDI files. Allow parameter in write function to also save Type 0 MIDI files.

craffel commented 6 years ago

Not all PrettyMIDI objects will be writeable as type 0 files since they can have more than 16 instruments. You could implement this and throw an error if there are too many instruments. I do not plan on implementing this.

fzalkow commented 4 years ago

@gburlet I also had the use case of writing type 0 files. However, instead of extending the writing functionalities of pretty_midi, I just used mido to convert from type 1 to type 0.

def midi_type1_to_type0(infile, outfile):
    type1 = mido.MidiFile(infile)
    type0 = mido.merge_tracks(type1.tracks)

    new_file = mido.MidiFile(type=0)
    new_file.tracks.append(type0)
    new_file.save(outfile)
Majda995 commented 2 years ago

when i convert Midi files type 1 to type 0 the new file (outfile )will not have the same length as the orignal one (infile)