[chuck-users] ChuK control via OSC

karl petermichl audioworld at gmail.com
Wed Jan 17 07:20:09 EST 2007


Hi enrike,

Thank you SO MUCH for the concrete, to-the-point clarifications!
Yes, I do not need strings, i want integers, so I will change the python
code.
It is good to know that floats are not so easy in python, I will ue your
divide-by-workaround in cae I need floats.

I will try, test and use all this later tomorrow, I will let you know if it
was a success and post some uasble code here.

Thank you again,
karl.

-----Ursprüngliche Nachricht-----
Von: chuck-users-bounces at lists.cs.princeton.edu
[mailto:chuck-users-bounces at lists.cs.princeton.edu] Im Auftrag von altern
Gesendet: Mittwoch, 17. Januar 2007 10:09
An: ChucK Users Mailing List
Betreff: Re: [chuck-users] ChuK control via OSC

hi karl!

ok, I have been dealing with OSC in ChucK recently and many times when the
data doesnt arrive but the code seems ok there is usually a problem with the
type of the data. Sometimes you think you are sending an int 1 and actually
is a float 1.0 etc...

And this is a similar case. I checked your code and it looked ok. So i went
back to python and did print type(value) before sending it and python said
that value variable is a string. So Tkinter values coming from sliders seem
to be strings. Weird, but problem solved, we just need to listen for strings
in Chuck. However, you are very unlikely to need a string but rather an int
or a float to chuck it into some frequency or amplitude. I dont think it is
possible to casting strings into ints or floats in ChucK (correct me if i am
wrong!), string support is yet basic but it seems to be coming soon.
So you need to cast your value to the right type in python with
int(value) or float(value). Something like this:
osc.sendMsg('/slider1', [int(value)], "127.0.0.1", 9000)

However, on top of all this there was an error on your code, you did
recv.event( "/slider1, int" ) @=> OscEvent oe;

but the right code would be
recv.event( "/slider1, i" ) @=> OscEvent oe;

Say you send several values from python like this osc.sendMsg('/slider1',
[1, 0.3, 'hello'], "127.0.0.1", 9000) you would listen to it this way
recv.event( "/slider1, i f s" ) @=> OscEvent oe;

and this is all the chuck code to listen to your slider, i changed a couple
of things on top of the i to make it more clear

OscRecv recv;
9000 => recv.port;
recv.listen();

recv.event( "/slider1, int" ) @=> OscEvent oe;

while( true ) {
     oe => now;
     while( oe.nextMsg() ){
         oe.getInt() => int i;
         <<< "got (via OSC):", i>>>;
         1::ms=>now;
     }
}

Note that one problem with the sliders in tkinter (same is true for wxpython
not sure about other libraries) is that it is difficult
(impossible?) to get them to operate with float numbers, if you want to get
0 to 1 values they stick to binary 0 or 1. I am not sure if this can
  be configured somehow in python (maybe extending the class) but the simple
trick would be to set it to display 0 to 100 and divide the value /100
before sending it or after receiving it. Note that it would still display 0
to 100  on the gui

having more than one slider in the interface you are likely to have to spork
one shred from each of them to listen for incoming messages . 
Check the documentation about shreds and if you have problems with this ask
in the list.

enrike


 

-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.432 / Virus Database: 268.16.13/632 - Release Date: 16.01.2007
16:36
 



More information about the chuck-users mailing list