[Csnd] Working with arrays / Saving a array created in a loop

Hello everybody!

I’m digging a little bit into the array facility of csound.

I wanted to created a array with values which defines the starting time (p2 - field) for triggering an instrument via the 'event‘ opcode.
This array should be a result out of another array, which holds values that define note-lengths/the duration of the instrument call.

This is how it should work:

instr 1
iDurArr[] fillarray 0.25, 0.5, 0.125, 0.01, 0.02
kDurIndex init 0

iStartValue = 0
kNewVal init iStartValue
while kDurIndex < lenarray(iDurArr) do
  gkStartTimeArr[] = kNewVal
  printk2 kNewVal
  kLastVal = kNewVal
  kNewVal = kLastVal + iDurArr[kDurIndex]
  kDurIndex += 1
od
endin

I get the right results. But when i understand it right, the gkStartTimeArr just exists temporarily and i can’t call the values when i need them. I want to combine this array with this kind of process:

while kDurIndex < lenarray(iDurArr) do
  event "i", 100, gKStartTimeArr[kDurIndex], iDurArr[kDurIndex]
  kDurIndex += 1
  if kDurIndex == lenarray(iDurArr) then
    kDurIndex = 0
  endif
od

How can i pair them that they work together? I don’t get it right now.

Greetings,
Philipp
Csound mailing list
Csound@listserv.heanet.ie
https://listserv.heanet.ie/cgi-bin/wa?A0=CSOUND
Send bugs reports to
        Issues · csound/csound · GitHub
Discussions of bugs and features can be posted here

why are you saying the the gkStartTimeArr just exists temporarily? did you try?
if it is a global array, it should persist during your run of csound.

Hi Joachim,

i got to the conclusion with testing it with this:
instr 1
iDurArr[] fillarray 0.25, 0.5, 0.125, 0.01, 0.02
kDurIndex init 0

iStartValue = 0
kNewVal init iStartValue
while kDurIndex < lenarray(iDurArr) do
  gkStartTimeArr[] = kNewVal
  printk2 kNewVal
  kLastVal = kNewVal
  kNewVal = kLastVal + iDurArr[kDurIndex]
  kDurIndex += 1
od
endin

instr 2
printk 0, lenarray(gkStartTimeArr), 10
endin

In instr 1 the right values are printed. But Instr 2 is giving me the length „-1“ .
Maybe i got something wrong?

this looks wrong:

  gkStartTimeArr[] = kNewVal

perhaps you mean this:

  gkStartTimArr[kDurIndex] = kNewVal

this should work, but you must crate your gkStartTimeArr before, like

  gkStartTimeArr[] init 10

Hello Joachim,

this works perfectly fine!

I would suggest to add some infos to the floss manual about this.
At least for me it is not very clear how this process is working just from reviewing the floss manual. E.g. this example:

iArr[] fillarray 1, 2, 3
iNew[] = iArr + 10 ; -> 11 12 13 as new array
iArr += 10 ; iArr is now 11 12 13

it doesn’t tell me that i have to create iNew[] from the beginning and that i have to use the index for this.
But maybe i’m the only person?

Greetings,
Philipp

hi philipp -

good to know it is working for you!

i understand what you mean. we just had a discussion on this list about the equal sign for arrays, or not working. it seems to be a bit complicated. probably in csound 7 (so perhaps soon =) it will be easier.

i am currently working on a new Getting Started for the floss manual. i hope i can cover some of these steps and traps. once i finished what i am doing now, i will send a link here on this list, and any suggestions will be appreciated.

so thanks for this, best -

  joachim