Cabbage Logo
Back to Cabbage Site

User input strings for OSCsend

From Cabbage plugin I’m sending OSC with
OSCsend kwhen, ihost, iport, idestination[, itype , xdata1, xdata2, ...]

I’d like to get user input strings for, e.g. host, port, destination.
I guess I could reinit the OSCsend opcode, but I’d need to get the strings in somehow.

Using texteditor seems an option, but I need to rewrite the string for example “localhost” to “192.168.1.42” and back. It would be nice to have “localhost” always there ready to be selected and the ability to modify the IP address, add a new one, switch between them, maybe having a history of strings ready to be selected, updated, with the ability to clear items and having the list saved within plugin so it loads automatically.

Perhaps it would be useful to have something like editable listbox, or selectively enter string lines from texteditor?

I might be missing something with the mentioned widgets. Is it possible to do something like that?
Any suggestions how to handle such case?

Can you not add that to the string the texteditor returns before sending it as an OSC message??

I’m trying to change the settings of the OSCsend opcode not to send OSC directly from texteditor.
I can change one string in texteditor, but could I have several strings and selectively send them?
Any alternatives to achieve simple user editable destination for OSC?

When it comes to the IP address I think reinit is your only option, or an event opcode to kill and start a new instance of the sending instrument. You can press up and down in the test editor to bring up the previous strings. It has a history, but this is wiped each time you restart the instrument. You could combine a listbox with the text editor?

Thanks for the suggestions!
Do I get it right that texteditor cannot selectively send strings, or can it send individual lines?
Do you think I’d be able to add listbox items by getting input from texteditor and would these items be saved for the next session after restarting the instrument? This is obviously interesting beyond the scope of OSC sending.

It sends individual lines each time you hit return.

You could populate a listbox from a file on disk, which could contain the IP address and commands you wish to use?

Hmmm… on MacOS, I have to hit cmd+enter and then texteditor send all lines not individual lines (same as right clicking and selecting send text).

I’m trying to change listbox items at k-rate. Possible?
The listbox example crashes Cabbage 2.8.121.

Is your texteditor set to multiline? It shouldn’t be?

Thanks I’ll take a look tomorrow.

Thanks! I see that by setting wrap(0) I can hit Enter on texteditor to pass 1 string.
But in multiline (wrap(1) ), cmd+Enter passes ALL strings. So, I suppose it is not possible to pass selected strings?

With listbox I could load items from file and maybe(?) change items like you show here: Combobox vs Listbox Dynamicism
The “problem” with that is a fixed length array of item strings.
Is there a simple way to change, append and delete items/lines in a text file? I think it is easy with numbers but it seems complicated with strings.

You know you can append items to a combobox using cabbageSet, IF the combobox string channel types? Check this example, it dynamically changes the items in the combobox:

<Cabbage>
form caption("Untitled") size(400, 300), guiMode("queue"), pluginId("def1")
keyboard bounds(8, 158, 381, 95)
combobox bounds(20, 24, 160, 30) channel("combo1"), channelType("string")
</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

giNoteCounter init 0
;instrument will be triggered by keyboard widget
instr 1
    cabbageSet "combo1", {{ items("one", "two", "three"), value("one") }}
endin

instr 2
    cabbageSet "combo1", {{ items("two", "three", "four"), value("two") }}
endin

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

Cool! That is useful. Thanks!

I’m still looking for a way to save user input to a file though. Maybe this is more of a Csound question rather than Cabbage. I could find the readf opcode but I don’t know how I could write to a text file. Maybe I just have to go with a preset file containing all IP addresses or manually type in an address each time?

A work around might be to have a few texteditors with init strings like “localhost” or an IP number (which can be modified) and a radiogroup to select which string is being sent to OSCsend

1 Like

I’ve used the foutk opcode for writing text files before without any issues.

Thanks! That one was hiding from me. Can this work with strings? Maybe one needs to convert string to number?

I guess it might involve some kind of conversion. You can use these opcodes directly in Cabbage. In particular the file to string and string to file. When used with strToArray, they can be quite useful.

Thanks! These are really precious opcodes! I think I can make it with them.
My plan is to: get input from multiple texteditors, concatenate strings with space separator, save to disk, load, separate stings with strToArray, update texteditors (this would be the init if file exists).

It seems however, that strings in string arrays can be maximum 7 characters long. Is this a bug in strToArray or is it a Csound limitation?

i’d say definitely a bug in Cabbage, I’ll take a look. Apologies for the delay in getting back to you, my kids are on school holidays, which means I struggle to find time to work on this stuff. But I will look into it soon :+1:, along with the other issue posted.

I just pushed a fix for this issue. Passes my tests :+1:

Thanks! I imagined you must be extra busy this time of year :sunny: - no worries!
The other issues (buttons in Reaper, automation and gestures in Live, Non-latched buttons & automation) are more “baffling” as you say.

I just tested your fix on splitting strings and maybe it was too early, but it still seem to behave like before. I’ll give it a go another day.

I can workaround this by making a UDO using strindex and strsub. I couldn’t find a way to detect the number of separator strings other counting them in a loop, using this count to define a string array and then run a loop again to fill up the array, so I’m probably doing it in a stupid way and your opcode is surely more efficient.

I suppose I could use a local path for external opcodes and bundle them, right?

Btw, it seems that reinit might work best in my case for OSCsend, so I don’t need to change all 20+ k-rate variables to global for an OSC instrument to receive them. Or am I missing something?

I doubt it, a few well placed reinits can be very powerful. I just tested here with 2.8.124 and it’s working fine?

What do you doubt? It seems you’re confirming my opinion about reinit.

This splits fine S2split = "1234 123456789 12345678"
but try splitting this: S2split = "1234 12345678 123456789"
my output (in 2.8.124) from

SArray[] strToArray S2split, " "
iCnt = 0
while iCnt < lenarray(SArray) do
    prints SArray[iCnt]
    iCnt += 1
    prints "\n"
od 

is

1234
1234567
123456789