-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improving automation stability for forwarded parameters
- Loading branch information
1 parent
7db24bf
commit c829ad5
Showing
5 changed files
with
182 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
#include "UnitTests.h" | ||
#include "processors/chain/ProcessorChainActionHelper.h" | ||
#include "state/ParamForwardManager.h" | ||
|
||
class ForwardingParamStabilityTest : public UnitTest | ||
{ | ||
public: | ||
ForwardingParamStabilityTest() | ||
: UnitTest ("Forwarding Parameter Stability Test") | ||
{ | ||
} | ||
|
||
bool addProcessor (ProcessorChain& chain, UndoManager* um) | ||
{ | ||
// get random processor | ||
auto& storeMap = ProcessorStore::getStoreMap(); | ||
auto storeIter = storeMap.begin(); | ||
int storeIndex = rand.nextInt ((int) storeMap.size()); | ||
std::advance (storeIter, storeIndex); | ||
|
||
auto& actionHelper = chain.getActionHelper(); | ||
actionHelper.addProcessor (storeIter->second.factory (um)); | ||
|
||
return true; | ||
} | ||
|
||
bool removeProcessor (ProcessorChain& chain) | ||
{ | ||
const auto& procs = chain.getProcessors(); | ||
if (procs.isEmpty()) | ||
return false; | ||
|
||
auto procIndexToRemove = rand.nextInt (procs.size()); | ||
auto* procToRemove = procs[procIndexToRemove]; | ||
|
||
auto& actionHelper = chain.getActionHelper(); | ||
actionHelper.removeProcessor (procToRemove); | ||
|
||
return true; | ||
} | ||
|
||
using ParamNames = std::array<std::string, 500>; | ||
auto runPlugin() | ||
{ | ||
BYOD plugin; | ||
auto* undoManager = plugin.getVTS().undoManager; | ||
auto& procChain = plugin.getProcChain(); | ||
|
||
struct Action | ||
{ | ||
String name; | ||
std::function<bool()> action; | ||
}; | ||
|
||
std::vector<Action> actions { | ||
{ "Add Processor", [&] | ||
{ return addProcessor (procChain, undoManager); } }, | ||
{ "Remove Processor", [&] | ||
{ return removeProcessor (procChain); } }, | ||
}; | ||
|
||
for (int count = 0; count < 100;) | ||
{ | ||
auto& action = actions[rand.nextInt ((int) actions.size())]; | ||
if (action.action()) | ||
{ | ||
int timeUntilNextAction = rand.nextInt ({ 5, 500 }); | ||
juce::MessageManager::getInstance()->runDispatchLoopUntil (timeUntilNextAction); | ||
count++; | ||
} | ||
} | ||
|
||
auto& forwardingParams = plugin.getParamForwarder().getForwardedParameters(); | ||
ParamNames paramNames {}; | ||
for (auto [idx, param] : chowdsp::enumerate (forwardingParams)) | ||
{ | ||
if (auto* forwardedParam = param->getParam()) | ||
paramNames[idx] = forwardedParam->getName (1024).toStdString(); | ||
} | ||
|
||
juce::MemoryBlock state; | ||
plugin.getStateInformation (state); | ||
|
||
return std::make_tuple (paramNames, state); | ||
} | ||
|
||
void testPlugin (const ParamNames& paramNames, const juce::MemoryBlock& state) | ||
{ | ||
BYOD plugin; | ||
plugin.setStateInformation (state.getData(), (int) state.getSize()); | ||
|
||
auto& forwardingParams = plugin.getParamForwarder().getForwardedParameters(); | ||
for (auto [idx, param] : chowdsp::enumerate (forwardingParams)) | ||
{ | ||
if (auto* forwardedParam = param->getParam()) | ||
expectEquals (forwardedParam->getName (1024).toStdString(), | ||
paramNames[idx], | ||
"Parameter name mismatch"); | ||
else | ||
expectEquals (std::string {}, | ||
paramNames[idx], | ||
"Parameter name mismatch"); | ||
} | ||
} | ||
|
||
void runTest() override | ||
{ | ||
rand = Random { 1234 }; // getRandom(); | ||
|
||
beginTest ("Forwarding Parameter Stability Test"); | ||
const auto [paramNames, state] = runPlugin(); | ||
testPlugin (paramNames, state); | ||
} | ||
|
||
Random rand; | ||
}; | ||
|
||
static ForwardingParamStabilityTest forwardingParamStabilityTest; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters