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.

134 lines
4.9KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library.
  4. Copyright (c) 2017 - ROLI Ltd.
  5. JUCE is an open source library subject to commercial or open-source
  6. licensing.
  7. By using JUCE, you agree to the terms of both the JUCE 5 End-User License
  8. Agreement and JUCE 5 Privacy Policy (both updated and effective as of the
  9. 27th April 2017).
  10. End User License Agreement: www.juce.com/juce-5-licence
  11. Privacy Policy: www.juce.com/juce-5-privacy-policy
  12. Or: You may also use this code under the terms of the GPL v3 (see
  13. www.gnu.org/licenses).
  14. JUCE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY, AND ALL WARRANTIES, WHETHER
  15. EXPRESSED OR IMPLIED, INCLUDING MERCHANTABILITY AND FITNESS FOR PURPOSE, ARE
  16. DISCLAIMED.
  17. ==============================================================================
  18. */
  19. #include "../JuceLibraryCode/JuceHeader.h"
  20. #include "MainHostWindow.h"
  21. #include "InternalFilters.h"
  22. #if ! (JUCE_PLUGINHOST_VST || JUCE_PLUGINHOST_VST3 || JUCE_PLUGINHOST_AU)
  23. #error "If you're building the audio plugin host, you probably want to enable VST and/or AU support"
  24. #endif
  25. //==============================================================================
  26. class PluginHostApp : public JUCEApplication,
  27. private AsyncUpdater
  28. {
  29. public:
  30. PluginHostApp() {}
  31. void initialise (const String&) override
  32. {
  33. // initialise our settings file..
  34. PropertiesFile::Options options;
  35. options.applicationName = "Juce Audio Plugin Host";
  36. options.filenameSuffix = "settings";
  37. options.osxLibrarySubFolder = "Preferences";
  38. appProperties = new ApplicationProperties();
  39. appProperties->setStorageParameters (options);
  40. mainWindow = new MainHostWindow();
  41. mainWindow->setUsingNativeTitleBar (true);
  42. commandManager.registerAllCommandsForTarget (this);
  43. commandManager.registerAllCommandsForTarget (mainWindow);
  44. mainWindow->menuItemsChanged();
  45. // Important note! We're going to use an async update here so that if we need
  46. // to re-open a file and instantiate some plugins, it will happen AFTER this
  47. // initialisation method has returned.
  48. // On Windows this probably won't make a difference, but on OSX there's a subtle event loop
  49. // issue that can happen if a plugin runs one of those irritating modal dialogs while it's
  50. // being loaded. If that happens inside this method, the OSX event loop seems to be in some
  51. // kind of special "initialisation" mode and things get confused. But if we load the plugin
  52. // later when the normal event loop is running, everything's fine.
  53. triggerAsyncUpdate();
  54. }
  55. void handleAsyncUpdate() override
  56. {
  57. File fileToOpen;
  58. for (int i = 0; i < getCommandLineParameterArray().size(); ++i)
  59. {
  60. fileToOpen = File::getCurrentWorkingDirectory().getChildFile (getCommandLineParameterArray()[i]);
  61. if (fileToOpen.existsAsFile())
  62. break;
  63. }
  64. if (! fileToOpen.existsAsFile())
  65. {
  66. RecentlyOpenedFilesList recentFiles;
  67. recentFiles.restoreFromString (getAppProperties().getUserSettings()->getValue ("recentFilterGraphFiles"));
  68. if (recentFiles.getNumFiles() > 0)
  69. fileToOpen = recentFiles.getFile (0);
  70. }
  71. if (fileToOpen.existsAsFile())
  72. if (GraphDocumentComponent* graph = mainWindow->getGraphEditor())
  73. if (FilterGraph* ioGraph = graph->graph.get())
  74. ioGraph->loadFrom (fileToOpen, true);
  75. }
  76. void shutdown() override
  77. {
  78. mainWindow = nullptr;
  79. appProperties = nullptr;
  80. LookAndFeel::setDefaultLookAndFeel (nullptr);
  81. }
  82. void systemRequestedQuit() override
  83. {
  84. if (mainWindow != nullptr)
  85. mainWindow->tryToQuitApplication();
  86. else
  87. JUCEApplicationBase::quit();
  88. }
  89. const String getApplicationName() override { return "Juce Plug-In Host"; }
  90. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  91. bool moreThanOneInstanceAllowed() override { return true; }
  92. ApplicationCommandManager commandManager;
  93. ScopedPointer<ApplicationProperties> appProperties;
  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)