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!