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. if (newModificationTime != modificationTime)
  304. {
  305. modificationTime = newModificationTime;
  306. return true;
  307. }
  308. return false;
  309. }
  310. //==============================================================================
  311. File Project::resolveFilename (String filename) const
  312. {
  313. if (filename.isEmpty())
  314. return File();
  315. filename = replacePreprocessorDefs (getPreprocessorDefs(), filename);
  316. if (FileHelpers::isAbsolutePath (filename))
  317. return File::createFileWithoutCheckingPath (FileHelpers::currentOSStylePath (filename)); // (avoid assertions for windows-style paths)
  318. return getFile().getSiblingFile (FileHelpers::currentOSStylePath (filename));
  319. }
  320. String Project::getRelativePathForFile (const File& file) const
  321. {
  322. String filename (file.getFullPathName());
  323. File relativePathBase (getFile().getParentDirectory());
  324. String p1 (relativePathBase.getFullPathName());
  325. String p2 (file.getFullPathName());
  326. while (p1.startsWithChar (File::separator))
  327. p1 = p1.substring (1);
  328. while (p2.startsWithChar (File::separator))
  329. p2 = p2.substring (1);
  330. if (p1.upToFirstOccurrenceOf (File::separatorString, true, false)
  331. .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::separatorString, true, false)))
  332. {
  333. filename = FileHelpers::getRelativePathFrom (file, relativePathBase);
  334. }
  335. return filename;
  336. }
  337. //==============================================================================
  338. const ProjectType& Project::getProjectType() const
  339. {
  340. if (const ProjectType* type = ProjectType::findType (getProjectTypeString()))
  341. return *type;
  342. const ProjectType* guiType = ProjectType::findType (ProjectType_GUIApp::getTypeName());
  343. jassert (guiType != nullptr);
  344. return *guiType;
  345. }
  346. //==============================================================================
  347. void Project::createPropertyEditors (PropertyListBuilder& props)
  348. {
  349. props.add (new TextPropertyComponent (getProjectNameValue(), "Project Name", 256, false),
  350. "The name of the project.");
  351. props.add (new TextPropertyComponent (getVersionValue(), "Project Version", 16, false),
  352. "The project's version number, This should be in the format major.minor.point[.point]");
  353. props.add (new TextPropertyComponent (getCompanyName(), "Company Name", 256, false),
  354. "Your company name, which will be added to the properties of the binary where possible");
  355. props.add (new TextPropertyComponent (getCompanyWebsite(), "Company Website", 256, false),
  356. "Your company website, which will be added to the properties of the binary where possible");
  357. props.add (new TextPropertyComponent (getCompanyEmail(), "Company E-mail", 256, false),
  358. "Your company e-mail, which will be added to the properties of the binary where possible");
  359. {
  360. StringArray projectTypeNames;
  361. Array<var> projectTypeCodes;
  362. const Array<ProjectType*>& types = ProjectType::getAllTypes();
  363. for (int i = 0; i < types.size(); ++i)
  364. {
  365. projectTypeNames.add (types.getUnchecked(i)->getDescription());
  366. projectTypeCodes.add (types.getUnchecked(i)->getType());
  367. }
  368. props.add (new ChoicePropertyComponent (getProjectTypeValue(), "Project Type", projectTypeNames, projectTypeCodes));
  369. }
  370. props.add (new TextPropertyComponent (getBundleIdentifier(), "Bundle Identifier", 256, false),
  371. "A unique identifier for this product, mainly for use in OSX/iOS builds. It should be something like 'com.yourcompanyname.yourproductname'");
  372. if (getProjectType().isAudioPlugin())
  373. createAudioPluginPropertyEditors (props);
  374. {
  375. const int maxSizes[] = { 20480, 10240, 6144, 2048, 1024, 512, 256, 128, 64 };
  376. StringArray maxSizeNames;
  377. Array<var> maxSizeCodes;
  378. maxSizeNames.add (TRANS("Default"));
  379. maxSizeCodes.add (var());
  380. maxSizeNames.add (String());
  381. maxSizeCodes.add (var());
  382. for (int i = 0; i < numElementsInArray (maxSizes); ++i)
  383. {
  384. const int sizeInBytes = maxSizes[i] * 1024;
  385. maxSizeNames.add (File::descriptionOfSizeInBytes (sizeInBytes));
  386. maxSizeCodes.add (sizeInBytes);
  387. }
  388. props.add (new ChoicePropertyComponent (getMaxBinaryFileSize(), "BinaryData.cpp size limit", maxSizeNames, maxSizeCodes),
  389. "When splitting binary data into multiple cpp files, the Projucer attempts to keep the file sizes below this threshold. "
  390. "(Note that individual resource files which are larger than this size cannot be split across multiple cpp files).");
  391. }
  392. props.add (new BooleanPropertyComponent (shouldIncludeBinaryInAppConfig(), "Include Binary",
  393. "Include BinaryData.h in the AppConfig.h file"));
  394. props.add (new TextPropertyComponent (getProjectPreprocessorDefs(), "Preprocessor definitions", 32768, true),
  395. "Global preprocessor definitions. Use the form \"NAME1=value NAME2=value\", using whitespace, commas, or "
  396. "new-lines to separate the items - to include a space or comma in a definition, precede it with a backslash.");
  397. props.add (new TextPropertyComponent (getProjectUserNotes(), "Notes", 32768, true),
  398. "Extra comments: This field is not used for code or project generation, it's just a space where you can express your thoughts.");
  399. }
  400. void Project::createAudioPluginPropertyEditors (PropertyListBuilder& props)
  401. {
  402. props.add (new BooleanPropertyComponent (shouldBuildVST(), "Build VST", "Enabled"),
  403. "Whether the project should produce a VST plugin.");
  404. props.add (new BooleanPropertyComponent (shouldBuildVST3(), "Build VST3", "Enabled"),
  405. "Whether the project should produce a VST3 plugin.");
  406. props.add (new BooleanPropertyComponent (shouldBuildAU(), "Build AudioUnit", "Enabled"),
  407. "Whether the project should produce an AudioUnit plugin.");
  408. props.add (new BooleanPropertyComponent (shouldBuildAUv3(), "Build AudioUnit v3", "Enabled"),
  409. "Whether the project should produce an AudioUnit version 3 plugin.");
  410. props.add (new BooleanPropertyComponent (shouldBuildRTAS(), "Build RTAS", "Enabled"),
  411. "Whether the project should produce an RTAS plugin.");
  412. props.add (new BooleanPropertyComponent (shouldBuildAAX(), "Build AAX", "Enabled"),
  413. "Whether the project should produce an AAX plugin.");
  414. /* TODO: this property editor is temporarily disabled because right now we build standalone if and only if
  415. we also build AUv3. However as soon as targets are supported on non-Xcode exporters as well, we should
  416. re-enable this option and allow to build the standalone plug-in independently from AUv3.
  417. */
  418. // props.add (new BooleanPropertyComponent (shouldBuildStandalone(), "Build Standalone", "Enabled"),
  419. // "Whether the project should produce a standalone version of the plugin. Required for AUv3.");
  420. props.add (new TextPropertyComponent (getPluginName(), "Plugin Name", 128, false),
  421. "The name of your plugin (keep it short!)");
  422. props.add (new TextPropertyComponent (getPluginDesc(), "Plugin Description", 256, false),
  423. "A short description of your plugin.");
  424. props.add (new TextPropertyComponent (getPluginManufacturer(), "Plugin Manufacturer", 256, false),
  425. "The name of your company (cannot be blank).");
  426. props.add (new TextPropertyComponent (getPluginManufacturerCode(), "Plugin Manufacturer Code", 4, false),
  427. "A four-character unique ID for your company. Note that for AU compatibility, this must contain at least one upper-case letter!");
  428. props.add (new TextPropertyComponent (getPluginCode(), "Plugin Code", 4, false),
  429. "A four-character unique ID for your plugin. Note that for AU compatibility, this must contain at least one upper-case letter!");
  430. props.add (new TextPropertyComponent (getPluginChannelConfigs(), "Plugin Channel Configurations", 1024, false),
  431. "This list is a comma-separated set list in the form {numIns, numOuts} and each pair indicates a valid plug-in "
  432. "configuration. For example {1, 1}, {2, 2} means that the plugin can be used either with 1 input and 1 output, "
  433. "or with 2 inputs and 2 outputs. If your plug-in requires side-chains, aux output buses etc., then you must leave "
  434. "this field empty and override the setPreferredBusArrangement method in your AudioProcessor.");
  435. props.add (new BooleanPropertyComponent (getPluginIsSynth(), "Plugin is a Synth", "Is a Synth"),
  436. "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.");
  437. props.add (new BooleanPropertyComponent (getPluginWantsMidiInput(), "Plugin Midi Input", "Plugin wants midi input"),
  438. "Enable this if you want your plugin to accept midi messages.");
  439. props.add (new BooleanPropertyComponent (getPluginProducesMidiOut(), "Plugin Midi Output", "Plugin produces midi output"),
  440. "Enable this if your plugin is going to produce midi messages.");
  441. props.add (new BooleanPropertyComponent (getPluginIsMidiEffectPlugin(), "Midi Effect Plugin", "Plugin is a midi effect plugin"),
  442. "Enable this if your plugin only processes midi and no audio.");
  443. props.add (new BooleanPropertyComponent (getPluginEditorNeedsKeyFocus(), "Key Focus", "Plugin editor requires keyboard focus"),
  444. "Enable this if your plugin needs keyboard input - some hosts can be a bit funny about keyboard focus..");
  445. props.add (new TextPropertyComponent (getPluginAUExportPrefix(), "Plugin AU Export Prefix", 64, false),
  446. "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.");
  447. props.add (new TextPropertyComponent (getPluginAUMainType(), "Plugin AU Main Type", 128, false),
  448. "In an AU, this is the value that is set as JucePlugin_AUMainType. Leave it blank unless you want to use a custom value.");
  449. props.add (new TextPropertyComponent (getPluginVSTCategory(), "VST Category", 64, false),
  450. "In a VST, this is the value that is set as JucePlugin_VSTCategory. Leave it blank unless you want to use a custom value.");
  451. props.add (new TextPropertyComponent (getPluginRTASCategory(), "Plugin RTAS Category", 64, false),
  452. "(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, "
  453. "ePlugInCategory_PitchShift, ePlugInCategory_Reverb, ePlugInCategory_Delay, "
  454. "ePlugInCategory_Modulation, ePlugInCategory_Harmonic, ePlugInCategory_NoiseReduction, "
  455. "ePlugInCategory_Dither, ePlugInCategory_SoundField");
  456. props.add (new TextPropertyComponent (getPluginAAXCategory(), "Plugin AAX Category", 64, false),
  457. "This is one of the categories from the AAX_EPlugInCategory enum");
  458. props.add (new TextPropertyComponent (getAAXIdentifier(), "Plugin AAX Identifier", 256, false),
  459. "The value to use for the JucePlugin_AAXIdentifier setting");
  460. }
  461. //==============================================================================
  462. static StringArray getVersionSegments (const Project& p)
  463. {
  464. StringArray segments;
  465. segments.addTokens (p.getVersionString(), ",.", "");
  466. segments.trim();
  467. segments.removeEmptyStrings();
  468. return segments;
  469. }
  470. int Project::getVersionAsHexInteger() const
  471. {
  472. const StringArray segments (getVersionSegments (*this));
  473. int value = (segments[0].getIntValue() << 16)
  474. + (segments[1].getIntValue() << 8)
  475. + segments[2].getIntValue();
  476. if (segments.size() >= 4)
  477. value = (value << 8) + segments[3].getIntValue();
  478. return value;
  479. }
  480. String Project::getVersionAsHex() const
  481. {
  482. return "0x" + String::toHexString (getVersionAsHexInteger());
  483. }
  484. StringPairArray Project::getPreprocessorDefs() const
  485. {
  486. return parsePreprocessorDefs (projectRoot [Ids::defines]);
  487. }
  488. File Project::getBinaryDataCppFile (int index) const
  489. {
  490. const File cpp (getGeneratedCodeFolder().getChildFile ("BinaryData.cpp"));
  491. if (index > 0)
  492. return cpp.getSiblingFile (cpp.getFileNameWithoutExtension() + String (index + 1))
  493. .withFileExtension (cpp.getFileExtension());
  494. return cpp;
  495. }
  496. Project::Item Project::getMainGroup()
  497. {
  498. return Item (*this, projectRoot.getChildWithName (Ids::MAINGROUP), false);
  499. }
  500. PropertiesFile& Project::getStoredProperties() const
  501. {
  502. return getAppSettings().getProjectProperties (getProjectUID());
  503. }
  504. static void findImages (const Project::Item& item, OwnedArray<Project::Item>& found)
  505. {
  506. if (item.isImageFile())
  507. {
  508. found.add (new Project::Item (item));
  509. }
  510. else if (item.isGroup())
  511. {
  512. for (int i = 0; i < item.getNumChildren(); ++i)
  513. findImages (item.getChild (i), found);
  514. }
  515. }
  516. void Project::findAllImageItems (OwnedArray<Project::Item>& items)
  517. {
  518. findImages (getMainGroup(), items);
  519. }
  520. //==============================================================================
  521. Project::Item::Item (Project& p, const ValueTree& s, bool isModuleCode)
  522. : project (p), state (s), belongsToModule (isModuleCode)
  523. {
  524. }
  525. Project::Item::Item (const Item& other)
  526. : project (other.project), state (other.state), belongsToModule (other.belongsToModule)
  527. {
  528. }
  529. Project::Item Project::Item::createCopy() { Item i (*this); i.state = i.state.createCopy(); return i; }
  530. String Project::Item::getID() const { return state [Ids::ID]; }
  531. void Project::Item::setID (const String& newID) { state.setProperty (Ids::ID, newID, nullptr); }
  532. Drawable* Project::Item::loadAsImageFile() const
  533. {
  534. return isValid() ? Drawable::createFromImageFile (getFile())
  535. : nullptr;
  536. }
  537. Project::Item Project::Item::createGroup (Project& project, const String& name, const String& uid, bool isModuleCode)
  538. {
  539. Item group (project, ValueTree (Ids::GROUP), isModuleCode);
  540. group.setID (uid);
  541. group.initialiseMissingProperties();
  542. group.getNameValue() = name;
  543. return group;
  544. }
  545. bool Project::Item::isFile() const { return state.hasType (Ids::FILE); }
  546. bool Project::Item::isGroup() const { return state.hasType (Ids::GROUP) || isMainGroup(); }
  547. bool Project::Item::isMainGroup() const { return state.hasType (Ids::MAINGROUP); }
  548. bool Project::Item::isImageFile() const
  549. {
  550. return isFile() && (ImageFileFormat::findImageFormatForFileExtension (getFile()) != nullptr
  551. || getFile().hasFileExtension ("svg"));
  552. }
  553. Project::Item Project::Item::findItemWithID (const String& targetId) const
  554. {
  555. if (state [Ids::ID] == targetId)
  556. return *this;
  557. if (isGroup())
  558. {
  559. for (int i = getNumChildren(); --i >= 0;)
  560. {
  561. Item found (getChild(i).findItemWithID (targetId));
  562. if (found.isValid())
  563. return found;
  564. }
  565. }
  566. return Item (project, ValueTree(), false);
  567. }
  568. bool Project::Item::canContain (const Item& child) const
  569. {
  570. if (isFile())
  571. return false;
  572. if (isGroup())
  573. return child.isFile() || child.isGroup();
  574. jassertfalse;
  575. return false;
  576. }
  577. bool Project::Item::shouldBeAddedToTargetProject() const { return isFile(); }
  578. Value Project::Item::getShouldCompileValue() { return state.getPropertyAsValue (Ids::compile, getUndoManager()); }
  579. bool Project::Item::shouldBeCompiled() const { return state [Ids::compile]; }
  580. Value Project::Item::getShouldAddToBinaryResourcesValue() { return state.getPropertyAsValue (Ids::resource, getUndoManager()); }
  581. bool Project::Item::shouldBeAddedToBinaryResources() const { return state [Ids::resource]; }
  582. Value Project::Item::getShouldAddToXcodeResourcesValue() { return state.getPropertyAsValue (Ids::xcodeResource, getUndoManager()); }
  583. bool Project::Item::shouldBeAddedToXcodeResources() const { return state [Ids::xcodeResource]; }
  584. Value Project::Item::getShouldInhibitWarningsValue() { return state.getPropertyAsValue (Ids::noWarnings, getUndoManager()); }
  585. bool Project::Item::shouldInhibitWarnings() const { return state [Ids::noWarnings]; }
  586. bool Project::Item::isModuleCode() const { return belongsToModule; }
  587. String Project::Item::getFilePath() const
  588. {
  589. if (isFile())
  590. return state [Ids::file].toString();
  591. return String();
  592. }
  593. File Project::Item::getFile() const
  594. {
  595. if (isFile())
  596. return project.resolveFilename (state [Ids::file].toString());
  597. return File();
  598. }
  599. void Project::Item::setFile (const File& file)
  600. {
  601. setFile (RelativePath (project.getRelativePathForFile (file), RelativePath::projectFolder));
  602. jassert (getFile() == file);
  603. }
  604. void Project::Item::setFile (const RelativePath& file)
  605. {
  606. jassert (isFile());
  607. state.setProperty (Ids::file, file.toUnixStyle(), getUndoManager());
  608. state.setProperty (Ids::name, file.getFileName(), getUndoManager());
  609. }
  610. bool Project::Item::renameFile (const File& newFile)
  611. {
  612. const File oldFile (getFile());
  613. if (oldFile.moveFileTo (newFile)
  614. || (newFile.exists() && ! oldFile.exists()))
  615. {
  616. setFile (newFile);
  617. ProjucerApplication::getApp().openDocumentManager.fileHasBeenRenamed (oldFile, newFile);
  618. return true;
  619. }
  620. return false;
  621. }
  622. bool Project::Item::containsChildForFile (const RelativePath& file) const
  623. {
  624. return state.getChildWithProperty (Ids::file, file.toUnixStyle()).isValid();
  625. }
  626. Project::Item Project::Item::findItemForFile (const File& file) const
  627. {
  628. if (getFile() == file)
  629. return *this;
  630. if (isGroup())
  631. {
  632. for (int i = getNumChildren(); --i >= 0;)
  633. {
  634. Item found (getChild(i).findItemForFile (file));
  635. if (found.isValid())
  636. return found;
  637. }
  638. }
  639. return Item (project, ValueTree(), false);
  640. }
  641. File Project::Item::determineGroupFolder() const
  642. {
  643. jassert (isGroup());
  644. File f;
  645. for (int i = 0; i < getNumChildren(); ++i)
  646. {
  647. f = getChild(i).getFile();
  648. if (f.exists())
  649. return f.getParentDirectory();
  650. }
  651. Item parent (getParent());
  652. if (parent != *this)
  653. {
  654. f = parent.determineGroupFolder();
  655. if (f.getChildFile (getName()).isDirectory())
  656. f = f.getChildFile (getName());
  657. }
  658. else
  659. {
  660. f = project.getProjectFolder();
  661. if (f.getChildFile ("Source").isDirectory())
  662. f = f.getChildFile ("Source");
  663. }
  664. return f;
  665. }
  666. void Project::Item::initialiseMissingProperties()
  667. {
  668. if (! state.hasProperty (Ids::ID))
  669. setID (createAlphaNumericUID());
  670. if (isFile())
  671. {
  672. state.setProperty (Ids::name, getFile().getFileName(), nullptr);
  673. }
  674. else if (isGroup())
  675. {
  676. for (int i = getNumChildren(); --i >= 0;)
  677. getChild(i).initialiseMissingProperties();
  678. }
  679. }
  680. Value Project::Item::getNameValue()
  681. {
  682. return state.getPropertyAsValue (Ids::name, getUndoManager());
  683. }
  684. String Project::Item::getName() const
  685. {
  686. return state [Ids::name];
  687. }
  688. void Project::Item::addChild (const Item& newChild, int insertIndex)
  689. {
  690. state.addChild (newChild.state, insertIndex, getUndoManager());
  691. }
  692. void Project::Item::removeItemFromProject()
  693. {
  694. state.getParent().removeChild (state, getUndoManager());
  695. }
  696. Project::Item Project::Item::getParent() const
  697. {
  698. if (isMainGroup() || ! isGroup())
  699. return *this;
  700. return Item (project, state.getParent(), belongsToModule);
  701. }
  702. struct ItemSorter
  703. {
  704. static int compareElements (const ValueTree& first, const ValueTree& second)
  705. {
  706. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  707. }
  708. };
  709. struct ItemSorterWithGroupsAtStart
  710. {
  711. static int compareElements (const ValueTree& first, const ValueTree& second)
  712. {
  713. const bool firstIsGroup = first.hasType (Ids::GROUP);
  714. const bool secondIsGroup = second.hasType (Ids::GROUP);
  715. if (firstIsGroup == secondIsGroup)
  716. return first [Ids::name].toString().compareNatural (second [Ids::name].toString());
  717. return firstIsGroup ? -1 : 1;
  718. }
  719. };
  720. static void sortGroup (ValueTree& state, bool keepGroupsAtStart, UndoManager* undoManager)
  721. {
  722. if (keepGroupsAtStart)
  723. {
  724. ItemSorterWithGroupsAtStart sorter;
  725. state.sort (sorter, undoManager, true);
  726. }
  727. else
  728. {
  729. ItemSorter sorter;
  730. state.sort (sorter, undoManager, true);
  731. }
  732. }
  733. static bool isGroupSorted (const ValueTree& state, bool keepGroupsAtStart)
  734. {
  735. if (state.getNumChildren() == 0)
  736. return false;
  737. if (state.getNumChildren() == 1)
  738. return true;
  739. ValueTree stateCopy (state.createCopy());
  740. sortGroup (stateCopy, keepGroupsAtStart, nullptr);
  741. return stateCopy.isEquivalentTo (state);
  742. }
  743. void Project::Item::sortAlphabetically (bool keepGroupsAtStart, bool recursive)
  744. {
  745. sortGroup (state, keepGroupsAtStart, getUndoManager());
  746. if (recursive)
  747. for (int i = getNumChildren(); --i >= 0;)
  748. getChild(i).sortAlphabetically (keepGroupsAtStart, true);
  749. }
  750. Project::Item Project::Item::getOrCreateSubGroup (const String& name)
  751. {
  752. for (int i = state.getNumChildren(); --i >= 0;)
  753. {
  754. const ValueTree child (state.getChild (i));
  755. if (child.getProperty (Ids::name) == name && child.hasType (Ids::GROUP))
  756. return Item (project, child, belongsToModule);
  757. }
  758. return addNewSubGroup (name, -1);
  759. }
  760. Project::Item Project::Item::addNewSubGroup (const String& name, int insertIndex)
  761. {
  762. String newID (createGUID (getID() + name + String (getNumChildren())));
  763. int n = 0;
  764. while (project.getMainGroup().findItemWithID (newID).isValid())
  765. newID = createGUID (newID + String (++n));
  766. Item group (createGroup (project, name, newID, belongsToModule));
  767. jassert (canContain (group));
  768. addChild (group, insertIndex);
  769. return group;
  770. }
  771. bool Project::Item::addFileAtIndex (const File& file, int insertIndex, const bool shouldCompile)
  772. {
  773. if (file == File() || file.isHidden() || file.getFileName().startsWithChar ('.'))
  774. return false;
  775. if (file.isDirectory())
  776. {
  777. Item group (addNewSubGroup (file.getFileName(), insertIndex));
  778. for (DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories); iter.next();)
  779. if (! project.getMainGroup().findItemForFile (iter.getFile()).isValid())
  780. group.addFileRetainingSortOrder (iter.getFile(), shouldCompile);
  781. }
  782. else if (file.existsAsFile())
  783. {
  784. if (! project.getMainGroup().findItemForFile (file).isValid())
  785. addFileUnchecked (file, insertIndex, shouldCompile);
  786. }
  787. else
  788. {
  789. jassertfalse;
  790. }
  791. return true;
  792. }
  793. bool Project::Item::addFileRetainingSortOrder (const File& file, bool shouldCompile)
  794. {
  795. const bool wasSortedGroupsNotFirst = isGroupSorted (state, false);
  796. const bool wasSortedGroupsFirst = isGroupSorted (state, true);
  797. if (! addFileAtIndex (file, 0, shouldCompile))
  798. return false;
  799. if (wasSortedGroupsNotFirst || wasSortedGroupsFirst)
  800. sortAlphabetically (wasSortedGroupsFirst, false);
  801. return true;
  802. }
  803. void Project::Item::addFileUnchecked (const File& file, int insertIndex, const bool shouldCompile)
  804. {
  805. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  806. item.initialiseMissingProperties();
  807. item.getNameValue() = file.getFileName();
  808. item.getShouldCompileValue() = shouldCompile && file.hasFileExtension (fileTypesToCompileByDefault);
  809. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  810. if (canContain (item))
  811. {
  812. item.setFile (file);
  813. addChild (item, insertIndex);
  814. }
  815. }
  816. bool Project::Item::addRelativeFile (const RelativePath& file, int insertIndex, bool shouldCompile)
  817. {
  818. Item item (project, ValueTree (Ids::FILE), belongsToModule);
  819. item.initialiseMissingProperties();
  820. item.getNameValue() = file.getFileName();
  821. item.getShouldCompileValue() = shouldCompile;
  822. item.getShouldAddToBinaryResourcesValue() = project.shouldBeAddedToBinaryResourcesByDefault (file);
  823. if (canContain (item))
  824. {
  825. item.setFile (file);
  826. addChild (item, insertIndex);
  827. return true;
  828. }
  829. return false;
  830. }
  831. Icon Project::Item::getIcon() const
  832. {
  833. const Icons& icons = getIcons();
  834. if (isFile())
  835. {
  836. if (isImageFile())
  837. return Icon (icons.imageDoc, Colours::blue);
  838. return Icon (icons.document, Colours::yellow);
  839. }
  840. if (isMainGroup())
  841. return Icon (icons.juceLogo, Colours::orange);
  842. return Icon (icons.folder, Colours::darkgrey);
  843. }
  844. bool Project::Item::isIconCrossedOut() const
  845. {
  846. return isFile()
  847. && ! (shouldBeCompiled()
  848. || shouldBeAddedToBinaryResources()
  849. || getFile().hasFileExtension (headerFileExtensions));
  850. }
  851. //==============================================================================
  852. ValueTree Project::getConfigNode()
  853. {
  854. return projectRoot.getOrCreateChildWithName (Ids::JUCEOPTIONS, nullptr);
  855. }
  856. const char* const Project::configFlagDefault = "default";
  857. const char* const Project::configFlagEnabled = "enabled";
  858. const char* const Project::configFlagDisabled = "disabled";
  859. Value Project::getConfigFlag (const String& name)
  860. {
  861. ValueTree configNode (getConfigNode());
  862. Value v (configNode.getPropertyAsValue (name, getUndoManagerFor (configNode)));
  863. if (v.getValue().toString().isEmpty())
  864. v = configFlagDefault;
  865. return v;
  866. }
  867. bool Project::isConfigFlagEnabled (const String& name) const
  868. {
  869. return projectRoot.getChildWithName (Ids::JUCEOPTIONS).getProperty (name) == configFlagEnabled;
  870. }
  871. void Project::sanitiseConfigFlags()
  872. {
  873. ValueTree configNode (getConfigNode());
  874. for (int i = configNode.getNumProperties(); --i >= 0;)
  875. {
  876. const var value (configNode [configNode.getPropertyName(i)]);
  877. if (value != configFlagEnabled && value != configFlagDisabled)
  878. configNode.removeProperty (configNode.getPropertyName(i), getUndoManagerFor (configNode));
  879. }
  880. }
  881. //==============================================================================
  882. String Project::getPluginRTASCategoryCode()
  883. {
  884. if (static_cast<bool> (getPluginIsSynth().getValue()))
  885. return "ePlugInCategory_SWGenerators";
  886. String s (getPluginRTASCategory().toString());
  887. if (s.isEmpty())
  888. s = "ePlugInCategory_None";
  889. return s;
  890. }
  891. String Project::getAUMainTypeString()
  892. {
  893. String s (getPluginAUMainType().toString());
  894. if (s.isEmpty())
  895. {
  896. // Unfortunately, Rez uses a header where kAudioUnitType_MIDIProcessor is undefined
  897. // Use aumi instead.
  898. if (getPluginIsMidiEffectPlugin().getValue()) s = "'aumi'";
  899. else if (getPluginIsSynth().getValue()) s = "kAudioUnitType_MusicDevice";
  900. else if (getPluginWantsMidiInput().getValue()) s = "kAudioUnitType_MusicEffect";
  901. else s = "kAudioUnitType_Effect";
  902. }
  903. return s;
  904. }
  905. String Project::getAUMainTypeCode()
  906. {
  907. String s (getPluginAUMainType().toString());
  908. if (s.isEmpty())
  909. {
  910. if (getPluginIsMidiEffectPlugin().getValue()) s = "aumi";
  911. else if (getPluginIsSynth().getValue()) s = "aumu";
  912. else if (getPluginWantsMidiInput().getValue()) s = "aumf";
  913. else s = "aufx";
  914. }
  915. return s;
  916. }
  917. String Project::getPluginVSTCategoryString()
  918. {
  919. String s (getPluginVSTCategory().toString().trim());
  920. if (s.isEmpty())
  921. s = static_cast<bool> (getPluginIsSynth().getValue()) ? "kPlugCategSynth"
  922. : "kPlugCategEffect";
  923. return s;
  924. }
  925. bool Project::isAUPluginHost()
  926. {
  927. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_AU");
  928. }
  929. bool Project::isVSTPluginHost()
  930. {
  931. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST");
  932. }
  933. bool Project::isVST3PluginHost()
  934. {
  935. return getModules().isModuleEnabled ("juce_audio_processors") && isConfigFlagEnabled ("JUCE_PLUGINHOST_VST3");
  936. }
  937. //==============================================================================
  938. EnabledModuleList& Project::getModules()
  939. {
  940. if (enabledModulesList == nullptr)
  941. enabledModulesList = new EnabledModuleList (*this, projectRoot.getOrCreateChildWithName (Ids::MODULES, nullptr));
  942. return *enabledModulesList;
  943. }
  944. //==============================================================================
  945. ValueTree Project::getExporters()
  946. {
  947. return projectRoot.getOrCreateChildWithName (Ids::EXPORTFORMATS, nullptr);
  948. }
  949. int Project::getNumExporters()
  950. {
  951. return getExporters().getNumChildren();
  952. }
  953. ProjectExporter* Project::createExporter (int index)
  954. {
  955. jassert (index >= 0 && index < getNumExporters());
  956. return ProjectExporter::createExporter (*this, getExporters().getChild (index));
  957. }
  958. void Project::addNewExporter (const String& exporterName)
  959. {
  960. ScopedPointer<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterName));
  961. ValueTree exporters (getExporters());
  962. exporters.addChild (exp->settings, -1, getUndoManagerFor (exporters));
  963. }
  964. void Project::createExporterForCurrentPlatform()
  965. {
  966. addNewExporter (ProjectExporter::getCurrentPlatformExporterName());
  967. }
  968. //==============================================================================
  969. String Project::getFileTemplate (const String& templateName)
  970. {
  971. int dataSize;
  972. if (const char* data = BinaryData::getNamedResource (templateName.toUTF8(), dataSize))
  973. return String::fromUTF8 (data, dataSize);
  974. jassertfalse;
  975. return String();
  976. }
  977. //==============================================================================
  978. Project::ExporterIterator::ExporterIterator (Project& p) : index (-1), project (p) {}
  979. Project::ExporterIterator::~ExporterIterator() {}
  980. bool Project::ExporterIterator::next()
  981. {
  982. if (++index >= project.getNumExporters())
  983. return false;
  984. exporter = project.createExporter (index);
  985. if (exporter == nullptr)
  986. {
  987. jassertfalse; // corrupted project file?
  988. return next();
  989. }
  990. return true;
  991. }