I'm currently programming a step sequencer. The code is pretty much by now, so I will not post the code right away. I'd rather explain everything first and would then post the appropriate portions of the code, if necessary.
By now I'm using the .read() method on the midi input to filter out the midi clock bytes. For each received clock a function is executed. In this function a counter is incremented and reset to 0 as soon as it reaches 96. Therefore I receive 96 ticks each bar. Now, my sequencer sends a Midi Note On for every 8th note (or every 12th tick). So if counter%12==0, a new Note is triggered. For now the Note Off is triggered if the counter%11==0. So I have 11 stages to adjust the Note Off. E.g.: I could send Note Off on counter%6 to reduce the gate length to about half.
Though what I want to do, is to adjust the Note Off without steps. In other words I want to have a pot controlling the gate length from 0% to 100% of the length between the note On of the corresponding Note and the Note On of the next note.
Does anyone know of any projects that had to deal with this kind of problem? Any code examples that I should look at?
At the moment I'm thinking of measuring the milliseconds between two clock ticks in order to calculate the bpm and send the midi Note Off after a given amount of milliseconds. On the other hand, this seems kind of unstable... Does anyone have a different idea on how to solve this problem?
Thanks in advance!