Cabbage Logo
Back to Cabbage Site

Mouse Grid

I found a slight mistake in the overlay, it should be this instead (using left/top coordinates instead):

    SCode = sprintf("bounds(%d, %d, %d, %d), channel(\"overlay%d\"), colour(0, 0, 0, 100)", iLeft, iTop, iSize*iCols, iSize*iRows, iId) 
    cabbageCreate "image", SCode
1 Like

Ok!

Haha! Ok :wink:

Yes! It’s a new discovery for me, p5.js. It’s a great way to learn programming as you can map things visually quite easily! Will look into generating ‘proper’ filmstrips as well (not just quantized to a small number but to give the full range to each slider). Have you found some ‘magic’ number of frames to use? Is using MIDI resolution (127 frames) an OK amount or is that overkill (I noticed in some examples there were as much as 30 or so frames for ea. filmstrip image).

Thanks! Yes, agreed! I also did a quick test exporting these to a VST/AU and both: a) having a straight ‘filmstrip’ slider and b) implementing the mouse polling had the same 1-2% dent on the DAW’s CPU meter (running Live on a 2015 Mac laptop).

As to the Monome idea, it sounds like a great plan! But first, I want to start building instruments for the Sensel/Thunder (I started with a M4L MIDI device but I’m thinking more and more of building various sound engines myself on Csound/Cabbage –– perhaps implementing some kind of OSC send/receive protocol to send slider data to other plugins etc. –– I’ve found MIDI implementation for VST/AU quite fuzzy on potentially limiting, this rather from the DAWs point of view –– it seems to me they each impose their own rules about it). For those using the Sensel or if you’re curious, you can check out this video, which documents that work :slight_smile:

I think size is the only real limitation here. The bigger they are the more memory they take up. Note that the number of frames doesn’t affect the slider resolution. It will still move in the smallest possible increments even if the frame has not updated.

The Sensel is really nice. I wish it had been around when I first started messing with MIDI controllers :frowning:

1 Like

Nice. That was the real question to ask :slight_smile: thanks for the answer!

Yes, I’m excited to explore its possibilities –– and those of Csound: it seems to me that the two together are quite a match!

Sorry: as I started implementing these I found more mistakes. Here are the UDOs updated:

opcode GridDraw, 0, iiiiii
    iSize, iCols, iRows, iLeft, iTop, iId    xin
    
    iCount  init    0

    while iCount < iCols do
        SCode   sprintf "bounds(%d, %d, %d, %d) channel(\"g%dc%d\") range(0, %d, 0, 1, 1), filmstrip(\"vGridSlider%d.png\", %d, valueTextBox(\"0\"), popup(\"0\")", iCount*iSize+iLeft, iTop, iSize, iSize*iRows, iId, iCount+1, iRows-1, iRows, iRows
        cabbageCreate "vslider", SCode
        iCount+=1
    od
    
    SCode = sprintf("bounds(%d, %d, %d, %d), channel(\"overlay%d\"), colour(0, 0, 0, 100)", iLeft, iTop, iSize*iCols, iSize*iRows, iId) 
    cabbageCreate "image", SCode
endop

opcode GridCtl, 0, iiii
    iSize, iCols, iRows, iId    xin
    
    kMouseDown  chnget "MOUSE_DOWN_LEFT"
    kMouseX     chnget "MOUSE_X"
    kMouseY     chnget "MOUSE_Y"
    
    SOverlay    sprintf "overlay%d", iId
   
    iOverlay[]  cabbageGet SOverlay, "bounds" 
    iLeft       = iOverlay[0]
    iTop        = iOverlay[1]
    iWidth      = iOverlay[2]
    iHeight     = iOverlay[3] 
   
    if (kMouseX > iLeft && kMouseX < iLeft+iWidth && kMouseY > iTop && kMouseY < iTop + iHeight) then
        kColumn = int(((kMouseX - iLeft) / iSize) + 1)
        kVal    = int(((kMouseY - iTop) * -iRows / iHeight) + iRows)
        
        if kMouseDown == 1 then
            SChannel = sprintfk("g%dc%d", iId, kColumn)
            cabbageSetValue SChannel, kVal
        endif
    endif
endop
1 Like