ProjectDowngrade.cpp 37 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780
  1. #include "engine/ProjectDowngrade.h"
  2. #include "engine/ProjectFile.h"
  3. #include "core/DirectWaveState.h"
  4. #include "core/EchoSuite.h"
  5. #include "core/FacetEq.h"
  6. #include "core/LuxeVerb.h"
  7. #include "core/LynxVerbs.h"
  8. #include "core/MixSuite.h"
  9. #include "core/VoiceShift.h"
  10. #include <cmath>
  11. #include <functional>
  12. // TR_NOOP marks the loss texts for translation (tools/i18n_keys.py); the UI translates them
  13. #ifndef TR_NOOP
  14. #define TR_NOOP(text) text
  15. #endif
  16. namespace lynx::olderlynx
  17. {
  18. namespace
  19. {
  20. using Losses = std::vector<Loss>;
  21. juce::DynamicObject* objectOf (const juce::var& v) { return v.getDynamicObject(); }
  22. juce::Array<juce::var>* arrayOf (const juce::var& v) { return v.getArray(); }
  23. bool drop (juce::DynamicObject& o, const char* key)
  24. {
  25. if (! o.hasProperty (key))
  26. return false;
  27. o.removeProperty (key);
  28. return true;
  29. }
  30. juce::String channelName (const juce::var& c, int index)
  31. {
  32. const auto name = c["name"].toString();
  33. return name.isNotEmpty() ? "\"" + name + "\"" : "#" + juce::String (index + 1);
  34. }
  35. juce::String insertName (const juce::var& mixer, int track)
  36. {
  37. // (language-neutral: "#3 \"Kick\"", the Master as "#0")
  38. const auto name = mixer[track]["name"].toString();
  39. return "#" + juce::String (track) + (name.isNotEmpty() ? " \"" + name + "\"" : juce::String());
  40. }
  41. // "a, b, c" (at most four, then "…")
  42. juce::String listOf (const juce::StringArray& names)
  43. {
  44. juce::StringArray shown;
  45. for (int i = 0; i < names.size() && i < 4; ++i)
  46. shown.add (names[i]);
  47. return shown.joinIntoString (", ") + (names.size() > 4 ? juce::String::fromUTF8 (", \u2026") : juce::String());
  48. }
  49. void forEachChannel (const juce::var& root, const std::function<void (juce::DynamicObject&, int)>& fn)
  50. {
  51. if (auto* channels = arrayOf (root["channels"]))
  52. for (int i = 0; i < channels->size(); ++i)
  53. if (auto* c = objectOf ((*channels)[i]))
  54. fn (*c, i);
  55. }
  56. // every clip array of the project: the Playlist, the stored arrangements, the clip grid's slots
  57. void forEachClip (const juce::var& root, const std::function<void (juce::Array<juce::var>&)>& fn)
  58. {
  59. auto list = [&] (const juce::var& clips) {
  60. if (auto* a = arrayOf (clips))
  61. for (auto& c : *a)
  62. if (auto* fields = arrayOf (c))
  63. fn (*fields);
  64. };
  65. list (root["playlist"]);
  66. if (auto* arrangements = arrayOf (root["arrangements"]))
  67. for (const auto& a : *arrangements)
  68. list (a["clips"]);
  69. if (auto* slots = arrayOf (root["clipGrid"]["clips"]))
  70. for (const auto& s : *slots)
  71. list (s["clip"]);
  72. }
  73. // Every effect object below `v` (the mixer's slots, a Patcher's nodes, a rack's branches): `fn (effect, where)`, `where`
  74. // the insert ("#3 \"Vox\"") of a mixer slot, else "Patcher"
  75. void forEachEffect (const juce::var& root, const std::function<void (juce::DynamicObject&, const juce::String&)>& fn)
  76. {
  77. std::function<void (const juce::var&, const juce::String&)> walk = [&] (const juce::var& v, const juce::String& where) {
  78. if (auto* a = arrayOf (v))
  79. {
  80. for (auto& item : *a)
  81. walk (item, where);
  82. return;
  83. }
  84. auto* o = objectOf (v);
  85. if (o == nullptr)
  86. return;
  87. if (o->getProperty ("kind").isString() && o->getProperty ("params").isArray())
  88. fn (*o, where);
  89. for (auto& p : o->getProperties())
  90. walk (p.value, "Patcher");
  91. };
  92. if (auto* mixer = arrayOf (root["mixer"]))
  93. for (int t = 0; t < mixer->size(); ++t)
  94. if (auto* fx = arrayOf ((*mixer)[t]["effects"]))
  95. for (auto& e : *fx)
  96. {
  97. if (auto* o = objectOf (e); o != nullptr && o->getProperty ("kind").isString() && o->getProperty ("params").isArray())
  98. fn (*o, insertName (root["mixer"], t));
  99. if (auto* o = objectOf (e))
  100. for (auto& p : o->getProperties())
  101. walk (p.value, "Patcher");
  102. }
  103. if (auto* channels = arrayOf (root["channels"]))
  104. for (auto& c : *channels)
  105. if (auto* o = objectOf (c))
  106. for (auto& p : o->getProperties())
  107. walk (p.value, "Patcher");
  108. }
  109. void addOnce (juce::StringArray& list, const juce::String& item)
  110. {
  111. if (! list.contains (item))
  112. list.add (item);
  113. }
  114. // Rollup 0.1.30 (round 190il): what the other 0.1.30 rounds save that 0.1.28 cannot hold (round 190hq's step above
  115. // knew only its own). Each loss is reported only when the project has it.
  116. void toRelease0128FromRollup030 (juce::var& root, Losses& lost)
  117. {
  118. auto& o = *objectOf (root);
  119. // channels: Tetra (round 190hs) is not in 0.1.28, which would play its channels as its basic synth: an empty Sampler
  120. // (silent) keeps the channel, its notes and its routing; DirectWave states (rounds 190hz / 190ii) get their short zone
  121. // records completed as DirectWave reads them, since 0.1.28 skipped them (FL's version-36 programs lost their loops)
  122. {
  123. juce::StringArray tetra, helix;
  124. forEachChannel (root, [&] (juce::DynamicObject& c, int i) {
  125. const auto instrument = c.getProperty ("instrument").toString();
  126. if (instrument == "tetra" || instrument == "helix") // (rollup step 3: Helix, round 190ja, as Tetra)
  127. {
  128. (instrument == "tetra" ? tetra : helix).add (channelName (juce::var (&c), i));
  129. c.setProperty ("instrument", "sampler");
  130. drop (c, "modelParams");
  131. drop (c, "pluginState");
  132. drop (c, "samplePath");
  133. }
  134. else if (instrument == "directwave")
  135. {
  136. juce::MemoryOutputStream decoded;
  137. if (! juce::Base64::convertFromBase64 (decoded, c.getProperty ("pluginState").toString()))
  138. return;
  139. const auto* bytes = static_cast<const std::uint8_t*> (decoded.getData());
  140. auto doc = dw::readDoc (std::vector<std::uint8_t> (bytes, bytes + decoded.getDataSize()));
  141. if (doc && dw::completeShortZoneRecords (*doc) > 0)
  142. {
  143. const auto state = dw::writeDoc (*doc);
  144. c.setProperty ("pluginState", juce::Base64::toBase64 (state.data(), state.size()));
  145. }
  146. }
  147. });
  148. if (! tetra.isEmpty())
  149. lost.push_back ({ TR_NOOP ("Tetra is not in this release: its channels become empty Samplers and play nothing: {0}"), listOf (tetra), true });
  150. if (! helix.isEmpty())
  151. lost.push_back ({ TR_NOOP ("Helix is not in this release: its channels become empty Samplers and play nothing: {0}"), listOf (helix), true });
  152. }
  153. // notes: index 19 holds a note's MPE curves (round 190hy)
  154. {
  155. int curved = 0;
  156. if (auto* patterns = arrayOf (root["patterns"]))
  157. for (auto& p : *patterns)
  158. if (auto* notes = arrayOf (p["notes"]))
  159. for (auto& n : *notes)
  160. if (auto* fields = arrayOf (n); fields != nullptr && fields->size() > 19)
  161. {
  162. ++curved;
  163. fields->removeRange (19, fields->size() - 19);
  164. }
  165. if (curved > 0)
  166. lost.push_back ({ TR_NOOP ("{0} note(s) lose their MPE curves (pitch bend, slide, pressure)"), juce::String (curved), true });
  167. }
  168. // Pattern Blocks: a third element marks a muted block (round 190ht); 0.1.28 reads only [pattern, start] and drops
  169. // any other block. A muted block plays nothing, so it is left out (the sound stays); the rest keep their two.
  170. {
  171. int muted = 0;
  172. auto blocks = [&muted] (const juce::var& list) {
  173. if (auto* a = arrayOf (list))
  174. for (int i = a->size(); --i >= 0;)
  175. if (auto* b = arrayOf ((*a)[i]); b != nullptr && b->size() > 2)
  176. {
  177. if ((int) (*b)[2] != 0)
  178. {
  179. a->remove (i);
  180. ++muted;
  181. }
  182. else
  183. b->removeRange (2, b->size() - 2);
  184. }
  185. };
  186. blocks (root["blocks"]);
  187. if (auto* arrangements = arrayOf (root["arrangements"]))
  188. for (const auto& a : *arrangements)
  189. blocks (a["blocks"]);
  190. if (muted > 0)
  191. lost.push_back ({ TR_NOOP ("{0} muted Pattern Block(s) are left out (they play nothing)"), juce::String (muted), false });
  192. }
  193. // clips: index 13 is the clip's pitch, ±48 semitones since round 190hr (0.1.28 holds ±12)
  194. {
  195. int transposed = 0;
  196. forEachClip (root, [&] (juce::Array<juce::var>& clip) {
  197. if (clip.size() > 13)
  198. if (const auto pitch = (double) clip[13]; std::abs (pitch) > 12.0)
  199. {
  200. clip.set (13, juce::jlimit (-12.0, 12.0, pitch));
  201. ++transposed;
  202. }
  203. });
  204. if (transposed > 0)
  205. lost.push_back ({ TR_NOOP ("{0} clip(s) transposed by more than 12 semitones play at ±12"), juce::String (transposed), true });
  206. }
  207. // clip slots (round 190hr): the Start marker inside the loop, the clip's own scale
  208. {
  209. int markers = 0, scales = 0;
  210. if (auto* slots = arrayOf (root["clipGrid"]["clips"]))
  211. for (auto& slot : *slots)
  212. if (auto* so = objectOf (slot))
  213. {
  214. markers += drop (*so, "startMarker") ? 1 : 0;
  215. scales += drop (*so, "clipScale") ? 1 : 0;
  216. }
  217. if (markers > 0)
  218. lost.push_back ({ TR_NOOP ("{0} clip slot(s) launch from their loop start (the Start marker inside the loop)"), juce::String (markers), true });
  219. if (scales > 0)
  220. lost.push_back ({ TR_NOOP ("Clip scales (Scale Mode) of {0} clip slot(s)"), juce::String (scales), false });
  221. }
  222. // effects (round 190ho): Voice Shift's Measured law revision 1, Ridge Strip's 4K Pink EQ; (round 190iq) Hush De-esser's
  223. // measured Allround timing (hidden parameters 0.1.28 ignores: it plays revision 0, Black, and the earlier timing)
  224. {
  225. juce::StringArray thump, pink, hushTiming, echoVoicings, latticeTaps, luxeDucking, verbRevisions;
  226. forEachEffect (root, [&] (juce::DynamicObject& e, const juce::String& where) {
  227. auto* params = arrayOf (e.getProperty ("params"));
  228. if (params == nullptr) // (a slot written without parameters)
  229. return;
  230. const auto kind = e.getProperty ("kind").toString();
  231. if (kind == "voiceShift" && params->size() > voiceshift::revision)
  232. {
  233. if ((float) (double) (*params)[voiceshift::law] >= 0.5f && (float) (double) (*params)[voiceshift::revision] >= 0.5f)
  234. addOnce (thump, where);
  235. params->removeRange (voiceshift::revision, params->size() - voiceshift::revision);
  236. }
  237. else if (kind == "ridgeStrip" && params->size() > mixsuite::ridge::k4Pink)
  238. {
  239. if ((float) (double) (*params)[mixsuite::ridge::k4Pink] >= 0.5f)
  240. addOnce (pink, where);
  241. params->removeRange (mixsuite::ridge::k4Pink, params->size() - mixsuite::ridge::k4Pink);
  242. }
  243. else if (kind == "hushDeEsser" && params->size() > mixsuite::hush::timing)
  244. {
  245. // (the timing is the Allround law's: Single Vocal plays the same either way)
  246. if ((float) (double) (*params)[mixsuite::hush::timing] >= 0.5f && (float) (double) (*params)[mixsuite::hush::allround] >= 0.5f)
  247. addOnce (hushTiming, where);
  248. params->removeRange (mixsuite::hush::timing, params->size() - mixsuite::hush::timing);
  249. }
  250. // rollup step 3: round 190is's Echoform voicings revision (heard only with an echo voicing), round 190it's
  251. // reverb revisions (the Measured law's: Law 1), Lattice Mod's tap network and LuxeVerb's Space ducking
  252. else if (kind == "echoform" && params->size() > echosuite::echoform::revision)
  253. {
  254. if ((float) (double) (*params)[echosuite::echoform::revision] >= 0.5f && (float) (double) (*params)[echosuite::echoform::voicing] >= 0.5f)
  255. addOnce (echoVoicings, where);
  256. params->removeRange (echosuite::echoform::revision, params->size() - echosuite::echoform::revision);
  257. }
  258. else if (kind == "latticeMod" && params->size() > echosuite::lattice::revision)
  259. {
  260. if ((float) (double) (*params)[echosuite::lattice::revision] >= 0.5f)
  261. addOnce (latticeTaps, where);
  262. params->removeRange (echosuite::lattice::revision, params->size() - echosuite::lattice::revision);
  263. }
  264. else if (kind == "luxeVerb" && params->size() > luxeVerbSpaceDucking)
  265. {
  266. if ((float) (double) (*params)[luxeVerbSpaceDucking] > 0.0f)
  267. addOnce (luxeDucking, where);
  268. params->removeRange (luxeVerbSpaceDucking, params->size() - luxeVerbSpaceDucking);
  269. }
  270. else
  271. {
  272. const auto verb = [&] (const char* id, int law, int revision) {
  273. if (kind != id || params->size() <= revision)
  274. return;
  275. if ((float) (double) (*params)[revision] >= 0.5f && (float) (double) (*params)[law] >= 0.5f)
  276. addOnce (verbRevisions, where);
  277. params->removeRange (revision, params->size() - revision);
  278. };
  279. verb ("epochVerb", verbs::epoch::engineLaw, verbs::epoch::revision);
  280. verb ("atrium", verbs::atrium::engineLaw, verbs::atrium::revision);
  281. verb ("foilPlate", verbs::foil::engineLaw, verbs::foil::revision);
  282. verb ("halo", verbs::halo::engineLaw, verbs::halo::revision);
  283. }
  284. });
  285. if (! thump.isEmpty())
  286. lost.push_back ({ TR_NOOP ("Voice Shift's Measured law plays its earlier version (a low thump at sung onsets): {0}"), listOf (thump), true });
  287. if (! pink.isEmpty())
  288. lost.push_back ({ TR_NOOP ("Ridge Strip's 4K Pink EQ plays as the Black EQ: {0}"), listOf (pink), true });
  289. if (! hushTiming.isEmpty())
  290. lost.push_back ({ TR_NOOP ("Hush De-esser's Allround mode plays its earlier timing: {0}"), listOf (hushTiming), true });
  291. if (! echoVoicings.isEmpty())
  292. lost.push_back ({ TR_NOOP ("Echoform's echo voicings play their earlier loop: {0}"), listOf (echoVoicings), true });
  293. if (! verbRevisions.isEmpty())
  294. lost.push_back ({ TR_NOOP ("Epoch Verb, Atrium, Foil Plate and Halo play the 0.1.27 version of their Measured law: {0}"), listOf (verbRevisions), true });
  295. if (! latticeTaps.isEmpty())
  296. lost.push_back ({ TR_NOOP ("Lattice Mod plays its earlier tap network: {0}"), listOf (latticeTaps), true });
  297. if (! luxeDucking.isEmpty())
  298. lost.push_back ({ TR_NOOP ("LuxeVerb's Space ducking is not in this release: {0}"), listOf (luxeDucking), true });
  299. }
  300. // rollup step 3, round 190ik (warp engines): an 11-number warpModes list (the Texture / Complex Pro law), Beats'
  301. // pitch-aware law (0.1.28 reads it as Measured), Complex Pro / Texture transpositions rendered offline (0.1.28
  302. // renders a baked pitch only for Beats: it goes to the Pitch knob, as 0.1.28 itself moves it)
  303. {
  304. juce::StringArray pitchAware, newEngines, knobPitch;
  305. bool warped = false;
  306. // (a project saved by this build has the mark; a channel without its own list then plays the pitch-aware Beats
  307. // and the Measured Texture / Complex Pro laws, which 0.1.28 reads as Measured Beats and its Classic engines)
  308. const auto marked = (bool) root.getProperty ("warpLaw190ik", false);
  309. forEachChannel (root, [&] (juce::DynamicObject& c, int i) {
  310. auto* sampler = objectOf (c.getProperty ("samplerSettings"));
  311. if (sampler == nullptr)
  312. return;
  313. const juce::var sv (sampler);
  314. const auto method = (int) sv.getProperty ("stretchMethod", 0); // (StretchMethod: 3 Beats, 5 Texture, 6 Complex)
  315. const auto stretched = (double) sv.getProperty ("stretchBeats", 0.0) > 0.0;
  316. const auto keepsPitch = (bool) sv.getProperty ("keepPitch", false);
  317. warped = warped || stretched;
  318. auto* list = arrayOf (sampler->getProperty ("warpModes"));
  319. const auto listed = list != nullptr && list->size() >= 9;
  320. const auto beatsLaw = listed && list->size() > 9 ? (double) (*list)[9] : 2.0;
  321. const auto warpLaw = listed && list->size() > 10 ? (double) (*list)[10] : 1.0;
  322. const auto complexPro = listed && (double) (*list)[8] != 0.0;
  323. if (marked && stretched && keepsPitch && method == 3 && beatsLaw >= 1.5)
  324. pitchAware.add (channelName (juce::var (&c), i));
  325. if (marked && stretched && keepsPitch && warpLaw >= 0.5 && (method == 5 || (method == 6 && complexPro)))
  326. newEngines.add (channelName (juce::var (&c), i));
  327. if (list != nullptr && list->size() > 10)
  328. {
  329. if (beatsLaw >= 1.5)
  330. list->set (9, 1.0);
  331. list->removeRange (10, list->size() - 10);
  332. }
  333. if (const auto baked = (double) sv.getProperty ("stretchPitch", 0.0); baked != 0.0 && method != 3)
  334. {
  335. sampler->setProperty ("pitch", juce::jlimit (-24.0, 24.0, (double) sv.getProperty ("pitch", 0.0) + baked));
  336. sampler->removeProperty ("stretchPitch");
  337. knobPitch.add (channelName (juce::var (&c), i));
  338. }
  339. });
  340. if (! pitchAware.isEmpty())
  341. lost.push_back ({ TR_NOOP ("Beats' pitch-aware cuts play as the Measured law: {0}"), listOf (pitchAware), true });
  342. if (! newEngines.isEmpty())
  343. lost.push_back ({ TR_NOOP ("Texture and Complex Pro play their earlier engine (no grains or formants): {0}"), listOf (newEngines), true });
  344. if (! knobPitch.isEmpty())
  345. lost.push_back ({ TR_NOOP ("Complex Pro and Texture transpositions play through the Pitch knob: {0}"), listOf (knobPitch), true });
  346. // issue #187 (round 190ik): engine behaviour, nothing to drop; reported when warped samples meet tempo automation
  347. bool tempoAutomation = false;
  348. if (auto* automations = arrayOf (root["automations"]))
  349. for (const auto& a : *automations)
  350. tempoAutomation = tempoAutomation || a["target"][0].toString() == "tempo";
  351. if (warped && tempoAutomation)
  352. lost.push_back ({ TR_NOOP ("Warped samples do not follow tempo changes in this release: they keep the project tempo"), {}, true });
  353. }
  354. // rollup step 3, round 190im (R12): Live's deactivated clip slots ("inactive"); 0.1.28 plays them
  355. {
  356. int inactive = 0;
  357. if (auto* slots = arrayOf (root["clipGrid"]["clips"]))
  358. for (auto& slot : *slots)
  359. if (auto* so = objectOf (slot))
  360. inactive += drop (*so, "inactive") ? 1 : 0;
  361. if (inactive > 0)
  362. lost.push_back ({ TR_NOOP ("{0} deactivated clip slot(s) play again"), juce::String (inactive), true });
  363. }
  364. // rollup step 4, round 190jh: Facet EQ's automatic dynamic thresholds (hidden parameters past its count; 0.1.28 plays
  365. // those bands with their manual threshold)
  366. {
  367. juce::StringArray autoBands;
  368. forEachEffect (root, [&] (juce::DynamicObject& e, const juce::String& where) {
  369. auto* params = arrayOf (e.getProperty ("params"));
  370. if (params == nullptr || e.getProperty ("kind").toString() != "facetEq" || params->size() <= facet::autoThresholdParam0)
  371. return;
  372. for (int b = 0; b < 8 && facet::autoThresholdParam0 + b < params->size(); ++b)
  373. if ((float) (double) (*params)[facet::autoThresholdParam0 + b] >= 0.5f)
  374. addOnce (autoBands, where);
  375. params->removeRange (facet::autoThresholdParam0, params->size() - facet::autoThresholdParam0);
  376. });
  377. if (! autoBands.isEmpty())
  378. lost.push_back ({ TR_NOOP ("Facet EQ's automatic dynamic thresholds play with the bands' manual threshold: {0}"), listOf (autoBands), true });
  379. }
  380. // rollup step 4, round 190jl: MIDI Out channels and the plugin wrappers' Output port reach hardware MIDI outputs from
  381. // 0.1.30 on (0.1.28 sends them to plugins on that port only); engine behaviour, nothing to drop
  382. {
  383. juce::StringArray hardware;
  384. forEachChannel (root, [&] (juce::DynamicObject& c, int i) {
  385. // (the wrapper's "midiOutPort" is written only when it has a port)
  386. if (c.getProperty ("instrument").toString() == "midiOut" || c.getProperty ("plugin").hasProperty ("midiOutPort"))
  387. addOnce (hardware, channelName (juce::var (&c), i));
  388. });
  389. if (! hardware.isEmpty())
  390. lost.push_back ({ TR_NOOP ("MIDI Out channels and plugins' MIDI output reach only plugins in this release, not hardware MIDI outputs: {0}"), listOf (hardware), true });
  391. }
  392. // rollup step 4, round 190jg: sample-accurate automation of hosted CLAP / VST3 plugins (0.1.28 applies a change once
  393. // per piece of up to 128 samples); engine behaviour, reported when automation drives such a plugin's parameter
  394. {
  395. const auto hosted = [] (const juce::var& plugin) {
  396. const auto id = plugin["id"].toString();
  397. return id.startsWith ("VST3-") || id.startsWith ("CLAP-");
  398. };
  399. bool timed = false;
  400. std::function<void (const juce::var&)> walk = [&] (const juce::var& v) {
  401. if (timed)
  402. return;
  403. if (auto* a = arrayOf (v))
  404. {
  405. for (const auto& item : *a)
  406. walk (item);
  407. return;
  408. }
  409. auto* o = objectOf (v);
  410. if (o == nullptr)
  411. return;
  412. if (const auto& target = o->getProperty ("target"); target.isArray() && target.size() >= 4)
  413. {
  414. const auto kind = target[0].toString();
  415. const auto index = (int) target[1], slot = (int) target[2];
  416. if (kind == "channelParam")
  417. timed = root["channels"][index]["instrument"].toString() == "plugin" && hosted (root["channels"][index]["plugin"]);
  418. else if (kind == "effectParam")
  419. timed = root["mixer"][index]["effects"][slot]["kind"].toString() == "plugin" && hosted (root["mixer"][index]["effects"][slot]["plugin"]);
  420. }
  421. for (const auto& p : o->getProperties())
  422. walk (p.value);
  423. };
  424. walk (root["automations"]);
  425. walk (root["patterns"]);
  426. walk (root["playlistTracks"]);
  427. if (timed)
  428. lost.push_back ({ TR_NOOP ("Automation of hosted CLAP and VST3 plugins changes once per 128 samples in this release (0.1.30 places each change at its own sample)"), {}, true });
  429. }
  430. // the view
  431. {
  432. // rollup step 4: round 190jf's nested Playlist folders (0.1.28 opens the groups one level deep), round 190jd's
  433. // second display view of an effect (Fruity Limiter's CURVE; 0.1.28 shows its one view)
  434. if (auto* nests = arrayOf (root["playlistTrackNest"]))
  435. {
  436. const auto count = nests->size();
  437. drop (o, "playlistTrackNest");
  438. if (count > 0)
  439. lost.push_back ({ TR_NOOP ("{0} track(s) in nested Playlist folders open one level deep"), juce::String (count), false });
  440. }
  441. juce::StringArray views;
  442. forEachEffect (root, [&] (juce::DynamicObject& e, const juce::String& where) {
  443. if (drop (e, "displayView"))
  444. addOnce (views, where);
  445. });
  446. if (! views.isEmpty())
  447. lost.push_back ({ TR_NOOP ("Fruity Limiter's CURVE view (its display shows the scrolling graph): {0}"), listOf (views), false });
  448. bool colours = false;
  449. if (auto* automations = arrayOf (root["automations"]))
  450. for (auto& a : *automations)
  451. if (auto* ao = objectOf (a))
  452. colours = drop (*ao, "colour") || colours;
  453. if (colours)
  454. lost.push_back ({ TR_NOOP ("Automation clip colours"), {}, false });
  455. if (drop (o, "mixSnapshots"))
  456. lost.push_back ({ TR_NOOP ("Mix snapshots (the Mixer menu)"), {}, false });
  457. }
  458. }
  459. // --- 0.1.29 / 0.1.30 → 0.1.28 ------------------------------------------------------------------------------------------
  460. void toRelease0128 (juce::var& root, Losses& lost)
  461. {
  462. auto& o = *objectOf (root);
  463. // (reported only when the project has such automation: the mark is on in every new project)
  464. bool levelAutomation = false;
  465. if (auto* automations = arrayOf (root["automations"]))
  466. for (const auto& a : *automations)
  467. if (const auto kind = a["target"][0].toString(); kind == "mixerVolume" || kind == "mixerPan" || kind == "mixerSend" || kind == "vcaLevel")
  468. levelAutomation = true;
  469. if (drop (o, "mixerLevelPdc190hq") && levelAutomation)
  470. lost.push_back ({ TR_NOOP ("Mixer › Plugin delay compensation › \"Compensate fader and route automations too\" is not in this release: that automation plays a little early behind plugins with latency"), {}, true });
  471. int markers = 0;
  472. if (auto* automations = arrayOf (root["automations"]))
  473. for (auto& a : *automations)
  474. if (auto* ao = objectOf (a); ao != nullptr && drop (*ao, "tempoMarkers"))
  475. if (auto* points = arrayOf (a["points"]))
  476. markers += juce::jmax (0, points->size() - 1);
  477. if (markers > 0)
  478. lost.push_back ({ TR_NOOP ("{0} tempo marker(s) on the ruler become a plain tempo automation clip (the tempo plays the same)"), juce::String (markers), false });
  479. // round 190hq's side-chain compensation is engine behaviour: nothing to drop, but an older release lines up less
  480. bool sidechain = false;
  481. if (auto* mixer = arrayOf (root["mixer"]))
  482. for (const auto& t : *mixer)
  483. if (auto* fx = arrayOf (t["effects"]))
  484. for (const auto& e : *fx)
  485. sidechain = sidechain || (int) e.getProperty ("sidechain", -1) > 0 || (int) e.getProperty ("sidechain2", -1) > 0;
  486. if (sidechain)
  487. lost.push_back ({ TR_NOOP ("Side-chains are not lined up with plugin delay compensation in this release: behind plugins with latency, ducking may be a few milliseconds off"), {}, true });
  488. toRelease0128FromRollup030 (root, lost);
  489. }
  490. // --- 0.1.28 → 0.1.27 -----------------------------------------------------------------------------------------------------
  491. // A slot 0.1.27 does not know (it would drop it, moving every later slot): a switched-off Utility in its place.
  492. bool flattenUnknownEffect (juce::var& e)
  493. {
  494. auto* o = objectOf (e);
  495. if (o == nullptr || e["kind"].toString() != "anvilBus")
  496. return false;
  497. auto replacement = std::make_unique<juce::DynamicObject>();
  498. replacement->setProperty ("kind", "utility");
  499. replacement->setProperty ("on", false);
  500. for (const auto* keep : { "row", "sidechain", "sidechain2" })
  501. if (o->hasProperty (keep))
  502. replacement->setProperty (keep, o->getProperty (keep));
  503. e = juce::var (replacement.release());
  504. return true;
  505. }
  506. // nested chains (a Patcher's nodes, a rack's branches): every effect object below `v`
  507. void flattenNested (juce::var& v, int& count)
  508. {
  509. if (auto* a = arrayOf (v))
  510. {
  511. for (auto& item : *a)
  512. flattenNested (item, count);
  513. return;
  514. }
  515. auto* o = objectOf (v);
  516. if (o == nullptr)
  517. return;
  518. for (auto& p : o->getProperties())
  519. {
  520. auto value = p.value;
  521. if (value.isObject() && value["kind"].toString() == "anvilBus" && (p.name.toString() == "effect" || p.name.toString() == "head"))
  522. {
  523. if (flattenUnknownEffect (value))
  524. {
  525. o->setProperty (p.name, value);
  526. ++count;
  527. }
  528. continue;
  529. }
  530. if (auto* list = arrayOf (value); list != nullptr && (p.name.toString() == "chain" || p.name.toString() == "effects"))
  531. for (auto& item : *list)
  532. if (flattenUnknownEffect (item))
  533. ++count;
  534. flattenNested (value, count);
  535. }
  536. }
  537. // automation that drove slot (track, slot)'s parameters or mix now drives nothing ("none")
  538. void detachTargets (juce::var& v, int track, int slot)
  539. {
  540. auto isSlotTarget = [&] (const juce::var& t) {
  541. if (! t.isArray() || t.size() < 4)
  542. return false;
  543. const auto kind = t[0].toString();
  544. return (kind == "effectParam" || kind == "effectMix") && (int) t[1] == track && (int) t[2] == slot;
  545. };
  546. if (auto* a = arrayOf (v))
  547. {
  548. for (auto& item : *a)
  549. detachTargets (item, track, slot);
  550. return;
  551. }
  552. auto* o = objectOf (v);
  553. if (o == nullptr)
  554. return;
  555. for (auto& p : o->getProperties())
  556. {
  557. auto value = p.value;
  558. if (p.name.toString() == "target" && isSlotTarget (value))
  559. if (auto* t = arrayOf (value))
  560. t->set (0, "none");
  561. if (p.name.toString() == "links")
  562. if (auto* links = arrayOf (value))
  563. for (auto& l : *links)
  564. if (isSlotTarget (l))
  565. if (auto* t = arrayOf (l))
  566. t->set (0, "none");
  567. detachTargets (value, track, slot);
  568. }
  569. }
  570. void toRelease0127 (juce::var& root, Losses& lost)
  571. {
  572. auto& o = *objectOf (root);
  573. // the effect 0.1.28 added (Anvil Bus, round 190fk)
  574. {
  575. juce::StringArray where;
  576. if (auto* mixer = arrayOf (root["mixer"]))
  577. for (int t = 0; t < mixer->size(); ++t)
  578. if (auto* fx = arrayOf ((*mixer)[t]["effects"]))
  579. for (int s = 0; s < fx->size(); ++s)
  580. if (flattenUnknownEffect (fx->getReference (s)))
  581. {
  582. where.add (insertName (o.getProperty ("mixer"), t) + juce::String::fromUTF8 (" \u203a ") + juce::String (s + 1));
  583. detachTargets (root, t, s);
  584. }
  585. int nested = 0;
  586. if (auto* mixer = arrayOf (root["mixer"]))
  587. for (auto& t : *mixer)
  588. if (auto* fx = arrayOf (t["effects"]))
  589. for (auto& e : *fx)
  590. flattenNested (e, nested);
  591. if (auto* channels = arrayOf (root["channels"]))
  592. for (auto& c : *channels)
  593. flattenNested (c, nested);
  594. if (nested > 0)
  595. where.add (juce::String (nested) + juce::String::fromUTF8 (" \u00d7 Patcher"));
  596. if (! where.isEmpty())
  597. lost.push_back ({ TR_NOOP ("Anvil Bus is not in this release: it becomes a switched-off Utility in its slot, and its automation does nothing ({0})"), listOf (where), true });
  598. }
  599. // channels
  600. {
  601. juce::StringArray cut, pads, warp, frozen, beats, soundfonts;
  602. bool scales = false;
  603. forEachChannel (root, [&] (juce::DynamicObject& c, int i) {
  604. const auto name = channelName (juce::var (&c), i);
  605. if (drop (c, "cutOthersOnly") | drop (c, "cutAtNoteEnd"))
  606. cut.add (name);
  607. scales = drop (c, "editorScale") || scales;
  608. if (drop (c, "simplePad"))
  609. pads.add (name);
  610. if (drop (c, "trackFreeze"))
  611. frozen.add (name);
  612. if (auto* sampler = objectOf (c.getProperty ("samplerSettings")))
  613. {
  614. if (drop (*sampler, "warpModes"))
  615. warp.add (name);
  616. if ((int) sampler->getProperty ("stretchMethod") == (int) StretchMethod::beats)
  617. beats.add (name);
  618. }
  619. if (c.getProperty ("instrument").toString() == "soundfont")
  620. soundfonts.add (name);
  621. });
  622. if (! cut.isEmpty())
  623. lost.push_back ({ TR_NOOP ("Cut group modes (\"Cut others only\", \"Cut at the note's end\"): {0}"), listOf (cut), true });
  624. if (! pads.isEmpty())
  625. lost.push_back ({ TR_NOOP ("Simple workflow pad settings (mode, tone, release, group): {0}"), listOf (pads), true });
  626. if (! warp.isEmpty())
  627. lost.push_back ({ TR_NOOP ("Warp mode settings (Preserve, loop mode, grain sizes) go back to their defaults: {0}"), listOf (warp), true });
  628. if (! frozen.isEmpty())
  629. lost.push_back ({ TR_NOOP ("Freeze Track: these channels play live again (the same sound, more CPU): {0}"), listOf (frozen), false });
  630. if (scales)
  631. lost.push_back ({ TR_NOOP ("Plugin window sizes (Scale)"), {}, false });
  632. if (drop (o, "beatsLaw190gx") && ! beats.isEmpty())
  633. lost.push_back ({ TR_NOOP ("Beats warping uses this release's older (Classic) law: {0}"), listOf (beats), true });
  634. if (drop (o, "sfModBase190he") && ! soundfonts.isEmpty())
  635. lost.push_back ({ TR_NOOP ("Soundfont modulation knobs centre at this release's older value: {0}"), listOf (soundfonts), true });
  636. }
  637. // clips: index 24 (a Playlist clip's groove, round 190fm) and 25 (its envelopes, round 190gi) are new
  638. {
  639. int grooves = 0, envelopes = 0;
  640. forEachClip (root, [&] (juce::Array<juce::var>& clip) {
  641. if (clip.size() > 24 && (juce::int64) clip[24] != 0)
  642. ++grooves;
  643. if (clip.size() > 25 && (int) clip[25] >= 0)
  644. ++envelopes;
  645. if (clip.size() > 24)
  646. clip.removeRange (24, clip.size() - 24);
  647. });
  648. if (drop (o, "clipEnvelopes") && envelopes > 0)
  649. lost.push_back ({ TR_NOOP ("{0} audio clip envelope(s): those clips play at their own level and pan"), juce::String (envelopes), true });
  650. if (grooves > 0)
  651. lost.push_back ({ TR_NOOP ("{0} Playlist clip groove(s): those clips play straight"), juce::String (grooves), true });
  652. }
  653. // automation clips with several target links (round 190gw): 0.1.27 drives the first one, 1:1
  654. {
  655. juce::StringArray linked;
  656. if (auto* automations = arrayOf (root["automations"]))
  657. for (int i = 0; i < automations->size(); ++i)
  658. if (auto* a = objectOf ((*automations)[i]))
  659. {
  660. const auto links = a->getProperty ("links");
  661. const auto formula = links.isArray() && links.size() > 0 && links[0].isArray() && links[0].size() >= 5 ? links[0][4].toString() : juce::String();
  662. if (drop (*a, "links") && (links.size() > 1 || formula.isNotEmpty()))
  663. linked.add ("\"" + a->getProperty ("name").toString() + "\"");
  664. }
  665. if (! linked.isEmpty())
  666. lost.push_back ({ TR_NOOP ("Automation clips with several targets or a formula drive only their first target, 1:1: {0}"), listOf (linked), true });
  667. }
  668. // the song
  669. if (o.hasProperty ("beatUnit"))
  670. {
  671. const auto unit = (int) o.getProperty ("beatUnit");
  672. drop (o, "beatUnit");
  673. lost.push_back ({ TR_NOOP ("The time signature's beat unit: n/{0} becomes n/4"), juce::String (unit), true });
  674. }
  675. if (drop (o, "linkTracksToMixer"))
  676. lost.push_back ({ TR_NOOP ("\"Link Playlist tracks to mixer tracks\" (a setting)"), {}, false });
  677. if (drop (o, "midiGenerate"))
  678. lost.push_back ({ TR_NOOP ("MIDI generator settings"), {}, false });
  679. if (drop (o, "playlistRowHeight"))
  680. lost.push_back ({ TR_NOOP ("The Playlist's row height"), {}, false });
  681. }
  682. struct Step
  683. {
  684. const char* release; // the release this step's output is for
  685. void (*apply) (juce::var&, Losses&);
  686. };
  687. // newest first: a copy for release R runs every step down to R's
  688. constexpr Step steps[] = { { "0.1.28", toRelease0128 }, { "0.1.27", toRelease0127 } };
  689. } // namespace
  690. juce::StringArray releases()
  691. {
  692. juce::StringArray r;
  693. for (const auto& s : steps)
  694. r.add (s.release);
  695. return r;
  696. }
  697. Copy forRelease (const juce::String& projectJson, const juce::String& release)
  698. {
  699. Copy copy;
  700. if (! releases().contains (release))
  701. {
  702. copy.error = "no such release: " + release;
  703. return copy;
  704. }
  705. auto root = juce::JSON::parse (projectJson);
  706. if (objectOf (root) == nullptr)
  707. {
  708. copy.error = "not a project";
  709. return copy;
  710. }
  711. const auto from = root["savedBy"].toString();
  712. for (const auto& s : steps)
  713. {
  714. s.apply (root, copy.lost);
  715. if (release == s.release)
  716. break;
  717. }
  718. // stamped as that release's own file (no "saved by a newer version" notice there); where it came from, for us
  719. objectOf (root)->setProperty ("savedBy", release);
  720. if (from.isNotEmpty())
  721. objectOf (root)->setProperty ("copiedFrom", from);
  722. copy.json = juce::JSON::toString (root, true);
  723. copy.ok = true;
  724. return copy;
  725. }
  726. Copy forRelease (const Song& song, const juce::String& release)
  727. {
  728. return forRelease (ProjectFile::toJson (song), release);
  729. }
  730. juce::String copyName (const juce::String& projectName, const juce::String& release)
  731. {
  732. return (projectName.isNotEmpty() ? projectName : juce::String ("Untitled")) + " (for LYNX " + release + ")";
  733. }
  734. } // namespace lynx::olderlynx