Sleeping during iteration over MidiFile with merged tracks #609
-
|
Hi, thanks for a very nice library. I just have a feeling, that there is a bug in examples...during the iteration over the messages of the merged tracks like this for msg in MidiFile('song.mid'):
time.sleep(msg.time)
if not msg.is_meta:
port.send(msg)You actually "sleep" on every message, but as far as I understand it, in multi-track file, it usually happens that a note is played on more tracks at exactly same time, right? So in fact, when you merge it and compute relative and absolute times, you will have more message objects with the exact same time, right? And because you are iterating these "merged" messages, then each of these "messages played at the same time" will be iterated separately...and hence, separate E.g. you have 2 tracks and both have Am I right and the example is wrong? Or am I missing something? Or is that example only for "single track" midi file? Should there be also an example for "multi track" midi files? Thanks a lot!
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Hi and thank you for your interrest in The short answer is yes and no, the provided example is fine. The long answer: First,
The example provided is a very simple and naive approach to demonstrate where relevant data are stored in the objects. It is fine for playing back MIDI files (with one or more tracks) on a single MIDI port with loose accuracy ( If you want to play back complex files with overlapping events across multiple ports and/or need precise accuracy, you’d have to write the playback engine yourself or use another tool. I may add further capabilities in Confusien may arise when iterating over type 1 and 2 Hope this helps you understand the context and use mido appropriately for your project. |
Beta Was this translation helpful? Give feedback.
Hi and thank you for your interrest in
mido.The short answer is yes and no, the provided example is fine.
The long answer:
First,
MIDIis a serial protocol which means there can’t be any overlapping messages. They all happen in sequence. Given these are sent out fast enough they give the illusion of simultaneity.It has a concept of
channelsto address specific sounds or features in the receiver.MIDI FilesstoreMIDIprotocol data with a few metadata to help presentation and/or reproduction. These have a concept oftrackswhich are not related toMIDI’schannels(Eachtrackmay contain data that adresses multiplechannels).Furthermore, 3 standard layouts are defined and commonly refere…