1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-23 01:44:22 +00:00

Cleanup and refactoring work on the AudioProcessorGraph and the audio plugin host demo

This commit is contained in:
jules 2017-10-26 17:26:24 +01:00
parent f1f2a34d04
commit d0514c7924
24 changed files with 1850 additions and 2266 deletions

View file

@ -33,14 +33,14 @@
class MainHostWindow::PluginListWindow : public DocumentWindow
{
public:
PluginListWindow (MainHostWindow& owner_, AudioPluginFormatManager& pluginFormatManager)
PluginListWindow (MainHostWindow& mw, AudioPluginFormatManager& pluginFormatManager)
: DocumentWindow ("Available Plugins",
LookAndFeel::getDefaultLookAndFeel().findColour (ResizableWindow::backgroundColourId),
DocumentWindow::minimiseButton | DocumentWindow::closeButton),
owner (owner_)
owner (mw)
{
const File deadMansPedalFile (getAppProperties().getUserSettings()
->getFile().getSiblingFile ("RecentlyCrashedPluginsList"));
auto deadMansPedalFile = getAppProperties().getUserSettings()
->getFile().getSiblingFile ("RecentlyCrashedPluginsList");
setContentOwned (new PluginListComponent (pluginFormatManager,
owner.knownPluginList,
@ -58,11 +58,10 @@ public:
~PluginListWindow()
{
getAppProperties().getUserSettings()->setValue ("listWindowPos", getWindowStateAsString());
clearContentComponent();
}
void closeButtonPressed()
void closeButtonPressed() override
{
owner.pluginListWindow = nullptr;
}
@ -91,7 +90,9 @@ MainHostWindow::MainHostWindow()
setResizeLimits (500, 400, 10000, 10000);
centreWithSize (800, 600);
setContentOwned (new GraphDocumentComponent (formatManager, deviceManager), false);
graphHolder = new GraphDocumentComponent (formatManager, deviceManager);
setContentNonOwned (graphHolder, false);
restoreWindowStateFromString (getAppProperties().getUserSettings()->getValue ("mainWindowPos"));
@ -110,7 +111,7 @@ MainHostWindow::MainHostWindow()
knownPluginList.addChangeListener (this);
if (auto* filterGraph = getGraphEditor()->graph.get())
if (auto* filterGraph = graphHolder->graph.get())
filterGraph->addChangeListener (this);
addKeyListener (getCommandManager().getKeyMappings());
@ -131,7 +132,7 @@ MainHostWindow::~MainHostWindow()
pluginListWindow = nullptr;
knownPluginList.removeChangeListener (this);
if (auto* filterGraph = getGraphEditor()->graph.get())
if (auto* filterGraph = graphHolder->graph.get())
filterGraph->removeChangeListener (this);
getAppProperties().getUserSettings()->setValue ("mainWindowPos", getWindowStateAsString());
@ -142,6 +143,8 @@ MainHostWindow::~MainHostWindow()
#else
setMenuBar (nullptr);
#endif
graphHolder = nullptr;
}
void MainHostWindow::closeButtonPressed()
@ -165,18 +168,24 @@ struct AsyncQuitRetrier : private Timer
void MainHostWindow::tryToQuitApplication()
{
PluginWindow::closeAllCurrentlyOpenWindows();
if (ModalComponentManager::getInstance()->cancelAllModalComponents())
if (graphHolder->closeAnyOpenPluginWindows())
{
// Really important thing to note here: if the last call just deleted any plugin windows,
// we won't exit immediately - instead we'll use our AsyncQuitRetrier to let the message
// loop run for another brief moment, then try again. This will give any plugins a chance
// to flush any GUI events that may have been in transit before the app forces them to
// be unloaded
new AsyncQuitRetrier();
}
else if (ModalComponentManager::getInstance()->cancelAllModalComponents())
{
new AsyncQuitRetrier();
}
else if (getGraphEditor() == nullptr
|| getGraphEditor()->graph->saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk)
else if (graphHolder == nullptr || graphHolder->graph->saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk)
{
// Some plug-ins do not want [NSApp stop] to be called
// before the plug-ins are not deallocated.
getGraphEditor()->releaseGraph();
graphHolder->releaseGraph();
JUCEApplication::quit();
}
@ -198,11 +207,10 @@ void MainHostWindow::changeListenerCallback (ChangeBroadcaster* changed)
getAppProperties().saveIfNeeded();
}
}
else if (changed == getGraphEditor()->graph)
else if (graphHolder != nullptr && changed == graphHolder->graph)
{
String title = JUCEApplication::getInstance()->getApplicationName();
File f = getGraphEditor()->graph->getFile();
auto title = JUCEApplication::getInstance()->getApplicationName();
auto f = graphHolder->graph->getFile();
if (f.existsAsFile())
title = f.getFileName() + " - " + title;
@ -286,9 +294,9 @@ void MainHostWindow::menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/
{
if (menuItemID == 250)
{
if (auto* graphEditor = getGraphEditor())
if (auto* filterGraph = graphEditor->graph.get())
filterGraph->clear();
if (graphHolder != nullptr)
if (auto* graph = graphHolder->graph.get())
graph->clear();
}
else if (menuItemID >= 100 && menuItemID < 200)
{
@ -296,9 +304,10 @@ void MainHostWindow::menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/
recentFiles.restoreFromString (getAppProperties().getUserSettings()
->getValue ("recentFilterGraphFiles"));
if (auto* graphEditor = getGraphEditor())
if (graphEditor->graph != nullptr && graphEditor->graph->saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk)
graphEditor->graph->loadFrom (recentFiles.getFile (menuItemID - 100), true);
if (graphHolder != nullptr)
if (auto* graph = graphHolder->graph.get())
if (graph != nullptr && graph->saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk)
graph->loadFrom (recentFiles.getFile (menuItemID - 100), true);
}
else if (menuItemID >= 200 && menuItemID < 210)
{
@ -323,26 +332,25 @@ void MainHostWindow::menuItemSelected (int menuItemID, int /*topLevelMenuIndex*/
void MainHostWindow::menuBarActivated (bool isActivated)
{
if (auto* graphEditor = getGraphEditor())
if (isActivated)
graphEditor->unfocusKeyboardComponent();
if (isActivated && graphHolder != nullptr)
graphHolder->unfocusKeyboardComponent();
}
void MainHostWindow::createPlugin (const PluginDescription& desc, Point<int> pos)
{
if (auto* graphEditor = getGraphEditor())
graphEditor->createNewPlugin (desc, pos);
if (graphHolder != nullptr)
graphHolder->createNewPlugin (desc, pos);
}
void MainHostWindow::addPluginsToMenu (PopupMenu& m) const
{
if (auto* graphEditor = getGraphEditor())
if (graphHolder != nullptr)
{
int i = 0;
for (auto* t : internalTypes)
m.addItem (++i, t->name + " (" + t->pluginFormatName + ")",
graphEditor->graph->getNodeForName (t->name) == nullptr);
graphHolder->graph->getNodeForName (t->name) == nullptr);
}
m.addSeparator();
@ -439,28 +447,26 @@ void MainHostWindow::getCommandInfo (const CommandID commandID, ApplicationComma
bool MainHostWindow::perform (const InvocationInfo& info)
{
auto* graphEditor = getGraphEditor();
switch (info.commandID)
{
case CommandIDs::newFile:
if (graphEditor != nullptr && graphEditor->graph != nullptr && graphEditor->graph->saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk)
graphEditor->graph->newDocument();
if (graphHolder != nullptr && graphHolder->graph != nullptr && graphHolder->graph->saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk)
graphHolder->graph->newDocument();
break;
case CommandIDs::open:
if (graphEditor != nullptr && graphEditor->graph != nullptr && graphEditor->graph->saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk)
graphEditor->graph->loadFromUserSpecifiedFile (true);
if (graphHolder != nullptr && graphHolder->graph != nullptr && graphHolder->graph->saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk)
graphHolder->graph->loadFromUserSpecifiedFile (true);
break;
case CommandIDs::save:
if (graphEditor != nullptr && graphEditor->graph != nullptr)
graphEditor->graph->save (true, true);
if (graphHolder != nullptr && graphHolder->graph != nullptr)
graphHolder->graph->save (true, true);
break;
case CommandIDs::saveAs:
if (graphEditor != nullptr && graphEditor->graph != nullptr)
graphEditor->graph->saveAs (File(), true, true, true);
if (graphHolder != nullptr && graphHolder->graph != nullptr)
graphHolder->graph->saveAs (File(), true, true, true);
break;
case CommandIDs::showPluginListEditor:
@ -486,8 +492,8 @@ bool MainHostWindow::perform (const InvocationInfo& info)
menuItemsChanged();
}
if (graphEditor != nullptr)
graphEditor->setDoublePrecision (newIsDoublePrecision);
if (graphHolder != nullptr)
graphHolder->setDoublePrecision (newIsDoublePrecision);
}
break;
@ -537,9 +543,9 @@ void MainHostWindow::showAudioSettings()
getAppProperties().getUserSettings()->setValue ("audioDeviceState", audioState);
getAppProperties().getUserSettings()->saveIfNeeded();
if (auto* graphEditor = getGraphEditor())
if (graphEditor->graph != nullptr)
graphEditor->graph->removeIllegalConnections();
if (graphHolder != nullptr)
if (graphHolder->graph != nullptr)
graphHolder->graph->graph.removeIllegalConnections();
}
bool MainHostWindow::isInterestedInFileDrag (const StringArray&)
@ -561,11 +567,11 @@ void MainHostWindow::fileDragExit (const StringArray&)
void MainHostWindow::filesDropped (const StringArray& files, int x, int y)
{
if (auto* graphEditor = getGraphEditor())
if (graphHolder != nullptr)
{
if (files.size() == 1 && File (files[0]).hasFileExtension (filenameSuffix))
if (files.size() == 1 && File (files[0]).hasFileExtension (FilterGraph::getFilenameSuffix()))
{
if (auto* filterGraph = graphEditor->graph.get())
if (auto* filterGraph = graphHolder->graph.get())
if (filterGraph->saveIfNeededAndUserAgrees() == FileBasedDocument::savedOk)
filterGraph->loadFrom (File (files[0]), true);
}
@ -574,7 +580,7 @@ void MainHostWindow::filesDropped (const StringArray& files, int x, int y)
OwnedArray<PluginDescription> typesFound;
knownPluginList.scanAndAddDragAndDroppedFiles (formatManager, files, typesFound);
auto pos = graphEditor->getLocalPoint (this, Point<int> (x, y));
auto pos = graphHolder->getLocalPoint (this, Point<int> (x, y));
for (int i = 0; i < jmin (5, typesFound.size()); ++i)
if (auto* desc = typesFound.getUnchecked(i))
@ -583,11 +589,6 @@ void MainHostWindow::filesDropped (const StringArray& files, int x, int y)
}
}
GraphDocumentComponent* MainHostWindow::getGraphEditor() const
{
return dynamic_cast<GraphDocumentComponent*> (getContentComponent());
}
bool MainHostWindow::isDoublePrecisionProcessing()
{
if (auto* props = getAppProperties().getUserSettings())