Grafer

Grafer
2006 by LFSaw
Do you know these little drawing-boards with two knobs to control a pen in it?
This patch emulates one.
~res = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] * 10; w.refresh ( w = SCWindow("Grafer", Rect(128, 64, 340, 360)); w.view.background_(Color.gray(1)); w.drawHook_{ Pen.use { Pen.width = 2; Color.black.set; Pen.beginPath; ~point = (~res[0])@(~res[1]); Pen.moveTo(~point); ((~res.size div: 2) - 1).do{|i| ~point = ~res[(2*i)+2]@(~point.y); Pen.lineTo(~point); ~point = ~res[(2*i)+2]@~res[(2*i)+3]; Pen.lineTo(~point); }; ~res.size.odd.if{ ~point = (~res.last)@(~point.y); Pen.lineTo(~point); }; Pen.stroke; } }; w.front; ) ~lastWasX = true; ~extentX = {|direction = 1| var extent = direction.sign; ~lastWasX.if({ ~res[~res.size-1] = ~res.last + extent; },{ //\newX.postln; ~res = ~res.add(~res[~res.size-2] + extent); ~lastWasX = true; }); {w.refresh}.defer }; ~extentY = {|direction = 1| var extent = direction.sign; ~lastWasX.if({ ~res = ~res.add(~res[~res.size-2] + extent); ~lastWasX = false; },{ ~res[~res.size-1] = ~res.last + extent; }); {w.refresh}.defer } ~res = 50!4; ~lastWasX = false; w.refresh ~extentX.value(-1); ~res.postln ~extentX.value(1); ~res.postln ~extentY.value(-1); ~res.postln ~extentY.value(1); ~res.postln  ///////////// Griffin Powermate ///////////////// /* set your Powermate to spit out left -> Ctrl-1 right -> Ctrl-2 down-Left -> Ctrl-3 down-Right -> Ctrl-3 short-Down -> Ctrl-4 */ w.view.keyDownAction_{|view, key, mod| (mod == 262401).if{ (key == $1).if{~extentX.value( 1)}; (key == $2).if{~extentX.value(-1)}; (key == $3).if{~extentY.value( 1)}; (key == $4).if{~extentY.value(-1)}; (key == $5).if{~res = 0!4; ~lastWasX = false; {w.refresh}.defer}; } } ///////////// MIDI ///////////////// /* MIDIIn.disconnect */ // set values to nrpn Channels 0 and 1 MIDIIn.connect; // init for one port midi interface MIDIIn.control = { arg src, chan, num, val; (chan == 0).if{ (num == 96).if{~extentX.value(1)}; (num == 97).if{~extentX.value(-1)}; (num == 65).if{~res = 400!4; ~lastWasX = false; {w.refresh}.defer}; //num.postln; }; (chan == 1).if{ (num == 96).if{~extentY.value(-1)}; (num == 97).if{~extentY.value(1)}; }; }; MIDIIn.disconnect;