BD
Joined: Mar 08, 2008 Posts: 1 Location: US
|
Posted: Sat Mar 08, 2008 6:57 pm Post subject:
Midi OSC Subject description: Sending Midi over OSC |
 |
|
Hi, I am new to Chuck and am working on integrating two examples that are provided with Chuck -- "gomidi.ck" and ""OSC_send.ck". Essentially, I need to send midi data via an OSC port.
my code is attached, but throws an error. There might be data mismatch problems where I am adding the Midi input data received in "gomidi.ck" (i.e. msg.data1,msg.data2, msg.data3) to the OSC send Object (xmit) . Would appreciate if anyone can take a look into this and suggest. Thanks!
| Code: |
"localhost" => string hostname;
// number of the device to open (see: chuck --probe)
1 => int device;
// get command line
if( me.args() ) me.arg(0) => Std.atoi => device;
// the midi event
MidiIn min;
// the message for retrieving data
MidiMsg msg;
///OSC SET-UP
6449 => int port;
// get command line
if( me.args() ) me.arg(0) => hostname;
if( me.args() > 1 ) me.arg(1) => Std.atoi => port;
////OSC SET_UP////
// send object
OscSend xmit;
// aim the transmitter
xmit.setHost( hostname, port );
// open the device
if( !min.open( device ) ) me.exit();
// print out device that was opened
<<< "MIDI device:", min.num(), " -> ", min.name() >>>;
//***work on this code from here...send midi to osc..
// infinite time loop
while( true )
{
// start the message...
// the type string ',f' expects a single float argument
xmit.startMsg( "/sndbuf/buf/rate", "d" );
min => now;
// get the message(s)
while( min.recv(msg) )
{
// print out midi message
<<< msg.data1, msg.data2, msg.data3 >>>;
msg.data1 => xmit.addFloat;
msg.data2 => xmit.addFloat;
msg.data3 => xmit.addFloat;
<<< "sent (via OSC):", msg.data1, msg.data2, msg.data3 >>>;
}
}
|
|
|
Frostburn

Joined: Dec 12, 2007 Posts: 255 Location: Finland
Audio files: 9
|
Posted: Sun Mar 09, 2008 1:49 am Post subject:
|
 |
|
I haven't used OSC for anything yet but maybe you're supposed to have an "f" where you have xmit.startMsg( "/sndbuf/buf/rate", "d" ); . And then convert the midi messages that are of type int to type float by dividing with 127.0 . If the message is actually 14 bits in two data of 7 bits, then first recombine them and divide accordingly.
| Code: | "localhost" => string hostname;
// number of the device to open (see: chuck --probe)
1 => int device;
// get command line
if( me.args() ) me.arg(0) => Std.atoi => device; //First argument
// the midi event
MidiIn min;
// the message for retrieving data
MidiMsg msg;
///OSC SET-UP
6449 => int port;
// get command line
if( me.args() > 1 ) me.arg(1) => hostname; //We already used one argument up there ^
if( me.args() > 2 ) me.arg(2) => Std.atoi => port; //Third argument
////OSC SET_UP////
// send object
OscSend xmit;
// aim the transmitter
xmit.setHost( hostname, port );
// open the device
if( !min.open( device ) ) me.exit();
// print out device that was opened
<<< "MIDI device:", min.num(), " -> ", min.name() >>>;
//***work on this code from here...send midi to osc..
// infinite time loop
while( true )
{
// start the message...
// the type string ',f' expects a single float argument
xmit.startMsg( "/sndbuf/buf/rate", "f" );
min => now;
// get the message(s)
while( min.recv(msg) )
{
// print out midi message
<<< msg.data1, msg.data2, msg.data3 >>>;
msg.data1/127.0 => xmit.addFloat;
msg.data2/127.0 => xmit.addFloat;
msg.data3/127.0 => xmit.addFloat;
}
} |
_________________ To boldly go where no man has bothered to go before. |
|