4
0

PrShot190jv.inc 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. // --prshot190jv <folder> (round 190jv, helper "pr", coverage pianoroll-0183): FL's Piano roll View › Scale
  2. // highlighting › Automatic drawn offscreen — the View menu with its Scale highlighting submenu, and the Piano roll
  3. // with the same A minor line under "No scale" (the black-key rows) and under Automatic (FL's rule: the rows out of the
  4. // guessed key dark, here A minor = A B C D E F G#), Automatic on two notes (no guess: no dark row), and Automatic
  5. // with three notes of a D major triad selected (only those count). Each Piano roll picture at 1x and at 150 %
  6. // ("@150"); the menus at the shot scale (run again with "--shot-scale 1.5 --shot-suffix @150" for them at 150 %).
  7. // Then FL's arpeggiator tool (prtools-0003): the Arpeggiate dialog and FL's Default pattern previewed on a chord.
  8. // <folder>/checks.txt lists what was checked. Included in the app class of Main.cpp.
  9. bool runPrShot190jv (const juce::File& folder)
  10. {
  11. using namespace lynx;
  12. juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  13. folder.createDirectory();
  14. juce::StringArray report;
  15. bool allOk = true;
  16. const auto check = [&report, &allOk] (const char* name, bool ok, const juce::String& detail = {}) {
  17. report.add (juce::String (name) + "=" + (ok ? "OK" : "FAIL") + (detail.isEmpty() ? juce::String() : " " + detail));
  18. allOk = allOk && ok;
  19. };
  20. const auto writeImage = [&] (const juce::Image& image, const juce::File& f, const juce::String& name) {
  21. f.deleteFile();
  22. bool ok = false;
  23. if (auto out = f.createOutputStream())
  24. ok = juce::PNGImageFormat().writeImageToStream (image, *out);
  25. check (name.toRawUTF8(), ok && image.getWidth() > 0);
  26. };
  27. // 1x (or the asked shot scale) and, without an asked scale, 150 % beside it
  28. const auto shoot = [&] (juce::Component& c, const juce::String& name) {
  29. writeImage (shot::snapshot (c), shot::file (folder.getChildFile (name + ".png")), name);
  30. if (! shot::given())
  31. writeImage (c.createComponentSnapshot (c.getLocalBounds(), true, 1.5f), folder.getChildFile (name + "@150.png"), name + "@150");
  32. };
  33. // one channel (the Synth, 4) with an A minor line: A C E A B D E G# A over two bars
  34. AudioEngine engine (false);
  35. auto song = Song::makeDefault();
  36. song.currentPattern = 0;
  37. auto& p = song.patterns.front();
  38. p.notes.clear();
  39. std::int64_t start = 0;
  40. for (const auto key : { 57, 60, 64, 69, 59, 62, 64, 68, 69 })
  41. {
  42. Note n;
  43. n.channel = 4;
  44. n.start = start;
  45. n.length = 2 * ticksPerStep;
  46. n.key = key;
  47. p.notes.push_back (n);
  48. start += 2 * ticksPerStep;
  49. }
  50. engine.setSong (std::move (song));
  51. engine.setSelectedChannel (4);
  52. engine.dispatchPendingMessages();
  53. PianoRollComponent roll (engine);
  54. roll.setBounds (0, 0, 1100, 620);
  55. roll.setVisible (true);
  56. roll.scrollToNotes (true);
  57. engine.dispatchPendingMessages();
  58. // 1. the menus: View with its new submenu, and the submenu (FL's DFM order, then LYNX's scales)
  59. {
  60. const auto view = roll.getViewMenuForSnapshot();
  61. bool listed = false;
  62. for (juce::PopupMenu::MenuItemIterator it (view); it.next();)
  63. listed = listed || it.getItem().text == tr ("Scale highlighting");
  64. check ("view_menu_lists_scale_highlighting", listed);
  65. const auto sub = roll.getScaleHighlightMenuForSnapshot();
  66. juce::StringArray items;
  67. for (juce::PopupMenu::MenuItemIterator it (sub); it.next();)
  68. items.add (it.getItem().isSeparator ? juce::String ("-") : it.getItem().text.upToFirstOccurrenceOf ("\t", false, false));
  69. const auto automatic = items.indexOf (tr ("Automatic"));
  70. check ("submenu_automatic_after_no_scale", automatic > 0 && items[automatic - 1] == tr ("No scale"), items.joinIntoString (" | "));
  71. saveMenus (juce::StringArray { tr ("View"), tr ("Scale highlighting") }, std::vector<juce::PopupMenu> { view, sub },
  72. shot::fileName (folder.getChildFile ("pr190jv-01-view-scale-highlighting.png").getFullPathName()));
  73. }
  74. // 2. "No scale": LYNX's black-key rows (FL's Black notes)
  75. roll.setScaleForSnapshot (0, 0);
  76. shoot (roll, "pr190jv-02-no-scale");
  77. // 3. Automatic: A minor guessed, its rows light and the others dark
  78. roll.setAutoScale (true);
  79. const auto guessed = roll.autoScaleKeyForTests();
  80. check ("automatic_guesses_a_minor", guessed == 21, juce::String (guessed));
  81. roll.repaint();
  82. shoot (roll, "pr190jv-03-automatic-a-minor");
  83. // 4. Automatic with three D major notes selected among them: only the selection counts
  84. {
  85. engine.editSong ([] (Song& s) {
  86. for (const auto key : { 62, 66, 69 })
  87. {
  88. Note n;
  89. n.channel = 4;
  90. n.start = 20 * ticksPerStep;
  91. n.length = 4 * ticksPerStep;
  92. n.key = key;
  93. s.patterns.front().notes.push_back (n);
  94. }
  95. s.patterns.front().sortNotes();
  96. });
  97. engine.dispatchPendingMessages();
  98. std::vector<int> triad;
  99. const auto& notes = engine.getSong().patterns.front().notes;
  100. for (int i = 0; i < (int) notes.size(); ++i)
  101. if (notes[(std::size_t) i].start == 20 * ticksPerStep)
  102. triad.push_back (i);
  103. roll.selectMidiToolResult (triad);
  104. const auto selected = roll.autoScaleKeyForTests();
  105. check ("automatic_selection_d_major", triad.size() == 3 && selected == 2, juce::String (selected));
  106. roll.repaint();
  107. shoot (roll, "pr190jv-04-automatic-selection-d-major");
  108. roll.selectMidiToolResult ({});
  109. check ("automatic_back_to_all_notes", roll.autoScaleKeyForTests() >= 0);
  110. }
  111. // 5. Automatic on two notes: no guess, no dark row (FL: fewer than 3 notes)
  112. {
  113. engine.editSong ([] (Song& s) {
  114. auto& n = s.patterns.front().notes;
  115. n.resize (2);
  116. });
  117. engine.dispatchPendingMessages();
  118. check ("automatic_two_notes_no_guess", roll.autoScaleKeyForTests() == -1);
  119. roll.repaint();
  120. shoot (roll, "pr190jv-05-automatic-two-notes");
  121. }
  122. roll.setAutoScale (false);
  123. check ("automatic_off", ! roll.isAutoScaleForTests());
  124. // 6. coverage prtools-0003, FL's arpeggiator tool: the Arpeggiate dialog with its FL section (pattern None:
  125. // LYNX's arpeggiator), then FL's Default pattern (the user's FL install, read only) previewed on a C E G
  126. // chord of one bar: C E G C E G … every sixteenth (core/FlArpeggiator.h)
  127. {
  128. engine.editSong ([] (Song& s) {
  129. auto& n = s.patterns.front().notes;
  130. n.clear();
  131. for (const auto key : { 60, 64, 67 })
  132. {
  133. Note c;
  134. c.channel = 4;
  135. c.start = 0;
  136. c.length = 16 * ticksPerStep;
  137. c.key = key;
  138. n.push_back (c);
  139. }
  140. s.patterns.front().sortNotes();
  141. });
  142. engine.dispatchPendingMessages();
  143. roll.scrollToNotes (true);
  144. shoot (roll, "pr190jv-06-arp-chord");
  145. auto panel = makeNoteToolPanel (engine, NoteTool::arpeggiate, { 0, 1, 2 }, ticksPerStep);
  146. panel->setVisible (true);
  147. shoot (*panel, "pr190jv-07-arp-dialog");
  148. const auto chosen = noteToolChooseForSnapshot (*panel, tr ("Pattern"), "Default");
  149. check ("arp_fl_pattern_listed", chosen, chosen ? juce::String() : juce::String ("no FL install: Data/Patches/Scores/Arpeggiator"));
  150. if (chosen)
  151. {
  152. engine.dispatchPendingMessages();
  153. const auto& notes = engine.getSong().patterns.front().notes;
  154. auto order = true;
  155. for (int i = 0; i < (int) notes.size() && order; ++i)
  156. order = notes[(std::size_t) i].start == i * ticksPerStep && notes[(std::size_t) i].key == (i % 3 == 0 ? 60 : i % 3 == 1 ? 64 : 67);
  157. check ("arp_default_c_e_g_sixteenths", notes.size() == 16 && order, juce::String ((int) notes.size()));
  158. shoot (*panel, "pr190jv-08-arp-dialog-default");
  159. roll.repaint();
  160. shoot (roll, "pr190jv-09-arp-default-result");
  161. }
  162. panel.reset(); // (not accepted: the chord comes back)
  163. engine.dispatchPendingMessages();
  164. check ("arp_cancel_restores", engine.getSong().patterns.front().notes.size() == 3);
  165. }
  166. folder.getChildFile (shot::fileName ("checks.txt")).replaceWithText (report.joinIntoString ("\n") + "\n");
  167. return allOk;
  168. }