Eclectic I

Tuesday, March 25, 2008

CC3A wk 3

Triggering MIDI via OSC

I enjoyed working as a group on this project. We each seemed to contribute to a certain aspect of the exercise, although to me it is apparent that Jake and Dave have a much better grasp of the language than I. Although what they did made sense to me, I don't think I could have discovered how to go about doing it as quickly as they did.



Rather then look at the code sprawled across the screen, feel free to download them as a compact zip file. :)

All of the rtf files







/*
COMPUTER 1.
(1a) Takes MIDI note data and converts it to frequency
*/

//MIDI initialise
MIDIClient.init;

//connect to Remote SL (novation)
MIDIIn.connectByUID(
inport: 0,
uid: MIDIClient.sources.at(0).uid
);


//so notes will come up on the post whatsit
(

MIDIIn.noteOn = {

arg uid,
chan,
num,
vel
;

//["UID", uid, "Channel", chan, "Note", num, "Velocity", vel].postln;
x = num.midicps.postln; //post the freq (x) to yourself

{ //send x to the network (n)

n.sendMsg(
"treeTits",
x.postln;
);

}.value

};

)

/*
COMPUTER 1.
(1b) Sends the frequency (variable x) via OSC to computer 2
*/


//initialise Network

(

n = NetAddr(
hostname: "129.127.196.19",
port: 57120
);

)


Computer 2


(
// Open Sound Control Responder
r = OSCresponder
(
addr: nil, // Nil respond to messages from anywhere
cmdName: "treeTits", // An OSC command (same name as messge sent)
action: { // Action to perform

// Arguments - default
arg time, // OSC time
resp, // Responder name
msg, // Message
addr // Address
;

// Feedback
// [time, resp, msg, addr].postln;
x = {msg.at(1).cpsmidi}.value.postln;

{
// Send a message to that computer - in this case the converted MIDI value
n.sendMsg(
"treeTits", // Command Name (Same as OSCResponder Command Name)
//MIDIIn.noteOn // Argument Value
x.postln
);
}.value.postln;

{
// Send MIDI Note Value
m.noteOn(
chan: 1, // MIDI Channel
note: x, // Note Number
veloc: 90 // Velocity
);
m.noteOff(
chan: 1, // MIDI Channel
note: x, // Note Number
veloc: 90 // Velocity
);
}.value

}
).add; // Add method - adds OSC responder to server
)
// Open Sound Controller Sender

// Connect by Device Index Address
MIDIIn.connectByUID(
inport: 0,
uid: MIDIClient.sources.at(4).uid
);


(
// Setup MIDIIn Controller
MIDIIn.noteOn =
{

// Arguments
arg uid, // Device ID
chan, // MIDI Channel
num, // Note Number
vel // Velocity
;

// Feedback
//["UID", uid, "Channel", chan, "Note", num, "Velocity", vel].postln;

~noteToFreq = num.midicps.postln;

{
// Send a message to that computer
n.sendMsg(
"treeTits", // Command Name (Same as OSCResponder Command Name)
//MIDIIn.noteOn // Argument Value
~noteToFreq.postln
);
}.value


};
)


Computer 3 - playing the simple synth - MIDI out

(
// Setup MIDIOut
m = MIDIOut(
port: 0,
uid: MIDIClient.destinations.at(8).uid
);
)

(
// Open Sound Control Responder
r = OSCresponder
(
addr: nil, // Nil respond to messages from anywhere
cmdName: "treeTits", // An OSC command (same name as messge sent)
action: { // Action to perform

// Arguments - default
arg time, // OSC time
resp, // Responder name
msg, // Message
addr // Address
;

// Feedback
// [time, resp, msg, addr].postln;
x = {msg.at(1)}.value.postln;

{
// Send MIDI Note Value
m.noteOn(
chan: 1, // MIDI Channel
note: x, // Note Number
veloc: 90 // Velocity
);
m.noteOff(
chan: 1, // MIDI Channel
note: x, // Note Number
veloc: 90 // Velocity
);
}.value

}
).add; // Add method - adds OSC responder to server
)




3 Comments:

Blogger Luke.Digance - Eclectic I said...

Looking back, I wish I wasn't such a monkey toucher.

4:57 AM  
Blogger Ben said...

Amen.

7:52 AM  
Blogger Luke.Digance - Eclectic I said...

I should delete that post. Obviously I left my account open. But its funny so fuck it. Besides, the monkeys like to be touched, I regret nothing.... ?/???

6:08 PM  

Post a Comment

<< Home