electro-music.com   Dedicated to experimental electro-acoustic
and electronic music
 
    Front Page  |  Articles  |  Radio
 |  Media  |  Forum  |  Wiki  |  Links  |  Store
Forum with support of Syndicator RSS
 FAQFAQ   CalendarCalendar   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   LinksLinks
 RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in  Chat RoomChat Room 
Live streaming at radio.electro-music.com

  host / artist show at your time
  mosc Live music with Twyndyllyngs - Bill Fox and Howard Moscovitz
Please visit the chat
 Forum index » DIY Hardware and Software » ChucK programming language
Storing a list from Max to Chuck array
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [11 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
jirko



Joined: Dec 15, 2009
Posts: 59

PostPosted: Wed Feb 17, 2010 12:14 pm    Post subject: Storing a list from Max to Chuck array Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 3688
Location: Sweden
Audio files: 267
G2 patch files: 96

PostPosted: Thu Feb 18, 2010 4:26 am    Post subject: Reply with quote  Mark this post and the followings unread

There are nine 'f's in the OSC event specification, but the array only holds 8.

/Stefan

_________________
Antimon's Window
@soundcloud @Flattr home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
jirko



Joined: Dec 15, 2009
Posts: 59

PostPosted: Thu Feb 18, 2010 5:07 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 3688
Location: Sweden
Audio files: 267
G2 patch files: 96

PostPosted: Thu Feb 18, 2010 5:22 am    Post subject: Reply with quote  Mark this post and the followings unread

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 home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
jirko



Joined: Dec 15, 2009
Posts: 59

PostPosted: Thu Feb 18, 2010 7:37 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 3688
Location: Sweden
Audio files: 267
G2 patch files: 96

PostPosted: Thu Feb 18, 2010 8:13 am    Post subject: Reply with quote  Mark this post and the followings unread

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 home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
jirko



Joined: Dec 15, 2009
Posts: 59

PostPosted: Fri Feb 19, 2010 2:16 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message
Antimon



Joined: Jan 18, 2005
Posts: 3688
Location: Sweden
Audio files: 267
G2 patch files: 96

PostPosted: Fri Feb 19, 2010 2:41 am    Post subject: Reply with quote  Mark this post and the followings unread

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 home - you can't explain music
Back to top
View user's profile Send private message Visit poster's website
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Fri Feb 19, 2010 7:47 am    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website
jirko



Joined: Dec 15, 2009
Posts: 59

PostPosted: Fri Feb 19, 2010 9:23 am    Post subject: Reply with quote  Mark this post and the followings unread

you guys are ninjas!
thanks a lot for the help.
Back to top
View user's profile Send private message
Kassen
Janitor
Janitor


Joined: Jul 06, 2004
Posts: 7678
Location: The Hague, NL
G2 patch files: 3

PostPosted: Sun Feb 21, 2010 5:41 pm    Post subject: Reply with quote  Mark this post and the followings unread

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
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [11 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
 Forum index » DIY Hardware and Software » ChucK programming language
Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
e-m mkii

Please support our site. If you click through and buy from
our affiliate partners, we earn a small commission.


Forum with support of Syndicator RSS
Powered by phpBB © 2001, 2005 phpBB Group
Copyright © 2003 through 2009 by electro-music.com - Conditions Of Use