Csound Csound-dev Csound-tekno Search About

Re: [Csnd] [EXTERNAL] Re: [Csnd] New UDO syntax question

Date2026-06-09 10:53
FromJean Basile Sosa
SubjectRe: [Csnd] [EXTERNAL] Re: [Csnd] New UDO syntax question
Hi there and hi Victor,

I'm afraid to have no other choice to continue this thread today about a problem yet simple. 

I just want in order to set a given number of chnset(pfield value, string for name of the channel) and after set all corresponding chnget in a udo whose the xout ouptut is a array of k values.

I guess this is an other story of i- and k- rate confusion and maybe a misunderstanding of chnset and chnget behavior such as chnseti(ival[], []Sname), kval[] chngetk Sname[], etc.

I test the following code both in a udp maxmsp context and in a python script/app using udp, the problem comes from chnget who are set on the same S_name... I can just control the last channel, in this case ctrlArr[4] corresponding to the amplitude of an oscil. 

Here the code, out of udp context for test, with some comments which will be more telling than my words:



-odac ;--port=7777 



sr = 48000
ksmps = 32
nchnls = 2 
0dbfs  = 1

opcode test(n:i):(k[])

npfield:i = n // number of pfields

ctrlArr:k[] = init(npfield)
;S_chnstr:S = init(1)
bar:i[] = [1 ... npfield]

for j in [0 ... npfield-1] do
  chnstr:S = sprintf("%.02f_p%d", p1, bar[j])
  ;S_chnstr[j] = sprintf("%.02f_p%d", p1, bar[j])
  fieldvalue:i = pindex(bar[j])
  bar[j] = fieldvalue
  chnset(bar[j],chnstr)
  ;chnset(bar[j],S_chnstr[j])
  // use chnsetk, chnseti ?

  ctrlArr[j] = init(bar[j]) 
  ctrlArr[j] = chnget(chnstr) 
  ;ctrlArr[j] = chnget(S_chnstr[j])
  //I guess here is the problem : 
  //all chnget are seted on the same Sname, in this case the last
  // use chngetk ? Get an error linked to the previous chnset use

  print(j)
  print(bar[j]) // values of pfield
  puts(chnstr,1) // names of channels
  printk2(ctrlArr[0]) // values stored at index in a krate array 
  printk2(ctrlArr[1]) // 
  printk2(ctrlArr[2]) // 
  printk2(ctrlArr[3]) // 
  printk2(ctrlArr[4]) // 
od

xout(ctrlArr)
endop

instr 1
ctrlArr:k[] = test(5) 
asig = oscil(ctrlArr[4], ctrlArr[3])
outs(asig,asig)
endin 



i 1 0 1 80 0.5
e 

 

Thank you for your quick look, help and advice,

Best,

JB

Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2026-06-09 11:20
FromVictor Lazzarini <000010b17ddd988e-dmarc-request@LISTSERV.HEANET.IE>
SubjectRe: [Csnd] [EXTERNAL] Re: [Csnd] New UDO syntax question
I think the problem is that the channel names are created at i-time and the loop runs at perf time.

Why don't you try first creating the array with the channel names - then using that in the k-rate loop. Don't put the sprintf() in the k-rate loop.


Prof. Victor Lazzarini
Maynooth University
Ireland

> On 9 Jun 2026, at 10:53, Jean Basile Sosa  wrote:
>
> Hi there and hi Victor,
>
> I'm afraid to have no other choice to continue this thread today about a problem yet simple.
>
> I just want in order to set a given number of chnset(pfield value, string for name of the channel) and after set all corresponding chnget in a udo whose the xout ouptut is a array of k values.
>
> I guess this is an other story of i- and k- rate confusion and maybe a misunderstanding of chnset and chnget behavior such as chnseti(ival[], []Sname), kval[] chngetk Sname[], etc.
>
> I test the following code both in a udp maxmsp context and in a python script/app using udp, the problem comes from chnget who are set on the same S_name... I can just control the last channel, in this case ctrlArr[4] corresponding to the amplitude of an oscil.
>
> Here the code, out of udp context for test, with some comments which will be more telling than my words:
>
> 
> 
> -odac ;--port=7777
> 
> 
>
> sr = 48000
> ksmps = 32
> nchnls = 2
> 0dbfs  = 1
>
> opcode test(n:i):(k[])
>
> npfield:i = n // number of pfields
>
> ctrlArr:k[] = init(npfield)
> ;S_chnstr:S = init(1)
> bar:i[] = [1 ... npfield]
>
> for j in [0 ... npfield-1] do
>  chnstr:S = sprintf("%.02f_p%d", p1, bar[j])
>  ;S_chnstr[j] = sprintf("%.02f_p%d", p1, bar[j])
>  fieldvalue:i = pindex(bar[j])
>  bar[j] = fieldvalue
>  chnset(bar[j],chnstr)
>  ;chnset(bar[j],S_chnstr[j])
>  // use chnsetk, chnseti ?
>
>  ctrlArr[j] = init(bar[j])
>  ctrlArr[j] = chnget(chnstr)
>  ;ctrlArr[j] = chnget(S_chnstr[j])
>  //I guess here is the problem :
>  //all chnget are seted on the same Sname, in this case the last
>  // use chngetk ? Get an error linked to the previous chnset use
>
>  print(j)
>  print(bar[j]) // values of pfield
>  puts(chnstr,1) // names of channels
>  printk2(ctrlArr[0]) // values stored at index in a krate array
>  printk2(ctrlArr[1]) //
>  printk2(ctrlArr[2]) //
>  printk2(ctrlArr[3]) //
>  printk2(ctrlArr[4]) //
> od
>
> xout(ctrlArr)
> endop
>
> instr 1
> ctrlArr:k[] = test(5)
> asig = oscil(ctrlArr[4], ctrlArr[3])
> outs(asig,asig)
> endin
>
> 
> 
> i 1 0 1 80 0.5
> e
> 
> 
>
> Thank you for your quick look, help and advice,
>
> Best,
>
> JB
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
> Send bugs reports to
>        https://github.com/csound/csound/issues
> Discussions of bugs and features can be posted here
The information contained in this email may be confidential and privileged. It is intended only for the addressee(s) stated above. If you are not an addressee any use, dissemination, distribution, publication or copying of the information contained in this email is strictly prohibited. If you have received this email in error, please immediately notify us by email at dataprotection@mu.ie and delete this email from your system.

Please note that Maynooth University is subject to Freedom of Information and Data Protection laws. We may be required to disclose the content of emails under the FOI Act 2014, the Data Protection Act 2018 or GDPR.

Is don seolaí / do na seolaithe thuasluaite amháin an ríomhphost seo. D’fhéadfadh an t-eolas atá ann a bheith rúnda agus faoi phribhléid. Mura seolaí tú, tá cosc iomlán ar aon eolas atá sa ríomhphost seo a úsáid, a scaipeadh, a dháileadh, a fhoilsiú nó a chóipeáil. Má fuair tú an ríomhphost seo trí thimpiste, cuir sin in iúl dúinn láithreach trí ríomhphost a chur chuig  dataprotection@mu.ie  agus scrios an ríomhphost seo ó do chóras.

Tabhair faoi deara go bhfuil Ollscoil Mhá Nuad faoi réir dhlíthe um Shaoráil Faisnéise agus um Chosaint Sonraí. D’fhéadfadh ceangal a bheith orainn ábhar ríomhphoist a nochtadh faoin Acht um Shaoráil Faisnéise 2014, faoin Acht um Chosaint Sonraí 2018 nó faoi GDPR.

Registered charity number 20037130



Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here