mirror of
https://github.com/juce-framework/JUCE.git
synced 2026-01-10 23:44:24 +00:00
Added sanity-checking in AudioProcessor to block parameter change calls with nonsense indexes (as seen being sent by some buggy plugins). Also improved AudioProcessor::copyXmlToBinary method.
This commit is contained in:
parent
4aa931def3
commit
6aae0c798c
2 changed files with 59 additions and 43 deletions
|
|
@ -139,44 +139,59 @@ AudioProcessorListener* AudioProcessor::getListenerLocked (const int index) cons
|
|||
|
||||
void AudioProcessor::sendParamChangeMessageToListeners (const int parameterIndex, const float newValue)
|
||||
{
|
||||
jassert (isPositiveAndBelow (parameterIndex, getNumParameters()));
|
||||
|
||||
for (int i = listeners.size(); --i >= 0;)
|
||||
if (AudioProcessorListener* l = getListenerLocked (i))
|
||||
l->audioProcessorParameterChanged (this, parameterIndex, newValue);
|
||||
if (isPositiveAndBelow (parameterIndex, getNumParameters()))
|
||||
{
|
||||
for (int i = listeners.size(); --i >= 0;)
|
||||
if (AudioProcessorListener* l = getListenerLocked (i))
|
||||
l->audioProcessorParameterChanged (this, parameterIndex, newValue);
|
||||
}
|
||||
else
|
||||
{
|
||||
jassertfalse; // called with an out-of-range parameter index!
|
||||
}
|
||||
}
|
||||
|
||||
void AudioProcessor::beginParameterChangeGesture (int parameterIndex)
|
||||
{
|
||||
jassert (isPositiveAndBelow (parameterIndex, getNumParameters()));
|
||||
if (isPositiveAndBelow (parameterIndex, getNumParameters()))
|
||||
{
|
||||
#if JUCE_DEBUG
|
||||
// This means you've called beginParameterChangeGesture twice in succession without a matching
|
||||
// call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
|
||||
jassert (! changingParams [parameterIndex]);
|
||||
changingParams.setBit (parameterIndex);
|
||||
#endif
|
||||
|
||||
#if JUCE_DEBUG
|
||||
// This means you've called beginParameterChangeGesture twice in succession without a matching
|
||||
// call to endParameterChangeGesture. That might be fine in most hosts, but better to avoid doing it.
|
||||
jassert (! changingParams [parameterIndex]);
|
||||
changingParams.setBit (parameterIndex);
|
||||
#endif
|
||||
|
||||
for (int i = listeners.size(); --i >= 0;)
|
||||
if (AudioProcessorListener* l = getListenerLocked (i))
|
||||
l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
|
||||
for (int i = listeners.size(); --i >= 0;)
|
||||
if (AudioProcessorListener* l = getListenerLocked (i))
|
||||
l->audioProcessorParameterChangeGestureBegin (this, parameterIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
jassertfalse; // called with an out-of-range parameter index!
|
||||
}
|
||||
}
|
||||
|
||||
void AudioProcessor::endParameterChangeGesture (int parameterIndex)
|
||||
{
|
||||
jassert (isPositiveAndBelow (parameterIndex, getNumParameters()));
|
||||
if (isPositiveAndBelow (parameterIndex, getNumParameters()))
|
||||
{
|
||||
#if JUCE_DEBUG
|
||||
// This means you've called endParameterChangeGesture without having previously called
|
||||
// endParameterChangeGesture. That might be fine in most hosts, but better to keep the
|
||||
// calls matched correctly.
|
||||
jassert (changingParams [parameterIndex]);
|
||||
changingParams.clearBit (parameterIndex);
|
||||
#endif
|
||||
|
||||
#if JUCE_DEBUG
|
||||
// This means you've called endParameterChangeGesture without having previously called
|
||||
// endParameterChangeGesture. That might be fine in most hosts, but better to keep the
|
||||
// calls matched correctly.
|
||||
jassert (changingParams [parameterIndex]);
|
||||
changingParams.clearBit (parameterIndex);
|
||||
#endif
|
||||
|
||||
for (int i = listeners.size(); --i >= 0;)
|
||||
if (AudioProcessorListener* l = getListenerLocked (i))
|
||||
l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
|
||||
for (int i = listeners.size(); --i >= 0;)
|
||||
if (AudioProcessorListener* l = getListenerLocked (i))
|
||||
l->audioProcessorParameterChangeGestureEnd (this, parameterIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
jassertfalse; // called with an out-of-range parameter index!
|
||||
}
|
||||
}
|
||||
|
||||
void AudioProcessor::updateHostDisplay()
|
||||
|
|
@ -247,16 +262,17 @@ const uint32 magicXmlNumber = 0x21324356;
|
|||
|
||||
void AudioProcessor::copyXmlToBinary (const XmlElement& xml, juce::MemoryBlock& destData)
|
||||
{
|
||||
const String xmlString (xml.createDocument (String::empty, true, false));
|
||||
const size_t stringLength = xmlString.getNumBytesAsUTF8();
|
||||
{
|
||||
MemoryOutputStream out (destData, false);
|
||||
out.writeInt (magicXmlNumber);
|
||||
out.writeInt (0);
|
||||
xml.writeToStream (out, String::empty, true, false);
|
||||
out.writeByte (0);
|
||||
}
|
||||
|
||||
destData.setSize (stringLength + 9);
|
||||
|
||||
uint32* const d = static_cast<uint32*> (destData.getData());
|
||||
d[0] = ByteOrder::swapIfBigEndian ((const uint32) magicXmlNumber);
|
||||
d[1] = ByteOrder::swapIfBigEndian ((const uint32) stringLength);
|
||||
|
||||
xmlString.copyToUTF8 ((CharPointer_UTF8::CharType*) (d + 2), stringLength + 1);
|
||||
// go back and write the string length..
|
||||
static_cast<uint32*> (destData.getData())[1]
|
||||
= ByteOrder::swapIfBigEndian ((uint32) destData.getSize() - 9);
|
||||
}
|
||||
|
||||
XmlElement* AudioProcessor::getXmlFromBinary (const void* data, const int sizeInBytes)
|
||||
|
|
@ -276,7 +292,7 @@ XmlElement* AudioProcessor::getXmlFromBinary (const void* data, const int sizeIn
|
|||
|
||||
//==============================================================================
|
||||
void AudioProcessorListener::audioProcessorParameterChangeGestureBegin (AudioProcessor*, int) {}
|
||||
void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int) {}
|
||||
void AudioProcessorListener::audioProcessorParameterChangeGestureEnd (AudioProcessor*, int) {}
|
||||
|
||||
//==============================================================================
|
||||
bool AudioPlayHead::CurrentPositionInfo::operator== (const CurrentPositionInfo& other) const noexcept
|
||||
|
|
|
|||
|
|
@ -620,10 +620,6 @@ public:
|
|||
*/
|
||||
WrapperType wrapperType;
|
||||
|
||||
/** @internal */
|
||||
static void JUCE_CALLTYPE setTypeOfNextNewPlugin (WrapperType);
|
||||
|
||||
protected:
|
||||
//==============================================================================
|
||||
/** Helper function that just converts an xml element into a binary blob.
|
||||
|
||||
|
|
@ -643,6 +639,10 @@ protected:
|
|||
*/
|
||||
static XmlElement* getXmlFromBinary (const void* data, int sizeInBytes);
|
||||
|
||||
/** @internal */
|
||||
static void JUCE_CALLTYPE setTypeOfNextNewPlugin (WrapperType);
|
||||
|
||||
protected:
|
||||
/** @internal */
|
||||
AudioPlayHead* playHead;
|
||||
|
||||
|
|
@ -650,7 +650,7 @@ protected:
|
|||
void sendParamChangeMessageToListeners (int parameterIndex, float newValue);
|
||||
|
||||
private:
|
||||
Array <AudioProcessorListener*> listeners;
|
||||
Array<AudioProcessorListener*> listeners;
|
||||
Component::SafePointer<AudioProcessorEditor> activeEditor;
|
||||
double sampleRate;
|
||||
int blockSize, numInputChannels, numOutputChannels, latencySamples;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue