Browse Source

Minor clean-ups in plugin host demo.

tags/2021-05-28
jules 12 years ago
parent
commit
d36df96acc
4 changed files with 50 additions and 58 deletions
  1. +3
    -3
      extras/audio plugin host/Source/FilterGraph.cpp
  2. +20
    -28
      extras/audio plugin host/Source/HostStartup.cpp
  3. +25
    -25
      extras/audio plugin host/Source/MainHostWindow.cpp
  4. +2
    -2
      extras/audio plugin host/Source/MainHostWindow.h

+ 3
- 3
extras/audio plugin host/Source/FilterGraph.cpp View File

@@ -244,7 +244,7 @@ Result FilterGraph::saveDocument (const File& file)
File FilterGraph::getLastDocumentOpened() File FilterGraph::getLastDocumentOpened()
{ {
RecentlyOpenedFilesList recentFiles; RecentlyOpenedFilesList recentFiles;
recentFiles.restoreFromString (appProperties->getUserSettings()
recentFiles.restoreFromString (getAppProperties().getUserSettings()
->getValue ("recentFilterGraphFiles")); ->getValue ("recentFilterGraphFiles"));
return recentFiles.getFile (0); return recentFiles.getFile (0);
@@ -253,12 +253,12 @@ File FilterGraph::getLastDocumentOpened()
void FilterGraph::setLastDocumentOpened (const File& file) void FilterGraph::setLastDocumentOpened (const File& file)
{ {
RecentlyOpenedFilesList recentFiles; RecentlyOpenedFilesList recentFiles;
recentFiles.restoreFromString (appProperties->getUserSettings()
recentFiles.restoreFromString (getAppProperties().getUserSettings()
->getValue ("recentFilterGraphFiles")); ->getValue ("recentFilterGraphFiles"));
recentFiles.addFile (file); recentFiles.addFile (file);
appProperties->getUserSettings()
getAppProperties().getUserSettings()
->setValue ("recentFilterGraphFiles", recentFiles.toString()); ->setValue ("recentFilterGraphFiles", recentFiles.toString());
} }


+ 20
- 28
extras/audio plugin host/Source/HostStartup.cpp View File

@@ -31,18 +31,11 @@
#endif #endif
ApplicationCommandManager* commandManager = nullptr;
ApplicationProperties* appProperties = nullptr;
//============================================================================== //==============================================================================
class PluginHostApp : public JUCEApplication class PluginHostApp : public JUCEApplication
{ {
public: public:
//==============================================================================
PluginHostApp()
{
}
PluginHostApp() {}
void initialise (const String& commandLine) void initialise (const String& commandLine)
{ {
@@ -56,38 +49,30 @@ public:
appProperties = new ApplicationProperties(); appProperties = new ApplicationProperties();
appProperties->setStorageParameters (options); appProperties->setStorageParameters (options);
commandManager = new ApplicationCommandManager();
mainWindow = new MainHostWindow(); mainWindow = new MainHostWindow();
//mainWindow->setUsingNativeTitleBar (true);
mainWindow->setUsingNativeTitleBar (true);
commandManager->registerAllCommandsForTarget (this);
commandManager->registerAllCommandsForTarget (mainWindow);
commandManager.registerAllCommandsForTarget (this);
commandManager.registerAllCommandsForTarget (mainWindow);
mainWindow->menuItemsChanged(); 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() void shutdown()
{ {
mainWindow = 0;
appProperties->closeFiles();
deleteAndZero (commandManager);
deleteAndZero (appProperties);
mainWindow = nullptr;
appProperties = nullptr;
} }
void systemRequestedQuit() void systemRequestedQuit()
{ {
if (mainWindow != 0)
if (mainWindow != nullptr)
mainWindow->tryToQuitApplication(); mainWindow->tryToQuitApplication();
else else
JUCEApplication::quit(); JUCEApplication::quit();
@@ -97,10 +82,17 @@ public:
const String getApplicationVersion() { return ProjectInfo::versionString; } const String getApplicationVersion() { return ProjectInfo::versionString; }
bool moreThanOneInstanceAllowed() { return true; } bool moreThanOneInstanceAllowed() { return true; }
ApplicationCommandManager commandManager;
ScopedPointer<ApplicationProperties> appProperties = nullptr;
private: private:
ScopedPointer <MainHostWindow> mainWindow;
ScopedPointer<MainHostWindow> mainWindow;
}; };
static PluginHostApp& getApp() { return *dynamic_cast<PluginHostApp*>(JUCEApplication::getInstance()); }
ApplicationCommandManager& getCommandManager() { return getApp().commandManager; }
ApplicationProperties& getAppProperties() { return *getApp().appProperties; }
// This kicks the whole thing off.. // This kicks the whole thing off..
START_JUCE_APPLICATION (PluginHostApp) START_JUCE_APPLICATION (PluginHostApp)

+ 25
- 25
extras/audio plugin host/Source/MainHostWindow.cpp View File

@@ -36,25 +36,25 @@ public:
DocumentWindow::minimiseButton | DocumentWindow::closeButton), DocumentWindow::minimiseButton | DocumentWindow::closeButton),
owner (owner_) owner (owner_)
{ {
const File deadMansPedalFile (appProperties->getUserSettings()
const File deadMansPedalFile (getAppProperties().getUserSettings()
->getFile().getSiblingFile ("RecentlyCrashedPluginsList")); ->getFile().getSiblingFile ("RecentlyCrashedPluginsList"));
setContentOwned (new PluginListComponent (formatManager, setContentOwned (new PluginListComponent (formatManager,
owner.knownPluginList, owner.knownPluginList,
deadMansPedalFile, deadMansPedalFile,
appProperties->getUserSettings()), true);
getAppProperties().getUserSettings()), true);
setResizable (true, false); setResizable (true, false);
setResizeLimits (300, 400, 800, 1500); setResizeLimits (300, 400, 800, 1500);
setTopLeftPosition (60, 60); setTopLeftPosition (60, 60);
restoreWindowStateFromString (appProperties->getUserSettings()->getValue ("listWindowPos"));
restoreWindowStateFromString (getAppProperties().getUserSettings()->getValue ("listWindowPos"));
setVisible (true); setVisible (true);
} }
~PluginListWindow() ~PluginListWindow()
{ {
appProperties->getUserSettings()->setValue ("listWindowPos", getWindowStateAsString());
getAppProperties().getUserSettings()->setValue ("listWindowPos", getWindowStateAsString());
clearContentComponent(); clearContentComponent();
} }
@@ -78,7 +78,7 @@ MainHostWindow::MainHostWindow()
formatManager.addDefaultFormats(); formatManager.addDefaultFormats();
formatManager.addFormat (new InternalPluginFormat()); formatManager.addFormat (new InternalPluginFormat());
ScopedPointer<XmlElement> savedAudioState (appProperties->getUserSettings()
ScopedPointer<XmlElement> savedAudioState (getAppProperties().getUserSettings()
->getXmlValue ("audioDeviceState")); ->getXmlValue ("audioDeviceState"));
deviceManager.initialise (256, 256, savedAudioState, true); deviceManager.initialise (256, 256, savedAudioState, true);
@@ -89,24 +89,24 @@ MainHostWindow::MainHostWindow()
setContentOwned (new GraphDocumentComponent (formatManager, &deviceManager), false); setContentOwned (new GraphDocumentComponent (formatManager, &deviceManager), false);
restoreWindowStateFromString (appProperties->getUserSettings()->getValue ("mainWindowPos"));
restoreWindowStateFromString (getAppProperties().getUserSettings()->getValue ("mainWindowPos"));
setVisible (true); setVisible (true);
InternalPluginFormat internalFormat; InternalPluginFormat internalFormat;
internalFormat.getAllTypes (internalTypes); internalFormat.getAllTypes (internalTypes);
ScopedPointer<XmlElement> savedPluginList (appProperties->getUserSettings()->getXmlValue ("pluginList"));
ScopedPointer<XmlElement> savedPluginList (getAppProperties().getUserSettings()->getXmlValue ("pluginList"));
if (savedPluginList != nullptr) if (savedPluginList != nullptr)
knownPluginList.recreateFromXml (*savedPluginList); knownPluginList.recreateFromXml (*savedPluginList);
pluginSortMethod = (KnownPluginList::SortMethod) appProperties->getUserSettings()
pluginSortMethod = (KnownPluginList::SortMethod) getAppProperties().getUserSettings()
->getIntValue ("pluginSortMethod", KnownPluginList::sortByManufacturer); ->getIntValue ("pluginSortMethod", KnownPluginList::sortByManufacturer);
knownPluginList.addChangeListener (this); knownPluginList.addChangeListener (this);
addKeyListener (commandManager->getKeyMappings());
addKeyListener (getCommandManager().getKeyMappings());
Process::setPriority (Process::HighPriority); Process::setPriority (Process::HighPriority);
@@ -116,7 +116,7 @@ MainHostWindow::MainHostWindow()
setMenuBar (this); setMenuBar (this);
#endif #endif
commandManager->setFirstCommandTarget (this);
getCommandManager().setFirstCommandTarget (this);
} }
MainHostWindow::~MainHostWindow() MainHostWindow::~MainHostWindow()
@@ -131,7 +131,7 @@ MainHostWindow::~MainHostWindow()
knownPluginList.removeChangeListener (this); knownPluginList.removeChangeListener (this);
appProperties->getUserSettings()->setValue ("mainWindowPos", getWindowStateAsString());
getAppProperties().getUserSettings()->setValue ("mainWindowPos", getWindowStateAsString());
clearContentComponent(); clearContentComponent();
} }
@@ -164,8 +164,8 @@ void MainHostWindow::changeListenerCallback (ChangeBroadcaster*)
if (savedPluginList != nullptr) 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) if (topLevelMenuIndex == 0)
{ {
// "File" menu // "File" menu
menu.addCommandItem (commandManager, CommandIDs::open);
menu.addCommandItem (&getCommandManager(), CommandIDs::open);
RecentlyOpenedFilesList recentFiles; RecentlyOpenedFilesList recentFiles;
recentFiles.restoreFromString (appProperties->getUserSettings()
recentFiles.restoreFromString (getAppProperties().getUserSettings()
->getValue ("recentFilterGraphFiles")); ->getValue ("recentFilterGraphFiles"));
PopupMenu recentFilesMenu; PopupMenu recentFilesMenu;
recentFiles.createPopupMenuItems (recentFilesMenu, 100, true, true); recentFiles.createPopupMenuItems (recentFilesMenu, 100, true, true);
menu.addSubMenu ("Open recent file", recentFilesMenu); 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.addSeparator();
menu.addCommandItem (commandManager, StandardApplicationCommandIDs::quit);
menu.addCommandItem (&getCommandManager(), StandardApplicationCommandIDs::quit);
} }
else if (topLevelMenuIndex == 1) else if (topLevelMenuIndex == 1)
{ {
@@ -211,7 +211,7 @@ PopupMenu MainHostWindow::getMenuForIndex (int topLevelMenuIndex, const String&
{ {
// "Options" menu // "Options" menu
menu.addCommandItem (commandManager, CommandIDs::showPluginListEditor);
menu.addCommandItem (&getCommandManager(), CommandIDs::showPluginListEditor);
PopupMenu sortTypeMenu; 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);
@@ -222,10 +222,10 @@ PopupMenu MainHostWindow::getMenuForIndex (int topLevelMenuIndex, const String&
menu.addSubMenu ("Plugin menu type", sortTypeMenu); menu.addSubMenu ("Plugin menu type", sortTypeMenu);
menu.addSeparator(); menu.addSeparator();
menu.addCommandItem (commandManager, CommandIDs::showAudioSettings);
menu.addCommandItem (&getCommandManager(), CommandIDs::showAudioSettings);
menu.addSeparator(); menu.addSeparator();
menu.addCommandItem (commandManager, CommandIDs::aboutBox);
menu.addCommandItem (&getCommandManager(), CommandIDs::aboutBox);
} }
return menu; return menu;
@@ -243,7 +243,7 @@ void MainHostWindow::menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/
else if (menuItemID >= 100 && menuItemID < 200) else if (menuItemID >= 100 && menuItemID < 200)
{ {
RecentlyOpenedFilesList recentFiles; RecentlyOpenedFilesList recentFiles;
recentFiles.restoreFromString (appProperties->getUserSettings()
recentFiles.restoreFromString (getAppProperties().getUserSettings()
->getValue ("recentFilterGraphFiles")); ->getValue ("recentFilterGraphFiles"));
if (graphEditor != nullptr && graphEditor->graph.saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk) 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 == 203) pluginSortMethod = KnownPluginList::sortByManufacturer;
else if (menuItemID == 204) pluginSortMethod = KnownPluginList::sortByFileSystemLocation; else if (menuItemID == 204) pluginSortMethod = KnownPluginList::sortByFileSystemLocation;
appProperties->getUserSettings()->setValue ("pluginSortMethod", (int) pluginSortMethod);
getAppProperties().getUserSettings()->setValue ("pluginSortMethod", (int) pluginSortMethod);
menuItemsChanged(); menuItemsChanged();
} }
@@ -427,8 +427,8 @@ void MainHostWindow::showAudioSettings()
ScopedPointer<XmlElement> audioState (deviceManager.createStateXml()); ScopedPointer<XmlElement> audioState (deviceManager.createStateXml());
appProperties->getUserSettings()->setValue ("audioDeviceState", audioState);
appProperties->getUserSettings()->saveIfNeeded();
getAppProperties().getUserSettings()->setValue ("audioDeviceState", audioState);
getAppProperties().getUserSettings()->saveIfNeeded();
GraphDocumentComponent* const graphEditor = getGraphEditor(); GraphDocumentComponent* const graphEditor = getGraphEditor();


+ 2
- 2
extras/audio plugin host/Source/MainHostWindow.h View File

@@ -40,8 +40,8 @@ namespace CommandIDs
static const int aboutBox = 0x30300; static const int aboutBox = 0x30300;
} }
extern ApplicationCommandManager* commandManager;
extern ApplicationProperties* appProperties;
ApplicationCommandManager& getCommandManager();
ApplicationProperties& getAppProperties();
//============================================================================== //==============================================================================
/** /**


Loading…
Cancel
Save