Cabbage Logo
Back to Cabbage Site

Chnset and Svariable

Hello,
Using OSC,I found out that chnset does not accept the name of the channel inside a Svariable:

Smessage sprintfk "value(%d)", kValue
chnset Smessage, "ComboBox_receive"

works great

but the following does not work even if Csound seems to recognize the channel. Not adding the " creates an error with the channel name.

Smessage sprintfk "value(%d)" , kValue
SchannelName sprintfk "\"%s\"","ComboBox_receive"
chnset Smessage,SchannelName

Could someone explain me why ? Or is this a bug ?

This should work, but you don’t need the extra "s. I use this approach quite a lot. Once again I wish I had access to a pc to test it. What’s the error when you do:
Sthing sprintfk "%s", "channelName"
That should work?

My problem is that “channelname” is contained by a Svariable. The aim is to make a

chnset kVal, Svar

and I cannot make an explicit reference to “channelname”. The error is :

I receive invalid channel name:

SECTION 1:
INIT ERROR in instr 1: invalid channel name
chnset.k kValue SM
B 0.000 - note deleted. i2 had 1 init errors

Here is the full code… which is trivial

Python

import OSC
c = OSC.OSCClient()
c.connect(('127.0.0.1', 57290))   # localhost, port 57120
oscmsg = OSC.OSCMessage()
oscmsg.setAddress("/mysynth")
oscmsg.append("combobox")
oscmsg.append(5)
c.send(oscmsg)

and Cabbage Csound

<Cabbage>
form caption("Untitled") size(400, 300), colour(58, 110, 182), pluginID("def1")
combobox bounds(65, 18, 100, 30), channel("combobox"), identchannel("comboboxR"),items("Item 1", "Item 2", "Item 3","Item $", "Item5")
</Cabbage>
<CsoundSynthesizer>
<CsOptions>
-n -d -+rtmidi=NULL -M0 -m0d --midi-key-cps=4 --midi-velocity-amp=5
</CsOptions>
<CsInstruments>
; Initialize the global variables. 
sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

giOsc OSCinit 57290
instr 1 
SMessage init ""
kValue init 0
kValue = 0
kFlag OSClisten giOsc,"/mysynth","si",SMessage,kValue
if (kFlag==0)  goto ex
	printf "%d    %s \n",kFlag, kValue, SMessage
	SM sprintf "%s",SMessage
	chnset kValue,SM
ex:
endin

</CsInstruments>
<CsScore>
f 0 z
i1 0 3600
</CsScore>
</CsoundSynthesizer>

Print the value of SMessage and see what it is. Channel can only be alphanumeric afaik…

Found the bug !!

It is simply that Csound +cabbage do not accept an empty string for the init.

Smessage init ""

The string must not be empty. The problem does not seem to be in the channels themselves. A

Smessage init “void”`

solves the problem. 9even if there is no channel named “void”. I think this is Csound bug or at least a very weird non logical behaviour :slight_smile:
I hope this .wlll help other users.

Do you get an error from Csound when you try to init a string with “”?

Channel. Yes. Error on the invalid channel . See first post.

Then I imagine it’s not a bug but intended behavior?

:slight_smile: Well you are right, it seems to be an intended behaviour but honestly, completely weird.
Why should it not be possible to init a string as an empty one ?

Anyway, as long as it is solved… I am looking forward to downloading the next cabbage beta version with the OSC dll .

I think that’s not it. You can init a string with “”. But what you can’t do is chnset to a channel called “”.

@gsenna you’re right in your assessment. Thanks for clearing this up :wink: