The JUCE cross-platform C++ framework, with DISTRHO/KXStudio specific changes
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

135 lines
5.0KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2015 - ROLI Ltd.
  5. Permission is granted to use this software under the terms of either:
  6. a) the GPL v2 (or any later version)
  7. b) the Affero GPL v3
  8. Details of these licenses can be found at: www.gnu.org/licenses
  9. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  10. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  11. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  12. ------------------------------------------------------------------------------
  13. To release a closed-source product which uses JUCE, commercial licenses are
  14. available: visit www.juce.com for more information.
  15. ==============================================================================
  16. */
  17. #include "../JuceLibraryCode/JuceHeader.h"
  18. #include "MainHostWindow.h"
  19. #include "InternalFilters.h"
  20. #if ! (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_VST3 || JUCE_PLUGINHOST_AU)
  21. #error "If you're building the audio plugin host, you probably want to enable VST and/or AU support"
  22. #endif
  23. //==============================================================================
  24. class PluginHostApp : public JUCEApplication,
  25. private AsyncUpdater
  26. {
  27. public:
  28. PluginHostApp() {}
  29. void initialise (const String&) override
  30. {
  31. // initialise our settings file..
  32. PropertiesFile::Options options;
  33. options.applicationName = "Juce Audio Plugin Host";
  34. options.filenameSuffix = "settings";
  35. options.osxLibrarySubFolder = "Preferences";
  36. appProperties = new ApplicationProperties();
  37. appProperties->setStorageParameters (options);
  38. LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  39. mainWindow = new MainHostWindow();
  40. mainWindow->setUsingNativeTitleBar (true);
  41. commandManager.registerAllCommandsForTarget (this);
  42. commandManager.registerAllCommandsForTarget (mainWindow);
  43. mainWindow->menuItemsChanged();
  44. // Important note! We're going to use an async update here so that if we need
  45. // to re-open a file and instantiate some plugins, it will happen AFTER this
  46. // initialisation method has returned.
  47. // On Windows this probably won't make a difference, but on OSX there's a subtle event loop
  48. // issue that can happen if a plugin runs one of those irritating modal dialogs while it's
  49. // being loaded. If that happens inside this method, the OSX event loop seems to be in some
  50. // kind of special "initialisation" mode and things get confused. But if we load the plugin
  51. // later when the normal event loop is running, everything's fine.
  52. triggerAsyncUpdate();
  53. }
  54. void handleAsyncUpdate() override
  55. {
  56. File fileToOpen;
  57. for (int i = 0; i < getCommandLineParameterArray().size(); ++i)
  58. {
  59. fileToOpen = File::getCurrentWorkingDirectory().getChildFile (getCommandLineParameterArray()[i]);
  60. if (fileToOpen.existsAsFile())
  61. break;
  62. }
  63. if (! fileToOpen.existsAsFile())
  64. {
  65. RecentlyOpenedFilesList recentFiles;
  66. recentFiles.restoreFromString (getAppProperties().getUserSettings()->getValue ("recentFilterGraphFiles"));
  67. if (recentFiles.getNumFiles() > 0)
  68. fileToOpen = recentFiles.getFile (0);
  69. }
  70. if (fileToOpen.existsAsFile())
  71. if (GraphDocumentComponent* graph = mainWindow->getGraphEditor())
  72. if (FilterGraph* ioGraph = graph->graph.get())
  73. ioGraph->loadFrom (fileToOpen, true);
  74. }
  75. void shutdown() override
  76. {
  77. mainWindow = nullptr;
  78. appProperties = nullptr;
  79. LookAndFeel::setDefaultLookAndFeel (nullptr);
  80. }
  81. void systemRequestedQuit() override
  82. {
  83. if (mainWindow != nullptr)
  84. mainWindow->tryToQuitApplication();
  85. else
  86. JUCEApplicationBase::quit();
  87. }
  88. const String getApplicationName() override { return "Juce Plug-In Host"; }
  89. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  90. bool moreThanOneInstanceAllowed() override { return true; }
  91. ApplicationCommandManager commandManager;
  92. ScopedPointer<ApplicationProperties> appProperties;
  93. LookAndFeel_V3 lookAndFeel;
  94. private:
  95. ScopedPointer<MainHostWindow> mainWindow;
  96. };
  97. static PluginHostApp& getApp() { return *dynamic_cast<PluginHostApp*>(JUCEApplication::getInstance()); }
  98. ApplicationCommandManager& getCommandManager() { return getApp().commandManager; }
  99. ApplicationProperties& getAppProperties() { return *getApp().appProperties; }
  100. // This kicks the whole thing off..
  101. START_JUCE_APPLICATION (PluginHostApp)