Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preset discovery and processor factory optimization #317

Merged
merged 13 commits into from
Jul 7, 2023
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ if(BYOD_BUILD_CLAP)
CLAP_FEATURES audio-effect distortion
CLAP_PROCESS_EVENTS_RESOLUTION_SAMPLES 64
CLAP_USE_JUCE_PARAMETER_RANGES DISCRETE
CLAP_SUPPORTS_CUSTOM_FACTORY 1
)
endif()

Expand Down
2 changes: 1 addition & 1 deletion modules/chowdsp_wdf
24 changes: 24 additions & 0 deletions src/BYOD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,3 +121,27 @@ AudioProcessor* JUCE_CALLTYPE createPluginFilter()
{
return new BYOD();
}

#if HAS_CLAP_JUCE_EXTENSIONS
#include "state/presets/PresetDiscovery.h"

bool BYOD::presetLoadFromLocation (uint32_t location_kind, const char* location, const char* load_key) noexcept
{
return preset_discovery::presetLoadFromLocation (*presetManager, location_kind, location, load_key);
}

static const clap_preset_discovery_factory byod_preset_discovery_factory {
.count = preset_discovery::count,
.get_descriptor = preset_discovery::get_descriptor,
.create = preset_discovery::create,
};

const void* JUCE_CALLTYPE clapJuceExtensionCustomFactory (const char* factory_id)
{
if (strcmp (factory_id, CLAP_PRESET_DISCOVERY_FACTORY_ID) == 0)
{
return &byod_preset_discovery_factory;
}
return nullptr;
}
#endif
8 changes: 8 additions & 0 deletions src/BYOD.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ class BYOD : public chowdsp::PluginBase<BYOD>
auto& getUndoManager() { return undoManager; }
auto& getStateManager() { return *stateManager; }

#if HAS_CLAP_JUCE_EXTENSIONS
bool supportsPresetLoad() const noexcept override
{
return true;
}
bool presetLoadFromLocation (uint32_t location_kind, const char* location, const char* load_key) noexcept override;
#endif

