Report MIDI Note Duration at NoteOn (non real-time)
Hi,
I'm making a sample player in Max for Live and I need to trigger it using MIDI editor in Live (edit: MIDI notes have already been recorded, so I'm not doing this in real time). I'm using [notein] to report pitch and velocity, however, I need to report note duration as well. I need this to set the total duration for the volume envelope. I used [borax] but it gives me the duration at note off. How can I get the MIDI note duration when the sample is triggered (note on).
Thanks,
Suren
Can you explain better? The duration is measured between note on and off. You cant get it at note on. You can maybe set it and ignore the note off like a oneshot playmode.
Hi 11olsen,
Thank you for your reply. I need to trigger a sample in a Max patch using MIDI in live. I need three information from MIDI notes: Velocity, duration and note on. Note on will trigger the sample while velocity and note duration will shape a volume envelope for playback - velocity is my sustain and duration is the total ramp time for ~line. I set the attack and release inside the patch.
I need the duration to avoid clicks in playback as I'm not in poly mode. If I only use the note on I would get clicks when the MIDI note duration is less than sample's total time.
I've underlined the MIDI information that I need:

Duration is measured as the time between reception of a NoteOn and it’s corresponding NoteOff.
There is no way to know the duration of a note until you have seen the noteoff event. By definition! That’s how MIDI works.
Ok, I found this in the LOM section of the reference:

This assumes that both NoteOn and NoteOff events have been seen. Fine, if you’re working with something already recorded But won’t work in real-time.
Yea that's right. I'm only working with pre-recorded MIDI. Reporting duration at NoteOn in real-time doesn't make sense :)
Added this to the title as well.
Well, I don't know anything about Live but a trivial google search for "Live get_selected_notes" turns up the following from 5 years ago on this forum
https://cycling74.com/forums/help-with-m4l-javascript-and-get_selected_notes
Looks like that function returns a sequence of items where each item contains information about each note found in the selection, including the duration)
Cool, thanks. That seems to be a way of doing this, but I think I'd stick to using only Max objects this time... Don't know anything about Javascript :P
once, i also really wanted to know about the OP's question, until i realized it would be pointless for live situations. so i never really looked into it.
however, if your only concern is the clicks, then you could use an extra [~line 1. 0. 2?] after the amp_env, triggered by note on's, which will work as a snappy fade-out when note retriggered before end.
you say it's for a sampler, if however you plan to use this for synths as well, make sure that note-on's retrigger the phase of the OSC (if you want consistent phase start with each note)