You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
3.0 KiB
Plaintext

(
// VISUALS
// Init vars and window
var projectionWin, arduino_port, osc_func, brightness = {0} ! 27, refresh_func;
projectionWin = Window.new("Remembering Clive Wearing", Rect(500, 500, 750, 500)).front;
projectionWin.background = Color.black;
// Keybinds (these can be change if conflicting with system keybinds)
projectionWin.view.keyDownAction = { |doc, char, mod, unicode, keycode, key|
case
// <ctrl + f> = enter full screen
{mod == 262144 && key == 70} {projectionWin.fullScreen}
// <esc> = exit full screen
{mod == 0 && key == 16777216} {projectionWin.endFullScreen}
// <ctrl + r> = run synth
{mod == 262144 && key == 82} {refresh_func.fork(AppClock); ~flicker.run}
// <ctrl + p> = pause synth
{mod == 262144 && key == 80} {~flicker.run(false)}
// <ctrl + s> = start / fade in
{mod == 262144 && key == 83} {~fadeInTrigBus.set(1)}
// <ctrl + e> = end / fade out
{mod == 262144 && key == 69} {~fadeOutTrigBus.set(1)}
// <ctrl + t> = trigger wake
{mod == 262144 && key == 84} {~wakeTrigBus.set(1)}
};
// Connect arduino; edit first arg / port to match index or name of port: SerialPort.listDevices
if(~arduino == 1, { arduino_port = SerialPort("/dev/ttyACM0", 115200);
r= Routine({
var byte, str, res;
99999.do{|i|
byte = arduino_port.read;
if(byte==13, {
(str).postln;
str = "";
},
{
str= str++byte.asAscii;
});
};
}).play;
}, {});
// Get control signals from SynthDef
osc_func = OSCFunc.new({arg msg, time; brightness[msg[2]] = msg[3]; },'/tr', s.addr);
// Draw the window
projectionWin.drawFunc = {
var projectionRect = projectionWin.view.bounds;
{|i| var outerLen, vPad, outerSquare;
outerLen = projectionRect.width / 2;
vPad = projectionRect.height - outerLen;
outerSquare = projectionRect.insetBy(outerLen * i, vPad / 2).resizeTo(outerLen, outerLen);
outerSquare = outerSquare.insetBy(outerLen * 0.05,
outerLen * 0.05).resizeTo(outerLen * 0.9, outerLen * 0.9);
{|j| var innerLen, innerSquare;
innerLen = outerSquare.width / 3;
innerSquare = outerSquare.insetBy(innerLen * (j % 3),
innerLen * (j / 3).trunc).resizeTo(innerLen, innerLen);
Pen.addOval(innerSquare);
Pen.fillRadialGradient(innerSquare.center, innerSquare.center,
(innerSquare.width / 16), (innerSquare.width / 2),
Color.black.blend(Color.new255(255, 214, 170, 255), pow(brightness[(i * 9) + j], 0.5)),
Color.black);
} ! 9 } ! 2
};
projectionWin.refresh;
// Refresh function
refresh_func = { while { true } {
// updateProjection
projectionWin.refresh;
if(~arduino == 1, {
// set min and max Brightness between 0 and 1 depending on wattage of light
// it is best to keep the min slightly higher than 0 to keep the light from turning completely off
{|i| var minBrightness = 0.15, maxBrightness = 0.85;
arduino_port.put(i);
arduino_port.put(253);
//if(brightness[0] < 0
arduino_port.put(((((brightness[i] * (maxBrightness - minBrightness)) + minBrightness) - 1).abs * 256).asInteger);
arduino_port.put(254);
//arduino_port.put(254);
} ! 18 }, {});
// delay
30.reciprocal.wait; } };
)
//Char.space.asInt