Cabbage Logo
Back to Cabbage Site

New cabbageGetWidgetChannels opcode

This opcode will return an array of widget channel names. An optional string arugment can be used to filter the widget channels, based on identifiers that have been set. This opcode runs at i-time only.

Added in Cabbage v2.6.9


SChannels[] cabbageGetWidgetChannels [SIdentifierFilter]


  • SIdentifierFiler – optional filter in the form of Cabbage identifier syntax. For example, if this is set to automatable(1), only widgets with automatable(1) will be added to the output array.

  • SChannels[] – a string array of widget channel names


form caption("Presets") size(370, 280), guiMode("queue"), colour(58, 110, 182), pluginId("MPre")
keyboard bounds(10, 90, 345, 95)
rslider bounds(12, 8, 85, 79), channel("att"), range(0, 1, 0.01), text("Att.")
rslider bounds(98, 8, 85, 79), channel("dec"), range(0, 1, 0.4), text("Dec.")
rslider bounds(184, 8, 85, 79), channel("sus"), range(0, 1, 0.7), text("Sus.")
rslider bounds(270, 8, 85, 79), channel("rel"), range(0, 1, 0.8), text("Rel.")
-n -d -+rtmidi=NULL -M0 --midi-key-cps=4 --midi-velocity-amp=5
; Initialize the global variables.
;sr is set by the host
ksmps = 32
nchnls = 2
0dbfs = 1

;instrument will be triggered by keyboard widget
instr 1
    SNames[] cabbageGetWidgetChannels "automatable(1)"
    prints "\nChannels with automatable() set to 1\n"
    printarray SNames

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

So, I’ve noticed that the list of strings returned from cabbageGetWidgetChannels is ordered by their order of creation? Is this always going to be true? If it is, then that could be used to populate a list of widget channels that can be used by an instrument, removing the need to hard-code the channels with an explicit string. This could also make it easier to write generic UDO’s for getting widget values by passing an array of channel names. It would remove the need to use sprintf to create the keys on the fly.

When I create groups of widgets, I’ll tag then with a “_obj(strkey)”, and once my widgets are created, I can the lists of channel name in looking for “_obj(strkey)”. As long as they are in creation order, I can rely on them to be in the right place in the list.

Yes, they should always be listed in the order they were created.

Exactly. Worth testing though. :rofl:

Thanks, Rory.

Well, it’s working! I used a filter to get the channel names and I saved the array to use with my instrument, and my opcode can now get the data without having to know what the actually channel names are! And keeping it in one place makes it easy to maintain. I’m planning on using this oscillator in many different configurations, but I don’t have to work about rewriting the data access!

1 Like