Csound Csound-dev Csound-tekno Search About

[Csnd] array question

Date2014-01-01 04:52
FromForrest Cahoon
Subject[Csnd] array question
I've trying to use arrays and am running into a syntax problem.  This is what I have:

giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8

giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15

giBaseFreq = 8

opcode getFreq, k, kk

kNoteNumber, kHoldKey xin

kOctave = floor(kNoteNumber/12)

kStep = kNoteNumber - (kOctave * 12)

if kHoldKey > 0 then

iScale = giStdScale

else

iScale = giAltScale

endif

kFreq = giBaseFreq * (2^kOctave) * iScale[kStep]

xout kFreq

endop



This is to use an alternate scale when I hold down an on/off controller key on my MIDI device.

As written, this code gives the following error:


error: Unable to find opcode entry for '=' with matching argument types:
Found: i = i[]
Line: 54 Loc: 1
Parsing failed due to 1 semantic error!
WARNING: Stopping on parser failure

cannot compile orchestra


The problem is that iScale is an i-type variable, not an i-array-type variable. But I don't want to initialize storage for an array variable; I want to just declare that it's an array variable so I can use it to reference the same array that's already stored in another variable. Is that possible? What syntax do I need?



Date2014-01-02 14:40
FromTarmo Johannes
SubjectRe: [Csnd] array question

Hi,

 

I am not sure if you have solved already your problem. What I did a bit in similar situation was to put the arrays into another array so resulting a two-dimensional array and using an index to disitinguish between them:

 

giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8

 

giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15

 

giScales[] array giStdScale, giAltScale

 

; constants for clearer code:

#define STD #0#

#define ALT #1#

 

;....

if kHoldKey > 0 then

kFreq = giBaseFreq * (2^kOctave) * giScales[$STD][kStep]

else

kFreq = giBaseFreq * (2^kOctave) * giScales[$ALT][kStep]

endif

 

; etc---

 

 

Did not test, but I hope it helps.

best!

 

tarmo

 

Oh, and HAPPY NEW YEAR!

 

 

 

 

On Tuesday 31 December 2013 22:52:18 Forrest Cahoon wrote:

I've trying to use arrays and am running into a syntax problem.  This is what I have:

giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8

giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15

giBaseFreq = 8

opcode getFreq, k, kk

kNoteNumber, kHoldKey xin

kOctave = floor(kNoteNumber/12)

kStep = kNoteNumber - (kOctave * 12)

if kHoldKey > 0 then

iScale = giStdScale

else

iScale = giAltScale

endif

kFreq = giBaseFreq * (2^kOctave) * iScale[kStep]

xout kFreq

endop



This is to use an alternate scale when I hold down an on/off controller key on my MIDI device.

As written, this code gives the following error:


error: Unable to find opcode entry for '=' with matching argument types:

Found: i = i[]
Line: 54 Loc: 1
Parsing failed due to 1 semantic error!
WARNING: Stopping on parser failure

cannot compile orchestra


The problem is that iScale is an i-type variable, not an i-array-type variable. But I don't want to initialize storage for an array variable; I want to just declare that it's an array variable so I can use it to reference the same array that's already stored in another variable. Is that possible? What syntax do I need?





Date2014-01-08 04:21
FromForrest Cahoon
SubjectRe: [Csnd] array question
I meant to reply to this earlier, Tarmo, because this is a great idea. It just so happens that kHoldKey represents an on/off MIDI controller with values 0 and 1. So actually, using your idea, I can get rid of the if altogether and just use

kFreq = giBaseFreq * (2^kOctave) * giScales[kHoldKey][kStep]

which is super clean and elegant, IMHO. Thanks for sharing!

On Thu, Jan 2, 2014 at 8:40 AM, Tarmo Johannes <tarmo.johannes@otsakool.edu.ee> wrote:

Hi,

 

I am not sure if you have solved already your problem. What I did a bit in similar situation was to put the arrays into another array so resulting a two-dimensional array and using an index to disitinguish between them:

 

giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8

 

giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15

 

giScales[] array giStdScale, giAltScale

 

; constants for clearer code:

#define STD #0#

#define ALT #1#

 

;....

if kHoldKey > 0 then

kFreq = giBaseFreq * (2^kOctave) * giScales[$STD][kStep]

else

kFreq = giBaseFreq * (2^kOctave) * giScales[$ALT][kStep]

