diff --git a/modules/juce_audio_basics/buffers/juce_AudioChannelSet.cpp b/modules/juce_audio_basics/buffers/juce_AudioChannelSet.cpp index 9573d8be9a..bc101d5806 100644 --- a/modules/juce_audio_basics/buffers/juce_AudioChannelSet.cpp +++ b/modules/juce_audio_basics/buffers/juce_AudioChannelSet.cpp @@ -29,7 +29,7 @@ bool AudioChannelSet::operator< (const AudioChannelSet& other) const noexcept String AudioChannelSet::getChannelTypeName (AudioChannelSet::ChannelType type) { if (type >= discreteChannel0) - return String ("Discrete ") + String (type - discreteChannel0 + 1); + return "Discrete " + String (type - discreteChannel0 + 1); switch (type) { @@ -54,8 +54,8 @@ String AudioChannelSet::getChannelTypeName (AudioChannelSet::ChannelType type) case wideLeft: return NEEDS_TRANS("Wide Left"); case wideRight: return NEEDS_TRANS("Wide Right"); case LFE2: return NEEDS_TRANS("LFE 2"); - case leftSurroundSide: return NEEDS_TRANS ("Left Surround Side"); - case rightSurroundSide: return NEEDS_TRANS ("Right Surround Side"); + case leftSurroundSide: return NEEDS_TRANS("Left Surround Side"); + case rightSurroundSide: return NEEDS_TRANS("Right Surround Side"); case ambisonicW: return NEEDS_TRANS("Ambisonic W"); case ambisonicX: return NEEDS_TRANS("Ambisonic X"); case ambisonicY: return NEEDS_TRANS("Ambisonic Y"); @@ -103,7 +103,7 @@ String AudioChannelSet::getAbbreviatedChannelTypeName (AudioChannelSet::ChannelT default: break; } - return ""; + return {}; } AudioChannelSet::ChannelType AudioChannelSet::getChannelTypeFromAbbreviation (const String& abbr) @@ -112,33 +112,33 @@ AudioChannelSet::ChannelType AudioChannelSet::getChannelTypeFromAbbreviation (co return static_cast (static_cast (discreteChannel0) + abbr.getIntValue() + 1); - if (abbr == "L") return left; - else if (abbr == "R") return right; - else if (abbr == "C") return centre; - else if (abbr == "Lfe") return LFE; - else if (abbr == "Ls") return leftSurround; - else if (abbr == "Rs") return rightSurround; - else if (abbr == "Lc") return leftCentre; - else if (abbr == "Rc") return rightCentre; - else if (abbr == "Cs") return centreSurround; - else if (abbr == "Lrs") return leftSurroundRear; - else if (abbr == "Rrs") return rightSurroundRear; - else if (abbr == "Tm") return topMiddle; - else if (abbr == "Tfl") return topFrontLeft; - else if (abbr == "Tfc") return topFrontCentre; - else if (abbr == "Tfr") return topFrontRight; - else if (abbr == "Trl") return topRearLeft; - else if (abbr == "Trc") return topRearCentre; - else if (abbr == "Trr") return topRearRight; - else if (abbr == "Wl") return wideLeft; - else if (abbr == "Wr") return wideRight; - else if (abbr == "Lfe2") return LFE2; - else if (abbr == "Lss") return leftSurroundSide; - else if (abbr == "Rss") return rightSurroundSide; - else if (abbr == "W") return ambisonicW; - else if (abbr == "X") return ambisonicX; - else if (abbr == "Y") return ambisonicY; - else if (abbr == "Z") return ambisonicZ; + if (abbr == "L") return left; + if (abbr == "R") return right; + if (abbr == "C") return centre; + if (abbr == "Lfe") return LFE; + if (abbr == "Ls") return leftSurround; + if (abbr == "Rs") return rightSurround; + if (abbr == "Lc") return leftCentre; + if (abbr == "Rc") return rightCentre; + if (abbr == "Cs") return centreSurround; + if (abbr == "Lrs") return leftSurroundRear; + if (abbr == "Rrs") return rightSurroundRear; + if (abbr == "Tm") return topMiddle; + if (abbr == "Tfl") return topFrontLeft; + if (abbr == "Tfc") return topFrontCentre; + if (abbr == "Tfr") return topFrontRight; + if (abbr == "Trl") return topRearLeft; + if (abbr == "Trc") return topRearCentre; + if (abbr == "Trr") return topRearRight; + if (abbr == "Wl") return wideLeft; + if (abbr == "Wr") return wideRight; + if (abbr == "Lfe2") return LFE2; + if (abbr == "Lss") return leftSurroundSide; + if (abbr == "Rss") return rightSurroundSide; + if (abbr == "W") return ambisonicW; + if (abbr == "X") return ambisonicX; + if (abbr == "Y") return ambisonicY; + if (abbr == "Z") return ambisonicZ; return unknown; } @@ -146,11 +146,10 @@ AudioChannelSet::ChannelType AudioChannelSet::getChannelTypeFromAbbreviation (co String AudioChannelSet::getSpeakerArrangementAsString() const { StringArray speakerTypes; - Array speakers = getChannelTypes(); - for (int i = 0; i < speakers.size(); ++i) + for (auto& speaker : getChannelTypes()) { - String name = getAbbreviatedChannelTypeName (speakers.getReference (i)); + auto name = getAbbreviatedChannelTypeName (speaker); if (name.isNotEmpty()) speakerTypes.add (name); @@ -161,12 +160,11 @@ String AudioChannelSet::getSpeakerArrangementAsString() const AudioChannelSet AudioChannelSet::fromAbbreviatedString (const String& str) { - StringArray abbr = StringArray::fromTokens(str, true); AudioChannelSet set; - for (int i = 0; i < abbr.size(); ++i) + for (auto& abbr : StringArray::fromTokens (str, true)) { - AudioChannelSet::ChannelType type = getChannelTypeFromAbbreviation (abbr[i]); + auto type = getChannelTypeFromAbbreviation (abbr); if (type != unknown) set.addChannel (type); @@ -177,7 +175,7 @@ AudioChannelSet AudioChannelSet::fromAbbreviatedString (const String& str) String AudioChannelSet::getDescription() const { - if (isDiscreteLayout()) return String ("Discrete #") + String (size()); + if (isDiscreteLayout()) return "Discrete #" + String (size()); if (*this == disabled()) return "Disabled"; if (*this == mono()) return "Mono"; if (*this == stereo()) return "Stereo"; @@ -203,16 +201,13 @@ String AudioChannelSet::getDescription() const if (*this == octagonal()) return "Octagonal"; if (*this == ambisonic()) return "Ambisonic"; - - return "Unknown"; } bool AudioChannelSet::isDiscreteLayout() const noexcept { - Array speakers = getChannelTypes(); - for (int i = 0; i < speakers.size(); ++i) - if (speakers.getReference (i) > ambisonicZ) + for (auto& speaker : getChannelTypes()) + if (speaker > ambisonicZ) return true; return false; @@ -236,6 +231,7 @@ AudioChannelSet::ChannelType AudioChannelSet::getTypeOfChannel (int index) const int AudioChannelSet::getChannelIndexForType (AudioChannelSet::ChannelType type) const noexcept { int idx = 0; + for (int bit = channels.findNextSetBit (0); bit >= 0; bit = channels.findNextSetBit (bit + 1)) { if (static_cast (bit) == type) @@ -271,7 +267,7 @@ void AudioChannelSet::removeChannel (ChannelType newChannel) channels.clearBit (bit); } -AudioChannelSet AudioChannelSet::disabled() { return AudioChannelSet(); } +AudioChannelSet AudioChannelSet::disabled() { return {}; } AudioChannelSet AudioChannelSet::mono() { return AudioChannelSet (1u << centre); } AudioChannelSet AudioChannelSet::stereo() { return AudioChannelSet ((1u << left) | (1u << right)); } AudioChannelSet AudioChannelSet::createLCR() { return AudioChannelSet ((1u << left) | (1u << right) | (1u << centre)); } @@ -303,30 +299,30 @@ AudioChannelSet AudioChannelSet::discreteChannels (int numChannels) AudioChannelSet AudioChannelSet::canonicalChannelSet (int numChannels) { - if (numChannels == 1) return AudioChannelSet::mono(); - if (numChannels == 2) return AudioChannelSet::stereo(); - if (numChannels == 3) return AudioChannelSet::createLCR(); - if (numChannels == 4) return AudioChannelSet::quadraphonic(); - if (numChannels == 5) return AudioChannelSet::create5point0(); - if (numChannels == 6) return AudioChannelSet::create5point1(); - if (numChannels == 7) return AudioChannelSet::create7point0(); - if (numChannels == 8) return AudioChannelSet::create7point1(); + if (numChannels == 1) return AudioChannelSet::mono(); + if (numChannels == 2) return AudioChannelSet::stereo(); + if (numChannels == 3) return AudioChannelSet::createLCR(); + if (numChannels == 4) return AudioChannelSet::quadraphonic(); + if (numChannels == 5) return AudioChannelSet::create5point0(); + if (numChannels == 6) return AudioChannelSet::create5point1(); + if (numChannels == 7) return AudioChannelSet::create7point0(); + if (numChannels == 8) return AudioChannelSet::create7point1(); return discreteChannels (numChannels); } AudioChannelSet AudioChannelSet::namedChannelSet (int numChannels) { - if (numChannels == 1) return AudioChannelSet::mono(); - if (numChannels == 2) return AudioChannelSet::stereo(); - if (numChannels == 3) return AudioChannelSet::createLCR(); - if (numChannels == 4) return AudioChannelSet::quadraphonic(); - if (numChannels == 5) return AudioChannelSet::create5point0(); - if (numChannels == 6) return AudioChannelSet::create5point1(); - if (numChannels == 7) return AudioChannelSet::create7point0(); - if (numChannels == 8) return AudioChannelSet::create7point1(); - - return AudioChannelSet(); + if (numChannels == 1) return AudioChannelSet::mono(); + if (numChannels == 2) return AudioChannelSet::stereo(); + if (numChannels == 3) return AudioChannelSet::createLCR(); + if (numChannels == 4) return AudioChannelSet::quadraphonic(); + if (numChannels == 5) return AudioChannelSet::create5point0(); + if (numChannels == 6) return AudioChannelSet::create5point1(); + if (numChannels == 7) return AudioChannelSet::create7point0(); + if (numChannels == 8) return AudioChannelSet::create7point1(); + + return {}; } Array AudioChannelSet::channelSetsWithNumberOfChannels (int numChannels) diff --git a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp index 20559c16cb..34fcee13f8 100644 --- a/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp +++ b/modules/juce_audio_plugin_client/VST/juce_VST_Wrapper.cpp @@ -157,9 +157,8 @@ namespace //============================================================================== #elif JUCE_LINUX -class SharedMessageThread : public Thread +struct SharedMessageThread : public Thread { -public: SharedMessageThread() : Thread ("VstMessageThread"), initialised (false) @@ -235,8 +234,8 @@ private: void release() noexcept { - for (int i = tempChannels.size(); --i >= 0;) - delete[] (tempChannels.getUnchecked(i)); + for (auto* c : tempChannels) + delete[] c; tempChannels.clear(); } @@ -257,43 +256,28 @@ private: public: //============================================================================== - JuceVSTWrapper (VstHostCallback cb, AudioProcessor* const af) + JuceVSTWrapper (VstHostCallback cb, AudioProcessor* af) : hostCallback (cb), - sampleRate (44100.f), - blockSize (1024), - filter (af), - chunkMemoryTime (0), - isProcessing (false), - isBypassed (false), - hasShutdown (false), - isInSizeWindow (false), - firstProcessCallback (true), - shouldDeleteEditor (false), - #if JUCE_64BIT - useNSView (true), - #else - useNSView (false), - #endif - hostWindow (0) + processor (af) { // VST-2 does not support disabling buses: so always enable all of them - filter->enableAllBuses(); + processor->enableAllBuses(); findMaxTotalChannels (maxNumInChannels, maxNumOutChannels); // You must at least have some channels - jassert (filter->isMidiEffect() || (maxNumInChannels > 0 || maxNumOutChannels > 0)); + jassert (processor->isMidiEffect() || (maxNumInChannels > 0 || maxNumOutChannels > 0)); - if (filter->isMidiEffect()) + if (processor->isMidiEffect()) maxNumInChannels = maxNumOutChannels = 2; #ifdef JucePlugin_PreferredChannelConfigurations - filter->setPlayConfigDetails (maxNumInChannels, maxNumOutChannels, 44100.0, 1024); + processor->setPlayConfigDetails (maxNumInChannels, maxNumOutChannels, 44100.0, 1024); #endif - filter->setRateAndBufferSizeDetails (0, 0); - filter->setPlayHead (this); - filter->addListener (this); + processor->setRateAndBufferSizeDetails (0, 0); + processor->setPlayHead (this); + processor->addListener (this); memset (&vstEffect, 0, sizeof (vstEffect)); vstEffect.interfaceIdentifier = juceVstInterfaceIdentifier; @@ -305,7 +289,7 @@ public: vstEffect.numParameters = af->getNumParameters(); vstEffect.numInputChannels = maxNumInChannels; vstEffect.numOutputChannels = maxNumOutChannels; - vstEffect.latency = filter->getLatencySamples(); + vstEffect.latency = processor->getLatencySamples(); vstEffect.effectPointer = this; vstEffect.plugInIdentifier = JucePlugin_VSTUniqueID; @@ -321,7 +305,7 @@ public: vstEffect.flags |= vstEffectFlagHasEditor; vstEffect.flags |= vstEffectFlagInplaceAudio; - if (filter->supportsDoublePrecisionProcessing()) + if (processor->supportsDoublePrecisionProcessing()) vstEffect.flags |= vstEffectFlagInplaceDoubleAudio; #if JucePlugin_IsSynth @@ -350,10 +334,10 @@ public: hasShutdown = true; - delete filter; - filter = nullptr; + delete processor; + processor = nullptr; - jassert (editorComp == 0); + jassert (editorComp == nullptr); deleteTempChannels(); @@ -377,7 +361,6 @@ public: display = XWindowSystem::getInstance()->displayUnref(); #endif } - } VstEffectInterface* getVstEffectInterface() noexcept { return &vstEffect; } @@ -386,7 +369,7 @@ public: void internalProcessReplacing (FloatType** inputs, FloatType** outputs, int32 numSamples, VstTempBuffers& tmpBuffers) { - const bool isMidiEffect = filter->isMidiEffect(); + const bool isMidiEffect = processor->isMidiEffect(); if (firstProcessCallback) { @@ -400,7 +383,7 @@ public: if (! isProcessing) resume(); - filter->setNonRealtime (isProcessLevelOffline()); + processor->setNonRealtime (isProcessLevelOffline()); #if JUCE_WINDOWS if (getHostType().isWavelab()) @@ -408,7 +391,7 @@ public: int priority = GetThreadPriority (GetCurrentThread()); if (priority <= THREAD_PRIORITY_NORMAL && priority >= THREAD_PRIORITY_LOWEST) - filter->setNonRealtime (true); + processor->setNonRealtime (true); } #endif } @@ -420,12 +403,12 @@ public: jassert (activePlugins.contains (this)); { - const int numIn = filter->getTotalNumInputChannels(); - const int numOut = filter->getTotalNumOutputChannels(); + const int numIn = processor->getTotalNumInputChannels(); + const int numOut = processor->getTotalNumOutputChannels(); - const ScopedLock sl (filter->getCallbackLock()); + const ScopedLock sl (processor->getCallbackLock()); - if (filter->isSuspended()) + if (processor->isSuspended()) { for (int i = 0; i < numOut; ++i) if (outputs[i] != nullptr) @@ -436,7 +419,7 @@ public: int i; for (i = 0; i < numOut; ++i) { - FloatType* chan = tmpBuffers.tempChannels.getUnchecked(i); + auto* chan = tmpBuffers.tempChannels.getUnchecked(i); if (chan == nullptr) { @@ -485,19 +468,16 @@ public: AudioBuffer chans (tmpBuffers.channels, isMidiEffect ? 0 : numChannels, numSamples); if (isBypassed) - filter->processBlockBypassed (chans, midiEvents); + processor->processBlockBypassed (chans, midiEvents); else - filter->processBlock (chans, midiEvents); + processor->processBlock (chans, midiEvents); } // copy back any temp channels that may have been used.. for (i = 0; i < numOut; ++i) - { - const FloatType* const chan = tmpBuffers.tempChannels.getUnchecked(i); - - if (chan != nullptr && outputs[i] != nullptr) - memcpy (outputs[i], chan, sizeof (FloatType) * (size_t) numSamples); - } + if (auto* chan = tmpBuffers.tempChannels.getUnchecked(i)) + if (auto* dest = outputs[i]) + memcpy (dest, chan, sizeof (FloatType) * (size_t) numSamples); } } @@ -547,7 +527,7 @@ public: void processReplacing (float** inputs, float** outputs, int32 sampleFrames) { - jassert (! filter->isUsingDoublePrecision()); + jassert (! processor->isUsingDoublePrecision()); internalProcessReplacing (inputs, outputs, sampleFrames, floatTempBuffers); } @@ -558,7 +538,7 @@ public: void processDoubleReplacing (double** inputs, double** outputs, int32 sampleFrames) { - jassert (filter->isUsingDoublePrecision()); + jassert (processor->isUsingDoublePrecision()); internalProcessReplacing (inputs, outputs, sampleFrames, doubleTempBuffers); } @@ -570,30 +550,30 @@ public: //============================================================================== void resume() { - if (filter != nullptr) + if (processor != nullptr) { isProcessing = true; - const size_t nInAndOutChannels = static_cast (vstEffect.numInputChannels + vstEffect.numOutputChannels); - floatTempBuffers .channels.calloc (nInAndOutChannels); - doubleTempBuffers.channels.calloc (nInAndOutChannels); + auto numInAndOutChannels = static_cast (vstEffect.numInputChannels + vstEffect.numOutputChannels); + floatTempBuffers .channels.calloc (numInAndOutChannels); + doubleTempBuffers.channels.calloc (numInAndOutChannels); - const double currentRate = sampleRate; - const int currentBlockSize = blockSize; + auto currentRate = sampleRate; + auto currentBlockSize = blockSize; firstProcessCallback = true; - filter->setNonRealtime (isProcessLevelOffline()); - filter->setRateAndBufferSizeDetails (currentRate, currentBlockSize); + processor->setNonRealtime (isProcessLevelOffline()); + processor->setRateAndBufferSizeDetails (currentRate, currentBlockSize); deleteTempChannels(); - filter->prepareToPlay (currentRate, currentBlockSize); + processor->prepareToPlay (currentRate, currentBlockSize); midiEvents.ensureSize (2048); midiEvents.clear(); - vstEffect.latency = filter->getLatencySamples(); + vstEffect.latency = processor->getLatencySamples(); /** If this plug-in is a synth or it can receive midi events we need to tell the host that we want midi. In the SDK this method is marked as deprecated, but @@ -607,7 +587,7 @@ public: if (getHostType().isAbletonLive() && hostCallback != nullptr - && filter->getTailLengthSeconds() == std::numeric_limits::max()) + && processor->getTailLengthSeconds() == std::numeric_limits::max()) { AbletonLiveHostSpecific hostCmd; @@ -627,9 +607,9 @@ public: void suspend() { - if (filter != nullptr) + if (processor != nullptr) { - filter->releaseResources(); + processor->releaseResources(); outgoingEvents.freeEvents(); isProcessing = false; @@ -652,7 +632,7 @@ public: | vstTimingInfoFlagTimeSignatureValid | vstTimingInfoFlagSmpteValid | vstTimingInfoFlagNearestClockValid; - pointer_sized_int result = hostCallback (&vstEffect, hostOpcodeGetTimingInfo, 0, flags, 0, 0); + auto result = hostCallback (&vstEffect, hostOpcodeGetTimingInfo, 0, flags, 0, 0); ti = reinterpret_cast (result); } @@ -732,11 +712,11 @@ public: //============================================================================== float getParameter (int32 index) const { - if (filter == nullptr) + if (processor == nullptr) return 0.0f; - jassert (isPositiveAndBelow (index, filter->getNumParameters())); - return filter->getParameter (index); + jassert (isPositiveAndBelow (index, processor->getNumParameters())); + return processor->getParameter (index); } static float getParameterCB (VstEffectInterface* vstInterface, int32 index) @@ -746,10 +726,10 @@ public: void setParameter (int32 index, float value) { - if (filter != nullptr) + if (processor != nullptr) { - jassert (isPositiveAndBelow (index, filter->getNumParameters())); - filter->setParameter (index, value); + jassert (isPositiveAndBelow (index, processor->getNumParameters())); + processor->setParameter (index, value); } } @@ -778,7 +758,7 @@ public: void audioProcessorChanged (AudioProcessor*) override { - vstEffect.latency = filter->getLatencySamples(); + vstEffect.latency = processor->getLatencySamples(); if (hostCallback != nullptr) hostCallback (&vstEffect, hostOpcodeUpdateView, 0, 0, 0, 0); @@ -794,7 +774,7 @@ public: bool getPinProperties (VstPinInfo& properties, bool direction, int index) const { - if (filter->isMidiEffect()) + if (processor->isMidiEffect()) return false; int channelIdx, busIdx; @@ -805,21 +785,21 @@ public: properties.shortText[0] = 0; properties.configurationType = vstSpeakerConfigTypeEmpty; - if ((channelIdx = filter->getOffsetInBusBufferForAbsoluteChannelIndex (direction, index, busIdx)) >= 0) + if ((channelIdx = processor->getOffsetInBusBufferForAbsoluteChannelIndex (direction, index, busIdx)) >= 0) { - AudioProcessor::Bus& bus = *filter->getBus (direction, busIdx); - const AudioChannelSet& channelSet = bus.getCurrentLayout(); - AudioChannelSet::ChannelType channelType = channelSet.getTypeOfChannel (channelIdx); + auto& bus = *processor->getBus (direction, busIdx); + auto& channelSet = bus.getCurrentLayout(); + auto channelType = channelSet.getTypeOfChannel (channelIdx); properties.flags = vstPinInfoFlagIsActive | vstPinInfoFlagValid; properties.configurationType = SpeakerMappings::channelSetToVstArrangementType (channelSet); String label = bus.getName(); #ifdef JucePlugin_PreferredChannelConfigurations - label += String (" ") + String (channelIdx); + label += " " + String (channelIdx); #else if (channelSet.size() > 1) - label += String (" ") + AudioChannelSet::getAbbreviatedChannelTypeName (channelType); + label += " " + AudioChannelSet::getAbbreviatedChannelTypeName (channelType); #endif label.copyToUTF8 (properties.text, (size_t) (vstMaxParameterOrPinLabelLength + 1)); @@ -868,25 +848,25 @@ public: static AudioChannelSet vstArrangementTypeToChannelSet (const VstSpeakerConfiguration& arr) { - if (arr.type == vstSpeakerConfigTypeEmpty) return AudioChannelSet::disabled(); - else if (arr.type == vstSpeakerConfigTypeMono) return AudioChannelSet::mono(); - else if (arr.type == vstSpeakerConfigTypeLR) return AudioChannelSet::stereo(); - else if (arr.type == vstSpeakerConfigTypeLRC) return AudioChannelSet::createLCR(); - else if (arr.type == vstSpeakerConfigTypeLRS) return AudioChannelSet::createLRS(); - else if (arr.type == vstSpeakerConfigTypeLRCS) return AudioChannelSet::createLCRS(); - else if (arr.type == vstSpeakerConfigTypeLRCLsRs) return AudioChannelSet::create5point0(); - else if (arr.type == vstSpeakerConfigTypeLRCLfeLsRs) return AudioChannelSet::create5point1(); - else if (arr.type == vstSpeakerConfigTypeLRCLsRsCs) return AudioChannelSet::create6point0(); - else if (arr.type == vstSpeakerConfigTypeLRCLfeLsRsCs) return AudioChannelSet::create6point1(); - else if (arr.type == vstSpeakerConfigTypeLRLsRsSlSr) return AudioChannelSet::create6point0Music(); - else if (arr.type == vstSpeakerConfigTypeLRLfeLsRsSlSr) return AudioChannelSet::create6point1Music(); - else if (arr.type == vstSpeakerConfigTypeLRCLsRsSlSr) return AudioChannelSet::create7point0(); - else if (arr.type == vstSpeakerConfigTypeLRCLsRsLcRc) return AudioChannelSet::create7point0SDDS(); - else if (arr.type == vstSpeakerConfigTypeLRCLfeLsRsSlSr) return AudioChannelSet::create7point1(); - else if (arr.type == vstSpeakerConfigTypeLRCLfeLsRsLcRc) return AudioChannelSet::create7point1SDDS(); - else if (arr.type == vstSpeakerConfigTypeLRLsRs) return AudioChannelSet::quadraphonic(); - - for (const Mapping* m = getMappings(); m->vst2 != vstSpeakerConfigTypeEmpty; ++m) + if (arr.type == vstSpeakerConfigTypeEmpty) return AudioChannelSet::disabled(); + if (arr.type == vstSpeakerConfigTypeMono) return AudioChannelSet::mono(); + if (arr.type == vstSpeakerConfigTypeLR) return AudioChannelSet::stereo(); + if (arr.type == vstSpeakerConfigTypeLRC) return AudioChannelSet::createLCR(); + if (arr.type == vstSpeakerConfigTypeLRS) return AudioChannelSet::createLRS(); + if (arr.type == vstSpeakerConfigTypeLRCS) return AudioChannelSet::createLCRS(); + if (arr.type == vstSpeakerConfigTypeLRCLsRs) return AudioChannelSet::create5point0(); + if (arr.type == vstSpeakerConfigTypeLRCLfeLsRs) return AudioChannelSet::create5point1(); + if (arr.type == vstSpeakerConfigTypeLRCLsRsCs) return AudioChannelSet::create6point0(); + if (arr.type == vstSpeakerConfigTypeLRCLfeLsRsCs) return AudioChannelSet::create6point1(); + if (arr.type == vstSpeakerConfigTypeLRLsRsSlSr) return AudioChannelSet::create6point0Music(); + if (arr.type == vstSpeakerConfigTypeLRLfeLsRsSlSr) return AudioChannelSet::create6point1Music(); + if (arr.type == vstSpeakerConfigTypeLRCLsRsSlSr) return AudioChannelSet::create7point0(); + if (arr.type == vstSpeakerConfigTypeLRCLsRsLcRc) return AudioChannelSet::create7point0SDDS(); + if (arr.type == vstSpeakerConfigTypeLRCLfeLsRsSlSr) return AudioChannelSet::create7point1(); + if (arr.type == vstSpeakerConfigTypeLRCLfeLsRsLcRc) return AudioChannelSet::create7point1SDDS(); + if (arr.type == vstSpeakerConfigTypeLRLsRs) return AudioChannelSet::quadraphonic(); + + for (auto* m = getMappings(); m->vst2 != vstSpeakerConfigTypeEmpty; ++m) { if (m->vst2 == arr.type) { @@ -904,30 +884,30 @@ public: static int32 channelSetToVstArrangementType (AudioChannelSet channels) { - if (channels == AudioChannelSet::disabled()) return vstSpeakerConfigTypeEmpty; - else if (channels == AudioChannelSet::mono()) return vstSpeakerConfigTypeMono; - else if (channels == AudioChannelSet::stereo()) return vstSpeakerConfigTypeLR; - else if (channels == AudioChannelSet::createLCR()) return vstSpeakerConfigTypeLRC; - else if (channels == AudioChannelSet::createLRS()) return vstSpeakerConfigTypeLRS; - else if (channels == AudioChannelSet::createLCRS()) return vstSpeakerConfigTypeLRCS; - else if (channels == AudioChannelSet::create5point0()) return vstSpeakerConfigTypeLRCLsRs; - else if (channels == AudioChannelSet::create5point1()) return vstSpeakerConfigTypeLRCLfeLsRs; - else if (channels == AudioChannelSet::create6point0()) return vstSpeakerConfigTypeLRCLsRsCs; - else if (channels == AudioChannelSet::create6point1()) return vstSpeakerConfigTypeLRCLfeLsRsCs; - else if (channels == AudioChannelSet::create6point0Music()) return vstSpeakerConfigTypeLRLsRsSlSr; - else if (channels == AudioChannelSet::create6point1Music()) return vstSpeakerConfigTypeLRLfeLsRsSlSr; - else if (channels == AudioChannelSet::create7point0()) return vstSpeakerConfigTypeLRCLsRsSlSr; - else if (channels == AudioChannelSet::create7point0SDDS()) return vstSpeakerConfigTypeLRCLsRsLcRc; - else if (channels == AudioChannelSet::create7point1()) return vstSpeakerConfigTypeLRCLfeLsRsSlSr; - else if (channels == AudioChannelSet::create7point1SDDS()) return vstSpeakerConfigTypeLRCLfeLsRsLcRc; - else if (channels == AudioChannelSet::quadraphonic()) return vstSpeakerConfigTypeLRLsRs; - - Array chans (channels.getChannelTypes()); + if (channels == AudioChannelSet::disabled()) return vstSpeakerConfigTypeEmpty; + if (channels == AudioChannelSet::mono()) return vstSpeakerConfigTypeMono; + if (channels == AudioChannelSet::stereo()) return vstSpeakerConfigTypeLR; + if (channels == AudioChannelSet::createLCR()) return vstSpeakerConfigTypeLRC; + if (channels == AudioChannelSet::createLRS()) return vstSpeakerConfigTypeLRS; + if (channels == AudioChannelSet::createLCRS()) return vstSpeakerConfigTypeLRCS; + if (channels == AudioChannelSet::create5point0()) return vstSpeakerConfigTypeLRCLsRs; + if (channels == AudioChannelSet::create5point1()) return vstSpeakerConfigTypeLRCLfeLsRs; + if (channels == AudioChannelSet::create6point0()) return vstSpeakerConfigTypeLRCLsRsCs; + if (channels == AudioChannelSet::create6point1()) return vstSpeakerConfigTypeLRCLfeLsRsCs; + if (channels == AudioChannelSet::create6point0Music()) return vstSpeakerConfigTypeLRLsRsSlSr; + if (channels == AudioChannelSet::create6point1Music()) return vstSpeakerConfigTypeLRLfeLsRsSlSr; + if (channels == AudioChannelSet::create7point0()) return vstSpeakerConfigTypeLRCLsRsSlSr; + if (channels == AudioChannelSet::create7point0SDDS()) return vstSpeakerConfigTypeLRCLsRsLcRc; + if (channels == AudioChannelSet::create7point1()) return vstSpeakerConfigTypeLRCLfeLsRsSlSr; + if (channels == AudioChannelSet::create7point1SDDS()) return vstSpeakerConfigTypeLRCLfeLsRsLcRc; + if (channels == AudioChannelSet::quadraphonic()) return vstSpeakerConfigTypeLRLsRs; if (channels == AudioChannelSet::disabled()) return vstSpeakerConfigTypeEmpty; - for (const Mapping* m = getMappings(); m->vst2 != vstSpeakerConfigTypeEmpty; ++m) + auto chans = channels.getChannelTypes(); + + for (auto* m = getMappings(); m->vst2 != vstSpeakerConfigTypeEmpty; ++m) if (m->matches (chans)) return m->vst2; @@ -941,7 +921,7 @@ public: for (int i = 0; i < result.numberOfChannels; ++i) { - VstIndividualSpeakerInfo& speaker = result.speakers[i]; + auto& speaker = result.speakers[i]; zeromem (&speaker, sizeof (VstIndividualSpeakerInfo)); speaker.type = getSpeakerType (channels.getTypeOfChannel (i)); @@ -1070,18 +1050,18 @@ public: void createEditorComp() { - if (hasShutdown || filter == nullptr) + if (hasShutdown || processor == nullptr) return; if (editorComp == nullptr) { - if (AudioProcessorEditor* const ed = filter->createEditorIfNeeded()) + if (auto* ed = processor->createEditorIfNeeded()) { vstEffect.flags |= vstEffectFlagHasEditor; ed->setOpaque (true); ed->setVisible (true); - editorComp = new EditorCompWrapper (*this, ed); + editorComp = new EditorCompWrapper (*this, *ed); } else { @@ -1103,7 +1083,7 @@ public: if (editorComp != nullptr) { - if (Component* const modalComponent = Component::getCurrentlyModalComponent()) + if (auto* modalComponent = Component::getCurrentlyModalComponent()) { modalComponent->exitModalState (0); @@ -1122,7 +1102,7 @@ public: } #endif - filter->editorBeingDeleted (editorComp->getEditorComp()); + processor->editorBeingDeleted (editorComp->getEditorComp()); editorComp = nullptr; @@ -1193,7 +1173,7 @@ public: static pointer_sized_int dispatcherCB (VstEffectInterface* vstInterface, int32 opCode, int32 index, pointer_sized_int value, void* ptr, float opt) { - JuceVSTWrapper* wrapper = getWrapper (vstInterface); + auto* wrapper = getWrapper (vstInterface); VstOpCodeArguments args = { index, value, ptr, opt }; if (opCode == plugInOpcodeClose) @@ -1277,7 +1257,7 @@ public: #endif } - if (ComponentPeer* peer = editorComp->getPeer()) + if (auto* peer = editorComp->getPeer()) { peer->handleMovedOrResized(); peer->getComponent().repaint(); @@ -1288,17 +1268,15 @@ public: //============================================================================== // A component to hold the AudioProcessorEditor, and cope with some housekeeping // chores when it changes or repaints. - class EditorCompWrapper : public Component + struct EditorCompWrapper : public Component { - public: - EditorCompWrapper (JuceVSTWrapper& w, AudioProcessorEditor* editor) - : wrapper (w) + EditorCompWrapper (JuceVSTWrapper& w, AudioProcessorEditor& editor) : wrapper (w) { setOpaque (true); - editor->setOpaque (true); + editor.setOpaque (true); - setBounds (editor->getBounds()); - editor->setTopLeftPosition (0, 0); + setBounds (editor.getBounds()); + editor.setTopLeftPosition (0, 0); addAndMakeVisible (editor); #if JUCE_WINDOWS @@ -1333,7 +1311,7 @@ public: void resized() override { - if (Component* const editorChildComp = getChildComponent(0)) + if (auto* editorChildComp = getChildComponent(0)) editorChildComp->setBounds (getLocalBounds()); #if JUCE_MAC && ! JUCE_64BIT @@ -1409,38 +1387,47 @@ public: //============================================================================== private: VstHostCallback hostCallback; - float sampleRate; - int32 blockSize; + AudioProcessor* processor = {}; + double sampleRate = 44100.0; + int32 blockSize = 1024; VstEffectInterface vstEffect; - AudioProcessor* filter; juce::MemoryBlock chunkMemory; - juce::uint32 chunkMemoryTime; + juce::uint32 chunkMemoryTime = 0; ScopedPointer editorComp; VstEditorBounds editorBounds; MidiBuffer midiEvents; VSTMidiEventList outgoingEvents; - bool isProcessing, isBypassed, hasShutdown, isInSizeWindow, firstProcessCallback; - bool shouldDeleteEditor, useNSView; + + bool isProcessing = false, isBypassed = false, hasShutdown = false, isInSizeWindow = false; + bool firstProcessCallback = true, shouldDeleteEditor = false; + + #if JUCE_64BIT + bool useNSView = true; + #else + bool useNSView = false; + #endif + VstTempBuffers floatTempBuffers; VstTempBuffers doubleTempBuffers; - int maxNumInChannels, maxNumOutChannels; + int maxNumInChannels = 0, maxNumOutChannels = 0; HeapBlock cachedInArrangement, cachedOutArrangement; #if JUCE_MAC - void* hostWindow; + void* hostWindow = {}; #elif JUCE_LINUX - ::Display* display; - Window hostWindow; + ::Display* display = {}; + Window hostWindow = {}; #else - HWND hostWindow; + HWND hostWindow = {}; #endif - static JuceVSTWrapper* getWrapper (VstEffectInterface* vstInterface) noexcept { return static_cast (vstInterface->effectPointer); } + static JuceVSTWrapper* getWrapper (VstEffectInterface* v) noexcept { return static_cast (v->effectPointer); } bool isProcessLevelOffline() { - return hostCallback != nullptr && (int32) hostCallback (&vstEffect, hostOpcodeGetCurrentAudioProcessingLevel, 0, 0, 0, 0) == 4; + return hostCallback != nullptr + && (int32) hostCallback (&vstEffect, hostOpcodeGetCurrentAudioProcessingLevel, 0, 0, 0, 0) == 4; } static inline int32 convertHexVersionToDecimal (const unsigned int hexVersion) @@ -1460,7 +1447,7 @@ private: // Workarounds for hosts which attempt to open editor windows on a non-GUI thread.. (Grrrr...) static void checkWhetherMessageThreadIsCorrect() { - const PluginHostType host (getHostType()); + auto host = getHostType(); if (host.isWavelab() || host.isCubaseBridged() || host.isPremiere()) { @@ -1490,11 +1477,9 @@ private: { tmpBuffers.release(); - if (filter != nullptr) - { - const int nInputAndOutputChannels = vstEffect.numInputChannels + vstEffect.numOutputChannels; - tmpBuffers.tempChannels.insertMultiple (0, nullptr, nInputAndOutputChannels); - } + if (processor != nullptr) + tmpBuffers.tempChannels.insertMultiple (0, nullptr, vstEffect.numInputChannels + + vstEffect.numOutputChannels); } void deleteTempChannels() @@ -1507,36 +1492,37 @@ private: void findMaxTotalChannels (int& maxTotalIns, int& maxTotalOuts) { #ifdef JucePlugin_PreferredChannelConfigurations - int configs[][2] = {JucePlugin_PreferredChannelConfigurations}; + int configs[][2] = { JucePlugin_PreferredChannelConfigurations }; maxTotalIns = maxTotalOuts = 0; + for (auto& config : configs) { maxTotalIns = jmax (maxTotalIns, config[0]); maxTotalOuts = jmax (maxTotalOuts, config[1]); } #else - const int numInputBuses = filter->getBusCount (true); - const int numOutputBuses = filter->getBusCount (false); + auto numInputBuses = processor->getBusCount (true); + auto numOutputBuses = processor->getBusCount (false); if (numInputBuses > 1 || numOutputBuses > 1) { maxTotalIns = maxTotalOuts = 0; for (int i = 0; i < numInputBuses; ++i) - maxTotalIns += filter->getChannelCountOfBus (true, i); + maxTotalIns += processor->getChannelCountOfBus (true, i); for (int i = 0; i < numOutputBuses; ++i) - maxTotalOuts += filter->getChannelCountOfBus (false, i); + maxTotalOuts += processor->getChannelCountOfBus (false, i); } else { - maxTotalIns = numInputBuses > 0 ? filter->getBus (true, 0)->getMaxSupportedChannels (64) : 0; - maxTotalOuts = numOutputBuses > 0 ? filter->getBus (false, 0)->getMaxSupportedChannels (64) : 0; + maxTotalIns = numInputBuses > 0 ? processor->getBus (true, 0)->getMaxSupportedChannels (64) : 0; + maxTotalOuts = numOutputBuses > 0 ? processor->getBus (false, 0)->getMaxSupportedChannels (64) : 0; } #endif } - bool pluginHasSidechainsOrAuxs() const { return (filter->getBusCount (true) > 1 || filter->getBusCount (false) > 1); } + bool pluginHasSidechainsOrAuxs() const { return (processor->getBusCount (true) > 1 || processor->getBusCount (false) > 1); } //============================================================================== /** Host to plug-in calls. */ @@ -1544,7 +1530,7 @@ private: pointer_sized_int handleOpen (VstOpCodeArguments) { // Note: most hosts call this on the UI thread, but wavelab doesn't, so be careful in here. - if (filter->hasEditor()) + if (processor->hasEditor()) vstEffect.flags |= vstEffectFlagHasEditor; else vstEffect.flags &= ~vstEffectFlagHasEditor; @@ -1565,40 +1551,40 @@ private: pointer_sized_int handleSetCurrentProgram (VstOpCodeArguments args) { - if (filter != nullptr && isPositiveAndBelow((int) args.value, filter->getNumPrograms())) - filter->setCurrentProgram ((int) args.value); + if (processor != nullptr && isPositiveAndBelow ((int) args.value, processor->getNumPrograms())) + processor->setCurrentProgram ((int) args.value); return 0; } pointer_sized_int handleGetCurrentProgram (VstOpCodeArguments) { - return (filter != nullptr && filter->getNumPrograms() > 0 ? filter->getCurrentProgram() : 0); + return (processor != nullptr && processor->getNumPrograms() > 0 ? processor->getCurrentProgram() : 0); } pointer_sized_int handleSetCurrentProgramName (VstOpCodeArguments args) { - if (filter != nullptr && filter->getNumPrograms() > 0) - filter->changeProgramName (filter->getCurrentProgram(), (char*) args.ptr); + if (processor != nullptr && processor->getNumPrograms() > 0) + processor->changeProgramName (processor->getCurrentProgram(), (char*) args.ptr); return 0; } pointer_sized_int handleGetCurrentProgramName (VstOpCodeArguments args) { - if (filter != nullptr && filter->getNumPrograms() > 0) - filter->getProgramName (filter->getCurrentProgram()).copyToUTF8 ((char*) args.ptr, 24 + 1); + if (processor != nullptr && processor->getNumPrograms() > 0) + processor->getProgramName (processor->getCurrentProgram()).copyToUTF8 ((char*) args.ptr, 24 + 1); return 0; } pointer_sized_int handleGetParameterLabel (VstOpCodeArguments args) { - if (filter != nullptr) + if (processor != nullptr) { - jassert (isPositiveAndBelow (args.index, filter->getNumParameters())); + jassert (isPositiveAndBelow (args.index, processor->getNumParameters())); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more. - filter->getParameterLabel (args.index).copyToUTF8 ((char*) args.ptr, 24 + 1); + processor->getParameterLabel (args.index).copyToUTF8 ((char*) args.ptr, 24 + 1); } return 0; @@ -1606,11 +1592,11 @@ private: pointer_sized_int handleGetParameterText (VstOpCodeArguments args) { - if (filter != nullptr) + if (processor != nullptr) { - jassert (isPositiveAndBelow (args.index, filter->getNumParameters())); + jassert (isPositiveAndBelow (args.index, processor->getNumParameters())); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more. - filter->getParameterText (args.index, 24).copyToUTF8 ((char*) args.ptr, 24 + 1); + processor->getParameterText (args.index, 24).copyToUTF8 ((char*) args.ptr, 24 + 1); } return 0; @@ -1618,11 +1604,11 @@ private: pointer_sized_int handleGetParameterName (VstOpCodeArguments args) { - if (filter != nullptr) + if (processor != nullptr) { - jassert (isPositiveAndBelow (args.index, filter->getNumParameters())); + jassert (isPositiveAndBelow (args.index, processor->getNumParameters())); // length should technically be kVstMaxParamStrLen, which is 8, but hosts will normally allow a bit more. - filter->getParameterName (args.index, 32).copyToUTF8 ((char*) args.ptr, 32 + 1); + processor->getParameterName (args.index, 32).copyToUTF8 ((char*) args.ptr, 32 + 1); } return 0; @@ -1665,7 +1651,7 @@ private: *((VstEditorBounds**) args.ptr) = &editorBounds; - return (pointer_sized_int) (pointer_sized_int) &editorBounds; + return (pointer_sized_int) &editorBounds; } return 0; @@ -1677,7 +1663,7 @@ private: const MessageManagerLock mmLock; jassert (! recursionCheck); - startTimer (1000 / 4); // performs misc housekeeping chores + startTimerHz (4); // performs misc housekeeping chores deleteEditor (true); createEditorComp(); @@ -1715,17 +1701,17 @@ private: pointer_sized_int handleGetData (VstOpCodeArguments args) { - void** data = (void**) args.ptr; - bool onlyStoreCurrentProgramData = (args.index != 0); - - if (filter == nullptr) + if (processor == nullptr) return 0; + auto data = (void**) args.ptr; + bool onlyStoreCurrentProgramData = (args.index != 0); + chunkMemory.reset(); if (onlyStoreCurrentProgramData) - filter->getCurrentProgramStateInformation (chunkMemory); + processor->getCurrentProgramStateInformation (chunkMemory); else - filter->getStateInformation (chunkMemory); + processor->getStateInformation (chunkMemory); *data = (void*) chunkMemory.getData(); @@ -1738,21 +1724,21 @@ private: pointer_sized_int handleSetData (VstOpCodeArguments args) { - void* data = args.ptr; - int32 byteSize = (int32) args.value; - bool onlyRestoreCurrentProgramData = (args.index != 0); - - if (filter != nullptr) + if (processor != nullptr) { + void* data = args.ptr; + int32 byteSize = (int32) args.value; + bool onlyRestoreCurrentProgramData = (args.index != 0); + chunkMemory.reset(); chunkMemoryTime = 0; if (byteSize > 0 && data != nullptr) { if (onlyRestoreCurrentProgramData) - filter->setCurrentProgramStateInformation (data, byteSize); + processor->setCurrentProgramStateInformation (data, byteSize); else - filter->setStateInformation (data, byteSize); + processor->setStateInformation (data, byteSize); } } @@ -1772,22 +1758,22 @@ private: pointer_sized_int handleIsParameterAutomatable (VstOpCodeArguments args) { - if (filter == nullptr) + if (processor == nullptr) return 0; - const bool isMeter = (((filter->getParameterCategory (args.index) & 0xffff0000) >> 16) == 2); - return (filter->isParameterAutomatable (args.index) && (! isMeter) ? 1 : 0); + const bool isMeter = (((processor->getParameterCategory (args.index) & 0xffff0000) >> 16) == 2); + return (processor->isParameterAutomatable (args.index) && (! isMeter) ? 1 : 0); } pointer_sized_int handleParameterValueForText (VstOpCodeArguments args) { - if (filter != nullptr) + if (processor != nullptr) { - jassert (isPositiveAndBelow (args.index, filter->getNumParameters())); + jassert (isPositiveAndBelow (args.index, processor->getNumParameters())); - if (AudioProcessorParameter* p = filter->getParameters()[args.index]) + if (auto* p = processor->getParameters()[args.index]) { - filter->setParameter (args.index, p->getValueForText (String::fromUTF8 ((char*) args.ptr))); + processor->setParameter (args.index, p->getValueForText (String::fromUTF8 ((char*) args.ptr))); return 1; } } @@ -1797,9 +1783,9 @@ private: pointer_sized_int handleGetProgramName (VstOpCodeArguments args) { - if (filter != nullptr && isPositiveAndBelow (args.index, filter->getNumPrograms())) + if (processor != nullptr && isPositiveAndBelow (args.index, processor->getNumPrograms())) { - filter->getProgramName (args.index).copyToUTF8 ((char*) args.ptr, 24 + 1); + processor->getProgramName (args.index).copyToUTF8 ((char*) args.ptr, 24 + 1); return 1; } @@ -1808,12 +1794,12 @@ private: pointer_sized_int handleGetInputPinProperties (VstOpCodeArguments args) { - return (filter != nullptr && getPinProperties (*(VstPinInfo*) args.ptr, true, args.index)) ? 1 : 0; + return (processor != nullptr && getPinProperties (*(VstPinInfo*) args.ptr, true, args.index)) ? 1 : 0; } pointer_sized_int handleGetOutputPinProperties (VstOpCodeArguments args) { - return (filter != nullptr && getPinProperties (*(VstPinInfo*) args.ptr, false, args.index)) ? 1 : 0; + return (processor != nullptr && getPinProperties (*(VstPinInfo*) args.ptr, false, args.index)) ? 1 : 0; } pointer_sized_int handleGetPlugInCategory (VstOpCodeArguments) @@ -1823,14 +1809,14 @@ private: pointer_sized_int handleSetSpeakerConfiguration (VstOpCodeArguments args) { - VstSpeakerConfiguration* pluginInput = reinterpret_cast (args.value); - VstSpeakerConfiguration* pluginOutput = reinterpret_cast (args.ptr); + auto* pluginInput = reinterpret_cast (args.value); + auto* pluginOutput = reinterpret_cast (args.ptr); - if (filter->isMidiEffect()) + if (processor->isMidiEffect()) return 0; - const int numIns = filter->getBusCount (true); - const int numOuts = filter->getBusCount (false); + auto numIns = processor->getBusCount (true); + auto numOuts = processor->getBusCount (false); if (pluginInput != nullptr && pluginInput->type >= 0) { @@ -1852,21 +1838,21 @@ private: if (pluginOutput != nullptr && pluginOutput->numberOfChannels > 0 && numOuts == 0) return 0; - AudioProcessor::BusesLayout layouts = filter->getBusesLayout(); + auto layouts = processor->getBusesLayout(); - if (pluginInput != nullptr && pluginInput-> numberOfChannels >= 0 && numIns > 0) + if (pluginInput != nullptr && pluginInput-> numberOfChannels >= 0 && numIns > 0) layouts.getChannelSet (true, 0) = SpeakerMappings::vstArrangementTypeToChannelSet (*pluginInput); if (pluginOutput != nullptr && pluginOutput->numberOfChannels >= 0 && numOuts > 0) layouts.getChannelSet (false, 0) = SpeakerMappings::vstArrangementTypeToChannelSet (*pluginOutput); #ifdef JucePlugin_PreferredChannelConfigurations - short configs[][2] = {JucePlugin_PreferredChannelConfigurations}; + short configs[][2] = { JucePlugin_PreferredChannelConfigurations }; if (! AudioProcessor::containsLayout (layouts, configs)) return 0; #endif - return filter->setBusesLayout (layouts) ? 1 : 0; + return processor->setBusesLayout (layouts) ? 1 : 0; } pointer_sized_int handleSetBypass (VstOpCodeArguments args) @@ -1897,18 +1883,20 @@ private: if (handleManufacturerSpecificVST2Opcode (args.index, args.value, args.ptr, args.opt)) return 1; - if (auto vstFilter = dynamic_cast (filter)) - return vstFilter->handleVstManufacturerSpecific (args.index, args.value, args.ptr, args.opt); + if (auto callbackHandler = dynamic_cast (processor)) + return callbackHandler->handleVstManufacturerSpecific (args.index, args.value, args.ptr, args.opt); return 0; } pointer_sized_int handleCanPlugInDo (VstOpCodeArguments args) { - char* text = (char*) args.ptr; - if (strcmp (text, "receiveVstEvents") == 0 - || strcmp (text, "receiveVstMidiEvent") == 0 - || strcmp (text, "receiveVstMidiEvents") == 0) + auto text = (const char*) args.ptr; + auto matches = [=](const char* s) { return strcmp (text, s) == 0; }; + + if (matches ("receiveVstEvents") + || matches ("receiveVstMidiEvent") + || matches ("receiveVstMidiEvents")) { #if JucePlugin_WantsMidiInput || JucePlugin_IsMidiEffect return 1; @@ -1917,9 +1905,9 @@ private: #endif } - if (strcmp (text, "sendVstEvents") == 0 - || strcmp (text, "sendVstMidiEvent") == 0 - || strcmp (text, "sendVstMidiEvents") == 0) + if (matches ("sendVstEvents") + || matches ("sendVstMidiEvent") + || matches ("sendVstMidiEvents")) { #if JucePlugin_ProducesMidiOutput || JucePlugin_IsMidiEffect return 1; @@ -1928,23 +1916,24 @@ private: #endif } - if (strcmp (text, "receiveVstTimeInfo") == 0 - || strcmp (text, "conformsToWindowRules") == 0 - || strcmp (text, "bypass") == 0) + if (matches ("receiveVstTimeInfo") + || matches ("conformsToWindowRules") + || matches ("supportsViewDpiScaling") + || matches ("bypass")) { return 1; } // This tells Wavelab to use the UI thread to invoke open/close, // like all other hosts do. - if (strcmp (text, "openCloseAnyThread") == 0) + if (matches ("openCloseAnyThread")) return -1; - if (strcmp (text, "MPE") == 0) - return filter->supportsMPE() ? 1 : 0; + if (matches ("MPE")) + return processor->supportsMPE() ? 1 : 0; #if JUCE_MAC - if (strcmp (text, "hasCockosViewAsConfig") == 0) + if (matches ("hasCockosViewAsConfig")) { useNSView = true; return (int32) 0xbeef0000; @@ -1956,8 +1945,8 @@ private: pointer_sized_int handleGetTailSize (VstOpCodeArguments) { - if (filter != nullptr) - return (pointer_sized_int) (filter->getTailLengthSeconds() * sampleRate); + if (processor != nullptr) + return (pointer_sized_int) (processor->getTailLengthSeconds() * sampleRate); return 0; } @@ -1979,16 +1968,16 @@ private: pointer_sized_int handleGetSpeakerConfiguration (VstOpCodeArguments args) { - VstSpeakerConfiguration** pluginInput = reinterpret_cast (args.value); - VstSpeakerConfiguration** pluginOutput = reinterpret_cast (args.ptr); + auto** pluginInput = reinterpret_cast (args.value); + auto** pluginOutput = reinterpret_cast (args.ptr); - if (pluginHasSidechainsOrAuxs() || filter->isMidiEffect()) + if (pluginHasSidechainsOrAuxs() || processor->isMidiEffect()) return false; - AudioChannelSet inputLayout = filter->getChannelLayoutOfBus (true, 0); - AudioChannelSet outputLayout = filter->getChannelLayoutOfBus (false, 0); + auto inputLayout = processor->getChannelLayoutOfBus (true, 0); + auto outputLayout = processor->getChannelLayoutOfBus (false, 0); - const std::size_t speakerBaseSize = sizeof (VstSpeakerConfiguration) - (sizeof (VstIndividualSpeakerInfo) * 8); + auto speakerBaseSize = sizeof (VstSpeakerConfiguration) - (sizeof (VstIndividualSpeakerInfo) * 8); cachedInArrangement .malloc (speakerBaseSize + (static_cast (inputLayout. size()) * sizeof (VstSpeakerConfiguration)), 1); cachedOutArrangement.malloc (speakerBaseSize + (static_cast (outputLayout.size()) * sizeof (VstSpeakerConfiguration)), 1); @@ -1996,8 +1985,8 @@ private: *pluginInput = cachedInArrangement. getData(); *pluginOutput = cachedOutArrangement.getData(); - SpeakerMappings::channelSetToVstArrangement (filter->getChannelLayoutOfBus (true, 0), **pluginInput); - SpeakerMappings::channelSetToVstArrangement (filter->getChannelLayoutOfBus (false, 0), **pluginOutput); + SpeakerMappings::channelSetToVstArrangement (processor->getChannelLayoutOfBus (true, 0), **pluginInput); + SpeakerMappings::channelSetToVstArrangement (processor->getChannelLayoutOfBus (false, 0), **pluginOutput); return 1; } @@ -2011,12 +2000,12 @@ private: { if (! isProcessing) { - if (filter != nullptr) + if (processor != nullptr) { - filter->setProcessingPrecision (args.value == vstProcessingSampleTypeDouble - && filter->supportsDoublePrecisionProcessing() - ? AudioProcessor::doublePrecision - : AudioProcessor::singlePrecision); + processor->setProcessingPrecision ((args.value == vstProcessingSampleTypeDouble + && processor->supportsDoublePrecisionProcessing()) + ? AudioProcessor::doublePrecision + : AudioProcessor::singlePrecision); return 1; } @@ -2066,8 +2055,8 @@ namespace MessageManagerLock mmLock; #endif - AudioProcessor* const filter = createPluginFilterOfType (AudioProcessor::wrapperType_VST); - JuceVSTWrapper* const wrapper = new JuceVSTWrapper (audioMaster, filter); + auto* processor = createPluginFilterOfType (AudioProcessor::wrapperType_VST); + auto* wrapper = new JuceVSTWrapper (audioMaster, processor); return wrapper->getVstEffectInterface(); } }