Cabbage Logo
Back to Cabbage Site

2 instruments controlled by a slider

Im trying to create an 2 instruments. One of them is a continuous sound that has an amplitude and frequency controlled by 1 slide and the other is a 1 shot sound (that’s the easy part). The slider for the first instrument goes from 0 to 1, and when it hits 1 - it triggers the second instrument that plays a 1 shot sound (basically like a slingshot or the sound you get when you long press the like button on fb messenger).

Im trying to tackle 2 issues :

  1. when the slider gets to 1, the first instrument need to be silenced somehow, but since the slider shows 1 and is connected to amp and freq, Im thinking maybe theres a way to connect the slider to an envelope, or maybe somehow create a condition that if the slider is above 1 then amp/freq = 0.
  2. When trying to trigger the sound using an if statement ( if slider == 1 then event “i”, 2, 0, 2) I run into an issue where as long as the slider stays on 1 it keeps triggering it. I tried using “changed”, and maybe I didn’t set it up correctly but since the slider always change, I couldn’t get it to work.

any tips or advice on how to approach this?

This might get you started (you’ll need a newer version of Cabbage than 2.5.4. You can grab the latest beta build from here. Just hit the three dots on the right hand side to access the download :+1:

form caption("Untitled") size(400, 300), guiMode("queue"), pluginId("def1")
rslider bounds(16, 10, 60, 60) channel("rslider10000") range(0, 1, 0, 1, 0.001)
-n -d -+rtmidi=NULL -M0 --midi-key-cps=4 --midi-velocity-amp=5
; Initialize the global variables. 
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
    kSlider, kTrig cabbageGet "rslider10000"
    if kTrig == 1 && kSlider == 1 then
        event "i", 2, 0, 1

instr 2
    prints "Instrument started"

;causes Csound to run for about 7000 years...
i1 0 z

p.s. this can also be done using the changed opcode, just use the same idea, if slider is 1 AND changed is 1…

Interesting…Thank you so much! I’ll try it!