-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMozart_Ballot_GUI.scd
105 lines (86 loc) · 2.88 KB
/
Mozart_Ballot_GUI.scd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
// ************************************
// "Ballot" GUI for voting
// Mozart Dice Game
// SCLOrk, Spring 2016
// ************************************
var win, buttonArray, superDelegates, supDel = 0, referendumText, referendumYes, referendumNo;
Window.closeAll;
win = Window.new("Ballot", Rect(left: 450, top: 160, width: 250, height: 390)).front;
win.alwaysOnTop = true;
win.background = Color.new255(102, 102, 102, 255);
// Change the gaps and margins to see how they work
win.view.decorator = FlowLayout(win.view.bounds, margin: 10@10, gap: 10@10 );
buttonArray = Array.fill(12, {Button(win.view, 50@50)});
buttonArray.do({arg item, count;
item.states = [[ count + 1, Color.black, Color.rand ]]});
buttonArray.do({arg item, count;
item.action = {arg bt;
var myVote = count + 1;
("I vote for " ++ (myVote)).postln;
case
{ supDel == 0 } { ~sendVote.value(myVote) }
{ supDel == 1 } { { ~sendVote.value(myVote) }.dup(10) }
{ supDel == 2 } { ~sendVote.value(myVote) }; // ran out of superdelegates
}});
// SuperDelegates
superDelegates = Button.new(win.view, 230@50);
superDelegates.states = [[ "SUPERDELEGATE MODE", Color.black, Color.yellow ]];
superDelegates.action = {arg bt;
"printme".postln;
if(supDel==0,
{
var blink, implode;
~destination.sendMsg("/superD", 1); // flashing sign on conductor screen
supDel = 1;
blink = {
{
{ superDelegates.states = [[ "SUPERDELEGATE MODE ON", Color.white, Color.red ]] }.defer;
0.1.wait;
{ superDelegates.states = [[ "CHEATER!", Color.black, Color.yellow ]] }.defer;
0.1.wait;
}.loop;
}.fork;
implode = {
10.wait;
"BOOOOOOOM".postln;
blink.stop;
supDel = 2; // back to normal 1:1 vote, 'de-activate' button
~destination.sendMsg("/superD", 0);
{
superDelegates.states = [
[ "you ran out of superdelegates", Color.black, Color.white ],
[ "forget it", Color.black, Color.white ],
[ "already told you", Color.black, Color.white ],
[ "no more cheating", Color.black, Color.white ],
];
}.defer;
}.fork;
},
{
"you ran out of superdelegates".postln;
}
);
};
~referendumView = HLayoutView.new(win, 230@50);
~referendumView.visible = false; // start invisible
~referendumText = StaticText.new(~referendumView, 110@50);
~referendumText.string = "Anarchy?";
~referendumText.stringColor = Color.white;
~referendumText.align = \center;
// Referendum
referendumNo = Button.new(~referendumView, 60@50);
referendumNo.states = [[ "NO", Color.black, Color.red ]];
referendumYes = Button.new(~referendumView, 60@50);
referendumYes.states = [[ "YES", Color.black, Color.green ]];
referendumNo.action = { ~sendReferendumVote.value(0) };
referendumYes.action = { ~sendReferendumVote.value(1) };
win.onClose = {
Window.closeAll;
"Done!".postln;
TempoClock.clear;
s.freeAll;
p.stop; q.stop; t.clear;
};
CmdPeriod.doOnce({Window.closeAll});
"Mozart Ballot".postln;
"".postln;