| Author |
Message |
jirko

Joined: Dec 15, 2009 Posts: 59
|
Posted: Wed Feb 17, 2010 12:14 pm Post subject:
Storing a list from Max to Chuck array |
 |
|
Sorry guys, but I'm having problems again..
I want to send a list of floats from max to chuck and store this list into an array.
Data is arriving but the array always get's "out of Bounds".
Sure I'm missing something.
That's what I have:
| Code: |
OscRecv recv;
6449 => recv.port;
float f [ 8 ];
recv.listen();
recv.event( "/foo/kick_array, f f f f f f f f f" ) @=> OscEvent @ oe;
while( true )
{
oe => now;
while( oe.nextMsg())
{
oe.getFloat() @=> f [8 ];
<<< "got (via OSC):", f [ 0 ] >>>;
}
} |
|
|
|
Back to top
|
|
 |
Antimon

Joined: Jan 18, 2005 Posts: 3390 Location: Sweden
Audio files: 218
G2 patch files: 93
|
|
|
Back to top
|
|
 |
jirko

Joined: Dec 15, 2009 Posts: 59
|
Posted: Thu Feb 18, 2010 5:07 am Post subject:
|
 |
|
wooopa! I need to pay mor attention!
But something else is going wrong there in this code.
I cant print any position of the array. Any suggestions? |
|
|
Back to top
|
|
 |
Antimon

Joined: Jan 18, 2005 Posts: 3390 Location: Sweden
Audio files: 218
G2 patch files: 93
|
Posted: Thu Feb 18, 2010 5:22 am Post subject:
|
 |
|
I don't understand what you mean by "print any position of the array". Where in the code does this error occur - could you post an error message or the output from ChucK?
/Stefan _________________ Antimon's Window
@soundcloud @Flattr @myspace A blog home - you can't explain music |
|
|
Back to top
|
|
 |
jirko

Joined: Dec 15, 2009 Posts: 59
|
Posted: Thu Feb 18, 2010 7:37 am Post subject:
|
 |
|
There are no errors in the output.
I want to print the arriving data with this line but nothing happens.
| Code: | | <<< "got (via OSC):", f [ 1 ] >>>; |
this is the updated code:
| Code: | OscRecv recv;
6449 => recv.port;
float f [ 8 ];
recv.listen();
recv.event( "/foo/array, f f f f f f f f " ) @=> OscEvent @ oe;
while( true )
{
oe => now;
<<<oe>>>;
while( oe.nextMsg())
{
oe.getFloat() @=> f [8];
<<< "got (via OSC):", f [1],f [2],f [3],f [4],f [5],f [6],f [7],f [8]>>>;
}
} |
thanks! |
|
|
Back to top
|
|
 |
Antimon

Joined: Jan 18, 2005 Posts: 3390 Location: Sweden
Audio files: 218
G2 patch files: 93
|
Posted: Thu Feb 18, 2010 8:13 am Post subject:
|
 |
|
OK, first off, arrays are zero-dereferenced, meaning that indexes start at zero for the first element, one for the second and so on. This means that you should use f[0] through f[7] too look at your elements. if you use f[8] you should get an error.
This is not your problem, since you don't get that far. Do you get a printout from the line <<<oe>>>? If not, you should start looking at whatever is sending the OSC messages.
/Stefan _________________ Antimon's Window
@soundcloud @Flattr @myspace A blog home - you can't explain music |
|
|
Back to top
|
|
 |
jirko

Joined: Dec 15, 2009 Posts: 59
|
Posted: Fri Feb 19, 2010 2:16 am Post subject:
|
 |
|
The OSC msg is arriving but only the first float is getting into the array.
Im sending this from max:
/foo/array 1. 1.1 1.2 1.3 1.4 1.5 1.6 1.7
and I'm getting this in the chuck output:
402436704 :(OscEvent)
got (via OSC): 1.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000 0.000000
the chuck code:
| Code: | OscRecv recv;
6449 => recv.port;
float f [ 8 ];
recv.listen();
recv.event( "/foo/array, f f f f f f f f " ) @=> OscEvent @ oe;
while( true )
{
oe => now;
<<<oe>>>;
while( oe.nextMsg())
{
oe.getFloat() @=> f [0];
<<< "got (via OSC):", f [0], f [1],f [2],f [3],f [4],f [5],f [6],f [7]>>>;
}
} |
|
|
|
Back to top
|
|
 |
Antimon

Joined: Jan 18, 2005 Posts: 3390 Location: Sweden
Audio files: 218
G2 patch files: 93
|
Posted: Fri Feb 19, 2010 2:41 am Post subject:
|
 |
|
Ah ok, that makes sense. You're only taking the first float, after all!
This line copies a single float value from the incoming message to the first position in the array:
| Code: | oe.getFloat() @=> f [0];
|
Try adding this below the above:
| Code: | | oe.getFloat() @=> f [1]; |
It will copy one more. One way to take all values could be to make a loop:
| Code: | for (0 => int i; i < 8; i++) {
oe.getFloat() => f [i];
}
|
Edit: forgot to turn off html - and oh yeah, you don't need those @ signs when copying floats.
/Stefan _________________ Antimon's Window
@soundcloud @Flattr @myspace A blog home - you can't explain music |
|
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Fri Feb 19, 2010 7:47 am Post subject:
|
 |
|
What you could also do to make it yet better would be to initiate the array as length 0, then append the incoming floats based on "while(OE.nextMessage())" and grow the array dynamically.
That way the array you end up with will always have the exact same length as the message received. Right now the number 8 gets defined three times. Once implicitly as "f f f f f f f f", once at defining the array and once in the "for" loop.
This gets rid of the "magic numbers" and will help prevent errors when later updating the code. I think it also saves a line of code. _________________ Kassen |
|
|
Back to top
|
|
 |
jirko

Joined: Dec 15, 2009 Posts: 59
|
Posted: Fri Feb 19, 2010 9:23 am Post subject:
|
 |
|
you guys are ninjas!
thanks a lot for the help. |
|
|
Back to top
|
|
 |
Kassen
Janitor


Joined: Jul 06, 2004 Posts: 7678 Location: The Hague, NL
G2 patch files: 3
|
Posted: Sun Feb 21, 2010 5:41 pm Post subject:
|
 |
|
With some practice you too will be shooting your ChucK operators like ninja darts.
(hey! why do we not have a ninja emoticon?) _________________ Kassen |
|
|
Back to top
|
|
 |
|