Browse Source

Fix possible crash when replacing zyn with another zyn

tags/1.9.6
falkTX 9 years ago
parent
commit
b3e434849a
3 changed files with 45 additions and 27 deletions
  1. +2
    -0
      source/backend/engine/CarlaEngine.cpp
  2. +38
    -27
      source/native-plugins/zynaddsubfx-synth.cpp
  3. +5
    -0
      source/utils/CarlaMutex.hpp

+ 2
- 0
source/backend/engine/CarlaEngine.cpp View File

@@ -995,6 +995,8 @@ bool CarlaEngine::loadFile(const char* const filename)
//nicerName
if (addPlugin(PLUGIN_INTERNAL, nullptr, nicerName, "zynaddsubfx", 0, nullptr))
{
callback(ENGINE_CALLBACK_UI_STATE_CHANGED, curPluginId, 0, 0, 0.0f, nullptr);

if (CarlaPlugin* const plugin = getPlugin(curPluginId))
plugin->setCustomData(CUSTOM_DATA_TYPE_STRING, (extension == "xmz") ? "CarlaAlternateFile1" : "CarlaAlternateFile2", filename, true);
return true;


+ 38
- 27
source/native-plugins/zynaddsubfx-synth.cpp View File

@@ -232,11 +232,12 @@ class ZynAddSubFxInstanceCount
{
public:
ZynAddSubFxInstanceCount()
: fCount(0) {}
: fCount(0),
fMutex() {}

~ZynAddSubFxInstanceCount()
{
CARLA_ASSERT(fCount == 0);
CARLA_SAFE_ASSERT(fCount == 0);
}

void addOne(const NativeHostDescriptor* const host)
@@ -244,6 +245,8 @@ public:
if (fCount++ != 0)
return;

const CarlaMutexLocker cml(fMutex);

CARLA_SAFE_ASSERT(synth == nullptr);
CARLA_SAFE_ASSERT(denormalkillbuf == nullptr);

@@ -264,6 +267,8 @@ public:
if (--fCount != 0)
return;

const CarlaMutexLocker cml(fMutex);

CARLA_SAFE_ASSERT(synth != nullptr);
CARLA_SAFE_ASSERT(denormalkillbuf != nullptr);

@@ -276,6 +281,26 @@ public:
synth = nullptr;
}

void maybeReinit(const NativeHostDescriptor* const host)
{
if (static_cast< int>(host->get_buffer_size(host->handle)) == synth->buffersize &&
static_cast<uint>(host->get_sample_rate(host->handle)) == synth->samplerate)
return;

const CarlaMutexLocker cml(fMutex);

reinit(host);
}

CarlaMutex& getLock() noexcept
{
return fMutex;
}

private:
int fCount;
CarlaMutex fMutex;

void reinit(const NativeHostDescriptor* const host)
{
Master::deleteInstance();
@@ -315,18 +340,6 @@ public:
Master::getInstance();
}

void maybeReinit(const NativeHostDescriptor* const host)
{
if (static_cast< int>(host->get_buffer_size(host->handle)) == synth->buffersize &&
static_cast<uint>(host->get_sample_rate(host->handle)) == synth->samplerate)
return;

reinit(host);
}

private:
int fCount;

CARLA_PREVENT_HEAP_ALLOCATION
CARLA_DECLARE_NON_COPY_CLASS(ZynAddSubFxInstanceCount)
};
@@ -713,9 +726,9 @@ protected:
fMaster->part[0]->loadXMLinstrument(value);
}

pthread_mutex_unlock(&fMaster->mutex);
fMaster->applyparameters(false);

fMaster->applyparameters();
pthread_mutex_unlock(&fMaster->mutex);
}

// -------------------------------------------------------------------
@@ -733,7 +746,9 @@ protected:

void process(float**, float** const outBuffer, const uint32_t frames, const NativeMidiEvent* const midiEvents, const uint32_t midiEventCount) override
{
if (pthread_mutex_trylock(&fMaster->mutex) != 0)
const CarlaMutexTryLocker cmtl(sInstanceCount.getLock());

if (cmtl.wasNotLocked() || pthread_mutex_trylock(&fMaster->mutex) != 0)
{
FloatVectorOperations::clear(outBuffer[0], static_cast<int>(frames));
FloatVectorOperations::clear(outBuffer[1], static_cast<int>(frames));
@@ -936,16 +951,12 @@ private:
for (int i=0; i<NUM_MIDI_PARTS; ++i)
{
fMaster->partonoff(i, 1);

for (int npart=0; npart<NUM_MIDI_PARTS; ++npart)
{
fMaster->part[npart]->SetController(C_filtercutoff, static_cast<int>(fParameters[kParamFilterCutoff]));
fMaster->part[npart]->SetController(C_filterq, static_cast<int>(fParameters[kParamFilterQ]));
fMaster->part[npart]->SetController(C_bandwidth, static_cast<int>(fParameters[kParamBandwidth]));
fMaster->part[npart]->SetController(C_fmamp, static_cast<int>(fParameters[kParamModAmp]));
fMaster->part[npart]->SetController(C_resonance_center, static_cast<int>(fParameters[kParamResCenter]));
fMaster->part[npart]->SetController(C_resonance_bandwidth, static_cast<int>(fParameters[kParamResBandwidth]));
}
fMaster->part[i]->SetController(C_filtercutoff, static_cast<int>(fParameters[kParamFilterCutoff]));
fMaster->part[i]->SetController(C_filterq, static_cast<int>(fParameters[kParamFilterQ]));
fMaster->part[i]->SetController(C_bandwidth, static_cast<int>(fParameters[kParamBandwidth]));
fMaster->part[i]->SetController(C_fmamp, static_cast<int>(fParameters[kParamModAmp]));
fMaster->part[i]->SetController(C_resonance_center, static_cast<int>(fParameters[kParamResCenter]));
fMaster->part[i]->SetController(C_resonance_bandwidth, static_cast<int>(fParameters[kParamResBandwidth]));
}
}



+ 5
- 0
source/utils/CarlaMutex.hpp View File

@@ -228,6 +228,11 @@ public:
return fLocked;
}

bool wasNotLocked() const noexcept
{
return !fLocked;
}

private:
const Mutex& fMutex;
const bool fLocked;


Loading…
Cancel
Save