Author |
Message |
Diskette
Joined: Feb 29, 2008 Posts: 2 Location: england
|
Posted: Fri Feb 29, 2008 3:16 pm Post subject:
why doesent this work ? Subject description: arrays are confusing :S |
|
|
hey guys great forum! iv been trying to get my head round chuck for a few weeks, been ploughing through the chuck manual picking up what i can but i have no previous coding experience so its a little difficult. Was hoping someone could tell me where im going wrong with arrays etc.
[100 => float bpm;
minute / bpm => dur beat;
SinOsc s => dac;
[0.0,2.0,4.0,7.0,9.0,11.0] @=> float scale[];
while (true);
{
scale [Math.rand2(0,6) ] => float freq;
Std.mtof(48 + (Std.rand2(0,3)*12 + freq) ) => s.freq;
.25::beat =>now;
}
]
at the moment i seem to be getting "cannot perform + on object references" alot anyway any help would be much appreciated! |
|
Back to top
|
|
|
kijjaz
Joined: Sep 20, 2004 Posts: 765 Location: bangkok, thailand
Audio files: 4
|
Posted: Fri Feb 29, 2008 4:18 pm Post subject:
|
|
|
i did some code cleaning up here:
Code: | 100.0 => float bpm;
minute / bpm => dur beat;
SinOsc s => dac;
[0.0, 2, 4, 7, 9, 11] @=> float scale[];
while(true)
{
scale[Std.rand2(0, 5)] => float note;
Std.mtof(48.0 + Std.rand2(0, 3) * 12 + note) => s.freq;
.25::beat => now;
} |
Things about your patch:
- i'm not sure where you encounter the problem..
i guess we have to make sure which name is a function, and try to use it as a function.. for example..
Std.mtof(...)
s.freq(...)
are functions.
- guessing from what you had back there,
what you'd like to add to the second line in the while loop is that..
you are dealing with note number, not frequency yet.
so i change it to 'note' not frequency, and see if you've got the result you wanted.
- scale[n] <-- the maximum value of n would be 5 because we can point to it using n = 0 .. 5
just to make sure that ArrayOutOfBounds wouldn't occur.
- after my clean up, it'd work like this:
choose a random note from the scale
play at a random octave
starts at note 48 = C an octave below middle C
i guess this might be the musical result you're trying to do in there?
- - -
cool! this is gonna be a useful stuff. |
|
Back to top
|
|
|
Kassen
Janitor
Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Fri Feb 29, 2008 4:57 pm Post subject:
Re: why doesent this work ? Subject description: arrays are confusing :S |
|
|
Welcome on board!
Diskette wrote: |
while (true);
|
This line is one of the big problems. Because of the " ; " sign the "while" loop refers to a empty loop in which nothing happens.... which gets the whole VM stuck. _________________ Kassen |
|
Back to top
|
|
|
Diskette
Joined: Feb 29, 2008 Posts: 2 Location: england
|
Posted: Sat Mar 01, 2008 5:48 pm Post subject:
|
|
|
thanks guys this is much more on track now ill persevere and hopefully get somewhere ! |
|
Back to top
|
|
|
|