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.

152 lines
6.3 KiB
Plaintext

(
//~~FUNCTION THAT GENERATES THE GUI
~generateGUI = {
var win, clockStringFunc, metronomeStringFunc, metronomeColorFunc, masterView, faderView, tabs;
var tabButtonReset, transportButton, mixerButton, startPos = 0;
var partAbbr = ["guitar", "accompHigh", "accomLow", "interlude"];
var trackNames = ["guitar", "high", "low", "interlude"];
var partVols, partMutes, partPans;
var masterMute, masterVol;
partVols = [1, 1, 1, 1];
partMutes = [1, 1, 1, 1];
partPans = [0, 0, 0, 0];
masterMute = 1;
masterVol = 1;
clockStringFunc = {
arg div;
var min, sec;
sec = (div / 5).trunc;
min = (sec / 60).asInteger.asString;
if(min.size == 1, {min = "0" ++ min}, {});
sec = (sec % 60).asInteger.asString;
if(sec.size == 1, {sec = "0" ++ sec}, {});
min ++ ":" ++ sec
};
// [-30, -105, -104].asAscii and [-30, -105, -113].asAscii are unicode inverse bullet and normal bullet, respectively
metronomeStringFunc = { arg div; case {div % 20 < 2}
{[-30, -105, -104].asAscii} {div % 4 < 2} {[-30, -105, -113].asAscii} {true} {" "} };
metronomeColorFunc = { arg div; case {div % 20 < 2} {Color.red} {div % 4 < 2} {Color.blue} {true} {Color.black} };
~appStatusFunc = Task({
loop {
{~appStatus.string = ~appStatusString ++ "*"}.defer;
0.5.wait; {~appStatus.string = ~appStatusString ++ "* *"}.defer;
0.5.wait; {~appStatus.string = ~appStatusString ++ "* * *"}.defer;
0.5.wait; {~appStatus.string = ~appStatusString ++ "* * * *"}.defer;
0.5.wait; {~appStatus.string = ~appStatusString ++ "* * * * *"}.defer;
0.5.wait;
}
});
win = Window("Counterfeiting in Colonial Connecticut", Rect(500, 500, 1100, 500), false).front;
masterView = {
var view, masterIndicators, master, generator, transport, ranSeed, startPosText, pauseButton, clock, metronome;
OSCFunc({ arg msg, time; {
clock.string = clockStringFunc.value(msg[3]);
metronome.stringColor = metronomeColorFunc.value(msg[3]);
metronome.string = metronomeStringFunc.value(msg[3])}.defer;
},'/tr', s.addr);
view = View(win);
generator = HLayout(
Button(view).states_([["generate"]]).action_({
~appStatusString = "generating data";
~appStatusFunc.start;
~generateData.value(seed: ranSeed.string.asInteger);
}),
ranSeed = TextField(view).string_("20170121"),
Button(view).states_([["reset seed"]]).action_({ ranSeed.string = "20170121"}),
Button(view).states_([["random seed"]]).action_({ ranSeed.string = 50000000.rand.asString}),
[~appStatus = StaticText(view).string_("status: ready"), stretch: 1],
nil);
transport = HLayout(
Button(view).states_([["play", Color.black], ["stop", Color.black, Color.grey]]).action_(
/*
{| pState |
pauseButton.value = 0;
if(pState.value == 0, {~play.set(\playRate, 0, \startTrig, 0);
clock.string = clockStringFunc.value((startPos * ~totalDur * 5).asInteger)},
{~play.set(\startPos, startPos, \playRate, 1, \startTrig, 1)})}
*/
{| pState |
pauseButton.value = 0;
if(pState.value == 0, {~patterns[0].stop;
clock.string = clockStringFunc.value((startPos * ~totalDur * 5).asInteger)},
{~patterns[0].play})}
),
pauseButton = Button(view).states_([["pause", Color.black], ["pause", Color.black, Color.grey]]).action_(
{| pState |
if(pState.value == 1, {~play.set(\playRate, 0)},{~play.set(\playRate, 1)})}),
StaticText(view).string_("start time"),
[Slider(view, Rect(0, 0, 30, 5)).action_(
{|pos|
var min, sec;
startPosText.string = clockStringFunc.value((pos.value * ~totalDur * 5).asInteger);
startPos = pos.value;
}), stretch: 1],
startPosText = StaticText(win).string_("00:00").font_(Font("Monaco", 15)),
nil);
view.layout_(HLayout(
[VLayout(generator, nil,
HLayout(clock = StaticText(win).string_("00:00").font_(Font("Monaco", 200)),
StaticText(win).string_("|").font_(Font("Monaco", 200)),
metronome = StaticText(win).string_([-30, -105, -104].asAscii).font_(Font("Monaco", 300)).stringColor_(Color.red)),
nil, transport
), alignment: \top])) };
faderView = {
var view, masterIndicators, trackIndicators, master, tracks;
view = View(win);
masterIndicators = {LevelIndicator()} ! 2;
trackIndicators = {LevelIndicator()} ! 4;
OSCFunc.new({arg msg; {
{|i| masterIndicators[i].value = msg[3 + i].ampdb.linlin(-40, 0, 0, 1)} ! 2}.defer},
'/masterLevels', s.addr);
OSCFunc.new({arg msg; {
{|i| trackIndicators[i].value = msg[3 + i].ampdb.linlin(-40, 0, 0, 1)} ! 4}.defer},
'/trackLevels', s.addr);
master = HLayout(
VLayout(
[HLayout(
Slider(view).value_(0.8).action_(
{|v| masterVol = v.value * 1.25; ~play.set(\masterVol, masterVol)}),
masterIndicators[0],
masterIndicators[1]), stretch: 2],
Button(view).states_([["mute", Color.black], ["mute", Color.black, Color.grey]]).action_(
{|v| masterMute = (1 - v.value).abs; ~play.set(\masterMute, masterMute)}),
StaticText(view).string_(" master ").align_(\center)
//StaticText(view).string_("("++groupNames[group]++")").align_(\center)
),
nil);
tracks = { |part|
HLayout(
VLayout(
HLayout(
Slider(view).value_(0.8).action_(
{|v| partVols[part] = v.value * 1.25; ~play.set(partAbbr[part] ++ "Vol", partVols[part])}),
trackIndicators[part]),
Button(view).states_([["mute", Color.black], ["mute", Color.black, Color.grey]]).action_(
{|v| partMutes[part] = (1 - v.value).abs; ~play.set(partAbbr[part] ++ "Mute", partMutes[part])}),
StaticText(view).string_("pan").align_(\center),
Knob(view).value_(0.5).action_(
{|v| partPans[part] = v.value * 2 - 1; ~play.set(partAbbr[part] ++ "Pan", partPans[part])}),
StaticText(view).string_(trackNames[part]).align_(\center)
),
nil)
} ! 4;
view.layout_(HLayout(master, nil, *tracks))};
tabButtonReset = {transportButton.value = 1; mixerButton.value = 1; };
win.layout = VLayout(
HLayout(
transportButton = Button().states_([["transport", Color.white, Color.grey], ["transport", Color.black]]).action_(
{tabButtonReset.value; transportButton.value = 0; tabs.index = 0 }).value_(0),
mixerButton = Button().states_([["mixer", Color.white, Color.grey], ["mixer", Color.black]]).action_(
{tabButtonReset.value; mixerButton.value = 0; tabs.index = 1 }).value_(1)),
tabs = StackLayout(masterView.value, faderView.value));
};
)