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

Work around a Renoise Re-Entrant Param Difference #88

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src-juce/AWConsolidatedEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,7 +687,7 @@ struct ParamDisp : juce::Component, juce::TextEditor::Listener
{
bool go{false};
{
std::lock_guard<std::mutex> g(editor->processor.displayProcessorMutex);
LOCK(editor->processor.displayProcessorMutex);
go = editor->processor.awDisplayProcessor->canConvertParameterTextToValue(index);
}

Expand Down Expand Up @@ -723,7 +723,7 @@ struct ParamDisp : juce::Component, juce::TextEditor::Listener
float f{0};
bool worked{false};
{
std::lock_guard<std::mutex> g(editor->processor.displayProcessorMutex);
LOCK(editor->processor.displayProcessorMutex);
worked = editor->processor.awDisplayProcessor->parameterTextToValue(
index, ed.getText().toRawUTF8(), f);
}
Expand Down
27 changes: 20 additions & 7 deletions src-juce/AWConsolidatedProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ AWConsolidatedAudioProcessor::AWConsolidatedAudioProcessor()
fxParams[i] = new AWParam(juce::ParameterID(std::string("ctrl_") + std::to_string(i), 1),
"Name", juce::NormalisableRange<float>(0.f, 1.f), 0.f);
fxParams[i]->getTextHandler = [i, this](auto f, auto iv) {
std::lock_guard<std::mutex> g(this->displayProcessorMutex);
LOCK(this->displayProcessorMutex);
if (this->awDisplayProcessor && i < this->nProcessorParams)
{
for (int id = 0; id < this->nProcessorParams; ++id)
Expand All @@ -62,7 +62,7 @@ AWConsolidatedAudioProcessor::AWConsolidatedAudioProcessor()
}
};
fxParams[i]->getTextToValue = [i, this](auto s) {
std::lock_guard<std::mutex> g(this->displayProcessorMutex);
LOCK(this->displayProcessorMutex);
if (this->awDisplayProcessor && i < this->nProcessorParams)
{
float rv = 0.f;
Expand Down Expand Up @@ -229,18 +229,26 @@ void AWConsolidatedAudioProcessor::setAWProcessorTo(int registryIndex, bool init

if (initDisplay)
{
std::lock_guard<std::mutex> g(displayProcessorMutex);
LOCK(displayProcessorMutex);
awDisplayProcessor = rg.generator();
awDisplayProcessor->setSampleRate(getSampleRate());
}

setupParamDisplaysFromDisplayProcessor(registryIndex);
if (initDisplay)
{
setupParamDisplaysFromDisplayProcessor(registryIndex);
}
}

void AWConsolidatedAudioProcessor::setupParamDisplaysFromDisplayProcessor(int index)
{
// Renoise re-enters to get text when you set value notifying host
// so don't setvalue notifying host under the lock.
// See https://forum.renoise.com/t/macos-crash-with-airwindows-vst-when-changing-presets/72288/11
std::array<float, nAWParams> setParamsTo{};

{
std::lock_guard<std::mutex> g(displayProcessorMutex);
LOCK(displayProcessorMutex);

auto rg = AirwinRegistry::registry[index];

Expand All @@ -250,18 +258,23 @@ void AWConsolidatedAudioProcessor::setupParamDisplaysFromDisplayProcessor(int in
char txt[kVstMaxParamStrLen];
awDisplayProcessor->getParameterName(i, txt);
fxParams[i]->mutableName = txt;
fxParams[i]->setValueNotifyingHost(awDisplayProcessor->getParameter(i));
setParamsTo[i] = awDisplayProcessor->getParameter(i);
defaultValues[i] = awDisplayProcessor->getParameter(i);
active[i] = true;
}
for (int i = rg.nParams; i < nAWParams; ++i)
{
fxParams[i]->mutableName = "-";
fxParams[i]->setValueNotifyingHost(0.f);
setParamsTo[i] = 0.f;
active[i] = false;
}
}

for (int i=0; i<nAWParams; ++i)
{
fxParams[i]->setValueNotifyingHost(setParamsTo[i]);
}

updateHostDisplay(juce::AudioProcessor::ChangeDetails().withParameterInfoChanged(true));
rebuildUI = true;
}
Expand Down
24 changes: 23 additions & 1 deletion src-juce/AWConsolidatedProcessor.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,28 @@
#include <execinfo.h>
#endif

#if DEBUG_LOCK
struct LP {
std::string st;
int ln;
LP(const std::string &s, int l) : st(s), ln(l) {
std::cout << "LP LOCK " << st << ":" << ln << std::endl;
}

~LP() {
std::cout << "LP UNLOCK " << st << ":" << ln << std::endl;
}
};

#define LOCK(x) \
std::cout << __FILE__ << ":" << __LINE__ << " Locking " << #x << std::endl; \
LP lpCheck(__FILE__, __LINE__); \
std::lock_guard<std::mutex> g(x); \
std::cout << __FILE__ << ":" << __LINE__ << " Lock Garnerd " << #x << std::endl;
#else
#define LOCK(x) std::lock_guard<std::mutex> g(x);
#endif

template <typename T, int Capacity = 4096> class LockFreeQueue
{
public:
Expand Down Expand Up @@ -110,7 +132,7 @@ class AWConsolidatedAudioProcessor : public juce::AudioProcessor,
{
auto &rg = AirwinRegistry::registry[index];
{
std::lock_guard<std::mutex> g(displayProcessorMutex);
LOCK(displayProcessorMutex);
awDisplayProcessor = rg.generator();
awDisplayProcessor->setSampleRate(getSampleRate());
}
Expand Down
Loading