[Csnd] Language question/idea : Forward #1607 should init be able to copy i-arrays to k-arrays?

Trying to continue this discussion, which apparently happened in the wrong place :

https://github.com/csound/csound/issues/1607

Thank you Victor for writing, but your remark didn’t really answer our question. Perheaps it was not clear enough in our first message.

It could be rephrased like this : “Is there a direct way to init a k-rate array with values of an i-rate array (initialization only) ? And if no, wouldn’t ‘init’ keyword be a good candidate for such a task ?”

Because of course, if I write :

iArr fillarray 1, 2, 3, 4

kArr[] = iArr

The content of iArr will be copied in kArr at k-rate, because, as you wrote, it is a k-rate expression.

And “fillarray” (you mentionned in your previous answer) cannot be used to copy an array. So this solution is not relevant.

I know init is used to initialize an array with a scalar argument (size). But couldn’t the compiler do the job to just know if the argument is scalar or array, and then initialize with size (if scalar), or initialize and copy at initialization only (if array argument) ?

Let’s take a simple example :

opocode chord_manipulation, k[], i[]k
iArr[] , ktrig xin

// Here I want to copy the array at initialization only, because I need to manipulate it at k-rate (I don’t want the copy to happen every k-pass).

// So the only solution I found, was this :

isize lenarray iArr
kArr init isize
icnt init 0
while icnt < isize do
kArr[icnt] init iArr[icnt]
icnt += 1

od

// Where the language design would intuitively lead me to write :

kArr[] init iArr // which won’t build, but could be great

if(ktrig == 1) then

// Do some chord reversal here

endif

xout kArr

endop

instr 1
iChord1[] fillarray 50, 53, 55, 57

kReversed[] = chord_manipulation(iChord1, metro:k(1) )

endin

Finally, maybe there already is a simpler/smarter solution, which I don’t know.

Regards

Johann Philippe

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

if timeinstk() == 1 then
  kArr = iArr
endif

Csound mailing list Send bugs reports to Discussions of bugs and features can be posted here

Thank you Eduardo. It works, but is not i-rate.

if timeinstk() == 1 then
  kArr = iArr
endif

Trying to continue this discussion, which apparently happened in the wrong place :

https://github.com/csound/csound/issues/1607

Thank you Victor for writing, but your remark didn’t really answer our question. Perheaps it was not clear enough in our first message.

It could be rephrased like this : “Is there a direct way to init a k-rate array with values of an i-rate array (initialization only) ? And if no, wouldn’t ‘init’ keyword be a good candidate for such a task ?”

Because of course, if I write :

iArr fillarray 1, 2, 3, 4

kArr[] = iArr

The content of iArr will be copied in kArr at k-rate, because, as you wrote, it is a k-rate expression.

And “fillarray” (you mentionned in your previous answer) cannot be used to copy an array. So this solution is not relevant.

I know init is used to initialize an array with a scalar argument (size). But couldn’t the compiler do the job to just know if the argument is scalar or array, and then initialize with size (if scalar), or initialize and copy at initialization only (if array argument) ?

Let’s take a simple example :

opocode chord_manipulation, k[], i[]k
iArr[] , ktrig xin

// Here I want to copy the array at initialization only, because I need to manipulate it at k-rate (I don’t want the copy to happen every k-pass).

// So the only solution I found, was this :

isize lenarray iArr
kArr init isize
icnt init 0
while icnt < isize do
kArr[icnt] init iArr[icnt]
icnt += 1

od

// Where the language design would intuitively lead me to write :

kArr[] init iArr // which won’t build, but could be great

if(ktrig == 1) then

// Do some chord reversal here

endif

xout kArr

endop

instr 1
iChord1[] fillarray 50, 53, 55, 57

kReversed[] = chord_manipulation(iChord1, metro:k(1) )

endin

Finally, maybe there already is a simpler/smarter solution, which I don’t know.

Regards

Johann Philippe

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

At the moment, the only way I can think is

kArr[] fillaray iArr[0], iArr[1], …

but it would be easy to make an overload of fillarray that takes an i-time array. I’m not completely sure of the use case, but that’s off topic.

An overload of fillarray would make sense to me.

At the moment, the only way I can think is

kArr[] fillaray iArr[0], iArr[1], …

but it would be easy to make an overload of fillarray that takes an i-time array. I’m not completely sure of the use case, but that’s off topic.

I was looking at the code and you can indeed do

iArr fillarray 1,2,3

kArr[] = iArr

so we don’t need the overloaded fillarray. This assignment will work both at init and perf time.

kArr[] = iArr

I tried this, and iArr was copied in kArr at k-rate too, so it was impossible for me to do what I need (later manipulations on kArr) since kArr is returning to its original state at each k-pass. What I need is something that only copies at i-rate. Maybe I’m missing something ?

I was looking at the code and you can indeed do

iArr fillarray 1,2,3

kArr[] = iArr

so we don’t need the overloaded fillarray. This assignment will work both at init and perf time.

I see. I have added the overload to git develop (csound 7).

Thank you !

I see. I have added the overload to git develop (csound 7).