the best thing i can tell you about midi ins/outs is to find the example files that deal with midi and repurpose them how you need. they are basic enough that it should be easy to do.
http://chuck.cs.princeton.edu/doc/examples/you'll basically find the port, wrap it in an object, and then manipulate that object.
i'll try to break this down...
the first line is a comment, anything preceded by '//' is a comment explaining to you in english what is going on.
so it says, use chuck --probe in the terminal to find your midi ports.
then you choose which port in your code (0 in this case).
the next line means you can pass in the midi device as an argument when you run the code from command line (terminal / dos / whatever).
then you name the midi-in object ('min') so you can reference it later.
then you give a name for the message it will send ('msg').
open the device (aka turn it on).
print out the opening of the device for some feedback that it actually happened.
set up a loop to run infinitely... (while(true))
wait until a message is received from midi port.
print out the midi message and return to the top of the loop to wait for the next message.
example:
Code: Select all// number of the device to open (see: chuck --probe)
0 => 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;
// open the device
if( !min.open( device ) ) me.exit();
// print out device that was opened
<<< "MIDI device:", min.num(), " -> ", min.name() >>>;
// infinite time-loop
while( true )
{
// wait on the event 'min'
min => now;
// get the message(s)
while( min.recv(msg) )
{
// print out midi message
<<< msg.data1, msg.data2, msg.data3 >>>;
}
}
this is a VERY basic example and doesn't actually do anything with the midi message other than display it on screen, so you'd either need to find more examples to handle the messages, or write your own.
midi out will of course be slightly different (man pg. 23), but this was easy enough to break down line by line.
you could use the above code to interpret some midi messages and then try to create your own from what you learn.