-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgui.pde
More file actions
359 lines (272 loc) · 10.4 KB
/
Copy pathgui.pde
File metadata and controls
359 lines (272 loc) · 10.4 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
/* =========================================================
* ==== WARNING ===
* =========================================================
* The code in this tab has been generated from the GUI form
* designer and care should be taken when editing this file.
* Only add/edit code inside the event handlers i.e. only
* use lines between the matching comment tags. e.g.
void myBtnEvents(GButton button) { //_CODE_:button1:12356:
// It is safe to enter your event code here
} //_CODE_:button1:12356:
* Do not rename this tab!
*/
//Global Settings
int xInitialValueButtons = 100;
int yInitialValueButtons = 640;
String[] timeSignatureNames = {"4/4", "3/4", "2/4", "6/8"};
public void createGUI() {
G4P.messagesEnabled(false);
G4P.setGlobalColorScheme(GCScheme.BLUE_SCHEME);
G4P.setMouseOverEnabled(false);
// BPM Slider
BPM = new GCustomSlider(this, xInitialValueButtons, yInitialValueButtons, 120, 40, "grey_blue");
BPM.setLimits(120, 20, 240);
BPM.setNumberFormat(G4P.INTEGER, 0);
BPM.setOpaque(false);
BPM.addEventHandler(this, "BPMSlider");
// Undo
UndoButton = new GButton(this, xInitialValueButtons+154, yInitialValueButtons+5, 70, 30);
UndoButton.setText("Undo");
UndoButton.addEventHandler(this, "UndoClicked");
// Redo
RedoButton = new GButton(this, xInitialValueButtons+234, yInitialValueButtons+5, 70, 30);
RedoButton.setText("Redo");
RedoButton.addEventHandler(this, "RedoClicked");
// Note durations
NoteKey = new GDropList(this, xInitialValueButtons+324, yInitialValueButtons+5, 100, 80, 3, 10);
NoteKey.setItems(loadStrings("noteDurations.txt"), 2);
NoteKey.addEventHandler(this, "dropList1_click1");
// Play
PlayButton = new GButton(this, xInitialValueButtons+444, yInitialValueButtons+5, 100, 30);
PlayButton.setText("Play/Pause");
PlayButton.addEventHandler(this, "PlayClicked");
// Reset
button1 = new GButton(this, xInitialValueButtons+564, yInitialValueButtons+5, 80, 30);
button1.setText("Reset");
button1.setLocalColorScheme(GCScheme.RED_SCHEME);
button1.addEventHandler(this, "button1_click1");
// Save
button2 = new GButton(this, xInitialValueButtons+654, yInitialValueButtons+5, 80, 30);
button2.setText("Save");
button2.setLocalColorScheme(GCScheme.GOLD_SCHEME);
button2.addEventHandler(this, "button2_click1");
// Instruments
InstrumentKey = new GDropList(this, xInitialValueButtons+754, yInitialValueButtons+5, 120, 80, 3, 10);
InstrumentKey.setItems(instrumentNames, 0);
InstrumentKey.addEventHandler(this, "InstrumentChanged");
// =========================
// VOLUME SLIDER
// =========================
VolumeSlider = new GCustomSlider(this, xInitialValueButtons, yInitialValueButtons+45, 140, 40, "grey_blue");
VolumeSlider.setLimits(80, 0, 100);
VolumeSlider.setNumberFormat(G4P.INTEGER, 0);
VolumeSlider.setOpaque(false);
VolumeSlider.addEventHandler(this, "VolumeChanged");
// Track controls
PrevTrackButton = new GButton(this, xInitialValueButtons+160, yInitialValueButtons+50, 80, 30);
PrevTrackButton.setText("< Track");
PrevTrackButton.addEventHandler(this, "PrevTrackClicked");
NextTrackButton = new GButton(this, xInitialValueButtons+250, yInitialValueButtons+50, 80, 30);
NextTrackButton.setText("Track >");
NextTrackButton.addEventHandler(this, "NextTrackClicked");
AddTrackButton = new GButton(this, xInitialValueButtons+340, yInitialValueButtons+50, 90, 30);
AddTrackButton.setText("Add Track");
AddTrackButton.addEventHandler(this, "AddTrackClicked");
DeleteTrackButton = new GButton(this, xInitialValueButtons+440, yInitialValueButtons+50, 95, 30);
DeleteTrackButton.setText("Del Track");
DeleteTrackButton.setLocalColorScheme(GCScheme.RED_SCHEME);
DeleteTrackButton.addEventHandler(this, "DeleteTrackClicked");
AddMeasureButton = new GButton(this, xInitialValueButtons+545, yInitialValueButtons+50, 110, 30);
AddMeasureButton.setText("Add Measure");
AddMeasureButton.addEventHandler(this, "AddMeasureClicked");
DeleteMeasureButton = new GButton(this, xInitialValueButtons+665, yInitialValueButtons+50, 110, 30);
DeleteMeasureButton.setText("Del Measure");
DeleteMeasureButton.setLocalColorScheme(GCScheme.RED_SCHEME);
DeleteMeasureButton.addEventHandler(this, "DeleteMeasureClicked");
VisualizeButton = new GButton(this, xInitialValueButtons+544, yInitialValueButtons-45, 95, 30);
VisualizeButton.setText("Visualize");
VisualizeButton.addEventHandler(this, "VisualizeClicked");
KeySignatureButton = new GDropList(this, xInitialValueButtons+754, yInitialValueButtons-45, 120, 80, 3, 10);
KeySignatureButton.setItems(loadStrings("keySignatures.txt"), 0);
KeySignatureButton.addEventHandler(this, "UpdateKeySig");
TimeSignatureButton = new GDropList(this, xInitialValueButtons+654, yInitialValueButtons-45, 80, 80, 3, 10);
TimeSignatureButton.setItems(timeSignatureNames, 0);
TimeSignatureButton.addEventHandler(this, "UpdateTimeSig");
// =========================
// SAVE POPUP CONTROLS
// =========================
SaveNameBox = new GTextField(this, 350, 300, 300, 40);
SaveNameBox.setPromptText("Project Name");
SaveNameBox.setVisible(false);
SaveCheckbox = new GCheckbox(this, 350, 360, 280, 30);
SaveCheckbox.setText("");
SaveCheckbox.setVisible(false);
ConfirmSaveButton = new GButton(this, 420, 420, 150, 40);
ConfirmSaveButton.setText("Save Project");
ConfirmSaveButton.setVisible(false);
ConfirmSaveButton.addEventHandler(this, "ConfirmSaveClicked");
CloseSaveButton = new GButton(this, 675, 235, 35, 30);
CloseSaveButton.setText("X");
CloseSaveButton.setLocalColorScheme(GCScheme.RED_SCHEME);
CloseSaveButton.setVisible(false);
CloseSaveButton.addEventHandler(this, "CloseSaveClicked");
updateGUIVisibility();
}
/* ================= EVENT HANDLERS ================= */
public void BPMSlider(GCustomSlider source, GEvent event) {
int newTempo = int(source.getValueF());
if (currentScreen == composePage && userPiece != null) {
userPiece.tempo = newTempo;
}else if (demoEqualizer.piece != null) {
demoEqualizer.piece.tempo = newTempo;
}
}
public void VolumeChanged(GCustomSlider source, GEvent event) {
masterVolume = source.getValueF() / 100.0;
applyMasterVolumeToUserPiece();
}
public void InstrumentChanged(GDropList source, GEvent event) {
if (syncingInstrumentDropdown){
return;
}
int selected = source.getSelectedIndex();
if (selected >= 0 && selected < instrumentNames.length){
editManager.setActiveTrackInstrument(instrumentNames[selected]);
}
}
public void PrevTrackClicked(GButton source, GEvent event) {
editManager.changeTrack(-1);
}
public void NextTrackClicked(GButton source, GEvent event) {
editManager.changeTrack(1);
}
public void AddTrackClicked(GButton source, GEvent event) {
editManager.addTrackToPiece(createInstrumentByName(selectedInstrumentName()));
applyMasterVolumeToUserPiece();
}
public void DeleteTrackClicked(GButton source, GEvent event) {
editManager.deleteActiveTrack();
}
public void AddMeasureClicked(GButton source, GEvent event) {
editManager.addMeasureToPiece();
}
public void DeleteMeasureClicked(GButton source, GEvent event) {
editManager.deleteLastMeasure();
}
public void VisualizeClicked(GButton source, GEvent event) {
startUserPieceVisual();
}
public void UndoClicked(GButton source, GEvent event) {
undoAction();
editManager.setStatus("Undo");
}
public void RedoClicked(GButton source, GEvent event) {
redoAction();
editManager.setStatus("Redo");
}
public void dropList1_click1(GDropList source, GEvent event) {
int selected = source.getSelectedIndex();
float[] durations = {4.0, 2.0, 1.0, 0.5, 0.25};
if (selected >= 0 && selected < durations.length){
editManager.changeSelectedDuration(durations[selected]);
}
}
public void UpdateKeySig(GDropList source, GEvent event){
int selected = source.getSelectedIndex();
if (selected < 0){
return;
}
boolean sharp = selected <= 7;
int accidentalCount = selected;
if (!sharp){
accidentalCount = selected - 7;
}
KeySignature keySig = new KeySignature(sharp, accidentalCount);
editManager.updateKeySig(keySig);
}
public void UpdateTimeSig(GDropList source, GEvent event){
int selected = source.getSelectedIndex();
if (selected < 0){
return;
}
TimeSignature timeSig = new TimeSignature(4, 4);
if (selected == 1){
timeSig = new TimeSignature(3, 4);
}else if (selected == 2){
timeSig = new TimeSignature(2, 4);
}else if (selected == 3){
timeSig = new TimeSignature(6, 8);
}
editManager.updateTimeSig(timeSig);
}
public void PlayClicked(GButton source, GEvent event) {
MusicalPiece piece = demoEqualizer.piece;
if (currentScreen == composePage){
piece = userPiece;
}
if (piece == null) return;
if (piece.playing) {
piece.stopPlayback();
source.setText("Play");
} else {
piece.startPlayback();
source.setText("Pause");
}
}
public void button1_click1(GButton source, GEvent event) {
makeBlankUserPiece("My Piece");
source.setText("Reset");
PlayButton.setText("Play/Pause");
}
public void button2_click1(GButton source, GEvent event) {
showSavePopup = true;
updateGUIVisibility();
}
public void ConfirmSaveClicked(GButton source, GEvent event) {
String projectName = SaveNameBox.getText().trim();
if (projectName.equals("")) {
println("Please enter a project name.");
return;
}
if (!SaveCheckbox.isSelected()) {
println("Please confirm save.");
return;
}
saveCurrentProject(projectName);
editManager.setStatus("Saved " + projectName);
showSavePopup = false;
SaveNameBox.setText("");
SaveCheckbox.setSelected(false);
updateGUIVisibility();
}
public void CloseSaveClicked(GButton source, GEvent event) {
showSavePopup = false;
SaveNameBox.setText("");
SaveCheckbox.setSelected(false);
updateGUIVisibility();
}
/* ================= VARIABLES ================= */
GCustomSlider BPM;
GCustomSlider VolumeSlider;
GButton UndoButton;
GButton RedoButton;
GDropList NoteKey;
GDropList InstrumentKey;
GDropList KeySignatureButton;
GDropList TimeSignatureButton;
GLabel Notes;
GButton PlayButton;
GLabel label1;
GButton button1;
GButton button2;
GButton PrevTrackButton;
GButton NextTrackButton;
GButton AddTrackButton;
GButton DeleteTrackButton;
GButton AddMeasureButton;
GButton DeleteMeasureButton;
GButton VisualizeButton;
GTextField SaveNameBox;
GCheckbox SaveCheckbox;
GButton ConfirmSaveButton;
GButton CloseSaveButton;