_init.scd 898 Bytes
Newer Older
PLN (Algolia) committed
1 2 3 4 5 6 7 8 9 10
// Evaluate the block below to start the mapping MIDI -> OSC.
(
var on, off, cc;
var osc;

osc = NetAddr.new("127.0.0.1", 6010);

MIDIClient.init;
MIDIIn.connectAll;

11 12 13 14 15
// Initial: sends velocity on note's channel
// on = MIDIFunc.noteOn({ |val, num, chan, src|
// 	osc.sendMsg("/ctrl", num.asString, val/127);
// });

PLN (Algolia) committed
16
on = MIDIFunc.noteOn({ |val, num, chan, src|
17 18
	// it will be passed the arguments val, num, chan, and src, corresponding to the message value (e.g. velocity, control value, etc.)
	osc.sendMsg("/ctrl", "note", (num - 60));
PLN (Algolia) committed
19 20 21
});

off = MIDIFunc.noteOff({ |val, num, chan, src|
22
	osc.sendMsg("/ctrl", "note", 0);
PLN (Algolia) committed
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
});

cc = MIDIFunc.cc({ |val, num, chan, src|
	osc.sendMsg("/ctrl", num.asString, val/127);
});

if (~stopMidiToOsc != nil, {
	~stopMidiToOsc.value;
});

~stopMidiToOsc = {
	on.free;
	off.free;
	cc.free;
};
)

// Evaluate the line below to stop it.
// ~stopMidiToOsc.value;