Selaa lähdekoodia

Merge branch 'wip/livewf190ef-draw' into wip/livewf190ef

# Conflicts:
#	CMakeLists.txt
#	scripts/build-local.sh
#	scripts/build-windows-zig.sh
#	tests/tests.cpp
Ka1-S 3 viikkoa sitten
vanhempi
sitoutus
82ca32decb

+ 1 - 0
CMakeLists.txt

@@ -41,6 +41,7 @@ add_library(lynx_core STATIC
     src/core/ClipLauncher.cpp
     src/core/ClipLauncher.cpp
     src/core/SessionOps.cpp
     src/core/SessionOps.cpp
     src/core/RemoteMap.cpp
     src/core/RemoteMap.cpp
+    src/core/DrawMode.cpp
     src/core/Groove.cpp
     src/core/Groove.cpp
     src/core/Patcherize.cpp
     src/core/Patcherize.cpp
     src/core/Instruments.cpp
     src/core/Instruments.cpp

+ 4 - 0
docs/USER_GUIDE.md

@@ -64,6 +64,10 @@ In the clip grid (Clip-launch workflow):
   a groove file you own), then pick it for a MIDI clip in the slot's menu › Groove. The clip plays through it without
   a groove file you own), then pick it for a MIDI clip in the slot's menu › Groove. The clip plays through it without
   changing its notes. Each groove has Base, Quantize, Timing, Random and Velocity; **Global Amount** scales all grooves
   changing its notes. Each groove has Base, Quantize, Timing, Random and Velocity; **Global Amount** scales all grooves
   (0 to 130 %). **Commit groove** writes the result into the notes; **Extract groove** makes a groove from a clip.
   (0 to 130 %). **Commit groove** writes the result into the notes; **Extract groove** makes a groove from a clip.
+- **Draw Mode** (B, or Options › Draw Mode, in the Clip-launch layout): a drag in an automation lane draws steps as wide
+  as the Playlist's grid, each one at the height the mouse had over it; with the grid off (or Alt held) it draws
+  freehand. The automation outside what you drew stays as it was, and each stroke is one undo step. Press B again to go
+  back to adding and moving points. In the other layouts B stays the brush tool.
 
 
 ## Online sessions: make a song with a friend (phase 1, packages)
 ## Online sessions: make a song with a friend (phase 1, packages)
 
 

Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 0 - 0
scripts/build-local.sh


Tiedoston diff-näkymää rajattu, sillä se on liian suuri
+ 1 - 1
scripts/build-windows-zig.sh


+ 155 - 0
src/Main.cpp

@@ -4,6 +4,7 @@
 
 
 #include "core/KeyGuess.h"
 #include "core/KeyGuess.h"
 #include "core/Groove.h"
 #include "core/Groove.h"
+#include "core/DrawMode.h"
 #include "core/SessionOps.h"
 #include "core/SessionOps.h"
 #include "ui/ClipGridComponent.h"
 #include "ui/ClipGridComponent.h"
 #include "ui/SessionMixer.h"
 #include "ui/SessionMixer.h"
@@ -2038,6 +2039,16 @@ public:
             return;
             return;
         }
         }
 
 
+        if (args.contains ("--drawshot190ef"))
+        {
+            // LYNX.exe --drawshot190ef prefix: round 190ef off-screen, in the Clip-launch workflow: Draw Mode in an
+            // automation lane, steps at the grid width and an Alt (no grid) freehand stroke drawn through the Playlist's
+            // own mouse handlers, and the Options menu with "Draw Mode". Writes prefix-checks.txt.
+            runDrawShot190ef (args[args.indexOf ("--drawshot190ef") + 1].unquoted());
+            quit();
+            return;
+        }
+
         if (args.contains ("--liveshot190dr"))
         if (args.contains ("--liveshot190dr"))
         {
         {
             // LYNX.exe --liveshot190dr prefix: round 190dr off-screen, in the Clip-launch workflow: the Session mixer
             // LYNX.exe --liveshot190dr prefix: round 190dr off-screen, in the Clip-launch workflow: the Session mixer
@@ -16643,6 +16654,150 @@ private:
         lib.deleteRecursively();
         lib.deleteRecursively();
     }
     }
 
 
