Browse Source

Did some modernisation in AudioProcessor

tags/2021-05-28
jules 7 years ago
parent
commit
6d8dec34bd
2 changed files with 157 additions and 231 deletions
  1. +107
    -175
      modules/juce_audio_processors/processors/juce_AudioProcessor.cpp
  2. +50
    -56
      modules/juce_audio_processors/processors/juce_AudioProcessor.h

+ 107
- 175
modules/juce_audio_processors/processors/juce_AudioProcessor.cpp View File

@@ -35,44 +35,17 @@ void JUCE_CALLTYPE AudioProcessor::setTypeOfNextNewPlugin (AudioProcessor::Wrapp
}
AudioProcessor::AudioProcessor()
: AudioProcessor (BusesProperties().withInput ("Input", AudioChannelSet::stereo(), false)
.withOutput ("Output", AudioChannelSet::stereo(), false))
{
initialise (BusesProperties().withInput ("Input", AudioChannelSet::stereo(), false)
.withOutput ("Output", AudioChannelSet::stereo(), false));
}
AudioProcessor::AudioProcessor(const BusesProperties& ioConfig)
AudioProcessor::AudioProcessor (const BusesProperties& ioConfig)
{
initialise (ioConfig);
}
void AudioProcessor::initialise (const BusesProperties& ioConfig)
{
cachedTotalIns = 0;
cachedTotalOuts = 0;
wrapperType = wrapperTypeBeingCreated.get();
playHead = nullptr;
currentSampleRate = 0;
blockSize = 0;
latencySamples = 0;
#if JUCE_DEBUG
textRecursionCheck = false;
#endif
suspended = false;
nonRealtime = false;
processingPrecision = singlePrecision;
const int numInputBuses = ioConfig.inputLayouts.size();
const int numOutputBuses = ioConfig.outputLayouts.size();
for (int i = 0; i < numInputBuses; ++i)
createBus (true, ioConfig.inputLayouts. getReference (i));
for (int i = 0; i < numOutputBuses; ++i)
createBus (false, ioConfig.outputLayouts.getReference (i));
for (auto& layout : ioConfig.inputLayouts) createBus (true, layout);
for (auto& layout : ioConfig.outputLayouts) createBus (false, layout);
updateSpeakerFormatStrings();
}
@@ -100,6 +73,7 @@ bool AudioProcessor::addBus (bool isInput)
return false;
BusProperties busesProps;
if (! canApplyBusCountChange (isInput, true, busesProps))
return false;
@@ -109,7 +83,8 @@ bool AudioProcessor::addBus (bool isInput)
bool AudioProcessor::removeBus (bool inputBus)
{
const int numBuses = getBusCount (inputBus);
auto numBuses = getBusCount (inputBus);
if (numBuses == 0)
return false;
@@ -117,19 +92,18 @@ bool AudioProcessor::removeBus (bool inputBus)
return false;
BusProperties busesProps;
if (! canApplyBusCountChange (inputBus, false, busesProps))
return false;
const int busIdx = numBuses - 1;
const int numChannels = getChannelCountOfBus (inputBus, busIdx);
(inputBus ? inputBuses : outputBuses).remove (busIdx);
auto busIndex = numBuses - 1;
auto numChannels = getChannelCountOfBus (inputBus, busIndex);
(inputBus ? inputBuses : outputBuses).remove (busIndex);
audioIOChanged (true, numChannels > 0);
return true;
}
//==============================================================================
bool AudioProcessor::setBusesLayout (const BusesLayout& arr)
{
@@ -139,7 +113,8 @@ bool AudioProcessor::setBusesLayout (const BusesLayout& arr)
if (arr == getBusesLayout())
return true;
BusesLayout copy = arr;
auto copy = arr;
if (! canApplyBusesLayout (copy))
return false;
@@ -148,14 +123,14 @@ bool AudioProcessor::setBusesLayout (const BusesLayout& arr)
bool AudioProcessor::setBusesLayoutWithoutEnabling (const BusesLayout& arr)
{
const int numIns = getBusCount (true);
const int numOuts = getBusCount (false);
auto numIns = getBusCount (true);
auto numOuts = getBusCount (false);
jassert (arr.inputBuses. size() == numIns
&& arr.outputBuses.size() == numOuts);
BusesLayout request = arr;
const BusesLayout current = getBusesLayout();
auto request = arr;
auto current = getBusesLayout();
for (int i = 0; i < numIns; ++i)
if (request.getNumChannels (true, i) == 0)
@@ -174,8 +149,8 @@ bool AudioProcessor::setBusesLayoutWithoutEnabling (const BusesLayout& arr)
for (int i = 0; i < (isInput ? numIns : numOuts); ++i)
{
Bus& bus = *getBus (isInput, i);
AudioChannelSet& set = request.getChannelSet (isInput, i);
auto& bus = *getBus (isInput, i);
auto& set = request.getChannelSet (isInput, i);
if (! bus.isEnabled())
{
@@ -193,67 +168,51 @@ bool AudioProcessor::setBusesLayoutWithoutEnabling (const BusesLayout& arr)
AudioProcessor::BusesLayout AudioProcessor::getBusesLayout() const
{
BusesLayout layouts;
const int numInputs = getBusCount (true);
const int numOutputs = getBusCount (false);
for (int i = 0; i < numInputs; ++i)
layouts.inputBuses. add (getBus (true, i)->getCurrentLayout());
for (int i = 0; i < numOutputs; ++i)
layouts.outputBuses.add (getBus (false, i)->getCurrentLayout());
for (auto& i : inputBuses) layouts.inputBuses.add (i->getCurrentLayout());
for (auto& i : outputBuses) layouts.outputBuses.add (i->getCurrentLayout());
return layouts;
}
AudioChannelSet AudioProcessor::getChannelLayoutOfBus (bool isInput, int busIdx) const noexcept
AudioChannelSet AudioProcessor::getChannelLayoutOfBus (bool isInput, int busIndex) const noexcept
{
const OwnedArray<Bus>& buses = (isInput ? inputBuses : outputBuses);
if (Bus* bus = buses[busIdx])
if (auto* bus = (isInput ? inputBuses : outputBuses)[busIndex])
return bus->getCurrentLayout();
return AudioChannelSet();
return {};
}
bool AudioProcessor::setChannelLayoutOfBus (bool isInputBus, int busIdx, const AudioChannelSet& layout)
bool AudioProcessor::setChannelLayoutOfBus (bool isInputBus, int busIndex, const AudioChannelSet& layout)
{
if (Bus* bus = getBus (isInputBus, busIdx))
if (auto* bus = getBus (isInputBus, busIndex))
{
BusesLayout layouts = bus->getBusesLayoutForLayoutChangeOfBus (layout);
auto layouts = bus->getBusesLayoutForLayoutChangeOfBus (layout);
if (layouts.getChannelSet (isInputBus, busIdx) == layout)
if (layouts.getChannelSet (isInputBus, busIndex) == layout)
return applyBusLayouts (layouts);
return false;
}
// busIdx parameter is invalid
jassertfalse;
jassertfalse; // busIndex parameter is invalid
return false;
}
bool AudioProcessor::enableAllBuses()
{
BusesLayout layouts;
const int numInputs = getBusCount (true);
const int numOutputs = getBusCount (false);
for (int i = 0; i < numInputs; ++i)
layouts.inputBuses. add (getBus (true, i)->lastLayout);
for (int i = 0; i < numOutputs; ++i)
layouts.outputBuses.add (getBus (false, i)->lastLayout);
for (auto& i : inputBuses) layouts.inputBuses.add (i->lastLayout);
for (auto& i : outputBuses) layouts.outputBuses.add (i->lastLayout);
return setBusesLayout (layouts);
}
bool AudioProcessor::checkBusesLayoutSupported (const BusesLayout& layouts) const
{
const int numInputBuses = getBusCount (true);
const int numOutputBuses = getBusCount (false);
if (layouts.inputBuses. size() == numInputBuses
&& layouts.outputBuses.size() == numOutputBuses)
if (layouts.inputBuses.size() == inputBuses.size()
&& layouts.outputBuses.size() == outputBuses.size())
return isBusesLayoutSupported (layouts);
return false;
@@ -264,8 +223,8 @@ void AudioProcessor::getNextBestLayout (const BusesLayout& desiredLayout, BusesL
// if you are hitting this assertion then you are requesting a next
// best layout which does not have the same number of buses as the
// audio processor.
jassert (desiredLayout.inputBuses. size() == getBusCount (true)
&& desiredLayout.outputBuses.size() == getBusCount (false));
jassert (desiredLayout.inputBuses.size() == inputBuses.size()
&& desiredLayout.outputBuses.size() == outputBuses.size());
if (checkBusesLayoutSupported (desiredLayout))
{
@@ -273,9 +232,9 @@ void AudioProcessor::getNextBestLayout (const BusesLayout& desiredLayout, BusesL
return;
}
BusesLayout originalState = actualLayouts;
BusesLayout currentState = originalState;
BusesLayout bestSupported = currentState;
auto originalState = actualLayouts;
auto currentState = originalState;
auto bestSupported = currentState;
for (int dir = 0; dir < 2; ++dir)
{
@@ -286,18 +245,18 @@ void AudioProcessor::getNextBestLayout (const BusesLayout& desiredLayout, BusesL
auto& requestedLayouts = (isInput ? desiredLayout.inputBuses : desiredLayout.outputBuses);
auto& originalLayouts = (isInput ? originalState.inputBuses : originalState.outputBuses);
for (int busIdx = 0; busIdx < requestedLayouts.size(); ++busIdx)
for (int busIndex = 0; busIndex < requestedLayouts.size(); ++busIndex)
{
auto& best = bestLayouts .getReference (busIdx);
auto& requested = requestedLayouts.getReference (busIdx);
auto& original = originalLayouts .getReference (busIdx);
auto& best = bestLayouts .getReference (busIndex);
auto& requested = requestedLayouts.getReference (busIndex);
auto& original = originalLayouts .getReference (busIndex);
// do we need to do anything
if (original == requested)
continue;
currentState = bestSupported;
auto& current = currentLayouts .getReference (busIdx);
auto& current = currentLayouts .getReference (busIndex);
// already supported?
current = requested;
@@ -311,9 +270,9 @@ void AudioProcessor::getNextBestLayout (const BusesLayout& desiredLayout, BusesL
// try setting the opposite bus to the identical layout
const bool oppositeDirection = ! isInput;
if (getBusCount (oppositeDirection) > busIdx)
if (getBusCount (oppositeDirection) > busIndex)
{
auto& oppositeLayout = (oppositeDirection ? currentState.inputBuses : currentState.outputBuses).getReference (busIdx);
auto& oppositeLayout = (oppositeDirection ? currentState.inputBuses : currentState.outputBuses).getReference (busIndex);
oppositeLayout = requested;
if (checkBusesLayoutSupported (currentState))
@@ -323,7 +282,7 @@ void AudioProcessor::getNextBestLayout (const BusesLayout& desiredLayout, BusesL
}
// try setting the default layout
oppositeLayout = getBus (oppositeDirection, busIdx)->getDefaultLayout();
oppositeLayout = getBus (oppositeDirection, busIndex)->getDefaultLayout();
if (checkBusesLayoutSupported (currentState))
{
@@ -340,7 +299,7 @@ void AudioProcessor::getNextBestLayout (const BusesLayout& desiredLayout, BusesL
bool oIsInput = (oDir == 0);
auto oBusNum = getBusCount (oIsInput);
for (int oBusIdx = 0; oBusIdx < oBusNum; ++oBusIdx)
for (int oBusIndex = 0; oBusIndex < oBusNum; ++oBusIndex)
(oIsInput ? allTheSame.inputBuses : allTheSame.outputBuses).add (requested);
}
@@ -352,7 +311,7 @@ void AudioProcessor::getNextBestLayout (const BusesLayout& desiredLayout, BusesL
// what is closer the default or the current layout?
auto distance = std::abs (best.size() - requested.size());
auto& defaultLayout = getBus (isInput, busIdx)->getDefaultLayout();
auto& defaultLayout = getBus (isInput, busIndex)->getDefaultLayout();
if (std::abs (defaultLayout.size() - requested.size()) < distance)
{
@@ -385,10 +344,7 @@ void AudioProcessor::removeListener (AudioProcessorListener* const listenerToRem
listeners.removeFirstMatchingValue (listenerToRemove);
}
void AudioProcessor::setPlayConfigDetails (const int newNumIns,
const int newNumOuts,
const double newSampleRate,
const int newBlockSize)
void AudioProcessor::setPlayConfigDetails (int newNumIns, int newNumOuts, double newSampleRate, int newBlockSize)
{
bool success = true;
@@ -421,16 +377,6 @@ void AudioProcessor::setRateAndBufferSizeDetails (double newSampleRate, int newB
}
//==============================================================================
static int countTotalChannels (const OwnedArray<AudioProcessor::Bus>& buses) noexcept
{
int n = 0;
for (auto* bus : buses)
n += bus->getNumberOfChannels();
return n;
}
void AudioProcessor::numChannelsChanged() {}
void AudioProcessor::numBusesChanged() {}
void AudioProcessor::processorLayoutsChanged() {}
@@ -438,7 +384,7 @@ void AudioProcessor::processorLayoutsChanged() {}
int AudioProcessor::getChannelIndexInProcessBlockBuffer (bool isInput, int busIndex, int channelIndex) const noexcept
{
auto& ioBus = isInput ? inputBuses : outputBuses;
jassert (isPositiveAndBelow(busIndex, ioBus.size()));
jassert (isPositiveAndBelow (busIndex, ioBus.size()));
for (int i = 0; i < ioBus.size() && i < busIndex; ++i)
channelIndex += getChannelCountOfBus (isInput, i);
@@ -446,15 +392,15 @@ int AudioProcessor::getChannelIndexInProcessBlockBuffer (bool isInput, int busIn
return channelIndex;
}
int AudioProcessor::getOffsetInBusBufferForAbsoluteChannelIndex (bool isInput, int absoluteChannelIndex, /*out*/ int& busIdx) const noexcept
int AudioProcessor::getOffsetInBusBufferForAbsoluteChannelIndex (bool isInput, int absoluteChannelIndex, int& busIndex) const noexcept
{
auto numBuses = getBusCount (isInput);
int numChannels = 0;
for (busIdx = 0; busIdx < numBuses && absoluteChannelIndex >= (numChannels = getChannelLayoutOfBus (isInput, busIdx).size()); ++busIdx)
for (busIndex = 0; busIndex < numBuses && absoluteChannelIndex >= (numChannels = getChannelLayoutOfBus (isInput, busIndex).size()); ++busIndex)
absoluteChannelIndex -= numChannels;
return busIdx >= numBuses ? -1 : absoluteChannelIndex;
return busIndex >= numBuses ? -1 : absoluteChannelIndex;
}
//==============================================================================
@@ -902,11 +848,11 @@ bool AudioProcessor::disableNonMainBuses()
{
auto layouts = getBusesLayout();
for (int busIdx = 1; busIdx < layouts.inputBuses.size(); ++busIdx)
layouts.inputBuses.getReference (busIdx) = AudioChannelSet::disabled();
for (int busIndex = 1; busIndex < layouts.inputBuses.size(); ++busIndex)
layouts.inputBuses.getReference (busIndex) = AudioChannelSet::disabled();
for (int busIdx = 1; busIdx < layouts.outputBuses.size(); ++busIdx)
layouts.outputBuses.getReference (busIdx) = AudioChannelSet::disabled();
for (int busIndex = 1; busIndex < layouts.outputBuses.size(); ++busIndex)
layouts.outputBuses.getReference (busIndex) = AudioChannelSet::disabled();
return setBusesLayout (layouts);
}
@@ -943,10 +889,10 @@ bool AudioProcessor::applyBusLayouts (const BusesLayout& layouts)
int newNumberOfIns = 0, newNumberOfOuts = 0;
for (int busIdx = 0; busIdx < numInputBuses; ++busIdx)
for (int busIndex = 0; busIndex < numInputBuses; ++busIndex)
{
auto& bus = *getBus (true, busIdx);
const auto& set = layouts.getChannelSet (true, busIdx);
auto& bus = *getBus (true, busIndex);
const auto& set = layouts.getChannelSet (true, busIndex);
bus.layout = set;
if (! set.isDisabled())
@@ -955,10 +901,10 @@ bool AudioProcessor::applyBusLayouts (const BusesLayout& layouts)
newNumberOfIns += set.size();
}
for (int busIdx = 0; busIdx < numOutputBuses; ++busIdx)
for (int busIndex = 0; busIndex < numOutputBuses; ++busIndex)
{
auto& bus = *getBus (false, busIdx);
const auto& set = layouts.getChannelSet (false, busIdx);
auto& bus = *getBus (false, busIndex);
const auto& set = layouts.getChannelSet (false, busIndex);
bus.layout = set;
if (! set.isDisabled())
@@ -988,6 +934,16 @@ void AudioProcessor::audioIOChanged (bool busNumberChanged, bool channelNumChang
bus->updateChannelCount();
}
auto countTotalChannels = [](const OwnedArray<AudioProcessor::Bus>& buses) noexcept
{
int n = 0;
for (auto* bus : buses)
n += bus->getNumberOfChannels();
return n;
};
cachedTotalIns = countTotalChannels (inputBuses);
cachedTotalOuts = countTotalChannels (outputBuses);
@@ -1115,36 +1071,25 @@ AudioProcessor::Bus::Bus (AudioProcessor& processor, const String& busName,
jassert (! dfltLayout.isDisabled());
}
bool AudioProcessor::Bus::isInput() const
{
return owner.inputBuses.contains (this);
}
bool AudioProcessor::Bus::isInput() const noexcept { return owner.inputBuses.contains (this); }
int AudioProcessor::Bus::getBusIndex() const noexcept { return getDirectionAndIndex().index; }
int AudioProcessor::Bus::getBusIndex() const
AudioProcessor::Bus::BusDirectionAndIndex AudioProcessor::Bus::getDirectionAndIndex() const noexcept
{
bool ignore;
int idx;
busDirAndIndex (ignore, idx);
return idx;
}
BusDirectionAndIndex di;
di.index = owner.inputBuses.indexOf (this);
di.isInput = (di.index >= 0);
void AudioProcessor::Bus::busDirAndIndex (bool& input, int& idx) const noexcept
{
idx = owner.inputBuses.indexOf (this);
input = (idx >= 0);
if (! di.isInput)
di.index = owner.outputBuses.indexOf (this);
if (! input)
idx = owner.outputBuses.indexOf (this);
return di;
}
bool AudioProcessor::Bus::setCurrentLayout (const AudioChannelSet& busLayout)
{
bool isInput;
int idx;
busDirAndIndex (isInput, idx);
return owner.setChannelLayoutOfBus (isInput, idx, busLayout);
auto di = getDirectionAndIndex();
return owner.setChannelLayoutOfBus (di.isInput, di.index, busLayout);
}
bool AudioProcessor::Bus::setCurrentLayoutWithoutEnabling (const AudioChannelSet& set)
@@ -1168,21 +1113,20 @@ bool AudioProcessor::Bus::setCurrentLayoutWithoutEnabling (const AudioChannelSet
bool AudioProcessor::Bus::setNumberOfChannels (int channels)
{
bool isInputBus;
int busIdx;
busDirAndIndex (isInputBus, busIdx);
auto di = getDirectionAndIndex();
if (owner.setChannelLayoutOfBus (isInputBus, busIdx, AudioChannelSet::canonicalChannelSet (channels)))
if (owner.setChannelLayoutOfBus (di.isInput, di.index, AudioChannelSet::canonicalChannelSet (channels)))
return true;
if (channels == 0)
return false;
AudioChannelSet namedSet = AudioChannelSet::namedChannelSet (channels);
if (! namedSet.isDisabled() && owner.setChannelLayoutOfBus (isInputBus, busIdx, namedSet))
auto namedSet = AudioChannelSet::namedChannelSet (channels);
if (! namedSet.isDisabled() && owner.setChannelLayoutOfBus (di.isInput, di.index, namedSet))
return true;
return owner.setChannelLayoutOfBus (isInputBus, busIdx, AudioChannelSet::discreteChannels (channels));
return owner.setChannelLayoutOfBus (di.isInput, di.index, AudioChannelSet::discreteChannels (channels));
}
bool AudioProcessor::Bus::enable (bool shouldEnable)
@@ -1204,16 +1148,12 @@ int AudioProcessor::Bus::getMaxSupportedChannels (int limit) const
bool AudioProcessor::Bus::isLayoutSupported (const AudioChannelSet& set, BusesLayout* ioLayout) const
{
bool isInputBus;
int busIdx;
busDirAndIndex (isInputBus, busIdx);
auto di = getDirectionAndIndex();
// check that supplied ioLayout is actually valid
if (ioLayout != nullptr)
{
bool suppliedCurrentSupported = owner.checkBusesLayoutSupported (*ioLayout);
if (! suppliedCurrentSupported)
if (! owner.checkBusesLayoutSupported (*ioLayout))
{
*ioLayout = owner.getBusesLayout();
@@ -1222,16 +1162,16 @@ bool AudioProcessor::Bus::isLayoutSupported (const AudioChannelSet& set, BusesLa
}
}
BusesLayout currentLayout = (ioLayout != nullptr ? *ioLayout : owner.getBusesLayout());
const Array<AudioChannelSet>& actualBuses =
(isInputBus ? currentLayout.inputBuses : currentLayout.outputBuses);
auto currentLayout = (ioLayout != nullptr ? *ioLayout : owner.getBusesLayout());
auto& actualBuses = (di.isInput ? currentLayout.inputBuses : currentLayout.outputBuses);
if (actualBuses.getReference (busIdx) == set)
if (actualBuses.getReference (di.index) == set)
return true;
auto desiredLayout = currentLayout;
(isInputBus ? desiredLayout.inputBuses
: desiredLayout.outputBuses).getReference (busIdx) = set;
(di.isInput ? desiredLayout.inputBuses
: desiredLayout.outputBuses).getReference (di.index) = set;
owner.getNextBestLayout (desiredLayout, currentLayout);
@@ -1243,7 +1183,7 @@ bool AudioProcessor::Bus::isLayoutSupported (const AudioChannelSet& set, BusesLa
jassert (currentLayout.inputBuses. size() == owner.getBusCount (true)
&& currentLayout.outputBuses.size() == owner.getBusCount (false));
return actualBuses.getReference (busIdx) == set;
return actualBuses.getReference (di.index) == set;
}
bool AudioProcessor::Bus::isNumberOfChannelsSupported (int channels) const
@@ -1279,23 +1219,15 @@ AudioChannelSet AudioProcessor::Bus::supportedLayoutWithChannels (int channels)
AudioProcessor::BusesLayout AudioProcessor::Bus::getBusesLayoutForLayoutChangeOfBus (const AudioChannelSet& set) const
{
bool isInputBus;
int busIdx;
busDirAndIndex (isInputBus, busIdx);
auto layouts = owner.getBusesLayout();
isLayoutSupported (set, &layouts);
return layouts;
}
int AudioProcessor::Bus::getChannelIndexInProcessBlockBuffer (int channelIndex) const noexcept
{
bool isInputBus;
int busIdx;
busDirAndIndex (isInputBus, busIdx);
return owner.getChannelIndexInProcessBlockBuffer (isInputBus, busIdx, channelIndex);
auto di = getDirectionAndIndex();
return owner.getChannelIndexInProcessBlockBuffer (di.isInput, di.index, channelIndex);
}
void AudioProcessor::Bus::updateChannelCount() noexcept
@@ -1305,7 +1237,7 @@ void AudioProcessor::Bus::updateChannelCount() noexcept
//==============================================================================
void AudioProcessor::BusesProperties::addBus (bool isInput, const String& name,
const AudioChannelSet& dfltLayout, bool isActivatedByDefault)
const AudioChannelSet& dfltLayout, bool isActivatedByDefault)
{
jassert (dfltLayout.size() != 0);
@@ -1319,8 +1251,8 @@ void AudioProcessor::BusesProperties::addBus (bool isInput, const String& name,
}
AudioProcessor::BusesProperties AudioProcessor::BusesProperties::withInput (const String& name,
const AudioChannelSet& dfltLayout,
bool isActivatedByDefault) const
const AudioChannelSet& dfltLayout,
bool isActivatedByDefault) const
{
auto retval = *this;
retval.addBus (true, name, dfltLayout, isActivatedByDefault);
@@ -1328,8 +1260,8 @@ AudioProcessor::BusesProperties AudioProcessor::BusesProperties::withInput (con
}
AudioProcessor::BusesProperties AudioProcessor::BusesProperties::withOutput (const String& name,
const AudioChannelSet& dfltLayout,
bool isActivatedByDefault) const
const AudioChannelSet& dfltLayout,
bool isActivatedByDefault) const
{
auto retval = *this;
retval.addBus (false, name, dfltLayout, isActivatedByDefault);


+ 50
- 56
modules/juce_audio_processors/processors/juce_AudioProcessor.h View File

@@ -52,12 +52,11 @@ protected:
/** Constructor.
This constructor will create a main input and output bus which are diabled
by default. If you need more fine grain control then use the other
constructors.
by default. If you need more fine-grained control then use the other constructors.
*/
AudioProcessor();
/** Constructor for multibus AudioProcessors
/** Constructor for multi-bus AudioProcessors
If your AudioProcessor supports multiple buses than use this constructor
to initialise the bus layouts and bus names of your plug-in.
@@ -65,19 +64,18 @@ protected:
AudioProcessor (const BusesProperties& ioLayouts);
/** Constructor for AudioProcessors which use layout maps
If your AudioProcessor uses layout maps then use this constructor.
*/
#if JUCE_COMPILER_SUPPORTS_INITIALIZER_LISTS
AudioProcessor (const std::initializer_list<const short[2]>& channelLayoutList)
: AudioProcessor (busesPropertiesFromLayoutArray (layoutListToArray (channelLayoutList)))
{
initialise (busesPropertiesFromLayoutArray (layoutListToArray (channelLayoutList)));
}
#else
template <int numLayouts>
AudioProcessor (const short (&channelLayoutList) [numLayouts][2])
: AudioProcessor (busesPropertiesFromLayoutArray (layoutListToArray (channelLayoutList)))
{
initialise (busesPropertiesFromLayoutArray (layoutListToArray (channelLayoutList)));
}
#endif
@@ -312,7 +310,7 @@ public:
/** Get the channel set of a particular bus */
AudioChannelSet getChannelSet (bool isInput, int busIndex) const noexcept
{
return (isInput ? inputBuses : outputBuses) [busIndex];
return (isInput ? inputBuses : outputBuses)[busIndex];
}
/** Get the input channel layout on the main bus. */
@@ -342,17 +340,17 @@ public:
{
public:
/** Returns true if this bus is an input bus. */
bool isInput() const;
bool isInput() const noexcept;
/** Returns the index of this bus. */
int getBusIndex() const;
int getBusIndex() const noexcept;
/** Returns true if the current bus is the main input or output bus. */
bool isMain() const { return getBusIndex() == 0; }
bool isMain() const noexcept { return getBusIndex() == 0; }
//==============================================================================
/** The bus's name. */
const String &getName() const noexcept { return name; }
const String& getName() const noexcept { return name; }
/** Get the default layout of this bus.
@see AudioChannelSet
@@ -454,16 +452,21 @@ public:
template <typename FloatType>
AudioBuffer<FloatType> getBusBuffer (AudioBuffer<FloatType>& processBlockBuffer) const
{
bool isIn;
int busIdx;
busDirAndIndex (isIn, busIdx);
return owner.getBusBuffer (processBlockBuffer, isIn, busIdx);
auto di = getDirectionAndIndex();
return owner.getBusBuffer (processBlockBuffer, di.isInput, di.index);
}
private:
friend class AudioProcessor;
Bus (AudioProcessor&, const String&, const AudioChannelSet&, bool);
void busDirAndIndex (bool&, int&) const noexcept;
struct BusDirectionAndIndex
{
bool isInput;
int index;
};
BusDirectionAndIndex getDirectionAndIndex() const noexcept;
void updateChannelCount() noexcept;
AudioProcessor& owner;
@@ -480,14 +483,14 @@ public:
int getBusCount (bool isInput) const noexcept { return (isInput ? inputBuses : outputBuses).size(); }
/** Returns the audio bus with a given index and direction.
If busIdx is invalid then this method will return a nullptr.
If busIndex is invalid then this method will return a nullptr.
*/
Bus* getBus (bool isInput, int busIdx) noexcept { return (isInput ? inputBuses : outputBuses)[busIdx]; }
Bus* getBus (bool isInput, int busIndex) noexcept { return (isInput ? inputBuses : outputBuses)[busIndex]; }
/** Returns the audio bus with a given index and direction.
If busIdx is invalid then this method will return a nullptr.
If busIndex is invalid then this method will return a nullptr.
*/
const Bus* getBus (bool isInput, int busIdx) const noexcept { return const_cast<AudioProcessor*> (this)->getBus (isInput, busIdx); }
const Bus* getBus (bool isInput, int busIndex) const noexcept { return const_cast<AudioProcessor*> (this)->getBus (isInput, busIndex); }
//==============================================================================
/** Callback to query if a bus can currently be added.
@@ -583,15 +586,15 @@ public:
If the index, direction combination is invalid or the layout is not
supported by the audio processor then this method will return false.
*/
bool setChannelLayoutOfBus (bool isInput, int busIdx, const AudioChannelSet& layout);
bool setChannelLayoutOfBus (bool isInput, int busIndex, const AudioChannelSet& layout);
/** Provides the number of channels of the bus with a given index and direction.
If the index, direction combination is invalid then this will return zero.
*/
inline int getChannelCountOfBus (bool isInput, int busIdx) const noexcept
inline int getChannelCountOfBus (bool isInput, int busIndex) const noexcept
{
if (const Bus* bus = getBus (isInput, busIdx))
if (auto* bus = getBus (isInput, busIndex))
return bus->getNumberOfChannels();
return 0;
@@ -616,7 +619,7 @@ public:
It also provides the bus index. For example, this method would return one
for a processor with two stereo buses when given the absolute channel index.
*/
int getOffsetInBusBufferForAbsoluteChannelIndex (bool isInput, int absoluteChannelIndex, /*out*/ int& busIdx) const noexcept;
int getOffsetInBusBufferForAbsoluteChannelIndex (bool isInput, int absoluteChannelIndex, int& busIndex) const noexcept;
/** Returns an AudioBuffer containing a set of channel pointers for a specific bus.
This can be called in processBlock to get a buffer containing a sub-group of the master
@@ -625,8 +628,8 @@ public:
template <typename FloatType>
AudioBuffer<FloatType> getBusBuffer (AudioBuffer<FloatType>& processBlockBuffer, bool isInput, int busIndex) const
{
const int busNumChannels = getChannelCountOfBus (isInput, busIndex);
const int channelOffset = getChannelIndexInProcessBlockBuffer (isInput, busIndex, 0);
auto busNumChannels = getChannelCountOfBus (isInput, busIndex);
auto channelOffset = getChannelIndexInProcessBlockBuffer (isInput, busIndex, 0);
return AudioBuffer<FloatType> (processBlockBuffer.getArrayOfWritePointers() + channelOffset,
busNumChannels, processBlockBuffer.getNumSamples());
@@ -1503,8 +1506,8 @@ protected:
The default implementation will return false if canAddBus/canRemoveBus
returns false (the default behavior). Otherwise, this method returns
"Input #busIdx" for input buses and "Output #busIdx" for output buses
where busIdx is the index for newly created buses. The default layout
"Input #busIndex" for input buses and "Output #busIndex" for output buses
where busIndex is the index for newly created buses. The default layout
in this case will be the layout of the previous bus of the same direction.
*/
virtual bool canApplyBusCountChange (bool isInput, bool isAddingBuses,
@@ -1514,7 +1517,7 @@ protected:
friend struct PluginBusUtilities;
/** @internal */
AudioPlayHead* playHead;
AudioPlayHead* playHead = nullptr;
/** @internal */
void sendParamChangeMessageToListeners (int parameterIndex, float newValue);
@@ -1523,12 +1526,12 @@ private:
//==============================================================================
struct InOutChannelPair
{
int16 inChannels, outChannels;
int16 inChannels = 0, outChannels = 0;
InOutChannelPair() noexcept : inChannels (0), outChannels (0) {}
InOutChannelPair (const InOutChannelPair& o) noexcept : inChannels (o.inChannels), outChannels (o.outChannels) {}
InOutChannelPair (int16 inCh, int16 outCh) noexcept : inChannels (inCh), outChannels (outCh) {}
InOutChannelPair (const int16 (&config)[2]) noexcept : inChannels (config[0]), outChannels (config[1]) {}
InOutChannelPair() noexcept {}
InOutChannelPair (const InOutChannelPair& o) noexcept : inChannels (o.inChannels), outChannels (o.outChannels) {}
InOutChannelPair (int16 inCh, int16 outCh) noexcept : inChannels (inCh), outChannels (outCh) {}
InOutChannelPair (const int16 (&config)[2]) noexcept : inChannels (config[0]), outChannels (config[1]) {}
InOutChannelPair& operator= (const InOutChannelPair& o) noexcept { inChannels = o.inChannels; outChannels = o.outChannels; return *this; }
@@ -1544,10 +1547,7 @@ private:
Array<InOutChannelPair> layouts;
for (int i = 0; i < numLayouts; ++i)
{
InOutChannelPair pair (configuration [i]);
layouts.add (pair);
}
layouts.add (InOutChannelPair (configuration[i]));
return layouts;
}
@@ -1557,12 +1557,8 @@ private:
{
Array<InOutChannelPair> layouts;
for (std::initializer_list<const short[2]>::const_iterator it = configuration.begin();
it != configuration.end(); ++it)
{
InOutChannelPair pair (*it);
layouts.add (pair);
}
for (auto&& i : configuration)
layouts.add (InOutChannelPair (i));
return layouts;
}
@@ -1575,28 +1571,22 @@ private:
static bool containsLayout (const BusesLayout&, const Array<InOutChannelPair>&);
//==============================================================================
void initialise (const BusesProperties&);
void createBus (bool isInput, const BusProperties&);
//==============================================================================
Array<AudioProcessorListener*> listeners;
Component::SafePointer<AudioProcessorEditor> activeEditor;
double currentSampleRate;
int blockSize, latencySamples;
#if JUCE_DEBUG
bool textRecursionCheck;
#endif
bool suspended, nonRealtime;
ProcessingPrecision processingPrecision;
double currentSampleRate = 0;
int blockSize = 0, latencySamples = 0;
bool suspended = false, nonRealtime = false;
ProcessingPrecision processingPrecision = singlePrecision;
CriticalSection callbackLock, listenerLock;
friend class Bus;
mutable OwnedArray<Bus> inputBuses, outputBuses;
String cachedInputSpeakerArrString;
String cachedOutputSpeakerArrString;
int cachedTotalIns, cachedTotalOuts;
String cachedInputSpeakerArrString, cachedOutputSpeakerArrString;
int cachedTotalIns = 0, cachedTotalOuts = 0;
OwnedArray<AudioProcessorParameter> managedParameters;
AudioProcessorParameter* getParamChecked (int) const noexcept;
@@ -1605,6 +1595,10 @@ private:
BigInteger changingParams;
#endif
#if JUCE_DEBUG
bool textRecursionCheck = false;
#endif
AudioProcessorListener* getListenerLocked (int) const noexcept;
void updateSpeakerFormatStrings();
bool applyBusLayouts (const BusesLayout&);


Loading…
Cancel
Save