mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-11 23:54:18 +00:00
Threadsafety improvements
This commit is contained in:
parent
a268860713
commit
7d2310795f
4 changed files with 38 additions and 14 deletions
|
|
@ -49,7 +49,7 @@ MPEChannelAssigner::MPEChannelAssigner (Range<int> channelRange)
|
|||
|
||||
int MPEChannelAssigner::findMidiChannelForNewNote (int noteNumber) noexcept
|
||||
{
|
||||
if (numChannels == 1)
|
||||
if (numChannels <= 1)
|
||||
return firstChannel;
|
||||
|
||||
for (auto ch = firstChannel; (isLegacy || zone->isLowerZone() ? ch <= lastChannel : ch >= lastChannel); ch += channelIncrement)
|
||||
|
|
|
|||
|
|
@ -885,6 +885,7 @@ AudioProcessorGraph::AudioProcessorGraph()
|
|||
|
||||
AudioProcessorGraph::~AudioProcessorGraph()
|
||||
{
|
||||
cancelPendingUpdate();
|
||||
clearRenderingSequence();
|
||||
clear();
|
||||
}
|
||||
|
|
@ -962,6 +963,8 @@ AudioProcessorGraph::Node::Ptr AudioProcessorGraph::addNode (std::unique_ptr<Aud
|
|||
|
||||
bool AudioProcessorGraph::removeNode (NodeID nodeId)
|
||||
{
|
||||
const ScopedLock sl (getCallbackLock());
|
||||
|
||||
for (int i = nodes.size(); --i >= 0;)
|
||||
{
|
||||
if (nodes.getUnchecked(i)->nodeID == nodeId)
|
||||
|
|
@ -1227,22 +1230,34 @@ void AudioProcessorGraph::buildRenderingSequence()
|
|||
RenderSequenceBuilder<RenderSequenceDouble> builderD (*this, *newSequenceD);
|
||||
}
|
||||
|
||||
struct SampleRateAndBlockSize final
|
||||
{
|
||||
double sampleRate;
|
||||
int blockSize;
|
||||
};
|
||||
|
||||
const auto blockDetails = [&]
|
||||
{
|
||||
const ScopedLock sl (getCallbackLock());
|
||||
newSequenceF->prepareBuffers (getBlockSize());
|
||||
newSequenceD->prepareBuffers (getBlockSize());
|
||||
}
|
||||
auto details = SampleRateAndBlockSize { getSampleRate(), getBlockSize() };
|
||||
newSequenceF->prepareBuffers (details.blockSize);
|
||||
newSequenceD->prepareBuffers (details.blockSize);
|
||||
return details;
|
||||
}();
|
||||
|
||||
if (anyNodesNeedPreparing())
|
||||
{
|
||||
{
|
||||
const ScopedLock sl (getCallbackLock());
|
||||
renderSequenceFloat.reset();
|
||||
renderSequenceDouble.reset();
|
||||
}
|
||||
const ScopedLock sl (getCallbackLock());
|
||||
renderSequenceFloat.reset();
|
||||
renderSequenceDouble.reset();
|
||||
|
||||
for (auto* node : nodes)
|
||||
node->prepare (getSampleRate(), getBlockSize(), this, getProcessingPrecision());
|
||||
node->prepare (blockDetails.sampleRate,
|
||||
blockDetails.blockSize,
|
||||
this,
|
||||
getProcessingPrecision());
|
||||
|
||||
isPrepared = 1;
|
||||
}
|
||||
|
||||
const ScopedLock sl (getCallbackLock());
|
||||
|
|
@ -1254,13 +1269,16 @@ void AudioProcessorGraph::buildRenderingSequence()
|
|||
void AudioProcessorGraph::handleAsyncUpdate()
|
||||
{
|
||||
buildRenderingSequence();
|
||||
isPrepared = 1;
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
void AudioProcessorGraph::prepareToPlay (double sampleRate, int estimatedSamplesPerBlock)
|
||||
{
|
||||
setRateAndBufferSizeDetails (sampleRate, estimatedSamplesPerBlock);
|
||||
{
|
||||
const ScopedLock sl (getCallbackLock());
|
||||
setRateAndBufferSizeDetails (sampleRate, estimatedSamplesPerBlock);
|
||||
}
|
||||
|
||||
clearRenderingSequence();
|
||||
|
||||
if (MessageManager::getInstance()->isThisTheMessageThread())
|
||||
|
|
@ -1278,6 +1296,8 @@ void AudioProcessorGraph::releaseResources()
|
|||
{
|
||||
const ScopedLock sl (getCallbackLock());
|
||||
|
||||
cancelPendingUpdate();
|
||||
|
||||
isPrepared = 0;
|
||||
|
||||
for (auto* n : nodes)
|
||||
|
|
|
|||
|
|
@ -145,7 +145,8 @@ public:
|
|||
|
||||
const std::unique_ptr<AudioProcessor> processor;
|
||||
Array<Connection> inputs, outputs;
|
||||
std::atomic<bool> isPrepared { false }, bypassed { false };
|
||||
bool isPrepared = false;
|
||||
std::atomic<bool> bypassed { false };
|
||||
|
||||
Node (NodeID, std::unique_ptr<AudioProcessor>) noexcept;
|
||||
|
||||
|
|
|
|||
|
|
@ -258,7 +258,10 @@ AudioProcessorValueTreeState::AudioProcessorValueTreeState (AudioProcessor& p, U
|
|||
state.addListener (this);
|
||||
}
|
||||
|
||||
AudioProcessorValueTreeState::~AudioProcessorValueTreeState() {}
|
||||
AudioProcessorValueTreeState::~AudioProcessorValueTreeState()
|
||||
{
|
||||
stopTimer();
|
||||
}
|
||||
|
||||
//==============================================================================
|
||||
RangedAudioParameter* AudioProcessorValueTreeState::createAndAddParameter (const String& paramID,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue