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