How to know SimpleMIDIFile (or Ppar) duration

Is there a way to know how long a SimpleMIDIFile will play for when used as:

m = SimpleMIDIFile.read(path);
m.p.play;

As you may very well know, the .p method turns the SimpleMIDIFile into a Ppar, so checking how long that would play for would also be a great help!

Thanks!

T

Don’t know about SimpleMIDIFile, but I seem to recall that determining the duration of pattern came up a while ago and there was no definitive answer/it was deemed to complex.

Events in a MIDI file are timestamped, so the latest timestamp in the file should be the figure you need.

hjh

Hi, here is how to find out the duration of a SimpleMIDIFile:

m.timeMode = \seconds;
m.length; // returns the duration in seconds

If timeMode is not ‘seconds’ it defaults to ‘ticks’, and then the .length returns the duration in ticks. Note that in some cases the endOfTrack message in MIDIFiles can be incorrect, which will also cause .length to give an incorrect result. In such cases it can help to call:

m.adjustEndOfTrack;

and then .length again,

3 Likes