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.

979 lines
35KB

  1. /*
  2. ==============================================================================
  3. This file is part of the JUCE library - "Jules' Utility Class Extensions"
  4. Copyright 2004-10 by Raw Material Software Ltd.
  5. ------------------------------------------------------------------------------
  6. JUCE can be redistributed and/or modified under the terms of the GNU General
  7. Public License (Version 2), as published by the Free Software Foundation.
  8. A copy of the license is included in the JUCE distribution, or can be found
  9. online at www.gnu.org/licenses.
  10. JUCE is distributed in the hope that it will be useful, but WITHOUT ANY
  11. WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
  12. A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  13. ------------------------------------------------------------------------------
  14. To release a closed-source product which uses JUCE, commercial licenses are
  15. available: visit www.rawmaterialsoftware.com/juce for more information.
  16. ==============================================================================
  17. */
  18. #include "jucer_Project.h"
  19. #include "jucer_ProjectExporter.h"
  20. #include "jucer_ResourceFile.h"
  21. #include "jucer_ProjectSaver.h"
  22. #include "../../ui/jucer_OpenDocumentManager.h"
  23. //==============================================================================
  24. namespace Tags
  25. {
  26. const char* const projectRoot = "JUCERPROJECT";
  27. const char* const projectMainGroup = "MAINGROUP";
  28. const char* const group = "GROUP";
  29. const char* const file = "FILE";
  30. const char* const configurations = "CONFIGURATIONS";
  31. const char* const configuration = "CONFIGURATION";
  32. const char* const exporters = "EXPORTFORMATS";
  33. }
  34. const char* Project::projectFileExtension = ".jucer";
  35. //==============================================================================
  36. Project::Project (const File& file_)
  37. : FileBasedDocument (projectFileExtension,
  38. String ("*") + projectFileExtension,
  39. "Choose a Jucer project to load",
  40. "Save Jucer project"),
  41. projectRoot (Tags::projectRoot)
  42. {
  43. setFile (file_);
  44. setMissingDefaultValues();
  45. setChangedFlag (false);
  46. projectRoot.addListener (this);
  47. }
  48. Project::~Project()
  49. {
  50. projectRoot.removeListener (this);
  51. OpenDocumentManager::getInstance()->closeAllDocumentsUsingProject (*this, false);
  52. }
  53. //==============================================================================
  54. void Project::setTitle (const String& newTitle)
  55. {
  56. projectRoot.setProperty ("name", newTitle, getUndoManagerFor (projectRoot));
  57. getMainGroup().getName() = newTitle;
  58. }
  59. const String Project::getDocumentTitle()
  60. {
  61. return getProjectName().toString();
  62. }
  63. void Project::updateProjectSettings()
  64. {
  65. projectRoot.setProperty ("jucerVersion", ProjectInfo::versionString, 0);
  66. projectRoot.setProperty ("name", getDocumentTitle(), 0);
  67. }
  68. void Project::setMissingDefaultValues()
  69. {
  70. if (! projectRoot.hasProperty ("id"))
  71. projectRoot.setProperty ("id", createAlphaNumericUID(), 0);
  72. // Create main file group if missing
  73. if (! projectRoot.getChildWithName (Tags::projectMainGroup).isValid())
  74. {
  75. Item mainGroup (*this, ValueTree (Tags::projectMainGroup));
  76. projectRoot.addChild (mainGroup.getNode(), 0, 0);
  77. }
  78. getMainGroup().initialiseNodeValues();
  79. if (getDocumentTitle().isEmpty())
  80. setTitle ("Juce Project");
  81. if (! projectRoot.hasProperty ("projectType"))
  82. getProjectType() = (int) application;
  83. if (! projectRoot.hasProperty ("version"))
  84. getVersion() = "1.0.0";
  85. if (! projectRoot.hasProperty ("juceLinkage"))
  86. getJuceLinkageModeValue() = (int) useAmalgamatedJuceViaMultipleTemplates;
  87. const String juceFolderPath (getRelativePathForFile (StoredSettings::getInstance()->getLastKnownJuceFolder()));
  88. // Create configs group
  89. if (! projectRoot.getChildWithName (Tags::configurations).isValid())
  90. {
  91. projectRoot.addChild (ValueTree (Tags::configurations), 0, 0);
  92. createDefaultConfigs();
  93. }
  94. if (! projectRoot.getChildWithName (Tags::exporters).isValid())
  95. createDefaultExporters();
  96. const String sanitisedProjectName (makeValidCppIdentifier (getProjectName().toString(), false, true, false));
  97. if (! projectRoot.hasProperty ("buildVST"))
  98. {
  99. shouldBuildVST() = true;
  100. shouldBuildRTAS() = false;
  101. shouldBuildAU() = true;
  102. getPluginName() = getProjectName().toString();
  103. getPluginDesc() = getProjectName().toString();
  104. getPluginManufacturer() = "yourcompany";
  105. getPluginManufacturerCode() = "abcd";
  106. getPluginCode() = "Abcd";
  107. getPluginChannelConfigs() = "{1, 1}, {2, 2}";
  108. getPluginIsSynth() = false;
  109. getPluginWantsMidiInput() = false;
  110. getPluginProducesMidiOut() = false;
  111. getPluginSilenceInProducesSilenceOut() = false;
  112. getPluginTailLengthSeconds() = 0;
  113. getPluginEditorNeedsKeyFocus() = false;
  114. getPluginAUExportPrefix() = sanitisedProjectName + "AU";
  115. getPluginAUCocoaViewClassName() = sanitisedProjectName + "AU_V1";
  116. getPluginRTASCategory() = String::empty;
  117. }
  118. if (! projectRoot.hasProperty ("bundleIdentifier"))
  119. setBundleIdentifierToDefault();
  120. }
  121. //==============================================================================
  122. const String Project::loadDocument (const File& file)
  123. {
  124. XmlDocument doc (file);
  125. ScopedPointer <XmlElement> xml (doc.getDocumentElement());
  126. if (xml == 0 || ! xml->hasTagName (Tags::projectRoot))
  127. return "Not a valid Jucer project!";
  128. ValueTree newTree (ValueTree::fromXml (*xml));
  129. if (! newTree.hasType (Tags::projectRoot))
  130. return "The document contains errors and couldn't be parsed!";
  131. StoredSettings::getInstance()->recentFiles.addFile (file);
  132. StoredSettings::getInstance()->flush();
  133. projectRoot = newTree;
  134. setMissingDefaultValues();
  135. return String::empty;
  136. }
  137. const String Project::saveDocument (const File& file)
  138. {
  139. updateProjectSettings();
  140. {
  141. // (getting these forces the values to be sanitised)
  142. OwnedArray <Project::JuceConfigFlag> flags;
  143. getJuceConfigFlags (flags);
  144. }
  145. if (isJuceFolder (getLocalJuceFolder()))
  146. StoredSettings::getInstance()->setLastKnownJuceFolder (getLocalJuceFolder().getFullPathName());
  147. StoredSettings::getInstance()->recentFiles.addFile (file);
  148. ProjectSaver saver (*this, file);
  149. return saver.save();
  150. }
  151. //==============================================================================
  152. File Project::lastDocumentOpened;
  153. const File Project::getLastDocumentOpened()
  154. {
  155. return lastDocumentOpened;
  156. }
  157. void Project::setLastDocumentOpened (const File& file)
  158. {
  159. lastDocumentOpened = file;
  160. }
  161. //==============================================================================
  162. void Project::valueTreePropertyChanged (ValueTree& tree, const var::identifier& property)
  163. {
  164. if (isLibrary())
  165. getJuceLinkageModeValue() = (int) notLinkedToJuce;
  166. changed();
  167. }
  168. void Project::valueTreeChildrenChanged (ValueTree& tree)
  169. {
  170. changed();
  171. }
  172. void Project::valueTreeParentChanged (ValueTree& tree)
  173. {
  174. }
  175. //==============================================================================
  176. const File Project::resolveFilename (const String& filename) const
  177. {
  178. if (filename.isEmpty())
  179. return File::nonexistent;
  180. if (File::isAbsolutePath (filename))
  181. return File (filename);
  182. return getFile().getSiblingFile (filename);
  183. }
  184. const String Project::getRelativePathForFile (const File& file) const
  185. {
  186. String filename (file.getFullPathName());
  187. File relativePathBase (getFile().getParentDirectory());
  188. String p1 (relativePathBase.getFullPathName());
  189. String p2 (file.getFullPathName());
  190. while (p1.startsWithChar (File::separator))
  191. p1 = p1.substring (1);
  192. while (p2.startsWithChar (File::separator))
  193. p2 = p2.substring (1);
  194. if (p1.upToFirstOccurrenceOf (File::separatorString, true, false)
  195. .equalsIgnoreCase (p2.upToFirstOccurrenceOf (File::separatorString, true, false)))
  196. {
  197. filename = file.getRelativePathFrom (relativePathBase);
  198. }
  199. return filename;
  200. }
  201. //==============================================================================
  202. bool Project::shouldBeAddedToBinaryResourcesByDefault (const File& file)
  203. {
  204. return ! file.hasFileExtension (sourceFileExtensions);
  205. }
  206. Value Project::getProjectType() const
  207. {
  208. static const char* mappings[] = { "guiapp", "1", "consoleapp", "2", "audioplug", "3", "library", "4", "browserplug", "5", 0 };
  209. return Value (new ValueRemapperSource (projectRoot.getPropertyAsValue ("projectType", getUndoManagerFor (projectRoot)), mappings));
  210. }
  211. const StringArray Project::getProjectTypes() const
  212. {
  213. const char* types[] = { "Application (GUI)",
  214. "Application (Non-GUI)",
  215. "Audio Plug-in",
  216. //"Browser Plug-in",
  217. "Static Library",
  218. 0 };
  219. return StringArray (types);
  220. }
  221. Value Project::getJuceLinkageModeValue() const
  222. {
  223. static const char* mappings[] = { "none", "1", "static", "2", "amalg_big", "3", "amalg_template", "4", "amalg_multi", "5", 0 };
  224. return Value (new ValueRemapperSource (projectRoot.getPropertyAsValue ("juceLinkage", getUndoManagerFor (projectRoot)), mappings));
  225. }
  226. const StringArray Project::getJuceLinkageModes() const
  227. {
  228. const char* types[] = { "Not linked to Juce",
  229. "Linked to Juce Static Library",
  230. "Include Juce Amalgamated Files",
  231. "Include Juce Source Code Directly (In a single file)",
  232. "Include Juce Source Code Directly (Split across several files)",
  233. 0 };
  234. return StringArray (types);
  235. }
  236. const File Project::getLocalJuceFolder()
  237. {
  238. ScopedPointer <ProjectExporter> exp (ProjectExporter::createPlatformDefaultExporter (*this));
  239. if (exp != 0)
  240. {
  241. File f (resolveFilename (exp->getJuceFolder().toString()));
  242. if (isJuceFolder (f))
  243. return f;
  244. }
  245. return StoredSettings::getInstance()->getLastKnownJuceFolder();
  246. }
  247. //==============================================================================
  248. void Project::createPropertyEditors (Array <PropertyComponent*>& props)
  249. {
  250. props.add (new TextPropertyComponent (getProjectName(), "Project Name", 256, false));
  251. props.getLast()->setTooltip ("The name of the project.");
  252. props.add (new TextPropertyComponent (getVersion(), "Project Version", 16, false));
  253. props.getLast()->setTooltip ("The project's version number, This should be in the format major.minor.point");
  254. props.add (new ChoicePropertyComponent (getProjectType(), "Project Type", getProjectTypes()));
  255. props.add (new ChoicePropertyComponent (getJuceLinkageModeValue(), "Juce Linkage Method", getJuceLinkageModes()));
  256. props.getLast()->setTooltip ("The method by which your project will be linked to Juce.");
  257. props.add (new TextPropertyComponent (getBundleIdentifier(), "Bundle Identifier", 256, false));
  258. props.getLast()->setTooltip ("A unique identifier for this product, mainly for use in Mac builds. It should be something like 'com.yourcompanyname.yourproductname'");
  259. if (isAudioPlugin())
  260. {
  261. props.add (new BooleanPropertyComponent (shouldBuildVST(), "Build VST", "Enabled"));
  262. props.getLast()->setTooltip ("Whether the project should produce a VST plugin.");
  263. props.add (new BooleanPropertyComponent (shouldBuildAU(), "Build AudioUnit", "Enabled"));
  264. props.getLast()->setTooltip ("Whether the project should produce an AudioUnit plugin.");
  265. props.add (new BooleanPropertyComponent (shouldBuildRTAS(), "Build RTAS", "Enabled"));
  266. props.getLast()->setTooltip ("Whether the project should produce an RTAS plugin.");
  267. }
  268. if (isAudioPlugin())
  269. {
  270. props.add (new TextPropertyComponent (getPluginName(), "Plugin Name", 128, false));
  271. props.getLast()->setTooltip ("The name of your plugin (keep it short!)");
  272. props.add (new TextPropertyComponent (getPluginDesc(), "Plugin Description", 256, false));
  273. props.getLast()->setTooltip ("A short description of your plugin.");
  274. props.add (new TextPropertyComponent (getPluginManufacturer(), "Plugin Manufacturer", 256, false));
  275. props.getLast()->setTooltip ("The name of your company (cannot be blank).");
  276. props.add (new TextPropertyComponent (getPluginManufacturerCode(), "Plugin Manufacturer Code", 4, false));
  277. props.getLast()->setTooltip ("A four-character unique ID for your company.");
  278. props.add (new TextPropertyComponent (getPluginCode(), "Plugin Code", 4, false));
  279. props.getLast()->setTooltip ("A four-character unique ID for your plugin. Note that for AU compatibility, this must contain at least one upper-case letter!");
  280. props.add (new TextPropertyComponent (getPluginChannelConfigs(), "Plugin Channel Configurations", 256, false));
  281. props.getLast()->setTooltip ("This is the set of input/output channel configurations that your plugin can handle. The list is a comma-separated set of pairs of values in the form { numInputs, numOutputs }, and each "
  282. "pair indicates a valid configuration that the plugin can handle. So for example, {1, 1}, {2, 2} means that the plugin can be used in just two configurations: either with 1 input "
  283. "and 1 output, or with 2 inputs and 2 outputs.");
  284. props.add (new BooleanPropertyComponent (getPluginIsSynth(), "Plugin is a Synth", "Is a Synth"));
  285. props.getLast()->setTooltip ("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.");
  286. props.add (new BooleanPropertyComponent (getPluginWantsMidiInput(), "Plugin Midi Input", "Plugin wants midi input"));
  287. props.getLast()->setTooltip ("Enable this if you want your plugin to accept midi messages.");
  288. props.add (new BooleanPropertyComponent (getPluginProducesMidiOut(), "Plugin Midi Output", "Plugin produces midi output"));
  289. props.getLast()->setTooltip ("Enable this if your plugin is going to produce midi messages.");
  290. props.add (new BooleanPropertyComponent (getPluginSilenceInProducesSilenceOut(), "Silence", "Silence in produces silence out"));
  291. props.getLast()->setTooltip ("Enable this if your plugin has no tail - i.e. if passing a silent buffer to it will always result in a silent buffer being produced.");
  292. props.add (new TextPropertyComponent (getPluginTailLengthSeconds(), "Tail Length (in seconds)", 12, false));
  293. props.getLast()->setTooltip ("This indicates the length, in seconds, of the plugin's tail. This information may or may not be used by the host.");
  294. props.add (new BooleanPropertyComponent (getPluginEditorNeedsKeyFocus(), "Key Focus", "Plugin editor requires keyboard focus"));
  295. props.getLast()->setTooltip ("Enable this if your plugin needs keyboard input - some hosts can be a bit funny about keyboard focus..");
  296. props.add (new TextPropertyComponent (getPluginAUExportPrefix(), "Plugin AU Export Prefix", 64, false));
  297. props.getLast()->setTooltip ("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.");
  298. props.add (new TextPropertyComponent (getPluginAUCocoaViewClassName(), "Plugin AU Cocoa View Name", 64, false));
  299. props.getLast()->setTooltip ("In an AU, this is the name of Cocoa class that creates the UI. Some hosts bizarrely display the class-name, so you might want to make it reflect your plugin. But the name must be "
  300. "UNIQUE to this exact version of your plugin, to avoid objective-C linkage mix-ups that happen when different plugins containing the same class-name are loaded simultaneously.");
  301. props.add (new TextPropertyComponent (getPluginRTASCategory(), "Plugin RTAS Category", 64, false));
  302. props.getLast()->setTooltip ("(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, "
  303. "ePlugInCategory_PitchShift, ePlugInCategory_Reverb, ePlugInCategory_Delay, "
  304. "ePlugInCategory_Modulation, ePlugInCategory_Harmonic, ePlugInCategory_NoiseReduction, "
  305. "ePlugInCategory_Dither, ePlugInCategory_SoundField");
  306. }
  307. for (int i = props.size(); --i >= 0;)
  308. props.getUnchecked(i)->setPreferredHeight (22);
  309. }
  310. //==============================================================================
  311. Project::Item Project::getMainGroup()
  312. {
  313. return Item (*this, projectRoot.getChildWithName (Tags::projectMainGroup));
  314. }
  315. Project::Item Project::createNewGroup()
  316. {
  317. Item item (*this, ValueTree (Tags::group));
  318. item.initialiseNodeValues();
  319. item.getName() = "New Group";
  320. return item;
  321. }
  322. Project::Item Project::createNewItem (const File& file)
  323. {
  324. Item item (*this, ValueTree (Tags::file));
  325. item.initialiseNodeValues();
  326. item.getName() = file.getFileName();
  327. item.getShouldCompileValue() = file.hasFileExtension ("cpp;mm;c;m");
  328. item.getShouldAddToResourceValue() = shouldBeAddedToBinaryResourcesByDefault (file);
  329. return item;
  330. }
  331. //==============================================================================
  332. Project::Item::Item (Project& project_, const ValueTree& node_)
  333. : project (project_), node (node_)
  334. {
  335. }
  336. Project::Item::Item (const Item& other)
  337. : project (other.project), node (other.node)
  338. {
  339. }
  340. Project::Item::~Item()
  341. {
  342. }
  343. const String Project::Item::getID() const { return node ["id"]; }
  344. bool Project::Item::isFile() const { return node.hasType (Tags::file); }
  345. bool Project::Item::isGroup() const { return node.hasType (Tags::group) || isMainGroup(); }
  346. bool Project::Item::isMainGroup() const { return node.hasType (Tags::projectMainGroup); }
  347. bool Project::Item::canContain (const Item& child) const
  348. {
  349. if (isFile())
  350. return false;
  351. if (isGroup())
  352. return child.isFile() || child.isGroup();
  353. jassertfalse
  354. return false;
  355. }
  356. bool Project::Item::shouldBeAddedToTargetProject() const
  357. {
  358. return isFile();
  359. }
  360. bool Project::Item::shouldBeCompiled() const
  361. {
  362. return getShouldCompileValue().getValue();
  363. }
  364. Value Project::Item::getShouldCompileValue() const
  365. {
  366. return node.getPropertyAsValue ("compile", getUndoManager());
  367. }
  368. bool Project::Item::shouldBeAddedToBinaryResources() const
  369. {
  370. return getShouldAddToResourceValue().getValue();
  371. }
  372. Value Project::Item::getShouldAddToResourceValue() const
  373. {
  374. return node.getPropertyAsValue ("resource", getUndoManager());
  375. }
  376. const File Project::Item::getFile() const
  377. {
  378. if (isFile())
  379. return project.resolveFilename (node ["file"].toString());
  380. else
  381. return File::nonexistent;
  382. }
  383. void Project::Item::setFile (const File& file)
  384. {
  385. jassert (isFile());
  386. node.setProperty ("file", project.getRelativePathForFile (file), getUndoManager());
  387. node.setProperty ("name", file.getFileName(), getUndoManager());
  388. jassert (getFile() == file);
  389. }
  390. bool Project::Item::renameFile (const File& newFile)
  391. {
  392. const File oldFile (getFile());
  393. if (oldFile.moveFileTo (newFile))
  394. {
  395. setFile (newFile);
  396. OpenDocumentManager::getInstance()->fileHasBeenRenamed (oldFile, newFile);
  397. return true;
  398. }
  399. return false;
  400. }
  401. Project::Item Project::Item::findItemForFile (const File& file) const
  402. {
  403. if (getFile() == file)
  404. return *this;
  405. if (isGroup())
  406. {
  407. for (int i = getNumChildren(); --i >= 0;)
  408. {
  409. Item found (getChild(i).findItemForFile (file));
  410. if (found.isValid())
  411. return found;
  412. }
  413. }
  414. return Item (project, ValueTree::invalid);
  415. }
  416. const File Project::Item::determineGroupFolder() const
  417. {
  418. jassert (isGroup());
  419. File f;
  420. for (int i = 0; i < getNumChildren(); ++i)
  421. {
  422. f = getChild(i).getFile();
  423. if (f.exists())
  424. return f.getParentDirectory();
  425. }
  426. Item parent (getParent());
  427. if (parent != *this)
  428. {
  429. f = parent.determineGroupFolder();
  430. if (f.getChildFile (getName().toString()).isDirectory())
  431. f = f.getChildFile (getName().toString());
  432. }
  433. else
  434. {
  435. f = project.getFile().getParentDirectory();
  436. if (f.getChildFile ("Source").isDirectory())
  437. f = f.getChildFile ("Source");
  438. }
  439. return f;
  440. }
  441. void Project::Item::initialiseNodeValues()
  442. {
  443. if (! node.hasProperty ("id"))
  444. node.setProperty ("id", createAlphaNumericUID(), 0);
  445. if (isFile())
  446. {
  447. node.setProperty ("name", getFile().getFileName(), 0);
  448. }
  449. else if (isGroup())
  450. {
  451. for (int i = getNumChildren(); --i >= 0;)
  452. getChild(i).initialiseNodeValues();
  453. }
  454. }
  455. Value Project::Item::getName() const
  456. {
  457. return node.getPropertyAsValue ("name", getUndoManager());
  458. }
  459. void Project::Item::addChild (const Item& newChild, int insertIndex)
  460. {
  461. node.addChild (newChild.getNode(), insertIndex, getUndoManager());
  462. }
  463. void Project::Item::removeItemFromProject()
  464. {
  465. node.getParent().removeChild (node, getUndoManager());
  466. }
  467. Project::Item Project::Item::getParent() const
  468. {
  469. if (isMainGroup() || ! isGroup())
  470. return *this;
  471. return Item (project, node.getParent());
  472. }
  473. struct ItemSorter
  474. {
  475. static int compareElements (const ValueTree& first, const ValueTree& second)
  476. {
  477. return first["name"].toString().compareIgnoreCase (second["name"].toString());
  478. }
  479. };
  480. void Project::Item::sortAlphabetically()
  481. {
  482. ItemSorter sorter;
  483. node.sort (sorter);
  484. }
  485. bool Project::Item::addFile (const File& file, int insertIndex)
  486. {
  487. if (file == File::nonexistent || file.isHidden() || file.getFileName().startsWithChar ('.'))
  488. return false;
  489. if (file.isDirectory())
  490. {
  491. Item group (project.createNewGroup());
  492. group.getName() = file.getFileNameWithoutExtension();
  493. jassert (canContain (group));
  494. addChild (group, insertIndex);
  495. //group.setFile (file);
  496. DirectoryIterator iter (file, false, "*", File::findFilesAndDirectories);
  497. while (iter.next())
  498. group.addFile (iter.getFile(), -1);
  499. group.sortAlphabetically();
  500. }
  501. else if (file.existsAsFile())
  502. {
  503. Item item (project.createNewItem (file));
  504. if (canContain (item))
  505. {
  506. item.setFile (file);
  507. addChild (item, insertIndex);
  508. }
  509. }
  510. else
  511. {
  512. jassertfalse;
  513. }
  514. return true;
  515. }
  516. Image* Project::Item::getIcon() const
  517. {
  518. if (isFile())
  519. return LookAndFeel::getDefaultLookAndFeel().getDefaultDocumentFileImage();
  520. else if (isMainGroup())
  521. return ImageCache::getFromMemory (BinaryData::juce_icon_png, BinaryData::juce_icon_pngSize);
  522. else
  523. return LookAndFeel::getDefaultLookAndFeel().getDefaultFolderImage();
  524. }
  525. //==============================================================================
  526. ValueTree Project::getJuceConfigNode()
  527. {
  528. ValueTree configNode = projectRoot.getChildWithName ("JUCEOPTIONS");
  529. if (! configNode.isValid())
  530. {
  531. configNode = ValueTree ("JUCEOPTIONS");
  532. projectRoot.addChild (configNode, -1, 0);
  533. }
  534. return configNode;
  535. }
  536. void Project::getJuceConfigFlags (OwnedArray <JuceConfigFlag>& flags)
  537. {
  538. ValueTree configNode (getJuceConfigNode());
  539. File juceConfigH (getLocalJuceFolder().getChildFile ("juce_Config.h"));
  540. StringArray lines;
  541. lines.addLines (juceConfigH.loadFileAsString());
  542. for (int i = 0; i < lines.size(); ++i)
  543. {
  544. String line (lines[i].trim());
  545. if (line.startsWith ("/** ") && line.containsChar (':'))
  546. {
  547. ScopedPointer <JuceConfigFlag> config (new JuceConfigFlag());
  548. config->symbol = line.substring (4).upToFirstOccurrenceOf (":", false, false).trim();
  549. if (config->symbol.length() > 4)
  550. {
  551. config->description = line.fromFirstOccurrenceOf (":", false, false).trimStart();
  552. ++i;
  553. while (! (lines[i].contains ("*/") || lines[i].contains ("@see")))
  554. {
  555. if (lines[i].trim().isNotEmpty())
  556. config->description = config->description.trim() + " " + lines[i].trim();
  557. ++i;
  558. }
  559. config->description = config->description.upToFirstOccurrenceOf ("*/", false, false);
  560. config->value.referTo (getJuceConfigFlag (config->symbol));
  561. flags.add (config.release());
  562. }
  563. }
  564. }
  565. }
  566. Value Project::getJuceConfigFlag (const String& name)
  567. {
  568. static const char* valueRemappings[] = { "enabled", "1", "disabled", "2", "default", "3", 0 };
  569. ValueTree configNode (getJuceConfigNode());
  570. Value v (new ValueRemapperSource (configNode.getPropertyAsValue (name, getUndoManagerFor (configNode)),
  571. valueRemappings));
  572. if ((int) v.getValue() == 0)
  573. v = 3;
  574. return v;
  575. }
  576. //==============================================================================
  577. ValueTree Project::getConfigurations() const
  578. {
  579. return projectRoot.getChildWithName (Tags::configurations);
  580. }
  581. int Project::getNumConfigurations() const
  582. {
  583. return getConfigurations().getNumChildren();
  584. }
  585. Project::BuildConfiguration Project::getConfiguration (int index)
  586. {
  587. jassert (index < getConfigurations().getNumChildren());
  588. return BuildConfiguration (this, getConfigurations().getChild (index));
  589. }
  590. bool Project::hasConfigurationNamed (const String& name) const
  591. {
  592. const ValueTree configs (getConfigurations());
  593. for (int i = configs.getNumChildren(); --i >= 0;)
  594. if (configs.getChild(i) ["name"].toString() == name)
  595. return true;
  596. return false;
  597. }
  598. const String Project::getUniqueConfigName (String name) const
  599. {
  600. String nameRoot (name);
  601. while (CharacterFunctions::isDigit (nameRoot.getLastCharacter()))
  602. nameRoot = nameRoot.dropLastCharacters (1);
  603. nameRoot = nameRoot.trim();
  604. int suffix = 2;
  605. while (hasConfigurationNamed (name))
  606. name = nameRoot + " " + String (suffix++);
  607. return name;
  608. }
  609. void Project::addNewConfiguration (BuildConfiguration* configToCopy)
  610. {
  611. const String configName (getUniqueConfigName (configToCopy != 0 ? configToCopy->config ["name"].toString()
  612. : "New Build Configuration"));
  613. ValueTree configs (getConfigurations());
  614. if (! configs.isValid())
  615. {
  616. projectRoot.addChild (ValueTree (Tags::configurations), 0, getUndoManagerFor (projectRoot));
  617. configs = getConfigurations();
  618. }
  619. ValueTree newConfig (Tags::configuration);
  620. if (configToCopy != 0)
  621. newConfig = configToCopy->config.createCopy();
  622. newConfig.setProperty ("name", configName, 0);
  623. configs.addChild (newConfig, -1, getUndoManagerFor (configs));
  624. }
  625. void Project::deleteConfiguration (int index)
  626. {
  627. ValueTree configs (getConfigurations());
  628. configs.removeChild (index, getUndoManagerFor (getConfigurations()));
  629. }
  630. void Project::createDefaultConfigs()
  631. {
  632. for (int i = 0; i < 2; ++i)
  633. {
  634. addNewConfiguration (0);
  635. BuildConfiguration config = getConfiguration (i);
  636. const bool debugConfig = i == 0;
  637. config.getName() = debugConfig ? "Debug" : "Release";
  638. config.isDebug() = debugConfig;
  639. config.getOptimisationLevel() = debugConfig ? 1 : 2;
  640. config.getTargetBinaryName() = getProjectFilenameRoot();
  641. }
  642. }
  643. //==============================================================================
  644. Project::BuildConfiguration::BuildConfiguration (Project* project_, const ValueTree& configNode)
  645. : project (project_),
  646. config (configNode)
  647. {
  648. }
  649. Project::BuildConfiguration::BuildConfiguration (const BuildConfiguration& other)
  650. : project (other.project),
  651. config (other.config)
  652. {
  653. }
  654. const Project::BuildConfiguration& Project::BuildConfiguration::operator= (const BuildConfiguration& other)
  655. {
  656. project = other.project;
  657. config = other.config;
  658. return *this;
  659. }
  660. Project::BuildConfiguration::~BuildConfiguration()
  661. {
  662. }
  663. const String Project::BuildConfiguration::getGCCOptimisationFlag() const
  664. {
  665. const int level = (int) getOptimisationLevel().getValue();
  666. return String (level <= 1 ? "0" : (level == 2 ? "s" : "3"));
  667. }
  668. static const char* osxSDKs[] = { "Use default", "10.4 SDK", "10.5 SDK", "10.6 SDK", 0 };
  669. static const char* osxSDKMappings[] = { "default", "1", "10.4 SDK", "2", "10.5 SDK", "3", "10.6 SDK", "4", "10.7 SDK", "5", 0 };
  670. void Project::BuildConfiguration::createPropertyEditors (Array <PropertyComponent*>& props)
  671. {
  672. props.add (new TextPropertyComponent (getName(), "Name", 96, false));
  673. props.getLast()->setTooltip ("The name of this configuration.");
  674. props.add (new BooleanPropertyComponent (isDebug(), "Debug mode", "Debugging enabled"));
  675. props.getLast()->setTooltip ("If enabled, this means that the configuration should be built with debug synbols.");
  676. const char* optimisationLevels[] = { "No optimisation", "Optimise for size and speed", "Optimise for maximum speed", 0 };
  677. props.add (new ChoicePropertyComponent (getOptimisationLevel(), "Optimisation", StringArray (optimisationLevels)));
  678. props.getLast()->setTooltip ("The optimisation level for this configuration");
  679. props.add (new TextPropertyComponent (getTargetBinaryName(), "Binary name", 256, false));
  680. props.getLast()->setTooltip ("The filename to use for the destination binary executable file. Don't add a suffix to this, because platform-specific suffixes will be added for each target platform.");
  681. props.add (new TextPropertyComponent (getTargetBinaryRelativePath(), "Binary location", 1024, false));
  682. props.getLast()->setTooltip ("The folder in which the finished binary should be placed. Leave this blank to cause the binary to be placed in its default location in the build folder.");
  683. props.add (new TextPropertyComponent (getHeaderSearchPath(), "Header search path", 16384, false));
  684. props.getLast()->setTooltip ("Extra header search paths. Use semi-colons to separate multiple paths.");
  685. props.add (new TextPropertyComponent (getPreprocessorDefs(), "Preprocessor definitions", 32768, false));
  686. props.getLast()->setTooltip ("Extra preprocessor definitions. Use whitespace or commas as a delimiter.");
  687. if ((int) getMacSDKVersion().getValue() == 0)
  688. getMacSDKVersion() = 1;
  689. props.add (new ChoicePropertyComponent (getMacSDKVersion(), "OSX Base SDK Version", StringArray (osxSDKs)));
  690. props.getLast()->setTooltip ("The version of OSX to link against in the XCode build.");
  691. if ((int) getMacCompatibilityVersion().getValue() == 0)
  692. getMacCompatibilityVersion() = 1;
  693. props.add (new ChoicePropertyComponent (getMacCompatibilityVersion(), "OSX Compatibility Version", StringArray (osxSDKs)));
  694. props.getLast()->setTooltip ("The minimum version of OSX that the target binary will be compatible with.");
  695. for (int i = props.size(); --i >= 0;)
  696. props.getUnchecked(i)->setPreferredHeight (22);
  697. }
  698. const StringArray Project::BuildConfiguration::parsePreprocessorDefs() const
  699. {
  700. StringArray defines;
  701. defines.addTokens (getPreprocessorDefs().toString(), " ,;", String::empty);
  702. defines.removeEmptyStrings (true);
  703. return defines;
  704. }
  705. const StringArray Project::BuildConfiguration::getHeaderSearchPaths() const
  706. {
  707. StringArray s;
  708. s.addTokens (getHeaderSearchPath().toString(), ";", String::empty);
  709. return s;
  710. }
  711. Value Project::BuildConfiguration::getMacSDKVersion() const
  712. {
  713. return Value (new ValueRemapperSource (config.getPropertyAsValue ("osxSDK", getUndoManager()), osxSDKMappings));
  714. }
  715. Value Project::BuildConfiguration::getMacCompatibilityVersion() const
  716. {
  717. return Value (new ValueRemapperSource (config.getPropertyAsValue ("osxCompatibility", getUndoManager()), osxSDKMappings));
  718. }
  719. //==============================================================================
  720. ValueTree Project::getExporters()
  721. {
  722. ValueTree exporters (projectRoot.getChildWithName (Tags::exporters));
  723. if (! exporters.isValid())
  724. {
  725. projectRoot.addChild (ValueTree (Tags::exporters), 0, getUndoManagerFor (projectRoot));
  726. exporters = getExporters();
  727. }
  728. return exporters;
  729. }
  730. int Project::getNumExporters()
  731. {
  732. return getExporters().getNumChildren();
  733. }
  734. ProjectExporter* Project::createExporter (int index)
  735. {
  736. jassert (index >= 0 && index < getNumExporters());
  737. return ProjectExporter::createExporter (*this, getExporters().getChild (index));
  738. }
  739. void Project::addNewExporter (int exporterIndex)
  740. {
  741. ScopedPointer<ProjectExporter> exp (ProjectExporter::createNewExporter (*this, exporterIndex));
  742. ValueTree exporters (getExporters());
  743. exporters.addChild (exp->getSettings(), -1, getUndoManagerFor (exporters));
  744. }
  745. void Project::deleteExporter (int index)
  746. {
  747. ValueTree exporters (getExporters());
  748. exporters.removeChild (index, getUndoManagerFor (exporters));
  749. }
  750. void Project::createDefaultExporters()
  751. {
  752. ValueTree exporters (getExporters());
  753. exporters.removeAllChildren (getUndoManagerFor (exporters));
  754. for (int i = 0; i < ProjectExporter::getNumExporters(); ++i)
  755. addNewExporter (i);
  756. }
  757. //==============================================================================
  758. const String Project::getFileTemplate (const String& templateName)
  759. {
  760. int dataSize;
  761. const char* data = BinaryData::getNamedResource (templateName.toUTF8(), dataSize);
  762. if (data == 0)
  763. {
  764. jassertfalse;
  765. return String::empty;
  766. }
  767. return String::fromUTF8 (data, dataSize);
  768. }