length of a MIDI sequence

Floating Point's icon

trawling through the documentation, there doesn't seem to be a simple way of determining the length of a MIDI sequence before it's actually played, neither through seq nor detonate.

The only way I can think of doing it is to keep sending an incremented nth message to a loaded file in detonate until the accumulated delta times stop changing, but this seems clumsy to me (ie delta time is zero for simultaneous notes, so there's no reliable way to tell the sequence has actually ended) Anyone got another way to do this??
thanks,
T

Floating Point's icon

Well here's a patch to show what I'm going on about. I'm using the -1 end of sequence flag to stop the process, but it still is pretty clumsy imo.

Question: is there an easier way?

Max Patch
Copy patch and select New From Clipboard in Max.

Dan Nigrin's icon

I don't think there's a way around this - the MIDI file format
doesn't specify the length of a sequence (at least in ticks or bars
or whatever) at the beginning of a file. I'd be happy to be told
otherwise though, as I am struggling with a related problem at the
moment as well..

What you *can* count on is the Meta Event "End of Track" (decimal 47,
hex 0x2F) to tell when the track is over, but that's it.... See
http://www.sonicspot.com/guide/midifiles.html

Dan

At 1:13 PM +1000 9/11/08, Terry McDermott wrote:
>trawling through the documentation, there doesn't seem to be a
>simple way of determining the length of a MIDI sequence before it's
>actually played, neither through seq nor detonate.
>
>The only way I can think of doing it is to keep sending an
>incremented nth message to a loaded file in detonate until the
>accumulated delta times stop changing, but this seems clumsy to me
>(ie delta time is zero for simultaneous notes, so there's no
>reliable way to tell the sequence has actually ended) Anyone got
>another way to do this??
>thanks,
>T

--
Dan Nigrin - Defective Records
202 Hack / PC-1600 User / VSTi Host / Jack OS X / Major Malfunction
http://defectiverecords.com
http://jackosx.com

Floating Point's icon

Hmmm,
yep, of course, they're all delta ticks in a midi file, so even if seq or detonate had that feature it would still have to open it , 'play' it through and add all the delta times up at the end, it seems. crazy.
thanks for the advice
T

grigou's icon

Hello,

I have the same problem.

I want to load a midi file in a multislider and then, play it in loop. I use detonate, but it can't give me the correct length of a midi sequence if the last event is a rest.

For example, if I load a file with 1 measure in 4/4 with 4 quarter notes, everything is ok.

Then, I load a file with 1 measure in 4/4 with 3 quarter notes and a quarter rest at the end. In this case, the first output (time) of detonate gives me the message -1 when it plays the third quarter note, so it doesn't take care if there's rest or not after this quarter note. So it gives me a wrong midi file duration, because it considers that my sequence is like a 3/4 measure instead of a 4/4 measure.

I also tried with the jit.qt.movie object, but it's the same problem.
For my file with 4 quarter notes at 60 bpm, it gives me a duration of 4 seconds. But for my file with the rest at the end, it gives me a duration of 3 secondes instead of 4 seconds.

Is there a way to know the correct length when there's rest at the end of a midi sequence ?

By the way, I search a way to do this without external objects or scripts.

Thanks for the help.

Dan Nigrin's icon

As I mentioned above - this is not a bug, it's just the way MIDI files work; they're not based on musical measures or anything. So after the last note is done playing, the file just ends.

Take a look at the documentation for my MC-202 or MC-4 Hack programs:

They illustrate graphically what is happening.

So for your case, you need to keep track of beats/bars/whatever, and then you need to manually "pad" the midi file (with a silent note, velocity 0) to complete the bar.

grigou's icon

Great, now I understand the problem !

So, I have to add this silent note with max or in my score editor (Sibelius, Finale, etc.) ?

Dan Nigrin's icon

Yes, exactly.

broc's icon

As I understand it you want the length quantized to bars (regardless how many notes are in the last bar).

So you could do this

1. find the number of bars, ie. divide the calculated length by the length of 1 bar (with float result R)
2. find the smallest following integer ("ceiling") of R (with result N).
3. Multiply N with the length of 1 bar.

grigou's icon

@Dan Nigrin : I tried, but it doesn't work for me.

I created 1 measure in 4/4 with 4 quarter notes with a velocity set to 0 for the last quarter note. When I import my midi file in the detonate, it gives me only the first three quarter notes but not the last one, as if it's a rest.

But, if I set the velocity to 1 for the last quarter note, it gives me the four quarter notes.

grigou's icon

broc, I don't see what you mean by divide the calculated length.

I wonder also if it works with different time signatures in the same midi file, like beginning in 4/4, then in 6/8, then in 2/4, and so on.

broc's icon

With 'calculated length' I mean the length you calculate from the notes, for example with detonate.

But obviously, my method will not work with different time signatures in the same file.