+    void runDrawShot190ef (const juce::String& prefix)
+    {
+        juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
+        lynx::AudioEngine offline (false);
+        lynx::MainComponent ui (offline, false);
+        const auto size = juce::StringArray::fromTokens (juce::SystemStats::getEnvironmentVariable ("LYNX_SNAPSHOT_SIZE", "1600x900"), "x", "");
+        ui.setSize (juce::jlimit (800, 3840, size[0].getIntValue()), juce::jlimit (450, 2160, size[1].getIntValue()));
+        const auto write = [&prefix] (juce::Component& c, const char* name) {
+            const auto file = lynx::shot::file (juce::File (prefix + "-" + name + ".png"));
+            file.deleteFile();
+            juce::FileOutputStream out (file);
+            juce::PNGImageFormat().writeImageToStream (lynx::shot::snapshot (c), out);
+        };
+        juce::String checks;
+        const auto check = [&checks] (const juce::String& what, bool ok) { checks << (ok ? "ok   " : "FAIL ") << what << "\n"; };
+
+        ui.setVisible (true);
+        ui.setClipLaunchWorkflow (true);
+        ui.setClipGridView (lynx::PlaylistArea::GridView::song);
+        ui.showPanelsForSnapshot ({ lynx::workspace::Panel::playlist });
+        lynx::autolanes::setShown (true);
+        offline.editSong ([] (lynx::Song& s) {
+            if (s.mixer.size() < 4)
+                s.mixer.resize (4);
+            s.mixer[1].name = "Bass";
+            s.mixer[2].name = "Pad";
+            s.playlistTracks.resize (std::max<std::size_t> (s.playlistTracks.size(), 6));
+            s.playlistTracks[0].name = "Bass";
+            s.playlistTracks[0].mode = lynx::PlaylistTrackMode::audio;
+            s.playlistTracks[0].mixerTrack = 1;
+            s.playlistTracks[1].name = "Pad";
+            s.playlistTracks[1].mode = lynx::PlaylistTrackMode::audio;
+            s.playlistTracks[1].mixerTrack = 2;
+        }, false);
+        lynx::createAutomationLane (offline, { lynx::AutomationTargetKind::mixerVolume, 1, 0, 0 }, 0);
+        lynx::createAutomationLane (offline, { lynx::AutomationTargetKind::mixerPan, 2, 0, 0 }, 1);
+        offline.editSong ([] (lynx::Song& s) {
+            for (int t = 0; t < 2; ++t)
+                if (! s.playlistTracks[(std::size_t) t].lanes.empty())
+                    s.playlistTracks[(std::size_t) t].lanes[0].height = 110;
+        }, false);
+        offline.dispatchPendingMessages();
+        auto& playlist = ui.getPlaylistForSnapshot();
+        playlist.setViewForSnapshot (180.0, 0, 0);
+        ui.resized();
+        offline.dispatchPendingMessages();
+
+        const auto& song = offline.getSong();
+        const auto laneA = song.playlistTracks[0].lanes.empty() ? -1 : song.playlistTracks[0].lanes[0].automation;
+        const auto laneB = song.playlistTracks[1].lanes.empty() ? -1 : song.playlistTracks[1].lanes[0].automation;
+        check ("two lanes made", laneA >= 0 && laneB >= 0);
+        if (laneA < 0 || laneB < 0)
+        {
+            juce::File (prefix + "-checks.txt").replaceWithText (checks);
+            return;
+        }
+        write (ui, "00-lanes-before");
+        const auto before = song.automations[(std::size_t) laneA].points;
+
+        // a drag through the Playlist's own handlers (the events a real mouse sends)
+        auto source = juce::Desktop::getInstance().getMainMouseSource();
+        const auto now = juce::Time::getCurrentTime();
+        const auto stroke = [&] (int track, const std::vector<juce::Point<float>>& path, juce::ModifierKeys extra) {
+            const juce::ModifierKeys mods (juce::ModifierKeys::leftButtonModifier | extra.getRawFlags());
+            const auto event = [&] (juce::Point<float> p, juce::ModifierKeys m, bool dragged) {
+                return juce::MouseEvent (source, p, m, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, &playlist, &playlist, now, path.front(), now, 1, dragged);
+            };
+            juce::ignoreUnused (track);
+            // (the engine joins the edits of one press into one undo step while a button is down)
+            const auto held = juce::ModifierKeys::currentModifiers;
+            juce::ModifierKeys::currentModifiers = mods;
+            playlist.mouseDown (event (path.front(), mods, false));
+            for (std::size_t i = 1; i < path.size(); ++i)
+                playlist.mouseDrag (event (path[i], mods, true));
+            juce::ModifierKeys::currentModifiers = held;
+            playlist.mouseUp (event (path.back(), extra, true));
+        };
+        const auto bodyA = playlist.laneBodyForSnapshot (0, 0), bodyB = playlist.laneBodyForSnapshot (1, 0);
+        const auto bar = (double) (4 * lynx::ppq);
+        const auto x = [&] (double bars) { return (float) playlist.xOfTickForSnapshot (bars * bar); };
+        const auto y = [] (juce::Rectangle<float> body, float v) { return body.getBottom() - v * body.getHeight(); };
+
+        lynx::drawmode::set (true);
+        // steps: a rise over bar 1 and a fall over bar 2, at the Playlist's grid (Line, at this zoom)
+        std::vector<juce::Point<float>> steps;
+        for (int k = 0; k <= 16; ++k)
+            steps.push_back ({ x (1.0 + k / 16.0) + 2.0f, y (bodyA, 0.15f + 0.05f * (float) k) });
+        for (int k = 0; k <= 16; ++k)
+            steps.push_back ({ x (2.0 + k / 16.0) + 2.0f, y (bodyA, 0.95f - 0.05f * (float) k) });
+        stroke (0, steps, {});
+        const auto& afterSteps = offline.getSong().automations[(std::size_t) laneA].points;
+        check ("Draw Mode drag made steps (" + juce::String ((int) afterSteps.size()) + " points)", afterSteps.size() > before.size() + 4);
+        bool unchangedOutside = true;
+        for (double t = 0.0; t < 6.0 * bar; t += 37.0)
+            if ((t < bar - 1.0 || t > 3.1 * bar) && std::abs (lynx::automationCurveAt (before, t) - lynx::automationCurveAt (afterSteps, t)) > 1.0e-4f)
+                unchangedOutside = false;
+        check ("the curve outside the drawn bars is unchanged", unchangedOutside);
+        {
+            // flat inside each drawn cell: the values in a cell's first and last tick are the same
+            int flatCells = 0, cells = 0;
+            for (double t = bar; t < 3.0 * bar; t += lynx::ppq / 4.0)
+            {
+                ++cells;
+                if (std::abs (lynx::automationCurveAt (afterSteps, t + 1.0) - lynx::automationCurveAt (afterSteps, t + lynx::ppq / 4.0 - 1.0)) < 1.0e-5f)
+                    ++flatCells;
+            }
+            check ("each sixteenth inside bars 2-3 is flat (" + juce::String (flatCells) + " / " + juce::String (cells) + ")", flatCells == cells);
+        }
+        // freehand: Alt (no grid) on the pad's pan lane, a wave over bars 1-4
+        const auto panBefore = offline.getSong().automations[(std::size_t) laneB].points;
+        std::vector<juce::Point<float>> wave;
+        for (int k = 0; k <= 60; ++k)
+            wave.push_back ({ x (1.0 + 3.0 * k / 60.0), y (bodyB, 0.5f + 0.4f * std::sin ((float) k * 0.3f)) });
+        stroke (1, wave, juce::ModifierKeys (juce::ModifierKeys::altModifier));
+        const auto& pan = offline.getSong().automations[(std::size_t) laneB].points;
+        check ("Alt drag drew freehand (" + juce::String ((int) pan.size()) + " points)", pan.size() > 30);
+        playlist.repaint();
+        write (ui, "01-draw-mode-steps-and-freehand");
+        if (auto* parent = playlist.getParentComponent())
+            write (*parent, "01b-playlist");
+
+        // one stroke is one undo step
+        offline.undo();
+        check ("one undo takes the whole freehand stroke back", offline.getSong().automations[(std::size_t) laneB].points == panBefore);
+
+        // Draw Mode off: the same press adds one point, as before
+        lynx::drawmode::set (false);
+        const auto countOff = offline.getSong().automations[(std::size_t) laneA].points.size();
+        stroke (0, { { x (4.5), y (bodyA, 0.8f) } }, {});
+        check ("Draw Mode off: a press adds one point", offline.getSong().automations[(std::size_t) laneA].points.size() == countOff + 1);
+
+        // the Options menu (Clip-launch layout) with the switch
+        lynx::drawmode::set (true);
+        {
+            const auto names = ui.getMenuNamesForSnapshot();
+            const auto index = names.indexOf (TRANS ("Options"));
+            if (index >= 0)
+                saveMenus (juce::StringArray { "Options" }, std::vector<juce::PopupMenu> { ui.getMenuForSnapshot (index) }, prefix + "-02-options-menu.png");
+            check ("Options menu found", index >= 0);
+        }
+        lynx::drawmode::set (false);
+        juce::File (prefix + "-checks.txt").replaceWithText (checks);
+    }
+
     void runLiveShot190dr (const juce::String& prefix)
     void runLiveShot190dr (const juce::String& prefix)
     {
     {
         juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);
         juce::LookAndFeel::setDefaultLookAndFeel (&lookAndFeel);

+ 161 - 0
src/core/DrawMode.cpp

@@ -0,0 +1,161 @@
+#include "core/DrawMode.h"
+
+#include <algorithm>
+#include <cmath>
+#include <map>
+
+namespace lynx::drawmode
+{
+namespace
+{
+bool on = false;
+int nextId = 1;
+std::map<int, std::function<void (bool)>>& listeners()
+{
+    static std::map<int, std::function<void (bool)>> all;
+    return all;
+}
+
+float clamp01 (float v) noexcept { return std::clamp (v, 0.0f, 1.0f); }
+// (the old curve just left of an edge is read 1e-6 tick early: equal within this is the same value)
+bool same (float a, float b) noexcept { return std::abs (a - b) <= 1.0e-5f; }
+} // namespace
+
+bool isOn() noexcept { return on; }
+
+void set (bool value)
+{
+    if (value == on)
+        return;
+    on = value;
+    const auto copy = listeners(); // (a listener may remove itself)
+    for (const auto& [id, fn] : copy)
+        if (fn != nullptr)
+            fn (on);
+}
+
+int addListener (std::function<void (bool)> listener)
+{
+    const auto id = nextId++;
+    listeners()[id] = std::move (listener);
+    return id;
+}
+
+void removeListener (int id) { listeners().erase (id); }
+
+std::vector<Cell> cellsBetween (std::int64_t t0, std::int64_t t1, std::int64_t grid)
+{
+    std::vector<Cell> out;
+    if (grid <= 0)
+        return out;
+    const auto lo = std::max<std::int64_t> (0, std::min (t0, t1)), hi = std::max<std::int64_t> (0, std::max (t0, t1));
+    constexpr std::int64_t maxCells = 100000; // (a sweep over hours of song at a one-tick grid)
+    const auto k0 = lo / grid, k1 = std::min (hi / grid, k0 + maxCells - 1);
+    out.reserve ((std::size_t) (k1 - k0 + 1));
+    for (auto k = k0; k <= k1; ++k)
+        out.push_back ({ k * grid, (k + 1) * grid });
+    return out;
+}
+
+std::vector<Step> stepsAlong (std::int64_t t0, float v0, std::int64_t t1, float v1, std::int64_t grid)
+{
+    std::vector<Step> out;
+    const auto cells = cellsBetween (t0, t1, grid);
+    out.reserve (cells.size());
+    for (const auto& c : cells)
+    {
+        auto v = v1;
+        if (cells.size() > 1 && t1 != t0)
+        {
+            const auto mid = 0.5 * ((double) c.from + (double) c.to);
+            const auto f = std::clamp ((mid - (double) t0) / ((double) t1 - (double) t0), 0.0, 1.0);
+            v = (float) ((double) v0 + ((double) v1 - (double) v0) * f);
+        }
+        out.push_back ({ c, clamp01 (v) });
+    }
+    return out;
+}
+
+void drawPiece (std::vector<AutomationPoint>& points, std::int64_t from, std::int64_t to, float vFrom, float vTo)
+{
+    from = std::max<std::int64_t> (0, from);
+    if (to <= from)
+        return;
+    vFrom = clamp01 (vFrom);
+    vTo = clamp01 (vTo);
+
+    // the old curve at the edges: the value just left of `from` (a jump there keeps its left side) and the value at `to`
+    const auto left = automationCurveAt (points, (double) from - 1.0e-6);
+    const auto right = automationCurveAt (points, (double) to);
+    const auto anyBefore = std::any_of (points.begin(), points.end(), [from] (const AutomationPoint& p) { return p.tick < from; });
+
+    // the point that starts the curve after `to`: the last one on `to` itself if there is one (it keeps its segment's
+    // mode and bend); otherwise a new one, cut from the segment that crosses `to` (its mode and bend)
+    int lastAtTo = -1, crossing = -1;
+    for (int i = 0; i < (int) points.size(); ++i)
+    {
+        if (points[(std::size_t) i].tick == to)
+            lastAtTo = i;
+        if (points[(std::size_t) i].tick < to)
+            crossing = i;
+    }
+    AutomationPoint after { to, right, 0.0f, 0 };
+    const auto keepAfter = lastAtTo >= 0;
+    const auto anyAfter = std::any_of (points.begin(), points.end(), [to] (const AutomationPoint& p) { return p.tick > to; });
+    if (! keepAfter && crossing >= 0 && anyAfter)
+    {
+        after.mode = points[(std::size_t) crossing].mode;
+        after.tension = points[(std::size_t) crossing].tension;
+    }
+
+    // out with what was in [from, to) and the earlier points on `to`
+    std::vector<AutomationPoint> kept;
+    kept.reserve (points.size() + 4);
+    for (int i = 0; i < (int) points.size(); ++i)
+    {
+        const auto t = points[(std::size_t) i].tick;
+        if ((t >= from && t < to) || (t == to && i != lastAtTo))
+            continue;
+        kept.push_back (points[(std::size_t) i]);
+    }
+
+    std::vector<AutomationPoint> piece;
+    if (anyBefore || from > 0)
+        piece.push_back ({ from, left, 0.0f, 0 });
+    piece.push_back ({ from, vFrom, 0.0f, 0 });
+    piece.push_back ({ to, vTo, 0.0f, 0 });
+    if (! keepAfter)
+        piece.push_back (after);
+
+    const auto at = std::find_if (kept.begin(), kept.end(), [from] (const AutomationPoint& p) { return p.tick >= from; });
+    kept.insert (at, piece.begin(), piece.end());
+
+    // tidy the drawn range: a point that repeats the next one (same tick and value) goes; so does the middle of three
+    // points with one value (a flat run stays flat whatever the segments' modes)
+    auto inside = [from, to] (const AutomationPoint& p) { return p.tick >= from && p.tick <= to; };
+    for (std::size_t i = 0; i + 1 < kept.size();)
+        if (inside (kept[i]) && kept[i].tick == kept[i + 1].tick && same (kept[i].value, kept[i + 1].value))
+            kept.erase (kept.begin() + (std::ptrdiff_t) i);
+        else
+            ++i;
+    for (std::size_t i = 1; i + 1 < kept.size();)
+        if (inside (kept[i]) && same (kept[i - 1].value, kept[i].value) && same (kept[i].value, kept[i + 1].value))
+            kept.erase (kept.begin() + (std::ptrdiff_t) i);
+        else
+            ++i;
+
+    points = std::move (kept);
+}
+
+void drawLine (std::vector<AutomationPoint>& points, std::int64_t t0, float v0, std::int64_t t1, float v1)
+{
+    if (t1 < t0)
+    {
+        std::swap (t0, t1);
+        std::swap (v0, v1);
+    }
+    if (t1 == t0)
+        t1 = t0 + 1;
+    drawPiece (points, t0, t1, v0, v1);
+}
+} // namespace lynx::drawmode

+ 64 - 0
src/core/DrawMode.h

@@ -0,0 +1,64 @@
+#pragma once
+
+// Draw Mode (round 190ef, the Clip-launch layout's B key; the reference DAW's "Options › Draw Mode", its pencil switch in
+// the control bar). With Draw Mode on, a drag in an automation lane draws instead of moving points:
+//   - with a grid: steps as wide as the grid, each one flat at the value the mouse had over it (arrangement-0089);
+//   - without a grid (snap off, or Alt held): freehand, the line follows the mouse (arrangement-0090).
+// What is outside the drawn range keeps its curve: a step's edges are vertical jumps, two points on one tick (the left
+// one carries the old curve's value there, the right one the new value; automationCurveAt gives the right one at the
+// tick itself). docs/analise/REA_rodada190ef.md has the evidence. No JUCE here.
+
+#include <cstdint>
+#include <functional>
+#include <vector>
+
+#include "core/Song.h"
+
+namespace lynx::drawmode
+{
+// --- the switch (a preference of the session, not of a project) --------------------------------------------------------
+bool isOn() noexcept;
+void set (bool on);
+inline void toggle() { set (! isOn()); }
+// Called on the message thread after every change (the control bar's switch, the Options menu, the Playlist's cursor).
+// Returns an id for removeListener.
+int addListener (std::function<void (bool on)> listener);
+void removeListener (int id);
+
+// --- the grid ----------------------------------------------------------------------------------------------------------
+// One cell of the grid: [from, to).
+struct Cell
+{
+    std::int64_t from = 0, to = 0;
+    bool operator== (const Cell&) const = default;
+};
+// The cells of a grid of `grid` ticks (counted from tick 0) a drag from t0 to t1 passes over, left to right (t1 may be
+// before t0). Ticks below 0 count as 0. grid <= 0: none.
+std::vector<Cell> cellsBetween (std::int64_t t0, std::int64_t t1, std::int64_t grid);
+
+// A step to draw: a cell and its value.
+struct Step
+{
+    Cell cell;
+    float value = 0.0f;
+};
+// The steps of one mouse move from (t0, v0) to (t1, v1): each cell passed takes the value the mouse had over the cell's
+// middle, on the straight line between the two positions (clamped to the move's ends, then to 0..1); a move that stays
+// in one cell gives that cell the value v1.
+std::vector<Step> stepsAlong (std::int64_t t0, float v0, std::int64_t t1, float v1, std::int64_t grid);
+
+// --- drawing into a point list --------------------------------------------------------------------------------------------
+// The curve over [from, to] becomes a straight piece from vFrom to vTo; before `from` and from `to` on it stays as it
+// was (an edge where the old curve has another value becomes a jump: two points on that tick). The points stay sorted;
+// points that only repeat a flat run inside [from, to] are merged. Values are clamped to 0..1. Exact outside [from, to]
+// where the old segments that cross an edge are straight (LYNX's default); a bent segment that crosses an edge is cut
+// there, so its part outside keeps its ends but not its exact bend. from >= to: nothing changes.
+void drawPiece (std::vector<AutomationPoint>& points, std::int64_t from, std::int64_t to, float vFrom, float vTo);
+// A step: [from, to) flat at `value`.
+inline void drawStep (std::vector<AutomationPoint>& points, std::int64_t from, std::int64_t to, float value)
+{
+    drawPiece (points, from, to, value, value);
+}
+// Freehand: the mouse went from (t0, v0) to (t1, v1) (either way round).
+void drawLine (std::vector<AutomationPoint>& points, std::int64_t t0, float v0, std::int64_t t1, float v1);
+} // namespace lynx::drawmode

+ 16 - 0
src/ui/MainComponent.cpp

@@ -6,6 +6,8 @@
 #include "ui/GamepadInput.h"
 #include "ui/GamepadInput.h"
 #include "ui/ThemeSettings.h"
 #include "ui/ThemeSettings.h"
 #include "ui/ColourPicker.h"
 #include "ui/ColourPicker.h"
+#include "core/DrawMode.h"
+#include "core/SessionKeys.h"
 #include "core/EditorLimit.h"
 #include "core/EditorLimit.h"
 #include "core/SessionKeys.h"
 #include "core/SessionKeys.h"
 #include "core/FlSettings.h"
 #include "core/FlSettings.h"
@@ -1775,6 +1777,16 @@ bool MainComponent::keyPressed (const juce::KeyPress& key)
     if (const auto own = keyMap.findUserBound (chord, focusContext(), pianoKeys); ! own.empty() && runAction (own))
     if (const auto own = keyMap.findUserBound (chord, focusContext(), pianoKeys); ! own.empty() && runAction (own))
         return true;
         return true;
 
 
+    // round 190ef: B is the reference's Draw Mode switch in the Clip-launch layout (core/SessionKeys.h); in the other
+    // layouts it stays the Playlist's and Piano roll's brush tool
+    if (key.getKeyCode() == 'B' || key.getKeyCode() == 'b')
+        if (isPlainKey (chord) && sessionkeys::defaultKeyActs (sessionkeys::Command::drawMode)
+            && dynamic_cast<juce::TextEditor*> (juce::Component::getCurrentlyFocusedComponent()) == nullptr)
+        {
+            drawmode::toggle();
+            return true;
+        }
+
     // 3. the focused panel's own keys
     // 3. the focused panel's own keys
     const auto focused = workspace.getFocused();
     const auto focused = workspace.getFocused();
     const auto panelShown = workspace.isPanelVisible (focused);
     const auto panelShown = workspace.isPanelVisible (focused);
@@ -8228,6 +8240,10 @@ juce::PopupMenu MainComponent::getMenuForIndex (int barIndex, const juce::String
         // round 177b-4): the controls moved while it is on link, in that order, to the controllers moved next
         // round 177b-4): the controls moved while it is on link, in that order, to the controllers moved next
         menu.addItem (tr ("Multilink to controllers") + shortcutText ("options.multilink"), true, engine.isMultilinkOn(),
         menu.addItem (tr ("Multilink to controllers") + shortcutText ("options.multilink"), true, engine.isMultilinkOn(),
                       [this] { runAction ("options.multilink"); });
                       [this] { runAction ("options.multilink"); });
+        // round 190ef: the reference's Options › Draw Mode (B), in the Clip-launch layout: a drag in an automation lane
+        // draws steps at the grid width, or freehand without a grid (core/DrawMode.h)
+        if (layoutStyle == layoutstyle::Style::clipLaunch)
+            menu.addItem (tr ("Draw Mode") + sessionkeys::menuKey (sessionkeys::Command::drawMode), true, drawmode::isOn(), [] { drawmode::toggle(); });
         {
         {
             juce::PopupMenu recording;
             juce::PopupMenu recording;
             addRecordOptions (recording);
             addRecordOptions (recording);

+ 59 - 3
src/ui/PlaylistComponent.cpp

@@ -1,4 +1,5 @@
 #include "core/FlCurve.h"
 #include "core/FlCurve.h"
+#include "core/DrawMode.h"
 #include "ui/CleanVoiceMenu.h"
 #include "ui/CleanVoiceMenu.h"
 #include "ui/FlMods.h"
 #include "ui/FlMods.h"
 #include "ui/Motion.h"
 #include "ui/Motion.h"
@@ -2867,6 +2868,22 @@ bool PlaylistComponent::laneMouseDown (const juce::MouseEvent& e)
     const auto point = lanePointAt (hit.track, hit.lane, e.getPosition());
     const auto point = lanePointAt (hit.track, hit.lane, e.getPosition());
     const auto body = laneBody (hit.track, hit.lane);
     const auto body = laneBody (hit.track, hit.lane);
 
 
+    // round 190ef, Draw Mode (the Clip-launch layout's B, core/DrawMode.h): a press draws the cell under the mouse at the
+    // grid width, a drag goes on drawing (freehand without a grid or with Alt, the Playlist's "no snap"); the right button
+    // keeps its point menu
+    if (drawmode::isOn() && ! flmods::popup (e.mods) && e.mods.isLeftButtonDown())
+    {
+        laneTrack = hit.track;
+        laneIndex = hit.lane;
+        setSelection ({});
+        drag = Drag::laneDraw;
+        drawFreehand = grid::resolve (snapBox).kind == grid::Kind::none || gridTicks() <= 1 || e.mods.isAltDown();
+        drawTick = juce::jmax<std::int64_t> (0, (std::int64_t) std::floor (xToTick (e.x)));
+        drawValue = laneValueOf (a, juce::jlimit (0.0f, 1.0f, (body.getBottom() - (float) e.y) / juce::jmax (1.0f, body.getHeight())));
+        laneDrawTo (e);
+        return true;
+    }
+
     if (flmods::popup (e.mods) || (e.mods.isAltDown() && point >= 0)) // on a point: delete it (FL's Alt+click too)
     if (flmods::popup (e.mods) || (e.mods.isAltDown() && point >= 0)) // on a point: delete it (FL's Alt+click too)
     {
     {
         if (point >= 0 && points.size() > 1)
         if (point >= 0 && points.size() > 1)
@@ -2918,6 +2935,34 @@ bool PlaylistComponent::laneMouseDown (const juce::MouseEvent& e)
     return true;
     return true;
 }
 }
 
 
+// round 190ef: one move of a Draw Mode drag, from the last position to the mouse (one undo step per press: editSong
+// joins the edits made while the button is held)
+void PlaylistComponent::laneDrawTo (const juce::MouseEvent& e)
+{
+    const auto a = laneAutomation (laneTrack, laneIndex);
+    if (a < 0)
+        return;
+    const auto body = laneBody (laneTrack, laneIndex);
+    const auto tick = juce::jmax<std::int64_t> (0, (std::int64_t) std::floor (xToTick (e.x)));
+    const auto value = laneValueOf (a, juce::jlimit (0.0f, 1.0f, (body.getBottom() - (float) e.y) / juce::jmax (1.0f, body.getHeight())));
+    const auto from = drawTick;
+    const auto fromValue = drawValue;
+    if (drawFreehand)
+        engine.editSong ([a, from, fromValue, tick, value] (Song& s) {
+            drawmode::drawLine (s.automations[(std::size_t) a].points, from, fromValue, tick, value);
+        });
+    else
+    {
+        const auto steps = drawmode::stepsAlong (from, fromValue, tick, value, gridTicks());
+        engine.editSong ([a, steps] (Song& s) {
+            for (const auto& step : steps)
+                drawmode::drawStep (s.automations[(std::size_t) a].points, step.cell.from, step.cell.to, step.value);
+        });
+    }
+    drawTick = tick;
+    drawValue = value;
+}
+
 // round 190cg: a tempo lane shows the song's own range (Song::tempoViewLow / High, the reference's lowest / highest BPM
 // round 190cg: a tempo lane shows the song's own range (Song::tempoViewLow / High, the reference's lowest / highest BPM
 // of the tempo lane) when one is set; every other lane, and a tempo lane without a range, shows 0 … 1 as before
 // of the tempo lane) when one is set; every other lane, and a tempo lane without a range, shows 0 … 1 as before
 float PlaylistComponent::laneShown (int automation, float value) const
 float PlaylistComponent::laneShown (int automation, float value) const
@@ -4504,6 +4549,10 @@ void PlaylistComponent::mouseDrag (const juce::MouseEvent& e)
             repaint();
             repaint();
             return;
             return;
 
 
+        case Drag::laneDraw:
+            laneDrawTo (e);
+            return;
+
         case Drag::lanePoint:
         case Drag::lanePoint:
         {
         {
             const auto a = laneAutomation (laneTrack, laneIndex);
             const auto a = laneAutomation (laneTrack, laneIndex);
@@ -4964,6 +5013,9 @@ void PlaylistComponent::postDragHint()
         case Drag::warpMarker: hint.text = tr ("Moving the warp marker: the audio around it stretches  [Alt] no snap"); break;
         case Drag::warpMarker: hint.text = tr ("Moving the warp marker: the audio around it stretches  [Alt] no snap"); break;
         case Drag::autoPoint: hint.text = tr ("Moving the point: then [Shift] keeps time  [Ctrl] keeps value"); break;
         case Drag::autoPoint: hint.text = tr ("Moving the point: then [Shift] keeps time  [Ctrl] keeps value"); break;
         case Drag::autoTension: hint.text = tr ("Bending the segment: drag up / down  [Ctrl] fine"); break;
         case Drag::autoTension: hint.text = tr ("Bending the segment: drag up / down  [Ctrl] fine"); break;
+        case Drag::laneDraw:
+            hint.text = drawFreehand ? tr ("Draw Mode: drawing freehand") : tr ("Draw Mode: drawing steps at the grid width  [Alt] freehand");
+            break;
         case Drag::lanePoint:
         case Drag::lanePoint:
         case Drag::laneTension:
         case Drag::laneTension:
         {
         {
@@ -8242,8 +8294,11 @@ void PlaylistComponent::updateCursor (juce::ModifierKeys mods)
     }
     }
     if (const auto lane = laneAt (p); lane.track >= 0) // round 177b
     if (const auto lane = laneAt (p); lane.track >= 0) // round 177b
     {
     {
-        setMouseCursor (p.x >= headerWidth && lanePointAt (lane.track, lane.lane, p) >= 0 ? juce::MouseCursor::DraggingHandCursor
-                                                                                           : juce::MouseCursor::NormalCursor);
+        if (p.x >= headerWidth && drawmode::isOn()) // round 190ef: Draw Mode's pencil
+            setMouseCursor (editorCursor (gesture::Cursor::draw));
+        else
+            setMouseCursor (p.x >= headerWidth && lanePointAt (lane.track, lane.lane, p) >= 0 ? juce::MouseCursor::DraggingHandCursor
+                                                                                               : juce::MouseCursor::NormalCursor);
         return;
         return;
     }
     }
     if (hover.header)
     if (hover.header)
@@ -8277,7 +8332,8 @@ ui::Hint PlaylistComponent::hintAt (juce::Point<int> p)
     {
     {
         const auto a = laneAutomation (lane.track, lane.lane);
         const auto a = laneAutomation (lane.track, lane.lane);
         hint.text = p.x < headerWidth ? tr ("Automation lane: [RMB] lane menu  [2xLMB] edit the points")
         hint.text = p.x < headerWidth ? tr ("Automation lane: [RMB] lane menu  [2xLMB] edit the points")
-                                      : tr ("Automation lane: [LMB] add or drag a point  [RMB] deletes a point  [Alt] drag bends the line  [Shift] adds on the line");
+                    : drawmode::isOn() ? tr ("Automation lane, Draw Mode: [LMB] drag draws steps at the grid width  [Alt] freehand  [RMB] deletes a point")
+                                       : tr ("Automation lane: [LMB] add or drag a point  [RMB] deletes a point  [Alt] drag bends the line  [Shift] adds on the line");
         hint.hasMenu = true;
         hint.hasMenu = true;
         if (a >= 0)
         if (a >= 0)
         {
         {

+ 10 - 1
src/ui/PlaylistComponent.h

@@ -165,6 +165,9 @@ public:
     void setViewForSnapshot (double pixelsPerBar, int firstBar, int firstTrack);
     void setViewForSnapshot (double pixelsPerBar, int firstBar, int firstTrack);
     void selectClipsForSnapshot (const std::vector<int>& clips) { setSelection (clips); repaint(); }
     void selectClipsForSnapshot (const std::vector<int>& clips) { setSelection (clips); repaint(); }
     void setScrollTickForSnapshot (double tick) { scrollTicks = tick; repaint(); }
     void setScrollTickForSnapshot (double tick) { scrollTicks = tick; repaint(); }
+    // round 190ef (--drawshot190ef): where a lane's curve is drawn, and the x of a tick
+    juce::Rectangle<float> laneBodyForSnapshot (int track, int lane) const { return laneBody (track, lane); }
+    double xOfTickForSnapshot (double tick) const { return tickToX (tick); }
     juce::PopupMenu getClipMenuForSnapshot (int index); // --snapshot: the clip menu of that clip
     juce::PopupMenu getClipMenuForSnapshot (int index); // --snapshot: the clip menu of that clip
     juce::PopupMenu getAutomationPointMenuForSnapshot (int clip, int point); // FL's point menu of an automation clip's point (round 190bw)
     juce::PopupMenu getAutomationPointMenuForSnapshot (int clip, int point); // FL's point menu of an automation clip's point (round 190bw)
     juce::PopupMenu getTrackMenuForSnapshot (int track) { return buildTrackMenu (track); }
     juce::PopupMenu getTrackMenuForSnapshot (int track) { return buildTrackMenu (track); }
@@ -237,7 +240,7 @@ public:
 
 
 private:
 private:
     enum class Drag { none, move, resize, trimLeft, slip, erase, seek, loop, select, fadeIn, fadeOut, paint, muting, knife, zoomRange, listen, pan, timeMove, timeShift, autoPoint, autoTension,
     enum class Drag { none, move, resize, trimLeft, slip, erase, seek, loop, select, fadeIn, fadeOut, paint, muting, knife, zoomRange, listen, pan, timeMove, timeShift, autoPoint, autoTension,
-                      lanePoint, laneTension, trackResize, preview, trackZoom, heightZoom, timeZoom, perfLaunch, clipGain, swipe, warpMarker };
+                      lanePoint, laneTension, laneDraw, trackResize, preview, trackZoom, heightZoom, timeZoom, perfLaunch, clipGain, swipe, warpMarker };
     void swipeTimeSelectionToComp (int lane);
     void swipeTimeSelectionToComp (int lane);
     // a swipe on a take lane (round 177c): the lane and the range so far
     // a swipe on a take lane (round 177c): the lane and the range so far
     int swipeLane = -1;
     int swipeLane = -1;
@@ -559,6 +562,12 @@ private:
     bool laneButtonHover = false;
     bool laneButtonHover = false;
     int laneTrack = -1, laneIndex = -1;                    // the lane a lanePoint / laneTension drag edits
     int laneTrack = -1, laneIndex = -1;                    // the lane a lanePoint / laneTension drag edits
     float tensionStart = 0.0f, tensionSign = 1.0f;
     float tensionStart = 0.0f, tensionSign = 1.0f;
+    // round 190ef, Draw Mode (core/DrawMode.h): a laneDraw drag's last mouse position (tick, value) and whether it draws
+    // freehand (no grid, or Alt) or steps at the grid width
+    std::int64_t drawTick = 0;
+    float drawValue = 0.0f;
+    bool drawFreehand = false;
+    void laneDrawTo (const juce::MouseEvent& e);
     // hover: what a click would hit (drives the cursor, the highlight and the hint)
     // hover: what a click would hit (drives the cursor, the highlight and the hint)
     struct Hover
     struct Hover
     {
     {

+ 215 - 0
tests/LiveWf190efDrawTests.inc

@@ -0,0 +1,215 @@
+// Round 190ef: Draw Mode (core/DrawMode.h): steps at the grid width and freehand lines drawn into automation points.
+// docs/analise/REA_rodada190ef.md.
+
+#include "core/DrawMode.h"
+
+namespace live190efdraw
+{
+using lynx::AutomationPoint;
+inline AutomationPoint pt (std::int64_t tick, float value, float tension = 0.0f, std::uint8_t mode = 0)
+{
+    AutomationPoint p;
+    p.tick = tick;
+    p.value = value;
+    p.tension = tension;
+    p.mode = mode;
+    return p;
+}
+// a ramp 0.2 → 0.8 over four bars, then down to 0.4 at bar 8
+inline std::vector<AutomationPoint> ramp()
+{
+    const std::int64_t bar = 4 * lynx::ppq;
+    return { pt (0, 0.2f), pt (4 * bar, 0.8f), pt (8 * bar, 0.4f) };
+}
+inline bool sorted (const std::vector<AutomationPoint>& p)
+{
+    for (std::size_t i = 1; i < p.size(); ++i)
+        if (p[i].tick < p[i - 1].tick)
+            return false;
+    return true;
+}
+// the old and new curves agree outside [from, to] (sampled every `every` ticks up to `end`)
+inline bool sameOutside (const std::vector<AutomationPoint>& before, const std::vector<AutomationPoint>& after, std::int64_t from,
+                         std::int64_t to, std::int64_t end, std::int64_t every = 7)
+{
+    for (std::int64_t t = 0; t <= end; t += every)
+    {
+        if (t >= from && t <= to)
+            continue;
+        if (std::abs (lynx::automationCurveAt (before, (double) t) - lynx::automationCurveAt (after, (double) t)) > 1.0e-4f)
+            return false;
+    }
+    // just left of `from` and at / after `to`
+    if (from > 0 && std::abs (lynx::automationCurveAt (before, (double) from - 0.5) - lynx::automationCurveAt (after, (double) from - 0.5)) > 1.0e-4f)
+        return false;
+    return std::abs (lynx::automationCurveAt (before, (double) to) - lynx::automationCurveAt (after, (double) to)) <= 1.0e-4f;
+}
+inline bool flatAt (const std::vector<AutomationPoint>& p, std::int64_t from, std::int64_t to, float v)
+{
+    for (auto t = from; t < to; t += std::max<std::int64_t> (1, (to - from) / 17))
+        if (std::abs (lynx::automationCurveAt (p, (double) t) - v) > 1.0e-5f)
+            return false;
+    return std::abs (lynx::automationCurveAt (p, (double) to - 0.25) - v) <= 1.0e-5f;
+}
+} // namespace live190efdraw
+
+TEST (live190ef_draw_cells_cover_the_drag_at_the_grid_width)
+{
+    using namespace lynx::drawmode;
+    const auto q = (std::int64_t) lynx::ppq, s16 = q / 4, bar = 4 * q, t8 = q / 3; // a sixteenth, a bar, an eighth triplet
+    auto cells = cellsBetween (s16 + 5, 3 * s16 + 1, s16);
+    CHECK (cells.size() == 3);
+    CHECK (cells.front() == (Cell { s16, 2 * s16 }) && cells.back() == (Cell { 3 * s16, 4 * s16 }));
+    // the same cells right to left, still in time order
+    CHECK (cellsBetween (3 * s16 + 1, s16 + 5, s16) == cells);
+    // a move inside one cell: that cell
+    CHECK (cellsBetween (bar + 10, bar + 900, bar) == std::vector<Cell> ({ { bar, 2 * bar } }));
+    // triplet widths: 0..q covered by three eighth-triplet cells
+    cells = cellsBetween (0, q - 1, t8);
+    CHECK (cells.size() == 3 && cells[2].to == q);
+    for (const auto& c : cells)
+        CHECK (c.to - c.from == t8);
+    // before the song: counted from 0; no grid: nothing
+    CHECK (cellsBetween (-500, 10, s16).front().from == 0);
+    CHECK (cellsBetween (0, 1000, 0).empty());
+}
+
+TEST (live190ef_draw_steps_along_a_move_take_the_mouse_value_over_each_cell)
+{
+    using namespace lynx::drawmode;
+    const auto g = (std::int64_t) lynx::ppq;
+    // one cell: the value the mouse has now
+    auto steps = stepsAlong (10, 0.1f, 20, 0.9f, g);
+    CHECK (steps.size() == 1 && std::abs (steps[0].value - 0.9f) < 1.0e-6f);
+    // across four cells the values follow the line through the cells' middles
+    steps = stepsAlong (0, 0.0f, 4 * g, 1.0f, g);
+    CHECK (steps.size() == 5);
+    CHECK (std::abs (steps[0].value - 0.125f) < 1.0e-5f && std::abs (steps[1].value - 0.375f) < 1.0e-5f);
+    CHECK (std::abs (steps[4].value - 1.0f) < 1.0e-5f); // (its middle is past the mouse: the end value)
+    // right to left the same line
+    const auto back = stepsAlong (4 * g, 1.0f, 0, 0.0f, g);
+    CHECK (back.size() == 5 && std::abs (back[1].value - 0.375f) < 1.0e-5f);
+    // values are clamped
+    steps = stepsAlong (0, 2.0f, 0, 2.0f, g);
+    CHECK (steps.size() == 1 && steps[0].value == 1.0f);
+    CHECK (stepsAlong (0, -1.0f, 5, -3.0f, g)[0].value == 0.0f);
+}
+
+TEST (live190ef_draw_a_step_is_flat_and_leaves_the_curve_outside_alone)
+{
+    using namespace live190efdraw;
+    const std::int64_t bar = 4 * lynx::ppq, g = lynx::ppq / 4;
+    const auto before = ramp();
+    for (const auto from : { (std::int64_t) 0, 3 * g, bar, 4 * bar - g, 4 * bar, 6 * bar + 3 * g, 8 * bar, 9 * bar })
+    {
+        auto p = before;
+        lynx::drawmode::drawStep (p, from, from + g, 0.65f);
+        CHECK (sorted (p));
+        CHECK (flatAt (p, from, from + g, 0.65f));
+        CHECK (sameOutside (before, p, from, from + g, 10 * bar));
+    }
+}
+
+TEST (live190ef_draw_adjacent_steps_and_a_redrawn_cell)
+{
+    using namespace live190efdraw;
+    const std::int64_t bar = 4 * lynx::ppq, g = lynx::ppq / 4;
+    const auto before = ramp();
+    auto p = before;
+    const float values[] = { 0.1f, 0.9f, 0.9f, 0.3f };
+    for (int i = 0; i < 4; ++i)
+        lynx::drawmode::drawStep (p, bar + i * g, bar + (i + 1) * g, values[i]);
+    CHECK (sorted (p));
+    for (int i = 0; i < 4; ++i)
+        CHECK (flatAt (p, bar + i * g, bar + (i + 1) * g, values[i]));
+    CHECK (sameOutside (before, p, bar, bar + 4 * g, 10 * bar));
+    // the two equal neighbours are one flat run: no point is left in its middle
+    const auto mid = bar + 2 * g;
+    CHECK (std::none_of (p.begin(), p.end(), [mid] (const lynx::AutomationPoint& x) { return x.tick == mid; }));
+    // drawing the same cell again replaces it
+    const auto count = p.size();
+    lynx::drawmode::drawStep (p, bar + 3 * g, bar + 4 * g, 0.5f);
+    CHECK (flatAt (p, bar + 3 * g, bar + 4 * g, 0.5f) && flatAt (p, bar + 2 * g, bar + 3 * g, 0.9f));
+    CHECK (p.size() == count && sorted (p));
+    // drawing a cell at the value the curve already has adds no jump
+    auto flat = std::vector<lynx::AutomationPoint> { pt (0, 0.5f), pt (bar, 0.5f) };
+    lynx::drawmode::drawStep (flat, g, 2 * g, 0.5f);
+    CHECK (flat.size() == 2);
+}
+
+TEST (live190ef_draw_a_bent_segment_cut_by_a_step_keeps_its_ends)
+{
+    using namespace live190efdraw;
+    const std::int64_t bar = 4 * lynx::ppq;
+    const std::vector<lynx::AutomationPoint> before { pt (0, 0.0f, 0.6f), pt (2 * bar, 1.0f), pt (3 * bar, 0.2f) };
+    auto p = before;
+    lynx::drawmode::drawStep (p, bar, bar + lynx::ppq, 0.3f);
+    CHECK (sorted (p));
+    // the values at the edges are the old ones (the cut piece's bend is approximate, as documented)
+    CHECK (std::abs (lynx::automationCurveAt (p, (double) bar - 1.0e-3) - lynx::automationCurveAt (before, (double) bar)) < 1.0e-3f);
+    CHECK (std::abs (lynx::automationCurveAt (p, (double) (bar + lynx::ppq)) - lynx::automationCurveAt (before, (double) (bar + lynx::ppq))) < 1.0e-5f);
+    CHECK (std::abs (lynx::automationCurveAt (p, 2.5 * bar) - lynx::automationCurveAt (before, 2.5 * bar)) < 1.0e-5f);
+}
+
+TEST (live190ef_draw_freehand_replaces_the_points_it_passes)
+{
+    using namespace live190efdraw;
+    const std::int64_t bar = 4 * lynx::ppq;
+    const auto before = ramp();
+    auto p = before;
+    // a stroke of three moves, the middle one right to left would be odd: draw left to right, then one backwards
+    lynx::drawmode::drawLine (p, bar, 0.1f, bar + 200, 0.4f);
+    lynx::drawmode::drawLine (p, bar + 200, 0.4f, bar + 500, 0.2f);
+    CHECK (sorted (p));
+    CHECK (std::abs (lynx::automationCurveAt (p, (double) bar + 100.0) - 0.25f) < 1.0e-4f);
+    CHECK (std::abs (lynx::automationCurveAt (p, (double) bar + 350.0) - 0.3f) < 1.0e-4f);
+    CHECK (sameOutside (before, p, bar, bar + 500, 10 * bar));
+    // the old point at 4 bars is gone when a stroke crosses it, and the curve after the stroke is the old one
+    auto q = before;
+    lynx::drawmode::drawLine (q, 5 * bar, 0.5f, 3 * bar, 0.5f); // (right to left)
+    CHECK (std::none_of (q.begin(), q.end(), [bar] (const lynx::AutomationPoint& x) { return x.tick == 4 * bar; }));
+    CHECK (flatAt (q, 3 * bar, 5 * bar, 0.5f));
+    CHECK (sameOutside (before, q, 3 * bar, 5 * bar, 10 * bar));
+    // a click without a move draws one tick; values are clamped
+    auto r = before;
+    lynx::drawmode::drawLine (r, 2 * bar, 3.0f, 2 * bar, 3.0f);
+    CHECK (sorted (r) && lynx::automationCurveAt (r, 2.0 * bar) == 1.0f);
+    CHECK (sameOutside (before, r, 2 * bar, 2 * bar + 1, 10 * bar));
+}
+
+TEST (live190ef_draw_into_an_empty_or_one_point_lane)
+{
+    using namespace live190efdraw;
+    std::vector<lynx::AutomationPoint> one { pt (0, 0.7f) };
+    const auto before = one;
+    lynx::drawmode::drawStep (one, 960, 1920, 0.2f);
+    CHECK (sorted (one) && flatAt (one, 960, 1920, 0.2f) && sameOutside (before, one, 960, 1920, 8000));
+    // a step at the very start of the song needs no left edge
+    std::vector<lynx::AutomationPoint> start { pt (0, 0.7f) };
+    lynx::drawmode::drawStep (start, 0, 240, 0.1f);
+    CHECK (start.front().tick == 0 && start.front().value == 0.1f && flatAt (start, 0, 240, 0.1f));
+    CHECK (std::abs (lynx::automationCurveAt (start, 300.0) - 0.7f) < 1.0e-6f);
+    // nothing to draw
+    auto same = before;
+    lynx::drawmode::drawStep (same, 500, 500, 0.3f);
+    CHECK (same == before);
+}
+
+TEST (live190ef_draw_mode_switch_and_listeners)
+{
+    using namespace lynx::drawmode;
+    set (false);
+    int calls = 0;
+    bool last = false;
+    const auto id = addListener ([&] (bool on) { ++calls; last = on; });
+    toggle();
+    CHECK (isOn() && calls == 1 && last);
+    set (true); // no change: no call
+    CHECK (calls == 1);
+    toggle();
+    CHECK (! isOn() && calls == 2 && ! last);
+    removeListener (id);
+    toggle();
+    CHECK (calls == 2);
+    set (false);
+}

+ 1 - 0
tests/tests.cpp

@@ -17521,6 +17521,7 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Warp190cgTests.inc"
 #include "Warp190cgTests.inc"
 #include "LiveScr190drTests.inc"
 #include "LiveScr190drTests.inc"
 #include "LiveWf190efMapTests.inc"
 #include "LiveWf190efMapTests.inc"
+#include "LiveWf190efDrawTests.inc"
 #include "BandlabExtras190chTests.inc"
 #include "BandlabExtras190chTests.inc"
 #include "DanceFix190cjTests.inc"
 #include "DanceFix190cjTests.inc"
 #include "Reverb190bzTests.inc"
 #include "Reverb190bzTests.inc"

Kaikkia tiedostoja ei voida näyttää, sillä liian monta tiedostoa muuttui tässä diffissä