21.3.07

CC Week 3 - OSC Responder

Consider the structure of a MIDI message and build functions that can transmit and receive all note on / off and modulation information between two computers using the OSC protocol. Consider the types of arguments that the function should take to make the function transportable and easily useable on other computers.


// ------------------------------------------------------------------------------------
// RECEIVER SETUP - OSC RESPONDER
// ------------------------------------------------------------------------------------

(
// Open Sound Control Responder
r = OSCresponder(
addr: nil, // nil respond to messages from anywhere
cmdName: "Note Off", // an OSC command (same name as messge sent)
cmdName: "Note On",
cmdName: "Key Pressure",
cmdName: "Control Change",
cmdName: "Program Change",
cmdName: "Channel Pressure",
cmdName: "Pitch Wheel Change",
action: { // action to perform

// Arguments - default
arg time, // OSC time
resp, // responder name
msg, // message
addr // address
;

// Feedback
[time, resp, msg, addr].postln;
}
).add; // add method - adds OSC responder to server
)


// ------------------------------------------------------------------------------------
// SENDER SETUP - OSC SEND USING NETADDR + SENDMSG
// ------------------------------------------------------------------------------------

(
// Setup the Network for the target computer (or the computer that is having data sent to it)
n = NetAddr(
hostname: "129.127.86.100", // IP Address of target computer
port: 57120 // Port Number that SC uses
);
)

(
// Send a message to that computer
n.sendMsg(
"Note Off", // Command Name (Same as OSCResponder Command Name)
"1000nnnn, 0kkkkkkk, 0vvvvvvv" //(kkkkkkk) is the key (note) number //(vvvvvvv) is the velocity
);
// Send a message to that computer
n.sendMsg(
"Note On",
"1001nnnn, 0kkkkkkk, 0vvvvvvv"
);
// Send a message to that computer
n.sendMsg(
"Key Pressure",
"1010nnnn, 0kkkkkkk, 0vvvvvvv" //(vvvvvvv) is the pressure value
);
// Send a message to that computer
n.sendMsg(
"Control Change",
"1011nnnn, 0ccccccc, 0vvvvvvv" // (ccccccc) is the controller number (0-119)
//(vvvvvvv) is the controller value (0-127)
);
// Send a message to that computer
n.sendMsg(
"Program Change",
"1100nnnn, 0ppppppp" // (ppppppp) is the new program number
);
// Send a message to that computer
n.sendMsg(
"Channel Pressure",
"1101nnnn, 0vvvvvvv" //(vvvvvvv) is the pressure value
);
// Send a message to that computer
n.sendMsg(
"Pitch Wheel Change",
"1110nnnn, 01111111, 0mmmmmmm" //(llllll) are the least significant 7 bits //(mmmmmm) are the most significant 7 bits
);
)


[1] Christian Haines. "Creative Computing: Semester 1, Week 3. Architecture & OSC." Lecture presented at EMU, University of Adelaide, South Australia, 15th March 2007.