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.

155 lines
5.6KB

  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 "UI/MainHostWindow.h"
  21. #include "Filters/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.reset (new ApplicationProperties());
  39. appProperties->setStorageParameters (options);
  40. mainWindow.reset (new MainHostWindow());
  41. mainWindow->setUsingNativeTitleBar (true);
  42. commandManager.registerAllCommandsForTarget (this);
  43. commandManager.registerAllCommandsForTarget (mainWindow.get());
  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. #if JUCE_ANDROID || JUCE_IOS
  59. fileToOpen = FilterGraph::getDefaultGraphDocumentOnMobile();
  60. #else
  61. for (int i = 0; i < getCommandLineParameterArray().size(); ++i)
  62. {
  63. fileToOpen = File::getCurrentWorkingDirectory().getChildFile (getCommandLineParameterArray()[i]);
  64. if (fileToOpen.existsAsFile())
  65. break;
  66. }
  67. #endif
  68. if (! fileToOpen.existsAsFile())
  69. {
  70. RecentlyOpenedFilesList recentFiles;
  71. recentFiles.restoreFromString (getAppProperties().getUserSettings()->getValue ("recentFilterGraphFiles"));
  72. if (recentFiles.getNumFiles() > 0)
  73. fileToOpen = recentFiles.getFile (0);
  74. }
  75. if (fileToOpen.existsAsFile())
  76. if (auto* graph = mainWindow->graphHolder.get())
  77. if (auto* ioGraph = graph->graph.get())
  78. ioGraph->loadFrom (fileToOpen, true);
  79. }
  80. void shutdown() override
  81. {
  82. mainWindow = nullptr;
  83. appProperties = nullptr;
  84. LookAndFeel::setDefaultLookAndFeel (nullptr);
  85. }
  86. void suspended() override
  87. {
  88. #if JUCE_ANDROID || JUCE_IOS
  89. if (GraphDocumentComponent* graph = mainWindow->graphHolder.get())
  90. if (FilterGraph* ioGraph = graph->graph.get())
  91. ioGraph->saveDocument (FilterGraph::getDefaultGraphDocumentOnMobile());
  92. #endif
  93. }
  94. void systemRequestedQuit() override
  95. {
  96. if (mainWindow != nullptr)
  97. mainWindow->tryToQuitApplication();
  98. else
  99. JUCEApplicationBase::quit();
  100. }
  101. void backButtonPressed() override
  102. {
  103. if (mainWindow->graphHolder != nullptr)
  104. mainWindow->graphHolder->hideLastSidePanel();
  105. }
  106. const String getApplicationName() override { return "Juce Plug-In Host"; }
  107. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  108. bool moreThanOneInstanceAllowed() override { return true; }
  109. ApplicationCommandManager commandManager;
  110. std::unique_ptr<ApplicationProperties> appProperties;
  111. private:
  112. std::unique_ptr<MainHostWindow> mainWindow;
  113. };
  114. static PluginHostApp& getApp() { return *dynamic_cast<PluginHostApp*>(JUCEApplication::getInstance()); }
  115. ApplicationProperties& getAppProperties() { return *getApp().appProperties; }
  116. ApplicationCommandManager& getCommandManager() { return getApp().commandManager; }
  117. bool isOnTouchDevice() { return Desktop::getInstance().getMainMouseSource().isTouch(); }
  118. // This kicks the whole thing off..
  119. START_JUCE_APPLICATION (PluginHostApp)