From bda618835261fae06e918c97778c158ee3e30793 Mon Sep 17 00:00:00 2001 From: Roland Rabien Date: Fri, 25 Aug 2023 15:11:46 -0700 Subject: [PATCH] Add menu for selecting wavetable --- modules/gin | 2 +- plugin/Source/Panels.h | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/modules/gin b/modules/gin index 39aa9c9..3c168aa 160000 --- a/modules/gin +++ b/modules/gin @@ -1 +1 @@ -Subproject commit 39aa9c9bf5fc2427e41fad2f01ce3796be32172a +Subproject commit 3c168aa48ef18b5fe7f4a671a91e299f9ec1e32c diff --git a/plugin/Source/Panels.h b/plugin/Source/Panels.h index 3a2a786..2038257 100644 --- a/plugin/Source/Panels.h +++ b/plugin/Source/Panels.h @@ -51,6 +51,7 @@ public: auto& h = getHeader(); h.addAndMakeVisible (nextButton); h.addAndMakeVisible (prevButton); + h.addMouseListener (this, false); nextButton.onClick = [this] { proc.incWavetable (idx, +1); }; prevButton.onClick = [this] { proc.incWavetable (idx, -1); }; } @@ -63,6 +64,44 @@ public: proc.osc2Table.removeListener (this); } + void mouseUp (const juce::MouseEvent& e) override + { + auto& h = getHeader(); + if (e.originalComponent == &h && e.mouseWasClicked()) + { + juce::StringArray tables; + for (auto i = 0; i < BinaryData::namedResourceListSize; i++) + if (juce::String (BinaryData::originalFilenames[i]).endsWith (".wav")) + tables.add (juce::String (BinaryData::originalFilenames[i]).upToLastOccurrenceOf (".wav", false, false)); + + tables.sortNatural(); + + std::map menus; + + for (auto t : tables) + { + auto prefix = t.upToFirstOccurrenceOf (" ", false, false); + auto suffix = t.fromFirstOccurrenceOf (" ", false, false); + + menus[prefix].addItem (t, [this, t] + { + if (idx == 0) + proc.osc1Table = t; + else + proc.osc2Table = t; + + proc.reloadWavetables(); + }); + } + + juce::PopupMenu m; + for (auto itr : menus) + m.addSubMenu (itr.first, itr.second); + + m.showMenuAsync ({}); + } + } + void resized() override { gin::ParamBox::resized();