Skip to content

Instantly share code, notes, and snippets.

@caseyanderson
Last active January 21, 2019 00:53
Show Gist options
  • Save caseyanderson/0c40144646815ad8ec2b06dfb825f856 to your computer and use it in GitHub Desktop.
Save caseyanderson/0c40144646815ad8ec2b06dfb825f856 to your computer and use it in GitHub Desktop.
/*
midi controls gui
written for midifighter twister
HT Scott Cazan for line 55
*/
s.boot;
MIDIIn.connectAll;
(
// make environment
a = currentEnvironment;
// list of sources
~sources = Array.with('this', 'is', 'a', 'test');
// make the control busses for each sources
for( 0, (~sources.size - 1), { |i |
a[((~sources[i])++"BusVol").asSymbol] = Bus.control(s, 1).set(0.0);
});
~window = Window.new("mixer", Rect(0, 0, 465, 335));
~window.background = Color.gray(0.15);
// how do i compute these coordinates per x num sources?
~col = [10, 120, 230, 340 ];
~row1 = [ 10, 10, 10, 10, 10 ];
~row2 = [60, 60, 60, 60 ];
~row3 = [120, 120, 120, 120];
// setup gui (label, number box (exact val), knob (approx val)) per source
for(0, ~sources.size - 1, { | i |
// label
a[("k"++i++"Label").asSymbol] = StaticText(~window, Rect( ~col[i], ~row1[i], 100, 50));
a[("k"++i++"Label").asSymbol].align = \center;
a[("k"++i++"Label").asSymbol].background = Color.gray(0.15);
a[("k"++i++"Label").asSymbol].stringColor = Color.white;
a[("k"++i++"Label").asSymbol].string = ~sources[i].asString;
// display val in NumberBox
a[("k"++i++"Val").asSymbol] = NumberBox(~window, Rect(~col[i], ~row2[i], 100, 50));
a[("k"++i++"Val").asSymbol].align = \center;
a[("k"++i++"Val").asSymbol].background = Color.white;
// make the knob, connect to NumberBox
a[("k"++i).asSymbol] = Knob.new(~window, Rect(~col[i], ~row3[i], 100, 100));
a[("k"++i).asSymbol].background_(Color.black);
a[("k"++i).asSymbol].action_{ |knob|
a[((~sources[i])++"BusVol").asSymbol].set(knob.value); // gui updates bus
a[("k"++i++"Val").asSymbol].value_(knob.value); // gui updates numberbox
};
});
~window.front;
)
(
// connect midi controller to gui per each source
for(0, ~sources.size - 1, { | i |
MIDIFunc.cc({arg ...msg;
var val = msg[0].linlin(0, 127, 0.0, 1.0);
{ a[("k"++i).asSymbol].valueAction_(val) }.defer;
}, i);
});
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment