Csound Csound-dev Csound-tekno Search About

[Csnd] puzzled, array in UDO

Date2023-02-15 21:03
FromOeyvind Brandtsegg
Subject[Csnd] puzzled, array in UDO
Hi

I am puzzled by how this (does not) work. There is probably something I misunderstand about internal Csound processes, so I thought I might ask here to get help understanding it.

I am trying to make a UDO to reverse the order of all elements in an array. It is easy enough at i-rate, and I can make the code work at k-rate if I do it inline (not in a UDO), but I fail to make it work with k-rate arrays in a UDO.
My code to reverse the order of elements is:
    kindex = 0
    while kindex < lenarray(kInput) do
      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
      kindex += 1
    od

A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
Any help is greatly appreciated.

all best
Øyvind

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>

; UDO to reverse the order of an array at i-rate
opcode Reverse, i[], i[]
  iInput[] xin
  iOutput[] init lenarray(iInput)
  index = 0
  while index < lenarray(iInput) do
    iOutput[index] = iInput[lenarray(iInput)-1-index]
    index += 1
  od
  xout iOutput
endop

; UDO to reverse the order of an array at k-rate
opcode Reverse, k[], k[]k
  kInput[], kindex xin
  kOutput[] init lenarray(kInput)
  while kindex < lenarray(kInput) do
    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
    kindex += 1
  od
  xout kOutput
endop

instr 1
  ; it does not work when the reversal is inside a UDO
  p3 = 4/kr
  kInput[] fillarray 1,2,3,4
  ktrig metro 1
  if ktrig > 0 then
    kindex = 0
    kOutput[] Reverse kInput, kindex
  endif
  printarray kOutput
endin

instr 2
  ; this one works as expected, when the reversal is not in a UDO
  p3 = 4/kr
  kInput[] fillarray 1,2,3,4
  kOutput[] init lenarray(kInput)
  ktrig metro 1
  if ktrig > 0 then
    kindex = 0
    while kindex < lenarray(kInput) do
      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
      kindex += 1
    od
  endif
  printarray kOutput
endin

instr 3
  ; it also works fine in a UDO with i-rate arrays
  iInput[] fillarray 1,2,3,4
  iOutput[] Reverse iInput
  printarray iOutput
endin

</CsInstruments>
<CsScore>
i1 0 .1
i2 1 .1
i3 2 .1
e
</CsScore>
</CsoundSynthesizer>
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

Date2023-02-15 21:25
From"Jeanette C."
SubjectRe: [Csnd] puzzled, array in UDO
Hey hey Oeyvind,
why do you pass the index to your k-rate opcode? This ight be an issue. Have 
you tried setting up the kIndex inside the opcode and perhaps passing the 
trigger and also have the if (kTrig == 1) statement inside the opcode. I 
didn't test it, but it feels odd reading it like this.

HTH.

Best wishes,

Jeanette

Feb 15 2023, Oeyvind Brandtsegg has written:

