Well this seems to have cut the CPU usage in half (BTW, I couldn’t really set the ksmps locally: either the UDO doesn’t accept it or Csound doesn’t like that I’m passing global variables around; either way I’d get INIT errors, whether declaring inside the UDO or on the ‘GetColumn’ instr)…
opcode GetColumn, 0, iiiiiikkk
icol, irows, iposx, iposy, isize, id, kms, kmx, kmy xin
kCurrentValue init 0
if kmx > iposx+(isize*(icol-1)) && kmx < iposx+(isize*icol) && kmy > iposy && kmy < iposy+(isize*irows) then
SGButChannel sprintfk "gbut%d%d", id, icol-1
if kCurrentValue != int((kmy-iposy)/isize) then
cabbageSetValue sprintfk("g%dc%d", id, icol), int((kmy-iposy)/isize)
kCurrentValue = int((kmy-iposy)/isize)
endif
endif
kPos cabbageGetValue sprintfk("g%dc%d", id, icol)
cabbageSet 1, SGButChannel, "bounds", iposx+(isize*(icol-1)), iposy+(isize*kPos), isize, isize
endop
instr GUI
kms chnget "MOUSE_DOWN_LEFT"
kmx chnget "MOUSE_X"
kmy chnget "MOUSE_Y"
MouseGridDraw gig1cols, gig1rows, gig1size, gig1posx, gig1posy, gig1id, gig1init
cabbageSetValue "g1c1", gig1init
cabbageSetValue "g1c2", gig1init
cabbageSetValue "g1c3", gig1init
cabbageSetValue "g1c4", gig1init
cabbageSetValue "g1c5", gig1init
cabbageSetValue "g1c6", gig1init
GetColumn 1, gig1rows, gig1posx, gig1posy, gig1size, gig1id, kms, kmx, kmy
GetColumn 2, gig1rows, gig1posx, gig1posy, gig1size, gig1id, kms, kmx, kmy
GetColumn 3, gig1rows, gig1posx, gig1posy, gig1size, gig1id, kms, kmx, kmy
GetColumn 4, gig1rows, gig1posx, gig1posy, gig1size, gig1id, kms, kmx, kmy
GetColumn 5, gig1rows, gig1posx, gig1posy, gig1size, gig1id, kms, kmx, kmy
GetColumn 6, gig1rows, gig1posx, gig1posy, gig1size, gig1id, kms, kmx, kmy
endin
instr 1
kms chnget "MOUSE_DOWN_LEFT"
kmx chnget "MOUSE_X"
kmy chnget "MOUSE_Y"
if kms == 1 then
GetColumn 1, gig1rows, gig1posx, gig1posy, gig1size, gig1id, kms, kmx, kmy
GetColumn 2, gig1rows, gig1posx, gig1posy, gig1size, gig1id, kms, kmx, kmy
GetColumn 3, gig1rows, gig1posx, gig1posy, gig1size, gig1id, kms, kmx, kmy
GetColumn 4, gig1rows, gig1posx, gig1posy, gig1size, gig1id, kms, kmx, kmy
GetColumn 5, gig1rows, gig1posx, gig1posy, gig1size, gig1id, kms, kmx, kmy
GetColumn 6, gig1rows, gig1posx, gig1posy, gig1size, gig1id, kms, kmx, kmy
endif
endin
///////////////////////////////////////////////////////////// INSTRUMENTS /////////////////////////////////////////////////////////////
instr 2
kc1 cabbageGetValue "g1c1"
kc2 cabbageGetValue "g1c2"
kc3 cabbageGetValue "g1c3"
kc4 cabbageGetValue "g1c4"
kc5 cabbageGetValue "g1c5"
kc6 cabbageGetValue "g1c6"
cabbageSetValue "g2c1", kc1
cabbageSetValue "g2c2", kc2
cabbageSetValue "g2c3", kc3
cabbageSetValue "g2c4", kc4
cabbageSetValue "g2c5", kc5
cabbageSetValue "g2c6", kc6
endin
</CsInstruments>
<CsScore>
i "GUI" 0 .1
i 1 0 z
i 2 0 z