Determining the length of a note on a track in a DAW

Good day!

I am a novice developer. I am currently developing a sampler that works with a sample library. I have different guitar samples in the sample library.

I want to add one interesting feature that could simplify the process of creating a musical part for the user.

What is the problem?

There are shorter and longer samples in the library, you can choose between them using the velocity value (for example, 127 is a long sound, 126 is a short sound). The user, working in DAW, can create notes of different sizes on the track, but if the note duration in piano roll exceeds the duration of the sample, then the sample sound will be played only up to a certain part of the drawn note, and in order to fix this, the user will have to change the velocity value to one that corresponds to a long sound.

What I want to do:

I want to find out the duration of the notes, and if the duration of the note prescribed in the piano roll is longer than the duration of the short sample, then the velocity value will change to the one that corresponds to the long sample.

What was I trying to do?

I don’t know why, but I was trying to catch MidiMessage. To do this, I wrote a function that, with NoteOn, recorded the value of a note and its position, and with NoteOff, found a note in the array, and recorded the position in map when the note ended. And obviously, if you subtract the initial time from the final time, you get the duration. I don’t know how much it was the right decision, but as a result, the plugin stopped playing anything written on the audio track in Cubase.

And the idea itself is questionable, because everything described above happens in real time, accordingly, I cannot find out its duration until the note is fully played, even if the algorithm above would work correctly.

What can I try in this case? Maybe someone has faced similar problems? I will be glad to read your suggestions and advice.

Thanks!

Sounds like you have no choice but to have a record/analyze step that is run first, where you record in the MIDI data, and after stopping the transport your code would select sounds for each note. But is even a “long” note always going to be long enough? What should happen in that case?

Alternatively, can you simply loop over the sample until you reach the Note Off, instead of changing between short and long samples? When it reaches the end, if the NoteOff has not arrived yet, loop back to the start of the sample?

You could just report some latency, like 1sec, and then declare that as the max possible duration. then do the thing you already did where you keep track of note lengths to define which sample is selected for an upcoming voice’s playback. then delay the midi by your latency before running the voices so they play where it would be expected. beware not all DAWs can add negative delay to midi inputs, so make sure to test that first.

alternatively you could change your design choice to offer a plugin internal piano roll. with such a feature you could skip all the complexity in regard to latency handling

Or you need to fix your sample to behave more properly, handle the note off and have release trigger samples to mimic what is happening on a real guitar.

2 Likes

Thanks for your reply.

Perhaps your solution is correct, but it is perceived as a certain “dirty hack”, which in some way kills the meaning of this feature, because after each change in the drawing in the piano roll, you will have to “record and analyze”, and instead of automation you will get a routine.

It was probably a mistake on my part to call the samples “short and long”, since a long sample is just a fully recorded extracted sound from the guitar before its lull. The short sample is about 1 second, the long one is 8 seconds, and there is still a very long 16 seconds. A short sample can be said to end abruptly, and a long one plays out until a complete lull. The user can draw any note in a piano roll, and, of course, it will not sound longer than it would on a real guitar in a DAW.

I wouldn’t say that it was a bad idea perse though. it might not suit your guitar context perfectly well but for example i always had the vision to have a note length modulator in a synthesizer, for example for automatic vibrato on emphasized notes. latency is only a problem for monitoring. for normal playback i wouldn’t call it a hack