IssuesShot190qr.inc 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. // --issuesshot190qr <prefix> (round 190qr, issues #274-#281): the pictures for the FL | LYNX check — the marker's menu
  2. // on its name (#281), the Channel rack at 3/4, 6/4 and 7/8 (#279), the Playlist at FL's deepest zoom with the samples
  3. // drawn and one step out, the Piano roll at its deepest zoom (#277), and the clip gain handle in view (#274, LYNX
  4. // extra on). @150: LYNX_SHOT_SCALE=1.5 and LYNX_SHOT_SUFFIX=@150. Included in the app class of Main.cpp.
  5. bool runIssuesShot190qr (const juce::String& prefix)
  6. {
  7. juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
  8. using namespace lynx;
  9. const juce::ScopedValueSetter<bool> shown (ui::showingForShots(), true);
  10. ui::motion::enabled() = false;
  11. const auto bar = (std::int64_t) 4 * ppq;
  12. const auto wav = juce::File::getSpecialLocation (juce::File::tempDirectory).getChildFile ("lynx-issuesshot190qr.wav");
  13. {
  14. // a plucked tone with a click at 1 s (a cut point): something to see sample by sample
  15. wav.deleteFile();
  16. juce::WavAudioFormat format;
  17. std::unique_ptr<juce::AudioFormatWriter> writer (format.createWriterFor (new juce::FileOutputStream (wav), 48000.0, 2, 24, {}, 0));
  18. juce::AudioBuffer<float> buffer (2, 48000 * 12);
  19. for (int i = 0; i < buffer.getNumSamples(); ++i)
  20. {
  21. const auto t = (float) i / 48000.0f, local = std::fmod (t, 0.5f);
  22. const auto v = 0.6f * std::exp (-local * 6.0f) * (std::sin (2.0f * juce::MathConstants<float>::pi * 220.0f * t) + 0.3f * std::sin (2.0f * juce::MathConstants<float>::pi * 1330.0f * t));
  23. buffer.setSample (0, i, v);
  24. buffer.setSample (1, i, v * 0.8f);
  25. }
  26. if (writer != nullptr)
  27. writer->writeFromAudioSampleBuffer (buffer, 0, buffer.getNumSamples());
  28. }
  29. auto song = Song::makeDefault();
  30. song.mode = PlayMode::song;
  31. song.bpm = 120.0;
  32. {
  33. Marker m;
  34. m.tick = 2 * bar;
  35. m.name = "Verse";
  36. song.addMarker (m);
  37. ChannelDef audio;
  38. audio.name = "Pluck";
  39. audio.instrument = InstrumentKind::audioClip;
  40. audio.samplePath = wav.getFullPathName().toStdString();
  41. song.channels.push_back (audio);
  42. Clip c;
  43. c.kind = ClipKind::audio;
  44. c.channel = (int) song.channels.size() - 1;
  45. c.track = 0;
  46. c.start = bar;
  47. c.length = 6 * bar;
  48. song.playlist.push_back (c);
  49. }
  50. AudioEngine offline (false);
  51. offline.setSong (song);
  52. MainComponent mainUi (offline, false);
  53. mainUi.setSize (1600, 900);
  54. offline.dispatchPendingMessages();
  55. auto& pl = mainUi.getPlaylistForSnapshot();
  56. pl.setSize (1400, 420);
  57. offline.getSampleLibrary().load (wav.getFullPathName()); // (as the rack holds it while the song plays)
  58. // #281: the ruler around the marker, and the menu a right-click on its name opens
  59. pl.setViewForSnapshot (96.0, 0, 0);
  60. savePng (shot::snapshot (pl, juce::Rectangle<int> (0, 0, 900, 140)), prefix + "-281-playlist-marker.png");
  61. const auto markerX = (int) std::lround (pl.xOfTickForSnapshot ((double) (2 * bar)));
  62. saveMenus (juce::StringArray { "Verse" }, std::vector<juce::PopupMenu> { pl.rulerMenu (markerX + 14, pl.markerTagYForSnapshot()) }, prefix + "-281-marker-menu.png");
  63. // #279: the rack at three time signatures
  64. auto& rack = mainUi.getRackForSnapshot();
  65. for (const auto [b, u] : { std::pair { 3, 4 }, { 6, 4 }, { 7, 8 } })
  66. {
  67. offline.editSong ([b = b, u = u] (Song& s) {
  68. s.beatsPerBar = b;
  69. s.beatUnit = u;
  70. s.activePattern().lengthTicks = 0;
  71. s.activePattern().notes.clear();
  72. });
  73. offline.dispatchPendingMessages();
  74. rack.setSize (900, 300);
  75. savePng (shot::snapshot (rack), prefix + "-279-rack-" + juce::String (b) + "-" + juce::String (u) + ".png");
  76. }
  77. offline.editSong ([] (Song& s) {
  78. s.beatsPerBar = 4;
  79. s.beatUnit = 4;
  80. });
  81. offline.dispatchPendingMessages();
  82. // #277: the deepest zoom (8 px a tick) at the 1 s cut point, and one notch of 16 out
  83. for (const auto [ppt, name] : { std::pair { maxPixelsPerTick, "deepest" }, { maxPixelsPerTick / 16.0, "16x-out" } })
  84. {
  85. pl.setViewForSnapshot (ppt * (double) bar, 0, 0);
  86. const auto width = (double) (pl.getWidth() - pl.headerWidthForSnapshot());
  87. pl.setScrollTickForSnapshot ((double) (bar + 2 * ppq) - width / ppt / 2.0); // (1 s after the clip's start at 120 BPM)
  88. savePng (shot::snapshot (pl), prefix + "-277-playlist-" + juce::String (name) + ".png");
  89. }
  90. auto& roll = mainUi.getPianoRollForSnapshot();
  91. roll.setSize (1200, 420);
  92. juce::MouseWheelDetails up {};
  93. up.deltaY = 1.0f;
  94. for (int i = 0; i < 80; ++i)
  95. {
  96. auto source = juce::Desktop::getInstance().getMainMouseSource();
  97. const auto now = juce::Time::getCurrentTime();
  98. const juce::Point<float> at (400.0f, 200.0f);
  99. roll.mouseWheelMove (juce::MouseEvent (source, at, juce::ModifierKeys (juce::ModifierKeys::ctrlModifier), 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, &roll, &roll, now, at, now, 1, false), up);
  100. }
  101. savePng (shot::snapshot (roll), prefix + "-277-pianoroll-deepest.png");
  102. // #274: zoomed in on the clip's first bar and a half, its middle out of view; the handle with the extra off / on
  103. const auto before = cliphandle::gainFollowsView();
  104. int audioClip = 0;
  105. for (int i = 0; i < (int) offline.getSong().playlist.size(); ++i)
  106. if (offline.getSong().playlist[(std::size_t) i].kind == ClipKind::audio)
  107. audioClip = i;
  108. pl.setViewForSnapshot (1600.0, 0, 0);
  109. pl.setScrollTickForSnapshot ((double) bar + 1.5 * (double) bar - (double) (pl.getWidth() - pl.headerWidthForSnapshot()) / (1600.0 / (double) bar));
  110. for (const auto on : { false, true })
  111. {
  112. workflowextras::setExtra ("playlist.gainHandleFollowsView", on);
  113. pl.hoverFadeForSnapshot (audioClip, 0);
  114. savePng (shot::snapshot (pl, juce::Rectangle<int> (0, 0, pl.getWidth(), 200)), prefix + "-274-gain-handle-" + (on ? "on" : "off") + ".png");
  115. }
  116. workflowextras::setExtra ("playlist.gainHandleFollowsView", before);
  117. pl.hoverFadeForSnapshot (-1, 0);
  118. wav.deleteFile();
  119. return true;
  120. }