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.

132 lines
4.9KB

  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. mainWindow = new MainHostWindow();
  39. mainWindow->setUsingNativeTitleBar (true);
  40. commandManager.registerAllCommandsForTarget (this);
  41. commandManager.registerAllCommandsForTarget (mainWindow);
  42. mainWindow->menuItemsChanged();
  43. // Important note! We're going to use an async update here so that if we need
  44. // to re-open a file and instantiate some plugins, it will happen AFTER this
  45. // initialisation method has returned.
  46. // On Windows this probably won't make a difference, but on OSX there's a subtle event loop
  47. // issue that can happen if a plugin runs one of those irritating modal dialogs while it's
  48. // being loaded. If that happens inside this method, the OSX event loop seems to be in some
  49. // kind of special "initialisation" mode and things get confused. But if we load the plugin
  50. // later when the normal event loop is running, everything's fine.
  51. triggerAsyncUpdate();
  52. }
  53. void handleAsyncUpdate() override
  54. {
  55. File fileToOpen;
  56. for (int i = 0; i < getCommandLineParameterArray().size(); ++i)
  57. {
  58. fileToOpen = File::getCurrentWorkingDirectory().getChildFile (getCommandLineParameterArray()[i]);
  59. if (fileToOpen.existsAsFile())
  60. break;
  61. }
  62. if (! fileToOpen.existsAsFile())
  63. {
  64. RecentlyOpenedFilesList recentFiles;
  65. recentFiles.restoreFromString (getAppProperties().getUserSettings()->getValue ("recentFilterGraphFiles"));
  66. if (recentFiles.getNumFiles() > 0)
  67. fileToOpen = recentFiles.getFile (0);
  68. }
  69. if (fileToOpen.existsAsFile())
  70. if (GraphDocumentComponent* graph = mainWindow->getGraphEditor())
  71. if (FilterGraph* ioGraph = graph->graph.get())
  72. ioGraph->loadFrom (fileToOpen, true);
  73. }
  74. void shutdown() override
  75. {
  76. mainWindow = nullptr;
  77. appProperties = nullptr;
  78. LookAndFeel::setDefaultLookAndFeel (nullptr);
  79. }
  80. void systemRequestedQuit() override
  81. {
  82. if (mainWindow != nullptr)
  83. mainWindow->tryToQuitApplication();
  84. else
  85. JUCEApplicationBase::quit();
  86. }
  87. const String getApplicationName() override { return "Juce Plug-In Host"; }
  88. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  89. bool moreThanOneInstanceAllowed() override { return true; }
  90. ApplicationCommandManager commandManager;
  91. ScopedPointer<ApplicationProperties> appProperties;
  92. private:
  93. ScopedPointer<MainHostWindow> mainWindow;
  94. };
  95. static PluginHostApp& getApp() { return *dynamic_cast<PluginHostApp*>(JUCEApplication::getInstance()); }
  96. ApplicationCommandManager& getCommandManager() { return getApp().commandManager; }
  97. ApplicationProperties& getAppProperties() { return *getApp().appProperties; }
  98. // This kicks the whole thing off..
  99. START_JUCE_APPLICATION (PluginHostApp)