-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMandelGUI.sc
148 lines (107 loc) · 2.73 KB
/
MandelGUI.sc
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
MandelGUI
(c) 2010 by Patrick Borgeat <[email protected]>
http://www.cappel-nord.de
Part of BenoitLib
http://github.com/cappelnord/BenoitLib
http://www.the-mandelbrots.de
*/
MandelGUI
{
var <window, bpmText, mesText, beatText, timerText, beatArr, clock, hub;
var sj;
var stillOpen = true;
classvar <>defaultPos;
*new {|hub, pos|
^super.new.init(hub ,pos);
}
init {|a_hub, pos|
hub = a_hub;
clock = hub.clock;
// well, 400@400 is quite random :-)
pos = pos ? defaultPos ? (400@400);
window = Window.new("MandelGUI", Rect(pos.x,pos.y,288,65), false);
window.addFlowLayout(10@10,5@5);
timerText = StaticText(window, 100@20);
mesText = StaticText(window, 45@20);
beatText = StaticText(window, 45@20);
CompositeView.new(window,Point(10,20)); // silly spacing
Button(window,45@20)
.states_([["Chat", Color.black, Color.clear]])
.action_({hub.chatWindow;});
window.view.decorator.nextLine;
bpmText = StaticText(window, 50@20);
StaticText(window,45@20).string_("BPM");
beatArr = nil.dup(4);
4.do {|i|
beatArr[i] = StaticText(window,20@20);
};
CompositeView.new(window,Point(10,20)); // silly spacing
Button(window,45@20)
.states_([["Shout", Color.black, Color.clear]])
.action_({hub.shoutWindow;});
this.prClearBeats;
sj = SkipJack({
var tempo = hub.externalTempo;
var color = Color.black;
var minutes, seconds;
MandelHub.debug.if {
tempo = hub.tempo;
};
(hub.tempo > hub.externalTempo).if {
color = Color(0,0.4,0);
};
(hub.tempo < hub.externalTempo).if {
color = Color(0.4,0,0);
};
bpmText.stringColor_(color);
bpmText.string_((tempo * 60).asString[0..5]);
minutes = (hub.timer.elapsedTime / 60).floor.asInteger.asString.padLeft(2, "0");
seconds = (hub.timer.elapsedTime % 60).floor.asInteger.asString.padLeft(2, "0");
timerText.string_(minutes ++ ":" ++ seconds);
beatText.string_((clock.beats % 4 + 1).asString[0..4]);
},0.1);
window.onClose_({this.prPrepClose;});
window.front;
this.prAddCmdPeriod ;
this.prSchedNextBeat;
}
close {
this.prPrepClose;
window.close;
}
prPrepClose {
sj.stop;
stillOpen = false;
}
prClearBeats {
stillOpen.if {
beatArr.do {|item|
item.background = Color.grey;
};
};
}
prSchedNextBeat {
var nextBeat = clock.beats.ceil;
var color = Color.green;
((nextBeat % 4) == 0).if {color = Color.red;};
clock.schedAbs(nextBeat, {
stillOpen.if {
{
this.prClearBeats;
beatArr[nextBeat%4].background = color;
mesText.string_((clock.beats / 4).floor.asInteger);
this.prSchedNextBeat;
}.defer;
};
});
}
prAddCmdPeriod {
stillOpen.if {
CmdPeriod.doOnce({
this.prAddCmdPeriod;
this.prSchedNextBeat;
});
};
}
}