diff --git a/extras/audio plugin host/Source/GraphEditorPanel.cpp b/extras/audio plugin host/Source/GraphEditorPanel.cpp index 6ed7eae717..0384aaf372 100644 --- a/extras/audio plugin host/Source/GraphEditorPanel.cpp +++ b/extras/audio plugin host/Source/GraphEditorPanel.cpp @@ -61,8 +61,15 @@ void PluginWindow::closeCurrentlyOpenWindowsFor (const uint32 nodeId) void PluginWindow::closeAllCurrentlyOpenWindows() { - for (int i = activePluginWindows.size(); --i >= 0;) - delete activePluginWindows.getUnchecked(i); + if (activePluginWindows.size() > 0) + { + for (int i = activePluginWindows.size(); --i >= 0;) + delete activePluginWindows.getUnchecked(i); + + Component dummyModalComp; + dummyModalComp.enterModalState(); + MessageManager::getInstance()->runDispatchLoopUntil (50); + } } PluginWindow* PluginWindow::getWindowFor (AudioProcessorGraph::Node* node, @@ -84,9 +91,7 @@ PluginWindow* PluginWindow::getWindowFor (AudioProcessorGraph::Node* node, } if (useGenericView) - { ui = new GenericAudioProcessorEditor (node->getProcessor()); - } if (ui != nullptr) { @@ -701,8 +706,7 @@ private: //============================================================================== GraphEditorPanel::GraphEditorPanel (FilterGraph& graph_) - : graph (graph_), - draggingConnector (nullptr) + : graph (graph_) { graph.addChangeListener (this); setOpaque (true); @@ -711,7 +715,7 @@ GraphEditorPanel::GraphEditorPanel (FilterGraph& graph_) GraphEditorPanel::~GraphEditorPanel() { graph.removeChangeListener (this); - deleteAndZero (draggingConnector); + draggingConnector = nullptr; deleteAllChildren(); } @@ -866,7 +870,6 @@ void GraphEditorPanel::beginConnectorDrag (const uint32 sourceFilterID, const in const uint32 destFilterID, const int destFilterChannel, const MouseEvent& e) { - delete draggingConnector; draggingConnector = dynamic_cast (e.originalComponent); if (draggingConnector == nullptr) @@ -897,9 +900,9 @@ void GraphEditorPanel::dragConnector (const MouseEvent& e) if (pin != nullptr) { uint32 srcFilter = draggingConnector->sourceFilterID; - int srcChannel = draggingConnector->sourceFilterChannel; + int srcChannel = draggingConnector->sourceFilterChannel; uint32 dstFilter = draggingConnector->destFilterID; - int dstChannel = draggingConnector->destFilterChannel; + int dstChannel = draggingConnector->destFilterChannel; if (srcFilter == 0 && ! pin->isInput) { @@ -938,11 +941,11 @@ void GraphEditorPanel::endDraggingConnector (const MouseEvent& e) const MouseEvent e2 (e.getEventRelativeTo (this)); uint32 srcFilter = draggingConnector->sourceFilterID; - int srcChannel = draggingConnector->sourceFilterChannel; + int srcChannel = draggingConnector->sourceFilterChannel; uint32 dstFilter = draggingConnector->destFilterID; - int dstChannel = draggingConnector->destFilterChannel; + int dstChannel = draggingConnector->destFilterChannel; - deleteAndZero (draggingConnector); + draggingConnector = nullptr; PinComponent* const pin = findPinAt (e2.x, e2.y); diff --git a/extras/audio plugin host/Source/GraphEditorPanel.h b/extras/audio plugin host/Source/GraphEditorPanel.h index 2b2521fd01..4d4b9bc1b6 100644 --- a/extras/audio plugin host/Source/GraphEditorPanel.h +++ b/extras/audio plugin host/Source/GraphEditorPanel.h @@ -67,7 +67,7 @@ public: //============================================================================== private: FilterGraph& graph; - ConnectorComponent* draggingConnector; + ScopedPointer draggingConnector; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GraphEditorPanel); }; diff --git a/extras/audio plugin host/Source/MainHostWindow.cpp b/extras/audio plugin host/Source/MainHostWindow.cpp index 76d1382119..bc8324b4a5 100644 --- a/extras/audio plugin host/Source/MainHostWindow.cpp +++ b/extras/audio plugin host/Source/MainHostWindow.cpp @@ -29,19 +29,18 @@ //============================================================================== -class PluginListWindow : public DocumentWindow +class MainHostWindow::PluginListWindow : public DocumentWindow { public: - PluginListWindow (KnownPluginList& knownPluginList) + PluginListWindow (MainHostWindow& owner_) : DocumentWindow ("Available Plugins", Colours::white, - DocumentWindow::minimiseButton | DocumentWindow::closeButton) + DocumentWindow::minimiseButton | DocumentWindow::closeButton), + owner (owner_) { - currentPluginListWindow = this; - const File deadMansPedalFile (appProperties->getUserSettings() ->getFile().getSiblingFile ("RecentlyCrashedPluginsList")); - setContentOwned (new PluginListComponent (knownPluginList, + setContentOwned (new PluginListComponent (owner.knownPluginList, deadMansPedalFile, appProperties->getUserSettings()), true); @@ -58,22 +57,19 @@ public: appProperties->getUserSettings()->setValue ("listWindowPos", getWindowStateAsString()); clearContentComponent(); - - jassert (currentPluginListWindow == this); - currentPluginListWindow = 0; } void closeButtonPressed() { - delete this; + owner.pluginListWindow = nullptr; } - static PluginListWindow* currentPluginListWindow; +private: + MainHostWindow& owner; + + JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginListWindow); }; -PluginListWindow* PluginListWindow::currentPluginListWindow = 0; - - //============================================================================== MainHostWindow::MainHostWindow() : DocumentWindow (JUCEApplication::getInstance()->getApplicationName(), Colours::lightgrey, @@ -120,12 +116,12 @@ MainHostWindow::MainHostWindow() MainHostWindow::~MainHostWindow() { - delete PluginListWindow::currentPluginListWindow; + pluginListWindow = nullptr; #if JUCE_MAC - setMacMainMenu (0); + setMacMainMenu (nullptr); #else - setMenuBar (0); + setMenuBar (nullptr); #endif knownPluginList.removeChangeListener (this); @@ -141,8 +137,10 @@ void MainHostWindow::closeButtonPressed() bool MainHostWindow::tryToQuitApplication() { - if (getGraphEditor() != 0 - && getGraphEditor()->graph.saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk) + PluginWindow::closeAllCurrentlyOpenWindows(); + + if (getGraphEditor() == nullptr + || getGraphEditor()->graph.saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk) { JUCEApplication::quit(); return true; @@ -159,7 +157,7 @@ void MainHostWindow::changeListenerCallback (ChangeBroadcaster*) // and it crashes, we've still saved the previous ones ScopedPointer savedPluginList (knownPluginList.createXml()); - if (savedPluginList != 0) + if (savedPluginList != nullptr) { appProperties->getUserSettings()->setValue ("pluginList", savedPluginList); appProperties->saveIfNeeded(); @@ -168,7 +166,7 @@ void MainHostWindow::changeListenerCallback (ChangeBroadcaster*) const StringArray MainHostWindow::getMenuBarNames() { - const char* const names[] = { "File", "Plugins", "Options", 0 }; + const char* const names[] = { "File", "Plugins", "Options", nullptr }; return StringArray (names); } @@ -203,7 +201,6 @@ const PopupMenu MainHostWindow::getMenuForIndex (int topLevelMenuIndex, const St menu.addSubMenu ("Create plugin", pluginsMenu); menu.addSeparator(); menu.addItem (250, "Delete all plugins"); - } else if (topLevelMenuIndex == 2) { @@ -212,10 +209,10 @@ const PopupMenu MainHostWindow::getMenuForIndex (int topLevelMenuIndex, const St menu.addCommandItem (commandManager, CommandIDs::showPluginListEditor); PopupMenu sortTypeMenu; - sortTypeMenu.addItem (200, "List plugins in default order", true, pluginSortMethod == KnownPluginList::defaultOrder); + sortTypeMenu.addItem (200, "List plugins in default order", true, pluginSortMethod == KnownPluginList::defaultOrder); sortTypeMenu.addItem (201, "List plugins in alphabetical order", true, pluginSortMethod == KnownPluginList::sortAlphabetically); - sortTypeMenu.addItem (202, "List plugins by category", true, pluginSortMethod == KnownPluginList::sortByCategory); - sortTypeMenu.addItem (203, "List plugins by manufacturer", true, pluginSortMethod == KnownPluginList::sortByManufacturer); + sortTypeMenu.addItem (202, "List plugins by category", true, pluginSortMethod == KnownPluginList::sortByCategory); + sortTypeMenu.addItem (203, "List plugins by manufacturer", true, pluginSortMethod == KnownPluginList::sortByManufacturer); sortTypeMenu.addItem (204, "List plugins based on the directory structure", true, pluginSortMethod == KnownPluginList::sortByFileSystemLocation); menu.addSubMenu ("Plugin menu type", sortTypeMenu); @@ -235,7 +232,7 @@ void MainHostWindow::menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/ if (menuItemID == 250) { - if (graphEditor != 0) + if (graphEditor != nullptr) graphEditor->graph.clear(); } else if (menuItemID >= 100 && menuItemID < 200) @@ -244,28 +241,23 @@ void MainHostWindow::menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/ recentFiles.restoreFromString (appProperties->getUserSettings() ->getValue ("recentFilterGraphFiles")); - if (graphEditor != 0 && graphEditor->graph.saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk) + if (graphEditor != nullptr && graphEditor->graph.saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk) graphEditor->graph.loadFrom (recentFiles.getFile (menuItemID - 100), true); } else if (menuItemID >= 200 && menuItemID < 210) { - if (menuItemID == 200) - pluginSortMethod = KnownPluginList::defaultOrder; - else if (menuItemID == 201) - pluginSortMethod = KnownPluginList::sortAlphabetically; - else if (menuItemID == 202) - pluginSortMethod = KnownPluginList::sortByCategory; - else if (menuItemID == 203) - pluginSortMethod = KnownPluginList::sortByManufacturer; - else if (menuItemID == 204) - pluginSortMethod = KnownPluginList::sortByFileSystemLocation; + if (menuItemID == 200) pluginSortMethod = KnownPluginList::defaultOrder; + else if (menuItemID == 201) pluginSortMethod = KnownPluginList::sortAlphabetically; + else if (menuItemID == 202) pluginSortMethod = KnownPluginList::sortByCategory; + else if (menuItemID == 203) pluginSortMethod = KnownPluginList::sortByManufacturer; + else if (menuItemID == 204) pluginSortMethod = KnownPluginList::sortByFileSystemLocation; appProperties->getUserSettings()->setValue ("pluginSortMethod", (int) pluginSortMethod); } else { createPlugin (getChosenType (menuItemID), - proportionOfWidth (0.3f + Random::getSystemRandom().nextFloat() * 0.6f), + proportionOfWidth (0.3f + Random::getSystemRandom().nextFloat() * 0.6f), proportionOfHeight (0.3f + Random::getSystemRandom().nextFloat() * 0.6f)); } } @@ -274,7 +266,7 @@ void MainHostWindow::createPlugin (const PluginDescription* desc, int x, int y) { GraphDocumentComponent* const graphEditor = getGraphEditor(); - if (graphEditor != 0) + if (graphEditor != nullptr) graphEditor->createNewPlugin (desc, x, y); } @@ -291,13 +283,9 @@ void MainHostWindow::addPluginsToMenu (PopupMenu& m) const const PluginDescription* MainHostWindow::getChosenType (const int menuID) const { if (menuID >= 1 && menuID < 1 + internalTypes.size()) - { return internalTypes [menuID - 1]; - } - else - { - return knownPluginList.getType (knownPluginList.getIndexChosenByMenu (menuID)); - } + + return knownPluginList.getType (knownPluginList.getIndexChosenByMenu (menuID)); } //============================================================================== @@ -373,26 +361,26 @@ bool MainHostWindow::perform (const InvocationInfo& info) switch (info.commandID) { case CommandIDs::open: - if (graphEditor != 0 && graphEditor->graph.saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk) + if (graphEditor != nullptr && graphEditor->graph.saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk) graphEditor->graph.loadFromUserSpecifiedFile (true); break; case CommandIDs::save: - if (graphEditor != 0) + if (graphEditor != nullptr) graphEditor->graph.save (true, true); break; case CommandIDs::saveAs: - if (graphEditor != 0) + if (graphEditor != nullptr) graphEditor->graph.saveAs (File::nonexistent, true, true, true); break; case CommandIDs::showPluginListEditor: - if (PluginListWindow::currentPluginListWindow == 0) - PluginListWindow::currentPluginListWindow = new PluginListWindow (knownPluginList); + if (pluginListWindow == nullptr) + pluginListWindow = new PluginListWindow (*this); - PluginListWindow::currentPluginListWindow->toFront (true); + pluginListWindow->toFront (true); break; case CommandIDs::showAudioSettings: @@ -400,15 +388,7 @@ bool MainHostWindow::perform (const InvocationInfo& info) break; case CommandIDs::aboutBox: - { -/* AboutBoxComponent aboutComp; - - DialogWindow::showModalDialog ("About", - &aboutComp, - this, Colours::white, - true, false, false); - */ } - + // TODO break; default: @@ -440,7 +420,7 @@ void MainHostWindow::showAudioSettings() GraphDocumentComponent* const graphEditor = getGraphEditor(); - if (graphEditor != 0) + if (graphEditor != nullptr) graphEditor->graph.removeIllegalConnections(); } @@ -463,29 +443,25 @@ void MainHostWindow::fileDragExit (const StringArray&) void MainHostWindow::filesDropped (const StringArray& files, int x, int y) { - if (files.size() == 1 && File (files[0]).hasFileExtension (filenameSuffix)) - { - GraphDocumentComponent* const graphEditor = getGraphEditor(); + GraphDocumentComponent* const graphEditor = getGraphEditor(); - if (graphEditor != 0 - && graphEditor->graph.saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk) + if (graphEditor != nullptr) + { + if (files.size() == 1 && File (files[0]).hasFileExtension (filenameSuffix)) { - graphEditor->graph.loadFrom (File (files[0]), true); + if (graphEditor->graph.saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk) + graphEditor->graph.loadFrom (File (files[0]), true); } - } - else - { - OwnedArray typesFound; - knownPluginList.scanAndAddDragAndDroppedFiles (files, typesFound); + else + { + OwnedArray typesFound; + knownPluginList.scanAndAddDragAndDroppedFiles (files, typesFound); - GraphDocumentComponent* const graphEditor = getGraphEditor(); + Point pos (graphEditor->getLocalPoint (this, Point (x, y))); - Point pos (x, y); - if (graphEditor != 0) - pos = graphEditor->getLocalPoint (this, pos); - - for (int i = 0; i < jmin (5, typesFound.size()); ++i) - createPlugin (typesFound.getUnchecked(i), pos.getX(), pos.getY()); + for (int i = 0; i < jmin (5, typesFound.size()); ++i) + createPlugin (typesFound.getUnchecked(i), pos.getX(), pos.getY()); + } } } diff --git a/extras/audio plugin host/Source/MainHostWindow.h b/extras/audio plugin host/Source/MainHostWindow.h index c05b7bca74..9d9f0fb48b 100644 --- a/extras/audio plugin host/Source/MainHostWindow.h +++ b/extras/audio plugin host/Source/MainHostWindow.h @@ -93,6 +93,9 @@ private: KnownPluginList knownPluginList; KnownPluginList::SortMethod pluginSortMethod; + class PluginListWindow; + ScopedPointer pluginListWindow; + void showAudioSettings(); JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (MainHostWindow);