How do you patch true midi-in duration data.
I'm having trouble calculating the duration of a midi note into my Max For Live device.
I have a device that uses live.step, so i have a toggle to use live.steps duration, or the midi-in data's duration.
My problem is that the duration seems to be one note behind. ie the first note's duration is calculated and used for the 2nd note's duration.
To calculate the duration
I am using midiin -> midiparse -> unjoin 2 -> borax (duration count) -> makenote
I may be wrong but I’d think that’s to be expected? You’re getting duration once the note off is received so it wouldn’t be applied until the following note/step if it’s happening in real time. If you really wanted to you could probably get the clips note dictionary and dump the duration’s into a zl.lookup and cycle through that so it’s one to one, if the length of the clip/seq is the same. But then you’d have to deal with when it happens initially and keeping it updated if the clip is changed. I may be totally wrong but in my head it sounds right.
simply put, you needed to split all the different 127 midi notes onto 127 different channels in order to assign the note off event to the right note on event.
there are varios ways how to implement something like that. it is usually a good idea to track and remember only the "held notes" in one place (coll?) and use that as lookup table, which already contains the continuous time value of the note-on event.
but you could also use a poly~, limit the note amount to 24, and then measure the distance with [timer].
(for the same note number, something which only theoretically exists, it would be right to cut off both notes with a single off event, so dont worry about that.)
Sorry I should've been more specific. I'm no good with words, which is why i patch.
I'm looking for a way to substitute the duration of a midi note. I would like to substitute the duration from live.step's output to midin's output.
Is this possible?
yes, remove note offs at input
and replace with own lengths at output.
Still struggling with this,
hopefully this helps describe the situation accurately. I imagine i'm just not putting the pieces (of midi) back together correctly, or maybe not using the proper object or workflow.
My issue in Abl Live is that when the 'new' note comes through it bangs out a false note-on from the previous triggered note. You can see in the picture where D4 is incorrectly trigger before the proper note A#3, which correctly triggers a note-on/off. (This leaves D4 with no note-off)
When i try to recreate this issue in Max (see example file) I experience different issues. I have commented the example file, hopefully it just serves as insight to how my max for live device is handled. Unfortunately my m4l device is too big to untangle and share.

what i currently miss in your patch is that when you switch modes (substitute note length or not), there is nothing which stops all running notes.
@Roman
Are you referring to the other inlets of midiformat when you say "all running notes" ?
I don't really have patience to go deep into your patch,
but imagine that you can have a chance to do the following :
you have a running sequencer that outputs durations.
current duration could be applied to incoming note
by removing it's note off and applying current seq duration.
As Roman says, when you switch modes you must take care to
avoid hanging notes.
Other option as allready mentioned was to have a list with durations in advance
to solve your initial problem, that duration gets applied to next note instead of current one.
Your example patch has 2 "fake test messages" from the stepper, a Note On that starts 70 127 960 and a Note Off that starts 70 0 960. "Duration" is meaningless for messages with velocity 0, i.e. Note Off. (because Note Offs mark the end of Note Ons instantly)
Every time makenote makes a note ON message with a given duration, it automatically makes a corresponding Note Off and sends the Note Off when the input Note On duration expires. (This is why you can't use makenote to generate "control messages" to turn on an LED at Note number 70 on some midi device, for example, the LED always turns right back Off when the "Note duration" expires)
It doesn't look like you are discarding any of the Note Off messages coming out of the stepper, but when you want to replace the duration of some Note Ons coming out of the stepper (using makenote) , I think you need to discard the Note Offs makenotewill be replacing.
I think the other responders are saying at least some of this too and more...