endif

 

; etc---

 

 

Did not test, but I hope it helps.

best!

 

tarmo

 

Oh, and HAPPY NEW YEAR!

 

 

 

 

On Tuesday 31 December 2013 22:52:18 Forrest Cahoon wrote:

I've trying to use arrays and am running into a syntax problem.  This is what I have:

giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8

giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15

giBaseFreq = 8

opcode getFreq, k, kk

kNoteNumber, kHoldKey xin

kOctave = floor(kNoteNumber/12)

kStep = kNoteNumber - (kOctave * 12)

if kHoldKey > 0 then

iScale = giStdScale

else

iScale = giAltScale

endif

kFreq = giBaseFreq * (2^kOctave) * iScale[kStep]

xout kFreq

endop



This is to use an alternate scale when I hold down an on/off controller key on my MIDI device.

As written, this code gives the following error:


error: Unable to find opcode entry for '=' with matching argument types:

Found: i = i[]
Line: 54 Loc: 1
Parsing failed due to 1 semantic error!
WARNING: Stopping on parser failure

cannot compile orchestra


The problem is that iScale is an i-type variable, not an i-array-type variable. But I don't want to initialize storage for an array variable; I want to just declare that it's an array variable so I can use it to reference the same array that's already stored in another variable. Is that possible? What syntax do I need?






Date2014-01-11 05:20
FromForrest Cahoon
SubjectRe: [Csnd] array question
Argh, it seems I spoke too soon -- I thought I could get this to work, and it looked great. But I had ugly code in place that worked, so I only got around to trying it just now.  No dice.

giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8

giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15

giScales[] array giStdScale, giAltScale


gives the error


error: Unable to find opcode entry for 'array' with matching argument types:
Found: i[] array i[]i[]


With giScales[][] array giStdScale, giAltScale


error:  Unable to find opcode entry for 'array' with matching argument types:
Found: i[][] array i[]i[]

What I was _really_ hoping would work

giScales[] = array( array(1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8), \

array(1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15) )


gives

error: error: opcode 'array' for expression with arg types k[]k[] not found, line 22
error: Unable to find opcode entry for '=' with matching argument types:
Found: i[] = @
Line: 23 Loc: 1

Oh well, at least I have something that works.



On Thu, Jan 2, 2014 at 8:40 AM, Tarmo Johannes <tarmo.johannes@otsakool.edu.ee> wrote:

Hi,

 

I am not sure if you have solved already your problem. What I did a bit in similar situation was to put the arrays into another array so resulting a two-dimensional array and using an index to disitinguish between them:

 

giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8

 

giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15

 

giScales[] array giStdScale, giAltScale

 

; constants for clearer code:

#define STD #0#

#define ALT #1#

 

;....

if kHoldKey > 0 then

kFreq = giBaseFreq * (2^kOctave) * giScales[$STD][kStep]

else

kFreq = giBaseFreq * (2^kOctave) * giScales[$ALT][kStep]

endif

 

; etc---

 

 

Did not test, but I hope it helps.

best!

 

tarmo

 

Oh, and HAPPY NEW YEAR!

 

 

 

 

On Tuesday 31 December 2013 22:52:18 Forrest Cahoon wrote:

I've trying to use arrays and am running into a syntax problem.  This is what I have:

giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8

giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15

giBaseFreq = 8

opcode getFreq, k, kk

kNoteNumber, kHoldKey xin

kOctave = floor(kNoteNumber/12)

kStep = kNoteNumber - (kOctave * 12)

if kHoldKey > 0 then

iScale = giStdScale

else

iScale = giAltScale

endif

kFreq = giBaseFreq * (2^kOctave) * iScale[kStep]

xout kFreq

endop



This is to use an alternate scale when I hold down an on/off controller key on my MIDI device.

As written, this code gives the following error:


error: Unable to find opcode entry for '=' with matching argument types:

Found: i = i[]
Line: 54 Loc: 1
Parsing failed due to 1 semantic error!
WARNING: Stopping on parser failure

cannot compile orchestra


The problem is that iScale is an i-type variable, not an i-array-type variable. But I don't want to initialize storage for an array variable; I want to just declare that it's an array variable so I can use it to reference the same array that's already stored in another variable. Is that possible? What syntax do I need?






