diff --git a/examples/audio plugin demo/Source/PluginProcessor.cpp b/examples/audio plugin demo/Source/PluginProcessor.cpp index 3f24e47c81..625d279427 100644 --- a/examples/audio plugin demo/Source/PluginProcessor.cpp +++ b/examples/audio plugin demo/Source/PluginProcessor.cpp @@ -47,8 +47,6 @@ class SineWaveVoice : public SynthesiserVoice { public: SineWaveVoice() - : angleDelta (0.0), - tailOff (0.0) { } @@ -112,7 +110,6 @@ public: } private: - template void processBlock (AudioBuffer& outputBuffer, int startSample, int numSamples) { @@ -122,8 +119,7 @@ private: { while (--numSamples >= 0) { - const FloatType currentSample = - static_cast (std::sin (currentAngle) * level * tailOff); + auto currentSample = static_cast (std::sin (currentAngle) * level * tailOff); for (int i = outputBuffer.getNumChannels(); --i >= 0;) outputBuffer.addSample (i, startSample, currentSample); @@ -146,7 +142,7 @@ private: { while (--numSamples >= 0) { - const FloatType currentSample = static_cast (std::sin (currentAngle) * level); + auto currentSample = static_cast (std::sin (currentAngle) * level); for (int i = outputBuffer.getNumChannels(); --i >= 0;) outputBuffer.addSample (i, startSample, currentSample); @@ -158,17 +154,12 @@ private: } } - double currentAngle, angleDelta, level, tailOff; + double currentAngle = 0, angleDelta = 0, level = 0, tailOff = 0; }; //============================================================================== JuceDemoPluginAudioProcessor::JuceDemoPluginAudioProcessor() - : AudioProcessor (getBusesProperties()), - lastUIWidth (400), - lastUIHeight (200), - gainParam (nullptr), - delayParam (nullptr), - delayPosition (0) + : AudioProcessor (getBusesProperties()) { lastPosInfo.resetToDefault(); @@ -208,10 +199,12 @@ bool JuceDemoPluginAudioProcessor::isBusesLayoutSupported (const BusesLayout& la return false; // do not allow disabling the main buses - if (mainOutput.isDisabled()) return false; + if (mainOutput.isDisabled()) + return false; // only allow stereo and mono - if (mainOutput.size() > 2) return false; + if (mainOutput.size() > 2) + return false; return true; } @@ -308,13 +301,13 @@ void JuceDemoPluginAudioProcessor::applyDelay (AudioBuffer& buffer, A for (int channel = 0; channel < getTotalNumOutputChannels(); ++channel) { - FloatType* const channelData = buffer.getWritePointer (channel); - FloatType* const delayData = delayBuffer.getWritePointer (jmin (channel, delayBuffer.getNumChannels() - 1)); + auto channelData = buffer.getWritePointer (channel); + auto delayData = delayBuffer.getWritePointer (jmin (channel, delayBuffer.getNumChannels() - 1)); delayPos = delayPosition; for (int i = 0; i < numSamples; ++i) { - const FloatType in = channelData[i]; + auto in = channelData[i]; channelData[i] += delayData[delayPos]; delayData[delayPos] = (delayData[delayPos] + in) * delayLevel; @@ -363,8 +356,8 @@ void JuceDemoPluginAudioProcessor::getStateInformation (MemoryBlock& destData) xml.setAttribute ("uiHeight", lastUIHeight); // Store the values of all our parameters, using their param ID as the XML attribute - for (int i = 0; i < getNumParameters(); ++i) - if (AudioProcessorParameterWithID* p = dynamic_cast (getParameters().getUnchecked(i))) + for (auto* param : getParameters()) + if (auto* p = dynamic_cast (param)) xml.setAttribute (p->paramID, p->getValue()); // then use this helper function to stuff it into the binary blob and return it.. @@ -389,8 +382,8 @@ void JuceDemoPluginAudioProcessor::setStateInformation (const void* data, int si lastUIHeight = jmax (xmlState->getIntAttribute ("uiHeight", lastUIHeight), 200); // Now reload our parameters.. - for (int i = 0; i < getNumParameters(); ++i) - if (AudioProcessorParameterWithID* p = dynamic_cast (getParameters().getUnchecked(i))) + for (auto* param : getParameters()) + if (auto* p = dynamic_cast (param)) p->setValue ((float) xmlState->getDoubleAttribute (p->paramID, p->getValue())); } } diff --git a/examples/audio plugin demo/Source/PluginProcessor.h b/examples/audio plugin demo/Source/PluginProcessor.h index d1dc07141e..430815a319 100644 --- a/examples/audio plugin demo/Source/PluginProcessor.h +++ b/examples/audio plugin demo/Source/PluginProcessor.h @@ -98,11 +98,11 @@ public: // these are used to persist the UI's size - the values are stored along with the // filter's other parameters, and the UI component will update them when it gets // resized. - int lastUIWidth, lastUIHeight; + int lastUIWidth = 400, lastUIHeight = 200; // Our parameters - AudioParameterFloat* gainParam; - AudioParameterFloat* delayParam; + AudioParameterFloat* gainParam = nullptr; + AudioParameterFloat* delayParam = nullptr; private: //============================================================================== @@ -115,7 +115,8 @@ private: AudioBuffer delayBufferFloat; AudioBuffer delayBufferDouble; - int delayPosition; + + int delayPosition = 0; Synthesiser synth; diff --git a/examples/audio plugin host/Source/GraphEditorPanel.cpp b/examples/audio plugin host/Source/GraphEditorPanel.cpp index bbd942381e..b13813d95f 100644 --- a/examples/audio plugin host/Source/GraphEditorPanel.cpp +++ b/examples/audio plugin host/Source/GraphEditorPanel.cpp @@ -70,7 +70,7 @@ void PluginWindow::closeAllCurrentlyOpenWindows() delete activePluginWindows.getUnchecked (i); Component dummyModalComp; - dummyModalComp.enterModalState(); + dummyModalComp.enterModalState (false); MessageManager::getInstance()->runDispatchLoopUntil (50); } } @@ -79,10 +79,8 @@ void PluginWindow::closeAllCurrentlyOpenWindows() struct ProcessorProgramPropertyComp : public PropertyComponent, private AudioProcessorListener { -public: ProcessorProgramPropertyComp (const String& name, AudioProcessor& p) - : PropertyComponent (name), - owner (p) + : PropertyComponent (name), owner (p) { owner.addListener (this); } @@ -142,22 +140,19 @@ struct ProgramAudioProcessorEditor : public AudioProcessorEditor panel.setBounds (getLocalBounds()); } -private: PropertyPanel panel; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (ProgramAudioProcessorEditor) }; //============================================================================== -PluginWindow* PluginWindow::getWindowFor (AudioProcessorGraph::Node* const node, - WindowFormatType type) +PluginWindow* PluginWindow::getWindowFor (AudioProcessorGraph::Node* node, WindowFormatType type) { jassert (node != nullptr); - for (int i = activePluginWindows.size(); --i >= 0;) - if (activePluginWindows.getUnchecked(i)->owner == node - && activePluginWindows.getUnchecked(i)->type == type) - return activePluginWindows.getUnchecked(i); + for (auto* w : activePluginWindows) + if (w->owner == node && w->type == type) + return w; auto* processor = node->getProcessor(); AudioProcessorEditor* ui = nullptr; @@ -223,8 +218,7 @@ struct PinComponent : public Component, public SettableTooltipClient { PinComponent (FilterGraph& g, uint32 id, int i, bool isIn) - : graph (g), pluginID (id), - index (i), isInput (isIn) + : graph (g), pluginID (id), index (i), isInput (isIn) { if (auto node = graph.getNodeForId (pluginID)) { @@ -261,10 +255,9 @@ struct PinComponent : public Component, Path p; p.addEllipse (w * 0.25f, h * 0.25f, w * 0.5f, h * 0.5f); - p.addRectangle (w * 0.4f, isInput ? (0.5f * h) : 0.0f, w * 0.2f, h * 0.5f); - Colour colour = (index == FilterGraph::midiChannelNumber ? Colours::red : Colours::green); + auto colour = (index == FilterGraph::midiChannelNumber ? Colours::red : Colours::green); g.setColour (colour.withRotatedHue (static_cast (busIdx) / 5.0f)); g.fillPath (p); diff --git a/examples/audio plugin host/Source/MainHostWindow.cpp b/examples/audio plugin host/Source/MainHostWindow.cpp index 01da4d6eee..508a31a653 100644 --- a/examples/audio plugin host/Source/MainHostWindow.cpp +++ b/examples/audio plugin host/Source/MainHostWindow.cpp @@ -321,7 +321,8 @@ void MainHostWindow::addPluginsToMenu (PopupMenu& m) const int i = 0; for (auto* t : internalTypes) - m.addItem (++i, t->name, graphEditor->graph->getNodeForName (t->name) == nullptr); + m.addItem (++i, t->name + " (" + t->pluginFormatName + ")", + graphEditor->graph->getNodeForName (t->name) == nullptr); } m.addSeparator(); diff --git a/modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp b/modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp index 1efbebc0cb..352b6c1c0b 100644 --- a/modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp +++ b/modules/juce_audio_processors/scanning/juce_KnownPluginList.cpp @@ -31,7 +31,7 @@ void KnownPluginList::clear() { ScopedLock lock (typesArrayLock); - if (types.size() > 0) + if (! types.isEmpty()) { types.clear(); sendChangeMessage(); @@ -42,9 +42,9 @@ PluginDescription* KnownPluginList::getTypeForFile (const String& fileOrIdentifi { ScopedLock lock (typesArrayLock); - for (int i = 0; i < types.size(); ++i) - if (types.getUnchecked(i)->fileOrIdentifier == fileOrIdentifier) - return types.getUnchecked(i); + for (auto* desc : types) + if (desc->fileOrIdentifier == fileOrIdentifier) + return desc; return nullptr; } @@ -53,9 +53,9 @@ PluginDescription* KnownPluginList::getTypeForIdentifierString (const String& id { ScopedLock lock (typesArrayLock); - for (int i = 0; i < types.size(); ++i) - if (types.getUnchecked(i)->matchesIdentifierString (identifierString)) - return types.getUnchecked(i); + for (auto* desc : types) + if (desc->matchesIdentifierString (identifierString)) + return desc; return nullptr; } @@ -65,15 +65,15 @@ bool KnownPluginList::addType (const PluginDescription& type) { ScopedLock lock (typesArrayLock); - for (int i = types.size(); --i >= 0;) + for (auto* desc : types) { - if (types.getUnchecked(i)->isDuplicateOf (type)) + if (desc->isDuplicateOf (type)) { // strange - found a duplicate plugin with different info.. - jassert (types.getUnchecked(i)->name == type.name); - jassert (types.getUnchecked(i)->isInstrument == type.isInstrument); + jassert (desc->name == type.name); + jassert (desc->isInstrument == type.isInstrument); - *types.getUnchecked(i) = type; + *desc = type; return false; } } @@ -89,7 +89,6 @@ void KnownPluginList::removeType (const int index) { { ScopedLock lock (typesArrayLock); - types.remove (index); } @@ -104,14 +103,9 @@ bool KnownPluginList::isListingUpToDate (const String& fileOrIdentifier, ScopedLock lock (typesArrayLock); - for (int i = types.size(); --i >= 0;) - { - const PluginDescription* const d = types.getUnchecked(i); - - if (d->fileOrIdentifier == fileOrIdentifier - && formatToUse.pluginNeedsRescanning (*d)) + for (auto* d : types) + if (d->fileOrIdentifier == fileOrIdentifier && formatToUse.pluginNeedsRescanning (*d)) return false; - } return true; } @@ -135,10 +129,8 @@ bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier, ScopedLock lock (typesArrayLock); - for (int i = types.size(); --i >= 0;) + for (auto* d : types) { - const PluginDescription* const d = types.getUnchecked(i); - if (d->fileOrIdentifier == fileOrIdentifier && d->pluginFormatName == format.getName()) { if (format.pluginNeedsRescanning (*d)) @@ -171,30 +163,27 @@ bool KnownPluginList::scanAndAddFile (const String& fileOrIdentifier, } } - for (int i = 0; i < found.size(); ++i) + for (auto* desc : found) { - PluginDescription* const desc = found.getUnchecked(i); jassert (desc != nullptr); - addType (*desc); typesFound.add (new PluginDescription (*desc)); } - return found.size() > 0; + return ! found.isEmpty(); } void KnownPluginList::scanAndAddDragAndDroppedFiles (AudioPluginFormatManager& formatManager, const StringArray& files, OwnedArray& typesFound) { - for (int i = 0; i < files.size(); ++i) + for (const auto& filenameOrID : files) { - const String filenameOrID (files[i]); bool found = false; for (int j = 0; j < formatManager.getNumFormats(); ++j) { - AudioPluginFormat* const format = formatManager.getFormat (j); + auto* format = formatManager.getFormat (j); if (format->fileMightContainThisPluginType (filenameOrID) && scanAndAddFile (filenameOrID, true, typesFound, *format)) @@ -216,8 +205,8 @@ void KnownPluginList::scanAndAddDragAndDroppedFiles (AudioPluginFormatManager& f Array subFiles; f.findChildFiles (subFiles, File::findFilesAndDirectories, false); - for (int j = 0; j < subFiles.size(); ++j) - s.add (subFiles.getReference(j).getFullPathName()); + for (auto& subFile : subFiles) + s.add (subFile.getFullPathName()); } scanAndAddDragAndDroppedFiles (formatManager, s, typesFound); @@ -340,7 +329,7 @@ void KnownPluginList::sort (const SortMethod method, bool forwards) //============================================================================== XmlElement* KnownPluginList::createXml() const { - XmlElement* const e = new XmlElement ("KNOWNPLUGINS"); + auto e = new XmlElement ("KNOWNPLUGINS"); { ScopedLock lock (typesArrayLock); @@ -349,8 +338,8 @@ XmlElement* KnownPluginList::createXml() const e->prependChildElement (types.getUnchecked(i)->createXml()); } - for (int i = 0; i < blacklist.size(); ++i) - e->createNewChildElement ("BLACKLISTED")->setAttribute ("id", blacklist[i]); + for (auto& b : blacklist) + e->createNewChildElement ("BLACKLISTED")->setAttribute ("id", b); return e; } @@ -381,12 +370,10 @@ struct PluginTreeUtils static void buildTreeByFolder (KnownPluginList::PluginTree& tree, const Array& allPlugins) { - for (int i = 0; i < allPlugins.size(); ++i) + for (auto* pd : allPlugins) { - PluginDescription* const pd = allPlugins.getUnchecked (i); - - String path (pd->fileOrIdentifier.replaceCharacter ('\\', '/') - .upToLastOccurrenceOf ("/", false, false)); + auto path = pd->fileOrIdentifier.replaceCharacter ('\\', '/') + .upToLastOccurrenceOf ("/", false, false); if (path.substring (1, 2) == ":") path = path.substring (2); @@ -401,15 +388,13 @@ struct PluginTreeUtils { for (int i = tree.subFolders.size(); --i >= 0;) { - KnownPluginList::PluginTree& sub = *tree.subFolders.getUnchecked(i); + auto& sub = *tree.subFolders.getUnchecked(i); optimiseFolders (sub, concatenateName || (tree.subFolders.size() > 1)); - if (sub.plugins.size() == 0) + if (sub.plugins.isEmpty()) { - for (int j = 0; j < sub.subFolders.size(); ++j) + for (auto* s : sub.subFolders) { - KnownPluginList::PluginTree* const s = sub.subFolders.getUnchecked(j); - if (concatenateName) s->folder = sub.folder + "/" + s->folder; @@ -429,10 +414,9 @@ struct PluginTreeUtils String lastType; ScopedPointer current (new KnownPluginList::PluginTree()); - for (int i = 0; i < sorted.size(); ++i) + for (auto* pd : sorted) { - const PluginDescription* const pd = sorted.getUnchecked(i); - String thisType (sortMethod == KnownPluginList::sortByCategory ? pd->category + auto thisType = (sortMethod == KnownPluginList::sortByCategory ? pd->category : pd->manufacturerName); if (! thisType.containsNonWhitespaceChars()) @@ -473,8 +457,8 @@ struct PluginTreeUtils path = path.fromFirstOccurrenceOf (":", false, false); // avoid the special AU formatting nonsense on Mac.. #endif - const String firstSubFolder (path.upToFirstOccurrenceOf ("/", false, false)); - const String remainingPath (path.fromFirstOccurrenceOf ("/", false, false)); + auto firstSubFolder = path.upToFirstOccurrenceOf ("/", false, false); + auto remainingPath = path.fromFirstOccurrenceOf ("/", false, false); for (int i = tree.subFolders.size(); --i >= 0;) { @@ -487,7 +471,7 @@ struct PluginTreeUtils } } - KnownPluginList::PluginTree* const newFolder = new KnownPluginList::PluginTree(); + auto newFolder = new KnownPluginList::PluginTree(); newFolder->folder = firstSubFolder; tree.subFolders.add (newFolder); addPlugin (*newFolder, pd, remainingPath); @@ -512,22 +496,18 @@ struct PluginTreeUtils { bool isTicked = false; - for (int i = 0; i < tree.subFolders.size(); ++i) + for (auto* sub : tree.subFolders) { - const KnownPluginList::PluginTree& sub = *tree.subFolders.getUnchecked(i); - PopupMenu subMenu; - const bool isItemTicked = addToMenu (sub, subMenu, allPlugins, currentlyTickedPluginID); + const bool isItemTicked = addToMenu (*sub, subMenu, allPlugins, currentlyTickedPluginID); isTicked = isTicked || isItemTicked; - m.addSubMenu (sub.folder, subMenu, true, nullptr, isItemTicked, 0); + m.addSubMenu (sub->folder, subMenu, true, nullptr, isItemTicked, 0); } - for (int i = 0; i < tree.plugins.size(); ++i) + for (auto* plugin : tree.plugins) { - const PluginDescription* const plugin = tree.plugins.getUnchecked(i); - - String name (plugin->name); + auto name = plugin->name; if (containsDuplicateNames (tree.plugins, name)) name << " (" << plugin->pluginFormatName << ')'; @@ -550,11 +530,11 @@ KnownPluginList::PluginTree* KnownPluginList::createTree (const SortMethod sortM ScopedLock lock (typesArrayLock); PluginSorter sorter (sortMethod, true); - for (int i = 0; i < types.size(); ++i) - sorted.addSorted (sorter, types.getUnchecked(i)); + for (auto* t : types) + sorted.addSorted (sorter, t); } - PluginTree* tree = new PluginTree(); + auto* tree = new PluginTree(); if (sortMethod == sortByCategory || sortMethod == sortByManufacturer || sortMethod == sortByFormat) { @@ -566,8 +546,8 @@ KnownPluginList::PluginTree* KnownPluginList::createTree (const SortMethod sortM } else { - for (int i = 0; i < sorted.size(); ++i) - tree->plugins.add (sorted.getUnchecked(i)); + for (auto* p : sorted) + tree->plugins.add (p); } return tree; @@ -595,7 +575,7 @@ void KnownPluginList::CustomScanner::scanFinished() {} bool KnownPluginList::CustomScanner::shouldExit() const noexcept { - if (ThreadPoolJob* job = ThreadPoolJob::getCurrentThreadPoolJob()) + if (auto* job = ThreadPoolJob::getCurrentThreadPoolJob()) return job->shouldExit(); return false; diff --git a/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp b/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp index 7261d5e5f9..00ee3c687d 100644 --- a/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp +++ b/modules/juce_gui_basics/windows/juce_ResizableWindow.cpp @@ -242,7 +242,7 @@ void ResizableWindow::childBoundsChanged (Component* child) jassert (child->getWidth() > 0); jassert (child->getHeight() > 0); - const BorderSize borders (getContentComponentBorder()); + auto borders = getContentComponentBorder(); setSize (child->getWidth() + borders.getLeftAndRight(), child->getHeight() + borders.getTopAndBottom());