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.

120 lines
4.1KB

  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. {
  26. public:
  27. PluginHostApp() {}
  28. void initialise (const String&) override
  29. {
  30. // initialise our settings file..
  31. PropertiesFile::Options options;
  32. options.applicationName = "Juce Audio Plugin Host";
  33. options.filenameSuffix = "settings";
  34. options.osxLibrarySubFolder = "Preferences";
  35. appProperties = new ApplicationProperties();
  36. appProperties->setStorageParameters (options);
  37. LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  38. mainWindow = new MainHostWindow();
  39. mainWindow->setUsingNativeTitleBar (true);
  40. commandManager.registerAllCommandsForTarget (this);
  41. commandManager.registerAllCommandsForTarget (mainWindow);
  42. mainWindow->menuItemsChanged();
  43. File fileToOpen;
  44. for (int i = 0; i < getCommandLineParameterArray().size(); ++i)
  45. {
  46. fileToOpen = File::getCurrentWorkingDirectory().getChildFile (getCommandLineParameterArray()[i]);
  47. if (fileToOpen.existsAsFile())
  48. break;
  49. }
  50. if (! fileToOpen.existsAsFile())
  51. {
  52. RecentlyOpenedFilesList recentFiles;
  53. recentFiles.restoreFromString (getAppProperties().getUserSettings()->getValue ("recentFilterGraphFiles"));
  54. if (recentFiles.getNumFiles() > 0)
  55. fileToOpen = recentFiles.getFile (0);
  56. }
  57. if (fileToOpen.existsAsFile())
  58. if (GraphDocumentComponent* graph = mainWindow->getGraphEditor())
  59. graph->graph.loadFrom (fileToOpen, true);
  60. }
  61. void shutdown() override
  62. {
  63. mainWindow = nullptr;
  64. appProperties = nullptr;
  65. LookAndFeel::setDefaultLookAndFeel (nullptr);
  66. }
  67. void systemRequestedQuit() override
  68. {
  69. if (mainWindow != nullptr)
  70. mainWindow->tryToQuitApplication();
  71. else
  72. JUCEApplicationBase::quit();
  73. }
  74. const String getApplicationName() override { return "Juce Plug-In Host"; }
  75. const String getApplicationVersion() override { return ProjectInfo::versionString; }
  76. bool moreThanOneInstanceAllowed() override { return true; }
  77. ApplicationCommandManager commandManager;
  78. ScopedPointer<ApplicationProperties> appProperties;
  79. LookAndFeel_V3 lookAndFeel;
  80. private:
  81. ScopedPointer<MainHostWindow> mainWindow;
  82. };
  83. static PluginHostApp& getApp() { return *dynamic_cast<PluginHostApp*>(JUCEApplication::getInstance()); }
  84. ApplicationCommandManager& getCommandManager() { return getApp().commandManager; }
  85. ApplicationProperties& getAppProperties() { return *getApp().appProperties; }
  86. // This kicks the whole thing off..
  87. START_JUCE_APPLICATION (PluginHostApp)