# User input strings for OSCsend

**URL:** <https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309>\
**Category:** Cabbage Stew\
**Created:** [4 July 2022 07:44 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309 "2022-07-04T07:44:24Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Samo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@Samo](https://forum.cabbageaudio.com/u/Samo)\
**Post date:** [4 July 2022 07:44 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/1 "2022-07-04T07:44:25Z")

</div>

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?

---

<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:** [4 July 2022 18:27 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/2 "2022-07-04T18:27:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Samo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@Samo](https://forum.cabbageaudio.com/u/Samo)\
**Post date:** [4 July 2022 18:49 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/3 "2022-07-04T18:49:35Z")

</div>

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?

---

<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:** [5 July 2022 09:15 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/4 "2022-07-05T09:15:51Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Samo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@Samo](https://forum.cabbageaudio.com/u/Samo)\
**Post date:** [5 July 2022 10:05 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/5 "2022-07-05T10:05:56Z")

</div>

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.

---

<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:** [5 July 2022 10:12 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/6 "2022-07-05T10:12:49Z")

</div>

> [@Samo](#):
>
> Do I get it right that `texteditor` cannot selectively send strings, or can it send individual lines?

It sends individual lines each time you hit return.

> [@Samo](#):
>
> Do you think I’d be able to add `listbox` items by getting input from `texteditor`

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

---

<div class="post-metadata">

**Author:** ![Samo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@Samo](https://forum.cabbageaudio.com/u/Samo)\
**Post date:** [7 July 2022 17:23 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/7 "2022-07-07T17:23:43Z")

</div>

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.

---

<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:** [7 July 2022 18:05 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/8 "2022-07-07T18:05:46Z")

</div>

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

> [@Samo](#):
>
> The listbox example crashes Cabbage 2.8.121.

Thanks I’ll take a look tomorrow.

---

<div class="post-metadata">

**Author:** ![Samo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@Samo](https://forum.cabbageaudio.com/u/Samo)\
**Post date:** [8 July 2022 07:32 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/9 "2022-07-08T07:32:24Z")

</div>

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](https://forum-next.cabbageaudio.com/t/combobox-vs-listbox-dynamicism/2697)  
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.

---

<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:** [8 July 2022 16:42 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/10 "2022-07-08T16:42:37Z")

</div>

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>
```

---

<div class="post-metadata">

**Author:** ![Samo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@Samo](https://forum.cabbageaudio.com/u/Samo)\
**Post date:** [9 July 2022 11:15 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/11 "2022-07-09T11:15:45Z")

</div>

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`…

---

<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:** [11 July 2022 19:04 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/12 "2022-07-11T19:04:54Z")

</div>

I’ve used the [foutk](http://foutk) opcode for writing text files before without any issues.

---

<div class="post-metadata">

**Author:** ![Samo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@Samo](https://forum.cabbageaudio.com/u/Samo)\
**Post date:** [12 July 2022 07:46 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/13 "2022-07-12T07:46:48Z")

</div>

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

---

<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:** [12 July 2022 13:37 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/14 "2022-07-12T13:37:28Z")

</div>

I guess it might involve some kind of conversion. You can use [these](https://rorywalsh.github.io/csoundPluginOpcodes) opcodes directly in Cabbage. In particular the file to string and string to file. When used with strToArray, they can be quite useful.

---

<div class="post-metadata">

**Author:** ![Samo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@Samo](https://forum.cabbageaudio.com/u/Samo)\
**Post date:** [12 July 2022 18:02 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/15 "2022-07-12T18:02:49Z")

</div>

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?

---

<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:** [15 July 2022 14:39 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/16 "2022-07-15T14:39:32Z")

</div>

> [@Samo](#):
>
> 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 👍, along with the other issue posted.

---

<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:** [15 July 2022 15:45 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/17 "2022-07-15T15:45:19Z")

</div>

I just pushed a fix for this issue. Passes my tests 👍

---

<div class="post-metadata">

**Author:** ![Samo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@Samo](https://forum.cabbageaudio.com/u/Samo)\
**Post date:** [15 July 2022 16:51 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/18 "2022-07-15T16:51:45Z")

</div>

Thanks! I imagined you must be extra busy this time of year ☀ - no worries!  
The other issues (buttons in Reaper, automation and gestures in Live, [https://forum-next.cabbageaudio.com/t/non-latched-buttons-automation/3307/24](https://forum-next.cabbageaudio.com/t/non-latched-buttons-automation/3307/24)) 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?

---

<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:** [16 July 2022 18:04 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/19 "2022-07-16T18:04:00Z")

</div>

> [@Samo](#):
>
> 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 `reinit`s can be very powerful. I just tested here with 2.8.124 and it’s working fine?

---

<div class="post-metadata">

**Author:** ![Samo](https://forum.cabbageaudio.com/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@Samo](https://forum.cabbageaudio.com/u/Samo)\
**Post date:** [17 July 2022 06:23 UTC](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309/20 "2022-07-17T06:23:09Z")

</div>

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
```

[Next page](https://forum.cabbageaudio.com/t/user-input-strings-for-oscsend/3309.md?page=2)
