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.

314 lines
13KB

  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. #pragma once
  20. #include "../../Utility/UI/PropertyComponents/jucer_LabelPropertyComponent.h"
  21. //==============================================================================
  22. class GlobalPathsWindowComponent : public Component,
  23. private Timer,
  24. private Value::Listener
  25. {
  26. public:
  27. GlobalPathsWindowComponent()
  28. {
  29. addChildComponent (rescanJUCEPathButton);
  30. rescanJUCEPathButton.onClick = [this]
  31. {
  32. ProjucerApplication::getApp().rescanJUCEPathModules();
  33. lastJUCEModulePath = getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS()).get();
  34. };
  35. addChildComponent (rescanUserPathButton);
  36. rescanUserPathButton.onClick = [this]
  37. {
  38. ProjucerApplication::getApp().rescanUserPathModules();
  39. lastUserModulePath = getAppSettings().getStoredPath (Ids::defaultUserModulePath, TargetOS::getThisOS()).get();
  40. };
  41. addAndMakeVisible (resetToDefaultsButton);
  42. resetToDefaultsButton.onClick = [this] { resetCurrentOSPathsToDefaults(); };
  43. addAndMakeVisible (propertyViewport);
  44. propertyViewport.setViewedComponent (&propertyGroup, false);
  45. auto os = TargetOS::getThisOS();
  46. if (os == TargetOS::osx) selectedOSValue = "osx";
  47. else if (os == TargetOS::windows) selectedOSValue = "windows";
  48. else if (os == TargetOS::linux) selectedOSValue = "linux";
  49. selectedOSValue.addListener (this);
  50. buildProps();
  51. lastJUCEModulePath = getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS()).get();
  52. lastUserModulePath = getAppSettings().getStoredPath (Ids::defaultUserModulePath, TargetOS::getThisOS()).get();
  53. }
  54. ~GlobalPathsWindowComponent() override
  55. {
  56. auto juceValue = getAppSettings().getStoredPath (Ids::defaultJuceModulePath, TargetOS::getThisOS());
  57. auto userValue = getAppSettings().getStoredPath (Ids::defaultUserModulePath, TargetOS::getThisOS());
  58. auto jucePathNeedsScanning = (! juceValue.isUsingDefault() && juceValue.get() != lastJUCEModulePath);
  59. auto userPathNeedsScanning = (! userValue.isUsingDefault() && userValue.get() != lastUserModulePath);
  60. if (jucePathNeedsScanning)
  61. ProjucerApplication::getApp().rescanJUCEPathModules();
  62. if (userPathNeedsScanning)
  63. ProjucerApplication::getApp().rescanUserPathModules();
  64. }
  65. void paint (Graphics& g) override
  66. {
  67. g.fillAll (findColour (backgroundColourId));
  68. }
  69. void paintOverChildren (Graphics& g) override
  70. {
  71. g.setColour (findColour (defaultHighlightColourId).withAlpha (flashAlpha));
  72. g.fillRect (boundsToHighlight);
  73. }
  74. void resized() override
  75. {
  76. auto b = getLocalBounds().reduced (10);
  77. auto buttonBounds = b.removeFromBottom (50);
  78. rescanJUCEPathButton.setBounds (buttonBounds.removeFromLeft (150).reduced (5, 10));
  79. rescanUserPathButton.setBounds (buttonBounds.removeFromLeft (150).reduced (5, 10));
  80. resetToDefaultsButton.setBounds (buttonBounds.removeFromRight (150).reduced (5, 10));
  81. propertyGroup.updateSize (0, 0, getWidth() - 20 - propertyViewport.getScrollBarThickness());
  82. propertyViewport.setBounds (b);
  83. }
  84. void highlightJUCEPath()
  85. {
  86. if (isTimerRunning() || ! isSelectedOSThisOS())
  87. return;
  88. PropertyComponent* jucePathPropertyComponent = nullptr;
  89. for (auto* prop : propertyGroup.properties)
  90. if (prop->getName() == "Path to JUCE")
  91. jucePathPropertyComponent = prop;
  92. if (jucePathPropertyComponent != nullptr)
  93. {
  94. boundsToHighlight = getLocalArea (&propertyGroup, jucePathPropertyComponent->getBounds());
  95. flashAlpha = 0.0f;
  96. hasFlashed = false;
  97. startTimer (25);
  98. }
  99. }
  100. private:
  101. //==============================================================================
  102. void timerCallback() override
  103. {
  104. flashAlpha += (hasFlashed ? -0.05f : 0.05f);
  105. if (flashAlpha > 0.75f)
  106. {
  107. hasFlashed = true;
  108. }
  109. else if (flashAlpha < 0.0f)
  110. {
  111. flashAlpha = 0.0f;
  112. boundsToHighlight = {};
  113. stopTimer();
  114. }
  115. repaint();
  116. }
  117. void valueChanged (Value&) override
  118. {
  119. buildProps();
  120. resized();
  121. }
  122. //==============================================================================
  123. bool isSelectedOSThisOS() { return TargetOS::getThisOS() == getSelectedOS(); }
  124. TargetOS::OS getSelectedOS() const
  125. {
  126. auto val = selectedOSValue.getValue();
  127. if (val == "osx") return TargetOS::osx;
  128. else if (val == "windows") return TargetOS::windows;
  129. else if (val == "linux") return TargetOS::linux;
  130. jassertfalse;
  131. return TargetOS::unknown;
  132. }
  133. //==============================================================================
  134. void buildProps()
  135. {
  136. updateValues();
  137. PropertyListBuilder builder;
  138. auto isThisOS = isSelectedOSThisOS();
  139. builder.add (new ChoicePropertyComponent (selectedOSValue, "OS", { "OSX", "Windows", "Linux" }, { "osx", "windows", "linux" }),
  140. "Use this dropdown to set the global paths for different OSes. "
  141. "\nN.B. These paths are stored locally and will only be used when "
  142. "saving a project on this machine. Other machines will have their own "
  143. "locally stored paths.");
  144. builder.add (new LabelPropertyComponent ("JUCE"), {});
  145. builder.add (new FilePathPropertyComponent (jucePathValue, "Path to JUCE", true, isThisOS),
  146. "This should be the path to the top-level directory of your JUCE folder. "
  147. "This path will be used when searching for the JUCE examples and DemoRunner application.");
  148. builder.add (new FilePathPropertyComponent (juceModulePathValue, "JUCE Modules", true, isThisOS),
  149. String ("This should be the path to the folder containing the JUCE modules that you wish to use, typically the \"modules\" directory of your JUCE folder.")
  150. + (isThisOS ? " Use the button below to re-scan a new path." : ""));
  151. builder.add (new FilePathPropertyComponent (userModulePathValue, "User Modules", true, isThisOS, {}, {}, true),
  152. String ("A path to a folder containing any custom modules that you wish to use.")
  153. + (isThisOS ? " Use the button below to re-scan new paths." : ""));
  154. builder.add (new LabelPropertyComponent ("SDKs"), {});
  155. builder.add (new FilePathPropertyComponent (vstPathValue, "VST (Legacy) SDK", true, isThisOS),
  156. "If you are building a legacy VST plug-in then this path should point to a VST2 SDK. "
  157. "The VST2 SDK can be obtained from the vstsdk3610_11_06_2018_build_37 (or older) VST3 SDK or JUCE version 5.3.2. "
  158. "You also need a VST2 license from Steinberg to distribute VST2 plug-ins.");
  159. builder.add (new FilePathPropertyComponent (vst3PathValue, "VST3 SDK", true, isThisOS),
  160. "This path can be set to use a custom VST3 SDK instead of the one which is embedded in JUCE.");
  161. if (getSelectedOS() != TargetOS::linux)
  162. {
  163. builder.add (new FilePathPropertyComponent (aaxPathValue, "AAX SDK", true, isThisOS),
  164. "If you are building AAX plug-ins, this should be the path to the AAX SDK folder.");
  165. builder.add (new FilePathPropertyComponent (rtasPathValue, "RTAS SDK (deprecated)", true, isThisOS),
  166. "If you are building RTAS plug-ins, this should be the path to the RTAS SDK folder.");
  167. }
  168. builder.add (new FilePathPropertyComponent (androidSDKPathValue, "Android SDK", true, isThisOS),
  169. "This path will be used when writing the local.properties file of an Android project and should point to the Android SDK folder.");
  170. builder.add (new FilePathPropertyComponent (androidNDKPathValue, "Android NDK", true, isThisOS),
  171. "This path will be used when writing the local.properties file of an Android project and should point to the Android NDK folder.");
  172. if (isThisOS)
  173. {
  174. builder.add (new LabelPropertyComponent ("Other"), {});
  175. #if JUCE_MAC
  176. String exeLabel ("app");
  177. #elif JUCE_WINDOWS
  178. String exeLabel ("executable");
  179. #else
  180. String exeLabel ("startup script");
  181. #endif
  182. builder.add (new FilePathPropertyComponent (clionExePathValue, "CLion " + exeLabel, false, isThisOS),
  183. "This path will be used for the \"Save Project and Open in IDE...\" option of the CLion exporter.");
  184. builder.add (new FilePathPropertyComponent (androidStudioExePathValue, "Android Studio " + exeLabel, false, isThisOS),
  185. "This path will be used for the \"Save Project and Open in IDE...\" option of the Android Studio exporter.");
  186. rescanJUCEPathButton.setVisible (true);
  187. rescanUserPathButton.setVisible (true);
  188. }
  189. else
  190. {
  191. rescanJUCEPathButton.setVisible (false);
  192. rescanUserPathButton.setVisible (false);
  193. }
  194. propertyGroup.setProperties (builder);
  195. }
  196. void updateValues()
  197. {
  198. auto& settings = getAppSettings();
  199. auto os = getSelectedOS();
  200. jucePathValue = settings.getStoredPath (Ids::jucePath, os);
  201. juceModulePathValue = settings.getStoredPath (Ids::defaultJuceModulePath, os);
  202. userModulePathValue = settings.getStoredPath (Ids::defaultUserModulePath, os);
  203. vstPathValue = settings.getStoredPath (Ids::vstLegacyPath, os);
  204. vst3PathValue = settings.getStoredPath (Ids::vst3Path, os);
  205. rtasPathValue = settings.getStoredPath (Ids::rtasPath, os);
  206. aaxPathValue = settings.getStoredPath (Ids::aaxPath, os);
  207. androidSDKPathValue = settings.getStoredPath (Ids::androidSDKPath, os);
  208. androidNDKPathValue = settings.getStoredPath (Ids::androidNDKPath, os);
  209. clionExePathValue = settings.getStoredPath (Ids::clionExePath, os);
  210. androidStudioExePathValue = settings.getStoredPath (Ids::androidStudioExePath, os);
  211. }
  212. void resetCurrentOSPathsToDefaults()
  213. {
  214. jucePathValue .resetToDefault();
  215. juceModulePathValue .resetToDefault();
  216. userModulePathValue .resetToDefault();
  217. vstPathValue .resetToDefault();
  218. vst3PathValue .resetToDefault();
  219. rtasPathValue .resetToDefault();
  220. aaxPathValue .resetToDefault();
  221. androidSDKPathValue .resetToDefault();
  222. androidNDKPathValue .resetToDefault();
  223. clionExePathValue .resetToDefault();
  224. androidStudioExePathValue.resetToDefault();
  225. repaint();
  226. }
  227. //==============================================================================
  228. Value selectedOSValue;
  229. ValueWithDefault jucePathValue, juceModulePathValue, userModulePathValue,
  230. vst3PathValue, vstPathValue, rtasPathValue, aaxPathValue,
  231. androidSDKPathValue, androidNDKPathValue,
  232. clionExePathValue, androidStudioExePathValue;
  233. Viewport propertyViewport;
  234. PropertyGroupComponent propertyGroup { "Global Paths", { getIcons().openFolder, Colours::transparentBlack } };
  235. TextButton rescanJUCEPathButton { "Re-scan JUCE Modules" },
  236. rescanUserPathButton { "Re-scan User Modules" },
  237. resetToDefaultsButton { "Reset to Defaults" };
  238. Rectangle<int> boundsToHighlight;
  239. float flashAlpha = 0.0f;
  240. bool hasFlashed = false;
  241. var lastJUCEModulePath, lastUserModulePath;
  242. //==============================================================================
  243. JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (GlobalPathsWindowComponent)
  244. };