Skip to content

Commit 53778fa

Browse files
committed
List LV2 plugs in categories with submenus
1 parent 821480e commit 53778fa

File tree

5 files changed

+53
-15
lines changed

5 files changed

+53
-15
lines changed

Source/GuitarixEditor.cpp

+34-3
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,32 @@ void GuitarixEditor::createPluginEditors(bool l, bool r, bool s)
244244
if(s) ed_s.createPluginEditors();
245245
}
246246

247+
bool GuitarixEditor::cat_match(std::string cat_in, std::vector<std::string> to_match) {
248+
return std::any_of(to_match.begin(), to_match.end(),
249+
[&cat_in](const auto& s){ return cat_in.find(s) != std::string::npos; });
250+
}
251+
252+
int GuitarixEditor::get_category(std::string cat_in) {
253+
std::vector<std::string> check = {"Delay", "Reverb", "Echo"};
254+
if (cat_match(cat_in, check)) return 0;
255+
check.clear();
256+
check.assign( {"Distortion", "Waveshaper", "Amplifier" } );
257+
if (cat_match(cat_in, check)) return 1;
258+
check.clear();
259+
check.assign( {"Dynamics", "Compressor", "Envelope", "Expander", "Gate", "Limiter"} );
260+
if (cat_match(cat_in, check)) return 2;
261+
check.clear();
262+
check.assign( {"Filter", "Allpass", "Bandpass", "Comb", "EQ", "Highpass", "Lowpass" } );
263+
if (cat_match(cat_in, check)) return 3;
264+
check.clear();
265+
check.assign( {"Generator", "Constant", "Instrument", "Oscillator" } );
266+
if (cat_match(cat_in, check)) return 4;
267+
check.clear();
268+
check.assign( {"Modulator", "Chorus", "Flanger", "Phaser", "Spatial", "Spectral", "Pitch" } );
269+
if (cat_match(cat_in, check)) return 5;
270+
return 6;
271+
}
272+
247273
void GuitarixEditor::buttonClicked(juce::Button * b)
248274
{
249275
if (b == &monoButton)
@@ -294,8 +320,7 @@ void GuitarixEditor::buttonClicked(juce::Button * b)
294320
"\n \n";
295321

296322
juce::AlertWindow alertWindow("About Guitarix.vst",
297-
txt,
298-
AlertWindow::InfoIcon);
323+
txt, AlertWindow::InfoIcon);
299324
alertWindow.addButton("Ok", 0);
300325
alertWindow.setUsingNativeTitleBar(true);
301326