Date2014-01-11 11:11
Fromjoachim heintz
SubjectRe: [Csnd] array question
you could do this to get your two-dimensional array:

giScales[] init 12, 12
giScales array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 
15/8,
	 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15

but i must say, that i personally think that your first thought (to 
select one of some given arrays in a midi-triggered instrument, if i 
recall correctly) was better and gives clearer code. if you like, send 
the code again which did not work.

best -

	joachim






sr = 44100
ksmps = 32
nchnls = 2
0dbfs = 1

instr 1
giScales[] init 12, 12
giScales array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 
15/8,
	 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15
iIndx = 0
until iIndx == 12 do
prints "giScales[0][%d] = %.3f\n", iIndx, giScales[0][iIndx]
iIndx += 1
od	
iIndx = 0
until iIndx == 12 do
prints "giScales[1][%d] = %.3f\n", iIndx, giScales[1][iIndx]
iIndx += 1
od
endin



i 1 0 1






Am 11.01.2014 06:20, schrieb Forrest Cahoon:
> Argh, it seems I spoke too soon -- I thought I could get this to work,
> and it looked great. But I had ugly code in place that worked, so I only
> got around to trying it just now.  No dice.
>
> giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3,
> 16/9, 15/8
>
> giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9,
> 12/7, 7/4, 28/15
>
> giScales[] array giStdScale, giAltScale
>
>
> gives the error
>
>
> error: Unable to find opcode entry for 'array' with matching argument types:
> Found: i[] array i[]i[]
>
>
> With giScales[][] array giStdScale, giAltScale
>
>
> error:  Unable to find opcode entry for 'array' with matching argument
> types:
> Found: i[][] array i[]i[]
>
> What I was _really_ hoping would work
>
> giScales[] = array( array(1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5,
> 5/3, 16/9, 15/8), \
>
> array(1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15) )
>
>
> gives
>
> error: error: opcode 'array' for expression with arg types k[]k[] not
> found, line 22
> error: Unable to find opcode entry for '=' with matching argument types:
> Found: i[] = @
> Line: 23 Loc: 1
>
> Oh well, at least I have something that works.
>
>
>
> On Thu, Jan 2, 2014 at 8:40 AM, Tarmo Johannes
> >
> wrote:
>
>     __
>
>     Hi,
>
>     I am not sure if you have solved already your problem. What I did a
>     bit in similar situation was to put the arrays into another array so
>     resulting a two-dimensional array and using an index to disitinguish
>     between them:
>
>     giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5,
>     5/3, 16/9, 15/8
>
>     giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9,
>     12/7, 7/4, 28/15
>
>     giScales[] array giStdScale, giAltScale
>
>     ; constants for clearer code:
>
>     #define STD #0#
>
>     #define ALT #1#
>
>     ;....
>
>     if kHoldKey > 0 then
>
>     kFreq = giBaseFreq * (2^kOctave) * giScales[$STD][kStep]
>
>     else
>
>     kFreq = giBaseFreq * (2^kOctave) * giScales[$ALT][kStep]
>
>     endif
>
>     ; etc---
>
>     Did not test, but I hope it helps.
>
>     best!
>
>     tarmo
>
>     Oh, and HAPPY NEW YEAR!
>
>     On Tuesday 31 December 2013 22:52:18 Forrest Cahoon wrote:
>
>     I've trying to use arrays and am running into a syntax problem.
>     This is what I have:
>
>     giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5,
>     5/3, 16/9, 15/8
>
>     giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9,
>     12/7, 7/4, 28/15
>
>     giBaseFreq = 8
>
>     opcode getFreq, k, kk
>
>     kNoteNumber, kHoldKey xin
>
>     kOctave = floor(kNoteNumber/12)
>
>     kStep = kNoteNumber - (kOctave * 12)
>
>     if kHoldKey > 0 then
>
>     iScale = giStdScale
>
>     else
>
>     iScale = giAltScale
>
>     endif
>
>     kFreq = giBaseFreq * (2^kOctave) * iScale[kStep]
>
>     xout kFreq
>
>     endop
>
>
>
>     This is to use an alternate scale when I hold down an on/off
>     controller key on my MIDI device.
>
>     As written, this code gives the following error:
>
>
>     error: Unable to find opcode entry for '=' with matching argument types:
>
>     Found: i = i[]
>     Line: 54 Loc: 1
>     Parsing failed due to 1 semantic error!
>     WARNING: Stopping on parser failure
>
>     cannot compile orchestra
>
>
>     The problem is that iScale is an i-type variable, not an
>     i-array-type variable. But I don't want to initialize storage for an
>     array variable; I want to just declare that it's an array variable
>     so I can use it to reference the same array that's already stored in
>     another variable. Is that possible? What syntax do I need?
>
>
>
>
>

