Cabbage Logo
Back to Cabbage Site

Custom vslider question

Hello,

So I’m making a custom vertical slider, and I’m having a little problem with initializing the y-position of the visualizer. When you press the slider, it jumps up, but I’m trying to make it initialize to the same value as it jumps up to.

Does anyone have a tip to solve this?

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue") pluginId("def1")
vslider bounds(90, 125, 30, 50) channel("PitchVolume") range(0, 1, 0, 1, 0.01) trackerColour(255, 255, 255, 0) fontColour(123, 40, 40, 0) textColour(160, 160, 160, 0) colour(255, 255, 255, 0), trackerBackgroundColour(27, 32, 38, 255)

image bounds(95, 162, 6, 30), channel("PitchVolume2") mouseInteraction(0), corners(4), colour(127, 255, 127,  255)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1

kPitchVol cabbageGetValue "PitchVolume"

iBoundsPitch1[] cabbageGet "PitchVolume2", "bounds"

cabbageSet changed2(kPitchVol), "PitchVolume2", "bounds", iBoundsPitch1[0], iBoundsPitch1[1]-kPitchVol*30, 6, (iBoundsPitch1[3] - 30) + (kPitchVol*30)

endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
f0 z
;starts instrument 1 and runs it for a week
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>

Try this. More or less what you were trying, but I used a scale opcode to wrap the slider position to the length of the slider. Also note how I use a k-rate variable to trigger an update on the first cycle. This means the image will get updated straight away, without you have to click on it :+1:

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue") pluginId("def1")
vslider bounds(90, 125, 30, 150) channel("PitchVolume") range(0, 1, 1, 1, 0.01) trackerColour(255, 255, 255, 0) fontColour(123, 40, 40, 0) textColour(160, 160, 160, 0) colour(255, 255, 255, 0), trackerBackgroundColour(27, 32, 38, 255)
image bounds(95, 162, 6, 135), channel("PitchVolume2") mouseInteraction(0), corners(4), colour(127, 255, 127,  255)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d 
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
    kInit init 1
    kPitchVol cabbageGetValue "PitchVolume"
    kLength scale kPitchVol, 0, 135, 0, 1
    iBoundsPitch1[] cabbageGet "PitchVolume2", "bounds"
    cabbageSet changed2(kPitchVol)+kInit, "PitchVolume2", "bounds", iBoundsPitch1[0], iBoundsPitch1[1]+(iBoundsPitch1[3]-kLength)-30, 6, kLength
    kInit = 0
endin

</CsInstruments>
<CsScore>
f0 z
i1 0 [60*60*24*7] 
</CsScore>
</CsoundSynthesizer>
1 Like