diff --git a/Source/PS_Source/StretchSource.cpp b/Source/PS_Source/StretchSource.cpp index bc29199..289fab1 100644 --- a/Source/PS_Source/StretchSource.cpp +++ b/Source/PS_Source/StretchSource.cpp @@ -134,9 +134,12 @@ void StretchAudioSource::setMainVolume(double decibels) { if (decibels == m_main_volume) return; - ScopedLock locker(m_cs); - m_main_volume = jlimit(-144.0, 12.0, decibels); - ++m_param_change_count; + if (m_cs.tryEnter()) + { + m_main_volume = jlimit(-144.0, 12.0, decibels); + ++m_param_change_count; + m_cs.exit(); + } } void StretchAudioSource::setLoopXFadeLength(double lenseconds) diff --git a/Source/PluginProcessor.cpp b/Source/PluginProcessor.cpp index bd4c19c..2c47662 100644 --- a/Source/PluginProcessor.cpp +++ b/Source/PluginProcessor.cpp @@ -226,7 +226,7 @@ void PaulstretchpluginAudioProcessor::startplay(Range playrange, int num void PaulstretchpluginAudioProcessor::prepareToPlay(double sampleRate, int samplesPerBlock) { - std::lock_guard locker(m_mutex); + ScopedLock locker(m_cs); if (getNumOutputChannels() != m_cur_num_out_chans) m_ready_to_play = false; if (m_using_memory_buffer == true) @@ -301,7 +301,7 @@ void copyAudioBufferWrappingPosition(const AudioBuffer& src, AudioBuffer< void PaulstretchpluginAudioProcessor::processBlock (AudioSampleBuffer& buffer, MidiBuffer& midiMessages) { - std::lock_guard locker(m_mutex); + ScopedLock locker(m_cs); ScopedNoDenormals noDenormals; const int totalNumInputChannels = getTotalNumInputChannels(); const int totalNumOutputChannels = getTotalNumOutputChannels(); @@ -394,7 +394,7 @@ void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int if (tree.isValid()) { { - std::lock_guard locker(m_mutex); + ScopedLock locker(m_cs); for (int i = 0; i < getNumParameters(); ++i) { auto par = getFloatParameter(i); @@ -416,7 +416,7 @@ void PaulstretchpluginAudioProcessor::setStateInformation (const void* data, int void PaulstretchpluginAudioProcessor::setRecordingEnabled(bool b) { - std::lock_guard locker(m_mutex); + ScopedLock locker(m_cs); int lenbufframes = getSampleRate()*m_max_reclen; if (b == true) { @@ -462,7 +462,7 @@ String PaulstretchpluginAudioProcessor::setAudioFile(File f) //MessageManager::callAsync([cb, file]() { cb("Too high bit depth in file " + file.getFullPathName()); }); return "Too high bit depth in file " + f.getFullPathName(); } - std::lock_guard locker(m_mutex); + ScopedLock locker(m_cs); m_stretch_source->setAudioFile(f); m_current_file = f; m_using_memory_buffer = false; diff --git a/Source/PluginProcessor.h b/Source/PluginProcessor.h index a0c9c03..8198363 100644 --- a/Source/PluginProcessor.h +++ b/Source/PluginProcessor.h @@ -104,7 +104,7 @@ private: void finishRecording(int lenrecorded); bool m_using_memory_buffer = true; int m_cur_num_out_chans = 2; - std::mutex m_mutex; + CriticalSection m_cs; File m_current_file;