Cabbage Logo
Back to Cabbage Site

Problems with cabbageSet on image bounds

Hello, I have a issue with setting the bounds position with cabbageSet (in the if-statement).

Am I doing something wrong?

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue") pluginId("def1")

;;;;;;;;;;;;;;;;;;;;;
;Graphical envelope
;;;;;;;;;;;;;;;;;;;;;

;Background
image bounds(1, 1, 160, 120) channel("Background")

;Points
image bounds(118, 80, 19, 23) channel("PointOne") colour(255, 0, 0, 255)

</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1

;Mouse position and clicks
kPosX cabbageGet "MOUSE_X"
kPosY cabbageGet "MOUSE_Y"
kMouseDown cabbageGet "MOUSE_DOWN_LEFT"

;Background position and size
iBounds[] cabbageGet "Background", "bounds"
iBoundsPosX = iBounds[0]
iBoundsPosY = iBounds[1]
iBoundsSizeX = iBounds[2]
iBoundsSizeY = iBounds[3]

if kMouseDown == 1 then
    cabbageSet "PointOne", "bounds", kPosX, kPosY, 10, 10
endif

endin

</CsInstruments>
<CsScore>
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

That’s because you are calling cabbageSet at i-rate. Try this instead:

;if kMouseDown == 1 then
    cabbageSet kMouseDown, "PointOne", "bounds", kPosX, kPosY, 10, 10
;endif

I find myself constantly looking at the syntax hints in the status bar when it comes to these opcodes. Otherwise it can be a little confusing at to which run at i-time. If you don’t have a trigger with cabbageSet it will always run at i-time.

Thanks, I also see I overlooked that in the docs. Is this the same for cabbageGet? If you “get” the channel data without a trigger, it will run at i-rate? Couldn’t find out on the docs page

If used at perf-time you must pass a trigger signal as the first argument. What is perf-time?

First comes init-time, then perf-time. More details here.