From c8a79d469337e03fbd9302794d5b521c2dbe56e5 Mon Sep 17 00:00:00 2001 From: Roland Rabien Date: Sun, 27 Aug 2023 07:57:23 -0700 Subject: [PATCH] More UI --- modules/gin | 2 +- plugin/Source/Panels.h | 1 + plugin/Source/PluginEditor.cpp | 1 + plugin/Source/PluginProcessor.cpp | 51 ++++++++++++++++++++++++++++--- plugin/Source/PluginProcessor.h | 2 ++ 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/modules/gin b/modules/gin index 4f32472..8ee85cd 160000 --- a/modules/gin +++ b/modules/gin @@ -1 +1 @@ -Subproject commit 4f3247283ed2288c9e33edd9bbf37d3f4f16bdc9 +Subproject commit 8ee85cdbf9b749ef03ca31ba50ff2ad7706e5bf6 diff --git a/plugin/Source/Panels.h b/plugin/Source/Panels.h index 31b57ef..a0d0496 100644 --- a/plugin/Source/Panels.h +++ b/plugin/Source/Panels.h @@ -39,6 +39,7 @@ public: wt = new gin::WavetableComponent(); wt->setName ("wt"); wt->setWavetables (idx == 0 ? &proc.osc1Tables : &proc.osc2Tables); + wt->onFileDrop = [this] (const juce::File& f) { proc.loadUserWavetable (idx, f); }; addControl (wt, 5, 0, 3, 2); timer.startTimerHz (60); diff --git a/plugin/Source/PluginEditor.cpp b/plugin/Source/PluginEditor.cpp index aebcf17..5863181 100644 --- a/plugin/Source/PluginEditor.cpp +++ b/plugin/Source/PluginEditor.cpp @@ -49,4 +49,5 @@ void WavetableAudioProcessorEditor::resized() rc.removeFromTop (40); editor.setBounds (rc); + patchBrowser.setBounds (rc); } diff --git a/plugin/Source/PluginProcessor.cpp b/plugin/Source/PluginProcessor.cpp index 481d047..84aa2a1 100644 --- a/plugin/Source/PluginProcessor.cpp +++ b/plugin/Source/PluginProcessor.cpp @@ -336,16 +336,21 @@ void WavetableAudioProcessor::ReverbParams::setup (WavetableAudioProcessor& p) mix = p.addExtParam ("rvbMix", "Mix", "", "", {0.0f, 1.0f, 0.0f, 1.0f}, 0.0f, 0.0f); } -static void loadWaveTable (juce::OwnedArray& table, double sr, const juce::MemoryBlock& wav) +static bool loadWaveTable (juce::OwnedArray& table, double sr, const juce::MemoryBlock& wav) { auto is = new juce::MemoryInputStream (wav, false); if (auto reader = std::unique_ptr (juce::WavAudioFormat().createReaderFor (is, true))) { - juce::AudioSampleBuffer buf (1, int (reader->lengthInSamples)); - reader->read (&buf, 0, int (reader->lengthInSamples), 0, true, false); + if (auto sz = gin::getWavetableSize (wav); sz > 0) + { + juce::AudioSampleBuffer buf (1, int (reader->lengthInSamples)); + reader->read (&buf, 0, int (reader->lengthInSamples), 0, true, false); - loadWavetables (table, sr, buf, reader->sampleRate, gin::getWavetableSize (wav)); + loadWavetables (table, sr, buf, reader->sampleRate, sz); + return true; + } } + return false; } //============================================================================== @@ -430,13 +435,27 @@ void WavetableAudioProcessor::reloadWavetables() if (sr == 0) return; - if (auto mb = loadMemory (osc1Table.toString()); mb.getSize() > 0) + if (userTable1.getSize() > 0) + { + if (shouldLoad (0, osc1Table.toString(), sr)) + loadWaveTable (osc1Tables, sr, userTable1); + } + else if (auto mb = loadMemory (osc1Table.toString()); mb.getSize() > 0) + { if (shouldLoad (0, osc1Table.toString(), sr)) loadWaveTable (osc1Tables, sr, mb); + } + if (userTable2.getSize() > 0) + { + if (shouldLoad (0, osc2Table.toString(), sr)) + loadWaveTable (osc2Tables, sr, userTable2); + } if (auto mb = loadMemory (osc2Table.toString()); mb.getSize() > 0) + { if (shouldLoad (1, osc2Table.toString(), sr)) loadWaveTable (osc2Tables, sr, mb); + } } void WavetableAudioProcessor::incWavetable (int osc, int delta) @@ -461,6 +480,22 @@ void WavetableAudioProcessor::incWavetable (int osc, int delta) reloadWavetables(); } +void WavetableAudioProcessor::loadUserWavetable (int osc, const juce::File f) +{ + auto& table = osc == 0 ? osc1Tables : osc2Tables; + auto& mb = osc == 0 ? userTable1 : userTable2; + auto& name = osc == 0 ? osc1Table : osc2Table; + + juce::MemoryBlock raw; + f.loadFileAsData (raw); + + if (loadWaveTable (table, gin::Processor::getSampleRate(), raw)) + { + mb = raw; + name = f.getFileNameWithoutExtension(); + } +} + //============================================================================== void WavetableAudioProcessor::stateUpdated() { @@ -469,6 +504,9 @@ void WavetableAudioProcessor::stateUpdated() osc1Table = state.getProperty ("wt1"); osc2Table = state.getProperty ("wt2"); + userTable1.fromBase64Encoding (state.getProperty ("wt1Data").toString()); + userTable2.fromBase64Encoding (state.getProperty ("wt2Data").toString()); + reloadWavetables(); } @@ -478,6 +516,9 @@ void WavetableAudioProcessor::updateState() state.setProperty ("wt1", osc1Table, nullptr); state.setProperty ("wt2", osc2Table, nullptr); + + state.setProperty ("wt1Data", userTable1.toBase64Encoding(), nullptr); + state.setProperty ("wt2Data", userTable2.toBase64Encoding(), nullptr); } //============================================================================== diff --git a/plugin/Source/PluginProcessor.h b/plugin/Source/PluginProcessor.h index bbf8c3c..5fb72bc 100644 --- a/plugin/Source/PluginProcessor.h +++ b/plugin/Source/PluginProcessor.h @@ -39,6 +39,7 @@ public: void reloadWavetables(); void incWavetable (int osc, int delta); + void loadUserWavetable (int osc, const juce::File f); void applyEffects (juce::AudioSampleBuffer& buffer); @@ -256,6 +257,7 @@ public: gin::BandLimitedLookupTables analogTables; juce::Value osc1Table, osc2Table; + juce::MemoryBlock userTable1, userTable2; //============================================================================== gin::ModMatrix modMatrix;