Hello,
I’m testing out some things, and I was wondering if anyone has any tips on how I could temporarily freeze the value of a variable (kGain_2) when changing a slider. As soon as I stop changing the parameter, I want it to jump back to the correct value.
Something like this, but I can’t get it to work:
<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue") pluginId("def1")
rslider bounds(296, 162, 100, 100), channel("gain"), range(0, 1, 0, 1, .01), text("Gain"), trackerColour("lime"), outlineColour(0, 0, 0, 50), textColour("black")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d
</CsOptions>
<CsInstruments>
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1
instr 1
kGain, kGainTrig cabbageGetValue "gain"
kGain_2 init 0.5
if changed2(kGain) == 1 then
kGain_2 = kGain_2
else
kGain_2 = kGain
endif
printk2 kGain_2
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>
Maybe something like this?
iFreeze = 0.5
kGainIN portk cabbageGetValue:k("gain"), 0.01
if changed2:k(kGainIN)==1 then
kGain = iFreeze
else
kGain = kGainIN
endif
Thanks, it is close, but I am trying to make iFreeze a k-rate that stores the value of kGainIN right before adjusting the slider: If kGainIN is 0.7, and you start rotating the slider from 0.7 to 0.3, iFreeze (but k-rate) stores 0.7 until you stop adjusting the slider, then it would switch to 0.3.
Maybe this will do in that case? I don’t know if there is a more elegant way of doing this without using portk?
kSliderIN = cabbageGetValue:k("slider1")
kSliderIN portk kSliderIN, 0.01
if changed2:k(kSliderIN)==0 then
kSlider = kSliderIN
endif
1 Like
You cracked the code! This is a nice way to do it, thank you very much! 
Here’s the code for people from the future!
<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue") pluginId("def1")
rslider bounds(296, 162, 100, 100), channel("gain"), range(0, 1, 0, 1, .01), text("Gain"), trackerColour("lime"), outlineColour(0, 0, 0, 50), textColour("black")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d
</CsOptions>
<CsInstruments>
; Initialize the global variables.
ksmps = 32
nchnls = 2
0dbfs = 1
instr 1
kGain, kGainTrig cabbageGetValue "gain"
kGain portk kGain, 0.01
if changed2:k(kGain)==0 then
kGain_2 = kGain
endif
printk2 kGain_2
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>
This is the second thread I’ve looked at today that someone else has answered. What’s going on around here
I’ll have to roll back on my 8 hours sleep! 
No no! Your sleep is of value to us! 
1 Like