Cabbage Logo
Back to Cabbage Site

Delay Midi Notes

Can you try this one? It’s rewritten slightly using a different approach and opcodes:

<Cabbage> bounds(0, 0, 0, 0)
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginid("midO")
keyboard bounds(8, 158, 381, 95)
rslider bounds(74, 28, 60, 60) range(0, 1, 0, 1, 0.001),channel("DelNoteOne")
rslider bounds(148, 28, 60, 60) range(0, 1, 0, 1, 0.001),channel("DelNoteTwo")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-dm0 -n -+rtmidi=NULL -M0 -Q0 --midi-key=4 --midi-velocity=5
</CsOptions>
<CsInstruments>
ksmps = 32
nchnls = 2
0dbfs = 1

giChan = 0

instr 1 ;Triggered by MIDI notes on channel 1
    
    ifund notnum
    ivel  veloc
    
    iDelayTimeOne chnget "DelNoteOne"
    iDelayTimeTwo chnget "DelNoteTwo"
                          
    kTrig init 1
    schedkwhen delayk(kTrig,iDelayTimeOne), 0, 0, 200, 0, 1, giChan, ifund, ivel, 143
    schedkwhen delayk(kTrig,iDelayTimeTwo), 0, 0, 200, 0, 1, giChan, ifund+10, ivel, 143 
    kTrig = 0    
                   
    schedkwhen release:k(), 0, 0, 200, 0, 1, giChan, ifund, 0, 127
    schedkwhen release:k(), 0, 0, 200, 0, 1, giChan, ifund+10, 0, 127
    
    giChan  wrap  giChan + 1, 1, 17
endin

instr 200
    midiout p7+p4, p4, p5, p6
    turnoff
endin

</CsInstruments>
<CsScore>
f0 z
</CsScore>
</CsoundSynthesizer>

@iainmccurdy I tried your latest code and I have the same time problems. I found that if you press more than one note, the notes get stuck (they hold). I do not feel any difference with “giChan wrap giChan + 1, 1, 17” multiple channels and without it, therefore, here the best option for me. But I would like to find a good accurate solution. You are helping me a lot, thank you very much.

<Cabbage> bounds(0, 0, 0, 0)
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginid("midO")
keyboard bounds(8, 158, 381, 95)
rslider bounds(74, 28, 60, 60) range(0.0, 1, 0.0, 1, 0.0001),channel("DelNoteOne")
rslider bounds(148, 28, 60, 60) range(0.0, 1, 0.0, 1, 0.0001),channel("DelNoteTwo")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-dm0 -n -+rtmidi=NULL -M0 -Q0 --midi-key=4 --midi-velocity=5
</CsOptions>
<CsInstruments>
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1 ;Triggered by MIDI notes on channel 1
    
    ifund notnum
    ivel  veloc
    irand = rnd(100)/100
    
    iDelayTimeOne chnget "DelNoteOne"
    iDelayTimeTwo chnget "DelNoteTwo"
    
    kTrig init 1
    schedkwhen delayk(kTrig,iDelayTimeOne+0.008),0,0,200+irand, 0, -1, ifund, ivel
    schedkwhen delayk(kTrig,iDelayTimeTwo+0.008),0,0,210+irand, 0, -1, ifund, ivel 
    kTrig = 0    
                 
    kRel release
    if kRel == 1 && changed(kRel) == 1 then
        event "i", -1*(200+irand), 0, -1, ifund, ivel
        event "i", -1*(210+irand), 0, -1, ifund, ivel 
    endif
        
endin

instr 200                         
    midion 1, p4, p5 
endin

instr 210
    midion 1, p4+10, p5 
endin

</CsInstruments>
<CsScore>
f0 z
</CsScore>
</CsoundSynthesizer>`

I took out the sub-instrument calls which should simplify timing. I tested this in AudioMulch playing repeated notes as fast as humanly possible as well as playing all notes of the keyboard at once and I’m not able to produce stuck or missing notes. Seems pretty stable for me :slight_smile:

<Cabbage> bounds(0, 0, 0, 0)
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginid("midO")
keyboard bounds(8, 158, 381, 95)
rslider bounds(74, 28, 60, 60) range(0, 1, 0, 1, 0.001),channel("DelNoteOne")
rslider bounds(148, 28, 60, 60) range(0, 1, 0, 1, 0.001),channel("DelNoteTwo")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-dm0 -n -+rtmidi=NULL -M0 -Q0 --midi-key=4 --midi-velocity=5
</CsOptions>
<CsInstruments>

ksmps = 32
nchnls = 2
0dbfs = 1

instr 1 ;Triggered by MIDI notes on channel 1
    
    ifund notnum
    ivel  veloc
    
    iDelayTimeOne chnget "DelNoteOne"
    iDelayTimeTwo chnget "DelNoteTwo"
                          
    kTrig init 1
    if (delayk(kTrig,iDelayTimeOne)==1) then
     midiout 144, 1, ifund, ivel    
    endif
    if (delayk(kTrig,iDelayTimeTwo)==1) then
     midiout 144, 1, ifund+10, ivel    
    endif
    kTrig = 0    

    if (release:k()==1) then
     midiout 128, 1, ifund, 0    
     midiout 128, 1, ifund+10, 0    
    endif
    
endin

</CsInstruments>
<CsScore>
f0 z
</CsScore>
</CsoundSynthesizer>
1 Like

Now it’s working much better! no more stuck notes :slight_smile: Just One more thing … and I do not know if I’m trying to go too far … when I re-sampled the notes in a new midi clip, the notes are not completely in the correct position, I tested in Ableton and Cubase and they have the same problem. It is a minimal and not dramatic problem, but you may have an idea of ​​how could I adjust it? Thanks!

Are they consistently out of position? Like is each and every notes a fixed amount out of position?

Sorry, I just took a closer look at the video and can see better now what you’re referring to. Can you try setting ksmps to 1 and running it again?

I tested with 1 ksmps and it works just like in the last video I shared. Each note I have re-sampled is in a different position, it is really minimal.

It’s hard to tell from the video, but is each note offset by the same amount, or does the re-positioning appear random?

does the re-positioning appear random?

Yes. It´s a really minimal difference. Some notes are close to the grid and others no…

I guess in this case, the simplest thing to do would be to set the quantisation on the track your are sending the notes to, so that each note starts get repositioned to the correct snap point. That should work or? It’s odd that there is this random re-positioning. I wonder if it only happens with Live?

O yes! Quantize notes is a good solution, but if I can accurate more without quantizing would be perfect. The same problem is happend in cubase too. I guess at this point it’s the best I can have and it’s fine… But if anyone find a solution for this, it will more than welcome.
Thanks for your help @rorywalsh and @iainmccurdy!

I’m not really sure what might be causing it. The fact that they appear somewhat random is odd. I would have expected all notes to be out of sync in the same way. Perhaps @iainmccurdy has some ideas about why this is happening?