0

I am currently writing a midi generator using preexisting midi files. I'm getting confused as each midi file I download seems to be saved in a slightly different format. I particularly getting confused as to what tracks are and how they effect time. In the midi files docs it states:

File Types
There are three types of MIDI files:

type 0 (single track): all messages are saved in one track
type 1 (synchronous): all tracks start at the same time
type 2 (asynchronous): each track is independent of the others
When creating a new file, you can select type by passing the type keyword argument, or by setting the type attribute:

mid = MidiFile(type=2)
mid.type = 1
Type 0 files must have exactly one track. A ValueError is raised if you attempt to save a file with no tracks or with more than one track.

My questions are
1. When it makes the distinction between synchronous and asynchronous tracks, does this mean synchronous means delta time 're-starts from 0' for each new track whereas asynchronous are consecutive in terms of timing? If not what does this mean?
2. If my above assumption is correct, in which situation would you use asynchronous files?
3. How does one split up tracks if type 2?

Essentially I am trying to regularise all the different ways of formatting midi files so that I can manipulate the data more easily between types. Any help with this would be appreciated.

Cheers

3
  • If you're interested in algorithmic composition, it might be better to start with an existing library and framework. If you tinker with low-level stuff like MIDI file parsing, it will take a long time to get far enough to see the forest from the trees, and you'll have lots of extra code to worry about. Every line of code written contains some percentage of bugs and problems to solve, so you should try to write as few lines of code as possible to stay focused. Maybe something like Python and music21? web.mit.edu/music21/doc/moduleReference/… Commented Dec 29, 2019 at 11:53
  • I'm using mido with python
    – staplegun
    Commented Dec 29, 2019 at 12:48
  • Ok, I thought you were making your own MIDI import library from scratch. :D Commented Dec 29, 2019 at 12:58

1 Answer 1

0
  1. asynchronous in type 2 means that each track is an independent sequence : type 2 track are not meant to be played simultaneously. This differs from type 1 where tracks are meant to be played simultaneously. In type 1, timing of each track starts at zero time. Type 1 often has a "tempo track" as first track containing all tempo information.

  2. I've not seen type 2 beeing used very often. It's just a way to store multiple sequences in a single midifile. Think of it as an archive midifile.

  3. Not meant for that.

So i think type 0 is what you need as you only have to do your split joins operation for a single track.

2
  • In an old MIDI file description, type 2 was said to contain ”patterns”, so it would be like, the song’s intro could be one pattern, verse another pattern, chorus, bridge etc each part in its own pattern. And these would be triggered on playback in some unspecified order. I think there used to be hardware sequencers that used patterns like this. Maybe even arranger keyboards. I could be wrong. In any case it’s not a very commonly used thing. Commented Dec 29, 2019 at 13:02
  • Small note: type 2 files are super super rare. Many libraries and programs even don't work with such files for this reason.
    – Maxim
    Commented Dec 29, 2019 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.