recording midi chords with detonate

Florent Ghys's icon
Max Patch
Copy patch and select New From Clipboard in Max.

hi,
I am formatting a message with time, pitch, and velocity to record midi notes into a detonate object.
It's the same thing as the example in the reference file:

Everything works great as long as I play monodies but I can't find a way to make this work with chords.
I don't really understand why.
any ideas appreciated!
thanks

Florent Ghys's icon

I can't really figure this one out.
It sounds like detonate has issues playing back chords.
Pitch, velocity, and time sounds good, but durations are shorter for some reason. Sounds like detonate sends velocity 0 too fast.
Chords I am sending to detonate look like this (with duration, pitch and velocity):
1089 55 108
0 60 108
601 55 0
0 60 0

any idea?

Christopher Dobrian's icon

To use [detonate] successfully, it's crucial that you be aware of the distinction between "duration", which is how long a note sounds from note-on to note-off, and "delta time" (also known as "inter-onset interval" or "IOI"), which is the time between the onsets of events, which is to say the time elapsed since the previous event. When you're recording into [detonate] you need to provide, at a minimum, . You don't need to provide note-off information; that will be supplied by [detonate] based on the duration info you provide. So, in your example, if you're sending [detonate] three numbers to record, it's interpreting those as as you seem to expect, but it's getting no duration information so it's setting the duration of each note to 0 and thus turning each one off immediately.

broc's icon

@Christopher

On the detonate ref page there is an example showing that input of is not required (?)

Christopher Dobrian's icon

@Broc Good observation. While that example is not technically wrong, it will produce very short notes as I described (assuming no message has ever been received in the duration inlet). I can understand why the example was made that way for conciseness, but it's a little misleading.

BTW, I was incorrect that the duration of the notes will be set to 0. The reference page says "a duration of 10 milliseconds is used by default."

Florent Ghys's icon

Thanks a lot Christopher! I never really understood that distinction between delta time and duration. Now I do!
And as Broc was mentioning, the example in the reference file doesn't include a duration, and somehow works great when playing monodies and even overlapping notes. It just doesn't report the right duration when notes are too near from each others (=chords).
I made patch that measures the time between note on and note off for each pitch. A simple timer that bangs the duration out on every note off. Now my issue is when to send the information.
For example, let say I want to record 3 notes. Note 1 happens first and lasts 10 seconds. Note 2 and 3 happen right after note 1 but they last 3 and 5 seconds. In order to report the information for note 1, I need to wait until note 1 is off. But in the meanwhile notes 2 and 3 are already off.
I am getting confused here.

Does it mean I can't really record in detonate in "real-time" and somehow I'd need to record the data in a coll, and once the recording is over, re-order, and then dump into detonate?
thanks again

broc's icon

But this quote from the ref page still suggests that input is not required.

"In 3rd inlet: The velocity of the note. If the velocity is 0--indicating a note-off-- the event will be treated as the end of an earlier note-on the same key, and will determine the duration of that earlier note."

Florent Ghys's icon

yes it sounds like omitting is the simple way of using detonate, and it works great with simple monodies.
but as soon as there are notes overlapping or more complex polyphonies, detonate doesn't keep track accurately of the duration

Florent Ghys's icon

borax is the way to go

Florent Ghys's icon
Max Patch
Copy patch and select New From Clipboard in Max.

Ok so I am now trying to format a message with borax, like that:

but I guess there is an order issue. It doesn't even play the right pitches.

The issue I ran into outside of borax is that the duration that comes out of the note-off needs to be associated with the right and I can't figure out how to do that.

Florent Ghys's icon

It sounds like I should use the voice allocation number coming out of borax in order to associate the right information with the right note.I just can't make it work. I am stuck.
If someone has an idea, let me know.

Christopher Dobrian's icon

@Broc You're right. That's an alternative way.

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

It's slightly (but not overly) complicated. If there's no duration specified, and no subsequent note-off message to create a duration, then the last received duration value is used (or, if none has been received, the default is used, which appears to actually be 200 rather than 10 as stated in the manual). I did some tests to see to confirm that, and to see to what extent the manual is correct. I hope this patch will clarify.

Florent Ghys's icon
Max Patch
Copy patch and select New From Clipboard in Max.

thanks again Christopher, this is helpful
for some reason when I send the message without a duration, and with a velocity 0 later, the duration is not displayed in the detonate window, but looks fine in the text file.
As you were saying earlier, sending a and omitting the note-off seems to work much better
----
I am trying to format this kind of message from a notein and I am having a hard time. Using borax I can determine the voice allocation number, and then trigger the duration that comes with a note-off to the correct list with the corresponding note-on.
I am also keeping track of the notes' order from borax's duration count outlet.
That way I can generate a 5-element list with . These lists go into a coll.
When the recording is done, I send "sort -1 -1" to reorder the coll and dump it out to detonate.

The delta-times are not accurate, some notes are missing. What is wrong with my patch?

Florent Ghys's icon

my delta time was wrong, it was not omitting the note-off, my bad
so now it works great, thanks again Christopher

The issue I have now is that the chords I am generating sometimes contain common notes. So for example if I hold a C chord 48-52-55 for one second and then 500ms after that first chord I hold a G 50-55-59 for one second, the delta time and duration are wrong for the note 55, because there were two consecutive note-in without a note-off.
It's not an issue with detonate here, it's the voice allocation from borax that doesn't conceive that the same note can be in another voice.
Should I try to trick borax and do a custom allocation system, or is there another way around?

Christopher Dobrian's icon

1. I've done some more testing and have verified what you have observed, namely that [detonate] does not handle polyphonic MIDI input correctly. It can determine duration based on the time between note-on and note-off messages, but only if the note-off is the next event received after the note-on. If some other note-on event intervenes, then it decides that the previous note-on should be assigned the default duration instead of waiting for the note-off. In my opinion, that's a bug. I'll report it.

2. In your patch, instead of using timer to calculate the delta times, why not use the right outlet of [borax], which gives you that information for every MIDI note event, be it note-on or note-off? The advantage of doing it that way is that [borax] also gives you an identifying index number ("delta count") for the delta time, out the next-to-last outlet, so that you can associate that delta time with the correct note.

3. To construct your own messages for [detonate] consisting of , you might want to do something along the lines of the example patch shown in this thread: https://cycling74.com/forums/anyone-know-of-a-tool-for-converting-data-between-midi-format-and-coll/

4. Depending on what you want to do with the information, you might consider simply recording the data into a format 0 MIDI file with the [seq] object. The [mtr] object might also help you accomplish what you want. But it would be nice if [detonate] worked correctly...

Florent Ghys's icon

Thanks again Christopher!

1 I have noticed the same behavior as the one you're describing. Maybe it is a bug.
It would be great if that "simple" feature of detonate (= not sending the duration) would work better.

2 For some reason I needed to independently reset the timer, so that is why I didn't use the right outlet of borax.

3 Your patch looks so much better and simpler than mine! Thanks for sharing.

4 detonate works just fine with the duration parameter. So I'm good now.

all best
Florent