private:
void processBypassDelay (AudioBuffer<float>& buffer);
void updateSampleLatency (int latencySamples);
Expand Down
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ target_sources(BYOD PRIVATE
state/ParamForwardManager.cpp
state/presets/PresetInfoHelpers.cpp
state/presets/PresetManager.cpp
state/presets/PresetDiscovery.cpp
state/presets/PresetsServerSyncManager.cpp
state/presets/PresetsServerUserManager.cpp
state/presets/PresetsServerCommunication.cpp
Expand Down
1 change: 1 addition & 0 deletions src/headless/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ target_sources(BYOD_headless PRIVATE
tests/PreBufferTest.cpp
tests/PresetsTest.cpp
tests/PresetSearchTest.cpp
tests/ProcessorStoreInfoTest.cpp
tests/RAMUsageTest.cpp
tests/SilenceTest.cpp
tests/StereoTest.cpp
Expand Down
2 changes: 1 addition & 1 deletion src/headless/GuitarMLFilterDesigner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void GuitarMLFilterDesigner::generateFiles ([[maybe_unused]] const ArgumentList&
noiseGenerator.setSeed (123);
noiseGenerator.setNoiseType (chowdsp::Noise<float>::NoiseType::Normal);

const auto factory = ProcessorStore::getStoreMap().at ("GuitarML");
const auto factory = ProcessorStore::getStoreMap().at ("GuitarML").factory;
const auto processFile = [&factory,
&saveLoadHelper,
&noiseGenerator] (const juce::String& filePath, double sampleRate)
Expand Down
2 changes: 1 addition & 1 deletion src/headless/PresetSaveLoadTime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ void setUpInitialProcChain (ProcessorChain& procChain, ProcessorChainActionHelpe
int storeIndex = rand.nextInt ((int) storeMap.size());
std::advance (storeIter, storeIndex);

actionHelper.addProcessor (storeIter->second (um));
actionHelper.addProcessor (storeIter->second.factory (um));
auto* newProc = procChain.getProcessors().getLast();
actionHelper.addConnection ({ prevProc, 0, newProc, 0 });

Expand Down
4 changes: 2 additions & 2 deletions src/headless/tests/BadModulationTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ class BadModulationTest : public UnitTest
void runTest() override
{
StringArray processorsWithNoModulation {};
for (auto [name, factory] : ProcessorStore::getStoreMap())
for (auto [name, storeEntry] : ProcessorStore::getStoreMap())
{
const auto proc = factory (nullptr);
const auto proc = storeEntry.factory (nullptr);

bool hasModulationInputs = false;
for (int i = 0; i < proc->getNumInputs(); ++i)
Expand Down
25 changes: 25 additions & 0 deletions src/headless/tests/ProcessorStoreInfoTest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#include "processors/ProcessorStore.h"

class ProcessorStoreInfoTest : public UnitTest
{
public:
ProcessorStoreInfoTest()
: UnitTest ("Processor Store Info Test")
{
}

void runTest() override
{
for (const auto& [name, storeEntry] : ProcessorStore::getStoreMap())
{
const auto proc = storeEntry.factory (nullptr);
beginTest ("Checking processor info for: " + name);
expectEquals (proc->getName(), name, "Processor name is incorrect!");
expectEquals (proc->getProcessorType(), storeEntry.info.type, "Processor type is incorrect!");
expectEquals (proc->getNumInputs(), storeEntry.info.numInputs, "Processor # inputs is incorrect!");
expectEquals (proc->getNumOutputs(), storeEntry.info.numOutputs, "Processor # outputs is incorrect!");
}
}
};

static ProcessorStoreInfoTest processorStoreInfoTest;
12 changes: 6 additions & 6 deletions src/headless/tests/StereoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class StereoTest : public UnitTest

plugin.prepareToPlay (sampleRate, blockSize);

auto& splitterFactory = ProcessorStore::getStoreMap().at ("Stereo Splitter");
auto& mergerFactory = ProcessorStore::getStoreMap().at ("Stereo Merger");
auto& splitterFactory = ProcessorStore::getStoreMap().at ("Stereo Splitter").factory;
auto& mergerFactory = ProcessorStore::getStoreMap().at ("Stereo Merger").factory;

actionHelper.addProcessor (splitterFactory (undoManager));
actionHelper.addProcessor (mergerFactory (undoManager));
Expand Down Expand Up @@ -69,8 +69,8 @@ class StereoTest : public UnitTest

plugin.prepareToPlay (sampleRate, blockSize);

auto& splitterFactory = ProcessorStore::getStoreMap().at ("Stereo Splitter");
auto& mergerFactory = ProcessorStore::getStoreMap().at ("Stereo Merger");
auto& splitterFactory = ProcessorStore::getStoreMap().at ("Stereo Splitter").factory;
auto& mergerFactory = ProcessorStore::getStoreMap().at ("Stereo Merger").factory;

actionHelper.addProcessor (splitterFactory (undoManager));
actionHelper.addProcessor (mergerFactory (undoManager));
Expand Down Expand Up @@ -125,7 +125,7 @@ class StereoTest : public UnitTest

plugin.prepareToPlay (sampleRate, blockSize);

auto& splitterFactory = ProcessorStore::getStoreMap().at ("Stereo Splitter");
auto& splitterFactory = ProcessorStore::getStoreMap().at ("Stereo Splitter").factory;
actionHelper.addProcessor (splitterFactory (undoManager));

auto* input = &chain.getInputProcessor();
Expand Down Expand Up @@ -165,7 +165,7 @@ class StereoTest : public UnitTest

plugin.prepareToPlay (sampleRate, blockSize);

auto& splitterFactory = ProcessorStore::getStoreMap().at ("Stereo Splitter");
auto& splitterFactory = ProcessorStore::getStoreMap().at ("Stereo Splitter").factory;
actionHelper.addProcessor (splitterFactory (undoManager));

auto* input = &chain.getInputProcessor();
Expand Down
2 changes: 1 addition & 1 deletion src/headless/tests/UndoRedoTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class UndoRedoTest : public UnitTest
std::advance (storeIter, storeIndex);

auto& actionHelper = chain.getActionHelper();
actionHelper.addProcessor (storeIter->second (um));
actionHelper.addProcessor (storeIter->second.factory (um));

return true;
}
Expand Down
4 changes: 2 additions & 2 deletions src/headless/tests/UnitTests.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

static inline void runTestForAllProcessors (UnitTest* ut, const std::function<void (BaseProcessor*)>& testFunc, const StringArray& procsToSkip = {})
{
for (auto [name, factory] : ProcessorStore::getStoreMap())
for (auto [name, storeEntry] : ProcessorStore::getStoreMap())
{
if (procsToSkip.contains (name))
{
std::cout << "Skipping " << ut->getName() << " for processor: " << name << std::endl;
continue;
}

auto proc = factory (nullptr);
auto proc = storeEntry.factory (nullptr);
ut->beginTest (proc->getName() + " Test");
testFunc (proc.get());
proc->freeInternalMemory();
Expand Down
Loading