Date2014-01-11 15:18
FromTarmo Johannes
SubjectRe: [Csnd] array question

Oh, right,

 

I looked again what I did in my code and it was with array of table indexes, not arrays.

 

Indeed, would be nice to have more flexible way to define two-deimensional array. But at your case a woraroud replacing firt two arrays could help:

 

giStdScale ftgen 0,0,-13,-2, 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3,

16/9, 15/8

 

giAltScale ftgen 0,0,-13,-2, 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7,

7/4, 28/15

giScales[] array giStdScale, giAltScale

 

and later:

 

kFreq = giBaseFreq * (2^kOctave) * tab(kStep,giScales[kHoldKey])

 

if I got you right.

 

best!

tarmo

 

 

 

 

 

On Friday 10 January 2014 23:20:53 Forrest Cahoon wrote:

Argh, it seems I spoke too soon -- I thought I could get this to work, and it looked great. But I had ugly code in place that worked, so I only got around to trying it just now.  No dice.

giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8

giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15

giScales[] array giStdScale, giAltScale


gives the error


error: Unable to find opcode entry for 'array' with matching argument types:

Found: i[] array i[]i[]


With

giScales[][] array giStdScale, giAltScale


error:  Unable to find opcode entry for 'array' with matching argument types:
Found: i[][] array i[]i[]

What I was _really_ hoping would work

giScales[] = array( array(1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8), \

array(1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15) )


gives

error: error: opcode 'array' for expression with arg types k[]k[] not found, line 22

error: Unable to find opcode entry for '=' with matching argument types:
Found: i[] = @
Line: 23 Loc: 1

Oh well, at least I have something that works.




On Thu, Jan 2, 2014 at 8:40 AM, Tarmo Johannes <tarmo.johannes@otsakool.edu.ee> wrote:

Hi,

 

I am not sure if you have solved already your problem. What I did a bit in similar situation was to put the arrays into another array so resulting a two-dimensional array and using an index to disitinguish between them:

 

giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8

 

giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15

 

giScales[] array giStdScale, giAltScale

 

; constants for clearer code:

#define STD #0#

#define ALT #1#

 

;....

if kHoldKey > 0 then

kFreq = giBaseFreq * (2^kOctave) * giScales[$STD][kStep]

else

kFreq = giBaseFreq * (2^kOctave) * giScales[$ALT][kStep]

endif

 

; etc---

 

 

Did not test, but I hope it helps.

best!

 

tarmo

 

Oh, and HAPPY NEW YEAR!

 

 

 

 

On Tuesday 31 December 2013 22:52:18 Forrest Cahoon wrote:

I've trying to use arrays and am running into a syntax problem.  This is what I have:

giStdScale[] array 1, 16/15, 9/8, 6/5, 5/4, 4/3, 45/32, 3/2, 8/5, 5/3, 16/9, 15/8

giAltScale[] array 1, 15/14, 8/7, 7/6, 9/7, 7/5, 64/45, 10/7, 14/9, 12/7, 7/4, 28/15

giBaseFreq = 8

opcode getFreq, k, kk

kNoteNumber, kHoldKey xin

kOctave = floor(kNoteNumber/12)

kStep = kNoteNumber - (kOctave * 12)

if kHoldKey > 0 then

iScale = giStdScale

else

iScale = giAltScale

endif

kFreq = giBaseFreq * (2^kOctave) * iScale[kStep]

xout kFreq

endop



This is to use an alternate scale when I hold down an on/off controller key on my MIDI device.

As written, this code gives the following error:


error: Unable to find opcode entry for '=' with matching argument types:

Found: i = i[]
Line: 54 Loc: 1
Parsing failed due to 1 semantic error!
WARNING: Stopping on parser failure

cannot compile orchestra


The problem is that iScale is an i-type variable, not an i-array-type variable. But I don't want to initialize storage for an array variable; I want to just declare that it's an array variable so I can use it to reference the same array that's already stored in another variable. Is that possible? What syntax do I need?