Csound Csound-dev Csound-tekno Search About

[Csnd] Arrays inside a Array

Date2024-01-31 08:01
FromPhilipp Neumann
Subject[Csnd] Arrays inside a Array
Hello everybody!

I was wondering if there is a way to work with arrays inside a array.
I was asking myself this question just out of interest. Partly also i was thinking what this could offer for compositional work.

This works not:

instr 1

  kArr1[] fillarray 1,2,3,4,5
  kArr2[] fillarray 10,20,30,40,50
  kArr3[] fillarray kArr1,kArr2
  
endin


Greetings,
Philipp
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

Date2024-01-31 09:10
FromRory Walsh
SubjectRe: [Csnd] Arrays inside a Array
I don't think this is possible Peter, but I could be wrong. You can insert an array into another array, but not using the syntax above. I guess you would have to do it the long way. Maybe a multidimensional array would offer more options to you? 

On Wed, 31 Jan 2024 at 08:01, Philipp Neumann <philipp@von-neumann.com> wrote:
Hello everybody!

I was wondering if there is a way to work with arrays inside a array.
I was asking myself this question just out of interest. Partly also i was thinking what this could offer for compositional work.

This works not:

instr 1

  kArr1[] fillarray 1,2,3,4,5
  kArr2[] fillarray 10,20,30,40,50
  kArr3[] fillarray kArr1,kArr2

endin


Greetings,
Philipp
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

Date2024-01-31 12:02
Fromthorin kerr
SubjectRe: [Csnd] Arrays inside a Array
Here's a possible method:
Concatenate the arrays, and append the index positions of the appends at the end of the array.
As long as you know the last values in the array refer to index positions, you can then extract the embedded arrays using slicearray.
Here's an example (it's a bit more convenient to demonstrate this with i-rate arrays).

<CsoundSynthesizer>
<CsOptions>
-odac --nchnls=2 --0dbfs=1 -m0 --sample-rate=48000 --ksmps=120
</CsOptions>
<CsInstruments>
;; With the help of ArrCat udo from the csudo repository, Joahim Heintz, MIT License 2023
;; https://github.com/csudo/csudo/blob/master/arrays/ArrCat.csd#L23C1-L39C6

opcode ArrCat, i[], i[]i[]
  iArr1[], iArr2[] xin
  iLenOutArr = lenarray(iArr1) + lenarray(iArr2)
  iOutArr[] init iLenOutArr
  indx = 0
  while indx < lenarray(iArr1) do
    iOutArr[indx] = iArr1[indx]
    indx += 1
  od
  while indx < iLenOutArr do
    iOutArr[indx] = iArr2[indx-lenarray(iArr1)]
    indx += 1
  od
  xout iOutArr
  endop

instr 1
   iArr1[] fillarray 1,2,3,4,5
   iArr2[] fillarray 10,20,30,40,50
   idelimiters[] fillarray lenarray(iArr1),lenarray(iArr1) + lenarray(iArr2)

   ;; now combine them all into one array, storing the delimiter values at the end.    
   icombined[] ArrCat iArr1, iArr2
   icombined[] ArrCat icombined, idelimiters

   printf_i "\nCombined array:",1
   printarray icombined
   ;; to extract the arrays,
   ;; use the delimiter values as position  indices for slicearray.
 
   idivndx1 = icombined[lenarray(icombined) - 2]
   idivndx2 = icombined[lenarray(icombined) - 1]
   iArr1extracted[] slicearray icombined,0,idivndx1-1
   iArr2extracted[] slicearray icombined,idivndx1,idivndx2-1

   printf_i "\nExtracted Array 1:",1
   printarray iArr1extracted

   printf_i "\nExtracted Array 2:",1
   printarray iArr2extracted

endin

</CsInstruments>

<CsScore>
i1 0 1
e
</CsScore>
</CsoundSynthesizer>



On Wed, Jan 31, 2024 at 6:01 PM Philipp Neumann <philipp@von-neumann.com> wrote:
Hello everybody!

I was wondering if there is a way to work with arrays inside a array.
I was asking myself this question just out of interest. Partly also i was thinking what this could offer for compositional work.

This works not:

instr 1

  kArr1[] fillarray 1,2,3,4,5
  kArr2[] fillarray 10,20,30,40,50
  kArr3[] fillarray kArr1,kArr2

endin


Greetings,
Philipp
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

Date2024-01-31 16:58
FromRichard Knight
SubjectRe: [Csnd] Arrays inside a Array
Maybe 2d arrays and setrow/getrow could be of use, eg

instr 1
   kArr1[] fillarray 1,2,3,4,5
   kArr2[] fillarray 10,20,30,40,50
   kArr3[][] init 2, 5

   kArr3 setrow kArr1, 0
   kArr3 setrow kArr2, 1

   printarray kArr3
   turnoff
endin


... then the getrow opcode to get the row/dimension of kArr3 into a 1d 
array if required..


On 2024-01-31 08:01, Philipp Neumann wrote:
> Hello everybody!
> 
> I was wondering if there is a way to work with arrays inside a array.
> I was asking myself this question just out of interest. Partly also i
> was thinking what this could offer for compositional work.
> 
> This works not:
> 
> instr 1
> 
>   kArr1[] fillarray 1,2,3,4,5
>   kArr2[] fillarray 10,20,30,40,50
>   kArr3[] fillarray kArr1,kArr2
> 
> endin
> 
> 
> Greetings,
> Philipp
> 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