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.

1262 lines
44KB

  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 "../jucer_Headers.h"
  18. #include "jucer_Project.h"
  19. #include "jucer_ProjectType.h"
  20. #include "../Project Saving/jucer_ProjectExporter.h"
  21. #include "../Project Saving/jucer_ProjectSaver.h"
  22. #include "../Application/jucer_OpenDocumentManager.h"
  23. #include "../Application/jucer_Application.h"
  24. namespace
  25. {
  26. String makeValid4CC (const String& seed)
  27. {
  28. String s (CodeHelpers::makeValidIdentifier (seed, false, true, false) + "xxxx");
  29. return s.substring (0, 1).toUpperCase()
  30. + s.substring (1, 4).toLowerCase();
  31. }
  32. }
  33. //==============================================================================
  34. Project::Project (const File& f)
  35. : FileBasedDocument (projectFileExtension,
  36. String ("*") + projectFileExtension,
  37. "Choose a Jucer project to load",
  38. "Save Jucer project"),
  39. projectRoot (Ids::JUCERPROJECT),
  40. isSaving (false)
  41. {
  42. Logger::writeToLog ("Loading project: " + f.getFullPathName());
  43. setFile (f);
  44. removeDefunctExporters();
  45. updateOldModulePaths();
  46. setMissingDefaultValues();
  47. setChangedFlag (false);
  48. projectRoot.addListener (this);
  49. modificationTime = getFile().getLastModificationTime();
  50. }
  51. Project::~Project()
  52. {
  53. projectRoot.removeListener (this);
  54. ProjucerApplication::getApp().openDocumentManager.closeAllDocumentsUsingProject (*this, false);
  55. }
  56. const char* Project::projectFileExtension = ".jucer";
  57. //==============================================================================
  58. void Project::setTitle (const String& newTitle)
  59. {
  60. projectRoot.setProperty (Ids::name, newTitle, getUndoManagerFor (projectRoot));
  61. getMainGroup().getNameValue() = newTitle;
  62. }
  63. String Project::getTitle() const
  64. {
  65. return projectRoot.getChildWithName (Ids::MAINGROUP) [Ids::name];
  66. }
  67. String Project::getDocumentTitle()
  68. {
  69. return getTitle();
  70. }
  71. void Project::updateProjectSettings()
  72. {
  73. projectRoot.setProperty (Ids::jucerVersion, ProjectInfo::versionString, nullptr);
  74. projectRoot.setProperty (Ids::name, getDocumentTitle(), nullptr);
  75. }
  76. void Project::setMissingDefaultValues()
  77. {
  78. if (! projectRoot.hasProperty (Ids::ID))
  79. projectRoot.setProperty (Ids::ID, createAlphaNumericUID(), nullptr);
  80. // Create main file group if missing
  81. if (! projectRoot.getChildWithName (Ids::MAINGROUP).isValid())
  82. {
  83. Item mainGroup (*this, ValueTree (Ids::MAINGROUP), false);
  84. projectRoot.addChild (mainGroup.state, 0, 0);
  85. }
  86. getMainGroup().initialiseMissingProperties();
  87. if (getDocumentTitle().isEmpty())
  88. setTitle ("JUCE Project");
  89. if (! projectRoot.hasProperty (Ids::projectType))
  90. getProjectTypeValue() = ProjectType_GUIApp::getTypeName();
  91. if (! projectRoot.hasProperty (Ids::version))
  92. getVersionValue() = "1.0.0";
  93. updateOldStyleConfigList();
  94. moveOldPropertyFromProjectToAllExporters (Ids::bigIcon);
  95. moveOldPropertyFromProjectToAllExporters (Ids::smallIcon);
  96. if (getProjectType().isAudioPlugin())
  97. setMissingAudioPluginDefaultValues();
  98. getModules().sortAlphabetically();
  99. if (getBundleIdentifier().toString().isEmpty())
  100. getBundleIdentifier() = getDefaultBundleIdentifier();
  101. if (shouldIncludeBinaryInAppConfig() == var())
  102. shouldIncludeBinaryInAppConfig() = true;
  103. ProjucerApplication::getApp().updateNewlyOpenedProject (*this);
  104. }
  105. void Project::updateDeprecatedProjectSettingsInteractively()
  106. {
  107. jassert (! ProjucerApplication::getApp().isRunningCommandLine);
  108. for (Project::ExporterIterator exporter (*this); exporter.next();)
  109. exporter->updateDeprecatedProjectSettingsInteractively();
  110. }
  111. void Project::setMissingAudioPluginDefaultValues()
  112. {
  113. const String sanitisedProjectName (CodeHelpers::makeValidIdentifier (getTitle(), false, true, false));
  114. setValueIfVoid (shouldBuildVST(), true);
  115. setValueIfVoid (shouldBuildVST3(), false);
  116. setValueIfVoid (shouldBuildAU(), true);
  117. setValueIfVoid (shouldBuildAUv3(), false);
  118. setValueIfVoid (shouldBuildRTAS(), false);
  119. setValueIfVoid (shouldBuildAAX(), false);
  120. setValueIfVoid (shouldBuildStandalone(), false);
  121. setValueIfVoid (getPluginName(), getTitle());
  122. setValueIfVoid (getPluginDesc(), getTitle());
  123. setValueIfVoid (getPluginManufacturer(), "yourcompany");
  124. setValueIfVoid (getPluginManufacturerCode(), "Manu");
  125. setValueIfVoid (getPluginCode(), makeValid4CC (getProjectUID() + getProjectUID()));
  126. setValueIfVoid (getPluginChannelConfigs(), String());
  127. setValueIfVoid (getPluginIsSynth(), false);
  128. setValueIfVoid (getPluginWantsMidiInput(), false);
  129. setValueIfVoid (getPluginProducesMidiOut(), false);
  130. setValueIfVoid (getPluginIsMidiEffectPlugin(), false);
  131. setValueIfVoid (getPluginEditorNeedsKeyFocus(), false);
  132. setValueIfVoid (getPluginAUExportPrefix(), sanitisedProjectName + "AU");
  133. setValueIfVoid (getPluginRTASCategory(), String());
  134. setValueIfVoid (getBundleIdentifier(), getDefaultBundleIdentifier());
  135. setValueIfVoid (getAAXIdentifier(), getDefaultAAXIdentifier());
  136. setValueIfVoid (getPluginAAXCategory(), "AAX_ePlugInCategory_Dynamics");
  137. }
  138. void Project::updateOldStyleConfigList()
  139. {
  140. ValueTree deprecatedConfigsList (projectRoot.getChildWithName (Ids::CONFIGURATIONS));
  141. if (deprecatedConfigsList.isValid())
  142. {
  143. projectRoot.removeChild (deprecatedConfigsList, nullptr);
  144. for (Project::ExporterIterator exporter (*this); exporter.next();)
  145. {
  146. if (exporter->getNumConfigurations() == 0)
  147. {
  148. ValueTree newConfigs (deprecatedConfigsList.createCopy());
  149. if (! exporter->isXcode())
  150. {
  151. for (int j = newConfigs.getNumChildren(); --j >= 0;)
  152. {
  153. ValueTree config (newConfigs.getChild(j));
  154. config.removeProperty (Ids::osxSDK, nullptr);
  155. config.removeProperty (Ids::osxCompatibility, nullptr);
  156. config.removeProperty (Ids::osxArchitecture, nullptr);
  157. }
  158. }
  159. exporter->settings.addChild (newConfigs, 0, nullptr);
  160. }
  161. }
  162. }
  163. }
  164. void Project::moveOldPropertyFromProjectToAllExporters (Identifier name)
  165. {
  166. if (projectRoot.hasProperty (name))
  167. {
  168. for (Project::ExporterIterator exporter (*this); exporter.next();)
  169. exporter->settings.setProperty (name, projectRoot [name], nullptr);
  170. projectRoot.removeProperty (name, nullptr);
  171. }
  172. }
  173. void Project::removeDefunctExporters()
  174. {
  175. ValueTree exporters (projectRoot.getChildWithName (Ids::EXPORTFORMATS));
  176. for (;;)
  177. {
  178. ValueTree oldVC6Exporter (exporters.getChildWithName ("MSVC6"));
  179. if (oldVC6Exporter.isValid())
  180. exporters.removeChild (oldVC6Exporter, nullptr);
  181. else
  182. break;
  183. }
  184. }
  185. void Project::updateOldModulePaths()
  186. {
  187. for (Project::ExporterIterator exporter (*this); exporter.next();)
  188. exporter->updateOldModulePaths();
  189. }
  190. //==============================================================================
  191. static int getVersionElement (StringRef v, int index)
  192. {
  193. StringArray parts;
  194. parts.addTokens (v, "., ", StringRef());
  195. return parts [parts.size() - index - 1].getIntValue();
  196. }
  197. static int getJuceVersion (const String& v)
  198. {
  199. return getVersionElement (v, 2) * 100000
  200. + getVersionElement (v, 1) * 1000
  201. + getVersionElement (v, 0);
  202. }
  203. static int getBuiltJuceVersion()
  204. {
  205. return JUCE_MAJOR_VERSION * 100000
  206. + JUCE_MINOR_VERSION * 1000
  207. + JUCE_BUILDNUMBER;
  208. }
  209. static bool isAnyModuleNewerThanProjucer (const OwnedArray<ModuleDescription>& modules)
  210. {
  211. for (int i = modules.size(); --i >= 0;)
  212. {
  213. const ModuleDescription* m = modules.getUnchecked(i);
  214. if (m->getID().startsWith ("juce_")
  215. && getJuceVersion (m->getVersion()) > getBuiltJuceVersion())
  216. return true;
  217. }
  218. return false;
  219. }
  220. void Project::warnAboutOldProjucerVersion()
  221. {
  222. ModuleList available;
  223. available.scanAllKnownFolders (*this);
  224. if (isAnyModuleNewerThanProjucer (available.modules))
  225. {
  226. if (ProjucerApplication::getApp().isRunningCommandLine)
  227. std::cout << "WARNING! This version of the Projucer is out-of-date!" << std::endl;
  228. else
  229. AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
  230. "Projucer",
  231. "This version of the Projucer is out-of-date!"
  232. "\n\n"
  233. "Always make sure that you're running the very latest version, "
  234. "preferably compiled directly from the JUCE repository that you're working with!");
  235. }
  236. }
  237. //==============================================================================
  238. static File lastDocumentOpened;
  239. File Project::getLastDocumentOpened() { return lastDocumentOpened; }
  240. void Project::setLastDocumentOpened (const File& file) { lastDocumentOpened = file; }
  241. static void registerRecentFile (const File& file)
  242. {
  243. RecentlyOpenedFilesList::registerRecentFileNatively (file);
  244. getAppSettings().recentFiles.addFile (file);
  245. getAppSettings().flush();
  246. }
  247. //==============================================================================
  248. Result Project::loadDocument (const File& file)
  249. {
  250. ScopedPointer<XmlElement> xml (XmlDocument::parse (file));
  251. if (xml == nullptr || ! xml->hasTagName (Ids::JUCERPROJECT.toString()))
  252. return Result::fail ("Not a valid Jucer project!");
  253. ValueTree newTree (ValueTree::fromXml (*xml));
  254. if (! newTree.hasType (Ids::JUCERPROJECT))
  255. return Result::fail ("The document contains errors and couldn't be parsed!");
  256. registerRecentFile (file);
  257. enabledModulesList = nullptr;
  258. projectRoot = newTree;
  259. removeDefunctExporters();
  260. setMissingDefaultValues();
  261. updateOldModulePaths();
  262. setChangedFlag (false);
  263. if (! ProjucerApplication::getApp().isRunningCommandLine)
  264. warnAboutOldProjucerVersion();
  265. return Result::ok();
  266. }
  267. Result Project::saveDocument (const File& file)
  268. {
  269. return saveProject (file, false);
  270. }
  271. Result Project::saveProject (const File& file, bool isCommandLineApp)
  272. {
  273. if (isSaving)
  274. return Result::ok();
  275. updateProjectSettings();
  276. sanitiseConfigFlags();
  277. if (! isCommandLineApp)
  278. registerRecentFile (file);
  279. const ScopedValueSetter<bool> vs (isSaving, true, false);
  280. ProjectSaver saver (*this, file);
  281. return saver.save (! isCommandLineApp);
  282. }
  283. Result Project::saveResourcesOnly (const File& file)
  284. {
  285. ProjectSaver saver (*this, file);
  286. return saver.saveResourcesOnly();
  287. }
  288. //==============================================================================
  289. void Project::valueTreePropertyChanged (ValueTree&, const Identifier& property)
  290. {
  291. if (property == Ids::projectType)
  292. setMissingDefaultValues();
  293. changed();
  294. }
  295. void Project::valueTreeChildAdded (ValueTree&, ValueTree&) { changed(); }
  296. void Project::valueTreeChildRemoved (ValueTree&, ValueTree&, int) { changed(); }
  297. void Project::valueTreeChildOrderChanged (ValueTree&, int, int) { changed(); }
  298. void Project::valueTreeParentChanged (ValueTree&) {}
  299. //==============================================================================
  300. bool Project::hasProjectBeenModified()
  301. {
  302. Time newModificationTime = getFile().getLastModificationTime();
  303. Time oldModificationTime = modificationTime;
  304. modificationTime = newModificationTime;
  305. return (newModificationTime.toMilliseconds() > (oldModificationTime.toMilliseconds() + 1000LL));
  306. }
  307. //==============================================================================
  308. File Project::resolveFilename (String filename) const
  309. {
  310. if (filename.isEmpty())
  311. return File();
  312. filename = replacePreprocessorDefs (getPreprocessorDefs(), filename);
  313. if (FileHelpers::isAbsolutePath (filename))
  314. return File::createFileWithoutCheckingPath (FileHelpers::currentOSStylePath (filename)); // (avoid assertions for windows-style paths)
  315. return getFile().getSiblingFile (FileHelpers::currentOSStylePath (filename));
  316. }
  317. String Project::getRelativePathForFile (const File& file) const
  318. {
  319. String filename (file.getFullPathName());
  320. File relativePathBase (getFile().getParentDirectory());
  321. String p1 (relativePathBase.getFullPathName());
  322. String p2 (file.getFullPathName());
  323. while (p1.startsWithChar (File::separator))
  324. p1 = p1.substring (1);
  325. while (p2.startsWithChar (File::separator))
  326. p2 = p2.substring (1);
  327. if (p1.upToFirstOccurrenceOf (File::separatorString, true, false)
  328. .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::separatorString, true, false)))
  329. {
  330. filename = FileHelpers::getRelativePathFrom (file, relativePathBase);
  331. }
  332. return filename;
  333. }
  334. //==============================================================================
  335. const ProjectType& Project::getProjectType() const
  336. {
  337. if (const ProjectType* type = ProjectType::findType (getProjectTypeString()))
  338. return *type;
  339. const ProjectType* guiType = ProjectType::findType (ProjectType_GUIApp::getTypeName());
  340. jassert (guiType != nullptr);
  341. return *guiType;
  342. }
  343. //==============================================================================
  344. void Project::createPropertyEditors (PropertyListBuilder& props)
  345. {
  346. props.add (new TextPropertyComponent (getProjectNameValue(), "Project Name", 256, false),
  347. "The name of the project.");
  348. props.add (new TextPropertyComponent (getVersionValue(), "Project Version", 16, false),
  349. "The project's version number, This should be in the format major.minor.point[.point]");
  350. props.add (new TextPropertyComponent (getCompanyName(), "Company Name", 256, false),
  351. "Your company name, which will be added to the properties of the binary where possible");
  352. props.add (new TextPropertyComponent (getCompanyWebsite(), "Company Website", 256, false),
  353. "Your company website, which will be added to the properties of the binary where possible");
  354. props.add (new TextPropertyComponent (getCompanyEmail(), "Company E-mail", 256, false),
  355. "Your company e-mail, which will be added to the properties of the binary where possible");
  356. {
  357. StringArray projectTypeNames;
  358. Array<var> projectTypeCodes;
  359. const Array<ProjectType*>& types = ProjectType::getAllTypes();
  360. for (int i = 0; i < types.size(); ++i)
  361. {
  362. projectTypeNames.add (types.getUnchecked(i)->getDescription());
  363. projectTypeCodes.add (types.getUnchecked(i)->getType());
  364. }
  365. props.add (new ChoicePropertyComponent (getProjectTypeValue(), "Project Type", projectTypeNames, projectTypeCodes));
  366. }
  367. props.add (new TextPropertyComponent (getBundleIdentifier(), "Bundle Identifier", 256, false),
  368. "A unique identifier for this product, mainly for use in OSX/iOS builds. It should be something like 'com.yourcompanyname.yourproductname'");
  369. if (getProjectType().isAudioPlugin())
  370. createAudioPluginPropertyEditors (props);
  371. {
  372. const int maxSizes[] = { 20480, 10240, 6144, 2048, 1024, 512, 256, 128, 64 };
  373. StringArray maxSizeNames;
  374. Array<var> maxSizeCodes;
  375. maxSizeNames.add (TRANS("Default"));
  376. maxSizeCodes.add (var());
  377. maxSizeNames.add (String());
  378. maxSizeCodes.add (var());
  379. for (int i = 0; i < numElementsInArray (maxSizes); ++i)
  380. {
  381. const int sizeInBytes = maxSizes[i] * 1024;
  382. maxSizeNames.add (File::descriptionOfSizeInBytes (sizeInBytes));
  383. maxSizeCodes.add (sizeInBytes);
  384. }
  385. props.add (new ChoicePropertyComponent (getMaxBinaryFileSize(), "BinaryData.cpp size limit", maxSizeNames, maxSizeCodes),
  386. "When splitting binary data into multiple cpp files, the Projucer attempts to keep the file sizes below this threshold. "
  387. "(Note that individual resource files which are larger than this size cannot be split across multiple cpp files).");
  388. }
  389. props.add (new BooleanPropertyComponent (shouldIncludeBinaryInAppConfig(), "Include Binary",
  390. "Include BinaryData.h in the AppConfig.h file"));
  391. props.add (new TextPropertyComponent (binaryDataNamespace(), "BinaryData Namespace", 256, false),
  392. "The namespace containing the binary assests. If left empty this defaults to \"BinaryData\".");
  393. props.add (new TextPropertyComponent (getProjectPreprocessorDefs(), "Preprocessor definitions", 32768, true),
  394. "Global preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  395. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  396. props.add (new TextPropertyComponent (getProjectUserNotes(), "Notes", 32768, true),
  397. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  398. }
  399. void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props)
  400. {
  401. props.add (new BooleanPropertyComponent (shouldBuildVST(), "Build VST", "Enabled"),
  402. "Whether the project should produce a VST plugin.");
  403. props.add (new BooleanPropertyComponent (shouldBuildVST3(), "Build VST3", "Enabled"),
  404. "Whether the project should produce a VST3 plugin.");
  405. props.add (new BooleanPropertyComponent (shouldBuildAU(), "Build AudioUnit", "Enabled"),
  406. "Whether the project should produce an AudioUnit plugin.");
  407. props.add (new BooleanPropertyComponent (shouldBuildAUv3(), "Build AudioUnit v3", "Enabled"),
  408. "Whether the project should produce an AudioUnit version 3 plugin.");
  409. props.add (new BooleanPropertyComponent (shouldBuildRTAS(), "Build RTAS", "Enabled"),
  410. "Whether the project should produce an RTAS plugin.");
  411. props.add (new BooleanPropertyComponent (shouldBuildAAX(), "Build AAX", "Enabled"),
  412. "Whether the project should produce an AAX plugin.");
  413. /* TODO: this property editor is temporarily disabled because right now we build standalone if and only if
  414. we also build AUv3. However as soon as targets are supported on non-Xcode exporters as well, we should
  415. re-enable this option and allow to build the standalone plug-in independently from AUv3.
  416. */
  417. // props.add (new BooleanPropertyComponent (shouldBuildStandalone(), "Build Standalone", "Enabled"),
  418. // "Whether the project should produce a standalone version of the plugin. Required for AUv3.");
  419. props.add (new TextPropertyComponent (getPluginName(), "Plugin Name", 128, false),
  420. "The name of your plugin (keep it short!)");
  421. props.add (new TextPropertyComponent (getPluginDesc(), "Plugin Description", 256, false),
  422. "A short description of your plugin.");
  423. props.add (new TextPropertyComponent (getPluginManufacturer(), "Plugin Manufacturer", 256, false),
  424. "The name of your company (cannot be blank).");
  425. props.add (new TextPropertyComponent (getPluginManufacturerCode(), "Plugin Manufacturer Code", 4, false),
  426. "A four-character unique ID for your company. Note that for AU compatibility, this must contain at least one upper-case letter!");
  427. props.add (new TextPropertyComponent (getPluginCode(), "Plugin Code", 4, false),
  428. "A four-character unique ID for your plugin. Note that for AU compatibility, this must contain at least one upper-case letter!");
  429. props.add (new TextPropertyComponent (getPluginChannelConfigs(), "Plugin Channel Configurations", 1024, false),
  430. "This list is a comma-separated set list in the form {numIns, numOuts} and each pair indicates a valid plug-in "
  431. "configuration. For example {1, 1}, {2, 2} means that the plugin can be used either with 1 input and 1 output, "
  432. "or with 2 inputs and 2 outputs. If your plug-in requires side-chains, aux output buses etc., then you must leave "
  433. "this field empty and override the setPreferredBusArrangement method in your AudioProcessor.");
  434. props.add (new BooleanPropertyComponent (getPluginIsSynth(), "Plugin is a Synth", "Is a Synth"),
  435. "Enable this if you want your plugin to be treated as a synth or generator. It doesn't make much difference to the plugin itself, but some hosts treat synths differently to other plugins.");
  436. props.add (new BooleanPropertyComponent (getPluginWantsMidiInput(), "Plugin Midi Input", "Plugin wants midi input"),
  437. "Enable this if you want your plugin to accept midi messages.");
  438. props.add (new BooleanPropertyComponent (getPluginProducesMidiOut(), "Plugin Midi Output", "Plugin produces midi output"),
  439. "Enable this if your plugin is going to produce midi messages.");
  440. props.add (new BooleanPropertyComponent (getPluginIsMidiEffectPlugin(), "Midi Effect Plugin", "Plugin is a midi effect plugin"),
  441. "Enable this if your plugin only processes midi and no audio.");
  442. props.add (new BooleanPropertyComponent (getPluginEditorNeedsKeyFocus(), "Key Focus", "Plugin editor requires keyboard focus"),
  443. "Enable this if your plugin needs keyboard input - some hosts can be a bit funny about keyboard focus..");
  444. props.add (new TextPropertyComponent (getPluginAUExportPrefix(), "Plugin AU Export Prefix", 64, false),
  445. "A prefix for the names of exported entry-point functions that the component exposes - typically this will be a version of your plugin's name that can be used as part of a C++ token.");
  446. props.add (new TextPropertyComponent (getPluginAUMainType(), "Plugin AU Main Type", 128, false),
  447. "In an AU, this is the value that is set as JucePlugin_AUMainType. Leave it blank unless you want to use a custom value.");
  448. props.add (new TextPropertyComponent (getPluginVSTCategory(), "VST Category", 64, false),
  449. "In a VST, this is the value that is set as JucePlugin_VSTCategory. Leave it blank unless you want to use a custom value.");
  450. props.add (new TextPropertyComponent (getPluginRTASCategory(), "Plugin RTAS Category", 64, false),
  451. "(Leave this blank if your plugin is a synth). This is one of the RTAS categories from FicPluginEnums.h, such as: ePlugInCategory_None, ePlugInCategory_EQ, ePlugInCategory_Dynamics, "
  452. "ePlugInCategory_PitchShift, ePlugInCategory_Reverb, ePlugInCategory_Delay, "
  453. "ePlugInCategory_Modulation, ePlugInCategory_Harmonic, ePlugInCategory_NoiseReduction, "
  454. "ePlugInCategory_Dither, ePlugInCategory_SoundField");
  455. props.add (new TextPropertyComponent (getPluginAAXCategory(), "Plugin AAX Category", 64, false),
  456. "This is one of the categories from the AAX_EPlugInCategory enum");
  457. props.add (new TextPropertyComponent (getAAXIdentifier(), "Plugin AAX Identifier", 256, false),
  458. "The value to use for the JucePlugin_AAXIdentifier setting");
  459. }
  460. //==============================================================================
  461. static StringArray getVersionSegments (const Project& p)
  462. {
  463. StringArray segments;
  464. segments.addTokens (p.getVersionString(), ",.", "");
  465. segments.trim();
  466. segments.removeEmptyStrings();
  467. return segments;
  468. }
  469. int Project::getVersionAsHexInteger() const
  470. {
  471. const StringArray segments (getVersionSegments (*this));
  472. int value = (segments[0].getIntValue() << 16)
  473. + (segments[1].getIntValue() << 8)
  474. + segments[2].getIntValue();
  475. if (segments.size() >= 4)
  476. value = (value << 8) + segments[3].getIntValue();
  477. return value;
  478. }
  479. String Project::getVersionAsHex() const
  480. {
  481. return "0x" + String::toHexString (getVersionAsHexInteger());
  482. }
  483. StringPairArray Project::getPreprocessorDefs() const
  484. {
  485. return parsePreprocessorDefs (projectRoot [Ids::defines]);
  486. }
  487. File Project::getBinaryDataCppFile (int index) const
  488. {
  489. const File cpp (getGeneratedCodeFolder().getChildFile ("BinaryData.cpp"));
  490. if (index > 0)
  491. return cpp.getSiblingFile (cpp.getFileNameWithoutExtension() + String (index + 1))
  492. .withFileExtension (cpp.getFileExtension());
  493. return cpp;
  494. }
  495. Project::Item Project::getMainGroup()
  496. {
  497. return Item (*this, projectRoot.getChildWithName (Ids::MAINGROUP), false);
  498. }
  499. PropertiesFile& Project::getStoredProperties() const
  500. {
  501. return getAppSettings().getProjectProperties (getProjectUID());
  502. }
  503. static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found)
  504. {
  505. if (item.isImageFile())
  506. {
  507. found.add (new Project::Item (item));
  508. }
  509. else if (item.isGroup())
  510. {
  511. for (int i = 0; i < item.getNumChildren(); ++i)
  512. findImages (item.getChild (i), found);
  513. }
  514. }
  515. void Project::findAllImageItems (OwnedArray<Project::Item>& items)
  516. {
  517. findImages (getMainGroup(), items);
  518. }
  519. //==============================================================================
  520. Project::Item::Item (Project& p, const ValueTree& s, bool isModuleCode)
  521. : project (p), state (s), belongsToModule (isModuleCode)
  522. {
  523. }
  524. Project::Item::Item (const Item& other)
  525. : project (other.project), state (other.state), belongsToModule (other.belongsToModule)
  526. {
  527. }
  528. Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.state.createCopy(); return i; }
  529. String Project::Item::getID() const { return state [Ids::ID]; }
  530. void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
  531. Drawable* Project::Item::loadAsImageFile() const
  532. {
  533. return isValid() ? Drawable::createFromImageFile (getFile())
  534. : nullptr;
  535. }
  536. Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
  537. {
  538. Item group (project, ValueTree (Ids::GROUP), isModuleCode);
  539. group.setID (uid);
  540. group.initialiseMissingProperties();
  541. group.getNameValue() = name;
  542. return group;
  543. }
  544. bool Project::Item::isFile() const { return state.hasType (Ids::FILE); }
  545. bool Project::Item::isGroup() const { return state.hasType (Ids::GROUP) || isMainGroup(); }
  546. bool Project::Item::isMainGroup() const { return state.hasType (Ids::MAINGROUP); }
  547. bool Project::Item::isImageFile() const
  548. {
  549. return isFile() && (ImageFileFormat::findImageFormatForFileExtension (getFile()) != nullptr
  550. || getFile().hasFileExtension ("svg"));
  551. }
  552. Project::Item Project::Item::findItemWithID (const String& targetId) const
  553. {
  554. if (state [Ids::ID] == targetId)
  555. return *this;
  556. if (isGroup())
  557. {
  558. for (int i = getNumChildren(); --i >= 0;)
  559. {
  560. Item found (getChild(i).findItemWithID (targetId));
  561. if (found.isValid())
  562. return found;
  563. }
  564. }
  565. return Item (project, ValueTree(), false);
  566. }
  567. bool Project::Item::canContain (const Item& child) const
  568. {
  569. if (isFile())
  570. return false;
  571. if (isGroup())
  572. return child.isFile() || child.isGroup();
  573. jassertfalse;
  574. return false;
  575. }
  576. bool Project::Item::shouldBeAddedToTargetProject() const { return isFile(); }
  577. Value Project::Item::getShouldCompileValue() { return state.getPropertyAsValue (Ids::compile, getUndoManager()); }
  578. bool Project::Item::shouldBeCompiled() const { return state [Ids::compile]; }
  579. Value Project::Item::getShouldAddToBinaryResourcesValue() { return state.getPropertyAsValue (Ids::resource, getUndoManager()); }
  580. bool Project::Item::shouldBeAddedToBinaryResources() const { return state [Ids::resource]; }
  581. Value Project::Item::getShouldAddToXcodeResourcesValue() { return state.getPropertyAsValue (Ids::xcodeResource, getUndoManager()); }
  582. bool Project::Item::shouldBeAddedToXcodeResources() const { return state [Ids::xcodeResource]; }
  583. Value Project::Item::getShouldInhibitWarningsValue() { return state.getPropertyAsValue (Ids::noWarnings, getUndoManager()); }
  584. bool Project::Item::shouldInhibitWarnings() const { return state [Ids::noWarnings]; }
  585. bool Project::Item::isModuleCode() const { return belongsToModule; }
  586. String Project::Item::getFilePath() const
  587. {
  588. if (isFile())
  589. return state [Ids::file].toString();
  590. return String();
  591. }
  592. File Project::Item::getFile() const
  593. {
  594. if (isFile())
  595. return project.resolveFilename (state [Ids::file].toString());
  596. return File();
  597. }
  598. void Project::Item::setFile (const File& file)
  599. {
  600. setFile (RelativePath (project.getRelativePathForFile (file), RelativePath::projectFolder));
  601. jassert (getFile() == file);
  602. }
  603. void Project::Item::setFile (const RelativePath& file)
  604. {
  605. jassert (isFile());
  606. state.setProperty (Ids::file, file.toUnixStyle(), getUndoManager());
  607. state.setProperty (Ids::name, file.getFileName(), getUndoManager());
  608. }
  609. bool Project::Item::renameFile (const File& newFile)
  610. {
  611. const File oldFile (getFile());
  612. if (oldFile.moveFileTo (newFile)
  613. || (newFile.exists() && ! oldFile.exists()))
  614. {
  615. setFile (newFile);
  616. ProjucerApplication::getApp().openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
  617. return true;
  618. }
  619. return false;
  620. }
  621. bool Project::Item::containsChildForFile (const RelativePath& file) const
  622. {
  623. return state.getChildWithProperty (Ids::file, file.toUnixStyle()).isValid();
  624. }
  625. Project::Item Project::Item::findItemForFile (const File& file) const
  626. {
  627. if (getFile() == file)
  628. return *this;
  629. if (isGroup())
  630. {
  631. for (int i = getNumChildren(); --i >= 0;)
  632. {
  633. Item found (getChild(i).findItemForFile (file));
  634. if (found.isValid())
  635. return found;
  636. }
  637. }
  638. return Item (project, ValueTree(), false);
  639. }
  640. File Project::Item::determineGroupFolder() const
  641. {
  642. jassert (isGroup());
  643. File f;
  644. for (int i = 0; i < getNumChildren(); ++i)
  645. {
  646. f = getChild(i).getFile();
  647. if (f.exists())
  648. return f.getParentDirectory();
  649. }
  650. Item parent (getParent());
  651. if (parent != *this)
  652. {
  653. f = parent.determineGroupFolder();
  654. if (f.getChildFile (getName()).isDirectory())
  655. f = f.getChildFile (getName());
  656. }
  657. else
  658. {
  659. f = project.getProjectFolder();
  660. if (f.getChildFile ("Source").isDirectory())
  661. f = f.getChildFile ("Source");
  662. }
  663. return f;
  664. }
  665. void Project::Item::initialiseMissingProperties()
  666. {
  667. if (! state.hasProperty (Ids::ID))
  668. setID (createAlphaNumericUID());
  669. if (isFile())
  670. {
  671. state.setProperty (Ids::name, getFile().getFileName(), nullptr);
  672. }
  673. else if (isGroup())
  674. {
  675. for (int i = getNumChildren(); --i >= 0;)
  676. getChild(i).initialiseMissingProperties();
  677. }
  678. }
  679. Value Project::Item::getNameValue()
  680. {
  681. return state.getPropertyAsValue (Ids::name, getUndoManager());
  682. }
  683. String Project::Item::getName() const
  684. {
  685. return state [Ids::name];
  686. }
  687. void Project::Item::addChild (const Item& newChild, int insertIndex)
  688. {
  689. state.addChild (newChild.state, insertIndex, getUndoManager());
  690. }
  691. void Project::Item::removeItemFromProject()
  692. {
  693. state.getParent().removeChild (state, getUndoManager());
  694. }
  695. Project::Item Project::Item::getParent() const
  696. {
  697. if (isMainGroup() || ! isGroup())
  698. return *this;
  699. return Item (project, state.getParent(), belongsToModule);
  700. }
  701. struct ItemSorter
  702. {
  703. static int compareElements (const ValueTree& first, const ValueTree& second)
  704. {
  705. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  706. }
  707. };
  708. struct ItemSorterWithGroupsAtStart
  709. {
  710. static int compareElements (const ValueTree& first, const ValueTree& second)
  711. {
  712. const bool firstIsGroup = first.hasType (Ids::GROUP);
  713. const bool secondIsGroup = second.hasType (Ids::GROUP);
  714. if (firstIsGroup == secondIsGroup)
  715. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  716. return firstIsGroup ? -1 : 1;
  717. }
  718. };
  719. static void sortGroup (ValueTree& state, bool keepGroupsAtStart, UndoManager* undoManager)
  720. {
  721. if (keepGroupsAtStart)
  722. {
  723. ItemSorterWithGroupsAtStart sorter;
  724. state.sort (sorter, undoManager, true);
  725. }
  726. else
  727. {
  728. ItemSorter sorter;
  729. state.sort (sorter, undoManager, true);
  730. }
  731. }
  732. static bool isGroupSorted (const ValueTree& state, bool keepGroupsAtStart)
  733. {
  734. if (state.getNumChildren() == 0)
  735. return false;
  736. if (state.getNumChildren() == 1)
  737. return true;
  738. ValueTree stateCopy (state.createCopy());
  739. sortGroup (stateCopy, keepGroupsAtStart, nullptr);
  740. return stateCopy.isEquivalentTo (state);
  741. }
  742. void Project::Item::sortAlphabetically (bool keepGroupsAtStart, bool recursive)
  743. {
  744. sortGroup (state, keepGroupsAtStart, getUndoManager());
  745. if (recursive)
  746. for (int i = getNumChildren(); --i >= 0;)
  747. getChild(i).sortAlphabetically (keepGroupsAtStart, true);
  748. }
  749. Project::Item Project::Item::getOrCreateSubGroup (const String& name)
  750. {
  751. for (int i = state.getNumChildren(); --i >= 0;)
  752. {
  753. const ValueTree child (state.getChild (i));
  754. if (child.getProperty (Ids::name) == name && child.hasType (Ids::GROUP))
  755. return Item (project, child, belongsToModule);
  756. }
  757. return addNewSubGroup (name, -1);
  758. }
  759. Project::Item Project::Item::addNewSubGroup (const String& name, int insertIndex)
  760. {
  761. String newID (createGUID (getID() + name + String (getNumChildren())));
  762. int n = 0;
  763. while (project.getMainGroup().findItemWithID (newID).isValid())
  764. newID = createGUID (newID + String (++n));
  765. Item group (createGroup (project, name, newID, belongsToModule));
  766. jassert (canContain (group));
  767. addChild (group, insertIndex);
  768. return group;
  769. }
  770. bool Project::Item::addFileAtIndex (const File& file, int insertIndex, const bool shouldCompile)
  771. {
  772. if (file == File() || file.isHidden() || file.getFileName().startsWithChar ('.'))
  773. return false;
  774. if (file.isDirectory())
  775. {
  776. Item group (addNewSubGroup (file.getFileName(), insertIndex));
  777. for (DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories); iter.next();)
  778. if (! project.getMainGroup().findItemForFile (iter.getFile()).isValid())
  779. group.addFileRetainingSortOrder (iter.getFile(), shouldCompile);
  780. }
  781. else if (file.existsAsFile())
  782. {
  783. if (! project.getMainGroup().findItemForFile (file).isValid())
  784. addFileUnchecked (file, insertIndex, shouldCompile);
  785. }
  786. else
  787. {
  788. jassertfalse;
  789. }
  790. return true;
  791. }
  792. bool Project::Item::addFileRetainingSortOrder (const File& file, bool shouldCompile)
  793. {
  794. const bool wasSortedGroupsNotFirst = isGroupSorted (state, false);
  795. const bool wasSortedGroupsFirst = isGroupSorted (state, true);
  796. if (! addFileAtIndex (file, 0, shouldCompile))
  797. return false;
  798. if (wasSortedGroupsNotFirst || wasSortedGroupsFirst)
  799. sortAlphabetically (wasSortedGroupsFirst, false);
  800. return true;
  801. }
  802. void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile)
  803. {
  804. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  805. item.initialiseMissingProperties();
  806. item.getNameValue() = file.getFileName();
  807. item.getShouldCompileValue() = shouldCompile && file.hasFileExtension (fileTypesToCompileByDefault);
  808. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  809. if (canContain (item))
  810. {
  811. item.setFile (file);
  812. addChild (item, insertIndex);
  813. }
  814. }
  815. bool Project::Item::addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile)
  816. {
  817. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  818. item.initialiseMissingProperties();
  819. item.getNameValue() = file.getFileName();
  820. item.getShouldCompileValue() = shouldCompile;
  821. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  822. if (canContain (item))
  823. {
  824. item.setFile (file);
  825. addChild (item, insertIndex);
  826. return true;
  827. }
  828. return false;
  829. }
  830. Icon Project::Item::getIcon() const
  831. {
  832. const Icons& icons = getIcons();
  833. if (isFile())
  834. {
  835. if (isImageFile())
  836. return Icon (icons.imageDoc, Colours::blue);
  837. return Icon (icons.document, Colours::yellow);
  838. }
  839. if (isMainGroup())
  840. return Icon (icons.juceLogo, Colours::orange);
  841. return Icon (icons.folder, Colours::darkgrey);
  842. }
  843. bool Project::Item::isIconCrossedOut() const
  844. {
  845. return isFile()
  846. && ! (shouldBeCompiled()
  847. || shouldBeAddedToBinaryResources()
  848. || getFile().hasFileExtension (headerFileExtensions));
  849. }
  850. //==============================================================================
  851. ValueTree Project::getConfigNode()
  852. {
  853. return projectRoot.getOrCreateChildWithName (Ids::JUCEOPTIONS, nullptr);
  854. }
  855. const char* const Project::configFlagDefault = "default";
  856. const char* const Project::configFlagEnabled = "enabled";
  857. const char* const Project::configFlagDisabled = "disabled";
  858. Value Project::getConfigFlag (const String& name)
  859. {
  860. ValueTree configNode (getConfigNode());
  861. Value v (configNode.getPropertyAsValue (name, getUndoManagerFor (configNode)));
  862. if (v.getValue().toString().isEmpty())
  863. v = configFlagDefault;
  864. return v;
  865. }
  866. bool Project::isConfigFlagEnabled (const String& name) const
  867. {
  868. return projectRoot.getChildWithName (Ids::JUCEOPTIONS).getProperty (name) == configFlagEnabled;
  869. }
  870. void Project::sanitiseConfigFlags()
  871. {
  872. ValueTree configNode (getConfigNode());
  873. for (int i = configNode.getNumProperties(); --i >= 0;)
  874. {
  875. const var value (configNode [configNode.getPropertyName(i)]);
  876. if (value != configFlagEnabled && value != configFlagDisabled)
  877. configNode.removeProperty (configNode.getPropertyName(i), getUndoManagerFor (configNode));
  878. }
  879. }
  880. //==============================================================================
  881. String Project::getPluginRTASCategoryCode()
  882. {
  883. if (static_cast<bool> (getPluginIsSynth().getValue()))
  884. return "ePlugInCategory_SWGenerators";
  885. String s (getPluginRTASCategory().toString());
  886. if (s.isEmpty())
  887. s = "ePlugInCategory_None";
  888. return s;
  889. }
  890. String Project::getAUMainTypeString()
  891. {
  892. String s (getPluginAUMainType().toString());
  893. if (s.isEmpty())
  894. {
  895. // Unfortunately, Rez uses a header where kAudioUnitType_MIDIProcessor is undefined
  896. // Use aumi instead.
  897. if (getPluginIsMidiEffectPlugin().getValue()) s = "'aumi'";
  898. else if (getPluginIsSynth().getValue()) s = "kAudioUnitType_MusicDevice";
  899. else if (getPluginWantsMidiInput().getValue()) s = "kAudioUnitType_MusicEffect";
  900. else s = "kAudioUnitType_Effect";
  901. }
  902. return s;
  903. }
  904. String Project::getAUMainTypeCode()
  905. {
  906. String s (getPluginAUMainType().toString());
  907. if (s.isEmpty())
  908. {
  909. if (getPluginIsMidiEffectPlugin().getValue()) s = "aumi";
  910. else if (getPluginIsSynth().getValue()) s = "aumu";
  911. else if (getPluginWantsMidiInput().getValue()) s = "aumf";
  912. else s = "aufx";
  913. }
  914. return s;
  915. }
  916. String Project::getPluginVSTCategoryString()
  917. {
  918. String s (getPluginVSTCategory().toString().trim());
  919. if (s.isEmpty())
  920. s = static_cast<bool> (getPluginIsSynth().getValue()) ? "kPlugCategSynth"
  921. : "kPlugCategEffect";
  922. return s;
  923. }
  924. bool Project::isAUPluginHost()
  925. {
  926. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_AU");
  927. }
  928. bool Project::isVSTPluginHost()
  929. {
  930. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST");
  931. }
  932. bool Project::isVST3PluginHost()
  933. {
  934. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3");
  935. }
  936. //==============================================================================
  937. EnabledModuleList& Project::getModules()
  938. {
  939. if (enabledModulesList == nullptr)
  940. enabledModulesList = new EnabledModuleList (*this, projectRoot.getOrCreateChildWithName (Ids::MODULES, nullptr));
  941. return *enabledModulesList;
  942. }
  943. //==============================================================================
  944. ValueTree Project::getExporters()
  945. {
  946. return projectRoot.getOrCreateChildWithName (Ids::EXPORTFORMATS, nullptr);
  947. }
  948. int Project::getNumExporters()
  949. {
  950. return getExporters().getNumChildren();
  951. }
  952. ProjectExporter* Project::createExporter (int index)
  953. {
  954. jassert (index >= 0 && index < getNumExporters());
  955. return ProjectExporter::createExporter (*this, getExporters().getChild (index));
  956. }
  957. void Project::addNewExporter (const String& exporterName)
  958. {
  959. ScopedPointer<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterName));
  960. ValueTree exporters (getExporters());
  961. exporters.addChild (exp->settings, -1, getUndoManagerFor (exporters));
  962. }
  963. void Project::createExporterForCurrentPlatform()
  964. {
  965. addNewExporter (ProjectExporter::getCurrentPlatformExporterName());
  966. }
  967. //==============================================================================
  968. String Project::getFileTemplate (const String& templateName)
  969. {
  970. int dataSize;
  971. if (const char* data = BinaryData::getNamedResource (templateName.toUTF8(), dataSize))
  972. return String::fromUTF8 (data, dataSize);
  973. jassertfalse;
  974. return String();
  975. }
  976. //==============================================================================
  977. Project::ExporterIterator::ExporterIterator (Project& p) : index (-1), project (p) {}
  978. Project::ExporterIterator::~ExporterIterator() {}
  979. bool Project::ExporterIterator::next()
  980. {
  981. if (++index >= project.getNumExporters())
  982. return false;
  983. exporter = project.createExporter (index);
  984. if (exporter == nullptr)
  985. {
  986. jassertfalse; // corrupted project file?
  987. return next();
  988. }
  989. return true;
  990. }