diff --git a/plugin/Source/Panels.h b/plugin/Source/Panels.h index 65bd3c0..161699e 100644 --- a/plugin/Source/Panels.h +++ b/plugin/Source/Panels.h @@ -143,16 +143,16 @@ public: } else if (e.originalComponent == &h && e.mouseWasClicked() && e.x >= prevButton.getRight() && e.x <= nextButton.getX()) { - auto tables = proc.getWavetableNames(); + auto files = proc.getWavetableFiles(); std::map menus; - for (auto t : tables) + for (auto& f : files) { - auto prefix = t.upToFirstOccurrenceOf (" ", false, false); - auto suffix = t.fromFirstOccurrenceOf (" ", false, false); + auto t = f.getFileNameWithoutExtension(); + auto category = f.getParentDirectory().getFileName(); - menus[prefix].addItem (t, [this, t] + menus[category].addItem (t, [this, t] { if (idx == 0) { @@ -171,7 +171,7 @@ public: juce::PopupMenu m; m.setLookAndFeel (&getLookAndFeel()); - + for (auto itr : menus) m.addSubMenu (itr.first, itr.second); diff --git a/plugin/Source/PluginProcessor.cpp b/plugin/Source/PluginProcessor.cpp index 27bead0..956f6f7 100644 --- a/plugin/Source/PluginProcessor.cpp +++ b/plugin/Source/PluginProcessor.cpp @@ -643,12 +643,15 @@ void WavetableAudioProcessor::reloadWavetables() { auto loadMemory = [&] (const juce::String& name) -> juce::MemoryBlock { - auto file = systemResourceRoot().getChildFile ("Wavetables").getChildFile (name + ".wt2048"); - if (file.existsAsFile()) + auto wtDir = systemResourceRoot().getChildFile ("Wavetables"); + if (wtDir.isDirectory()) { - juce::MemoryBlock mb; - if (file.loadFileAsData (mb)) - return mb; + for (auto& file : wtDir.findChildFiles (juce::File::findFiles, true, name + ".wt2048")) + { + juce::MemoryBlock mb; + if (file.loadFileAsData (mb)) + return mb; + } } return {}; }; @@ -788,15 +791,38 @@ juce::Array WavetableAudioProcessor::getFactoryProgramDirectories() juce::StringArray WavetableAudioProcessor::getWavetableNames() const { juce::StringArray tables; - auto wtDir = systemResourceRoot().getChildFile ("Wavetables"); - if (wtDir.isDirectory()) - for (auto f : wtDir.findChildFiles (juce::File::findFiles, false, "*.wt2048")) - tables.add (f.getFileNameWithoutExtension()); + for (auto& f : getWavetableFiles()) + tables.add (f.getFileNameWithoutExtension()); tables.sortNatural(); return tables; } +juce::Array WavetableAudioProcessor::getWavetableFiles() const +{ + juce::Array files; + auto wtDir = systemResourceRoot().getChildFile ("Wavetables"); + if (wtDir.isDirectory()) + files = wtDir.findChildFiles (juce::File::findFiles, true, "*.wt2048"); + + struct Sorter + { + static int compareElements (const juce::File& a, const juce::File& b) + { + auto categoryCmp = a.getParentDirectory().getFileName() + .compareNatural (b.getParentDirectory().getFileName()); + if (categoryCmp != 0) + return categoryCmp; + return a.getFileNameWithoutExtension() + .compareNatural (b.getFileNameWithoutExtension()); + } + }; + Sorter sorter; + files.sort (sorter); + + return files; +} + //============================================================================== void WavetableAudioProcessor::setupModMatrix() { diff --git a/plugin/Source/PluginProcessor.h b/plugin/Source/PluginProcessor.h index b96eb51..5ef0f1b 100644 --- a/plugin/Source/PluginProcessor.h +++ b/plugin/Source/PluginProcessor.h @@ -56,6 +56,7 @@ public: void incWavetable (int osc, int delta); bool loadUserWavetable (int osc, const juce::File& f, int sz); juce::StringArray getWavetableNames() const; + juce::Array getWavetableFiles() const; void applyEffects (juce::AudioSampleBuffer& buffer); void applyEffect (juce::AudioSampleBuffer& buffer, int fxId);