forked from plugdata-team/plugdata
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddObjectMenu.h
More file actions
694 lines (622 loc) · 36.4 KB
/
AddObjectMenu.h
File metadata and controls
694 lines (622 loc) · 36.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
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
/*
// Copyright (c) 2023 Alex Mitchell and Timothy Schoen
// For information on usage and redistribution, and for a DISCLAIMER OF ALL
// WARRANTIES, see the file, "LICENSE.txt," in this distribution.
*/
#pragma once
#include "Dialogs.h"
#include "Components/ObjectDragAndDrop.h"
#define DEBUG_PRINT_OBJECT_LIST 0
class ObjectItem final : public ObjectDragAndDrop
, public SettableTooltipClient {
public:
ObjectItem(PluginEditor* e, String const& text, String const& icon, String const& tooltip, String const& patch, ObjectIDs const objectID, std::function<void(bool)> const& dismissCalloutBox)
: ObjectDragAndDrop(e)
, titleText(text)
, iconText(icon)
, objectPatch(patch)
, dismissMenu(dismissCalloutBox)
, editor(e)
{
setTooltip(tooltip.replace("(@keypress) ", getKeyboardShortcutDescription(objectID)));
}
void dismiss(bool const withAnimation) override
{
dismissMenu(withAnimation);
}
String getKeyboardShortcutDescription(ObjectIDs const objectID) const
{
auto keyPresses = editor->commandManager.getKeyMappings()->getKeyPressesAssignedToCommand(objectID);
if (keyPresses.size()) {
return "(" + keyPresses.getReference(0).getTextDescription() + ") ";
}
return String();
}
void paint(Graphics& g) override
{
auto const highlight = findColour(PlugDataColour::popupMenuActiveBackgroundColourId);
auto const iconBounds = getLocalBounds().reduced(14).translated(0, -7);
auto const textBounds = getLocalBounds().removeFromBottom(14);
if (isHovering) {
g.setColour(highlight);
g.fillRoundedRectangle(iconBounds.toFloat(), Corners::defaultCornerRadius);
}
Fonts::drawText(g, titleText, textBounds, findColour(PlugDataColour::popupMenuTextColourId), 13.0f, Justification::centred);
Fonts::drawIcon(g, iconText, iconBounds.reduced(2), findColour(PlugDataColour::popupMenuTextColourId), 30);
}
bool hitTest(int const x, int const y) override
{
return getLocalBounds().reduced(16).translated(0, -7).contains(x, y);
}
void mouseEnter(MouseEvent const& e) override
{
isHovering = true;
repaint();
}
void mouseExit(MouseEvent const& e) override
{
isHovering = false;
repaint();
}
String getObjectString() override
{
// If this is an array, replace @arrName with unused name
auto patchString = objectPatch;
if (patchString.contains("@arrName")) {
editor->pd->setThis();
patchString = patchString.replace("@arrName", String::fromUTF8(pd::Interface::getUnusedArrayName()->s_name));
}
return patchString;
}
String getPatchStringName() override
{
return titleText + String(" object");
}
void mouseUp(MouseEvent const& e) override
{
if (e.mouseWasDraggedSinceMouseDown()) {
dismissMenu(false);
} else {
#if !JUCE_IOS
ObjectClickAndDrop::attachToMouse(this);
dismissMenu(false);
#endif
}
}
private:
String titleText;
String iconText;
String objectPatch;
bool isHovering = false;
std::function<void(bool)> dismissMenu;
PluginEditor* editor;
};
class ObjectList final : public Component {
public:
ObjectList(PluginEditor* e, std::function<void(bool)> const& dismissCalloutBox)
: editor(e)
, dismissMenu(dismissCalloutBox)
{
#if DEBUG_PRINT_OBJECT_LIST == 1
printAllObjects();
#endif
}
void resized() override
{
auto const width = getWidth();
int column = 0;
int const maxColumns = width / itemSize;
int offset = 0;
for (auto const button : objectButtons) {
button->setBounds(column * itemSize, offset, itemSize, itemSize);
column++;
if (column >= maxColumns) {
column = 0;
offset += itemSize;
}
}
}
void showCategory(String const& categoryToView)
{
objectButtons.clear();
auto objectsToShow = getValue<bool>(SettingsFile::getInstance()->getPropertyAsValue("hvcc_mode")) ? heavyObjectList : defaultObjectList;
for (auto& [categoryName, objectCategory] : objectsToShow) {
if (categoryName != categoryToView)
continue;
for (auto& [icon, patch, tooltip, name, objectID] : objectCategory) {
auto objectPatch = patch;
if (objectPatch.isEmpty())
objectPatch = "#X obj 0 0 " + name;
else if (!objectPatch.startsWith("#")) {
objectPatch = ObjectThemeManager::get()->getCompleteFormat(objectPatch);
}
auto* button = objectButtons.add(new ObjectItem(editor, name, icon, tooltip, objectPatch, objectID, dismissMenu));
addAndMakeVisible(button);
}
}
resized();
}
static void printAllObjects()
{
static bool hasRun = false;
if (hasRun)
return;
hasRun = true;
std::cout << "==== object icon list in CSV format ====" << std::endl;
for (auto& [categoryName, objectCategory] : defaultObjectList) {
String cat = categoryName;
for (auto& [icon, patch, tooltip, name, objectID] : objectCategory) {
std::cout << cat << ", " << name << ", " << icon << std::endl;
}
}
std::cout << "==== end of list ====" << std::endl;
}
OwnedArray<ObjectItem> objectButtons;
static inline HeapArray<std::pair<String, HeapArray<std::tuple<String, String, String, String, ObjectIDs>>>> const defaultObjectList = {
{ "Default",
{
{ Icons::GlyphEmptyObject, "#X obj 0 0", "(@keypress) Empty object", "Object", NewObject },
{ Icons::GlyphMessage, "#X msg 0 0", "(@keypress) Message", "Message", NewMessage },
{ Icons::GlyphFloatBox, "#X floatatom 0 0 5 0 0 0 - - - 0", "(@keypress) Float box", "Float", NewFloatAtom },
{ Icons::GlyphSymbolBox, "#X symbolatom 0 0 10 0 0 0 - - - 0", "Symbol box", "Symbol", NewSymbolAtom },
{ Icons::GlyphListBox, "#X listbox 0 0 20 0 0 0 - - - 0", "(@keypress) List box", "List", NewListAtom },
{ Icons::GlyphComment, "#X text 0 0 comment", "(@keypress) Comment", "Comment", NewComment },
{ Icons::GlyphArray, "#N canvas 0 0 450 250 (subpatch) 0;\n#X array @arrName 100 float 2;\n#X coords 0 1 100 -1 200 140 1;\n#X restore 0 0 graph;", "(@keypress) Array", "Array", NewArray },
{ Icons::GlyphGOP, "#N canvas 0 0 450 250 (subpatch) 1;\n#X coords 0 1 100 -1 200 140 1 0 0;\n#X restore 0 0 graph;", "(@keypress) Graph on parent", "Graph", NewGraphOnParent },
} },
{ "UI",
{
// GUI object default settings are in ObjectManager.h
{ Icons::GlyphBang, "bng", "(@keypress) Bang", "Bang", NewBang },
{ Icons::GlyphToggle, "tgl", "(@keypress) Toggle", "Toggle", NewToggle },
{ Icons::GlyphButton, "button", "Button", "Button", OtherObject },
{ Icons::GlyphKnob, "knob", "Knob", "Knob", OtherObject },
{ Icons::GlyphVSlider, "vsl", "(@keypress) Vertical slider", "V. Slider", NewVerticalSlider },
{ Icons::GlyphHSlider, "hsl", "(@keypress) Horizontal slider", "H. Slider", NewHorizontalSlider },
{ Icons::GlyphVRadio, "vradio", "(@keypress) Vertical radio box", "V. Radio", NewVerticalRadio },
{ Icons::GlyphHRadio, "hradio", "(@keypress) Horizontal radio box", "H. Radio", NewHorizontalRadio },
{ Icons::GlyphNumber, "nbx", "(@keypress) Number box", "Number", NewNumbox },
{ Icons::GlyphCanvas, "cnv", "(@keypress) Canvas", "Canvas", NewCanvas },
{ Icons::GlyphFunction, "function", "Function", "Function", OtherObject },
{ Icons::GlyphOscilloscope, "scope~", "Oscilloscope", "Scope", OtherObject },
{ Icons::GlyphKeyboard, "keyboard", "Piano keyboard", "Keyboard", OtherObject },
{ Icons::GlyphMessbox, "messbox", "ELSE Message box", "Messbox", OtherObject },
{ Icons::GlyphBicoeff, "#X obj 0 0 bicoeff 450 150 peaking", "Bicoeff generator", "Bicoeff", OtherObject },
{ Icons::GlyphVUMeter, "vu", "(@keypress) VU meter", "VU Meter", NewVUMeter },
} },
{ "General",
{
{ Icons::GlyphMetro, "#X obj 0 0 metro 1 120 permin", "Metro", "Metro", OtherObject },
{ Icons::GlyphCounter, "#X obj 0 0 count 5", "Count", "Count", OtherObject },
{ Icons::GlyphTrigger, "#X obj 0 0 trigger", "Trigger", "Trigger", OtherObject },
{ Icons::GlyphMoses, "#X obj 0 0 moses", "Moses", "Moses", OtherObject },
{ Icons::GlyphSpigot, "#X obj 0 0 spigot", "Spigot", "Spigot", OtherObject },
{ Icons::GlyphBondo, "#X obj 0 0 bondo", "Bondo", "Bondo", OtherObject },
{ Icons::GlyphSelect, "#X obj 0 0 select", "Select", "Select", OtherObject },
{ Icons::GlyphRoute, "#X obj 0 0 route", "Route", "Route", OtherObject },
{ Icons::GlyphExpr, "#X obj 0 0 expr", "Expr", "Expr", OtherObject },
{ Icons::GlyphLoadbang, "#X obj 0 0 loadbang", "Loadbang", "Loadbang", OtherObject },
{ Icons::GlyphPack, "#X obj 0 0 pack", "Pack", "Pack", OtherObject },
{ Icons::GlyphUnpack, "#X obj 0 0 unpack", "Unpack", "Unpack", OtherObject },
{ Icons::GlyphPrint, "#X obj 0 0 print", "Print", "Print", OtherObject },
{ Icons::GlyphTimer, "#X obj 0 0 timer", "Timer", "Timer", OtherObject },
{ Icons::GlyphDelay, "#X obj 0 0 delay 1 60 permin", "Delay", "Delay", OtherObject },
{ Icons::GlyphSfz, "#X obj 0 0 sfz~", "Sfz sample player using sfizz", "Sfz", OtherObject },
} },
{ "MIDI",
{
{ Icons::GlyphMidiIn, "#X obj 0 0 midiin", "MIDI in", "MIDI in", OtherObject },
{ Icons::GlyphMidiOut, "#X obj 0 0 midiout", "MIDI out", "MIDI out", OtherObject },
{ Icons::GlyphNoteIn, "#X obj 0 0 notein", "Note in", "Note in", OtherObject },
{ Icons::GlyphNoteOut, "#X obj 0 0 noteout", "Note out", "Note out", OtherObject },
{ Icons::GlyphCtlIn, "#X obj 0 0 ctlin", "Control in", "Ctl in", OtherObject },
{ Icons::GlyphCtlOut, "#X obj 0 0 ctlout", "Control out", "Ctl out", OtherObject },
{ Icons::GlyphPgmIn, "#X obj 0 0 pgmin", "Program in", "Pgm in", OtherObject },
{ Icons::GlyphPgmOut, "#X obj 0 0 pgmout", "Program out", "Pgm out", OtherObject },
{ Icons::GlyphSysexIn, "#X obj 0 0 sysexin", "Sysex in", "Sysex in", OtherObject },
{ Icons::GlyphMtof, "#X obj 0 0 mtof", "MIDI to frequency", "mtof", OtherObject },
{ Icons::GlyphFtom, "#X obj 0 0 ftom", "Frequency to MIDI", "ftom", OtherObject },
{ Icons::GlyphAutotune, "#X obj 0 0 autotune", "Pitch quantizer", "Autotune", OtherObject },
} },
{ "IO",
{
{ Icons::GlyphAdc, "#X obj 0 0 adc~", "Adc", "Adc", OtherObject },
{ Icons::GlyphDac, "#X obj 0 0 dac~", "Dac", "Dac", OtherObject },
{ Icons::GlyphOut, "#X obj 0 0 out~", "Out", "Out", OtherObject },
{ Icons::GlyphBlocksize, "#X obj 0 0 blocksize~", "Blocksize", "Blocksize", OtherObject },
{ Icons::GlyphSamplerate, "#X obj 0 0 samplerate~", "Samplerate", "Samplerate", OtherObject },
{ Icons::GlyphSetDsp, "#X obj 0 0 setdsp~", "Setdsp", "Setdsp", OtherObject },
{ Icons::GlyphNetreceive, "#X obj 0 0 netreceive", "Netreceive", "Netreceive", OtherObject },
{ Icons::GlyphNetsend, "#X obj 0 0 netsend", "Netsend", "Netsend", OtherObject },
{ Icons::GlyphOSCsend, "#X obj 0 0 osc.send", "OSC send", "OSC send", OtherObject },
{ Icons::GlyphOSCreceive, "#X obj 0 0 osc.receive", "OSC receive", "OSC receive", OtherObject },
{ Icons::GlyphSend, "#X obj 0 0 s", "Send", "Send", OtherObject },
{ Icons::GlyphReceive, "#X obj 0 0 r", "Receive", "Receive", OtherObject },
{ Icons::GlyphSignalSend, "#X obj 0 0 s~", "Send~", "Send~", OtherObject },
{ Icons::GlyphSignalReceive, "#X obj 0 0 r~", "Receive~", "Receive~", OtherObject },
} },
{ "Osc~",
{
{ Icons::GlyphPhasor, "#X obj 0 0 phasor~", "Phasor", "Phasor", OtherObject },
{ Icons::GlyphOsc, "#X obj 0 0 osc~ 440", "Osc", "Osc", OtherObject },
{ Icons::GlyphOscBL, "#X obj 0 0 bl.osc~ 440", "Osc band limited", "Bl. Osc", OtherObject },
{ Icons::GlyphTriangle, "#X obj 0 0 tri~ 440", "Triangle", "Triangle", OtherObject },
{ Icons::GlyphTriBL, "#X obj 0 0 bl.tri~ 100", "Triangle band limited", "Bl. Tri", OtherObject },
{ Icons::GlyphSquare, "#X obj 0 0 square~", "Square", "Square", OtherObject },
{ Icons::GlyphSquareBL, "#X obj 0 0 bl.tri~ 440", "Square band limited", "Bl. Square", OtherObject },
{ Icons::GlyphSaw, "#X obj 0 0 saw~ 440", "Saw", "Saw", OtherObject },
{ Icons::GlyphSawBL, "#X obj 0 0 bl.saw~ 440", "Saw band limited", "Bl. Saw", OtherObject },
{ Icons::GlyphImp, "#X obj 0 0 imp~ 100", "Impulse", "Impulse", OtherObject },
{ Icons::GlyphImpBL, "#X obj 0 0 bl.imp~ 100", "Impulse band limited", "Bl. Imp", OtherObject },
{ Icons::GlyphWavetable, "#X obj 0 0 wavetable~", "Wavetable", "Wavetab", OtherObject },
{ Icons::GlyphWavetableBL, "#X obj 0 0 bl.wavetable~", "Wavetable band limited", "Bl. Wavetab", OtherObject },
{ Icons::GlyphPlaits, "#X obj 0 0 plaits~", "Plaits", "Plaits", OtherObject },
} },
{ "FX~",
{
{ Icons::GlyphCrusher, "#X obj 0 0 crusher~ 0.1 0.1", "Crusher", "Crusher", OtherObject },
{ Icons::GlyphDelayEffect, "#X obj 0 0 delay~ 22050 14700", "Delay", "Delay", OtherObject },
{ Icons::GlyphDrive, "#X obj 0 0 drive~", "Drive", "Drive", OtherObject },
{ Icons::GlyphFlanger, "#X obj 0 0 flanger~ 0.1 20 -0.6", "Flanger", "Flanger", OtherObject },
{ Icons::GlyphCombRev, "#X obj 0 0 comb.rev~ 500 1 0.99 0.99", "Comb reverberator", "Comb. Rev", OtherObject },
{ Icons::GlyphComp, "#X obj 0 0 duck~", "Sidechain compressor", "Duck", OtherObject },
{ Icons::GlyphBallance, "#X obj 0 0 balance~", "Balance", "Balance", OtherObject },
{ Icons::GlyphPan, "#X obj 0 0 pan2~", "Pan", "Pan", OtherObject },
{ Icons::GlyphReverb, "#X obj 0 0 free.rev~ 0.7 0.6 0.5 0.7", "Reverb", "Reverb", OtherObject },
{ Icons::GlyphFreeze, "#X obj 0 0 freeze~", "Freeze", "Freeze", OtherObject },
{ Icons::GlyphRingmod, "#X obj 0 0 rm~ 150", "Ringmod", "Ringmod", OtherObject },
{ Icons::GlyphSVFilter, "#X obj 0 0 svfilter~ 1729 0.42", "State variable filter", "SVFilter", OtherObject },
{ Icons::GlyphClip, "#X obj 0 0 clip~ -0.5 0.5", "Clip", "Clip", OtherObject },
{ Icons::GlyphFold, "#X obj 0 0 fold~ -0.5 0.5", "Fold", "Fold", OtherObject },
{ Icons::GlyphWrap, "#X obj 0 0 wrap2~ -0.5 0.5", "Wrap", "Wrap", OtherObject },
} },
{ "Multi~",
{
{ Icons::GlyphMultiSnake, "#X obj 0 0 snake~ 2", "Multichannel snake", "Snake", OtherObject },
{ Icons::GlyphMultiGet, "#X obj 0 0 get~", "Multichannel get", "Get", OtherObject },
{ Icons::GlyphMultiPick, "#X obj 0 0 pick~", "Multichannel pick", "Pick", OtherObject },
{ Icons::GlyphMultiSig, "#X obj 0 0 sigs~", "Multichannel value signal", "Sigs", OtherObject },
{ Icons::GlyphMultiMerge, "#X obj 0 0 merge~", "Multichannel merge", "Merge", OtherObject },
{ Icons::GlyphMultiUnmerge, "#X obj 0 0 unmerge~", "Multichannel unmerge", "Unmerge", OtherObject },
} },
{ "Math",
{
{ Icons::GlyphGeneric, "", "Add", "+", OtherObject },
{ Icons::GlyphGeneric, "", "Subtract", "-", OtherObject },
{ Icons::GlyphGeneric, "", "Multiply", "*", OtherObject },
{ Icons::GlyphGeneric, "", "Divide", "/", OtherObject },
{ Icons::GlyphGeneric, "", "Remainder", "%", OtherObject },
{ Icons::GlyphGeneric, "", "Reversed inlet subtraction", "!-", OtherObject },
{ Icons::GlyphGeneric, "", "Reversed inlet division", "!/", OtherObject },
{ Icons::GlyphGeneric, "", "Greater than", ">", OtherObject },
{ Icons::GlyphGeneric, "", "Less than", "<", OtherObject },
{ Icons::GlyphGeneric, "", "Greater or equal", ">=", OtherObject },
{ Icons::GlyphGeneric, "", "Less or equal", "<=", OtherObject },
{ Icons::GlyphGeneric, "", "Equality", "==", OtherObject },
{ Icons::GlyphGeneric, "", "Not equal", "!=", OtherObject },
{ Icons::GlyphGeneric, "", "Minimum", "min", OtherObject },
{ Icons::GlyphGeneric, "", "Maximum", "max", OtherObject },
} },
{ "Math~",
{
{ Icons::GlyphGenericSignal, "", "(signal) Add", "+~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Subtract", "-~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Multiply", "*~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Divide", "/~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Remainder", "%~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Reversed inlet subtraction", "!-~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Reversed inlet division", "!/~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Greater than", ">~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Less than", "<~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Greater or equal", ">=~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Less or equal", "<=~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Equality", "==~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Not equal", "!=~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Minimum", "min~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Maximum", "max~", OtherObject },
} },
};
static inline HeapArray<std::pair<String, HeapArray<std::tuple<String, String, String, String, ObjectIDs>>>> const heavyObjectList = {
{ "Default",
{
{ Icons::GlyphEmptyObject, "#X obj 0 0", "(@keypress) Empty object", "Object", NewObject },
{ Icons::GlyphMessage, "#X msg 0 0", "(@keypress) Message", "Message", NewMessage },
{ Icons::GlyphFloatBox, "#X floatatom 0 0 5 0 0 0 - - - 0", "(@keypress) Float box", "Float", NewFloatAtom },
{ Icons::GlyphSymbolBox, "#X symbolatom 0 0 10 0 0 0 - - - 0", "Symbol box", "Symbol", NewSymbolAtom },
{ Icons::GlyphComment, "#X text 0 0 comment", "(@keypress) Comment", "Comment", NewComment },
{ Icons::GlyphArray, "#N canvas 0 0 450 250 (subpatch) 0;\n#X array @arrName 100 float 2;\n#X coords 0 1 100 -1 200 140 1;\n#X restore 0 0 graph;", "(@keypress) Array", "Array", NewArray },
{ Icons::GlyphGOP, "#N canvas 0 0 450 250 (subpatch) 1;\n#X coords 0 1 100 -1 200 140 1 0 0;\n#X restore 0 0 graph;", "(@keypress) Graph on parent", "Graph", NewGraphOnParent },
} },
{ "UI",
{
// GUI object default settings are in OjbectManager.h
{ Icons::GlyphBang, "bng", "(@keypress) Bang", "Bang", NewBang },
{ Icons::GlyphToggle, "tgl", "(@keypress) Toggle", "Toggle", NewToggle },
{ Icons::GlyphKnob, "knob", "Knob", "Knob", OtherObject },
{ Icons::GlyphVSlider, "vsl", "(@keypress) Vertical slider", "V. Slider", NewVerticalSlider },
{ Icons::GlyphHSlider, "hsl", "(@keypress) Horizontal slider", "H. Slider", NewHorizontalSlider },
{ Icons::GlyphVRadio, "vradio", "(@keypress) Vertical radio box", "V. Radio", NewVerticalRadio },
{ Icons::GlyphHRadio, "hradio", "(@keypress) Horizontal radio box", "H. Radio", NewHorizontalRadio },
{ Icons::GlyphNumber, "nbx", "(@keypress) Number box", "Number", NewNumbox },
{ Icons::GlyphCanvas, "cnv", "(@keypress) Canvas", "Canvas", NewCanvas },
} },
{ "General",
{
{ Icons::GlyphMetro, "#X obj 0 0 metro 1 120 permin", "Metro", "Metro", OtherObject },
{ Icons::GlyphTrigger, "#X obj 0 0 trigger", "Trigger", "Trigger", OtherObject },
{ Icons::GlyphMoses, "#X obj 0 0 moses", "Moses", "Moses", OtherObject },
{ Icons::GlyphSpigot, "#X obj 0 0 spigot", "Spigot", "Spigot", OtherObject },
{ Icons::GlyphSelect, "#X obj 0 0 select", "Select", "Select", OtherObject },
{ Icons::GlyphRoute, "#X obj 0 0 route", "Route", "Route", OtherObject },
{ Icons::GlyphLoadbang, "#X obj 0 0 loadbang", "Loadbang", "Loadbang", OtherObject },
{ Icons::GlyphPack, "#X obj 0 0 pack", "Pack", "Pack", OtherObject },
{ Icons::GlyphUnpack, "#X obj 0 0 unpack", "Unpack", "Unpack", OtherObject },
{ Icons::GlyphPrint, "#X obj 0 0 print", "Print", "Print", OtherObject },
{ Icons::GlyphTimer, "#X obj 0 0 timer", "Timer", "Timer", OtherObject },
{ Icons::GlyphDelay, "#X obj 0 0 delay 1 60 permin", "Delay", "Delay", OtherObject },
} },
{ "MIDI",
{
{ Icons::GlyphMidiIn, "#X obj 0 0 midiin", "MIDI in", "MIDI in", OtherObject },
{ Icons::GlyphMidiOut, "#X obj 0 0 midiout", "MIDI out", "MIDI out", OtherObject },
{ Icons::GlyphNoteIn, "#X obj 0 0 notein", "Note in", "Note in", OtherObject },
{ Icons::GlyphNoteOut, "#X obj 0 0 noteout", "Note out", "Note out", OtherObject },
{ Icons::GlyphCtlIn, "#X obj 0 0 ctlin", "Control in", "Ctl in", OtherObject },
{ Icons::GlyphCtlOut, "#X obj 0 0 ctlout", "Control out", "Ctl out", OtherObject },
{ Icons::GlyphPgmIn, "#X obj 0 0 pgmin", "Program in", "Pgm in", OtherObject },
{ Icons::GlyphPgmOut, "#X obj 0 0 pgmout", "Program out", "Pgm out", OtherObject },
{ Icons::GlyphGeneric, "#X obj 0 0 touchin", "Touch in", "Tch in", OtherObject },
{ Icons::GlyphGeneric, "#X obj 0 0 touchout", "Touch out", "Tch out", OtherObject },
{ Icons::GlyphGeneric, "#X obj 0 0 polytouchin", "Poly Touch in", "Ptch in", OtherObject },
{ Icons::GlyphGeneric, "#X obj 0 0 polytouchout", "Poly Touch in", "Ptch out", OtherObject },
{ Icons::GlyphMtof, "#X obj 0 0 mtof", "MIDI to frequency", "mtof", OtherObject },
{ Icons::GlyphFtom, "#X obj 0 0 ftom", "Frequency to MIDI", "ftom", OtherObject },
} },
{ "IO",
{
{ Icons::GlyphAdc, "#X obj 0 0 adc~", "Adc", "Adc", OtherObject },
{ Icons::GlyphDac, "#X obj 0 0 dac~", "Dac", "Dac", OtherObject },
{ Icons::GlyphSend, "#X obj 0 0 s", "Send", "Send", OtherObject },
{ Icons::GlyphReceive, "#X obj 0 0 r", "Receive", "Receive", OtherObject },
{ Icons::GlyphSignalSend, "#X obj 0 0 s~", "Send~", "Send~", OtherObject },
{ Icons::GlyphSignalReceive, "#X obj 0 0 r~", "Receive~", "Receive~", OtherObject },
} },
{ "Osc~",
{
{ Icons::GlyphPhasor, "#X obj 0 0 phasor~", "Phasor", "Phasor", OtherObject },
{ Icons::GlyphOsc, "#X obj 0 0 osc~ 440", "Osc", "Osc", OtherObject },
{ Icons::GlyphOscBL, "#X obj 0 0 hv.osc~ sine", "Sine band limited", "Hv Sine", OtherObject },
{ Icons::GlyphSquareBL, "#X obj 0 0 hv.osc~ square", "Square band limited", "Hv Square", OtherObject },
{ Icons::GlyphSawBL, "#X obj 0 0 hv.osc~ saw", "Saw band limited", "Hv Saw", OtherObject },
{ Icons::GlyphPinknoise, "#X obj 0 0 hv.pinknoise~", "Pink Noise", "Pink Noise", OtherObject },
{ Icons::GlyphOsc, "#X obj 0 0 hv.lfo sine", "Sine LFO", "Sine LFO", OtherObject },
{ Icons::GlyphLFORamp, "#X obj 0 0 hv.lfo ramp", "Ramp LFO", "Ramp LFO", OtherObject },
{ Icons::GlyphLFOSaw, "#X obj 0 0 hv.lfo saw", "Saw LFO", "Saw LFO", OtherObject },
{ Icons::GlyphTriangle, "#X obj 0 0 hv.lfo triangle", "Triangle LFO", "Tri LFO", OtherObject },
{ Icons::GlyphLFOSquare, "#X obj 0 0 hv.lfo square", "Square LFO", "Sq LFO", OtherObject },
{ Icons::GlyphPulse, "#X obj 0 0 hv.lfo pulse", "Pulse LFO", "Pulse LFO", OtherObject },
} },
{ "FX~",
{
{ Icons::GlyphComp, "#X obj 0 0 hv.compressor~", "Compressor", "Compress", OtherObject },
{ Icons::GlyphFlanger, "#X obj 0 0 hv.flanger~", "Flanger", "Flanger", OtherObject },
{ Icons::GlyphCombRev, "#X obj 0 0 hv.comb~", "Comb filter", "Comb. Filt", OtherObject },
{ Icons::GlyphReverb, "#X obj 0 0 hv.reverb~", "Reverb", "Reverb", OtherObject },
{ Icons::GlyphRezLowpass, "#X obj 0 0 hv.filter~ lowpass", "Resonant Lowpass Filter", "Res Lp Filt", OtherObject },
{ Icons::GlyphRezHighpass, "#X obj 0 0 hv.filter~ bandpass1", "Resonant Bandpass Filter", "Res Bp Filt", OtherObject },
{ Icons::GlyphBandpass, "#X obj 0 0 hv.filter~ highpass", "Resonant Highpass Filter", "Res Hp Filt", OtherObject },
{ Icons::GlyphAllPass, "#X obj 0 0 hv.filter~ allpass", "Resonant Allpass Filter", "Res Ap Filt", OtherObject },
{ Icons::GlyphLowpass, "#X obj 0 0 hv.lop~", "One-pole Lowpass", "1p Lp Filt", OtherObject },
{ Icons::GlyphHighpass, "#X obj 0 0 hv.hip~", "One-pole Highpass", "1p Hp Filt", OtherObject },
{ Icons::GlyphFreqShift, "#X obj 0 0 hv.freqshift~", "Frequency Shifter", "Freq Shift", OtherObject },
} },
{ "Math",
{
{ Icons::GlyphGeneric, "", "Add", "+", OtherObject },
{ Icons::GlyphGeneric, "", "Subtract", "-", OtherObject },
{ Icons::GlyphGeneric, "", "Multiply", "*", OtherObject },
{ Icons::GlyphGeneric, "", "Divide", "/", OtherObject },
{ Icons::GlyphGeneric, "", "Remainder", "%", OtherObject },
{ Icons::GlyphGeneric, "", "Greater than", ">", OtherObject },
{ Icons::GlyphGeneric, "", "Less than", "<", OtherObject },
{ Icons::GlyphGeneric, "", "Greater or equal", ">=", OtherObject },
{ Icons::GlyphGeneric, "", "Less or equal", "<=", OtherObject },
{ Icons::GlyphGeneric, "", "Equality", "==", OtherObject },
{ Icons::GlyphGeneric, "", "Not equal", "!=", OtherObject },
{ Icons::GlyphGeneric, "", "Minimum", "min", OtherObject },
{ Icons::GlyphGeneric, "", "Maximum", "max", OtherObject },
} },
{ "Math~",
{
{ Icons::GlyphGenericSignal, "", "(signal) Add", "+~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Subtract", "-~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Multiply", "*~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Divide", "/~", OtherObject },
{ Icons::GlyphGenericSignal, "#X obj 0 0 hv.gt~", "(signal) Greater than", ">~", OtherObject },
{ Icons::GlyphGenericSignal, "#X obj 0 0 hv.lt~", "(signal) Less than", "<~", OtherObject },
{ Icons::GlyphGenericSignal, "#X obj 0 0 hv.gte~", "(signal) Greater or equal", ">=~", OtherObject },
{ Icons::GlyphGenericSignal, "#X obj 0 0 hv.lte~", "(signal) Less or equal", "<=~", OtherObject },
{ Icons::GlyphGenericSignal, "#X obj 0 0 hv.eq~", "(signal) Equality", "==~", OtherObject },
{ Icons::GlyphGenericSignal, "#X obj 0 0 hv.neq~", "(signal) Not equal", "!=~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Minimum", "min~", OtherObject },
{ Icons::GlyphGenericSignal, "", "(signal) Maximum", "max~", OtherObject },
} },
};
private:
PluginEditor* editor;
std::function<void(bool)> dismissMenu;
int const itemSize = 64;
};
class ObjectCategoryView final : public Component {
public:
ObjectCategoryView(PluginEditor* e, std::function<void(bool)> const& dismissCalloutBox)
: list(e, dismissCalloutBox)
{
addAndMakeVisible(list);
auto objectsToShow = getValue<bool>(SettingsFile::getInstance()->getPropertyAsValue("hvcc_mode")) ? ObjectList::heavyObjectList : ObjectList::defaultObjectList;
// make the 2nd category active (which will be after the default category if it exists)
if (objectsToShow.size() > 1) {
// this should always be populated, but just incase we are testing a new blank object list etc
list.showCategory(objectsToShow[1].first);
}
for (auto const& [categoryName, category] : objectsToShow) {
if (categoryName == "Default")
continue;
auto* button = categories.add(new TextButton(categoryName));
button->setConnectedEdges(12);
button->onClick = [this, cName = categoryName] {
list.showCategory(cName);
resized();
};
button->setClickingTogglesState(true);
button->setRadioGroupId(hash("add_menu_category"));
button->setColour(TextButton::textColourOffId, findColour(PlugDataColour::popupMenuTextColourId));
button->setColour(TextButton::textColourOnId, findColour(PlugDataColour::popupMenuTextColourId));
button->setColour(TextButton::buttonColourId, findColour(PlugDataColour::popupMenuBackgroundColourId).contrasting(0.035f));
button->setColour(TextButton::buttonOnColourId, findColour(PlugDataColour::popupMenuBackgroundColourId).contrasting(0.075f));
button->setColour(ComboBox::outlineColourId, Colours::transparentBlack);
addAndMakeVisible(button);
}
if (categories.size() > 0) {
categories.getFirst()->setConnectedEdges(Button::ConnectedOnRight);
categories.getFirst()->setToggleState(true, dontSendNotification);
categories.getLast()->setConnectedEdges(Button::ConnectedOnLeft);
}
resized();
}
void resized() override
{
auto bounds = getLocalBounds();
auto buttonBounds = bounds.removeFromTop(48).reduced(6, 14).translated(4, 0);
auto const buttonWidth = buttonBounds.getWidth() / std::max(1, categories.size());
for (auto* category : categories) {
category->setBounds(buttonBounds.removeFromLeft(buttonWidth).expanded(1, 0));
}
list.setBounds(bounds);
}
private:
ObjectList list;
OwnedArray<TextButton> categories;
};
class AddObjectMenuButton final : public Component {
String const icon;
String const text;
public:
bool toggleState = false;
bool clickingTogglesState = false;
std::function<void()> onClick = [] { };
explicit AddObjectMenuButton(String const& iconStr, String const& textStr = String())
: icon(iconStr)
, text(textStr)
{
setInterceptsMouseClicks(true, false);
setAlwaysOnTop(true);
}
void paint(Graphics& g) override
{
auto b = getLocalBounds().reduced(4, 2);
auto colour = findColour(PlugDataColour::popupMenuTextColourId);
if (isMouseOver()) {
g.setColour(findColour(PlugDataColour::popupMenuActiveBackgroundColourId));
g.fillRoundedRectangle(b.toFloat(), Corners::defaultCornerRadius);
}
if (toggleState) {
colour = findColour(PlugDataColour::toolbarActiveColourId);
}
auto const iconArea = b.removeFromLeft(24).withSizeKeepingCentre(24, 24);
if (text.isNotEmpty()) {
Fonts::drawIcon(g, icon, iconArea.translated(3.0f, 0.0f), colour, 14.0f, true);
b.removeFromLeft(4);
b.removeFromRight(3);
Fonts::drawFittedText(g, text, b, colour, 14.0f);
} else {
Fonts::drawIcon(g, icon, iconArea, colour, 14.0f, true);
}
}
void mouseUp(MouseEvent const& e) override
{
if (clickingTogglesState) {
toggleState = !toggleState;
}
onClick();
repaint();
}
void mouseEnter(MouseEvent const& e) override
{
repaint();
}
void mouseExit(MouseEvent const& e) override
{
repaint();
}
};
class AddObjectMenu final : public Component {
public:
explicit AddObjectMenu(PluginEditor* e)
: objectBrowserButton(Icons::Object, "Show Object Browser")
, pinButton(Icons::Pin)
, editor(e)
, objectList(e, [this](bool const shouldFade) { dismiss(shouldFade); })
, categoriesList(e, [this](bool const shouldFade) { dismiss(shouldFade); })
{
categoriesList.setVisible(true);
addAndMakeVisible(categoriesList);
addAndMakeVisible(objectList);
addAndMakeVisible(objectBrowserButton);
addAndMakeVisible(pinButton);
setSize(515, 300);
objectList.showCategory("Default");
objectBrowserButton.onClick = [this] {
if (currentCalloutBox)
currentCalloutBox->dismiss();
Dialogs::showObjectBrowserDialog(&editor->openedDialog, editor);
};
pinButton.toggleState = SettingsFile::getInstance()->getProperty<bool>("add_object_menu_pinned");
pinButton.clickingTogglesState = true;
pinButton.onClick = [this] {
SettingsFile::getInstance()->setProperty("add_object_menu_pinned", pinButton.toggleState);
};
pinButton.repaint();
}
void resized() override
{
auto bounds = getLocalBounds();
auto buttonsBounds = bounds.removeFromTop(26);
pinButton.setBounds(buttonsBounds.removeFromRight(28));
objectBrowserButton.setBounds(buttonsBounds);
bounds.removeFromTop(6);
objectList.setBounds(bounds.removeFromTop(75));
categoriesList.setBounds(bounds);
}
void dismiss(bool const shouldHide)
{
if (currentCalloutBox) {
// If the panel is pinned, only fade it out
if (pinButton.toggleState) {
animator.animateComponent(currentCalloutBox, currentCalloutBox->getBounds(), shouldHide ? 0.1f : 1.0f, 300, false, 0.0f, 0.0f);
}
// Otherwise, fade the panel on drag start: calling dismiss or setVisible will lead to the drag event getting lost, so we just set alpha instead
// Ditto for calling animator.fadeOut because that will also call setVisible(false)
else if (shouldHide) {
animator.animateComponent(currentCalloutBox, currentCalloutBox->getBounds(), 0.0f, 300, false, 0.0f, 0.0f);
}
// and destroy the panel on mouse-up
else {
currentCalloutBox->dismiss();
}
}
}
static void show(PluginEditor* editor, Rectangle<int> const bounds)
{
auto addObjectMenu = std::make_unique<AddObjectMenu>(editor);
currentCalloutBox = &editor->showCalloutBox(std::move(addObjectMenu), bounds);
}
private:
AddObjectMenuButton objectBrowserButton;
AddObjectMenuButton pinButton;
static inline SafePointer<CallOutBox> currentCalloutBox = nullptr;
PluginEditor* editor;
ObjectList objectList;
ObjectCategoryView categoriesList;
ComponentAnimator animator;
};