«OSC to MIDI converter (GUI)» by rukano

on 04 Jan'12 21:04 in midioscconverter

Code written in about 1 hour trying to emulate gui and behaviour of osculator. Ended up being just a OSC to MIDI CC converter... but it's open to other things. Feel free to enhance and complement, or even make a class for this (and a future Quark?)

Goal was to use less than 100 lines. Turned up working with just 35 :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
var window = Window("OSC to MIDI", Rect(200, 200, 690, 540), false).front;
var layout = window.addFlowLayout((0@0),(0@0));
var font = Font("Monaco", 12), size1 = (200@20), size2 = (70@20), size3 = (20@20), midi, net, responders = ();
var gui_addrlabel = StaticText(window, (50@20)).font_(font).string_("addr").align_(\center);
var gui_addr = TextField(window, (150@20)).font_(font).align_(\center).string_("all").enabled_(false); // TODO!
var gui_portlabel = StaticText(window, (50@20)).font_(font).string_("port").align_(\center);
var gui_port = NumberBox(window, (75@20)).font_(font).value_(0).align_(\center).clipLo_(0).clipHi_(0).enabled_(false); // TODO!
var gui_space = StaticText(window, (15@20));
var gui_midiinit = Button(window, (75@20)).states_([["INIT"], ["REFRESH"]]);
var gui_devicelabel = StaticText(window, (50@20)).font_(font).string_("device").align_(\center);
var gui_mididevices = PopUpMenu(window, (175@20)).items_(["-- init midi first --"]);
gui_midiinit.action_({ |but|
	if(but.value == 1) { MIDIClient.init } { but.value_(1) };
	gui_mididevices.items_(MIDIClient.destinations.collect{ |dest| dest.name })
});
gui_mididevices.action_({ |m| midi = MIDIOut(m.value) });
layout.nextLine; // labels
StaticText(window, size1).font_(font).string_("msg").align_(\center);
["min", "max", "type", "chan", "num", "min", "max"].do{ |name| StaticText(window, size2).font_(font).string_(name).align_(\center) };
25.do{ |i| // 25 responders with conversion
	var cmd="/cmd"+/+i, inmin=0, inmax=1, type="control", chan=0, outmin=0, outmax=127, num=50+i;
	TextField(window, size1).font_(font).stringColor_(Color.green(0.5)).string_(cmd).action_({ |v| cmd = v.string; responders[i].cmdName = cmd });
	NumberBox(window, size2).scroll_step_(0.01).step_(0.001).value_(inmin).align_(\center).stringColor_(Color.red(0.8)).action_({ |v| inmin = v.value });
	NumberBox(window, size2).scroll_step_(0.01).step_(0.001).value_(inmax).align_(\center).stringColor_(Color.red(0.8)).action_({ |v| inmax = v.value });
	PopUpMenu(window, size2).items_(["control"]).stringColor_(Color.yellow(0.8)).value_(0).action_({ |v| type = v.items[v.value].asSymbol });
	NumberBox(window, size2).value_(chan).clipLo_(0).clipHi_(15).align_(\center).action_({ |v| chan = v.value });
	NumberBox(window, size2).value_(num).clipLo_(0).clipHi_(127).align_(\center).action_({ |v| num = v.value });
	NumberBox(window, size2).value_(outmin).clipLo_(0).clipHi_(127).align_(\center).stringColor_(Color.blue(0.8)).action_({ |v| outmin = v.value });
	NumberBox(window, size2).value_(outmax).clipLo_(0).clipHi_(127).align_(\center).stringColor_(Color.blue(0.8)).action_({ |v| outmax = v.value});
	responders[i] = OSCresponder(net, cmd, { |time, resp, msg, addr|
		var val = msg[1].linlin(inmin, inmax, outmin, outmax).round;
		[type, chan, num, val].postln;
		midi.perform(type, chan, num, val);
	}).add;
};
raw 2903 chars (focus & ctrl+a+c to copy)
reception
comments