4
0

Issues178aTests.inc 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557
  1. // Round 178a: GitHub issues #87, #63, #86 (docs/analise/REA_rodada178a.md)
  2. #include "core/ClipOps.h"
  3. // #87: an audio clip dropped at 130 BPM, then the tempo lowered to 108: the clip kept its length in ticks while its
  4. // audio (played at the file's own speed) got shorter in bars, so the clip showed an empty tail. FL keeps such a clip's
  5. // region in milliseconds and resizes it with the tempo; a clip whose channel follows the tempo keeps its beats.
  6. TEST (issues178a_audio_clips_follow_a_tempo_change)
  7. {
  8. using namespace lynx;
  9. auto song = Song::makeDefault();
  10. song.bpm = 130.0;
  11. song.playlist.clear();
  12. song.arrangements.resize (2);
  13. song.currentArrangement = 0;
  14. ChannelDef plain;
  15. plain.instrument = InstrumentKind::audioClip;
  16. plain.samplePath = "drill.wav";
  17. ChannelDef synced = plain; // Time stretch set: the whole file lasts 16 beats, whatever the tempo
  18. synced.sampler.stretchBeats = 16.0f;
  19. song.channels.push_back (plain);
  20. const auto plainIndex = (int) song.channels.size() - 1;
  21. song.channels.push_back (synced);
  22. const auto syncedIndex = (int) song.channels.size() - 1;
  23. // a 60 s file at 44.1 kHz, as the Playlist sizes a dropped clip
  24. const double frames = 60.0 * 44100.0, rate = 44100.0;
  25. Clip whole;
  26. whole.kind = ClipKind::audio;
  27. whole.channel = plainIndex;
  28. whole.start = 4 * ppq;
  29. whole.length = clipops::fileTicks (song.channels[(std::size_t) plainIndex], frames, rate, song.bpm);
  30. CHECK (whole.length == 130 * ppq); // 60 s at 130 BPM = 130 beats
  31. Clip trimmed = whole; // a part of it: skips 10 s, plays 20 s, with fades
  32. trimmed.track = 1;
  33. trimmed.offset = (std::int64_t) (10.0 * 130.0 / 60.0 * ppq);
  34. trimmed.length = (std::int64_t) (20.0 * 130.0 / 60.0 * ppq);
  35. trimmed.fadeIn = ppq;
  36. trimmed.fadeOut = 2 * ppq;
  37. Clip stretched = whole;
  38. stretched.track = 2;
  39. stretched.channel = syncedIndex;
  40. stretched.length = 16 * ppq;
  41. Clip pattern;
  42. pattern.kind = ClipKind::pattern;
  43. pattern.track = 3;
  44. pattern.length = 8 * ppq;
  45. song.playlist = { whole, trimmed, stretched, pattern };
  46. song.arrangements[1].clips = { whole };
  47. clipops::followTempo (song, 108.0);
  48. CHECK (song.bpm == 108.0);
  49. // the whole clip ends where its audio does at the new tempo: no empty tail
  50. const auto& w = song.playlist[0];
  51. const auto audio = clipops::fileTicks (song.channels[(std::size_t) plainIndex], frames, rate, 108.0);
  52. std::printf (" whole clip at 108 BPM: %lld ticks, audio %lld ticks\n", (long long) w.length, (long long) audio);
  53. CHECK (std::llabs (w.length - audio) <= 1);
  54. CHECK (w.start == 4 * ppq); // the position stays
  55. // the trimmed clip plays the same seconds of the same file
  56. const auto& t = song.playlist[1];
  57. const auto seconds = [] (double ticks, double bpm) { return ticks / ppq * 60.0 / bpm; };
  58. CHECK (std::abs (seconds ((double) t.offset + t.offsetFraction, 108.0) - 10.0) < 1e-6);
  59. CHECK (std::abs (seconds ((double) t.length, 108.0) - 20.0) < 0.001);
  60. CHECK (std::abs (seconds ((double) t.fadeIn, 108.0) - seconds (ppq, 130.0)) < 0.001);
  61. CHECK (std::abs (seconds ((double) t.fadeOut, 108.0) - seconds (2 * ppq, 130.0)) < 0.001);
  62. // tempo-synced audio and pattern clips keep their beats
  63. CHECK (song.playlist[2].length == 16 * ppq);
  64. CHECK (song.playlist[3].length == 8 * ppq);
  65. // the stored arrangement follows too
  66. CHECK (std::llabs (song.arrangements[1].clips[0].length - audio) <= 1);
  67. // back to 130: the clips are as they were (to the tick), even after many small steps (a drag on the tempo)
  68. for (int i = 1; i <= 220; ++i)
  69. clipops::followTempo (song, 108.0 + 0.1 * i);
  70. clipops::followTempo (song, 130.0);
  71. CHECK (std::llabs (song.playlist[0].length - whole.length) <= 2);
  72. CHECK (std::llabs (song.playlist[1].offset - trimmed.offset) <= 2);
  73. CHECK (std::llabs (song.playlist[1].length - trimmed.length) <= 2);
  74. // the same tempo again changes nothing
  75. const auto before = song.playlist;
  76. clipops::followTempo (song, 130.0);
  77. CHECK (song.playlist == before);
  78. }
  79. #include "core/Arpeggiator.h"
  80. // #63 (the rest of it): the Arpeggiator played every note centred, with no fine pitch or Mod X / Y: it kept only the
  81. // held notes' keys and velocities. Each arpeggiated note now takes the expression of the held note it plays.
  82. TEST (issues178a_arpeggiator_keeps_the_note_pan)
  83. {
  84. using namespace lynx;
  85. ArpSettings s;
  86. s.direction = 1; // up
  87. s.stepBeats = 0.25f;
  88. Arpeggiator arp;
  89. const auto tps = ticksPerSample (120.0, 48000.0);
  90. std::array<NoteEvent, 2> in {};
  91. const float pans[] = { -1.0f, 0.75f };
  92. const int keys[] = { 60, 67 };
  93. for (int k = 0; k < 2; ++k)
  94. {
  95. auto& e = in[(std::size_t) k];
  96. e.type = NoteEvent::Type::on;
  97. e.channel = 0;
  98. e.key = keys[k];
  99. e.velocity = 0.8f;
  100. e.pan = pans[k];
  101. e.cents = k == 0 ? -30.0f : 40.0f;
  102. e.modX = k == 0 ? 0.1f : 0.9f;
  103. e.modY = k == 0 ? 0.2f : 0.7f;
  104. e.colour = (std::int8_t) (k + 3);
  105. }
  106. std::vector<NoteEvent> played;
  107. auto first = true;
  108. for (double tick = 0.0; tick < ppq * 2.0; tick += 512 * tps)
  109. {
  110. int out = 0;
  111. arp.process (0, first ? in.data() : nullptr, first ? 2 : 0, tick, tps, 512, s, arp.output.data(), out);
  112. first = false;
  113. for (int i = 0; i < out; ++i)
  114. if (arp.output[(std::size_t) i].type == NoteEvent::Type::on)
  115. played.push_back (arp.output[(std::size_t) i]);
  116. }
  117. CHECK (played.size() >= 6);
  118. for (const auto& e : played)
  119. {
  120. const auto k = e.key == 60 ? 0 : 1;
  121. CHECK (e.key == keys[k]);
  122. CHECK (e.pan == pans[k]);
  123. CHECK (e.cents == (k == 0 ? -30.0f : 40.0f));
  124. CHECK (e.modX == (k == 0 ? 0.1f : 0.9f) && e.modY == (k == 0 ? 0.2f : 0.7f));
  125. CHECK (e.colour == (std::int8_t) (k + 3));
  126. }
  127. // FL's Repeat 0 (the whole chord on each step) keeps each note's own pan too
  128. s.octaveRepeat = 0;
  129. arp.reset();
  130. played.clear();
  131. first = true;
  132. for (double tick = 0.0; tick < ppq; tick += 512 * tps)
  133. {
  134. int out = 0;
  135. arp.process (0, first ? in.data() : nullptr, first ? 2 : 0, tick, tps, 512, s, arp.output.data(), out);
  136. first = false;
  137. for (int i = 0; i < out; ++i)
  138. if (arp.output[(std::size_t) i].type == NoteEvent::Type::on)
  139. played.push_back (arp.output[(std::size_t) i]);
  140. }
  141. CHECK (played.size() >= 2);
  142. for (const auto& e : played)
  143. CHECK (e.pan == ((e.key % 12) == 0 ? -1.0f : 0.75f));
  144. }
  145. // #63: a note's Mod X / Mod Y on FL's native sampler voice: FL adds the note's Init.FCut / FRes ((b − 128) / 128 of its
  146. // Mod X / Y bytes, REA_rodada76 §1) to the channel's filter X / Y. So a note at Mod X 64 (0.25) on a channel at filter X
  147. // 228 sounds exactly like a centred note on a channel at filter X 100; a centred note is unchanged.
  148. TEST (issues178a_note_mod_x_moves_the_fl_voice_filter)
  149. {
  150. using namespace lynx;
  151. auto noise = std::make_shared<SampleData>();
  152. noise->sampleRate = 44100.0;
  153. std::uint32_t seed = 7;
  154. for (int i = 0; i < 22050; ++i)
  155. {
  156. seed = (seed * 1103515245u + 12345u) & 0x7fffffffu;
  157. noise->left.push_back ((float) (((double) seed / 2147483647.0 * 2.0 - 1.0) * 0.3));
  158. }
  159. const std::vector<std::int32_t> plain = { 0, 0, 100, 20000, 20000, 30000, 50, 20000, 0, 100, 20000, 0, 32950, 0, 0, 0, 0 };
  160. const std::vector<std::int32_t> vol = { 4, 0, 100, 20000, 20000, 30000, 50, 20000, 0, 100, 20000, 0, 32950, 0, 0, 0, -101 };
  161. auto render = [&] (int filterX, int filterY, std::optional<std::pair<float, float>> mod) {
  162. ChannelDef c;
  163. c.instrument = InstrumentKind::sampler;
  164. for (const auto* r : { &plain, &vol, &plain, &plain, &plain })
  165. c.sampler.flChannel.insert (c.sampler.flChannel.end(), r->begin(), r->end());
  166. c.sampler.flChannel.insert (c.sampler.flChannel.end(), { filterX, filterY, 0, 96 });
  167. auto inst = makeInstrument (InstrumentKind::sampler, noise);
  168. inst->prepare (44100.0);
  169. inst->configure (c, 120.0);
  170. inst->setSongPosition (0.0);
  171. if (mod)
  172. inst->setNextNoteModulation (mod->first, mod->second);
  173. inst->noteOn (60, 100.0f / 128.0f);
  174. std::vector<float> l (8000), r (8000);
  175. inst->render (l.data(), r.data(), 8000, 1.0f, 1.0f);
  176. return l;
  177. };
  178. const auto centred = render (100, 64, std::nullopt);
  179. CHECK (render (100, 64, std::pair { 0.5f, 0.5f }) == centred); // Mod X / Y at centre: nothing changes
  180. const auto darker = render (100, 64, std::pair { 0.25f, 0.5f });
  181. CHECK (darker != centred); // the note's Mod X moves the cutoff
  182. const auto same = render (228, 64, std::pair { 0.25f, 0.5f }); // 228/256 − 0.5 = 100/256
  183. auto diff = 0.0;
  184. for (std::size_t i = 0; i < same.size(); ++i)
  185. diff = std::max (diff, (double) std::abs (same[i] - centred[i]));
  186. std::printf (" channel X 228 + note Mod X 0.25 vs channel X 100: max diff %.3g\n", diff);
  187. CHECK (diff < 1e-6);
  188. CHECK (render (100, 64, std::pair { 0.5f, 0.9f }) != centred); // Mod Y: the resonance
  189. }
  190. #include "core/TempoMap.h"
  191. #include "core/PianoRollTools.h"
  192. #include "core/MidiImport.h"
  193. #include "core/FlpExport.h"
  194. namespace issues178a
  195. {
  196. lynx::PatternEvents tempoLane (std::initializer_list<std::pair<std::int64_t, double>> events)
  197. {
  198. lynx::PatternEvents lane;
  199. lane.target = { lynx::AutomationTargetKind::tempo, 0 };
  200. for (const auto& [tick, bpm] : events)
  201. lane.events.push_back ({ tick, lynx::valueFromTempo (bpm) });
  202. return lane;
  203. }
  204. bool near (double a, double b, double tolerance = 0.01) { return std::abs (a - b) <= tolerance; }
  205. } // namespace issues178a
  206. // #86, pattern mode: the current pattern's Tempo events, looped with it; before the first one, the project tempo.
  207. TEST (issues178a_tempo_events_in_pattern_mode)
  208. {
  209. using namespace lynx;
  210. auto song = Song::makeDefault();
  211. song.bpm = 130.0;
  212. song.mode = PlayMode::pattern;
  213. song.patterns.resize (1);
  214. song.currentPattern = 0;
  215. auto& p = song.patterns[0];
  216. CHECK (! tempomap::active (song));
  217. CHECK (song.tempoAt (ppq) == 130.0);
  218. p.events.push_back (issues178a::tempoLane ({ { ppq, 140.0 }, { 3 * ppq, 90.0 } }));
  219. const auto length = (double) p.effectiveLength (song.meter());
  220. CHECK (tempomap::active (song));
  221. CHECK (song.tempoAt (0.0) == 130.0); // before the first event
  222. CHECK (issues178a::near (song.tempoAt (ppq), 140.0));
  223. CHECK (issues178a::near (song.tempoAt (2.5 * ppq), 140.0));
  224. CHECK (issues178a::near (song.tempoAt (3 * ppq), 90.0));
  225. CHECK (issues178a::near (song.tempoAt (length + 0.5 * ppq), 90.0)); // the next loop: the last event still holds
  226. CHECK (issues178a::near (song.tempoAt (length + ppq), 140.0));
  227. // the time a beat lasts follows the events: one beat at 130, two at 140, then 90
  228. const auto seconds = song.secondsForTicks (4 * ppq);
  229. const auto expected = 60.0 / 130.0 + 2.0 * 60.0 / 140.0 + 60.0 / 90.0;
  230. std::printf (" 4 beats with tempo events: %.4f s (exact %.4f s)\n", seconds, expected);
  231. CHECK (std::abs (seconds - expected) < 0.01);
  232. // another pattern without events: the project tempo
  233. song.patterns.resize (2);
  234. song.currentPattern = 1;
  235. CHECK (! tempomap::active (song));
  236. CHECK (song.tempoAt (3 * ppq) == 130.0);
  237. }
  238. // #86, song mode (FL's time map): pattern clips play their Tempo events while the position is inside them and the last
  239. // write holds afterwards (nothing is restored); inside a tempo automation clip the clip wins; after it, its last value
  240. // holds until a later event.
  241. TEST (issues178a_tempo_events_in_song_mode)
  242. {
  243. using namespace lynx;
  244. auto song = Song::makeDefault();
  245. song.bpm = 120.0;
  246. song.mode = PlayMode::song;
  247. song.playlist.clear();
  248. song.automations.clear();
  249. song.patterns.resize (1);
  250. auto& p = song.patterns[0];
  251. p.lengthTicks = 4 * ppq;
  252. p.events.push_back (issues178a::tempoLane ({ { 0, 100.0 }, { 2 * ppq, 150.0 } }));
  253. Clip a;
  254. a.kind = ClipKind::pattern;
  255. a.pattern = 0;
  256. a.start = 8 * ppq;
  257. a.length = 4 * ppq;
  258. song.playlist.push_back (a);
  259. CHECK (tempomap::active (song));
  260. CHECK (song.tempoAt (4 * ppq) == 120.0); // before the clip
  261. CHECK (issues178a::near (song.tempoAt (8 * ppq), 100.0));
  262. CHECK (issues178a::near (song.tempoAt (11 * ppq), 150.0));
  263. CHECK (issues178a::near (song.tempoAt (40 * ppq), 150.0)); // held after the clip
  264. // a clip that starts in the middle of its pattern (offset 2 beats) plays only the events from there on
  265. Clip b = a;
  266. b.start = 20 * ppq;
  267. b.offset = 3 * ppq;
  268. b.length = ppq;
  269. b.track = 1;
  270. song.playlist.push_back (b);
  271. CHECK (issues178a::near (song.tempoAt (20.5 * ppq), 150.0)); // (the clip played no event: 150 holds)
  272. // a tempo automation clip from 16 to 24: inside it, its curve wins over the pattern clip's events
  273. Automation t;
  274. t.target = { AutomationTargetKind::tempo, 0 };
  275. t.points = { { 0, valueFromTempo (60.0) }, { 8 * ppq, valueFromTempo (60.0) } };
  276. song.automations.push_back (t);
  277. Clip c;
  278. c.kind = ClipKind::automation;
  279. c.automation = 0;
  280. c.start = 16 * ppq;
  281. c.length = 8 * ppq;
  282. c.track = 2;
  283. song.playlist.push_back (c);
  284. Clip d = a; // a pattern clip overlapping the automation clip
  285. d.start = 18 * ppq;
  286. d.track = 3;
  287. song.playlist.push_back (d);
  288. CHECK (issues178a::near (song.tempoAt (12 * ppq), 150.0));
  289. CHECK (issues178a::near (song.tempoAt (16 * ppq), 60.0));
  290. CHECK (issues178a::near (song.tempoAt (21 * ppq), 60.0)); // the automation clip wins over d's events
  291. CHECK (issues178a::near (song.tempoAt (25 * ppq), 60.0)); // after it: the value it ended with
  292. Clip e = a;
  293. e.start = 26 * ppq;
  294. e.track = 4;
  295. song.playlist.push_back (e);
  296. CHECK (issues178a::near (song.tempoAt (26 * ppq), 100.0)); // a later event writes over it
  297. CHECK (issues178a::near (song.tempoAt (2 * ppq), 60.0)); // before anything: the first tempo clip's value
  298. }
  299. // #86: FL's .flp keeps the Tempo events as BPM × 1000 (0x40000005 events) and the initialized tempo in 0xD8; both go
  300. // through LYNX's export and import unchanged.
  301. TEST (issues178a_tempo_events_survive_flp)
  302. {
  303. using namespace lynx;
  304. auto song = Song::makeDefault();
  305. song.bpm = 128.0;
  306. song.patterns.resize (1);
  307. song.patterns[0].events.push_back (issues178a::tempoLane ({ { 0, 128.0 }, { 4 * ppq, 95.5 }, { 8 * ppq, 300.0 } }));
  308. flpexport::Options options;
  309. flpexport::Report report;
  310. const auto project = flp::parseProject (flpexport::exportFlp (song, options, report));
  311. auto found = 0;
  312. for (const auto& pattern : project.patterns)
  313. for (const auto& e : pattern.controlEvents)
  314. if (e.id.raw == flp::ControlId::tempo)
  315. {
  316. ++found;
  317. CHECK (e.value == 128000 || e.value == 95500 || e.value == 300000);
  318. }
  319. CHECK (found == 3);
  320. FlpImportOptions io;
  321. io.fileExists = [] (const std::string&) { return true; };
  322. const auto back = importFlp (project, io);
  323. const PatternEvents* lane = nullptr;
  324. for (const auto& p : back.patterns)
  325. if (const auto* l = tempomap::tempoLane (p))
  326. lane = l;
  327. CHECK (lane != nullptr);
  328. if (lane != nullptr)
  329. {
  330. CHECK (lane->events.size() == 3);
  331. if (lane->events.size() == 3)
  332. {
  333. CHECK (lane->events[1].tick == 4 * ppq);
  334. CHECK (issues178a::near (tempoFromValue (lane->events[0].value), 128.0, 0.001));
  335. CHECK (issues178a::near (tempoFromValue (lane->events[1].value), 95.5, 0.001));
  336. CHECK (issues178a::near (tempoFromValue (lane->events[2].value), 300.0, 0.001));
  337. }
  338. }
  339. }
  340. // #86: FL's MIDI import writes every Set Tempo as a Tempo event of the new pattern, a whole BPM rounded half to even
  341. // (10..522); the realign moves them with the notes. LYNX used to keep only the first tempo, and a file starting at
  342. // exactly 120 BPM took its second one.
  343. TEST (issues178a_midi_tempos_become_tempo_events)
  344. {
  345. using namespace lynx;
  346. CHECK (midiimport::midiTempoBpm (60.0 / 120.0) == 120.0);
  347. CHECK (midiimport::midiTempoBpm (60.0 / 120.5) == 120.0); // half to even
  348. CHECK (midiimport::midiTempoBpm (60.0 / 121.5) == 122.0);
  349. CHECK (midiimport::midiTempoBpm (60.0 / 99.7) == 100.0);
  350. CHECK (midiimport::midiTempoBpm (60.0 / 4.0) == 10.0); // FL's range
  351. CHECK (midiimport::midiTempoBpm (60.0 / 900.0) == 522.0);
  352. Pattern p;
  353. p.events.push_back (issues178a::tempoLane ({ { 0, 77.0 } })); // the pattern's old Tempo events are replaced
  354. PatternEvents vol;
  355. vol.target = { AutomationTargetKind::channelVolume, 0 };
  356. vol.events.push_back ({ 0, 0.5f });
  357. p.events.push_back (vol);
  358. const std::vector<PatternEvent> tempos = { { 0, valueFromTempo (120.0) }, { 2 * ppq, valueFromTempo (140.0) },
  359. { 2 * ppq, valueFromTempo (141.0) }, { 6 * ppq, valueFromTempo (90.0) } };
  360. midiimport::setTempoEvents (p, tempos, ppq);
  361. CHECK (p.events.size() == 2);
  362. const auto* lane = tempomap::tempoLane (p);
  363. CHECK (lane != nullptr);
  364. if (lane != nullptr)
  365. {
  366. CHECK (lane->events.size() == 3); // one per tick: the last one of a tick wins
  367. if (lane->events.size() == 3)
  368. {
  369. CHECK (lane->events[0].tick == 0 && issues178a::near (tempoFromValue (lane->events[0].value), 120.0));
  370. CHECK (lane->events[1].tick == ppq && issues178a::near (tempoFromValue (lane->events[1].value), 141.0));
  371. CHECK (lane->events[2].tick == 5 * ppq);
  372. }
  373. }
  374. midiimport::setTempoEvents (p, {}, 0);
  375. CHECK (tempomap::tempoLane (p) == nullptr && p.events.size() == 1);
  376. }
  377. // #86: FL's event score (.fsc of format 0x18): the Event editor's Save automation as / Open automation.
  378. TEST (issues178a_event_score_round_trip)
  379. {
  380. using namespace lynx;
  381. const std::vector<PatternEvent> events = { { 0, valueFromTempo (140.0) }, { ppq / 2, 0.25f }, { 7 * ppq, 1.0f } };
  382. const auto bytes = prtools::writeEventScore (events);
  383. CHECK (bytes.size() > 22 && bytes[0] == 'F' && bytes[8] == 0x18);
  384. const auto back = prtools::parseEventScore (bytes);
  385. CHECK (back.has_value());
  386. if (back)
  387. CHECK (*back == events);
  388. // a note score is not an event score
  389. std::vector<Note> notes (1);
  390. notes[0].key = 60;
  391. notes[0].length = ppq;
  392. CHECK (! prtools::parseEventScore (prtools::writeScore (notes)).has_value());
  393. CHECK (! prtools::parseEventScore (std::vector<std::uint8_t> { 1, 2, 3 }).has_value());
  394. }
  395. // #86: the head and last record of a real "Save automation as" from FL 2026.1.7 (a Tempo lane, records' control = 5)
  396. TEST (issues178a_event_score_from_real_fl_file)
  397. {
  398. using namespace lynx;
  399. const std::vector<std::uint8_t> file = {
  400. 0x46, 0x4c, 0x68, 0x64, 0x06, 0x00, 0x00, 0x00, 0x18, 0x00, 0x21, 0x00, 0x60, 0x00, 0x46, 0x4c, 0x64, 0x74, 0x81, 0x00,
  401. 0x00, 0x00, 0xc7, 0x0c, 0x32, 0x36, 0x2e, 0x31, 0x2e, 0x37, 0x2e, 0x35, 0x36, 0x35, 0x34, 0x00, 0x9f, 0x16, 0x16, 0x00,
  402. 0x00, 0xa9, 0x0f, 0x00, 0x00, 0x00, 0x1c, 0x01, 0xac, 0x01, 0x01, 0x00, 0xc0, 0x36, 0x46, 0x00, 0x4c, 0x00, 0x20, 0x00,
  403. 0x53, 0x00, 0x74, 0x00, 0x75, 0x00, 0x64, 0x00, 0x69, 0x00, 0x6f, 0x00, 0x20, 0x00, 0x32, 0x00, 0x36, 0x00, 0x2e, 0x00,
  404. 0x31, 0x00, 0x2e, 0x00, 0x37, 0x00, 0x2e, 0x00, 0x35, 0x00, 0x36, 0x00, 0x35, 0x00, 0x34, 0x00, 0x2e, 0x00, 0x35, 0x00,
  405. 0x36, 0x00, 0x35, 0x00, 0x34, 0x00, 0x00, 0x00, 0x25, 0x01, 0x41, 0x00, 0x00, 0xdf, 0x24, 0x25, 0x00, 0x00, 0x00, 0x05,
  406. 0x00, 0x00, 0x00, 0x27, 0x31, 0x44, 0x3d, 0x26, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x0e, 0x2d, 0x45, 0x3d, 0x2b,
  407. 0x01, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0xa0, 0x9a, 0xe2, 0x3d
  408. };
  409. const auto events = prtools::parseEventScore (file);
  410. CHECK (events.has_value());
  411. if (! events)
  412. return;
  413. CHECK (events->size() == 3);
  414. CHECK ((*events)[0].tick == (std::int64_t) std::llround (37.0 * ppq / 96.0));
  415. CHECK ((*events)[2].tick == (std::int64_t) std::llround (299.0 * ppq / 96.0));
  416. CHECK (std::abs (tempoFromValue ((*events)[2].value) - 66.651) < 0.01); // FL's hint bar showed 66.651 BPM for it
  417. // what we write for Tempo carries the same control number
  418. const auto written = prtools::writeEventScore (*events, 5);
  419. CHECK (written[written.size() - 8] == 5);
  420. CHECK (prtools::parseEventScore (written) == events);
  421. }
  422. TEST (issues178a_event_lane_takes_the_chosen_controller)
  423. {
  424. using namespace lynx;
  425. // the file FL imported in the Event editor (REA_rodada178a §11): C notes with CC 1 at 5, 21, ... each beat
  426. midiimport::ParsedMidi midi;
  427. midi.trackNames = { "", "other" };
  428. const std::int64_t beat = ppq;
  429. for (int i = 0; i < 8; ++i)
  430. {
  431. midi.events.push_back ({ 0, beat * i + beat, 0x90, (std::uint8_t) (48 + i), 100 });
  432. midi.events.push_back ({ 0, beat * i + beat, 0xB0, 1, (std::uint8_t) (i * 16 + 5) });
  433. }
  434. midi.events.push_back ({ 1, 0, 0xB1, 1, 127 }); // another track and MIDI channel
  435. midi.events.push_back ({ 0, 0, 0xB0, 7, 64 }); // another controller
  436. midiimport::Options o;
  437. CHECK (midiimport::controllerEvents (midi, o).size() == 10); // FL's "---": every controller, merged
  438. CHECK (midiimport::controllerEvents (midi, o)[0].tick == 0);
  439. o.controller = 1;
  440. o.track = 0;
  441. auto lane = midiimport::controllerEvents (midi, o);
  442. CHECK (lane.size() == 8);
  443. CHECK (lane[0].tick == beat && std::fabs (lane[0].value - 5.0f / 127.0f) < 1.0e-6f); // FL's .fsc: 0.03937
  444. CHECK (lane[1].tick == 2 * beat && std::fabs (lane[1].value - 21.0f / 127.0f) < 1.0e-6f); // FL's .fsc: 0.16535
  445. o.realign = true;
  446. CHECK (midiimport::controllerEvents (midi, o)[0].tick == 0); // the silence before the first note goes
  447. o.realign = false;
  448. o.track = -1;
  449. o.channels = 2; // MIDI channel 2 alone
  450. lane = midiimport::controllerEvents (midi, o);
  451. CHECK (lane.size() == 1 && lane[0].tick == 0 && lane[0].value == 1.0f);
  452. o.controller = 74;
  453. CHECK (midiimport::controllerEvents (midi, o).empty()); // FL then empties the lane
  454. }
  455. #include "core/BrowserView.h"
  456. // FL's Browser shows one "Scores" root for Data\Patches\Scores and the user's Presets\Scores: a folder in both is one
  457. // folder (its other copies merged in turn), a file in both takes the first folder's, case doesn't matter.
  458. TEST (issues178a_merged_roots_list_the_union_of_their_folders)
  459. {
  460. using namespace lynx;
  461. browserview::Listing user, data;
  462. user.folders = { "Automation" };
  463. user.files = { "Mine.fsc", "Randomness.fsc" };
  464. data.folders = { "Arpeggiator", "automation", "Chopping" };
  465. data.files = { "4 steps.fsc", "randomness.FSC" };
  466. const auto m = browserview::mergeListings ({ user, data });
  467. CHECK (m.folders.size() == 3);
  468. CHECK (m.folders[0].name == "Automation" && m.folders[0].from == 0);
  469. CHECK (m.folders[0].also == std::vector<int> { 1 });
  470. CHECK (m.folders[1].name == "Arpeggiator" && m.folders[1].from == 1 && m.folders[1].also.empty());
  471. CHECK (m.folders[2].name == "Chopping" && m.folders[2].from == 1);
  472. CHECK (m.files.size() == 3);
  473. CHECK (m.files[1].name == "Randomness.fsc" && m.files[1].from == 0 && m.files[1].also.empty());
  474. CHECK (m.files[2].name == "4 steps.fsc" && m.files[2].from == 1);
  475. // one folder alone lists as it is; none lists nothing
  476. CHECK (browserview::mergeListings ({ data }).folders.size() == 3);
  477. CHECK (browserview::mergeListings ({}).files.empty());
  478. }
  479. // Settings from before the merged roots. A user who hid "FL MIDI" (Data\Patches\Scores) or "Mixer presets (FL)" keeps
  480. // the merged root, without that folder (excluded, saved with the view); one who hid their own folder (the merged
  481. // root's first) still doesn't see the root.
  482. TEST (issues178a_merged_roots_keep_a_hidden_old_root_hidden)
  483. {
  484. using namespace lynx;
  485. const std::string user = "C:/Users/u/Documents/Image-Line/FL Studio/Presets/Mixer presets";
  486. const std::string data = "C:/Program Files/Image-Line/FL Studio 2026/Data/Patches/Mixer presets";
  487. browserview::View v; // hid FL's copy: the root stays, FL's folder is left out
  488. v.setShown (data, false);
  489. CHECK (browserview::migrateMergedRoot (v, user, { data }));
  490. CHECK (v.shows (user) && v.hidden.count (data) == 0 && v.excluded.count (data) == 1);
  491. CHECK (! browserview::migrateMergedRoot (v, user, { data })); // the next start: nothing more to do
  492. CHECK (browserview::View::fromText (v.toText()) == v); // saved with the view
  493. browserview::View own; // hid their own folder: the merged root (the same id) stays hidden, FL's isn't left out
  494. own.setShown (user, false);
  495. CHECK (! browserview::migrateMergedRoot (own, user, { data }));
  496. CHECK (! own.shows (user) && own.excluded.empty());
  497. browserview::View untouched; // nothing hidden: nothing changes
  498. CHECK (! browserview::migrateMergedRoot (untouched, user, { data }) && untouched.hidden.empty());
  499. // FL not installed or no user folder: the root is the one folder there is, nothing merged
  500. browserview::View alone;
  501. alone.setShown (data, false);
  502. CHECK (! browserview::migrateMergedRoot (alone, data, {}) && ! alone.shows (data));
  503. }