| Author |
Message |
t.alfred
Joined: May 06, 2008 Posts: 2 Location: Norway
|
Posted: Tue May 06, 2008 4:04 am Post subject:
OSC in Chuck |
 |
|
Hello,
could someone post an example that uses Open Sound Control
as input but receives more than one OSC event. The examples provided
with Chuck doesn't show how to use more than one eventat a time.
Here's examples of events I want to recieve:
"/instrument1/noteOn, f, i" (f is oscillator frequency in Hz and i is velocity)
"/instrument1/noteOff, f, i"
"/instrument1/filterFrequency, f" (f is filter frequency)
and so on..
How do I handle different signals in the main loop?
Thanks,
Alfred Last edited by t.alfred on Tue May 06, 2008 2:52 pm; edited 1 time in total |
|
|
Back to top
|
|
 |
quilime
Joined: Apr 22, 2008 Posts: 2 Location: CA, USA
|
Posted: Tue May 06, 2008 10:02 am Post subject:
|
 |
|
Hi t.alfred,
Can you send all your variables in one message and then parse them out in ChucK? I usualy send a "note id" integer for polyphony.
| Code: |
//java pseudocode to send OSC message
// send all control variables in one message
OscMessage mssg = new OscMessage("/instrument, i f i f i f" );
mssg.add(1); // instrument1 id
mssg.add(freq1); // instrument1 noteOn frequency float
mssg.add(vel1); // instrument1 noteOn velocity int
mssg.add(freq2); // instrument2 noteOff frequency float
mssg.add(vel2); // instrument2 noteOff velocity int
mssg.add(filterFreq); // filter frequency float
oscSend(mssg, "1234");
|
| Code: |
// receiving with chuck
OscRecv recv;
1234 => recv.port;
recv.listen();
recv.event( "/instrument, i f i f i f" ) @=> OscEvent oe;
SinOsc s[40]; // sin with polyphony 40
while ( true )
{
oe => now;
while ( oe.nextMsg() != 0 )
{
oe.getInt() => int id;
oe.getFloat() => float freqnoteOn;
oe.getInt() => int velnoteOn;
oe.getFloat() => float freqnoteOff;
oe.getInt() => int velnoteOff;
oe.getFloat() => float freqFilter;
// then do something ...
freq => s[id].freq;
//.... etc
// then send to the dac
s[id] => dac;
}
}
|
this code is untested, but hope it helps. Last edited by quilime on Tue May 06, 2008 12:55 pm; edited 1 time in total |
|
|
Back to top
|
|
 |
t.alfred
Joined: May 06, 2008 Posts: 2 Location: Norway
|
Posted: Tue May 06, 2008 12:45 pm Post subject:
|
 |
|
Thanks for answering!
I guess this is a possibility, it's the way I have to do it now. The only
problem is when you have lots of variables you want to send, it
will soon become very hard to handle. Besides its much more
convenient to send data in smaller amounts. This way you don't have
to pack and send all the data that's not changing.
The beauty of OSC is of course that you can give the variables/events
their own name, so why shouldn't it be possible to handle events
with different names in ChucK?
Al |
|
|
Back to top
|
|
 |
quilime
Joined: Apr 22, 2008 Posts: 2 Location: CA, USA
|
Posted: Tue May 06, 2008 12:57 pm Post subject:
|
 |
|
| Could you maybe just send OSC signals on a few ports at once? Maybe you could have a few OscRecv objects in ChucK listening on unique ports.... send all your filter messages on one port, and send all your note messages on another port... Not sure if that would work. I haven't tested that myself, as I am just learning OSC and learning the same things you seem to be going through. |
|
|
Back to top
|
|
 |
Antimon

Joined: Jan 18, 2005 Posts: 876 Location: Sweden
Audio files: 6
G2 patch files: 48
|
Posted: Wed May 07, 2008 6:59 am Post subject:
|
 |
|
Is it OK to copy/paste another person's post from the ChucK list? Mike Clemow had some problems that seems very close to what you want. This was his solution:
| Quote: | Hey folks,
So, using a combination of suggestions, I have arrived at a much
simpler version of the code that seems to work great. I haven't
scaled it up to grab all 14 OSC message types, but I think that I'm in
a much better place to do so at this point. I might have too many
me.yield() calls now, actually, but it works tons better.
thanks again!
mike
---
8000 => int oscport;
// the messages for the osc objects
"/leftraw, i" => string leftraw;
"/leftavg, i" => string leftavg;
spork ~ oscListener( oscport, leftraw );
me.yield();
spork ~ oscListener( oscport, leftavg );
me.yield();
SinOsc raw => dac;
SinOsc avg => dac;
// a generic osc listener shred
fun void oscListener( int port, string osctype ) {
// create our OSC receiver
OscRecv recv;
port => recv.port;
recv.listen();
int val;
string type;
// create an address in the receiver, store in new variable
recv.event( osctype ) @=> OscEvent oe;
while( true ) {
// wait for osc event to arrive
oe => now;
while( oe.nextMsg() ) {
oe.getInt() => val;
osctype => type;
if( type == leftraw ) {
val => raw.freq;
}
else if( type == leftavg ) {
val => avg.freq;
}
me.yield();
}
}
}
while( true ) {
1::second => now;
}
|
Here's a OSC shredding class I posted in that discussion:
| Code: | class OscListener {
fun void listenOnOsc(string msg, int port) {
OscRecv recv;
port => recv.port;
recv.listen();
recv.event(msg) @=> OscEvent oe;
while (true) {
oe => now;
while (oe.nextMsg()) {
receiveEvent(oe);
}
}
}
fun void receiveEvent(OscEvent oe) {
}
}
SinOsc raw => dac;
SinOsc avg => dac;
//---- Listen on OSC for raw
class ListenOnRaw extends OscListener {
fun void receiveEvent(OscEvent oe) {
<<< "Received raw event" >>>;
oe.getInt() => raw.freq;
}
}
ListenOnRaw listenOnRaw;
spork ~ listenOnRaw.listenOnOsc("/leftraw/press,i", 8000);
//---- Listen on OSC for avg
class ListenOnAvg extends OscListener {
fun void receiveEvent(OscEvent oe) {
<<< "Received avg event" >>>;
oe.getInt() => avg.freq;
}
}
ListenOnAvg listenOnAvg;
spork ~ listenOnAvg.listenOnOsc("/leftavg/press,i", 8001);
while (true) {
1::second => now;
} |
Ah, damn - I messed up the indentation. Don't have time to fix it now, maybe later.
/Stefan _________________ You are Wendy Mackaye, first girl on the red planet. |
|
|
Back to top
|
|
 |
|