@@ -305,6 +330,9 @@ void GuitarixEditor::buttonClicked(juce::Button * b)
305330
on_online_preset();
306331
}
307332
else if (b == &pluginButton) {
333+
const char* categories[] = {"Delay", "Distortion","Dynamics","Filter","Generator","Modulator","Utility"};
334+
int cl = sizeof(categories) / sizeof(categories[0]);
335+
PopupMenu item[7];
308336
PopupMenu menu;
309337
static int l = 0;
310338
if (!l) {
@@ -317,11 +345,14 @@ void GuitarixEditor::buttonClicked(juce::Button * b)
317345
if ((*v)->is_lv2) {
318346
bool enabled = (*v)->active;
319347
std::string s = (*v)->Name;
320-
menu.addItem (i, juce::String(s), true, enabled);
348+
item[get_category((*v)->ladspa_category)].addItem (i, juce::String(s), true, enabled);
321349
}
322350
i++;
323351
//fprintf(stderr, "%s %s\n", ((*v)->Name).c_str(),((*v)->category.c_str()));
324352
}
353+
for (int i = 0; i < cl; i++) {
354+
menu.addSubMenu(categories[i], item[i]);
355+
}
325356
menu.showMenuAsync (PopupMenu::Options()
326357
.withTargetComponent(&pluginButton)
327358
.withMaximumNumColumns(1),

Source/GuitarixEditor.h

+2
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,8 @@ class GuitarixEditor : public juce::AudioProcessorEditor, public juce::Button::L
196196
void on_preset_select();
197197
void on_online_preset();
198198
static void loadLV2PlugCallback(int i, GuitarixEditor* ge);
199+
bool cat_match(std::string cat_in, std::vector<std::string> to_match);
200+
int get_category(std::string cat_in);
199201
void downloadPreset(std::string uri);
200202
void read_online_preset_menu();
201203
static void handleOnlineMenu(int choice, GuitarixEditor* ge);

Source/PluginEditor.cpp

+14-10
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ void cat2color(const char* cat, juce::Colour &col)
4848

4949
//==============================================================================
5050
PluginEditor::PluginEditor(MachineEditor* ed, const char* id, const char* cat, PluginSelector *ps) :
51-
ed(ed), pid(id), ps(ps), cat(cat), lastDirectory(juce::File::getSpecialLocation(juce::File::userMusicDirectory))
51+
ed(ed), pid(id), ps(ps), cat(cat),
52+
lastIRDirectory(juce::File::getSpecialLocation(juce::File::userMusicDirectory)),
53+
lastNAMDirectory(juce::File::getSpecialLocation(juce::File::userMusicDirectory))
5254
{
5355
cat2color(cat, col);
5456
col = col.withAlpha((uint8)30);
@@ -402,8 +404,10 @@ void PluginEditor::set_nam_load_button_text(const std::string& attr, bool set)
402404

403405
auto set_nam_filename = [=](juce::String s)
404406
{ button->setButtonText(s); };
405-
set_nam_filename(juce::File(juce::String(
406-
dynamic_cast<gx_engine::StringParameter*>(p)->getString().get_value())).getFileNameWithoutExtension());
407+
juce::File namFile = juce::File(juce::String(
408+
dynamic_cast<gx_engine::StringParameter*>(p)->getString().get_value()));
409+
this->lastNAMDirectory = namFile.getParentDirectory();
410+
set_nam_filename(namFile.getFileNameWithoutExtension());
407411

408412
}
409413
}
@@ -425,7 +429,7 @@ void PluginEditor::set_ir_load_button_text(const std::string& attr, bool set)
425429
gx_engine::GxJConvSettings j = dynamic_cast<gx_engine::JConvParameter*>(p)->get_value();
426430
std::string fdir = j.getIRDir();
427431
if (is_factory_IR(fdir)) return;
428-
if (!fdir.empty()) lastDirectory = juce::File(fdir);
432+
if (!fdir.empty()) lastIRDirectory = juce::File(fdir);
429433
std::string fname = j.getIRFile();
430434
if (!fname.empty()) button->setButtonText(juce::String(fname));
431435
juce::Component *c = findChildByID(this, parid.c_str());
@@ -540,8 +544,8 @@ void PluginEditor::load_NAM(const std::string& attr, juce::Button* button, juce:
540544
}
541545

542546
void PluginEditor::open_nam_file_browser(juce::Button* button, const std::string& id) {
543-
auto fc = new juce::FileChooser ("Choose NAM file to load...", lastDirectory.isDirectory() ?
544-
lastDirectory : juce::File::getSpecialLocation(juce::File::userMusicDirectory), "*.nam", false);
547+
auto fc = new juce::FileChooser ("Choose NAM file to load...", lastNAMDirectory.isDirectory() ?
548+
lastNAMDirectory : juce::File::getSpecialLocation(juce::File::userMusicDirectory), "*.nam", false);
545549

546550
fc->launchAsync (juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
547551
[this, id, button, fc] (const juce::FileChooser& chooser) {
@@ -551,7 +555,7 @@ void PluginEditor::open_nam_file_browser(juce::Button* button, const std::string
551555
: result.toString (false)) ;
552556

553557
if(chosen.isNotEmpty()) {
554-
this->lastDirectory = result.getLocalFile().getParentDirectory();
558+
this->lastNAMDirectory = result.getLocalFile().getParentDirectory();
555559
this->load_NAM(id, button, chosen);
556560
}
557561
button->setToggleState(false, juce::dontSendNotification);
@@ -581,8 +585,8 @@ void PluginEditor::load_IR(const std::string& attr, juce::Button* button, juce::
581585
}
582586

583587
void PluginEditor::open_file_browser(juce::Button* button, const std::string& id) {
584-
auto fc = new juce::FileChooser ("Choose IR file to open...", lastDirectory.isDirectory() ?
585-
lastDirectory : juce::File::getSpecialLocation(juce::File::userMusicDirectory), "*.wav", false);
588+
auto fc = new juce::FileChooser ("Choose IR file to open...", lastIRDirectory.isDirectory() ?
589+
lastIRDirectory : juce::File::getSpecialLocation(juce::File::userMusicDirectory), "*.wav", false);
586590

587591
fc->launchAsync (juce::FileBrowserComponent::openMode | juce::FileBrowserComponent::canSelectFiles,
588592
[this, id, button, fc] (const juce::FileChooser& chooser) {
@@ -592,7 +596,7 @@ void PluginEditor::open_file_browser(juce::Button* button, const std::string& id
592596
: result.toString (false)) ;
593597

594598
if(chosen.isNotEmpty()) {
595-
this->lastDirectory = result.getLocalFile().getParentDirectory();
599+
this->lastIRDirectory = result.getLocalFile().getParentDirectory();
596600
this->load_IR(id, button, chosen);
597601
}
598602
button->setToggleState(false, juce::dontSendNotification);

Source/PluginEditor.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ class PluginEditor: public juce::Component,
136136
bool is_factory_IR(const std::string& dir);
137137
void load_IR(const std::string& attr, juce::Button* button, juce::String fname);
138138
void set_ir_load_button_text(const std::string& attr, bool set);
139-
juce::File lastDirectory;
139+
juce::File lastIRDirectory;
140+
juce::File lastNAMDirectory;
140141
void open_nam_file_browser(juce::Button* button, const std::string& id);
141142
void load_NAM(const std::string& attr, juce::Button* button, juce::String fname);
142143
void set_nam_load_button_text(const std::string& attr, bool set);

0 commit comments

Comments
 (0)