[Csnd-dev] Spaces in csoundSetOption
Date | 2025-01-09 09:17 |
From | Eduardo Moguillansky |
Subject | [Csnd-dev] Spaces in csoundSetOption |
Hi, Directly using the API in c (csound 7) I don't seem to be able to set an option which includes a space. In particular, setting the -o or --output option with a device which includes a space does not seem to work in any case. Looking at the source code it seems that a very naive string splitting code was added to csound 7. csound 6 PUBLIC int csoundSetOption(CSOUND *csound, const char *option){ /* if already compiled and running, return */ if (csound->engineStatus & CS_STATE_COMP) return 1; else { const char *args[2] = {"csound", option}; csound->info_message_request = 1; return (argdecode(csound, 1, args) ? 0 : 1); } } csound 7 /* count whitespaces */ while (*sp++ != '\0') { if (*sp == ' ') { cnt++; *sp = '\0'; sp++; } } args = (char **)mcalloc(csound, sizeof(char *) * (cnt + 2)); args[0] = "csound"; args[1] = sp = options; cnt = 1; /* split into separate args */ while (*opt) { if (*opt == ' ') { args[++cnt] = sp + 1; } sp++; opt++; } ret = argdecode(csound, cnt, (const char **)args); mfree(csound, args); mfree(csound, options); I don't know the rationale behind this inclusion but I think that at least some form of escaping or quotation should be added to the splitting. For me the actual solution would be to remove the splitting at the API level. cheers Eduardo |
Date | 2025-01-09 09:55 |
From | vlz |
Subject | Re: [Csnd-dev] Spaces in csoundSetOption |
I wrote this new code, because the 6.x version was problematic. I can look into improving it. Prof. Victor Lazzarini Maynooth University Ireland On 9 Jan 2025, at 09:17, Eduardo Moguillansky <eduardo.moguillansky@gmail.com> wrote:
|
Date | 2025-01-09 10:12 |
From | vlz |
Subject | Re: [Csnd-dev] [EXTERNAL] [Csnd-dev] Spaces in csoundSetOption |
I checked and this code works res = csoundSetOption(csound, "-o dac -m 6"); so you can have spaces between the arguments. There is a problem with more than a single space, which I can look into. > On 9 Jan 2025, at 09:55, vlz |
Date | 2025-01-09 11:29 |
From | vlz |
Subject | Re: [Csnd-dev] [EXTERNAL] [Csnd-dev] Spaces in csoundSetOption |
Multiple whitespaces are now properly accounted for in #2078. > On 9 Jan 2025, at 10:12, vlz |
Date | 2025-01-09 13:26 |
From | Eduardo Moguillansky |
Subject | Re: [Csnd-dev] [EXTERNAL] [Csnd-dev] Spaces in csoundSetOption |
The problem was with calls of the form res = csoundSetOption(csound, "-odac:Built-in Audio"); or similar, which are common in linux systems running pipewire. I see similar problems with midi devices with spaces. On Thu, Jan 9, 2025 at 12:29 PM vlz <viclazzarini@gmail.com> wrote: Multiple whitespaces are now properly accounted for in #2078. |
Date | 2025-01-09 13:28 |
From | Victor Lazzarini <000010b17ddd988e-dmarc-request@LISTSERV.HEANET.IE> |
Subject | Re: [Csnd-dev] [EXTERNAL] [Csnd-dev] Spaces in csoundSetOption |
I can fix that case. I thought quotes were needed for spaces in strings. The old version could not handle more than one option and this one is supposed to work just like reading from the command-line. ======================== Prof. Victor Lazzarini Maynooth University Ireland > On 9 Jan 2025, at 13:26, Eduardo Moguillansky |
Date | 2025-01-09 15:45 |
From | Victor Lazzarini <000010b17ddd988e-dmarc-request@LISTSERV.HEANET.IE> |
Subject | Re: [Csnd-dev] [EXTERNAL] [Csnd-dev] Spaces in csoundSetOption |
I don’t think this will work on the command-line csound -odac:Built-in Audio but this will csound -odac:"Built-in Audio" so you will need to quote your strings if there are spaces in them. Previously with a single option this wasn’t needed because it was taken as a one full option. However, to get more than one option, I have to tokenise in the form expected by Csound. I have added support for strings to the PR. So you can now do res = csoundSetOption(csound, "-odac:\"Built-in Audio\"”); ======================== Prof. Victor Lazzarini Maynooth University Ireland > On 9 Jan 2025, at 13:26, Eduardo Moguillansky |
Date | 2025-01-09 18:28 |
From | Eduardo Moguillansky |
Subject | Re: [Csnd-dev] [EXTERNAL] [Csnd-dev] Spaces in csoundSetOption |
Thanks, Victor! I tested the PR and it works as expected. On Thu, Jan 9, 2025 at 4:45 PM Victor Lazzarini <000010b17ddd988e-dmarc-request@listserv.heanet.ie> wrote: I don’t think this will work on the command-line |
Date | 2025-01-09 19:26 |
From | vlz |
Subject | Re: [Csnd-dev] [EXTERNAL] [Csnd-dev] Spaces in csoundSetOption |
Great. I'll wait for a review then merge. Prof. Victor Lazzarini Maynooth University Ireland On 9 Jan 2025, at 18:28, Eduardo Moguillansky <eduardo.moguillansky@gmail.com> wrote:
|