# 2 instruments controlled by a slider

**URL:** <https://forum.cabbageaudio.com/t/2-instruments-controlled-by-a-slider/3373>\
**Category:** Csound Noobs\
**Created:** [18 August 2022 13:45 UTC](https://forum.cabbageaudio.com/t/2-instruments-controlled-by-a-slider/3373 "2022-08-18T13:45:34Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sh\_Dev](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@Sh\_Dev](https://forum.cabbageaudio.com/u/Sh_Dev)\
**Post date:** [18 August 2022 13:45 UTC](https://forum.cabbageaudio.com/t/2-instruments-controlled-by-a-slider/3373/1 "2022-08-18T13:45:34Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![rorywalsh](https://forum.cabbageaudio.com/user_avatar/forum.cabbageaudio.com/rorywalsh/32/165_2.png) [@rorywalsh](https://forum.cabbageaudio.com/u/rorywalsh)\
**Post date:** [18 August 2022 17:34 UTC](https://forum.cabbageaudio.com/t/2-instruments-controlled-by-a-slider/3373/2 "2022-08-18T17:34:57Z")

</div>

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](https://dev.azure.com/rorywalsh/cabbage/_build/results?buildId=2425&view=artifacts&pathAsName=false&type=publishedArtifacts). Just hit the three dots on the right hand side to access the download 👍

```
<Cabbage>
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)
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; 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
    endif
endin

instr 2
    prints "Instrument started"
endin

</CsInstruments>
<CsScore>
;causes Csound to run for about 7000 years...
i1 0 z
</CsScore>
</CsoundSynthesizer>

```

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

---

<div class="post-metadata">

**Author:** ![Sh\_Dev](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/s/fbc32d/32.png) [@Sh\_Dev](https://forum.cabbageaudio.com/u/Sh_Dev)\
**Post date:** [18 August 2022 18:05 UTC](https://forum.cabbageaudio.com/t/2-instruments-controlled-by-a-slider/3373/3 "2022-08-18T18:05:58Z")

</div>

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