Created
March 15, 2020 17:05
-
-
Save madskjeldgaard/80717d2d1a41289d5c0363a990d2c1c0 to your computer and use it in GitHub Desktop.
Code for the Quarantine livestream #2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Code from the Quarantine Livestream #2 | |
A small gui program controlling a pattern | |
*/ | |
( | |
var numSliders = 4; | |
var numButtons = 2; | |
var sliders, buttons, sliderLayout, buttonLayout, layout; | |
w = Window.new; | |
sliders = numSliders.collect{ | |
Slider.new | |
.background_(Color.rand(0.25,0.9)) | |
}; | |
buttons = numButtons.collect{ | |
Button.new | |
}; | |
// This is where the magic happens: VLayout, HLayout | |
sliderLayout = HLayout.new(*sliders); | |
buttonLayout = VLayout.new(*buttons); | |
// Final layout | |
layout = VLayout(buttonLayout, sliderLayout); | |
// Start button | |
buttons[0] | |
.states_( | |
[["Start", Color.black, Color.rand]] | |
) | |
.action_({|obj| | |
Pdef(\quarantine).play | |
} | |
); | |
// Stop button | |
buttons[1] | |
.states_( | |
[["Stop", Color.black, Color.rand]] | |
).action_({|obj| | |
Pdef(\quarantine).stop | |
} | |
); | |
// Slider actions | |
// Slider 1: Change duration | |
sliders[0] | |
.action_({|obj| | |
var val = obj.value; | |
// Scale the duration MAKE SURE IT IS NOT ZERO!! | |
val = val.linlin(0.0,1.0,0.05,1.0); | |
Pdefn(\qdur, val) | |
}); | |
// Slider 2: Change scale degree | |
sliders[1] | |
.action_({|obj| | |
var val = obj.value; | |
val = val.linlin(0.0,1.0,0.0,7.0); | |
Pdefn(\qdeg, Pwhite(0, val)) | |
}); | |
// Slider 3: Change octave | |
sliders[2] | |
.action_({|obj| | |
var val = obj.value; | |
val = val.linlin(0.0,1.0,2,7); | |
Pdefn(\qoct, val) | |
}); | |
// Slider 4: Change amplitude | |
sliders[3] | |
.action_({|obj| | |
var val = obj.value; | |
val = val.linlin(0.0,1.0,0.0,0.75); | |
Pdefn(\qamp, val) | |
}); | |
w.layout = layout; | |
w.front; | |
Pdef(\quarantine, | |
Pbind( | |
\dur, Pdefn(\qdur, 0.25), | |
\scale, Scale.minor, | |
\degree, Pdefn(\qdeg, 0), | |
\octave, Pdefn(\qoct, 5), | |
\amp, Pdefn(\qamp, 0.5), | |
) | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment