[Csnd] Language question/idea : Forward #1607 should init be able to copy i-arrays to k-arrays?
Date | 2022-05-17 16:42 |
From | Johann Philippe <000002c2c0737523-dmarc-request@LISTSERV.HEANET.IE> |
Subject | [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 : 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 |
Date | 2022-05-17 20:18 |
From | Eduardo Moguillansky |
Subject | Re: [Csnd] Language question/idea : Forward #1607 should init be able to copy i-arrays to k-arrays? |
if timeinstk() == 1 then kArr = iArr endif On 17.05.22 17:42, Johann Philippe
wrote:
|
Date | 2022-05-17 21:09 |
From | Johann Philippe <000002c2c0737523-dmarc-request@LISTSERV.HEANET.IE> |
Subject | Re: [Csnd] Language question/idea : Forward #1607 should init be able to copy i-arrays to k-arrays? |
Thank you Eduardo. It works, but is not i-rate.
Le mardi 17 mai 2022, 20:18:40 UTC+1, Eduardo Moguillansky <eduardo.moguillansky@gmail.com> a écrit :
if timeinstk() == 1 then kArr = iArr endif On 17.05.22 17:42, Johann Philippe
wrote:
Trying to continue this
discussion, which apparently happened in the wrong place :
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
|
Date | 2022-05-18 08:41 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Language question/idea : Forward #1607 should init be able to copy i-arrays to k-arrays? |
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.
|
Date | 2022-05-18 10:32 |
From | Johann Philippe <000002c2c0737523-dmarc-request@LISTSERV.HEANET.IE> |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Language question/idea : Forward #1607 should init be able to copy i-arrays to k-arrays? |
An overload of fillarray would make sense to me.
Le mercredi 18 mai 2022, 09:42:01 UTC+2, Victor Lazzarini <victor.lazzarini@mu.ie> a écrit :
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.
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
|
Date | 2022-05-19 09:02 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Language question/idea : Forward #1607 should init be able to copy i-arrays to k-arrays? |
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.
|
Date | 2022-05-19 09:10 |
From | Johann Philippe <000002c2c0737523-dmarc-request@LISTSERV.HEANET.IE> |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Language question/idea : Forward #1607 should init be able to copy i-arrays to k-arrays? |
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 ?
Le jeudi 19 mai 2022, 09:02:26 UTC+1, Victor Lazzarini <victor.lazzarini@mu.ie> a écrit :
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.
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
|
Date | 2022-05-19 09:46 |
From | Victor Lazzarini |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Language question/idea : Forward #1607 should init be able to copy i-arrays to k-arrays? |
I see. I have added the overload to git develop (csound 7).
|
Date | 2022-05-19 10:00 |
From | Johann Philippe <000002c2c0737523-dmarc-request@LISTSERV.HEANET.IE> |
Subject | Re: [Csnd] [EXTERNAL] [Csnd] Language question/idea : Forward #1607 should init be able to copy i-arrays to k-arrays? |
Thank you !
Le jeudi 19 mai 2022, 09:46:34 UTC+1, Victor Lazzarini <victor.lazzarini@mu.ie> a écrit :
I see. I have added the overload to git develop (csound 7).
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
|