Issues190ftTests.inc 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. // Round 190ft (issues #163 / #164): FL Studio's Playlist track-header rules, core/TrackHeaderGestures.h, and FL's row
  2. // size law (core/EditorPolish.h) with its .flp field. Evidence: docs/analise/REA_rodada190ft.md.
  3. #include "core/EditorPolish.h"
  4. #include "core/FlpExport.h"
  5. #include "core/TrackHeaderGestures.h"
  6. TEST (issues190ft_header_selection_follows_fl)
  7. {
  8. using namespace lynx::trackhdr;
  9. // FUN_012e83e0's modes
  10. std::vector<int> sel { 2, 5 };
  11. applySelection (sel, 3, SelMode::only);
  12. CHECK ((sel == std::vector<int> { 3 }));
  13. applySelection (sel, 1, SelMode::toggle);
  14. applySelection (sel, 7, SelMode::toggle);
  15. CHECK ((sel == std::vector<int> { 1, 3, 7 }));
  16. applySelection (sel, 3, SelMode::toggle);
  17. CHECK ((sel == std::vector<int> { 1, 7 }));
  18. applySelection (sel, 7, SelMode::add);
  19. applySelection (sel, 4, SelMode::add);
  20. CHECK ((sel == std::vector<int> { 1, 4, 7 }));
  21. applySelection (sel, 4, SelMode::remove);
  22. applySelection (sel, 9, SelMode::remove);
  23. CHECK ((sel == std::vector<int> { 1, 7 }));
  24. // what a press does: click = alone; Ctrl = alone with its clips and a drag adds; Ctrl+Shift = add / remove (the drag
  25. // follows the result); Alt or Ctrl+Alt = alone; Shift = LYNX's range
  26. const auto plain = planPress (false, false, false);
  27. CHECK (plain.mode == SelMode::only && plain.clips == ClipPick::none && dragAfter (plain, true) == RangeDrag::none && ! plain.lynxShiftRange);
  28. // Ctrl alone: FL's press (alone + clips, range) once a drag leaves the track; a click toggles (LYNX extra, #163)
  29. const auto c = planPress (true, false, false);
  30. CHECK (c.mode == SelMode::only && c.clips == ClipPick::replace && dragAfter (c, true) == RangeDrag::select && c.ctrlClickToggles);
  31. CHECK (! planPress (true, true, false).ctrlClickToggles && ! planPress (false, false, false).ctrlClickToggles
  32. && ! planPress (true, false, true).ctrlClickToggles);
  33. // the toggle's clips follow the track
  34. const std::vector<int> clipTracks { 0, 2, 2, 1, -1, 2 };
  35. std::vector<int> clips { 3 };
  36. toggleTrackClips (clips, clipTracks, 2, true);
  37. CHECK ((clips == std::vector<int> { 3, 1, 2, 5 }));
  38. toggleTrackClips (clips, clipTracks, 2, true);
  39. CHECK ((clips == std::vector<int> { 3, 1, 2, 5 }));
  40. toggleTrackClips (clips, clipTracks, 2, false);
  41. CHECK ((clips == std::vector<int> { 3 }));
  42. const auto cs = planPress (true, true, false);
  43. CHECK (cs.mode == SelMode::toggle && cs.clips == ClipPick::add);
  44. CHECK (dragAfter (cs, true) == RangeDrag::select && dragAfter (cs, false) == RangeDrag::deselect);
  45. CHECK (planPress (false, false, true).mode == SelMode::only && planPress (true, false, true).clips == ClipPick::none);
  46. CHECK (planPress (false, true, false).lynxShiftRange);
  47. // the drag across the headers (FUN_012e8740 on every move): the range only grows
  48. std::vector<int> r { 0 };
  49. applyRange (r, 0, 3, true);
  50. CHECK ((r == std::vector<int> { 0, 1, 2, 3 }));
  51. applyRange (r, 0, 1, true); // (moving back leaves 2 and 3 selected)
  52. CHECK ((r == std::vector<int> { 0, 1, 2, 3 }));
  53. applyRange (r, 3, 2, false);
  54. CHECK ((r == std::vector<int> { 0, 1 }));
  55. }
  56. TEST (issues190ft_resize_band_and_presses)
  57. {
  58. using namespace lynx::trackhdr;
  59. // a quarter of the row, 4 … 14 px, at its bottom; none on rows of 6 px or less
  60. CHECK (resizeBand (38) == 9 && resizeBand (8) == 4 && resizeBand (200) == 14);
  61. CHECK (inResizeBand (38, 37) && inResizeBand (38, 29) && ! inResizeBand (38, 28) && ! inResizeBand (38, 38));
  62. CHECK (! inResizeBand (6, 5) && inResizeBand (16, 15) && ! inResizeBand (16, 11));
  63. // presses on the band
  64. CHECK (bandPress (false, false, false) == BandPress::resize);
  65. CHECK (bandPress (false, false, true) == BandPress::reset);
  66. CHECK (bandPress (false, true, false) == BandPress::toggleLock);
  67. CHECK (bandPress (true, false, false) == BandPress::toggleLock && bandPress (true, false, true) == BandPress::toggleLock);
  68. // FL's quick lock flip negates the locked size: never locked (−1) → 1 = the smallest row, and back
  69. CHECK (flippedLock (-1) == 1 && flippedLock (1) == -1 && flippedLock (60) == -60 && flippedLock (-60) == 60 && flippedLock (0) == 1);
  70. }
  71. TEST (issues190ft_resize_heights)
  72. {
  73. using namespace lynx;
  74. using namespace lynx::trackhdr;
  75. // FL's row limits (FUN_00ea0b30): 16 … 528 px, even
  76. CHECK (polish::minTrackHeight == 16 && polish::maxTrackHeight == 528);
  77. CHECK (draggedHeight (38, 40) == 78 && draggedHeight (38, 41) == 78 && draggedHeight (38, -100) == 16 && draggedHeight (38, 5000) == 528);
  78. // the dragged track is one of the selected ones: the distance from the first one's top shared down to it
  79. const std::vector<int> sel { 1, 2, 3 };
  80. CHECK (selectedHeight (sel, 2, 100, 200) == 50);
  81. CHECK (selectedHeight (sel, 3, 100, 250) == 50);
  82. CHECK (selectedHeight (sel, 1, 100, 160) == 60);
  83. CHECK (selectedHeight (sel, 2, 100, 132) == 0); // 16 px each: not above the smallest row, sizes stay
  84. CHECK (selectedHeight (sel, 9, 100, 150) == 50); // (a track outside the list counts as the first)
  85. // past the top of a row at its smallest
  86. CHECK (groupGesture (16, 68, 100) && ! groupGesture (16, 69, 100) && ! groupGesture (40, 0, 100));
  87. }
  88. TEST (issues190ft_fl_size_factor_law_and_flp)
  89. {
  90. using namespace lynx;
  91. // a row = 16 px + size × (default − 16): FL's Size menu on LYNX's 38 px default
  92. CHECK (polish::heightForFlSize (1.0) == 38 && polish::heightForFlSize (0.0) == 16 && polish::heightForFlSize (2.0) == 60);
  93. CHECK (polish::heightForFlSize (1.5) == 48 && polish::heightForFlSize (0.5) == 26 && polish::heightForFlSize (1.0 / 3.0) == 22);
  94. CHECK (polish::heightForFlSize (100.0) == 528 && polish::heightForFlSize (-1.0) == 38);
  95. CHECK (std::abs (polish::flSizeForHeight (60) - 2.0f) < 1.0e-6f && std::abs (polish::flSizeForHeight (16)) < 1.0e-6f
  96. && std::abs (polish::flSizeForHeight (0) - 1.0f) < 1.0e-6f);
  97. for (int h = 16; h <= 528; h += 2)
  98. CHECK (polish::heightForFlSize (polish::flSizeForHeight (h)) == h);
  99. // .flp: the f32 size at byte 13 of the 0xEE track event is written and read back with the same law (round 190gw: on the
  100. // song's default row, FL's 48 px: 200 % = 80 px)
  101. auto song = Song::makeDefault();
  102. song.playlistTracks.resize (4);
  103. song.playlistTracks[1].height = 80; // FL 200 %
  104. song.playlistTracks[2].height = 300;
  105. song.playlistTracks[3].lockedHeight = 80;
  106. flpexport::Options options;
  107. flpexport::Report report;
  108. const auto project = flp::parseProject (flpexport::exportFlp (song, options, report));
  109. float sizes[4] = { -1.0f, -1.0f, -1.0f, -1.0f };
  110. int locked3 = 0;
  111. for (const auto& a : project.arrangements)
  112. for (const auto& t : a.tracks)
  113. if (t.index >= 0 && t.index < 4)
  114. {
  115. sizes[t.index] = t.heightScale;
  116. if (t.index == 3)
  117. locked3 = t.lockedHeight;
  118. }
  119. CHECK (std::abs (sizes[0] - 1.0f) < 1.0e-6f && std::abs (sizes[1] - 2.0f) < 1.0e-6f
  120. && std::abs (sizes[2] - polish::flSizeForHeight (300, Song::flDefaultRowHeight)) < 1.0e-6f && locked3 == 80);
  121. const auto back = importFlp (project);
  122. CHECK (back.playlistTracks.size() >= 4);
  123. if (back.playlistTracks.size() >= 4)
  124. CHECK (back.playlistTracks[0].height == 0 && back.playlistTracks[1].height == 80 && back.playlistTracks[2].height == 300
  125. && back.playlistTracks[3].lockedHeight == 80);
  126. }