Oh, i did not know i can sleep for fraction of beat!
Well, as time in MIDI world is discrete i thought it would be wise to timestamp all events in ticks not in real time from the very beginning.
So instead of calculating corresponding tick for every event, i would know that events read in tick n belong to tick n-1 . I know i`m losing precision in time domain using this discretization, but i want to quantize events further into steps…
I`m trying to make something called “retrospective looper” - instead of regular mode of recording - “rec - perfom - loop” it would record always into kind of ring buffer and after pressing a button it would loop last x bars. Of course i want to hear what notes are being played maybe already quantized to steps in real time.
So with clock ticking at 24 ticks per beat i would something like this at each tick :
- read buffered midi messages (note ons, offs)
- write these events into record buffer at current_tick position, clear position if nothing was read
- write these events into play buffer into “next step” position ( (tick/6+1)*ticksPerStep - 1/16t quantization)
- send midi events from play buffer at this position
running this with clock ticking 24 times per beat and resetting after let`s say 384 ticks you would have 4 bar loop with overdubbing and quantization to sixteenth notes / steps . if play buffer position is cleared after playing it, you would get something like real-time quantization. played notes would “sound” on next step , (in real world it is needed to place note-off one step further if on-off happens inside one step)
now consider player is feeding the recording buffer with notes (overwritten each 4 bars), hearing quantized notes from play buffer and metronome, after multiple 2-bar takes he decides that the last 2-bars were nice, stops playing and hits “loop” button. boundaries for last 2-bars are calculated and part of the record buffer is copied into sequence (quantized), this sequence is then used to fill play buffer for corresponding ticks. i know that in this case only positions at steps (ticks mod 6 = 0 ) are really used , but consider having this also for unquantized CCs.