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 
 Forum index » DIY Hardware and Software » ChucK programming language
[SOLVED] Timing when reading data from OSC into array
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 Posts]
View unread posts
View new posts in the last week
Mark the topic unread :: View previous topic :: View next topic
Author Message
agkbill



Joined: Feb 15, 2007
Posts: 11
Location: Uppsala Sweden

PostPosted: Wed Dec 15, 2010 2:47 pm    Post subject:  [SOLVED] Timing when reading data from OSC into array Reply with quote  Mark this post and the followings unread

Hi!

Working on a sequencer app for monome (www.monome.org) but I can not get datainput from OSC to sync right in time.

As a start I work with one row on the monome, that is one row of 8 buttons with LED inside.

I use a array monome_row[] with 8 entry to store data about positions.

Active is LED on and 1, non active the opposing.


when the sequence is running the pattern moves one step every 250 ms for example.

I do that with a function move_monome_row[] that move all positions one step and put the last one first.

Then to show the state with the LED I have a function p_led that convert the positions in the array monome_row[] to a int that light up that pattern on the monome.

Well, all this work great.

The challenge is now to be able to modify the pattern in the array by pressing the buttons.

monome send three data, row, column, and state. State is if the button is pressed or not.

To initiate OSC from monome I use:

Code:
// create our OSC receiver
OscRecv recv;
// use port 8000
8000 => recv.port;
// start listening (launch thread)
recv.listen();
// create an address in the receiver, store in new variable
recv.event("/sleep/press", ",iii") @=> OscEvent oe;




For now I only use the x value.

Code:
while( true )
{
  200::ms => now;
 
   // get_ledd räknar ut värde för aktuell rad och skickar ut till monome genom p_led
   get_ledd( monome_row ) => p_led;
   move_monome_row( monome_row );
 
 
 

    // grab the next message from the queue.
    while ( oe.nextMsg() != 0 )
    {
           oe.getInt() => x;   
      oe.getInt() => y;
      oe.getInt() => state;
      x => xn;
      <<<xn>>>;
      <<<"monome_row" , monome_row[xn]>>>;
      <<<y>>>;
      <<<state>>>;
      if( monome_row[xn] == 1 )
      {
        0 => monome_row[xn];
      }
      else
      {
        1 => monome_row[xn];
        <<<"¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤">>>;
      }
   

      

    }
}



What I want is to invert the state of the position who button I press.

But I don’t get the response I want at all.

It is like the data I get pressing a button is not altering the array. If I hold it for a while it does but in a way that I cant control.

I should be able for example to follow a LED position moving and then by pressing the button in front of it for example adding that one.

Anyone who have any ide way I get this behavior?



All input most appreciated.


All the best!
/Christer[/code]

Last edited by agkbill on Fri Dec 17, 2010 11:21 am; edited 1 time in total
Back to top
View user's profile Send private message
vrachnasormora



Joined: Mar 22, 2007
Posts: 42
Location: Preveza,Greece

PostPosted: Wed Dec 15, 2010 5:32 pm    Post subject: Reply with quote  Mark this post and the followings unread

Hi Christer,

First you need to wait on the OSC event for incoming packets:

Code:
while ( true )
{
    oe => now; 

    // grab the next message from the queue.
    while ( oe.nextMsg() != 0 )
    {
        oe.getInt() => x;   
        oe.getInt() => y;
        oe.getInt() => state;
        .
        .
        .
    }
}


if you use this loop as the main one, create a function that calls get_ledd and
move_monome_row every 200 ms and spork this one before the main loop:

Code:
fun void make_soup()
{
    while( true )
    {
        200::ms => now;
       
        // get_ledd räknar ut värde för aktuell rad och skickar ut till monome genom p_led
        get_ledd( monome_row ) => p_led;
        move_monome_row( monome_row );
    }
}


spork~ make_soup();
   
   
while ( true )
{
    oe => now; 

    // grab the next message from the queue.
    while ( oe.nextMsg() != 0 )
    {
        oe.getInt() => x;   
        oe.getInt() => y;
        oe.getInt() => state;
        x => xn;
        <<<xn>>>;
        <<<"monome_row" , monome_row[xn]>>>;
        <<<y>>>;
        <<<state>>>;
        if( monome_row[xn] == 1 )
        {
            0 => monome_row[xn];
        }
        else
        {
            1 => monome_row[xn];
            <<<"¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤¤">>>;
        }
    }
}


I'm not sure but I also think that you may left the "Disable HTML in this post" checkbox empty before submitting your last post and the parser got naughty with your code.If you did, please remember to check it next time.
Don't let your code mess with mr. Parser.Bye Laughing
Back to top
View user's profile Send private message
agkbill



Joined: Feb 15, 2007
Posts: 11
Location: Uppsala Sweden

PostPosted: Fri Dec 17, 2010 10:29 am    Post subject: Reply with quote  Mark this post and the followings unread

Dear vrachnasormora,

Thank you very much.

What happens there is that you kind of start another chuck program that are running in parallel and they are sharing data in the variables, int or arrays and so on.
Then it should be in that way I should do if I whant to use input from my PC-keyboard as well.


I did however had some work to get it working. When I tried the code the first time it did behaved very strange and not as I wanted at all.

I stripped down the function so I finally saw exacly what data that was handled.

Then I could se that my monome sent not one set of data but two!

first X, Y and state 1 (button pressed) but then when I released the button it send again X,Y and state 0 (button released).

That was the big reason for strange result.

I put in a line that make my arrange modification part only case about state 1 data and now it works very well!

Things is moving forward. Very Happy

All the best!

/Christer
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic Moderators: Kassen
Page 1 of 1 [3 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
Niio1

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