diff --git a/extras/audio plugin host/Source/FilterGraph.cpp b/extras/audio plugin host/Source/FilterGraph.cpp index 94696eb881..f144d36ae3 100644 --- a/extras/audio plugin host/Source/FilterGraph.cpp +++ b/extras/audio plugin host/Source/FilterGraph.cpp @@ -244,7 +244,7 @@ Result FilterGraph::saveDocument (const File& file) File FilterGraph::getLastDocumentOpened() { RecentlyOpenedFilesList recentFiles; - recentFiles.restoreFromString (appProperties->getUserSettings() + recentFiles.restoreFromString (getAppProperties().getUserSettings() ->getValue ("recentFilterGraphFiles")); return recentFiles.getFile (0); @@ -253,12 +253,12 @@ File FilterGraph::getLastDocumentOpened() void FilterGraph::setLastDocumentOpened (const File& file) { RecentlyOpenedFilesList recentFiles; - recentFiles.restoreFromString (appProperties->getUserSettings() + recentFiles.restoreFromString (getAppProperties().getUserSettings() ->getValue ("recentFilterGraphFiles")); recentFiles.addFile (file); - appProperties->getUserSettings() + getAppProperties().getUserSettings() ->setValue ("recentFilterGraphFiles", recentFiles.toString()); } diff --git a/extras/audio plugin host/Source/HostStartup.cpp b/extras/audio plugin host/Source/HostStartup.cpp index c652819c24..878fd496fa 100644 --- a/extras/audio plugin host/Source/HostStartup.cpp +++ b/extras/audio plugin host/Source/HostStartup.cpp @@ -31,18 +31,11 @@ #endif -ApplicationCommandManager* commandManager = nullptr; -ApplicationProperties* appProperties = nullptr; - - //============================================================================== class PluginHostApp : public JUCEApplication { public: - //============================================================================== - PluginHostApp() - { - } + PluginHostApp() {} void initialise (const String& commandLine) { @@ -56,38 +49,30 @@ public: appProperties = new ApplicationProperties(); appProperties->setStorageParameters (options); - commandManager = new ApplicationCommandManager(); - mainWindow = new MainHostWindow(); - //mainWindow->setUsingNativeTitleBar (true); + mainWindow->setUsingNativeTitleBar (true); - commandManager->registerAllCommandsForTarget (this); - commandManager->registerAllCommandsForTarget (mainWindow); + commandManager.registerAllCommandsForTarget (this); + commandManager.registerAllCommandsForTarget (mainWindow); mainWindow->menuItemsChanged(); - if (commandLine.isNotEmpty() && mainWindow->getGraphEditor() != 0) - { - #if JUCE_MAC - if (! commandLine.trimStart().startsWith ("-")) - #endif - mainWindow->getGraphEditor()->graph.loadFrom (File::getCurrentWorkingDirectory() - .getChildFile (commandLine), true); - } + if (commandLine.isNotEmpty() + && ! commandLine.trimStart().startsWith ("-") + && mainWindow->getGraphEditor() != nullptr) + mainWindow->getGraphEditor()->graph.loadFrom (File::getCurrentWorkingDirectory() + .getChildFile (commandLine), true); } void shutdown() { - mainWindow = 0; - appProperties->closeFiles(); - - deleteAndZero (commandManager); - deleteAndZero (appProperties); + mainWindow = nullptr; + appProperties = nullptr; } void systemRequestedQuit() { - if (mainWindow != 0) + if (mainWindow != nullptr) mainWindow->tryToQuitApplication(); else JUCEApplication::quit(); @@ -97,10 +82,17 @@ public: const String getApplicationVersion() { return ProjectInfo::versionString; } bool moreThanOneInstanceAllowed() { return true; } + ApplicationCommandManager commandManager; + ScopedPointer appProperties = nullptr; + private: - ScopedPointer mainWindow; + ScopedPointer mainWindow; }; +static PluginHostApp& getApp() { return *dynamic_cast(JUCEApplication::getInstance()); } +ApplicationCommandManager& getCommandManager() { return getApp().commandManager; } +ApplicationProperties& getAppProperties() { return *getApp().appProperties; } + // This kicks the whole thing off.. START_JUCE_APPLICATION (PluginHostApp) diff --git a/extras/audio plugin host/Source/MainHostWindow.cpp b/extras/audio plugin host/Source/MainHostWindow.cpp index cb51821f42..d429523b7f 100644 --- a/extras/audio plugin host/Source/MainHostWindow.cpp +++ b/extras/audio plugin host/Source/MainHostWindow.cpp @@ -36,25 +36,25 @@ public: DocumentWindow::minimiseButton | DocumentWindow::closeButton), owner (owner_) { - const File deadMansPedalFile (appProperties->getUserSettings() + const File deadMansPedalFile (getAppProperties().getUserSettings() ->getFile().getSiblingFile ("RecentlyCrashedPluginsList")); setContentOwned (new PluginListComponent (formatManager, owner.knownPluginList, deadMansPedalFile, - appProperties->getUserSettings()), true); + getAppProperties().getUserSettings()), true); setResizable (true, false); setResizeLimits (300, 400, 800, 1500); setTopLeftPosition (60, 60); - restoreWindowStateFromString (appProperties->getUserSettings()->getValue ("listWindowPos")); + restoreWindowStateFromString (getAppProperties().getUserSettings()->getValue ("listWindowPos")); setVisible (true); } ~PluginListWindow() { - appProperties->getUserSettings()->setValue ("listWindowPos", getWindowStateAsString()); + getAppProperties().getUserSettings()->setValue ("listWindowPos", getWindowStateAsString()); clearContentComponent(); } @@ -78,7 +78,7 @@ MainHostWindow::MainHostWindow() formatManager.addDefaultFormats(); formatManager.addFormat (new InternalPluginFormat()); - ScopedPointer savedAudioState (appProperties->getUserSettings() + ScopedPointer savedAudioState (getAppProperties().getUserSettings() ->getXmlValue ("audioDeviceState")); deviceManager.initialise (256, 256, savedAudioState, true); @@ -89,24 +89,24 @@ MainHostWindow::MainHostWindow() setContentOwned (new GraphDocumentComponent (formatManager, &deviceManager), false); - restoreWindowStateFromString (appProperties->getUserSettings()->getValue ("mainWindowPos")); + restoreWindowStateFromString (getAppProperties().getUserSettings()->getValue ("mainWindowPos")); setVisible (true); InternalPluginFormat internalFormat; internalFormat.getAllTypes (internalTypes); - ScopedPointer savedPluginList (appProperties->getUserSettings()->getXmlValue ("pluginList")); + ScopedPointer savedPluginList (getAppProperties().getUserSettings()->getXmlValue ("pluginList")); if (savedPluginList != nullptr) knownPluginList.recreateFromXml (*savedPluginList); - pluginSortMethod = (KnownPluginList::SortMethod) appProperties->getUserSettings() + pluginSortMethod = (KnownPluginList::SortMethod) getAppProperties().getUserSettings() ->getIntValue ("pluginSortMethod", KnownPluginList::sortByManufacturer); knownPluginList.addChangeListener (this); - addKeyListener (commandManager->getKeyMappings()); + addKeyListener (getCommandManager().getKeyMappings()); Process::setPriority (Process::HighPriority); @@ -116,7 +116,7 @@ MainHostWindow::MainHostWindow() setMenuBar (this); #endif - commandManager->setFirstCommandTarget (this); + getCommandManager().setFirstCommandTarget (this); } MainHostWindow::~MainHostWindow() @@ -131,7 +131,7 @@ MainHostWindow::~MainHostWindow() knownPluginList.removeChangeListener (this); - appProperties->getUserSettings()->setValue ("mainWindowPos", getWindowStateAsString()); + getAppProperties().getUserSettings()->setValue ("mainWindowPos", getWindowStateAsString()); clearContentComponent(); } @@ -164,8 +164,8 @@ void MainHostWindow::changeListenerCallback (ChangeBroadcaster*) if (savedPluginList != nullptr) { - appProperties->getUserSettings()->setValue ("pluginList", savedPluginList); - appProperties->saveIfNeeded(); + getAppProperties().getUserSettings()->setValue ("pluginList", savedPluginList); + getAppProperties().saveIfNeeded(); } } @@ -183,20 +183,20 @@ PopupMenu MainHostWindow::getMenuForIndex (int topLevelMenuIndex, const String& if (topLevelMenuIndex == 0) { // "File" menu - menu.addCommandItem (commandManager, CommandIDs::open); + menu.addCommandItem (&getCommandManager(), CommandIDs::open); RecentlyOpenedFilesList recentFiles; - recentFiles.restoreFromString (appProperties->getUserSettings() + recentFiles.restoreFromString (getAppProperties().getUserSettings() ->getValue ("recentFilterGraphFiles")); PopupMenu recentFilesMenu; recentFiles.createPopupMenuItems (recentFilesMenu, 100, true, true); menu.addSubMenu ("Open recent file", recentFilesMenu); - menu.addCommandItem (commandManager, CommandIDs::save); - menu.addCommandItem (commandManager, CommandIDs::saveAs); + menu.addCommandItem (&getCommandManager(), CommandIDs::save); + menu.addCommandItem (&getCommandManager(), CommandIDs::saveAs); menu.addSeparator(); - menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit); + menu.addCommandItem (&getCommandManager(), StandardApplicationCommandIDs::quit); } else if (topLevelMenuIndex == 1) { @@ -211,7 +211,7 @@ PopupMenu MainHostWindow::getMenuForIndex (int topLevelMenuIndex, const String& { // "Options" menu - menu.addCommandItem (commandManager, CommandIDs::showPluginListEditor); + menu.addCommandItem (&getCommandManager(), CommandIDs::showPluginListEditor); PopupMenu sortTypeMenu; sortTypeMenu.addItem (200, "List plugins in default order", true, pluginSortMethod == KnownPluginList::defaultOrder); @@ -222,10 +222,10 @@ PopupMenu MainHostWindow::getMenuForIndex (int topLevelMenuIndex, const String& menu.addSubMenu ("Plugin menu type", sortTypeMenu); menu.addSeparator(); - menu.addCommandItem (commandManager, CommandIDs::showAudioSettings); + menu.addCommandItem (&getCommandManager(), CommandIDs::showAudioSettings); menu.addSeparator(); - menu.addCommandItem (commandManager, CommandIDs::aboutBox); + menu.addCommandItem (&getCommandManager(), CommandIDs::aboutBox); } return menu; @@ -243,7 +243,7 @@ void MainHostWindow::menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/ else if (menuItemID >= 100 && menuItemID < 200) { RecentlyOpenedFilesList recentFiles; - recentFiles.restoreFromString (appProperties->getUserSettings() + recentFiles.restoreFromString (getAppProperties().getUserSettings() ->getValue ("recentFilterGraphFiles")); if (graphEditor != nullptr && graphEditor->graph.saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk) @@ -257,7 +257,7 @@ void MainHostWindow::menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/ else if (menuItemID == 203) pluginSortMethod = KnownPluginList::sortByManufacturer; else if (menuItemID == 204) pluginSortMethod = KnownPluginList::sortByFileSystemLocation; - appProperties->getUserSettings()->setValue ("pluginSortMethod", (int) pluginSortMethod); + getAppProperties().getUserSettings()->setValue ("pluginSortMethod", (int) pluginSortMethod); menuItemsChanged(); } @@ -427,8 +427,8 @@ void MainHostWindow::showAudioSettings() ScopedPointer audioState (deviceManager.createStateXml()); - appProperties->getUserSettings()->setValue ("audioDeviceState", audioState); - appProperties->getUserSettings()->saveIfNeeded(); + getAppProperties().getUserSettings()->setValue ("audioDeviceState", audioState); + getAppProperties().getUserSettings()->saveIfNeeded(); GraphDocumentComponent* const graphEditor = getGraphEditor(); diff --git a/extras/audio plugin host/Source/MainHostWindow.h b/extras/audio plugin host/Source/MainHostWindow.h index 62b363abfa..7f123f0d5c 100644 --- a/extras/audio plugin host/Source/MainHostWindow.h +++ b/extras/audio plugin host/Source/MainHostWindow.h @@ -40,8 +40,8 @@ namespace CommandIDs static const int aboutBox = 0x30300; } -extern ApplicationCommandManager* commandManager; -extern ApplicationProperties* appProperties; +ApplicationCommandManager& getCommandManager(); +ApplicationProperties& getAppProperties(); //============================================================================== /**