Csound Csound-dev Csound-tekno Search About

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

Date2023-02-16 16:20
FromPhilipp Neumann
Subject[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
        https://github.com/csound/csound/issues
Discussions of bugs and features can be posted here

Date2023-02-16 17:22
Fromjoachim heintz
SubjectRe: [Csnd] Working with arrays / Saving a array created in a loop
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.


On 16/02/2023 17:20, Philipp Neumann wrote:
> 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
>          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 17:48
FromPhilipp Neumann
SubjectRe: [Csnd] Working with arrays / Saving a array created in a loop
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?

> Am 16.02.2023 um 18:22 schrieb joachim heintz :
> 
> 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.
> 
> 
> On 16/02/2023 17:20, Philipp Neumann wrote:
>> 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
>>         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 18:06
Fromjoachim heintz
SubjectRe: [Csnd] Working with arrays / Saving a array created in a loop
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


On 16/02/2023 18:48, Philipp Neumann wrote:
> 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?
> 
>> Am 16.02.2023 um 18:22 schrieb joachim heintz :
>>
>> 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.
>>
>>
>> On 16/02/2023 17:20, Philipp Neumann wrote:
>>> 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
>>>          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 09:39
FromPhilipp Neumann
SubjectRe: [Csnd] Working with arrays / Saving a array created in a loop
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

> Am 16.02.2023 um 19:06 schrieb joachim heintz :
> 
> 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
> 
> 
> On 16/02/2023 18:48, Philipp Neumann wrote:
>> 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?
>>> Am 16.02.2023 um 18:22 schrieb joachim heintz :
>>> 
>>> 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.
>>> 
>>> 
>>> On 16/02/2023 17:20, Philipp Neumann wrote:
>>>> 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
>>>>         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

Date2023-02-17 10:16
Fromjoachim heintz
SubjectRe: [Csnd] Working with arrays / Saving a array created in a loop
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


On 17/02/2023 10:39, Philipp Neumann wrote:
> 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
> 
>> Am 16.02.2023 um 19:06 schrieb joachim heintz :
>>
>> 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
>>
>>
>> On 16/02/2023 18:48, Philipp Neumann wrote:
>>> 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?
>>>> Am 16.02.2023 um 18:22 schrieb joachim heintz :
>>>>
>>>> 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.
>>>>
>>>>
>>>> On 16/02/2023 17:20, Philipp Neumann wrote:
>>>>> 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
>>>>>          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

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