FlmNotes190abTests.inc 5.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // Round 190ab (#88): the .flm note bytes beyond the velocity — pan, drum pitch, repeat, slide — as FLM plays them.
  2. TEST (flm190ab_note_pan_pitch_repeat_slide)
  3. {
  4. using namespace lynx;
  5. namespace t = flm182c;
  6. t::Bytes f;
  7. t::tag (f, "10LF");
  8. using E = t::Ev;
  9. const auto bytes = t::cat ({ f, t::head ("Notes", 120.0), t::rack (flm::kindMaster, {}),
  10. t::rack (flm::kindNormal, { t::module (0, 2, {}, "Default/Default", 0, 127, 44, true) }),
  11. t::rack (flm::kindNormal, {}, { t::sample ("Kick", "@R@", "Drum Samples\\Kick\\Kick 1.wav") }),
  12. t::channel (flm::kindMaster, "MASTER", 0, {}),
  13. t::channel (flm::kindNormal, "Lead", 1, { t::lane (0, "Lead", { t::clip (0, 4, 4, 0, 1, {
  14. E { 0, 2, 60 }, // the held note
  15. E { 1, 0.5, 67, 204, 127, 0x7FFF, 0, 1 }, // a slide inside it
  16. E { 3, 0.5, 64, 204, 127, 0x7FFF, 0, 1 }, // a slide with nothing held: FLM plays nothing
  17. E { 2.25, 0.5, 62, 204, 255, 0x4000, 2 }, // hard right, 2 repeats, a pitch word note lanes ignore
  18. E { 3.5, 0.25, 65, 204, 0, 0x7FFF, -1 } }) }) }), // hard left; a negative repeat is none
  19. t::channel (flm::kindNormal, "Drums", 2, { t::lane (3, "Drums", { t::clip (0, 4, 4, 0, 1, {
  20. E { 0.25, 0.1249, 0, 255, 57, 0x7FFF, 1 }, // an odd step with 1 repeat, panned left
  21. E { 0.5, 0.1249, 0, 255, 127, 0x7FFF, 1 }, // an even step with 1 repeat
  22. E { 1, 0.1249, 0, 255, 127, 65534 }, // an octave up
  23. E { 1.5, 0.1249, 0, 255, 127, 0 }, // an octave down
  24. E { 2, 0.1249, 0, 255, 127, 35000 }, // 0.818 semitones up
  25. E { 3, 0.1249, 0, 255, 127, 0x7FFF, 0, 1 } }) }, -1, -1, 0.263) }) }); // drum lanes do not slide
  26. std::string error;
  27. const auto parsed = flm::parse ({ bytes.data(), bytes.size() }, &error);
  28. CHECK (parsed.has_value());
  29. if (parsed)
  30. {
  31. const flm::Lane* drums = nullptr;
  32. for (const auto& c : parsed->channels)
  33. for (const auto& l : c.lanes)
  34. if (l.kind() == flm::LaneKind::drums)
  35. drums = &l;
  36. CHECK (drums != nullptr && drums->swing == 0.263 && drums->clips.size() == 1 && drums->clips[0].events[0].repeat == 1
  37. && drums->clips[0].events[0].pan == 57 && drums->clips[0].events[5].slide == 1);
  38. }
  39. FlpImportReport report;
  40. const auto song = importFlm (bytes, t::options (&report));
  41. CHECK (song.has_value());
  42. if (! song)
  43. return;
  44. CHECK (song->panTriangular); // FLM pans by balance
  45. const auto at = [] (int flmTick) { return (std::int64_t) std::llround ((double) flmTick / 128.0 * ppq); };
  46. const auto notesOf = [&] (const char* name) {
  47. std::vector<Note> out;
  48. const auto* c = t::channelNamed (*song, name);
  49. const auto index = c == nullptr ? -1 : (int) (c - song->channels.data());
  50. for (const auto& p : song->patterns)
  51. for (const auto& n : p.notes)
  52. if (n.channel == index)
  53. out.push_back (n);
  54. std::sort (out.begin(), out.end(), [] (const Note& a, const Note& b) { return a.start < b.start; });
  55. return out;
  56. };
  57. const auto lead = notesOf ("Lead");
  58. CHECK (lead.size() == 6);
  59. if (lead.size() == 6)
  60. {
  61. CHECK (lead[0].key == 60 && ! lead[0].slide && lead[0].pan == 0.0f && lead[0].finePitch == 0.0f);
  62. CHECK (lead[1].key == 67 && lead[1].slide && lead[1].start == at (128) && lead[1].length == at (64));
  63. // 2 repeats on an odd step, no swing: thirds of a 1/16, in FLM's own ticks (truncated): 288, 298, 309
  64. CHECK (lead[2].key == 62 && lead[2].start == at (288) && lead[2].pan == 1.0f && lead[2].finePitch == 0.0f && ! lead[2].slide);
  65. CHECK (lead[3].key == 62 && lead[3].start == at (298) && lead[3].pan == 1.0f && lead[3].velocity == lead[2].velocity);
  66. CHECK (lead[4].key == 62 && lead[4].start == at (309));
  67. // one note-off for all of them, at the note's end
  68. CHECK (lead[3].start + lead[3].length == lead[2].start + lead[2].length && lead[4].start + lead[4].length == lead[2].start + lead[2].length);
  69. CHECK (lead[5].key == 65 && lead[5].pan == -1.0f);
  70. }
  71. const auto drums = notesOf ("Kick");
  72. CHECK (drums.size() == 8);
  73. if (drums.size() == 8)
  74. {
  75. // odd step: the 1/16 is 1/4 − 0.263 / 8 of a beat, the hit half-way: tick (int) (32 + 13.896) = 45
  76. CHECK (drums[0].start == at (32) && drums[1].start == at (45) && std::abs (drums[0].pan - (114.0f - 255.0f) / 255.0f) < 1e-6f
  77. && drums[1].pan == drums[0].pan && drums[1].length == drums[0].length && drums[0].key == 60);
  78. // even step: 1/4 + 0.263 / 8, half-way: tick (int) (64 + 18.104) = 82
  79. CHECK (drums[2].start == at (64) && drums[3].start == at (82) && drums[2].pan == 0.0f);
  80. CHECK (drums[4].key == 72 && drums[4].finePitch == 0.0f && drums[5].key == 48 && drums[5].finePitch == 0.0f);
  81. CHECK (drums[6].key == 61 && std::abs (drums[6].finePitch - (float) (100.0 * (12.0 * (2.0 * 35000.0 / 65534.0 - 1.0) - 1.0))) < 1e-3f);
  82. CHECK (drums[7].start == at (384) && ! drums[7].slide && drums[7].key == 60);
  83. }
  84. CHECK (report.converted["FL Studio Mobile: slide note"] == 1 && report.converted["FL Studio Mobile: note repeat (extra hits)"] == 4
  85. && report.converted["FL Studio Mobile: drum note pitch"] == 3 && report.converted["FL Studio Mobile: note pan"] == 3
  86. && report.notReproduced["FL Studio Mobile: slide note without a held note (FLM plays nothing)"] == 1);
  87. }