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.

1245 lines
43KB

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