forked from atsushieno/ADLplug-AE
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadlplug-ae.patch
More file actions
504 lines (468 loc) · 21.4 KB
/
adlplug-ae.patch
File metadata and controls
504 lines (468 loc) · 21.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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
diff --git a/sources/opl3/ui/main_component.cc b/sources/opl3/ui/main_component.cc
index a009e6b..c0e590b 100644
--- a/sources/opl3/ui/main_component.cc
+++ b/sources/opl3/ui/main_component.cc
@@ -1213,13 +1213,14 @@ void Main_Component::buttonClicked (Button* buttonThatWasClicked)
else if (buttonThatWasClicked == btn_emulator.get())
{
//[UserButtonCode_btn_emulator] -- add your button handler code here..
- int selection = select_emulator_by_menu();
+ select_emulator_by_menu([&](int selection){
if (selection != 0 && (unsigned)(selection - 1) != chip_settings_.emulator) {
AudioParameterChoice &p = *pb.p_emulator;
p.beginChangeGesture();
p = selection - 1;
p.endChangeGesture();
}
+ });
//[/UserButtonCode_btn_emulator]
}
else if (buttonThatWasClicked == btn_deep_tremolo.get())
diff --git a/sources/opn2/ui/main_component.cc b/sources/opn2/ui/main_component.cc
index 7105b40..691dfba 100644
--- a/sources/opn2/ui/main_component.cc
+++ b/sources/opn2/ui/main_component.cc
@@ -1041,13 +1041,14 @@ void Main_Component::buttonClicked (Button* buttonThatWasClicked)
else if (buttonThatWasClicked == btn_emulator.get())
{
//[UserButtonCode_btn_emulator] -- add your button handler code here..
- int selection = select_emulator_by_menu();
+ select_emulator_by_menu([&](int selection) {
if (selection != 0 && (unsigned)(selection - 1) != chip_settings_.emulator) {
AudioParameterChoice &p = *pb.p_emulator;
p.beginChangeGesture();
p = selection - 1;
p.endChangeGesture();
}
+ });
//[/UserButtonCode_btn_emulator]
}
else if (buttonThatWasClicked == btn_algo_help.get())
diff --git a/sources/plugin_version.h b/sources/plugin_version.h
index ad7b9a3..5b7636e 100644
--- a/sources/plugin_version.h
+++ b/sources/plugin_version.h
@@ -4,7 +4,7 @@
// http://www.boost.org/LICENSE_1_0.txt)
#pragma once
-#include "AppConfig.h"
+//#include "AppConfig.h"
#define ADLplug_Version JucePlugin_VersionString
#define ADLplug_VersionFinal 1
diff --git a/sources/ui/components/midi_keyboard_ex.cc b/sources/ui/components/midi_keyboard_ex.cc
index d5914b1..67e8e89 100644
--- a/sources/ui/components/midi_keyboard_ex.cc
+++ b/sources/ui/components/midi_keyboard_ex.cc
@@ -5,11 +5,6 @@
#include "midi_keyboard_ex.h"
-// XXX(jpc) a hack so we don't need to link the whole `juce_audio_utils`
-namespace ex {
-#include <juce_audio_utils/gui/juce_MidiKeyboardComponent.cpp>
-}
-
Midi_Keyboard_Ex::Midi_Keyboard_Ex(MidiKeyboardState &state, Orientation orientation)
: MidiKeyboardComponent(state, orientation),
designated_note_color_((uint8_t)245, 0, 41, 0.5f)
diff --git a/sources/ui/components/midi_keyboard_ex.h b/sources/ui/components/midi_keyboard_ex.h
index f742ef6..3887945 100644
--- a/sources/ui/components/midi_keyboard_ex.h
+++ b/sources/ui/components/midi_keyboard_ex.h
@@ -6,12 +6,7 @@
#pragma once
#include "JuceHeader.h"
-// XXX(jpc) a hack so we don't need to link the whole `juce_audio_utils`
-namespace ex {
-#include <juce_audio_utils/gui/juce_MidiKeyboardComponent.h>
-}
-
-class Midi_Keyboard_Ex : public ex::juce::MidiKeyboardComponent {
+class Midi_Keyboard_Ex : public juce::MidiKeyboardComponent {
public:
Midi_Keyboard_Ex(MidiKeyboardState &state, Orientation orientation);
void highlight_note(unsigned note, unsigned velocity);
diff --git a/sources/ui/components/new_program_editor.cc b/sources/ui/components/new_program_editor.cc
index cf0dd48..d0d391e 100644
--- a/sources/ui/components/new_program_editor.cc
+++ b/sources/ui/components/new_program_editor.cc
@@ -218,7 +218,7 @@ void New_Program_Editor::buttonClicked (Button* buttonThatWasClicked)
unsigned pgm = to_uint7(edt_pgm_num->getText().toRawUTF8());
if (msb == ~0u || lsb == ~0u || pgm == ~0u)
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon,
"Invalid value", "Identifiers must be integers between 0 and 127.");
else {
diff --git a/sources/ui/generic_main_component.h b/sources/ui/generic_main_component.h
index b43e3cf..99fbe96 100644
--- a/sources/ui/generic_main_component.h
+++ b/sources/ui/generic_main_component.h
@@ -68,7 +68,7 @@ public:
void update_emulator_icon();
void build_emulator_menu(PopupMenu &menu);
- int select_emulator_by_menu();
+ void select_emulator_by_menu(std::function<void(int)> callback);
void handle_load_bank(Component *clicked);
void handle_save_bank(Component *clicked);
@@ -107,6 +107,7 @@ private:
void get_master_volume_limits(
const AudioParameterFloat ¶meter,
double &linmin, double &linmax, double &dbmin, double &dbmax) const;
+ void showOkCancelBoxAsync(MessageBoxIconType iconType, String title, String message, std::function<void(bool)> callback);
protected:
bool write_to_processor(
diff --git a/sources/ui/generic_main_component.tcc b/sources/ui/generic_main_component.tcc
index 61b860d..f6e70c7 100644
--- a/sources/ui/generic_main_component.tcc
+++ b/sources/ui/generic_main_component.tcc
@@ -554,6 +554,25 @@ void Generic_Main_Component<T>::handle_edit_program()
dlg_edit_program_ = dlgopts.launchAsync();
}
+class CB : public ModalComponentManager::Callback {
+ std::function<void(bool)> cb;
+
+public:
+ CB(std::function<void(bool)> callback) : cb(callback) {
+ }
+
+ void modalStateFinished (int returnValue) override {
+ cb(returnValue);
+ delete this;
+ }
+};
+
+template <class T>
+void Generic_Main_Component<T>::showOkCancelBoxAsync(MessageBoxIconType iconType, String title, String message, std::function<void(bool)> callback) {
+ auto cb = new CB(callback);
+ AlertWindow::showOkCancelBox(iconType, title, message, "OK", "Cancel", nullptr, cb);
+}
+
template <class T>
void Generic_Main_Component<T>::handle_add_program()
{
@@ -563,8 +582,7 @@ void Generic_Main_Component<T>::handle_add_program()
menu.addSeparator();
menu.addItem(3, "Delete bank");
menu.addItem(4, "Delete all banks");
- int selection = menu.showMenu(PopupMenu::Options()
- .withParentComponent(this));
+ menu.showMenuAsync(PopupMenu::Options().withTargetComponent(this), [this](int selection) {
unsigned part = midichannel_;
uint32_t program = midiprogram_[part];
@@ -604,10 +622,10 @@ void Generic_Main_Component<T>::handle_add_program()
break;
}
case 2: {
- bool confirm = AlertWindow::showOkCancelBox(
+ showOkCancelBoxAsync(
AlertWindow::QuestionIcon, "Delete program",
fmt::format("Confirm deletion of program {:c}{:03d}?",
- percussive ? 'P' : 'M', program & 127));
+ percussive ? 'P' : 'M', program & 127), [&](bool confirm) {
if (confirm) {
Messages::User::DeleteInstrument msg;
msg.bank = bank;
@@ -615,13 +633,14 @@ void Generic_Main_Component<T>::handle_add_program()
msg.notify_back = true;
write_to_processor(msg.tag, &msg, sizeof(msg));
}
+ });
break;
}
case 3: {
- bool confirm = AlertWindow::showOkCancelBox(
+ showOkCancelBoxAsync(
AlertWindow::QuestionIcon, "Delete bank",
fmt::format("Confirm deletion of bank {:03d}:{:03d}?",
- bank.msb, bank.lsb));
+ bank.msb, bank.lsb), [&](bool confirm) {
if (confirm) {
Messages::User::DeleteBank msg;
msg.bank = bank;
@@ -630,20 +649,23 @@ void Generic_Main_Component<T>::handle_add_program()
msg.bank.percussive = !bank.percussive;
write_to_processor(msg.tag, &msg, sizeof(msg));
}
+ });
break;
}
case 4: {
- bool confirm = AlertWindow::showOkCancelBox(
+ showOkCancelBoxAsync(
AlertWindow::QuestionIcon, "Delete all banks",
- fmt::format("Confirm deletion of all banks?"));
+ fmt::format("Confirm deletion of all banks?"), [&](bool confirm){
if (confirm) {
Messages::User::ClearBanks msg;
msg.notify_back = true;
write_to_processor(msg.tag, &msg, sizeof(msg));
}
+ });
break;
}
}
+ });
}
template <class T>
@@ -735,15 +757,14 @@ void Generic_Main_Component<T>::build_emulator_menu(PopupMenu &menu)
}
template <class T>
-int Generic_Main_Component<T>::select_emulator_by_menu()
+void Generic_Main_Component<T>::select_emulator_by_menu(std::function<void(int)> callback)
{
PopupMenu menu;
build_emulator_menu(menu);
unsigned emulator = chip_settings_.emulator;
- int selection = menu.showMenu(PopupMenu::Options()
+ menu.showMenuAsync(PopupMenu::Options()
.withParentComponent(this)
- .withItemThatMustBeVisible(emulator + 1));
- return selection;
+ .withItemThatMustBeVisible(emulator + 1), callback);
}
template <class T>
@@ -779,26 +800,31 @@ void Generic_Main_Component<T>::handle_load_bank(Component *clicked)
menu.addSubMenu("Load from collection", pak_submenu);
}
- int selection = menu.showAt(clicked);
+ menu.showMenuAsync(PopupMenu::Options()
+ .withTargetComponent(clicked), [=](int selection) {
if (selection == 1) {
- FileChooser chooser(TRANS("Load bank..."), bank_directory_, bank_file_filter, prefer_native_file_dialog);
- if (chooser.browseForFileToOpen()) {
+ auto chooser_ = new FileChooser(TRANS("Load bank..."), bank_directory_, bank_file_filter, prefer_native_file_dialog);
+ chooser_->launchAsync(FileBrowserComponent::FileChooserFlags::openMode | FileBrowserComponent::FileChooserFlags::canSelectFiles, [this,chooser_](const FileChooser& chooser) {
+ if (!chooser.getResults().isEmpty()) {
File file = chooser.getResult();
change_bank_directory(file.getParentDirectory());
int format = 0;
load_bank(file, format);
}
+ delete chooser_;
+ });
}
else if (selection == 2) {
int program_selection = self()->cb_program->getSelectedId();
if (program_selection == 0) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, TRANS("Load instrument..."), TRANS("Please select a program first."));
return;
}
- FileChooser chooser(TRANS("Load instrument..."), bank_directory_, ins_file_filter, prefer_native_file_dialog);
- if (chooser.browseForFileToOpen()) {
+ auto chooser_ = new FileChooser(TRANS("Load instrument..."), bank_directory_, ins_file_filter, prefer_native_file_dialog);
+ chooser_->launchAsync(FileBrowserComponent::FileChooserFlags::openMode | FileBrowserComponent::FileChooserFlags::canSelectFiles, [&,chooser_](const FileChooser& chooser) {
+ if (!chooser.getResults().isEmpty()) {
File file = chooser.getResult();
change_bank_directory(file.getParentDirectory());
int format = 0;
@@ -808,6 +834,8 @@ void Generic_Main_Component<T>::handle_load_bank(Component *clicked)
#endif
load_single_instrument(program_selection - 1, file, format);
}
+ delete chooser_;
+ });
}
else if (selection >= menu_index) {
uint32_t index = selection - menu_index;
@@ -815,6 +843,7 @@ void Generic_Main_Component<T>::handle_load_bank(Component *clicked)
std::string wopl = pak.extract(index);
load_bank_mem((const uint8_t *)wopl.data(), wopl.size(), name, 0);
}
+ });
}
template <class T>
@@ -830,6 +859,9 @@ void Generic_Main_Component<T>::handle_save_bank(Component *clicked)
menu.addItem(menu_index++, "Save bank file...");
menu.addItem(menu_index++, "Save instrument file...");
+#if true
+ auto overwrite_confirm = [](const File &file) { return true; };
+#else // FIXME: implement
auto overwrite_confirm =
[this](const File &file) {
bool confirm = true;
@@ -844,14 +876,16 @@ void Generic_Main_Component<T>::handle_save_bank(Component *clicked)
}
return confirm;
};
+#endif
- int selection = menu.showAt(clicked);
+ menu.showMenuAsync(PopupMenu::Options()
+ .withTargetComponent(clicked), [=](int selection){
if (selection == 1) {
File initial_file = bank_directory_.getChildFile(
File::createLegalFileName(self()->edt_bank_name->getText()));
- FileChooser chooser(TRANS("Save bank..."), initial_file, bank_file_filter, prefer_native_file_dialog);
- if (!chooser.browseForFileToSave(false))
- return;
+ auto chooser_ = new FileChooser(TRANS("Save bank..."), initial_file, bank_file_filter, prefer_native_file_dialog);
+ chooser_->launchAsync(FileBrowserComponent::FileChooserFlags::saveMode | FileBrowserComponent::FileChooserFlags::canSelectFiles, [&,chooser_](const FileChooser& chooser) {
+ if (!chooser.getResults().isEmpty()) {
File file = chooser.getResult();
file = file.withFileExtension(bank_file_extension);
@@ -860,18 +894,21 @@ void Generic_Main_Component<T>::handle_save_bank(Component *clicked)
change_bank_directory(file.getParentDirectory());
save_bank(file);
}
+ }
+ delete chooser_;
+ });
}
else if (selection == 2) {
int program_selection = self()->cb_program->getSelectedId();
if (program_selection == 0) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, TRANS("Save instrument..."), TRANS("Please select a program first."));
return;
}
- FileChooser chooser(TRANS("Save instrument..."), bank_directory_, ins_file_filter, prefer_native_file_dialog);
- if (!chooser.browseForFileToSave(false))
- return;
+ auto chooser_ = new FileChooser(TRANS("Save instrument..."), bank_directory_, ins_file_filter, prefer_native_file_dialog);
+ chooser_->launchAsync(FileBrowserComponent::FileChooserFlags::saveMode | FileBrowserComponent::FileChooserFlags::canSelectFiles, [&,chooser_](const FileChooser& chooser) {
+ if (!chooser.getResults().isEmpty()) {
File file = chooser.getResult();
file = file.withFileExtension(ins_file_extension);
@@ -880,7 +917,11 @@ void Generic_Main_Component<T>::handle_save_bank(Component *clicked)
change_bank_directory(file.getParentDirectory());
save_single_instrument(program_selection - 1, file);
}
+ }
+ delete chooser_;
+ });
}
+ });
}
template <class T>
@@ -895,20 +936,20 @@ void Generic_Main_Component<T>::load_bank(const File &file, int format)
const char *error_title = "Error loading bank";
if (stream->failedToOpen()) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The file could not be opened.");
return;
}
if ((length = stream->getTotalLength()) >= max_length) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The selected file is too large to be valid.");
return;
}
filedata.reset(new uint8_t[length]);
if (stream->read(filedata.get(), length) != length) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The input operation has failed.");
return;
}
@@ -928,20 +969,20 @@ void Generic_Main_Component<T>::load_single_instrument(uint32_t program, const F
const char *error_title = "Error loading instrument";
if (stream->failedToOpen()) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The file could not be opened.");
return;
}
if ((length = stream->getTotalLength()) >= max_length) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The selected file is too large to be valid.");
return;
}
filedata.reset(new uint8_t[length]);
if (stream->read(filedata.get(), length) != length) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The input operation has failed.");
return;
}
@@ -961,7 +1002,7 @@ void Generic_Main_Component<T>::load_bank_mem(const uint8_t *mem, size_t length,
default: {
WOPx::BankFile_Ptr wopl(WOPx::LoadBankFromMem((void *)mem, length, nullptr));
if (!wopl) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The input file is not in " WOPx_BANK_FORMAT " format.");
return;
}
@@ -1034,7 +1075,7 @@ void Generic_Main_Component<T>::load_single_instrument_mem(uint32_t program, con
default: {
WOPx::InstrumentFile wopi = {};
if (WOPx::LoadInstFromMem(&wopi, (void *)mem, length) != 0) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The input file is not in " WOPx_INST_FORMAT " format.");
return;
}
@@ -1045,7 +1086,7 @@ void Generic_Main_Component<T>::load_single_instrument_mem(uint32_t program, con
case 1:
ins = Instrument::from_sbi(mem, length);
if (ins.blank()) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The input file is not in SBI format.");
return;
}
@@ -1143,7 +1184,7 @@ void Generic_Main_Component<T>::save_bank(const File &file)
const char *error_title = "Error saving bank";
if (WOPx::SaveBankToMem(&wopl, filedata.get(), filesize, wopl.version, 0) != 0) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The bank could not be converted to " WOPx_BANK_FORMAT ".");
return;
}
@@ -1151,7 +1192,7 @@ void Generic_Main_Component<T>::save_bank(const File &file)
std::unique_ptr<FileOutputStream> stream(file.createOutputStream());
if (stream->failedToOpen()) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The file could not be opened.");
return;
}
@@ -1162,7 +1203,7 @@ void Generic_Main_Component<T>::save_bank(const File &file)
stream->flush();
if (!stream->getStatus()) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The output operation has failed.");
return;
}
@@ -1193,7 +1234,7 @@ void Generic_Main_Component<T>::save_single_instrument(uint32_t program, const F
const char *error_title = "Error saving instrument";
if (WOPx::SaveInstToMem(&opli, filedata.get(), filesize, opli.version) != 0) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The bank could not be converted to " WOPx_INST_FORMAT ".");
return;
}
@@ -1201,7 +1242,7 @@ void Generic_Main_Component<T>::save_single_instrument(uint32_t program, const F
std::unique_ptr<FileOutputStream> stream(file.createOutputStream());
if (stream->failedToOpen()) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The file could not be opened.");
return;
}
@@ -1212,7 +1253,7 @@ void Generic_Main_Component<T>::save_single_instrument(uint32_t program, const F
stream->flush();
if (!stream->getStatus()) {
- AlertWindow::showMessageBox(
+ AlertWindow::showMessageBoxAsync(
AlertWindow::WarningIcon, error_title, "The output operation has failed.");
return;
}
@@ -1224,11 +1265,12 @@ void Generic_Main_Component<T>::handle_change_keymap()
Midi_Keyboard_Ex &kb = *self()->midi_kb;
PopupMenu menu;
build_key_layout_menu(menu, last_key_layout_);
- int selection = menu.showMenu(PopupMenu::Options()
- .withParentComponent(this));
+ menu.showMenuAsync(PopupMenu::Options()
+ .withTargetComponent(this), [this,&kb](int selection) {
if (selection != 0)
last_key_layout_ = set_key_layout(kb, (Key_Layout)(selection - 1), *conf_);
kb.grabKeyboardFocus();
+ });
}
template <class T>