Cabbage Logo
Back to Cabbage Site

Dinamic MIDI Channel

Hello everybody! I was wondering if it is possible to have dynamic MIDI Channels for widgets? For example:
We have 2 channels:

  • Widget1: ChannelName -> “A”
  • Widget2: ChannelName -> “B”

And pressing “c” change the name of the channels. (This may be sent via MIDI as well or another way, IDK).

  • Widget1: ChannelName -> “C”
  • Widget2: ChannelName -> “D”

Any suggestions?

I’m not sure if you just meant to say ‘channel names’ and not ‘MIDI Channels’ in the first line of your question. MIDI channels don’t really have much direct connection with widgets.

Anyway, maybe this answers your question: you can’t change the channel name of a widget after it has been created (I don’t think) but you can overlay two widgets and toggle their visibility. Here is an example:

SwappingChannels.csd (1.0 KB)

<Cabbage>
form caption("Swap Channels") size(200, 90), colour(58, 110, 182), pluginid("def1")
rslider bounds(5,5,70,70), channel("Freq"), range(50,2000,220,0.5), text("Freq."), identchannel("FreqID")
rslider bounds(5,5,70,70), channel("Ndx"), range(0,20,5), text("Index"), identchannel("NdxID"), visible(0)
combobox items("Freq", "Index"), bounds(90, 5, 80, 30), channel("Select")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>

ksmps = 32
nchnls = 2
0dbfs = 1

giSine ftgen  0,0,4096,10,1

instr 1

; toggle visibility between two widgets
kSelect init   1
if changed:k(kSelect)==1 then
 chnset sprintfk:S("visible(%d)",1-kSelect), "FreqID"
 chnset sprintfk:S("visible(%d)",kSelect), "NdxID"
endif
kSelect chnget "Select"
kSelect -=     1



kFreq  chnget    "Freq"
kNdx   chnget    "Ndx"
aSig   foscili   0.2, kFreq, 1, 1, kNdx, giSine
       outs      aSig, aSig
endin

</CsInstruments>
<CsScore>
i 1 0 z
</CsScore>
</CsoundSynthesizer>
1 Like

Perfect, thank you. Yes I meant “channel names”, so I think i can use the toggle feature for now. BTW, the example didn’t work for me. I used the combo-box to change to “index” but it keeps showing Freq. Maybe it works but I’m wrong?

That’s weird because it works for me. Maybe @rorywalsh has a suggestion…

Works fine for me here too. @Slobodanip, can you check your audio settings. Some of the more recent versions of Cabbage had a small problem when working with sample rates of 48000, but I believe that is now fixed. Works fine for me here…

I closed everything, tried again, and it worked. Thank you!