> Hi
>
> I am puzzled by how this (does not) work. There is probably something I
> misunderstand about internal Csound processes, so I thought I might ask
> here to get help understanding it.
>
> I am trying to make a UDO to reverse the order of all elements in an array.
> It is easy enough at i-rate, and I can make the code work at k-rate if I do
> it inline (not in a UDO), but I fail to make it work with k-rate arrays in
> a UDO.
> My code to reverse the order of elements is:
>    kindex = 0
>    while kindex < lenarray(kInput) do
>      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>      kindex += 1
>    od
>
> A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code
> (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
> Any help is greatly appreciated.
>
> all best
> Øyvind
>
> 
> 
> 
> 
>
> ; UDO to reverse the order of an array at i-rate
> opcode Reverse, i[], i[]
>  iInput[] xin
>  iOutput[] init lenarray(iInput)
>  index = 0
>  while index < lenarray(iInput) do
>    iOutput[index] = iInput[lenarray(iInput)-1-index]
>    index += 1
>  od
>  xout iOutput
> endop
>
> ; UDO to reverse the order of an array at k-rate
> opcode Reverse, k[], k[]k
>  kInput[], kindex xin
>  kOutput[] init lenarray(kInput)
>  while kindex < lenarray(kInput) do
>    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>    kindex += 1
>  od
>  xout kOutput
> endop
>
> instr 1
>  ; it does not work when the reversal is inside a UDO
>  p3 = 4/kr
>  kInput[] fillarray 1,2,3,4
>  ktrig metro 1
>  if ktrig > 0 then
>    kindex = 0
>    kOutput[] Reverse kInput, kindex
>  endif
>  printarray kOutput
> endin
>
> instr 2
>  ; this one works as expected, when the reversal is not in a UDO
>  p3 = 4/kr
>  kInput[] fillarray 1,2,3,4
>  kOutput[] init lenarray(kInput)
>  ktrig metro 1
>  if ktrig > 0 then
>    kindex = 0
>    while kindex < lenarray(kInput) do
>      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>      kindex += 1
>    od
>  endif
>  printarray kOutput
> endin
>
> instr 3
>  ; it also works fine in a UDO with i-rate arrays
>  iInput[] fillarray 1,2,3,4
>  iOutput[] Reverse iInput
>  printarray iOutput
> endin
>
> 
> 
> i1 0 .1
> i2 1 .1
> i3 2 .1
> e
> 
> 
>
> 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
>

-- 
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

And when you say those words
It's the sweetest thing I've ever heard <3
(Britney Spears)

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

Date2023-02-15 22:59
FromGuillermo Senna
SubjectRe: [Csnd] puzzled, array in UDO
Cool bug! I'm testing with Csound v6.17, but by any chance does adding 
the line "kindex = kindex" before the loop inside the UDO also fix the 
issue for you?

On 15/2/23 18:03, Oeyvind Brandtsegg wrote:
> Hi
>
> I am puzzled by how this (does not) work. There is probably something 
> I misunderstand about internal Csound processes, so I thought I might 
> ask here to get help understanding it.
>
> I am trying to make a UDO to reverse the order of all elements in an 
> array. It is easy enough at i-rate, and I can make the code work at 
> k-rate if I do it inline (not in a UDO), but I fail to make it work 
> with k-rate arrays in a UDO.
> My code to reverse the order of elements is:
>     kindex = 0
>     while kindex < lenarray(kInput) do
>       kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>       kindex += 1
>     od
>
> A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound 
> code (without UDO) is pasted below. The problem shows in instr 1 
> (k-rate UDO).
> Any help is greatly appreciated.
>
> all best
> Øyvind
>
> 
> 
> 
> 
>
> ; UDO to reverse the order of an array at i-rate
> opcode Reverse, i[], i[]
>   iInput[] xin
>   iOutput[] init lenarray(iInput)
>   index = 0
>   while index < lenarray(iInput) do
>     iOutput[index] = iInput[lenarray(iInput)-1-index]
>     index += 1
>   od
>   xout iOutput
> endop
>
> ; UDO to reverse the order of an array at k-rate
> opcode Reverse, k[], k[]k
>   kInput[], kindex xin
>   kOutput[] init lenarray(kInput)
>   while kindex < lenarray(kInput) do
>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>     kindex += 1
>   od
>   xout kOutput
> endop
>
> instr 1
>   ; it does not work when the reversal is inside a UDO
>   p3 = 4/kr
>   kInput[] fillarray 1,2,3,4
>   ktrig metro 1
>   if ktrig > 0 then
>     kindex = 0
>     kOutput[] Reverse kInput, kindex
>   endif
>   printarray kOutput
> endin
>
> instr 2
>   ; this one works as expected, when the reversal is not in a UDO
>   p3 = 4/kr
>   kInput[] fillarray 1,2,3,4
>   kOutput[] init lenarray(kInput)
>   ktrig metro 1
>   if ktrig > 0 then
>     kindex = 0
>     while kindex < lenarray(kInput) do
>       kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>       kindex += 1
>     od
>   endif
>   printarray kOutput
> endin
>
> instr 3
>   ; it also works fine in a UDO with i-rate arrays
>   iInput[] fillarray 1,2,3,4
>   iOutput[] Reverse iInput
>   printarray iOutput
> endin
>
> 
> 
> i1 0 .1
> i2 1 .1
> i3 2 .1
> e
> 
> 
> 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 

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

Date2023-02-15 23:03
FromOeyvind Brandtsegg
SubjectRe: [Csnd] puzzled, array in UDO
Hi,  yes i did have the index inside at first,  and it worked the same.  
But your suggestion of putting the ktrig inside the UDO makes it work.
Thanks 


ons. 15. feb. 2023, 22:27 skrev Jeanette C. <julien@mail.upb.de>:
Hey hey Oeyvind,
why do you pass the index to your k-rate opcode? This ight be an issue. Have
you tried setting up the kIndex inside the opcode and perhaps passing the
trigger and also have the if (kTrig == 1) statement inside the opcode. I
didn't test it, but it feels odd reading it like this.

HTH.

Best wishes,

Jeanette

Feb 15 2023, Oeyvind Brandtsegg has written:

> Hi
>
> I am puzzled by how this (does not) work. There is probably something I
> misunderstand about internal Csound processes, so I thought I might ask
> here to get help understanding it.
>
> I am trying to make a UDO to reverse the order of all elements in an array.
> It is easy enough at i-rate, and I can make the code work at k-rate if I do
> it inline (not in a UDO), but I fail to make it work with k-rate arrays in
> a UDO.
> My code to reverse the order of elements is:
>    kindex = 0
>    while kindex < lenarray(kInput) do
>      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>      kindex += 1
>    od
>
> A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code
> (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
> Any help is greatly appreciated.
>
> all best
> Øyvind
>
> <CsoundSynthesizer>
> <CsOptions>
> </CsOptions>
> <CsInstruments>
>
> ; UDO to reverse the order of an array at i-rate
> opcode Reverse, i[], i[]
>  iInput[] xin
>  iOutput[] init lenarray(iInput)
>  index = 0
>  while index < lenarray(iInput) do
>    iOutput[index] = iInput[lenarray(iInput)-1-index]
>    index += 1
>  od
>  xout iOutput
> endop
>
> ; UDO to reverse the order of an array at k-rate
> opcode Reverse, k[], k[]k
>  kInput[], kindex xin
>  kOutput[] init lenarray(kInput)
>  while kindex < lenarray(kInput) do
>    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>    kindex += 1
>  od
>  xout kOutput
> endop
>
> instr 1
>  ; it does not work when the reversal is inside a UDO
>  p3 = 4/kr
>  kInput[] fillarray 1,2,3,4
>  ktrig metro 1
>  if ktrig > 0 then
>    kindex = 0
>    kOutput[] Reverse kInput, kindex
>  endif
>  printarray kOutput
> endin
>
> instr 2
>  ; this one works as expected, when the reversal is not in a UDO
>  p3 = 4/kr
>  kInput[] fillarray 1,2,3,4
>  kOutput[] init lenarray(kInput)
>  ktrig metro 1
>  if ktrig > 0 then
>    kindex = 0
>    while kindex < lenarray(kInput) do
>      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>      kindex += 1
>    od
>  endif
>  printarray kOutput
> endin
>
> instr 3
>  ; it also works fine in a UDO with i-rate arrays
>  iInput[] fillarray 1,2,3,4
>  iOutput[] Reverse iInput
>  printarray iOutput
> endin
>
> </CsInstruments>
> <CsScore>
> i1 0 .1
> i2 1 .1
> i3 2 .1
> e
> </CsScore>
> </CsoundSynthesizer>
>
> 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
>

--
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

And when you say those words
It's the sweetest thing I've ever heard <3
(Britney Spears)

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

Date2023-02-15 23:07
FromOeyvind Brandtsegg
SubjectRe: [Csnd] puzzled, array in UDO
Whoa, yes, guillermo, it does fix it.
Like this. 
That is indeed strange(?)

; UDO to reverse the order of an array at k-rate
opcode Reverse, k[], k[]k
  kInput[], kindex xin
  kOutput[] init lenarray(kInput)
  kindex = kindex
  while kindex < lenarray(kInput) do
    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
    kindex += 1
  od
  xout kOutput
endop


tor. 16. feb. 2023 kl. 00:03 skrev Oeyvind Brandtsegg <obrandts@gmail.com>:
Hi,  yes i did have the index inside at first,  and it worked the same.  
But your suggestion of putting the ktrig inside the UDO makes it work.
Thanks 


ons. 15. feb. 2023, 22:27 skrev Jeanette C. <julien@mail.upb.de>:
Hey hey Oeyvind,
why do you pass the index to your k-rate opcode? This ight be an issue. Have
you tried setting up the kIndex inside the opcode and perhaps passing the
trigger and also have the if (kTrig == 1) statement inside the opcode. I
didn't test it, but it feels odd reading it like this.

HTH.

Best wishes,

Jeanette

Feb 15 2023, Oeyvind Brandtsegg has written:

> Hi
>
> I am puzzled by how this (does not) work. There is probably something I
> misunderstand about internal Csound processes, so I thought I might ask
> here to get help understanding it.
>
> I am trying to make a UDO to reverse the order of all elements in an array.
> It is easy enough at i-rate, and I can make the code work at k-rate if I do
> it inline (not in a UDO), but I fail to make it work with k-rate arrays in
> a UDO.
> My code to reverse the order of elements is:
>    kindex = 0
>    while kindex < lenarray(kInput) do
>      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>      kindex += 1
>    od
>
> A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code
> (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
> Any help is greatly appreciated.
>
> all best
> Øyvind
>
> <CsoundSynthesizer>
> <CsOptions>
> </CsOptions>
> <CsInstruments>
>
> ; UDO to reverse the order of an array at i-rate
> opcode Reverse, i[], i[]
>  iInput[] xin
>  iOutput[] init lenarray(iInput)
>  index = 0
>  while index < lenarray(iInput) do
>    iOutput[index] = iInput[lenarray(iInput)-1-index]
>    index += 1
>  od
>  xout iOutput
> endop
>
> ; UDO to reverse the order of an array at k-rate
> opcode Reverse, k[], k[]k
>  kInput[], kindex xin
>  kOutput[] init lenarray(kInput)
>  while kindex < lenarray(kInput) do
>    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>    kindex += 1
>  od
>  xout kOutput
> endop
>
> instr 1
>  ; it does not work when the reversal is inside a UDO
>  p3 = 4/kr
>  kInput[] fillarray 1,2,3,4
>  ktrig metro 1
>  if ktrig > 0 then
>    kindex = 0
>    kOutput[] Reverse kInput, kindex
>  endif
>  printarray kOutput
> endin
>
> instr 2
>  ; this one works as expected, when the reversal is not in a UDO
>  p3 = 4/kr
>  kInput[] fillarray 1,2,3,4
>  kOutput[] init lenarray(kInput)
>  ktrig metro 1
>  if ktrig > 0 then
>    kindex = 0
>    while kindex < lenarray(kInput) do
>      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>      kindex += 1
>    od
>  endif
>  printarray kOutput
> endin
>
> instr 3
>  ; it also works fine in a UDO with i-rate arrays
>  iInput[] fillarray 1,2,3,4
>  iOutput[] Reverse iInput
>  printarray iOutput
> endin
>
> </CsInstruments>
> <CsScore>
> i1 0 .1
> i2 1 .1
> i3 2 .1
> e
> </CsScore>
> </CsoundSynthesizer>
>
> 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
>

--
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

And when you say those words
It's the sweetest thing I've ever heard <3
(Britney Spears)

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

Date2023-02-16 01:39
FromAaron Krister Johnson
SubjectRe: [Csnd] puzzled, array in UDO
Ah, it must be that the assignment to a local scope needs to happen.

To be filed away under "things to remember when you need to loop in an UDO"



On Wed, Feb 15, 2023 at 4:08 PM Oeyvind Brandtsegg <obrandts@gmail.com> wrote:
Whoa, yes, guillermo, it does fix it.
Like this. 
That is indeed strange(?)

; UDO to reverse the order of an array at k-rate
opcode Reverse, k[], k[]k
  kInput[], kindex xin
  kOutput[] init lenarray(kInput)
  kindex = kindex
  while kindex < lenarray(kInput) do
    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
    kindex += 1
  od
  xout kOutput
endop


tor. 16. feb. 2023 kl. 00:03 skrev Oeyvind Brandtsegg <obrandts@gmail.com>:
Hi,  yes i did have the index inside at first,  and it worked the same.  
But your suggestion of putting the ktrig inside the UDO makes it work.
Thanks 


ons. 15. feb. 2023, 22:27 skrev Jeanette C. <julien@mail.upb.de>:
Hey hey Oeyvind,
why do you pass the index to your k-rate opcode? This ight be an issue. Have
you tried setting up the kIndex inside the opcode and perhaps passing the
trigger and also have the if (kTrig == 1) statement inside the opcode. I
didn't test it, but it feels odd reading it like this.

HTH.

Best wishes,

Jeanette

Feb 15 2023, Oeyvind Brandtsegg has written:

> Hi
>
> I am puzzled by how this (does not) work. There is probably something I
> misunderstand about internal Csound processes, so I thought I might ask
> here to get help understanding it.
>
> I am trying to make a UDO to reverse the order of all elements in an array.
> It is easy enough at i-rate, and I can make the code work at k-rate if I do
> it inline (not in a UDO), but I fail to make it work with k-rate arrays in
> a UDO.
> My code to reverse the order of elements is:
>    kindex = 0
>    while kindex < lenarray(kInput) do
>      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>      kindex += 1
>    od
>
> A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code
> (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
> Any help is greatly appreciated.
>
> all best
> Øyvind
>
> <CsoundSynthesizer>
> <CsOptions>
> </CsOptions>
> <CsInstruments>
>
> ; UDO to reverse the order of an array at i-rate
> opcode Reverse, i[], i[]
>  iInput[] xin
>  iOutput[] init lenarray(iInput)
>  index = 0
>  while index < lenarray(iInput) do
>    iOutput[index] = iInput[lenarray(iInput)-1-index]
>    index += 1
>  od
>  xout iOutput
> endop
>
> ; UDO to reverse the order of an array at k-rate
> opcode Reverse, k[], k[]k
>  kInput[], kindex xin
>  kOutput[] init lenarray(kInput)
>  while kindex < lenarray(kInput) do
>    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>    kindex += 1
>  od
>  xout kOutput
> endop
>
> instr 1
>  ; it does not work when the reversal is inside a UDO
>  p3 = 4/kr
>  kInput[] fillarray 1,2,3,4
>  ktrig metro 1
>  if ktrig > 0 then
>    kindex = 0
>    kOutput[] Reverse kInput, kindex
>  endif
>  printarray kOutput
> endin
>
> instr 2
>  ; this one works as expected, when the reversal is not in a UDO
>  p3 = 4/kr
>  kInput[] fillarray 1,2,3,4
>  kOutput[] init lenarray(kInput)
>  ktrig metro 1
>  if ktrig > 0 then
>    kindex = 0
>    while kindex < lenarray(kInput) do
>      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>      kindex += 1
>    od
>  endif
>  printarray kOutput
> endin
>
> instr 3
>  ; it also works fine in a UDO with i-rate arrays
>  iInput[] fillarray 1,2,3,4
>  iOutput[] Reverse iInput
>  printarray iOutput
> endin
>
> </CsInstruments>
> <CsScore>
> i1 0 .1
> i2 1 .1
> i3 2 .1
> e
> </CsScore>
> </CsoundSynthesizer>
>
> 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
>

--
  * Website: http://juliencoder.de - for summer is a state of sound
  * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
  * Audiobombs: https://www.audiobombs.com/users/jeanette_c
  * GitHub: https://github.com/jeanette-c

And when you say those words
It's the sweetest thing I've ever heard <3
(Britney Spears)

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

Date2023-02-16 10:40
FromVictor Lazzarini
SubjectRe: [Csnd] [EXTERNAL] [Csnd] puzzled, array in UDO
yes, that’s a bug alright. I have looked at this and what happens is that if there are no perf statements outside the loop,
the opcode behaves in such a way that the loop is ignored. However if you insert any statement (like kindex = kindex) then
it works correctly. For example,

 opcode Test0, k, k
  kindex xin
  while kindex < 3 do
    kindex += 1
  od  
  xout kindex
endop

doesn’t work correctly, but this one does

 opcode Test1, k, k
  kindex xin
  k1 = 0
  while kindex < 3 do
    kindex += 1
  od  
  xout kindex
endop

I know that if there are no perf statements in a UDO there’s no perf cycle, but here we are ignoring perf statements inside
the loop. We’ll fix this.
========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 16 Feb 2023, at 01:39, Aaron Krister Johnson  wrote:
> 
> WARNINGThis email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
> Ah, it must be that the assignment to a local scope needs to happen.
> 
> To be filed away under "things to remember when you need to loop in an UDO"
> 
> 
> Aaron Krister Johnson
> Music, etc.:
> http://www.untwelve.org
> https://www.youtube.com/channel/UC_utjGYbSizWE0dNyr0Vdmg
> https://soundcloud.com/aaron-krister-johnson
> https://soundcloud.com/filtercreed
> https://aaronkristerjohnson.bandcamp.com/
> Code:
> https://github.com/akjmicro
> 
> 
> On Wed, Feb 15, 2023 at 4:08 PM Oeyvind Brandtsegg  wrote:
> Whoa, yes, guillermo, it does fix it.
> Like this. 
> That is indeed strange(?)
> 
> ; UDO to reverse the order of an array at k-rate
> opcode Reverse, k[], k[]k
>   kInput[], kindex xin
>   kOutput[] init lenarray(kInput)
>   kindex = kindex
>   while kindex < lenarray(kInput) do
>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>     kindex += 1
>   od
>   xout kOutput
> endop
> 
> 
> tor. 16. feb. 2023 kl. 00:03 skrev Oeyvind Brandtsegg :
> Hi,  yes i did have the index inside at first,  and it worked the same.  
> But your suggestion of putting the ktrig inside the UDO makes it work.
> Thanks 
> 
> 
> ons. 15. feb. 2023, 22:27 skrev Jeanette C. :
> Hey hey Oeyvind,
> why do you pass the index to your k-rate opcode? This ight be an issue. Have 
> you tried setting up the kIndex inside the opcode and perhaps passing the 
> trigger and also have the if (kTrig == 1) statement inside the opcode. I 
> didn't test it, but it feels odd reading it like this.
> 
> HTH.
> 
> Best wishes,
> 
> Jeanette
> 
> Feb 15 2023, Oeyvind Brandtsegg has written:
> 
> > Hi
> >
> > I am puzzled by how this (does not) work. There is probably something I
> > misunderstand about internal Csound processes, so I thought I might ask
> > here to get help understanding it.
> >
> > I am trying to make a UDO to reverse the order of all elements in an array.
> > It is easy enough at i-rate, and I can make the code work at k-rate if I do
> > it inline (not in a UDO), but I fail to make it work with k-rate arrays in
> > a UDO.
> > My code to reverse the order of elements is:
> >    kindex = 0
> >    while kindex < lenarray(kInput) do
> >      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
> >      kindex += 1
> >    od
> >
> > A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code
> > (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
> > Any help is greatly appreciated.
> >
> > all best
> > Øyvind
> >
> > 
> > 
> > 
> > 
> >
> > ; UDO to reverse the order of an array at i-rate
> > opcode Reverse, i[], i[]
> >  iInput[] xin
> >  iOutput[] init lenarray(iInput)
> >  index = 0
> >  while index < lenarray(iInput) do
> >    iOutput[index] = iInput[lenarray(iInput)-1-index]
> >    index += 1
> >  od
> >  xout iOutput
> > endop
> >
> > ; UDO to reverse the order of an array at k-rate
> > opcode Reverse, k[], k[]k
> >  kInput[], kindex xin
> >  kOutput[] init lenarray(kInput)
> >  while kindex < lenarray(kInput) do
> >    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
> >    kindex += 1
> >  od
> >  xout kOutput
> > endop
> >
> > instr 1
> >  ; it does not work when the reversal is inside a UDO
> >  p3 = 4/kr
> >  kInput[] fillarray 1,2,3,4
> >  ktrig metro 1
> >  if ktrig > 0 then
> >    kindex = 0
> >    kOutput[] Reverse kInput, kindex
> >  endif
> >  printarray kOutput
> > endin
> >
> > instr 2
> >  ; this one works as expected, when the reversal is not in a UDO
> >  p3 = 4/kr
> >  kInput[] fillarray 1,2,3,4
> >  kOutput[] init lenarray(kInput)
> >  ktrig metro 1
> >  if ktrig > 0 then
> >    kindex = 0
> >    while kindex < lenarray(kInput) do
> >      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
> >      kindex += 1
> >    od
> >  endif
> >  printarray kOutput
> > endin
> >
> > instr 3
> >  ; it also works fine in a UDO with i-rate arrays
> >  iInput[] fillarray 1,2,3,4
> >  iOutput[] Reverse iInput
> >  printarray iOutput
> > endin
> >
> > 
> > 
> > i1 0 .1
> > i2 1 .1
> > i3 2 .1
> > e
> > 
> > 
> >
> > 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
> >
> 
> -- 
>   * Website: http://juliencoder.de - for summer is a state of sound
>   * Youtube: https://www.youtube.com/channel/UCMS4rfGrTwz8W7jhC1Jnv7g
>   * Audiobombs: https://www.audiobombs.com/users/jeanette_c
>   * GitHub: https://github.com/jeanette-c
> 
> And when you say those words
> It's the sweetest thing I've ever heard <3
> (Britney Spears)
> 
> 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
> 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
> 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


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

Date2023-02-16 13:17
FromVictor Lazzarini
SubjectRe: [Csnd] [EXTERNAL] [Csnd] puzzled, array in UDO
I believe this is now fix in git (both csound6 and develop branches).

========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 16 Feb 2023, at 10:40, Victor Lazzarini  wrote:
> 
> yes, that’s a bug alright. I have looked at this and what happens is that if there are no perf statements outside the loop,
> the opcode behaves in such a way that the loop is ignored. However if you insert any statement (like kindex = kindex) then
> it works correctly. For example,
> 
> opcode Test0, k, k
>  kindex xin
>  while kindex < 3 do
>    kindex += 1
>  od  
>  xout kindex
> endop
> 
> doesn’t work correctly, but this one does
> 
> opcode Test1, k, k
>  kindex xin
>  k1 = 0
>  while kindex < 3 do
>    kindex += 1
>  od  
>  xout kindex
> endop
> 
> I know that if there are no perf statements in a UDO there’s no perf cycle, but here we are ignoring perf statements inside
> the loop. We’ll fix this.
> ========================
> Prof. Victor Lazzarini
> Maynooth University
> Ireland
> 
>> On 16 Feb 2023, at 01:39, Aaron Krister Johnson  wrote:
>> 
>> WARNINGThis email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
>> Ah, it must be that the assignment to a local scope needs to happen.
>> 
>> To be filed away under "things to remember when you need to loop in an UDO"
>> 
>> 
>> Aaron Krister Johnson
>> Music, etc.:
>> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.untwelve.org%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=82WVd%2F7SkjwJvK%2BSKQVrvPhDNjJB532n%2BL1lSAn2ZwE%3D&reserved=0
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUC_utjGYbSizWE0dNyr0Vdmg&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hzNV42ViOz1AR9CQsdUe2Nsq9PwcTiJST6hHBkO0m3I%3D&reserved=0
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Faaron-krister-johnson&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=SVfxPZwhQ8Q8ZF7JVd1eFu9lgBlHzTdwtLrt2fBC3pM%3D&reserved=0
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Ffiltercreed&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=52HeYu1t%2B5GIXVBQIsQje5cJyYrn4hXpklqYLI4jAUE%3D&reserved=0
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faaronkristerjohnson.bandcamp.com%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=PBqx7PqVa3J5CEu%2BWF71Kl6mkx6X0A2abrKMZ0MNlbs%3D&reserved=0
>> Code:
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fakjmicro&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2NnDOiEYbo7TCKl27CsSuLUP2dXVoWNDs2mmwLG1lz0%3D&reserved=0
>> 
>> 
>> On Wed, Feb 15, 2023 at 4:08 PM Oeyvind Brandtsegg  wrote:
>> Whoa, yes, guillermo, it does fix it.
>> Like this. 
>> That is indeed strange(?)
>> 
>> ; UDO to reverse the order of an array at k-rate
>> opcode Reverse, k[], k[]k
>>  kInput[], kindex xin
>>  kOutput[] init lenarray(kInput)
>>  kindex = kindex
>>  while kindex < lenarray(kInput) do
>>    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>    kindex += 1
>>  od
>>  xout kOutput
>> endop
>> 
>> 
>> tor. 16. feb. 2023 kl. 00:03 skrev Oeyvind Brandtsegg :
>> Hi,  yes i did have the index inside at first,  and it worked the same.  
>> But your suggestion of putting the ktrig inside the UDO makes it work.
>> Thanks 
>> 
>> 
>> ons. 15. feb. 2023, 22:27 skrev Jeanette C. :
>> Hey hey Oeyvind,
>> why do you pass the index to your k-rate opcode? This ight be an issue. Have 
>> you tried setting up the kIndex inside the opcode and perhaps passing the 
>> trigger and also have the if (kTrig == 1) statement inside the opcode. I 
>> didn't test it, but it feels odd reading it like this.
>> 
>> HTH.
>> 
>> Best wishes,
>> 
>> Jeanette
>> 
>> Feb 15 2023, Oeyvind Brandtsegg has written:
>> 
>>> Hi
>>> 
>>> I am puzzled by how this (does not) work. There is probably something I
>>> misunderstand about internal Csound processes, so I thought I might ask
>>> here to get help understanding it.
>>> 
>>> I am trying to make a UDO to reverse the order of all elements in an array.
>>> It is easy enough at i-rate, and I can make the code work at k-rate if I do
>>> it inline (not in a UDO), but I fail to make it work with k-rate arrays in
>>> a UDO.
>>> My code to reverse the order of elements is:
>>>   kindex = 0
>>>   while kindex < lenarray(kInput) do
>>>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>     kindex += 1
>>>   od
>>> 
>>> A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code
>>> (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
>>> Any help is greatly appreciated.
>>> 
>>> all best
>>> Øyvind
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>> ; UDO to reverse the order of an array at i-rate
>>> opcode Reverse, i[], i[]
>>> iInput[] xin
>>> iOutput[] init lenarray(iInput)
>>> index = 0
>>> while index < lenarray(iInput) do
>>>   iOutput[index] = iInput[lenarray(iInput)-1-index]
>>>   index += 1
>>> od
>>> xout iOutput
>>> endop
>>> 
>>> ; UDO to reverse the order of an array at k-rate
>>> opcode Reverse, k[], k[]k
>>> kInput[], kindex xin
>>> kOutput[] init lenarray(kInput)
>>> while kindex < lenarray(kInput) do
>>>   kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>   kindex += 1
>>> od
>>> xout kOutput
>>> endop
>>> 
>>> instr 1
>>> ; it does not work when the reversal is inside a UDO
>>> p3 = 4/kr
>>> kInput[] fillarray 1,2,3,4
>>> ktrig metro 1
>>> if ktrig > 0 then
>>>   kindex = 0
>>>   kOutput[] Reverse kInput, kindex
>>> endif
>>> printarray kOutput
>>> endin
>>> 
>>> instr 2
>>> ; this one works as expected, when the reversal is not in a UDO
>>> p3 = 4/kr
>>> kInput[] fillarray 1,2,3,4
>>> kOutput[] init lenarray(kInput)
>>> ktrig metro 1
>>> if ktrig > 0 then
>>>   kindex = 0
>>>   while kindex < lenarray(kInput) do
>>>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>     kindex += 1
>>>   od
>>> endif
>>> printarray kOutput
>>> endin
>>> 
>>> instr 3
>>> ; it also works fine in a UDO with i-rate arrays
>>> iInput[] fillarray 1,2,3,4
>>> iOutput[] Reverse iInput
>>> printarray iOutput
>>> endin
>>> 
>>> 
>>> 
>>> i1 0 .1
>>> i2 1 .1
>>> i3 2 .1
>>> e
>>> 
>>> 
>>> 
>>> Csound mailing list
>>> Csound@listserv.heanet.ie
>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0
>>> Send bugs reports to
>>>       https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0
>>> Discussions of bugs and features can be posted here
>>> 
>> 
>> -- 
>>  * Website: https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fjuliencoder.de%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=WJhyCJUerfSgM84mbFKFEc%2FbEbrmbK8DCkpCrhTSO3g%3D&reserved=0 - for summer is a state of sound
>>  * Youtube: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUCMS4rfGrTwz8W7jhC1Jnv7g&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RZJINBO85WJOXeLu5Xth9s%2Fjmu%2FPkqJfPjsoAfr4EdU%3D&reserved=0
>>  * Audiobombs: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.audiobombs.com%2Fusers%2Fjeanette_c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=5CaGO6NQTlGJf%2Fabt%2FpjByKNnrU3L3%2FYXt0KF%2B0nP9A%3D&reserved=0
>>  * GitHub: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjeanette-c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=a3zhMP%2FrNVToBUjwYzwyNw0RgPshLM4x1G24JDE9rA0%3D&reserved=0
>> 
>> And when you say those words
>> It's the sweetest thing I've ever heard <3
>> (Britney Spears)
>> 
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0
>> Send bugs reports to
>>        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0
>> Discussions of bugs and features can be posted here
>> Csound mailing list Csound@listserv.heanet.ie https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0 Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0 Discussions of bugs and features can be posted here
>> Csound mailing list Csound@listserv.heanet.ie https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0 Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0 Discussions of bugs and features can be posted here
> 
> 
> Csound mailing list
> Csound@listserv.heanet.ie
> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0
> Send bugs reports to
>        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0
> Discussions of bugs and features can be posted here


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

Date2023-02-16 14:30
FromOeyvind Brandtsegg
SubjectRe: [Csnd] [EXTERNAL] [Csnd] puzzled, array in UDO
Thanks so much. Happy to hear that it was not my own fault this time ;-)

I have a related issue, this time it is not related to processing it with a UDO, but it occurs when I try to reverse the contents of a global array.
My use case is that I would like to k-rate trigger the reversal of the contents of a global array in place.

My thinking was that I could do the reversal as before, and since I am inside a conditional, I would only copy the reversed array back to the global array once the reversal had been processed. 

Example below

all best
Øyvind

<CsoundSynthesizer>
<CsOptions>
</CsOptions>
<CsInstruments>

gkArr[] fillarray 1,2,3,4

instr 1
  ; works with local array
  kInput[] fillarray 1,2,3,4
  kOutput[] init lenarray(kInput)
  ktrig metro 1
  if ktrig > 0 then
    kindex = 0
    while kindex < lenarray(kInput) do
      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
      kindex += 1
    od
  printarray kOutput
  endif
endin

instr 2
  ; does not work when I use a global array as input and copy the result back to the same global array
  kInput[] = gkArr
  kOutput[] init lenarray(kInput)
  ktrig metro 1
  if ktrig > 0 then
    kindex = 0
    while kindex < lenarray(kInput) do
      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
      kindex += 1
    od
    gkArr = kOutput ; removing this line makes it work, ...but I would like to copy the result back to the same global array
    printarray kOutput
    printarray gkArr
  endif
endin

</CsInstruments>
<CsScore>
i1 0 3
i2 4 3
e
</CsScore>
</CsoundSynthesizer>

tor. 16. feb. 2023 kl. 14:18 skrev Victor Lazzarini <Victor.Lazzarini@mu.ie>:
I believe this is now fix in git (both csound6 and develop branches).

========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 16 Feb 2023, at 10:40, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
>
> yes, that’s a bug alright. I have looked at this and what happens is that if there are no perf statements outside the loop,
> the opcode behaves in such a way that the loop is ignored. However if you insert any statement (like kindex = kindex) then
> it works correctly. For example,
>
> opcode Test0, k, k
>  kindex xin
>  while kindex < 3 do
>    kindex += 1
>  od 
>  xout kindex
> endop
>
> doesn’t work correctly, but this one does
>
> opcode Test1, k, k
>  kindex xin
>  k1 = 0
>  while kindex < 3 do
>    kindex += 1
>  od 
>  xout kindex
> endop
>
> I know that if there are no perf statements in a UDO there’s no perf cycle, but here we are ignoring perf statements inside
> the loop. We’ll fix this.
> ========================
> Prof. Victor Lazzarini
> Maynooth University
> Ireland
>
>> On 16 Feb 2023, at 01:39, Aaron Krister Johnson <akjmicro@GMAIL.COM> wrote:
>>
>> WARNINGThis email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
>> Ah, it must be that the assignment to a local scope needs to happen.
>>
>> To be filed away under "things to remember when you need to loop in an UDO"
>>
>>
>> Aaron Krister Johnson
>> Music, etc.:
>> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.untwelve.org%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=82WVd%2F7SkjwJvK%2BSKQVrvPhDNjJB532n%2BL1lSAn2ZwE%3D&reserved=0
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUC_utjGYbSizWE0dNyr0Vdmg&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hzNV42ViOz1AR9CQsdUe2Nsq9PwcTiJST6hHBkO0m3I%3D&reserved=0
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Faaron-krister-johnson&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=SVfxPZwhQ8Q8ZF7JVd1eFu9lgBlHzTdwtLrt2fBC3pM%3D&reserved=0
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Ffiltercreed&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=52HeYu1t%2B5GIXVBQIsQje5cJyYrn4hXpklqYLI4jAUE%3D&reserved=0
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faaronkristerjohnson.bandcamp.com%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=PBqx7PqVa3J5CEu%2BWF71Kl6mkx6X0A2abrKMZ0MNlbs%3D&reserved=0
>> Code:
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fakjmicro&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2NnDOiEYbo7TCKl27CsSuLUP2dXVoWNDs2mmwLG1lz0%3D&reserved=0
>>
>>
>> On Wed, Feb 15, 2023 at 4:08 PM Oeyvind Brandtsegg <obrandts@gmail.com> wrote:
>> Whoa, yes, guillermo, it does fix it.
>> Like this.
>> That is indeed strange(?)
>>
>> ; UDO to reverse the order of an array at k-rate
>> opcode Reverse, k[], k[]k
>>  kInput[], kindex xin
>>  kOutput[] init lenarray(kInput)
>>  kindex = kindex
>>  while kindex < lenarray(kInput) do
>>    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>    kindex += 1
>>  od
>>  xout kOutput
>> endop
>>
>>
>> tor. 16. feb. 2023 kl. 00:03 skrev Oeyvind Brandtsegg <obrandts@gmail.com>:
>> Hi,  yes i did have the index inside at first,  and it worked the same. 
>> But your suggestion of putting the ktrig inside the UDO makes it work.
>> Thanks
>>
>>
>> ons. 15. feb. 2023, 22:27 skrev Jeanette C. <julien@mail.upb.de>:
>> Hey hey Oeyvind,
>> why do you pass the index to your k-rate opcode? This ight be an issue. Have
>> you tried setting up the kIndex inside the opcode and perhaps passing the
>> trigger and also have the if (kTrig == 1) statement inside the opcode. I
>> didn't test it, but it feels odd reading it like this.
>>
>> HTH.
>>
>> Best wishes,
>>
>> Jeanette
>>
>> Feb 15 2023, Oeyvind Brandtsegg has written:
>>
>>> Hi
>>>
>>> I am puzzled by how this (does not) work. There is probably something I
>>> misunderstand about internal Csound processes, so I thought I might ask
>>> here to get help understanding it.
>>>
>>> I am trying to make a UDO to reverse the order of all elements in an array.
>>> It is easy enough at i-rate, and I can make the code work at k-rate if I do
>>> it inline (not in a UDO), but I fail to make it work with k-rate arrays in
>>> a UDO.
>>> My code to reverse the order of elements is:
>>>   kindex = 0
>>>   while kindex < lenarray(kInput) do
>>>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>     kindex += 1
>>>   od
>>>
>>> A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code
>>> (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
>>> Any help is greatly appreciated.
>>>
>>> all best
>>> Øyvind
>>>
>>> <CsoundSynthesizer>
>>> <CsOptions>
>>> </CsOptions>
>>> <CsInstruments>
>>>
>>> ; UDO to reverse the order of an array at i-rate
>>> opcode Reverse, i[], i[]
>>> iInput[] xin
>>> iOutput[] init lenarray(iInput)
>>> index = 0
>>> while index < lenarray(iInput) do
>>>   iOutput[index] = iInput[lenarray(iInput)-1-index]
>>>   index += 1
>>> od
>>> xout iOutput
>>> endop
>>>
>>> ; UDO to reverse the order of an array at k-rate
>>> opcode Reverse, k[], k[]k
>>> kInput[], kindex xin
>>> kOutput[] init lenarray(kInput)
>>> while kindex < lenarray(kInput) do
>>>   kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>   kindex += 1
>>> od
>>> xout kOutput
>>> endop
>>>
>>> instr 1
>>> ; it does not work when the reversal is inside a UDO
>>> p3 = 4/kr
>>> kInput[] fillarray 1,2,3,4
>>> ktrig metro 1
>>> if ktrig > 0 then
>>>   kindex = 0
>>>   kOutput[] Reverse kInput, kindex
>>> endif
>>> printarray kOutput
>>> endin
>>>
>>> instr 2
>>> ; this one works as expected, when the reversal is not in a UDO
>>> p3 = 4/kr
>>> kInput[] fillarray 1,2,3,4
>>> kOutput[] init lenarray(kInput)
>>> ktrig metro 1
>>> if ktrig > 0 then
>>>   kindex = 0
>>>   while kindex < lenarray(kInput) do
>>>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>     kindex += 1
>>>   od
>>> endif
>>> printarray kOutput
>>> endin
>>>
>>> instr 3
>>> ; it also works fine in a UDO with i-rate arrays
>>> iInput[] fillarray 1,2,3,4
>>> iOutput[] Reverse iInput
>>> printarray iOutput
>>> endin
>>>
>>> </CsInstruments>
>>> <CsScore>
>>> i1 0 .1
>>> i2 1 .1
>>> i3 2 .1
>>> e
>>> </CsScore>
>>> </CsoundSynthesizer>
>>>
>>> Csound mailing list
>>> Csound@listserv.heanet.ie
>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0
>>> Send bugs reports to
>>>       https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0
>>> Discussions of bugs and features can be posted here
>>>
>>
>> --
>>  * Website: https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fjuliencoder.de%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=WJhyCJUerfSgM84mbFKFEc%2FbEbrmbK8DCkpCrhTSO3g%3D&reserved=0 - for summer is a state of sound
>>  * Youtube: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUCMS4rfGrTwz8W7jhC1Jnv7g&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RZJINBO85WJOXeLu5Xth9s%2Fjmu%2FPkqJfPjsoAfr4EdU%3D&reserved=0
>>  * Audiobombs: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.audiobombs.com%2Fusers%2Fjeanette_c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=5CaGO6NQTlGJf%2Fabt%2FpjByKNnrU3L3%2FYXt0KF%2B0nP9A%3D&reserved=0
>>  * GitHub: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjeanette-c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=a3zhMP%2FrNVToBUjwYzwyNw0RgPshLM4x1G24JDE9rA0%3D&reserved=0
>>
>> And when you say those words
>> It's the sweetest thing I've ever heard <3
>> (Britney Spears)
>>
>> Csound mailing list
>> Csound@listserv.heanet.ie
>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0
>> Send bugs reports to
>>        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0
>> Discussions of bugs and features can be posted here
>> Csound mailing list Csound@listserv.heanet.ie https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0 Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0 Discussions of bugs and features can be posted here
>> Csound mailing list Csound@listserv.heanet.ie https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0 Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0 Discussions of bugs and features can be posted here
>
>
> Csound mailing list
> Csound@listserv.heanet.ie
> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0
> Send bugs reports to
>        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0
> Discussions of bugs and features can be posted here


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

Date2023-02-16 15:43
Fromjoachim heintz
SubjectRe: [Csnd] [EXTERNAL] [Csnd] puzzled, array in UDO
hi oeyvind -

interesting to have a look at this ...

it does not work for me either, but is it really true to say it works in 
instrument 1?

when i do the same here (in my understanding), it would be:

   if ktrig > 0 then
     kindex = 0
     while kindex < lenarray(kInput) do
       kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
       kindex += 1
     od
     kInput = kOutput
     printarray kOutput
     printarray kInput
   endif

and then it does not work at all.

so it seems to me that this copying arrays with the equal sign is not 
reliable. what works for me is to copy "manually" in instr 2:

     ;copy kOOutput to gkArr
     kindx = 0
     while kindx < lenarray(kInput) do
       gkArr[kindx] = kOutput[kindx]
       kindx += 1
     od

best -
	joachim


On 16/02/2023 15:30, Oeyvind Brandtsegg wrote:
> Thanks so much. Happy to hear that it was not my own fault this time ;-)
> 
> I have a related issue, this time it is not related to processing it 
> with a UDO, but it occurs when I try to reverse the contents of a global 
> array.
> My use case is that I would like to k-rate trigger the reversal of the 
> contents of a global array in place.
> 
> My thinking was that I could do the reversal as before, and since I am 
> inside a conditional, I would only copy the reversed array back to the 
> global array once the reversal had been processed.
> 
> Example below
> 
> all best
> Øyvind
> 
> 
> 
> 
> 
> 
> gkArr[] fillarray 1,2,3,4
> 
> instr 1
>    ; works with local array
>    kInput[] fillarray 1,2,3,4
>    kOutput[] init lenarray(kInput)
>    ktrig metro 1
>    if ktrig > 0 then
>      kindex = 0
>      while kindex < lenarray(kInput) do
>        kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>        kindex += 1
>      od
>    printarray kOutput
>    endif
> endin
> 
> instr 2
>    ; does not work when I use a global array as input and copy the 
> result back to the same global array
>    kInput[] = gkArr
>    kOutput[] init lenarray(kInput)
>    ktrig metro 1
>    if ktrig > 0 then
>      kindex = 0
>      while kindex < lenarray(kInput) do
>        kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>        kindex += 1
>      od
>      gkArr = kOutput ; removing this line makes it work, ...but I would 
> like to copy the result back to the same global array
>      printarray kOutput
>      printarray gkArr
>    endif
> endin
> 
> 
> 
> i1 0 3
> i2 4 3
> e
> 
> 
> 
> tor. 16. feb. 2023 kl. 14:18 skrev Victor Lazzarini 
> >:
> 
>     I believe this is now fix in git (both csound6 and develop branches).
> 
>     ========================
>     Prof. Victor Lazzarini
>     Maynooth University
>     Ireland
> 
>      > On 16 Feb 2023, at 10:40, Victor Lazzarini
>     > wrote:
>      >
>      > yes, that’s a bug alright. I have looked at this and what happens
>     is that if there are no perf statements outside the loop,
>      > the opcode behaves in such a way that the loop is ignored.
>     However if you insert any statement (like kindex = kindex) then
>      > it works correctly. For example,
>      >
>      > opcode Test0, k, k
>      >  kindex xin
>      >  while kindex < 3 do
>      >    kindex += 1
>      >  od
>      >  xout kindex
>      > endop
>      >
>      > doesn’t work correctly, but this one does
>      >
>      > opcode Test1, k, k
>      >  kindex xin
>      >  k1 = 0
>      >  while kindex < 3 do
>      >    kindex += 1
>      >  od
>      >  xout kindex
>      > endop
>      >
>      > I know that if there are no perf statements in a UDO there’s no
>     perf cycle, but here we are ignoring perf statements inside
>      > the loop. We’ll fix this.
>      > ========================
>      > Prof. Victor Lazzarini
>      > Maynooth University
>      > Ireland
>      >
>      >> On 16 Feb 2023, at 01:39, Aaron Krister Johnson
>     > wrote:
>      >>
>      >> WARNINGThis email originated from outside of Maynooth
>     University's Mail System. Do not reply, click links or open
>     attachments unless you recognise the sender and know the content is
>     safe.
>      >> Ah, it must be that the assignment to a local scope needs to happen.
>      >>
>      >> To be filed away under "things to remember when you need to loop
>     in an UDO"
>      >>
>      >>
>      >> Aaron Krister Johnson
>      >> Music, etc.:
>      >>
>     https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.untwelve.org%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=82WVd%2F7SkjwJvK%2BSKQVrvPhDNjJB532n%2BL1lSAn2ZwE%3D&reserved=0 
>      >>
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUC_utjGYbSizWE0dNyr0Vdmg&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hzNV42ViOz1AR9CQsdUe2Nsq9PwcTiJST6hHBkO0m3I%3D&reserved=0 
>      >>
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Faaron-krister-johnson&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=SVfxPZwhQ8Q8ZF7JVd1eFu9lgBlHzTdwtLrt2fBC3pM%3D&reserved=0 
>      >>
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Ffiltercreed&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=52HeYu1t%2B5GIXVBQIsQje5cJyYrn4hXpklqYLI4jAUE%3D&reserved=0 
>      >>
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faaronkristerjohnson.bandcamp.com%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=PBqx7PqVa3J5CEu%2BWF71Kl6mkx6X0A2abrKMZ0MNlbs%3D&reserved=0 
>      >> Code:
>      >>
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fakjmicro&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2NnDOiEYbo7TCKl27CsSuLUP2dXVoWNDs2mmwLG1lz0%3D&reserved=0 
>      >>
>      >>
>      >> On Wed, Feb 15, 2023 at 4:08 PM Oeyvind Brandtsegg
>     > wrote:
>      >> Whoa, yes, guillermo, it does fix it.
>      >> Like this.
>      >> That is indeed strange(?)
>      >>
>      >> ; UDO to reverse the order of an array at k-rate
>      >> opcode Reverse, k[], k[]k
>      >>  kInput[], kindex xin
>      >>  kOutput[] init lenarray(kInput)
>      >>  kindex = kindex
>      >>  while kindex < lenarray(kInput) do
>      >>    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>      >>    kindex += 1
>      >>  od
>      >>  xout kOutput
>      >> endop
>      >>
>      >>
>      >> tor. 16. feb. 2023 kl. 00:03 skrev Oeyvind Brandtsegg
>     >:
>      >> Hi,  yes i did have the index inside at first,  and it worked
>     the same.
>      >> But your suggestion of putting the ktrig inside the UDO makes it
>     work.
>      >> Thanks
>      >>
>      >>
>      >> ons. 15. feb. 2023, 22:27 skrev Jeanette C.      >:
>      >> Hey hey Oeyvind,
>      >> why do you pass the index to your k-rate opcode? This ight be an
>     issue. Have
>      >> you tried setting up the kIndex inside the opcode and perhaps
>     passing the
>      >> trigger and also have the if (kTrig == 1) statement inside the
>     opcode. I
>      >> didn't test it, but it feels odd reading it like this.
>      >>
>      >> HTH.
>      >>
>      >> Best wishes,
>      >>
>      >> Jeanette
>      >>
>      >> Feb 15 2023, Oeyvind Brandtsegg has written:
>      >>
>      >>> Hi
>      >>>
>      >>> I am puzzled by how this (does not) work. There is probably
>     something I
>      >>> misunderstand about internal Csound processes, so I thought I
>     might ask
>      >>> here to get help understanding it.
>      >>>
>      >>> I am trying to make a UDO to reverse the order of all elements
>     in an array.
>      >>> It is easy enough at i-rate, and I can make the code work at
>     k-rate if I do
>      >>> it inline (not in a UDO), but I fail to make it work with
>     k-rate arrays in
>      >>> a UDO.
>      >>> My code to reverse the order of elements is:
>      >>>   kindex = 0
>      >>>   while kindex < lenarray(kInput) do
>      >>>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>      >>>     kindex += 1
>      >>>   od
>      >>>
>      >>> A full csd showing both the i-rate UDO, k-rate UDO, and regular
>     Csound code
>      >>> (without UDO) is pasted below. The problem shows in instr 1
>     (k-rate UDO).
>      >>> Any help is greatly appreciated.
>      >>>
>      >>> all best
>      >>> Øyvind
>      >>>
>      >>> 
>      >>> 
>      >>> 
>      >>> 
>      >>>
>      >>> ; UDO to reverse the order of an array at i-rate
>      >>> opcode Reverse, i[], i[]
>      >>> iInput[] xin
>      >>> iOutput[] init lenarray(iInput)
>      >>> index = 0
>      >>> while index < lenarray(iInput) do
>      >>>   iOutput[index] = iInput[lenarray(iInput)-1-index]
>      >>>   index += 1
>      >>> od
>      >>> xout iOutput
>      >>> endop
>      >>>
>      >>> ; UDO to reverse the order of an array at k-rate
>      >>> opcode Reverse, k[], k[]k
>      >>> kInput[], kindex xin
>      >>> kOutput[] init lenarray(kInput)
>      >>> while kindex < lenarray(kInput) do
>      >>>   kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>      >>>   kindex += 1
>      >>> od
>      >>> xout kOutput
>      >>> endop
>      >>>
>      >>> instr 1
>      >>> ; it does not work when the reversal is inside a UDO
>      >>> p3 = 4/kr
>      >>> kInput[] fillarray 1,2,3,4
>      >>> ktrig metro 1
>      >>> if ktrig > 0 then
>      >>>   kindex = 0
>      >>>   kOutput[] Reverse kInput, kindex
>      >>> endif
>      >>> printarray kOutput
>      >>> endin
>      >>>
>      >>> instr 2
>      >>> ; this one works as expected, when the reversal is not in a UDO
>      >>> p3 = 4/kr
>      >>> kInput[] fillarray 1,2,3,4
>      >>> kOutput[] init lenarray(kInput)
>      >>> ktrig metro 1
>      >>> if ktrig > 0 then
>      >>>   kindex = 0
>      >>>   while kindex < lenarray(kInput) do
>      >>>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>      >>>     kindex += 1
>      >>>   od
>      >>> endif
>      >>> printarray kOutput
>      >>> endin
>      >>>
>      >>> instr 3
>      >>> ; it also works fine in a UDO with i-rate arrays
>      >>> iInput[] fillarray 1,2,3,4
>      >>> iOutput[] Reverse iInput
>      >>> printarray iOutput
>      >>> endin
>      >>>
>      >>> 
>      >>> 
>      >>> i1 0 .1
>      >>> i2 1 .1
>      >>> i3 2 .1
>      >>> e
>      >>> 
>      >>> 
>      >>>
>      >>> Csound mailing list
>      >>> Csound@listserv.heanet.ie 
>      >>>
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0 
>      >>> Send bugs reports to
>      >>>
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0 
>      >>> Discussions of bugs and features can be posted here
>      >>>
>      >>
>      >> --
>      >>  * Website:
>     https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fjuliencoder.de%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=WJhyCJUerfSgM84mbFKFEc%2FbEbrmbK8DCkpCrhTSO3g%3D&reserved=0  - for summer is a state of sound
>      >>  * Youtube:
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUCMS4rfGrTwz8W7jhC1Jnv7g&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RZJINBO85WJOXeLu5Xth9s%2Fjmu%2FPkqJfPjsoAfr4EdU%3D&reserved=0 
>      >>  * Audiobombs:
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.audiobombs.com%2Fusers%2Fjeanette_c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=5CaGO6NQTlGJf%2Fabt%2FpjByKNnrU3L3%2FYXt0KF%2B0nP9A%3D&reserved=0 
>      >>  * GitHub:
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjeanette-c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=a3zhMP%2FrNVToBUjwYzwyNw0RgPshLM4x1G24JDE9rA0%3D&reserved=0 
>      >>
>      >> And when you say those words
>      >> It's the sweetest thing I've ever heard <3
>      >> (Britney Spears)
>      >>
>      >> Csound mailing list
>      >> Csound@listserv.heanet.ie 
>      >>
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0 
>      >> Send bugs reports to
>      >>
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0 
>      >> Discussions of bugs and features can be posted here
>      >> Csound mailing list Csound@listserv.heanet.ie
>     
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0  Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0  Discussions of bugs and features can be posted here
>      >> Csound mailing list Csound@listserv.heanet.ie
>     
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0  Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0  Discussions of bugs and features can be posted here
>      >
>      >
>      > Csound mailing list
>      > Csound@listserv.heanet.ie 
>      >
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0 
>      > Send bugs reports to
>      >
>     https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0 
>      > Discussions of bugs and features can be posted here
> 
> 
>     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
> 
> 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

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

Date2023-02-16 15:57
FromVictor Lazzarini
SubjectRe: [Csnd] [EXTERNAL] [Csnd] puzzled, array in UDO
It looks like the problem is that the copy happens at both i-time and perf-time. Since at i-time kOutput is all zeros, that gets copy to the global array and
then to kInput and so it’s zeros all the way. I have added a special k-rate copying opcode that gets called at i-time only to allocate memory if needed and
then copies only at k-rate. This is for csound 6 and it’s in the csound6 branch now. I tested your code and it passes.

In Csound 7, the code is parsed differently and the copy only happens at i-time (which is also wrong and needs fixing, but the problem is one that we
know of, code being parsed to use a =.generic opcode that is causing trouble also elsewhere).That’ll probably need to be addressed differently.

========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 16 Feb 2023, at 14:30, Oeyvind Brandtsegg  wrote:
> 
> Thanks so much. Happy to hear that it was not my own fault this time ;-)
> 
> I have a related issue, this time it is not related to processing it with a UDO, but it occurs when I try to reverse the contents of a global array.
> My use case is that I would like to k-rate trigger the reversal of the contents of a global array in place.
> 
> My thinking was that I could do the reversal as before, and since I am inside a conditional, I would only copy the reversed array back to the global array once the reversal had been processed. 
> 
> Example below
> 
> all best
> Øyvind
> 
> 
> 
> 
> 
> 
> gkArr[] fillarray 1,2,3,4
> 
> instr 1
>   ; works with local array
>   kInput[] fillarray 1,2,3,4
>   kOutput[] init lenarray(kInput)
>   ktrig metro 1
>   if ktrig > 0 then
>     kindex = 0
>     while kindex < lenarray(kInput) do
>       kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>       kindex += 1
>     od
>   printarray kOutput
>   endif
> endin
> 
> instr 2
>   ; does not work when I use a global array as input and copy the result back to the same global array
>   kInput[] = gkArr
>   kOutput[] init lenarray(kInput)
>   ktrig metro 1
>   if ktrig > 0 then
>     kindex = 0
>     while kindex < lenarray(kInput) do
>       kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>       kindex += 1
>     od
>     gkArr = kOutput ; removing this line makes it work, ...but I would like to copy the result back to the same global array
>     printarray kOutput
>     printarray gkArr
>   endif
> endin
> 
> 
> 
> i1 0 3
> i2 4 3
> e
> 
> 
> 
> tor. 16. feb. 2023 kl. 14:18 skrev Victor Lazzarini :
> I believe this is now fix in git (both csound6 and develop branches).
> 
> ========================
> Prof. Victor Lazzarini
> Maynooth University
> Ireland
> 
> > On 16 Feb 2023, at 10:40, Victor Lazzarini  wrote:
> > 
> > yes, that’s a bug alright. I have looked at this and what happens is that if there are no perf statements outside the loop,
> > the opcode behaves in such a way that the loop is ignored. However if you insert any statement (like kindex = kindex) then
> > it works correctly. For example,
> > 
> > opcode Test0, k, k
> >  kindex xin
> >  while kindex < 3 do
> >    kindex += 1
> >  od  
> >  xout kindex
> > endop
> > 
> > doesn’t work correctly, but this one does
> > 
> > opcode Test1, k, k
> >  kindex xin
> >  k1 = 0
> >  while kindex < 3 do
> >    kindex += 1
> >  od  
> >  xout kindex
> > endop
> > 
> > I know that if there are no perf statements in a UDO there’s no perf cycle, but here we are ignoring perf statements inside
> > the loop. We’ll fix this.
> > ========================
> > Prof. Victor Lazzarini
> > Maynooth University
> > Ireland
> > 
> >> On 16 Feb 2023, at 01:39, Aaron Krister Johnson  wrote:
> >> 
> >> WARNINGThis email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
> >> Ah, it must be that the assignment to a local scope needs to happen.
> >> 
> >> To be filed away under "things to remember when you need to loop in an UDO"
> >> 
> >> 
> >> Aaron Krister Johnson
> >> Music, etc.:
> >> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.untwelve.org%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=82WVd%2F7SkjwJvK%2BSKQVrvPhDNjJB532n%2BL1lSAn2ZwE%3D&reserved=0
> >> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUC_utjGYbSizWE0dNyr0Vdmg&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hzNV42ViOz1AR9CQsdUe2Nsq9PwcTiJST6hHBkO0m3I%3D&reserved=0
> >> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Faaron-krister-johnson&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=SVfxPZwhQ8Q8ZF7JVd1eFu9lgBlHzTdwtLrt2fBC3pM%3D&reserved=0
> >> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Ffiltercreed&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=52HeYu1t%2B5GIXVBQIsQje5cJyYrn4hXpklqYLI4jAUE%3D&reserved=0
> >> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faaronkristerjohnson.bandcamp.com%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=PBqx7PqVa3J5CEu%2BWF71Kl6mkx6X0A2abrKMZ0MNlbs%3D&reserved=0
> >> Code:
> >> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fakjmicro&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2NnDOiEYbo7TCKl27CsSuLUP2dXVoWNDs2mmwLG1lz0%3D&reserved=0
> >> 
> >> 
> >> On Wed, Feb 15, 2023 at 4:08 PM Oeyvind Brandtsegg  wrote:
> >> Whoa, yes, guillermo, it does fix it.
> >> Like this. 
> >> That is indeed strange(?)
> >> 
> >> ; UDO to reverse the order of an array at k-rate
> >> opcode Reverse, k[], k[]k
> >>  kInput[], kindex xin
> >>  kOutput[] init lenarray(kInput)
> >>  kindex = kindex
> >>  while kindex < lenarray(kInput) do
> >>    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
> >>    kindex += 1
> >>  od
> >>  xout kOutput
> >> endop
> >> 
> >> 
> >> tor. 16. feb. 2023 kl. 00:03 skrev Oeyvind Brandtsegg :
> >> Hi,  yes i did have the index inside at first,  and it worked the same.  
> >> But your suggestion of putting the ktrig inside the UDO makes it work.
> >> Thanks 
> >> 
> >> 
> >> ons. 15. feb. 2023, 22:27 skrev Jeanette C. :
> >> Hey hey Oeyvind,
> >> why do you pass the index to your k-rate opcode? This ight be an issue. Have 
> >> you tried setting up the kIndex inside the opcode and perhaps passing the 
> >> trigger and also have the if (kTrig == 1) statement inside the opcode. I 
> >> didn't test it, but it feels odd reading it like this.
> >> 
> >> HTH.
> >> 
> >> Best wishes,
> >> 
> >> Jeanette
> >> 
> >> Feb 15 2023, Oeyvind Brandtsegg has written:
> >> 
> >>> Hi
> >>> 
> >>> I am puzzled by how this (does not) work. There is probably something I
> >>> misunderstand about internal Csound processes, so I thought I might ask
> >>> here to get help understanding it.
> >>> 
> >>> I am trying to make a UDO to reverse the order of all elements in an array.
> >>> It is easy enough at i-rate, and I can make the code work at k-rate if I do
> >>> it inline (not in a UDO), but I fail to make it work with k-rate arrays in
> >>> a UDO.
> >>> My code to reverse the order of elements is:
> >>>   kindex = 0
> >>>   while kindex < lenarray(kInput) do
> >>>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
> >>>     kindex += 1
> >>>   od
> >>> 
> >>> A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code
> >>> (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
> >>> Any help is greatly appreciated.
> >>> 
> >>> all best
> >>> Øyvind
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> 
> >>> ; UDO to reverse the order of an array at i-rate
> >>> opcode Reverse, i[], i[]
> >>> iInput[] xin
> >>> iOutput[] init lenarray(iInput)
> >>> index = 0
> >>> while index < lenarray(iInput) do
> >>>   iOutput[index] = iInput[lenarray(iInput)-1-index]
> >>>   index += 1
> >>> od
> >>> xout iOutput
> >>> endop
> >>> 
> >>> ; UDO to reverse the order of an array at k-rate
> >>> opcode Reverse, k[], k[]k
> >>> kInput[], kindex xin
> >>> kOutput[] init lenarray(kInput)
> >>> while kindex < lenarray(kInput) do
> >>>   kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
> >>>   kindex += 1
> >>> od
> >>> xout kOutput
> >>> endop
> >>> 
> >>> instr 1
> >>> ; it does not work when the reversal is inside a UDO
> >>> p3 = 4/kr
> >>> kInput[] fillarray 1,2,3,4
> >>> ktrig metro 1
> >>> if ktrig > 0 then
> >>>   kindex = 0
> >>>   kOutput[] Reverse kInput, kindex
> >>> endif
> >>> printarray kOutput
> >>> endin
> >>> 
> >>> instr 2
> >>> ; this one works as expected, when the reversal is not in a UDO
> >>> p3 = 4/kr
> >>> kInput[] fillarray 1,2,3,4
> >>> kOutput[] init lenarray(kInput)
> >>> ktrig metro 1
> >>> if ktrig > 0 then
> >>>   kindex = 0
> >>>   while kindex < lenarray(kInput) do
> >>>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
> >>>     kindex += 1
> >>>   od
> >>> endif
> >>> printarray kOutput
> >>> endin
> >>> 
> >>> instr 3
> >>> ; it also works fine in a UDO with i-rate arrays
> >>> iInput[] fillarray 1,2,3,4
> >>> iOutput[] Reverse iInput
> >>> printarray iOutput
> >>> endin
> >>> 
> >>> 
> >>> 
> >>> i1 0 .1
> >>> i2 1 .1
> >>> i3 2 .1
> >>> e
> >>> 
> >>> 
> >>> 
> >>> Csound mailing list
> >>> Csound@listserv.heanet.ie
> >>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0
> >>> Send bugs reports to
> >>>       https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0
> >>> Discussions of bugs and features can be posted here
> >>> 
> >> 
> >> -- 
> >>  * Website: https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fjuliencoder.de%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=WJhyCJUerfSgM84mbFKFEc%2FbEbrmbK8DCkpCrhTSO3g%3D&reserved=0 - for summer is a state of sound
> >>  * Youtube: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUCMS4rfGrTwz8W7jhC1Jnv7g&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RZJINBO85WJOXeLu5Xth9s%2Fjmu%2FPkqJfPjsoAfr4EdU%3D&reserved=0
> >>  * Audiobombs: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.audiobombs.com%2Fusers%2Fjeanette_c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=5CaGO6NQTlGJf%2Fabt%2FpjByKNnrU3L3%2FYXt0KF%2B0nP9A%3D&reserved=0
> >>  * GitHub: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjeanette-c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=a3zhMP%2FrNVToBUjwYzwyNw0RgPshLM4x1G24JDE9rA0%3D&reserved=0
> >> 
> >> And when you say those words
> >> It's the sweetest thing I've ever heard <3
> >> (Britney Spears)
> >> 
> >> Csound mailing list
> >> Csound@listserv.heanet.ie
> >> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0
> >> Send bugs reports to
> >>        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0
> >> Discussions of bugs and features can be posted here
> >> Csound mailing list Csound@listserv.heanet.ie https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0 Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0 Discussions of bugs and features can be posted here
> >> Csound mailing list Csound@listserv.heanet.ie https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0 Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0 Discussions of bugs and features can be posted here
> > 
> > 
> > Csound mailing list
> > Csound@listserv.heanet.ie
> > https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0
> > Send bugs reports to
> >        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0
> > Discussions of bugs and features can be posted here
> 
> 
> 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
> 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


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

Date2023-02-16 16:12
FromGuillermo Senna
SubjectRe: [Csnd] [EXTERNAL] [Csnd] puzzled, array in UDO
The use of gotos is discouraged, but -based on what Victor said- if you 
don't want to update yet this should fix it:

     igoto jump
     gkArr = kOutput ; removing this line makes it work, ...but I would 
like to copy the result back to the same global array
jump:
     printarray gkArr

On 16/2/23 12:57, Victor Lazzarini wrote:
> It looks like the problem is that the copy happens at both i-time and perf-time. Since at i-time kOutput is all zeros, that gets copy to the global array and
> then to kInput and so it’s zeros all the way. I have added a special k-rate copying opcode that gets called at i-time only to allocate memory if needed and
> then copies only at k-rate. This is for csound 6 and it’s in the csound6 branch now. I tested your code and it passes.
>
> In Csound 7, the code is parsed differently and the copy only happens at i-time (which is also wrong and needs fixing, but the problem is one that we
> know of, code being parsed to use a =.generic opcode that is causing trouble also elsewhere).That’ll probably need to be addressed differently.
>
> ========================
> Prof. Victor Lazzarini
> Maynooth University
> Ireland
>
>> On 16 Feb 2023, at 14:30, Oeyvind Brandtsegg  wrote:
>>
>> Thanks so much. Happy to hear that it was not my own fault this time ;-)
>>
>> I have a related issue, this time it is not related to processing it with a UDO, but it occurs when I try to reverse the contents of a global array.
>> My use case is that I would like to k-rate trigger the reversal of the contents of a global array in place.
>>
>> My thinking was that I could do the reversal as before, and since I am inside a conditional, I would only copy the reversed array back to the global array once the reversal had been processed.
>>
>> Example below
>>
>> all best
>> Øyvind
>>
>> 
>> 
>> 
>> 
>>
>> gkArr[] fillarray 1,2,3,4
>>
>> instr 1
>>    ; works with local array
>>    kInput[] fillarray 1,2,3,4
>>    kOutput[] init lenarray(kInput)
>>    ktrig metro 1
>>    if ktrig > 0 then
>>      kindex = 0
>>      while kindex < lenarray(kInput) do
>>        kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>        kindex += 1
>>      od
>>    printarray kOutput
>>    endif
>> endin
>>
>> instr 2
>>    ; does not work when I use a global array as input and copy the result back to the same global array
>>    kInput[] = gkArr
>>    kOutput[] init lenarray(kInput)
>>    ktrig metro 1
>>    if ktrig > 0 then
>>      kindex = 0
>>      while kindex < lenarray(kInput) do
>>        kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>        kindex += 1
>>      od
>>      gkArr = kOutput ; removing this line makes it work, ...but I would like to copy the result back to the same global array
>>      printarray kOutput
>>      printarray gkArr
>>    endif
>> endin
>>
>> 
>> 
>> i1 0 3
>> i2 4 3
>> e
>> 
>> 
>>
>> tor. 16. feb. 2023 kl. 14:18 skrev Victor Lazzarini :
>> I believe this is now fix in git (both csound6 and develop branches).
>>
>> ========================
>> Prof. Victor Lazzarini
>> Maynooth University
>> Ireland
>>
>>> On 16 Feb 2023, at 10:40, Victor Lazzarini  wrote:
>>>
>>> yes, that’s a bug alright. I have looked at this and what happens is that if there are no perf statements outside the loop,
>>> the opcode behaves in such a way that the loop is ignored. However if you insert any statement (like kindex = kindex) then
>>> it works correctly. For example,
>>>
>>> opcode Test0, k, k
>>>   kindex xin
>>>   while kindex < 3 do
>>>     kindex += 1
>>>   od
>>>   xout kindex
>>> endop
>>>
>>> doesn’t work correctly, but this one does
>>>
>>> opcode Test1, k, k
>>>   kindex xin
>>>   k1 = 0
>>>   while kindex < 3 do
>>>     kindex += 1
>>>   od
>>>   xout kindex
>>> endop
>>>
>>> I know that if there are no perf statements in a UDO there’s no perf cycle, but here we are ignoring perf statements inside
>>> the loop. We’ll fix this.
>>> ========================
>>> Prof. Victor Lazzarini
>>> Maynooth University
>>> Ireland
>>>
>>>> On 16 Feb 2023, at 01:39, Aaron Krister Johnson  wrote:
>>>>
>>>> WARNINGThis email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
>>>> Ah, it must be that the assignment to a local scope needs to happen.
>>>>
>>>> To be filed away under "things to remember when you need to loop in an UDO"
>>>>
>>>>
>>>> Aaron Krister Johnson
>>>> Music, etc.:
>>>> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.untwelve.org%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=82WVd%2F7SkjwJvK%2BSKQVrvPhDNjJB532n%2BL1lSAn2ZwE%3D&reserved=0
>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUC_utjGYbSizWE0dNyr0Vdmg&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hzNV42ViOz1AR9CQsdUe2Nsq9PwcTiJST6hHBkO0m3I%3D&reserved=0
>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Faaron-krister-johnson&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=SVfxPZwhQ8Q8ZF7JVd1eFu9lgBlHzTdwtLrt2fBC3pM%3D&reserved=0
>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Ffiltercreed&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=52HeYu1t%2B5GIXVBQIsQje5cJyYrn4hXpklqYLI4jAUE%3D&reserved=0
>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faaronkristerjohnson.bandcamp.com%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=PBqx7PqVa3J5CEu%2BWF71Kl6mkx6X0A2abrKMZ0MNlbs%3D&reserved=0
>>>> Code:
>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fakjmicro&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2NnDOiEYbo7TCKl27CsSuLUP2dXVoWNDs2mmwLG1lz0%3D&reserved=0
>>>>
>>>>
>>>> On Wed, Feb 15, 2023 at 4:08 PM Oeyvind Brandtsegg  wrote:
>>>> Whoa, yes, guillermo, it does fix it.
>>>> Like this.
>>>> That is indeed strange(?)
>>>>
>>>> ; UDO to reverse the order of an array at k-rate
>>>> opcode Reverse, k[], k[]k
>>>>   kInput[], kindex xin
>>>>   kOutput[] init lenarray(kInput)
>>>>   kindex = kindex
>>>>   while kindex < lenarray(kInput) do
>>>>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>>     kindex += 1
>>>>   od
>>>>   xout kOutput
>>>> endop
>>>>
>>>>
>>>> tor. 16. feb. 2023 kl. 00:03 skrev Oeyvind Brandtsegg :
>>>> Hi,  yes i did have the index inside at first,  and it worked the same.
>>>> But your suggestion of putting the ktrig inside the UDO makes it work.
>>>> Thanks
>>>>
>>>>
>>>> ons. 15. feb. 2023, 22:27 skrev Jeanette C. :
>>>> Hey hey Oeyvind,
>>>> why do you pass the index to your k-rate opcode? This ight be an issue. Have
>>>> you tried setting up the kIndex inside the opcode and perhaps passing the
>>>> trigger and also have the if (kTrig == 1) statement inside the opcode. I
>>>> didn't test it, but it feels odd reading it like this.
>>>>
>>>> HTH.
>>>>
>>>> Best wishes,
>>>>
>>>> Jeanette
>>>>
>>>> Feb 15 2023, Oeyvind Brandtsegg has written:
>>>>
>>>>> Hi
>>>>>
>>>>> I am puzzled by how this (does not) work. There is probably something I
>>>>> misunderstand about internal Csound processes, so I thought I might ask
>>>>> here to get help understanding it.
>>>>>
>>>>> I am trying to make a UDO to reverse the order of all elements in an array.
>>>>> It is easy enough at i-rate, and I can make the code work at k-rate if I do
>>>>> it inline (not in a UDO), but I fail to make it work with k-rate arrays in
>>>>> a UDO.
>>>>> My code to reverse the order of elements is:
>>>>>    kindex = 0
>>>>>    while kindex < lenarray(kInput) do
>>>>>      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>>>      kindex += 1
>>>>>    od
>>>>>
>>>>> A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code
>>>>> (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
>>>>> Any help is greatly appreciated.
>>>>>
>>>>> all best
>>>>> Øyvind
>>>>>
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>>
>>>>> ; UDO to reverse the order of an array at i-rate
>>>>> opcode Reverse, i[], i[]
>>>>> iInput[] xin
>>>>> iOutput[] init lenarray(iInput)
>>>>> index = 0
>>>>> while index < lenarray(iInput) do
>>>>>    iOutput[index] = iInput[lenarray(iInput)-1-index]
>>>>>    index += 1
>>>>> od
>>>>> xout iOutput
>>>>> endop
>>>>>
>>>>> ; UDO to reverse the order of an array at k-rate
>>>>> opcode Reverse, k[], k[]k
>>>>> kInput[], kindex xin
>>>>> kOutput[] init lenarray(kInput)
>>>>> while kindex < lenarray(kInput) do
>>>>>    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>>>    kindex += 1
>>>>> od
>>>>> xout kOutput
>>>>> endop
>>>>>
>>>>> instr 1
>>>>> ; it does not work when the reversal is inside a UDO
>>>>> p3 = 4/kr
>>>>> kInput[] fillarray 1,2,3,4
>>>>> ktrig metro 1
>>>>> if ktrig > 0 then
>>>>>    kindex = 0
>>>>>    kOutput[] Reverse kInput, kindex
>>>>> endif
>>>>> printarray kOutput
>>>>> endin
>>>>>
>>>>> instr 2
>>>>> ; this one works as expected, when the reversal is not in a UDO
>>>>> p3 = 4/kr
>>>>> kInput[] fillarray 1,2,3,4
>>>>> kOutput[] init lenarray(kInput)
>>>>> ktrig metro 1
>>>>> if ktrig > 0 then
>>>>>    kindex = 0
>>>>>    while kindex < lenarray(kInput) do
>>>>>      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>>>      kindex += 1
>>>>>    od
>>>>> endif
>>>>> printarray kOutput
>>>>> endin
>>>>>
>>>>> instr 3
>>>>> ; it also works fine in a UDO with i-rate arrays
>>>>> iInput[] fillarray 1,2,3,4
>>>>> iOutput[] Reverse iInput
>>>>> printarray iOutput
>>>>> endin
>>>>>
>>>>> 
>>>>> 
>>>>> i1 0 .1
>>>>> i2 1 .1
>>>>> i3 2 .1
>>>>> e
>>>>> 
>>>>> 
>>>>>
>>>>> Csound mailing list
>>>>> Csound@listserv.heanet.ie
>>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0
>>>>> Send bugs reports to
>>>>>        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0
>>>>> Discussions of bugs and features can be posted here
>>>>>
>>>> -- 
>>>>   * Website: https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fjuliencoder.de%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=WJhyCJUerfSgM84mbFKFEc%2FbEbrmbK8DCkpCrhTSO3g%3D&reserved=0 - for summer is a state of sound
>>>>   * Youtube: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUCMS4rfGrTwz8W7jhC1Jnv7g&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RZJINBO85WJOXeLu5Xth9s%2Fjmu%2FPkqJfPjsoAfr4EdU%3D&reserved=0
>>>>   * Audiobombs: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.audiobombs.com%2Fusers%2Fjeanette_c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=5CaGO6NQTlGJf%2Fabt%2FpjByKNnrU3L3%2FYXt0KF%2B0nP9A%3D&reserved=0
>>>>   * GitHub: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjeanette-c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=a3zhMP%2FrNVToBUjwYzwyNw0RgPshLM4x1G24JDE9rA0%3D&reserved=0
>>>>
>>>> And when you say those words
>>>> It's the sweetest thing I've ever heard <3
>>>> (Britney Spears)
>>>>
>>>> Csound mailing list
>>>> Csound@listserv.heanet.ie
>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0
>>>> Send bugs reports to
>>>>         https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0
>>>> Discussions of bugs and features can be posted here
>>>> Csound mailing list Csound@listserv.heanet.ie https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0 Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0 Discussions of bugs and features can be posted here
>>>> Csound mailing list Csound@listserv.heanet.ie https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0 Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0 Discussions of bugs and features can be posted here
>>>
>>> Csound mailing list
>>> Csound@listserv.heanet.ie
>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0
>>> Send bugs reports to
>>>         https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0
>>> Discussions of bugs and features can be posted here
>>
>> 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
>> 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
>
> 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

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

Date2023-02-17 12:49
FromOeyvind Brandtsegg
SubjectRe: [Csnd] [EXTERNAL] [Csnd] puzzled, array in UDO
Ah, thanks, yes now I understand the cause of the problem. Thanks for the fix, and good to know it is being addressed for future improvements too.

tor. 16. feb. 2023 kl. 16:57 skrev Victor Lazzarini <Victor.Lazzarini@mu.ie>:
It looks like the problem is that the copy happens at both i-time and perf-time. Since at i-time kOutput is all zeros, that gets copy to the global array and
then to kInput and so it’s zeros all the way. I have added a special k-rate copying opcode that gets called at i-time only to allocate memory if needed and
then copies only at k-rate. This is for csound 6 and it’s in the csound6 branch now. I tested your code and it passes.

In Csound 7, the code is parsed differently and the copy only happens at i-time (which is also wrong and needs fixing, but the problem is one that we
know of, code being parsed to use a =.generic opcode that is causing trouble also elsewhere).That’ll probably need to be addressed differently.

========================
Prof. Victor Lazzarini
Maynooth University
Ireland

> On 16 Feb 2023, at 14:30, Oeyvind Brandtsegg <obrandts@GMAIL.COM> wrote:
>
> Thanks so much. Happy to hear that it was not my own fault this time ;-)
>
> I have a related issue, this time it is not related to processing it with a UDO, but it occurs when I try to reverse the contents of a global array.
> My use case is that I would like to k-rate trigger the reversal of the contents of a global array in place.
>
> My thinking was that I could do the reversal as before, and since I am inside a conditional, I would only copy the reversed array back to the global array once the reversal had been processed.
>
> Example below
>
> all best
> Øyvind
>
> <CsoundSynthesizer>
> <CsOptions>
> </CsOptions>
> <CsInstruments>
>
> gkArr[] fillarray 1,2,3,4
>
> instr 1
>   ; works with local array
>   kInput[] fillarray 1,2,3,4
>   kOutput[] init lenarray(kInput)
>   ktrig metro 1
>   if ktrig > 0 then
>     kindex = 0
>     while kindex < lenarray(kInput) do
>       kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>       kindex += 1
>     od
>   printarray kOutput
>   endif
> endin
>
> instr 2
>   ; does not work when I use a global array as input and copy the result back to the same global array
>   kInput[] = gkArr
>   kOutput[] init lenarray(kInput)
>   ktrig metro 1
>   if ktrig > 0 then
>     kindex = 0
>     while kindex < lenarray(kInput) do
>       kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>       kindex += 1
>     od
>     gkArr = kOutput ; removing this line makes it work, ...but I would like to copy the result back to the same global array
>     printarray kOutput
>     printarray gkArr
>   endif
> endin
>
> </CsInstruments>
> <CsScore>
> i1 0 3
> i2 4 3
> e
> </CsScore>
> </CsoundSynthesizer>
>
> tor. 16. feb. 2023 kl. 14:18 skrev Victor Lazzarini <Victor.Lazzarini@mu.ie>:
> I believe this is now fix in git (both csound6 and develop branches).
>
> ========================
> Prof. Victor Lazzarini
> Maynooth University
> Ireland
>
> > On 16 Feb 2023, at 10:40, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
> >
> > yes, that’s a bug alright. I have looked at this and what happens is that if there are no perf statements outside the loop,
> > the opcode behaves in such a way that the loop is ignored. However if you insert any statement (like kindex = kindex) then
> > it works correctly. For example,
> >
> > opcode Test0, k, k
> >  kindex xin
> >  while kindex < 3 do
> >    kindex += 1
> >  od 
> >  xout kindex
> > endop
> >
> > doesn’t work correctly, but this one does
> >
> > opcode Test1, k, k
> >  kindex xin
> >  k1 = 0
> >  while kindex < 3 do
> >    kindex += 1
> >  od 
> >  xout kindex
> > endop
> >
> > I know that if there are no perf statements in a UDO there’s no perf cycle, but here we are ignoring perf statements inside
> > the loop. We’ll fix this.
> > ========================
> > Prof. Victor Lazzarini
> > Maynooth University
> > Ireland
> >
> >> On 16 Feb 2023, at 01:39, Aaron Krister Johnson <akjmicro@GMAIL.COM> wrote:
> >>
> >> WARNINGThis email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
> >> Ah, it must be that the assignment to a local scope needs to happen.
> >>
> >> To be filed away under "things to remember when you need to loop in an UDO"
> >>
> >>
> >> Aaron Krister Johnson
> >> Music, etc.:
> >> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.untwelve.org%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=82WVd%2F7SkjwJvK%2BSKQVrvPhDNjJB532n%2BL1lSAn2ZwE%3D&reserved=0
> >> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUC_utjGYbSizWE0dNyr0Vdmg&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hzNV42ViOz1AR9CQsdUe2Nsq9PwcTiJST6hHBkO0m3I%3D&reserved=0
> >> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Faaron-krister-johnson&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=SVfxPZwhQ8Q8ZF7JVd1eFu9lgBlHzTdwtLrt2fBC3pM%3D&reserved=0
> >> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Ffiltercreed&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=52HeYu1t%2B5GIXVBQIsQje5cJyYrn4hXpklqYLI4jAUE%3D&reserved=0
> >> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faaronkristerjohnson.bandcamp.com%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=PBqx7PqVa3J5CEu%2BWF71Kl6mkx6X0A2abrKMZ0MNlbs%3D&reserved=0
> >> Code:
> >> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fakjmicro&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2NnDOiEYbo7TCKl27CsSuLUP2dXVoWNDs2mmwLG1lz0%3D&reserved=0
> >>
> >>
> >> On Wed, Feb 15, 2023 at 4:08 PM Oeyvind Brandtsegg <obrandts@gmail.com> wrote:
> >> Whoa, yes, guillermo, it does fix it.
> >> Like this.
> >> That is indeed strange(?)
> >>
> >> ; UDO to reverse the order of an array at k-rate
> >> opcode Reverse, k[], k[]k
> >>  kInput[], kindex xin
> >>  kOutput[] init lenarray(kInput)
> >>  kindex = kindex
> >>  while kindex < lenarray(kInput) do
> >>    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
> >>    kindex += 1
> >>  od
> >>  xout kOutput
> >> endop
> >>
> >>
> >> tor. 16. feb. 2023 kl. 00:03 skrev Oeyvind Brandtsegg <obrandts@gmail.com>:
> >> Hi,  yes i did have the index inside at first,  and it worked the same. 
> >> But your suggestion of putting the ktrig inside the UDO makes it work.
> >> Thanks
> >>
> >>
> >> ons. 15. feb. 2023, 22:27 skrev Jeanette C. <julien@mail.upb.de>:
> >> Hey hey Oeyvind,
> >> why do you pass the index to your k-rate opcode? This ight be an issue. Have
> >> you tried setting up the kIndex inside the opcode and perhaps passing the
> >> trigger and also have the if (kTrig == 1) statement inside the opcode. I
> >> didn't test it, but it feels odd reading it like this.
> >>
> >> HTH.
> >>
> >> Best wishes,
> >>
> >> Jeanette
> >>
> >> Feb 15 2023, Oeyvind Brandtsegg has written:
> >>
> >>> Hi
> >>>
> >>> I am puzzled by how this (does not) work. There is probably something I
> >>> misunderstand about internal Csound processes, so I thought I might ask
> >>> here to get help understanding it.
> >>>
> >>> I am trying to make a UDO to reverse the order of all elements in an array.
> >>> It is easy enough at i-rate, and I can make the code work at k-rate if I do
> >>> it inline (not in a UDO), but I fail to make it work with k-rate arrays in
> >>> a UDO.
> >>> My code to reverse the order of elements is:
> >>>   kindex = 0
> >>>   while kindex < lenarray(kInput) do
> >>>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
> >>>     kindex += 1
> >>>   od
> >>>
> >>> A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code
> >>> (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
> >>> Any help is greatly appreciated.
> >>>
> >>> all best
> >>> Øyvind
> >>>
> >>> <CsoundSynthesizer>
> >>> <CsOptions>
> >>> </CsOptions>
> >>> <CsInstruments>
> >>>
> >>> ; UDO to reverse the order of an array at i-rate
> >>> opcode Reverse, i[], i[]
> >>> iInput[] xin
> >>> iOutput[] init lenarray(iInput)
> >>> index = 0
> >>> while index < lenarray(iInput) do
> >>>   iOutput[index] = iInput[lenarray(iInput)-1-index]
> >>>   index += 1
> >>> od
> >>> xout iOutput
> >>> endop
> >>>
> >>> ; UDO to reverse the order of an array at k-rate
> >>> opcode Reverse, k[], k[]k
> >>> kInput[], kindex xin
> >>> kOutput[] init lenarray(kInput)
> >>> while kindex < lenarray(kInput) do
> >>>   kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
> >>>   kindex += 1
> >>> od
> >>> xout kOutput
> >>> endop
> >>>
> >>> instr 1
> >>> ; it does not work when the reversal is inside a UDO
> >>> p3 = 4/kr
> >>> kInput[] fillarray 1,2,3,4
> >>> ktrig metro 1
> >>> if ktrig > 0 then
> >>>   kindex = 0
> >>>   kOutput[] Reverse kInput, kindex
> >>> endif
> >>> printarray kOutput
> >>> endin
> >>>
> >>> instr 2
> >>> ; this one works as expected, when the reversal is not in a UDO
> >>> p3 = 4/kr
> >>> kInput[] fillarray 1,2,3,4
> >>> kOutput[] init lenarray(kInput)
> >>> ktrig metro 1
> >>> if ktrig > 0 then
> >>>   kindex = 0
> >>>   while kindex < lenarray(kInput) do
> >>>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
> >>>     kindex += 1
> >>>   od
> >>> endif
> >>> printarray kOutput
> >>> endin
> >>>
> >>> instr 3
> >>> ; it also works fine in a UDO with i-rate arrays
> >>> iInput[] fillarray 1,2,3,4
> >>> iOutput[] Reverse iInput
> >>> printarray iOutput
> >>> endin
> >>>
> >>> </CsInstruments>
> >>> <CsScore>
> >>> i1 0 .1
> >>> i2 1 .1
> >>> i3 2 .1
> >>> e
> >>> </CsScore>
> >>> </CsoundSynthesizer>
> >>>
> >>> Csound mailing list
> >>> Csound@listserv.heanet.ie
> >>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0
> >>> Send bugs reports to
> >>>       https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0
> >>> Discussions of bugs and features can be posted here
> >>>
> >>
> >> --
> >>  * Website: https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fjuliencoder.de%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=WJhyCJUerfSgM84mbFKFEc%2FbEbrmbK8DCkpCrhTSO3g%3D&reserved=0 - for summer is a state of sound
> >>  * Youtube: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUCMS4rfGrTwz8W7jhC1Jnv7g&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RZJINBO85WJOXeLu5Xth9s%2Fjmu%2FPkqJfPjsoAfr4EdU%3D&reserved=0
> >>  * Audiobombs: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.audiobombs.com%2Fusers%2Fjeanette_c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=5CaGO6NQTlGJf%2Fabt%2FpjByKNnrU3L3%2FYXt0KF%2B0nP9A%3D&reserved=0
> >>  * GitHub: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjeanette-c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=a3zhMP%2FrNVToBUjwYzwyNw0RgPshLM4x1G24JDE9rA0%3D&reserved=0
> >>
> >> And when you say those words
> >> It's the sweetest thing I've ever heard <3
> >> (Britney Spears)
> >>
> >> Csound mailing list
> >> Csound@listserv.heanet.ie
> >> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0
> >> Send bugs reports to
> >>        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0
> >> Discussions of bugs and features can be posted here
> >> Csound mailing list Csound@listserv.heanet.ie https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0 Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0 Discussions of bugs and features can be posted here
> >> Csound mailing list Csound@listserv.heanet.ie https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0 Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0 Discussions of bugs and features can be posted here
> >
> >
> > Csound mailing list
> > Csound@listserv.heanet.ie
> > https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0
> > Send bugs reports to
> >        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0
> > Discussions of bugs and features can be posted here
>
>
> 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
> 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


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

Date2023-02-17 12:50
FromOeyvind Brandtsegg
SubjectRe: [Csnd] [EXTERNAL] [Csnd] puzzled, array in UDO
Thanks Guillermo, that is a good hack to mitigate the problem in the current version.
Øyvind

tor. 16. feb. 2023 kl. 17:14 skrev Guillermo Senna <gsenna@gmail.com>:
The use of gotos is discouraged, but -based on what Victor said- if you
don't want to update yet this should fix it:

     igoto jump
     gkArr = kOutput ; removing this line makes it work, ...but I would
like to copy the result back to the same global array
jump:
     printarray gkArr

On 16/2/23 12:57, Victor Lazzarini wrote:
> It looks like the problem is that the copy happens at both i-time and perf-time. Since at i-time kOutput is all zeros, that gets copy to the global array and
> then to kInput and so it’s zeros all the way. I have added a special k-rate copying opcode that gets called at i-time only to allocate memory if needed and
> then copies only at k-rate. This is for csound 6 and it’s in the csound6 branch now. I tested your code and it passes.
>
> In Csound 7, the code is parsed differently and the copy only happens at i-time (which is also wrong and needs fixing, but the problem is one that we
> know of, code being parsed to use a =.generic opcode that is causing trouble also elsewhere).That’ll probably need to be addressed differently.
>
> ========================
> Prof. Victor Lazzarini
> Maynooth University
> Ireland
>
>> On 16 Feb 2023, at 14:30, Oeyvind Brandtsegg <obrandts@GMAIL.COM> wrote:
>>
>> Thanks so much. Happy to hear that it was not my own fault this time ;-)
>>
>> I have a related issue, this time it is not related to processing it with a UDO, but it occurs when I try to reverse the contents of a global array.
>> My use case is that I would like to k-rate trigger the reversal of the contents of a global array in place.
>>
>> My thinking was that I could do the reversal as before, and since I am inside a conditional, I would only copy the reversed array back to the global array once the reversal had been processed.
>>
>> Example below
>>
>> all best
>> Øyvind
>>
>> <CsoundSynthesizer>
>> <CsOptions>
>> </CsOptions>
>> <CsInstruments>
>>
>> gkArr[] fillarray 1,2,3,4
>>
>> instr 1
>>    ; works with local array
>>    kInput[] fillarray 1,2,3,4
>>    kOutput[] init lenarray(kInput)
>>    ktrig metro 1
>>    if ktrig > 0 then
>>      kindex = 0
>>      while kindex < lenarray(kInput) do
>>        kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>        kindex += 1
>>      od
>>    printarray kOutput
>>    endif
>> endin
>>
>> instr 2
>>    ; does not work when I use a global array as input and copy the result back to the same global array
>>    kInput[] = gkArr
>>    kOutput[] init lenarray(kInput)
>>    ktrig metro 1
>>    if ktrig > 0 then
>>      kindex = 0
>>      while kindex < lenarray(kInput) do
>>        kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>        kindex += 1
>>      od
>>      gkArr = kOutput ; removing this line makes it work, ...but I would like to copy the result back to the same global array
>>      printarray kOutput
>>      printarray gkArr
>>    endif
>> endin
>>
>> </CsInstruments>
>> <CsScore>
>> i1 0 3
>> i2 4 3
>> e
>> </CsScore>
>> </CsoundSynthesizer>
>>
>> tor. 16. feb. 2023 kl. 14:18 skrev Victor Lazzarini <Victor.Lazzarini@mu.ie>:
>> I believe this is now fix in git (both csound6 and develop branches).
>>
>> ========================
>> Prof. Victor Lazzarini
>> Maynooth University
>> Ireland
>>
>>> On 16 Feb 2023, at 10:40, Victor Lazzarini <Victor.Lazzarini@mu.ie> wrote:
>>>
>>> yes, that’s a bug alright. I have looked at this and what happens is that if there are no perf statements outside the loop,
>>> the opcode behaves in such a way that the loop is ignored. However if you insert any statement (like kindex = kindex) then
>>> it works correctly. For example,
>>>
>>> opcode Test0, k, k
>>>   kindex xin
>>>   while kindex < 3 do
>>>     kindex += 1
>>>   od
>>>   xout kindex
>>> endop
>>>
>>> doesn’t work correctly, but this one does
>>>
>>> opcode Test1, k, k
>>>   kindex xin
>>>   k1 = 0
>>>   while kindex < 3 do
>>>     kindex += 1
>>>   od
>>>   xout kindex
>>> endop
>>>
>>> I know that if there are no perf statements in a UDO there’s no perf cycle, but here we are ignoring perf statements inside
>>> the loop. We’ll fix this.
>>> ========================
>>> Prof. Victor Lazzarini
>>> Maynooth University
>>> Ireland
>>>
>>>> On 16 Feb 2023, at 01:39, Aaron Krister Johnson <akjmicro@GMAIL.COM> wrote:
>>>>
>>>> WARNINGThis email originated from outside of Maynooth University's Mail System. Do not reply, click links or open attachments unless you recognise the sender and know the content is safe.
>>>> Ah, it must be that the assignment to a local scope needs to happen.
>>>>
>>>> To be filed away under "things to remember when you need to loop in an UDO"
>>>>
>>>>
>>>> Aaron Krister Johnson
>>>> Music, etc.:
>>>> https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.untwelve.org%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=82WVd%2F7SkjwJvK%2BSKQVrvPhDNjJB532n%2BL1lSAn2ZwE%3D&reserved=0
>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUC_utjGYbSizWE0dNyr0Vdmg&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=hzNV42ViOz1AR9CQsdUe2Nsq9PwcTiJST6hHBkO0m3I%3D&reserved=0
>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Faaron-krister-johnson&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=SVfxPZwhQ8Q8ZF7JVd1eFu9lgBlHzTdwtLrt2fBC3pM%3D&reserved=0
>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fsoundcloud.com%2Ffiltercreed&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=52HeYu1t%2B5GIXVBQIsQje5cJyYrn4hXpklqYLI4jAUE%3D&reserved=0
>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Faaronkristerjohnson.bandcamp.com%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=PBqx7PqVa3J5CEu%2BWF71Kl6mkx6X0A2abrKMZ0MNlbs%3D&reserved=0
>>>> Code:
>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fakjmicro&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=2NnDOiEYbo7TCKl27CsSuLUP2dXVoWNDs2mmwLG1lz0%3D&reserved=0
>>>>
>>>>
>>>> On Wed, Feb 15, 2023 at 4:08 PM Oeyvind Brandtsegg <obrandts@gmail.com> wrote:
>>>> Whoa, yes, guillermo, it does fix it.
>>>> Like this.
>>>> That is indeed strange(?)
>>>>
>>>> ; UDO to reverse the order of an array at k-rate
>>>> opcode Reverse, k[], k[]k
>>>>   kInput[], kindex xin
>>>>   kOutput[] init lenarray(kInput)
>>>>   kindex = kindex
>>>>   while kindex < lenarray(kInput) do
>>>>     kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>>     kindex += 1
>>>>   od
>>>>   xout kOutput
>>>> endop
>>>>
>>>>
>>>> tor. 16. feb. 2023 kl. 00:03 skrev Oeyvind Brandtsegg <obrandts@gmail.com>:
>>>> Hi,  yes i did have the index inside at first,  and it worked the same.
>>>> But your suggestion of putting the ktrig inside the UDO makes it work.
>>>> Thanks
>>>>
>>>>
>>>> ons. 15. feb. 2023, 22:27 skrev Jeanette C. <julien@mail.upb.de>:
>>>> Hey hey Oeyvind,
>>>> why do you pass the index to your k-rate opcode? This ight be an issue. Have
>>>> you tried setting up the kIndex inside the opcode and perhaps passing the
>>>> trigger and also have the if (kTrig == 1) statement inside the opcode. I
>>>> didn't test it, but it feels odd reading it like this.
>>>>
>>>> HTH.
>>>>
>>>> Best wishes,
>>>>
>>>> Jeanette
>>>>
>>>> Feb 15 2023, Oeyvind Brandtsegg has written:
>>>>
>>>>> Hi
>>>>>
>>>>> I am puzzled by how this (does not) work. There is probably something I
>>>>> misunderstand about internal Csound processes, so I thought I might ask
>>>>> here to get help understanding it.
>>>>>
>>>>> I am trying to make a UDO to reverse the order of all elements in an array.
>>>>> It is easy enough at i-rate, and I can make the code work at k-rate if I do
>>>>> it inline (not in a UDO), but I fail to make it work with k-rate arrays in
>>>>> a UDO.
>>>>> My code to reverse the order of elements is:
>>>>>    kindex = 0
>>>>>    while kindex < lenarray(kInput) do
>>>>>      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>>>      kindex += 1
>>>>>    od
>>>>>
>>>>> A full csd showing both the i-rate UDO, k-rate UDO, and regular Csound code
>>>>> (without UDO) is pasted below. The problem shows in instr 1 (k-rate UDO).
>>>>> Any help is greatly appreciated.
>>>>>
>>>>> all best
>>>>> Øyvind
>>>>>
>>>>> <CsoundSynthesizer>
>>>>> <CsOptions>
>>>>> </CsOptions>
>>>>> <CsInstruments>
>>>>>
>>>>> ; UDO to reverse the order of an array at i-rate
>>>>> opcode Reverse, i[], i[]
>>>>> iInput[] xin
>>>>> iOutput[] init lenarray(iInput)
>>>>> index = 0
>>>>> while index < lenarray(iInput) do
>>>>>    iOutput[index] = iInput[lenarray(iInput)-1-index]
>>>>>    index += 1
>>>>> od
>>>>> xout iOutput
>>>>> endop
>>>>>
>>>>> ; UDO to reverse the order of an array at k-rate
>>>>> opcode Reverse, k[], k[]k
>>>>> kInput[], kindex xin
>>>>> kOutput[] init lenarray(kInput)
>>>>> while kindex < lenarray(kInput) do
>>>>>    kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>>>    kindex += 1
>>>>> od
>>>>> xout kOutput
>>>>> endop
>>>>>
>>>>> instr 1
>>>>> ; it does not work when the reversal is inside a UDO
>>>>> p3 = 4/kr
>>>>> kInput[] fillarray 1,2,3,4
>>>>> ktrig metro 1
>>>>> if ktrig > 0 then
>>>>>    kindex = 0
>>>>>    kOutput[] Reverse kInput, kindex
>>>>> endif
>>>>> printarray kOutput
>>>>> endin
>>>>>
>>>>> instr 2
>>>>> ; this one works as expected, when the reversal is not in a UDO
>>>>> p3 = 4/kr
>>>>> kInput[] fillarray 1,2,3,4
>>>>> kOutput[] init lenarray(kInput)
>>>>> ktrig metro 1
>>>>> if ktrig > 0 then
>>>>>    kindex = 0
>>>>>    while kindex < lenarray(kInput) do
>>>>>      kOutput[kindex] = kInput[lenarray(kInput)-1-kindex]
>>>>>      kindex += 1
>>>>>    od
>>>>> endif
>>>>> printarray kOutput
>>>>> endin
>>>>>
>>>>> instr 3
>>>>> ; it also works fine in a UDO with i-rate arrays
>>>>> iInput[] fillarray 1,2,3,4
>>>>> iOutput[] Reverse iInput
>>>>> printarray iOutput
>>>>> endin
>>>>>
>>>>> </CsInstruments>
>>>>> <CsScore>
>>>>> i1 0 .1
>>>>> i2 1 .1
>>>>> i3 2 .1
>>>>> e
>>>>> </CsScore>
>>>>> </CsoundSynthesizer>
>>>>>
>>>>> Csound mailing list
>>>>> Csound@listserv.heanet.ie
>>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0
>>>>> Send bugs reports to
>>>>>        https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0
>>>>> Discussions of bugs and features can be posted here
>>>>>
>>>> --
>>>>   * Website: https://eur02.safelinks.protection.outlook.com/?url=http%3A%2F%2Fjuliencoder.de%2F&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=WJhyCJUerfSgM84mbFKFEc%2FbEbrmbK8DCkpCrhTSO3g%3D&reserved=0 - for summer is a state of sound
>>>>   * Youtube: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.youtube.com%2Fchannel%2FUCMS4rfGrTwz8W7jhC1Jnv7g&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=RZJINBO85WJOXeLu5Xth9s%2Fjmu%2FPkqJfPjsoAfr4EdU%3D&reserved=0
>>>>   * Audiobombs: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fwww.audiobombs.com%2Fusers%2Fjeanette_c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=5CaGO6NQTlGJf%2Fabt%2FpjByKNnrU3L3%2FYXt0KF%2B0nP9A%3D&reserved=0
>>>>   * GitHub: https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fjeanette-c&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=a3zhMP%2FrNVToBUjwYzwyNw0RgPshLM4x1G24JDE9rA0%3D&reserved=0
>>>>
>>>> And when you say those words
>>>> It's the sweetest thing I've ever heard <3
>>>> (Britney Spears)
>>>>
>>>> Csound mailing list
>>>> Csound@listserv.heanet.ie
>>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0
>>>> Send bugs reports to
>>>>         https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0
>>>> Discussions of bugs and features can be posted here
>>>> Csound mailing list Csound@listserv.heanet.ie https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=Yca3EZNbOCske07N4CWNCiSi8qZWrDhqOR0aJSmWwSI%3D&reserved=0 Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408215862412%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=fDxWztT3jM7SkQJMImXm3YVlJ3ZoDntHCwR8uHFVhd0%3D&reserved=0 Discussions of bugs and features can be posted here
>>>> Csound mailing list Csound@listserv.heanet.ie https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0 Send bugs reports to https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0 Discussions of bugs and features can be posted here
>>>
>>> Csound mailing list
>>> Csound@listserv.heanet.ie
>>> https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Flistserv.heanet.ie%2Fcgi-bin%2Fwa%3FA0%3DCSOUND&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=DzFS6UOR4De65kaJCmZts6Y59pDRA80JrM9VO1sr%2Fck%3D&reserved=0
>>> Send bugs reports to
>>>         https://eur02.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fcsound%2Fcsound%2Fissues&data=05%7C01%7CVictor.Lazzarini%40mu.ie%7Cfef03f7be77740f97f3608db100a3384%7C1454f5ccbb354685bbd98621fd8055c9%7C0%7C0%7C638121408216018635%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=dRGpE8DD9ELjycLfwIAReSx581epSSlc7ged%2B8ohl0M%3D&reserved=0
>>> Discussions of bugs and features can be posted here
>>
>> 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
>> 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
>
> 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

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