Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
C# audioaudio-unitavaloniacpp20cross-platformdawdigital-audio-workstationdspjucelinux-audiomcp-servermidimusicmusic-productionpiano-rollplugin-hostsequencersynthesizervstvst3
(feat) Piano roll: drag while placing a note to move it, set its length or velocity (#45) (#399)
Chris Laupama2b2a3a54c380
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex d6200e2b..12292794 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -52,6 +52,10 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.window**) moves it into the floating window for a second screen; the window's dock buttonbrings it back. Nota remembers whether the Mixer was shown, where and how tall, and restoresit on the next launch.+- **Shape a note while placing it in the piano roll** (#45): after the double-click that adds+ a note, keep the button down and drag to move it (pitch and time); hold ⇧ to set its length+ or ⌘ / Ctrl to drag up and down for its velocity. The next note drawn takes the shaped+ length and velocity.- **The clip editor can fill the window** (#304): with a clip open in the Clip or Pattern tab,the new button at the right of the detail panel's header, **View → Clip editor fills thewindow** or ⌘⇧F (Ctrl+Shift+F) folds away the browser, the Arrangement / Session / Modulardiff --git a/FEATURES.md b/FEATURES.mdindex 5e782a80..3dfdb4c1 100644--- a/FEATURES.md+++ b/FEATURES.md@@ -305,6 +305,10 @@ docks as a panel under any of the three, or floats in its own window — seeeditor; transposing the selection.- A note drawn takes the length and velocity of the note last touched (clicked, moved,resized or velocity-changed); before any note is touched, one grid step at velocity 0.8.+ - **Shape a note as you place it** (#45): keep the button down after the double-click and+ drag — the new note moves (pitch and time, on the grid, ⌥ free); hold ⇧ to drag its+ end and set the length, ⌘ (Ctrl) to drag up / down for velocity. The modifier can change+ mid-drag.- **Note audition** (the speaker switch in the header, on by default): a note sounds whileit is placed, clicked or dragged, re-sounding at each new pitch. Nothing is auditionedwhile a take is recording.diff --git a/specs/066-piano-roll-place-drag/plan.md b/specs/066-piano-roll-place-drag/plan.mdnew file mode 100644index 00000000..cadf461c--- /dev/null+++ b/specs/066-piano-roll-place-drag/plan.md@@ -0,0 +1,43 @@+# Implementation Plan: Shape a note while placing it++**Branch**: `066-piano-roll-place-drag` | **Date**: 2026-10-30 | **Spec**: [spec.md](spec.md)++## Summary++The note grid's double-click placement already captures the pointer (for the audition). It+now also enters a new drag mode, `Place`, on the note just added. Each pointer move reads+the modifiers (`NotePlacementDrag.KindFor`) and, when the kind changed, re-anchors on the+note's current state; the move and length kinds reuse the existing Move / Resize drag code+(Move gains a row offset, `_rowGrab`, 0 for an ordinary note drag so it behaves as before),+the velocity kind maps vertical pixels to MIDI steps (`NotePlacementDrag.Velocity`). The+placement's own commit is the undo step, so the drag streams on the live path without+seeding another; release follows the existing drag release (pending placement, final push+or commit) and remembers the note as last touched.++## Technical Context++C# / .NET 10, Avalonia; no new dependency, no engine or ABI change. Not on the audio thread.++## Audio-thread impact++None. All of it runs on the UI thread inside the note grid's pointer handlers. Notes reach+the engine only through the C ABI calls the roll already makes (`SetClipNotes` /+`SetClipNotesLive` for arrangement clips, `SetSessionNotes` for Session slots), which publish+a new snapshot as before; nothing new runs on the audio thread, so there is no new+allocation, lock, I/O or logging there. Audition uses the existing note-on / note-off path.+Musical time stays with the Transport — the gesture only edits note beats.++## Constitution Check++UI-only, no audio-thread work (above), only the C ABI crosses managed/native, no JUCE+outside `pluginhost/`, SPDX/copyright header on the new file, no new dependency.++## Project Structure++- `src/managed/Nota.Application/Editing/NotePlacementDrag.cs` — pure: modifier → kind,+ drag → velocity.+- `src/managed/Nota.App/PianoRollView.cs` — `NoteGrid`: `Mode.Place`, `AnchorPlace`,+ `DragUpdate` branches, release, edge highlight while setting the length.+- `src/managed/Nota.App/PreferencesWindow.cs` — Shortcuts pane row.+- `tests/Nota.SmokeTest/NoteEditingTests.cs` — place-drag checks.+- `FEATURES.md`, `CHANGELOG.md`.diff --git a/specs/066-piano-roll-place-drag/spec.md b/specs/066-piano-roll-place-drag/spec.mdnew file mode 100644index 00000000..11d6b91f--- /dev/null+++ b/specs/066-piano-roll-place-drag/spec.md@@ -0,0 +1,85 @@+# Feature Specification: Shape a note while placing it++**Feature Branch**: `066-piano-roll-place-drag`++**Created**: 2026-10-30++**Status**: Implemented++**Input**: GitHub issue nota-daw/nota#45 — "Place a note and shape it in one gesture, instead+of placing it and then grabbing it again. While the mouse button is still held after placing+a note, dragging does something useful (choice by modifier or setting): drag horizontally to+set the length, drag to move the note (pitch / time) before releasing, with a modifier drag+vertically to set velocity. Today placement (double-click on empty space) adds the note and+returns; the held mouse does nothing until the next press. Look at FL Studio's piano roll."++## Nota Context++**Feature area**: UI (Avalonia, `src/managed/Nota.App/PianoRollView.cs`) — managed only, no+engine or ABI change.++**Existing behaviour this builds on**: double-click on empty grid adds a note with the length+and velocity of the last note touched (#44), auditions it until the button comes up, and+marks it as a pending placement that overwrites same-pitch notes once let go (specs/007).+Dragging an existing note moves it, dragging its edge resizes it, ⌥ during a drag ignores the+grid (FR-009 of the arrangement), and drags stream to the engine on the live path with one+undo step seeded at the gesture start.++## Clarifications++### Session 2026-10-30++- Q: Modifier or setting to pick what the held drag does? → A: Modifiers, read live, no+ setting. A plain drag moves the note — FL Studio's default, which the reporter points to;+ ⇧ sets the length (the end follows the drag, as dragging the edge does); ⌘ / Ctrl sets+ velocity with a vertical drag. ⌥ keeps meaning "off the grid".+- Q: What happens when the modifier changes mid-drag? → A: The drag switches what it does and+ continues from the note as it is at that moment — nothing jumps.++## User Scenarios & Testing++### User Story 1 - Place and move (P1)++A user double-clicks to add a note, keeps the button down and drags: the note follows the+pointer in pitch and time on the grid (⌥ off it), re-sounding at each new pitch, and lands+where the button comes up.++### User Story 2 - Place and set the length (P1)++Holding ⇧ while dragging after the double-click, the note's end follows the pointer+horizontally (snapped, never shorter than the minimum length); start and pitch stay.++### User Story 3 - Place and set the velocity (P2)++Holding ⌘ (macOS) / Ctrl (Windows, Linux) while dragging after the double-click, dragging up+makes the note louder and down quieter, one MIDI step per 2 px, clamped to 1..127; the note's+shade and the velocity lane follow.++### Edge Cases++- Release without moving: exactly today's placement.+- Losing the pointer (released outside the window) ends the placement drag. Hovering back over the grid does not keep moving the note.+- Switching into length or move mid-drag keeps the note as it is until the pointer actually moves; an off-grid end is not snapped by the switch itself.+- Velocity drag near the viewport edge does not auto-scroll the rows.+- Double-click on a note still deletes it; no drag follows.++## Requirements++- **FR-001**: After a double-click adds a note, while the button stays down, a drag shapes+ that note; the press does not need to be repeated.+- **FR-002**: Plain drag moves the note (pitch and time), snapped unless ⌥ is held.+- **FR-003**: ⇧ drag sets the length by moving the note's end; ⌘/Ctrl drag sets the velocity+ vertically. ⌘/Ctrl wins when both are held. Modifiers are read on every move.+- **FR-004**: Switching modifiers mid-drag re-anchors on the note's current state.+- **FR-005**: The placement stays pending (overwrites on let-go) exactly as before; the+ shaped note becomes the "last touched" note, so the next one drawn takes its length and+ velocity.+- **FR-006**: In the arrangement's editor the placement and its drag are one undo step+ (the live path); the Shortcuts pane and FEATURES.md list the gesture.++## Success Criteria++- **SC-001**: A note can be placed and given a different pitch, length or velocity in one+ press–drag–release.+- **SC-002**: `scripts/build-linux.sh` passes, including the new place-drag checks in the+ note-editing smoke tests.diff --git a/specs/066-piano-roll-place-drag/tasks.md b/specs/066-piano-roll-place-drag/tasks.mdnew file mode 100644index 00000000..e44e52d1--- /dev/null+++ b/specs/066-piano-roll-place-drag/tasks.md@@ -0,0 +1,14 @@+# Tasks: Shape a note while placing it++**Input**: [spec.md](spec.md), [plan.md](plan.md)++- [x] T001 [US1–3] `NotePlacementDrag` (kind from modifiers, velocity from drag) in+ `src/managed/Nota.Application/Editing/NotePlacementDrag.cs`+- [x] T002 [US1] `Mode.Place` entered by the double-click placement; plain drag moves the+ note through the Move path with `_rowGrab` in `src/managed/Nota.App/PianoRollView.cs`+- [x] T003 [US2] ⇧ drag runs the Resize path; edge highlight while it does+- [x] T004 [US3] ⌘/Ctrl drag sets velocity; no auto-scroll while it does+- [x] T005 Re-anchor on a modifier change (FR-004); remember the note on release (FR-005)+- [x] T006 Smoke checks in `tests/Nota.SmokeTest/NoteEditingTests.cs`+- [x] T007 Shortcuts pane (`PreferencesWindow.cs`), `FEATURES.md`, `CHANGELOG.md`+- [x] T008 `scripts/build-linux.sh` passesdiff --git a/src/managed/Nota.App/PianoRollView.cs b/src/managed/Nota.App/PianoRollView.csindex b5f0b280..89a96422 100644--- a/src/managed/Nota.App/PianoRollView.cs+++ b/src/managed/Nota.App/PianoRollView.cs@@ -1859,7 +1859,8 @@ public sealed partial class PianoRollView : UserControlprivate readonly PianoRollView _o;// PlayheadPending: pressed on the playhead line over empty space — a drag scrubs the// transport (Scrub), a click without movement stays an ordinary empty-space click.- private enum Mode { None, Move, Resize, ResizeLeft, Marquee, PlayheadPending, Scrub }+ // Place: the button is still down after the double-click that added a note (#45).+ private enum Mode { None, Move, Resize, ResizeLeft, Marquee, PlayheadPending, Scrub, Place }private double _pressX;private const double PlayheadGrabPx = 3, ScrubSlop = 3;private Mode _drag = Mode.None;@@ -1872,6 +1873,13 @@ public sealed partial class PianoRollView : UserControlprivate int _primary = -1;private double _grabBeat; // pointer-beat minus primary start, at grab (Move)private double _edgeGrab; // pointer beat minus the grabbed edge at press (Resize / ResizeLeft)+ private int _rowGrab; // pointer row minus the primary's row at grab (Move)++ // Place: what the held drag does now (re-anchored when the modifiers change it) and+ // where a velocity drag started.+ private PlaceDragKind _placeKind;+ private double _velY;+ private float _velAnchor;// Marquee (grid coords) + the selection to union with when additive.private Point _marqueeA, _marqueeB;@@ -1886,6 +1894,7 @@ public sealed partial class PianoRollView : UserControlprivate static readonly Cursor ArrowCursor = new(StandardCursorType.Arrow);private static readonly Cursor ResizeCursor = new(StandardCursorType.SizeWestEast);private static readonly Cursor MoveCursor = new(StandardCursorType.SizeAll);+ private static readonly Cursor VelocityCursor = new(StandardCursorType.SizeNorthSouth);private const double EdgePx = 6;// Live drag (feature): the pre-drag note list (to seed one undo entry) + whether the@@ -2002,7 +2011,8 @@ public sealed partial class PianoRollView : UserControl}if (n.ExprId > 0 || _o._expr.Editing(i)) DrawExpression(ctx, i, n, r, sel, ppb);// Resize-edge affordance: a bright bar on the edge a drag would trim.- bool edgeHi = ((_drag == Mode.Resize || _drag == Mode.ResizeLeft) && sel) || (_drag == Mode.None && _hoverNote == i && !_o.IsLocked(i));+ bool edgeHi = ((_drag == Mode.Resize || _drag == Mode.ResizeLeft || (_drag == Mode.Place && _placeKind == PlaceDragKind.Length)) && sel)+ || (_drag == Mode.None && _hoverNote == i && !_o.IsLocked(i));if (edgeHi){bool left = _drag == Mode.ResizeLeft || (_drag == Mode.None && _hoverLeft);@@ -2157,6 +2167,14 @@ public sealed partial class PianoRollView : UserControl_o._placementPending = true; // a drawn note overwrites what it lands on_o.Audition(nt.Pitch, nt.Velocity, slot: slot); // heard until the button comes upe.Pointer.Capture(this);+ // Still held, a drag shapes the new note. The commit below is the gesture's+ // one undo step, so the drag streams on the live path without seeding another.+ _primary = _o._notes.Count - 1;+ _dragMoved = false;+ _liveStarted = true;+ _drag = Mode.Place;+ AnchorPlace(p, PlaceKind(e.KeyModifiers));+ _lastGrid = p;}_o.Invalidate(); _o.CommitNotes(); _o.Changed?.Invoke();e.Handled = true;@@ -2204,7 +2222,7 @@ public sealed partial class PianoRollView : UserControl_edgeGrab = XToBeat(p.X) - (edge > 0 ? g.start + g.len : g.start);Cursor = ResizeCursor; _cursorKind = 1;}- else { _drag = Mode.Move; _grabBeat = XToBeat(p.X) - _o._notes[hit].StartBeat; Cursor = MoveCursor; _cursorKind = 2; }+ else { _drag = Mode.Move; _grabBeat = XToBeat(p.X) - _o._notes[hit].StartBeat; _rowGrab = 0; Cursor = MoveCursor; _cursorKind = 2; }_lastGrid = p;_o.Invalidate(); _o.Changed?.Invoke();}@@ -2228,53 +2246,113 @@ public sealed partial class PianoRollView : UserControlif (_drag == Mode.PlayheadPending && Math.Abs(p.X - _pressX) >= ScrubSlop) _drag = Mode.Scrub;if (_drag == Mode.Scrub) _o.SeekAtX(p.X, _free);if (_drag is Mode.PlayheadPending or Mode.Scrub) return;+ // Capture can already be gone (released outside the window): a later hover must not+ // keep shaping the note.+ if (_drag == Mode.Place && !e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)+ {+ EndDrag();+ return;+ }+ if (_drag == Mode.Place)+ {+ var kind = PlaceKind(e.KeyModifiers);+ if (kind != _placeKind) AnchorPlace(p, kind);+ }_lastGrid = p;DragUpdate(p);- EvaluateAutoScroll(p);+ if (_drag == Mode.Place && _placeKind == PlaceDragKind.Velocity) StopAutoScroll();+ else EvaluateAutoScroll(p);+ }++ private static PlaceDragKind PlaceKind(KeyModifiers m)+ => NotePlacementDrag.KindFor((m & KeyModifiers.Shift) != 0, (m & (KeyModifiers.Control | KeyModifiers.Meta)) != 0);++ // Start (or restart, when the modifiers switch what the drag does) shaping the placed+ // note from where it is now, so switching mid-drag never makes it jump.+ private void AnchorPlace(Point p, PlaceDragKind kind)+ {+ var n = _o._notes[_primary];+ _orig.Clear();+ _orig[_primary] = (n.StartBeat, n.Pitch, n.LengthBeats, _o._owner[_primary]);+ _placeKind = kind;+ _grabBeat = XToBeat(p.X) - n.StartBeat;+ _rowGrab = (int)Math.Floor(p.Y / RowH) - _o._rows.NearestRow(n.Pitch);+ _edgeGrab = XToBeat(p.X) - (n.StartBeat + n.LengthBeats);+ _velY = p.Y; _velAnchor = n.Velocity;+ (Cursor, _cursorKind) = kind switch+ {+ PlaceDragKind.Length => (ResizeCursor, 1),+ PlaceDragKind.Velocity => (VelocityCursor, 3),+ _ => (MoveCursor, 2),+ };}// Apply the current drag using a grid-space point (also re-used by auto-scroll).private void DragUpdate(Point p){- if (_drag == Mode.Move)+ var place = _drag == Mode.Place ? _placeKind : (PlaceDragKind?)null;+ if (_drag == Mode.Move || place == PlaceDragKind.Move){- double targetStart = Snap(XToBeat(p.X) - _grabBeat);var pr = _orig[_primary];+ double rawStart = XToBeat(p.X) - _grabBeat;+ // A modifier switch re-anchors on the note as it is. Snapping that beat on the+ // same move would shove an off-grid note before the pointer has moved.+ double targetStart = place == PlaceDragKind.Move+ ? NotePlacementDrag.BeatAfter(pr.start, rawStart - pr.start, Snap)+ : Snap(rawStart);double dBeat = targetStart - pr.start;// Rows, not semitones: folded, the group moves between visible rows (specs/045).- int dRows = _o._rows.NearestRow(pr.pitch) - (int)Math.Floor(p.Y / RowH);+ int dRows = _o._rows.NearestRow(pr.pitch) - ((int)Math.Floor(p.Y / RowH) - _rowGrab);// Clamp the shared delta so the whole group stays in-bounds (keeps shape): every// start within its reach — its clip and the open clips of its track it touches.var (lo, hi) = _o.ShiftRange(_orig.Keys, i => (_orig[i].start, _orig[i].len, _orig[i].owner), endsInside: false);dBeat = Math.Clamp(dBeat, lo, hi);dRows = _o.ClampRows(_orig.Values.Select(v => v.pitch), dRows);- foreach (var kv in _orig)+ // A modifier switch lands on the note as it is: nothing to apply until the result+ // differs from the note now (not from the anchor, or dragging back would stick).+ var cur = _o._notes[_primary];+ if (place != PlaceDragKind.Move || Math.Abs(pr.start + dBeat - cur.StartBeat) >= 1e-9+ || _o._rows.Step(pr.pitch, dRows) != cur.Pitch){- var n = _o._notes[kv.Key];- n.StartBeat = kv.Value.start + dBeat;- n.Pitch = _o._rows.Step(kv.Value.pitch, dRows);- _o._notes[kv.Key] = n;- _o._owner[kv.Key] = _o._set.OwnerAfterMove(kv.Value.owner, n.StartBeat);+ foreach (var kv in _orig)+ {+ var n = _o._notes[kv.Key];+ n.StartBeat = kv.Value.start + dBeat;+ n.Pitch = _o._rows.Step(kv.Value.pitch, dRows);+ _o._notes[kv.Key] = n;+ _o._owner[kv.Key] = _o._set.OwnerAfterMove(kv.Value.owner, n.StartBeat);+ }+ _dragMoved = true;+ PushLive();+ // A drag to a new pitch re-triggers the grabbed note there (#46).+ _o.Audition(_o._notes[_primary].Pitch, _o._notes[_primary].Velocity, slot: _o._owner[_primary]);}- _dragMoved = true;- PushLive();- // A drag to a new pitch re-triggers the grabbed note there (#46).- _o.Audition(_o._notes[_primary].Pitch, _o._notes[_primary].Velocity, slot: _o._owner[_primary]);}- else if (_drag == Mode.Resize)+ else if (_drag == Mode.Resize || place == PlaceDragKind.Length){// The grabbed note's end lands on the grid (not just the drag distance); the- // rest of the selection changes by the same amount.+ // rest of the selection changes by the same amount. A placement length-drag+ // keeps an off-grid end until the pointer actually moves horizontally.var pr = _orig[_primary];- double dLen = Snap(XToBeat(p.X) - _edgeGrab) - (pr.start + pr.len);- foreach (var kv in _orig)+ double anchoredEnd = pr.start + pr.len;+ double rawEnd = XToBeat(p.X) - _edgeGrab;+ double newEnd = place == PlaceDragKind.Length+ ? NotePlacementDrag.BeatAfter(anchoredEnd, rawEnd - anchoredEnd, Snap)+ : Snap(rawEnd);+ double dLen = newEnd - anchoredEnd;+ // Compared with the note now, not the anchor: dragging back must undo the extension.+ if (place != PlaceDragKind.Length+ || Math.Abs(Math.Max(_o.MinNoteLen, pr.len + dLen) - _o._notes[_primary].LengthBeats) >= 1e-9){- var n = _o._notes[kv.Key];- n.LengthBeats = Math.Max(_o.MinNoteLen, kv.Value.len + dLen);- _o._notes[kv.Key] = n;+ foreach (var kv in _orig)+ {+ var n = _o._notes[kv.Key];+ n.LengthBeats = Math.Max(_o.MinNoteLen, kv.Value.len + dLen);+ _o._notes[kv.Key] = n;+ }+ _dragMoved = true;+ PushLive();}- _dragMoved = true;- PushLive();}else if (_drag == Mode.ResizeLeft){@@ -2297,6 +2375,18 @@ public sealed partial class PianoRollView : UserControl_dragMoved = true;PushLive();}+ else if (place == PlaceDragKind.Velocity)+ {+ var n = _o._notes[_primary];+ float v = NotePlacementDrag.Velocity(_velAnchor, p.Y - _velY);+ if (v != n.Velocity)+ {+ n.Velocity = v;+ _o._notes[_primary] = n;+ _dragMoved = true;+ PushLive();+ }+ }else if (_drag == Mode.Marquee){_marqueeB = p;@@ -2344,7 +2434,10 @@ public sealed partial class PianoRollView : UserControlprotected override void OnPointerCaptureLost(PointerCaptureLostEventArgs e){_o.StopAudition();- if (_drag is Mode.PlayheadPending or Mode.Scrub) _drag = Mode.None;+ // A placement drag must not survive the capture: the button is up, and the next+ // hover would otherwise keep moving the note.+ if (_drag == Mode.Place) EndDrag();+ else if (_drag is Mode.PlayheadPending or Mode.Scrub) _drag = Mode.None;base.OnPointerCaptureLost(e);}@@ -2357,12 +2450,20 @@ public sealed partial class PianoRollView : UserControlprotected override void OnPointerReleased(PointerReleasedEventArgs e){- StopAutoScroll();_o.StopAudition();if (_drag == Mode.None) { e.Pointer.Capture(null); return; }+ EndDrag();+ e.Pointer.Capture(null);+ }++ // Release and capture-loss share this: a placement gesture must finish (and stop+ // auto-scroll) the moment the pointer is no longer ours.+ private void EndDrag()+ {+ StopAutoScroll();+ if (_drag == Mode.None) return;var was = _drag;_drag = Mode.None;- e.Pointer.Capture(null);Avalonia.Threading.Dispatcher.UIThread.Post(_o.ApplyDeferredFold); // after the edit landsif (was is Mode.PlayheadPending or Mode.Scrub){@@ -2371,7 +2472,7 @@ public sealed partial class PianoRollView : UserControlreturn;}_orig.Clear();- if ((was == Mode.Resize || was == Mode.ResizeLeft) && _dragMoved) _o.Remember(_primary);+ if (was is Mode.Resize or Mode.ResizeLeft or Mode.Place && _dragMoved) _o.Remember(_primary);if (was != Mode.Marquee && _dragMoved){_o._placementPending = true; // overwrites once the selection is let godiff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.csindex 9024571b..9a0c80b4 100644--- a/src/managed/Nota.App/PreferencesWindow.cs+++ b/src/managed/Nota.App/PreferencesWindow.cs@@ -1455,6 +1455,7 @@ public sealed partial class PreferencesWindow : NotaWindow("Esc", "Deselect · moved or pasted notes replace the notes under them"),("Delete", "Delete the selected notes"),("Double-click empty grid", "Add a note with the length and velocity of the last note touched · on a note, delete it"),+ ("Double-click and hold, drag", "Shape the new note: move it · ⇧ set its length · ⌘ drag up / down for velocity"),("Drag note edge", "Change the note's start or end"),("Click · drag the ruler", "Move the playhead there · drag to scrub, snapped to the grid · ⌥ off the grid"),("Drag the playhead line", "Scrub the playhead · on the ruler or over empty grid"),diff --git a/src/managed/Nota.Application/Editing/NotePlacementDrag.cs b/src/managed/Nota.Application/Editing/NotePlacementDrag.csnew file mode 100644index 00000000..9ed2bc6b--- /dev/null+++ b/src/managed/Nota.Application/Editing/NotePlacementDrag.cs@@ -0,0 +1,34 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.+//+// Shaping a note while it is placed (specs/066-piano-roll-place-drag, #45): after the+// double-click that adds a note, dragging with the button still held moves it, ⇧ sets its+// length, ⌘/Ctrl its velocity. Pure and UI-free: the smoke test drives it directly.++using System;++namespace Nota.Application.Editing;++public enum PlaceDragKind { Move, Length, Velocity }++public static class NotePlacementDrag+{+ /// <summary>Pixels of vertical drag per MIDI velocity step (full range in ~250 px).</summary>+ public const double PxPerVelocityStep = 2;++ /// <summary>What the held drag does, read live from the modifiers: ⌘/Ctrl wins over ⇧.</summary>+ public static PlaceDragKind KindFor(bool shift, bool command)+ => command ? PlaceDragKind.Velocity : shift ? PlaceDragKind.Length : PlaceDragKind.Move;++ /// <summary>The velocity after dragging <paramref name="dyPx"/> pixels down from where+ /// the velocity drag started at <paramref name="anchor"/>: up is louder, clamped to 1..127.</summary>+ public static float Velocity(float anchor, double dyPx)+ => NoteOverwrite.VelocityBy(anchor, (int)Math.Round(-dyPx / PxPerVelocityStep));++ /// <summary>Where a beat that was <paramref name="anchored"/> when this drag (or a modifier+ /// switch) started should sit after the pointer moves <paramref name="deltaBeats"/>. No+ /// movement keeps the anchored beat, so switching into the mode never snaps an off-grid+ /// note; later movement snaps the beat the pointer now points at.</summary>+ public static double BeatAfter(double anchored, double deltaBeats, Func<double, double> snap)+ => Math.Abs(deltaBeats) < 1e-9 ? anchored : snap(anchored + deltaBeats);+}diff --git a/tests/Nota.SmokeTest/NoteEditingTests.cs b/tests/Nota.SmokeTest/NoteEditingTests.csindex 59b209b7..e11c3cac 100644--- a/tests/Nota.SmokeTest/NoteEditingTests.cs+++ b/tests/Nota.SmokeTest/NoteEditingTests.cs@@ -128,5 +128,23 @@ internal static class NoteEditingTestsyield return (Midi(NoteOverwrite.VelocityBy(3 / 127f, -10)) == 1, "velocity: clamps at 1, never 0");var fine = NoteOverwrite.VelocityBy(0.8f, 1);yield return (Midi(fine) == (int)Math.Round(0.8 * 127) + 1 && OnStep(fine), "velocity: fine step lands on an integer MIDI value");++ // ---- shaping a note while placing it (specs/066, #45) -----------------------------+ yield return (NotePlacementDrag.KindFor(false, false) == PlaceDragKind.Move, "place drag: plain drag moves the new note");+ yield return (NotePlacementDrag.KindFor(true, false) == PlaceDragKind.Length, "place drag: ⇧ drag sets its length");+ yield return (NotePlacementDrag.KindFor(false, true) == PlaceDragKind.Velocity+ && NotePlacementDrag.KindFor(true, true) == PlaceDragKind.Velocity, "place drag: ⌘/Ctrl drag sets its velocity, over ⇧");+ double step = NotePlacementDrag.PxPerVelocityStep;+ yield return (Midi(NotePlacementDrag.Velocity(64 / 127f, -10 * step)) == 74, "place drag: dragging up 10 steps is 10 louder");+ yield return (Midi(NotePlacementDrag.Velocity(64 / 127f, 10 * step)) == 54, "place drag: dragging down is quieter");+ yield return (NotePlacementDrag.Velocity(64 / 127f, 0) == 64 / 127f, "place drag: no vertical movement keeps the velocity");+ yield return (Midi(NotePlacementDrag.Velocity(0.8f, -1000)) == 127 && Midi(NotePlacementDrag.Velocity(0.8f, 1000)) == 1,+ "place drag: velocity clamps to 1..127");+ // Half-beat grid: 0.7 snaps to 0.5. Switching into length (no pointer movement) must not.+ static double Half(double b) => Math.Round(b * 2) / 2;+ yield return (NotePlacementDrag.BeatAfter(0.7, 0, Half) == 0.7,+ "place drag: switching mode keeps an off-grid end");+ yield return (NotePlacementDrag.BeatAfter(0.7, 0.2, Half) == 1.0,+ "place drag: a later horizontal drag snaps the end");}}