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) Snap grid in the audio clip editor
Egor Khindikaynencfaabd8127b9
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex c2dfd2ce..801b370a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -36,13 +36,18 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.shortcuts act on the editor you used last: **⌘1 / ⌘2** narrow / widen the grid (in Auto,the density), **⌘3** triplets, **⌘4** snap on / off, **⌘5** Auto ↔ fixed (Ctrl onWindows and Linux; also under **Edit → Grid**). The settings are remembered app-wide,- separately for each editor. Holding **⌥ / Alt** while dragging now moves notes freely- in the piano roll too.+ one for the arrangement and one shared by the clip editors. Holding **⌥ / Alt** while+ dragging now moves notes freely in the piano roll too.+- **Snap grid in the audio clip editor:** the trim brackets, warp markers and clip-envelope+ points snap to the grid drawn in the waveform, with the same chip, menu and shortcuts as+ the piano roll (they share one setting). Warp markers follow snap on / off and ⌥ — they+ used to stick to whole beats.### Changed- **Grid controls:** clicking the toolbar's GRID cell (and the new grid chip in the pianoroll's header) opens a menu with every grid option instead of cycling through five- values. The arrangement now draws sub-beat lines when zoomed in. The piano roll's GRID+ values. The arrangement now draws sub-beat lines when zoomed in. The audio clip editor's+ Snap switch is replaced by the grid chip. The piano roll's GRIDsection is now **QUANTIZE**: Quantize and the clip tools use their own step (1/16 bydefault, triplets available), which no longer changes with the zoom. Press **⌘5** to goback to a fixed grid.diff --git a/FEATURES.md b/FEATURES.mdindex fa37c726..4547c5dd 100644--- a/FEATURES.md+++ b/FEATURES.md@@ -102,14 +102,15 @@ the mixer opens as a separate floating window (**View → Mixer**, ⌘M).and the name prints only at the head of each run so a repeated pattern reads as oneblock. View ▸ Clip names cycles every clip / first of a run / none; a clip named byhand always shows its name.-- **Snap grid** (arrangement and piano roll, each with its own setting, remembered- app-wide): **Auto** follows the zoom so you snap to the lines you see — finer as you zoom- in, whole bars zoomed out — in **Narrow / Medium / Wide** density; or a fixed step from- 1/32 to 4 bars (its label dims when it is finer than the drawn lines). **Triplets** in- both modes. The toolbar's GRID cell and the piano roll's header chip open a menu with- every option; ⌘1 / ⌘2 narrow / widen (in Auto, the density), ⌘3 triplets, ⌘4 snap- on / off, ⌘5 Auto ↔ fixed (also Edit → Grid), acting on the editor used last. Hold ⌥ to- drag freely; clip edges still attract a dragged clip.+- **Snap grid** (the arrangement, and the clip editors — piano roll and audio — which+ share one setting; remembered app-wide): **Auto** follows the zoom so you snap to the+ lines you see — finer as you zoom in, whole bars zoomed out — in **Narrow / Medium /+ Wide** density; or a fixed step from 1/32 to 4 bars (its label dims when it is finer+ than the drawn lines). **Triplets** in both modes. The toolbar's GRID cell and the piano+ roll's header chip open a menu with every option, as does the audio clip editor's header+ (trim brackets, warp markers and envelope points snap); ⌘1 / ⌘2 narrow / widen (in Auto,+ the density), ⌘3 triplets, ⌘4 snap on / off, ⌘5 Auto ↔ fixed (also Edit → Grid), acting+ on the editor used last. Hold ⌥ to drag freely; clip edges still attract a dragged clip.- **Session View** — a clip grid (tracks × scenes) with an inspector: named, coloured clipswith note / waveform previews and a progress pie on the clip's own clock; selection apartfrom launching, keyboard editing (arrows, Return, ⌘C/X/V, ⌘D, ⌘I, F2, Delete) and drag@@ -316,7 +317,8 @@ the mixer opens as a separate floating window (**View → Mixer**, ⌘M).The first use offers to download the model.- **Warp / time-stretch**: **Complex** and **Complex Pro** modes (the latter with formantpreservation, correct even when the sample rate and the device rate differ), plus- transient detection. A grid-snap toggle governs trimming a warped clip.+ transient detection. Trim brackets, warp markers and envelope points snap to the clip+ editors' snap grid.- **Changing the sample rate** does not break third-party plugins or warped clips — thecaches are rebuilt once when the rate changes.diff --git a/specs/003-adaptive-snap-grid/contracts/grid-ui.md b/specs/003-adaptive-snap-grid/contracts/grid-ui.mdindex 35d3eb2e..3d87b940 100644--- a/specs/003-adaptive-snap-grid/contracts/grid-ui.md+++ b/specs/003-adaptive-snap-grid/contracts/grid-ui.md@@ -18,13 +18,16 @@ Settings → Shortcuts.- Target editor (research R9): the piano roll if the detail area was used last and aMIDI clip editor is showing, otherwise the arrangement.- Each command sets the status line to `"<Editor> grid: <control label>"`, for example- "Arrangement grid: Auto · 1/4" or "Piano roll grid: Snap off" (FR-014).+ "Arrangement grid: Auto · 1/4" or "Clip editor grid: Snap off" (FR-014). The piano roll+ and the audio clip editor share one setting and are both "Clip editor".+- Target editor: the clip editor (MIDI or audio) if the detail area was used last and one+ is open, otherwise the arrangement.- The commands are always available; the palette never greys them out.- Menu: Edit → Grid submenu with the five items, in this order.## Settings → Shortcuts-A new group `GRID (ARRANGEMENT OR PIANO ROLL — WHICHEVER YOU USED LAST)`:+A new group `GRID (ARRANGEMENT OR CLIP EDITOR — WHICHEVER YOU USED LAST)`:| Keys | Description ||------|-------------|@@ -43,6 +46,7 @@ effect.|--------|----------|----------|| Arrangement | The existing toolbar cell `SnapChip` / `SnapLabel` | Forward-only cycling (`OnCycleSnap`) || Piano roll | A new chip in the clip-editor header's right group, before Scale | The GRID dropdown's role as the snap step |+| Audio clip editor | The same chip in its header's right group, before the file format | The Snap switch (trim only, whole beats) |### Label statesdiff --git a/specs/003-adaptive-snap-grid/plan.md b/specs/003-adaptive-snap-grid/plan.mdindex 7c6d0d6a..adeeacb4 100644--- a/specs/003-adaptive-snap-grid/plan.md+++ b/specs/003-adaptive-snap-grid/plan.md@@ -142,6 +142,15 @@ to `ArrangementGrid.SnapOn` in both directions.`TryMenuShortcut` path on Windows and Linux).- A GRID group in Settings → Shortcuts. The palette smoke test enforces it.+### 7a. Audio clip editor — `AudioClipEditorView.cs` (US4, research R13)++The header's Snap switch is replaced by a `SnapChip(EditorKind.PianoRoll, …)` that reads+the drawn axis. `WaveformView` resolves the grid per axis. It replaces the static+`SnapBeat` (whole beats) and the private `BeatStep` grid thinning with `SnapGrid.SnapBeat`+and `SnapGrid.GridLines`, honours `SnapOn` and Alt for the trim brackets, the warp markers+(add and drag) and the envelope points (add and drag), and draws the grid on the envelope+axis in Envelope mode. `GridTarget()` and the status line cover it (FR-021).+### 7. Tests — `tests/Nota.SmokeTest/SnapGridTests.cs` (new) + `Program.cs`A `--grid` flag and an entry in the full run, following the `TapTempoTests` pattern. The@@ -181,6 +190,7 @@ src/managed/├── ArrangementView.Controls.cs # ruler/footer grid lines├── PianoRollView.cs # _resolved, BeatsPerBar, nudges, quantize├── PianoRollView.Expression.cs # lane grid lines+ ├── AudioClipEditorView.cs # US4: chip, grid per axis, snapping (R13)├── MidiToolsView.cs # MidiToolContext.Grid = Quantize step (R11)├── ClipPropsView.cs # GRID → QUANTIZE├── ClipEditorView.cs # header SnapChipdiff --git a/specs/003-adaptive-snap-grid/research.md b/specs/003-adaptive-snap-grid/research.mdindex dcd299a5..1d3068fd 100644--- a/specs/003-adaptive-snap-grid/research.md+++ b/specs/003-adaptive-snap-grid/research.md@@ -147,9 +147,28 @@ Assumptions or the plan's Technical Context.together preserves current behaviour.- **Alternatives considered**: The snap step in effect (zoom-dependent output).+## R13 — The audio clip editor (US4, Clarifications Q6–Q7)++- **Decision**: `AudioClipEditorView` reads the piano roll's setting+ (`EditorKind.PianoRoll`, used for "the clip editor") and gets the same `SnapChip` in+ place of its Snap switch. It has two beat axes:+ - **warp beats** (`BeatToX`, mirrored when reversed) for the grid lines, the trim+ brackets and the warp markers, at `ppb = zoom · width / TotalBeats`;+ - **played clip beats** (`EnvBeatToX`, never mirrored) for the envelope, at+ `ppb = zoom · width / clipBeats`.+ Each axis resolves its own `ResolvedGrid`. In Envelope mode the lines are drawn on the+ envelope axis, otherwise on the warp axis. The header chip shows the axis that is+ drawn. Bars are 4 beats, as everywhere in the app (the editor's `BeatsPerBar` constant).+- **Rationale**: Lines and snapping must agree (FR-005) on whichever timeline the user is+ editing. A trimmed clip's played beats are offset from its warp beats, so one shared+ axis would put envelope points between the lines.+- **Alternatives considered**: Warp axis for everything (envelope points off the drawn+ lines on trimmed clips). A third, separate setting (rejected in Q6).+- **Shortcut target**: `GridTarget()` returns the clip editor when the detail area was used+ last and either a MIDI or an audio clip editor is open. The status line reads "Clip+ editor grid: …" for both, since they share the setting.+## R12 — Out-of-scope neighbours noted during research-- The audio clip editor (`AudioClipEditorView`) has its own "snap trim to whole beats"- switch. It is not part of either editor's grid and stays as is.- Song sections keep `SnapBar` (whole bars), per the spec.- MCP tools and Nota Remote do not expose the snap grid; unchanged.diff --git a/specs/003-adaptive-snap-grid/spec.md b/specs/003-adaptive-snap-grid/spec.mdindex 5a8b13e5..de386eb4 100644--- a/specs/003-adaptive-snap-grid/spec.md+++ b/specs/003-adaptive-snap-grid/spec.md@@ -47,6 +47,9 @@ expectations), [`BUILD.md`](../../BUILD.md), [`DESIGN.md`](../../DESIGN.md),- Q: What step does piano-roll Quantize use when the grid is adaptive? → A: Its own Quantize value in the GRID panel (default 1/16, triplets available), independent of the grid mode and zoom.- Q: Are the arrangement and piano-roll grid settings independent or shared? → A: Independent — each editor has its own mode, density, fixed step, triplets and snap on/off.- Q: In Fixed mode, what is drawn when the chosen step's lines would merge at a far zoom? → A: Lines are thinned to the density threshold; snapping still uses the chosen step; the snap control marks that the step is finer than the visible grid.+- Q: How does the arrangement's two-line toolbar cell show Adaptive mode? → A: Step on top, "AUTO GRID" caption below ("GRID" when Fixed), instead of "Auto · <step>" on one line.+- Q: Does the audio clip editor get the grid, and with which setting? → A: Yes, as a fourth story. It shares the piano roll's setting: both are the clip editor in the detail panel, one chip and one setting.+- Q: What snaps in the audio clip editor? → A: The trim brackets, warp markers and envelope points.## User Scenarios & Testing *(mandatory)*@@ -144,6 +147,35 @@ snapped positions fall on triplet divisions at several zoom levels and with a fi---+### User Story 4 - The same grid in the audio clip editor (Priority: P2)++A user warps a drum loop and trims it in the audio clip editor. As in the piano roll, they+zoom in to place a warp marker on a sixteenth, zoom out to trim to whole bars, and draw+clip-envelope points on the lines they see. The grid control sits in the editor's header,+where the old on/off Snap switch was.++**Why this priority**: The audio editor draws a grid that subdivides with zoom but snaps+only to whole beats — the original complaint, in a second editor. Without it the feature+is half done for audio users.++**Independent Test**: Open a warped audio clip, zoom in and out, and drag a warp marker, a+trim bracket and an envelope point. Each lands on a drawn line, and the header chip shows+the step.++**Acceptance Scenarios**:++1. **Given** a warped audio clip zoomed in until sixteenth lines are drawn, **When** the+ user drags a warp marker, **Then** it lands on the nearest drawn sixteenth line.+2. **Given** the same clip zoomed out to bar lines, **When** the user drags a trim bracket,+ **Then** the edge lands on a bar line.+3. **Given** Envelope mode, **When** the user adds or drags an envelope point, **Then** its+ time lands on a drawn line of the envelope's own timeline.+4. **Given** the piano roll was set to Fixed 1/8, **When** the user opens an audio clip,+ **Then** the audio editor's chip reads "1/8": the two clip editors share one setting.+5. **Given** any of these drags, **When** the user holds Alt, **Then** the item moves freely.++---+### Edge Cases- **Extreme zoom-in**: adaptive never goes finer than 1/32 (1/32T with triplets), even if@@ -170,6 +202,11 @@ snapped positions fall on triplet divisions at several zoom levels and with a fipiano roll). When neither has focus (for example after clicking a toolbar button or adevice card), they act on the editor the user last worked in.- **Text entry**: shortcuts do not fire while the user types in a text field.+- **Unwarped audio clips**: they have no beat grid, so the trim brackets keep moving by+ source frames and no beat lines are drawn. The envelope still uses the clip's played+ timeline, so in Envelope mode lines and snapping work as for a warped clip.+- **Reversed audio clips**: the grid mirrors with the waveform, as the beat lines do today.+ The envelope stays in playing order (left to right), and so does its grid.## Requirements *(mandatory)*@@ -224,7 +261,9 @@ snapped positions fall on triplet divisions at several zoom levels and with a fi- **FR-011**: Each editor MUST have a snap control showing the current state: "Auto · <step>"in Adaptive mode (the step updates live with zoom), "<step>" in Fixed mode, a triplet- suffix "T" when applicable, and a clear off state when Snap is off.+ suffix "T" when applicable, and a clear off state when Snap is off. The arrangement's+ toolbar cell MAY split this over its two lines to stay narrow: the step on top and the+ caption "AUTO GRID" (Adaptive) or "GRID" (Fixed) below.- **FR-012**: Clicking the snap control MUST open a menu with: Adaptive Narrow / Medium /Wide, each fixed step from FR-002, a Triplets toggle, and Snap on/off, with the currentchoice marked. Choosing an item MUST apply it immediately. This menu MUST replace the@@ -243,6 +282,22 @@ snapped positions fall on triplet divisions at several zoom levels and with a fi- **FR-015**: The new shortcuts MUST appear in Preferences → Shortcuts and in the app menuwhere editing commands are listed.+**Audio clip editor**++- **FR-018**: The audio clip editor MUST use the piano roll's grid setting (one setting+ for both clip editors) and show it with the same chip and menu in its header. The chip+ MUST replace the old Snap switch.+- **FR-019**: For warped clips, the trim brackets and warp markers MUST snap to the step in+ effect, resolved from the editor's zoom on the warp-beat axis. The drawn beat lines MUST+ come from the same positions. Warp markers MUST follow snap on/off and Alt (today they+ always snap to whole beats).+- **FR-020**: In Envelope mode, envelope points MUST snap in time to the step in effect on+ the envelope's own timeline (the clip's played beats), and the drawn lines MUST follow+ that timeline. The value axis is not snapped.+- **FR-021**: The grid shortcuts MUST act on the audio clip editor when it is the clip+ editor used last, as they do for the piano roll. The status line names it "Clip editor+ grid".+**Defaults and persistence**- **FR-016**: On first launch (no saved preference) both editors MUST start in@@ -253,7 +308,7 @@ snapped positions fall on triplet divisions at several zoom levels and with a fi### Key Entities-- **Grid setting** (one per editor): mode (Adaptive or Fixed), density (Narrow, Medium,+- **Grid setting** (one for the arrangement, one shared by the two clip editors): mode (Adaptive or Fixed), density (Narrow, Medium,Wide; remembered while in Fixed), fixed step (remembered while in Adaptive), tripletson/off, snap on/off.- **Quantize value** (piano roll only): a straight or triplet step used by Quantize,@@ -288,8 +343,9 @@ snapped positions fall on triplet divisions at several zoom levels and with a ficlose to its current default.- 1/64 and 1/32T exist today only in the piano roll's fixed list. 1/64 is dropped and theladder stops at 1/32 in both editors. 1/32T stays as the finest triplet step.-- The two editors share only the rule that computes the step in effect, not the setting- itself (FR-001).+- The arrangement and the clip editors share only the rule that computes the step in+ effect, not the setting itself (FR-001). The piano roll and the audio clip editor share+ the setting too (FR-018).- ⌘1–⌘5 are currently unused in Nota. If the plan finds a conflict, the binding moves andthe spec is updated.- The MCP and Remote surfaces are out of scope. They do not expose the snap grid today.diff --git a/specs/003-adaptive-snap-grid/tasks.md b/specs/003-adaptive-snap-grid/tasks.mdindex 897d8dd5..7f7caf93 100644--- a/specs/003-adaptive-snap-grid/tasks.md+++ b/specs/003-adaptive-snap-grid/tasks.md@@ -314,8 +314,34 @@ Task: "T023 Quantize + MidiToolsView use Grids.Quantize"## Phase 7: Convergence-- [ ] T054 Make ⌘1–⌘5 work while the floating detail window is active on macOS: that window has no native menu, so the key equivalents never fire there. In `src/managed/Nota.App/MainWindow.Input.cs` `HandleFloatingKeyDown`, match ⌘/Ctrl + 1–5 (no Alt/Shift) and run `grid.narrower` / `grid.wider` / `grid.triplets` / `grid.snap` / `grid.adaptive` through `_commands.Run`, then mark the key handled. Keep Windows/Linux from running it twice (their `TryMenuShortcut` path). Per FR-013 and plan R9 (partial)-- [ ] T055 Snap the dragged note edge's absolute position in the piano roll, not only the drag delta. In `src/managed/Nota.App/PianoRollView.cs` (`Mode.Resize` / `Mode.ResizeLeft`, `_resizeAnchor`), the end (or start) of the grabbed note should land on `SnapBeat(XToBeat(p.X))`, and the other selected notes should move by the same delta. Today a note whose end is off the grid keeps that offset when you resize it. Per US1/AC3 and FR-008 (partial)-- [ ] T056 Decide and reconcile the arrangement toolbar label with FR-011, which requires "Auto · <step>" in Adaptive mode. The toolbar cell shows the step plus an "AUTO GRID" caption (`src/managed/Nota.App/SnapChip.cs`, `MainWindow.axaml` SnapChip cell). Either render "Auto · 1/8" in the cell, or amend FR-011 in spec.md to allow the two-line toolbar variant that is already documented in contracts/grid-ui.md. Per FR-011 (contradicts)-- [ ] T057 Ignore grid shortcuts while a text field has keyboard focus: on macOS the native menu fires ⌘1–⌘5 even in a TextBox. Add a guard at the top of `StepGrid` in `src/managed/Nota.App/MainWindow.Commands.cs`: return if the focused element is inside a `TextBox` or `NumericUpDown`. Per spec Edge Cases "Text entry" (partial)-- [ ] T058 Fix the snap controls' width to their widest label so they never shift while zooming. The toolbar value `MinWidth="46"` (`src/managed/Nota.App/MainWindow.axaml`) fits "1/16T" but not "2 bars" / "4 bars". The piano-roll chip's `MinWidth = 82` (`src/managed/Nota.App/SnapChip.cs`) is narrower than "Auto · 4 bars". Measure the widest label in the mono font, or raise the minimums. Per plan Risks (toolbar width) (partial)+- [X] T054 Make ⌘1–⌘5 work while the floating detail window is active on macOS: that window has no native menu, so the key equivalents never fire there. In `src/managed/Nota.App/MainWindow.Input.cs` `HandleFloatingKeyDown`, match ⌘/Ctrl + 1–5 (no Alt/Shift) and run `grid.narrower` / `grid.wider` / `grid.triplets` / `grid.snap` / `grid.adaptive` through `_commands.Run`, then mark the key handled. Keep Windows/Linux from running it twice (their `TryMenuShortcut` path). Per FR-013 and plan R9 (partial)+- [X] T055 Snap the dragged note edge's absolute position in the piano roll, not only the drag delta. In `src/managed/Nota.App/PianoRollView.cs` (`Mode.Resize` / `Mode.ResizeLeft`, `_resizeAnchor`), the end (or start) of the grabbed note should land on `SnapBeat(XToBeat(p.X))`, and the other selected notes should move by the same delta. Today a note whose end is off the grid keeps that offset when you resize it. Per US1/AC3 and FR-008 (partial)+- [X] T056 Decide and reconcile the arrangement toolbar label with FR-011, which requires "Auto · <step>" in Adaptive mode. The toolbar cell shows the step plus an "AUTO GRID" caption (`src/managed/Nota.App/SnapChip.cs`, `MainWindow.axaml` SnapChip cell). Either render "Auto · 1/8" in the cell, or amend FR-011 in spec.md to allow the two-line toolbar variant that is already documented in contracts/grid-ui.md. Per FR-011 (contradicts)+- [X] T057 Ignore grid shortcuts while a text field has keyboard focus: on macOS the native menu fires ⌘1–⌘5 even in a TextBox. Add a guard at the top of `StepGrid` in `src/managed/Nota.App/MainWindow.Commands.cs`: return if the focused element is inside a `TextBox` or `NumericUpDown`. Per spec Edge Cases "Text entry" (partial)+- [X] T058 Fix the snap controls' width to their widest label so they never shift while zooming. The toolbar value `MinWidth="46"` (`src/managed/Nota.App/MainWindow.axaml`) fits "1/16T" but not "2 bars" / "4 bars". The piano-roll chip's `MinWidth = 82` (`src/managed/Nota.App/SnapChip.cs`) is narrower than "Auto · 4 bars". Measure the widest label in the mono font, or raise the minimums. Per plan Risks (toolbar width) (partial)++---++## Phase 8: User Story 4 - The same grid in the audio clip editor (Priority: P2)++**Goal**: The audio clip editor snaps its trim brackets, warp markers and envelope points+to the grid it draws, using the piano roll's setting and the same chip (spec US4,+FR-018–FR-021, research R13).++**Independent Test**: Open a warped clip; zoom in and out; drag a warp marker, a trim+bracket and an envelope point; each lands on a drawn line; the chip shows the step;+⌥ drags freely (US4 acceptance 1–5).++- [X] T059 [US4] In `src/managed/Nota.App/AudioClipEditorView.cs` `WaveformView`:+ - add `ResolvedGrid WarpGrid` (`SnapGrid.Resolve(EditorGrids.Shared.Get(EditorKind.PianoRoll), _zoom * Bounds.Width / TotalBeats, BeatsPerBar)`) and `ResolvedGrid EnvGrid` (the same at `_zoom * Bounds.Width / _clipBeats`);+ - add a `GridChanged` event raised from `InvalidateVisual` callers when the drawn axis's grid changes;+ - subscribe to `EditorGrids.Changed` while attached (redraw on `EditorKind.PianoRoll`).+- [X] T060 [US4] Replace the static whole-beat `SnapBeat` with an axis-aware snap that honours `SnapOn` and a live Alt flag (set from `e.KeyModifiers` on press and move):+ - trim brackets (around line 1034, replacing the `_snapGrid` flag);+ - warp-marker add (double-click, around line 924) and drag (around line 1053);+ - envelope point add (around line 885) and drag (around line 997), on the envelope axis.+- [X] T061 [US4] Draw the wave grid with `SnapGrid.GridLines` at the drawn step: warp axis (`BeatToX`) normally, envelope axis (`EnvBeatToX`) in Envelope mode (warped or not). Replace the `BeatStep`/`GridFinest` thinning in the grid loop (around line 1316). Keep the ruler's own label and tick logic.+- [X] T062 [US4] In the `AudioClipEditorView` header (around line 208), replace the Snap `SwitchRow` and `_snapToGrid` / `ToggleSnap` / `SetSnapToGrid` with `SnapChip.Create(EditorKind.PianoRoll, () => _wave.DrawnGrid)`, wired to `_wave.GridChanged`. Update the file's header comment.+- [X] T063 [US4] Shortcut target and status line (FR-021): in `src/managed/Nota.App/MainWindow.Commands.cs`, `GridTarget()` returns the clip editor when the detail area was used last and `_clipEditor` or `_audioEditor` is open. `StepGrid` resolves the label from the open editor and names it "Clip editor grid".+- [X] T064 [US4] Docs: CHANGELOG entry (the audio editor joins the grid; the Snap switch is replaced), FEATURES.md audio-editor bullet, nota-docs `editing/audio-clips` EN + RU (and `basics/transport` snap-grid section: "the clip editors share one setting"), re-shoot `editing/audio-clip-editor`, then `npm run build` and `npm run check`.+- [X] T065 [US4] Verify with the headless harness (warped clip: marker, trim and envelope drags with and without ⌥; chip label shared with the piano roll) and run `scripts/build.sh`.diff --git a/src/managed/Nota.App/AudioClipEditorView.cs b/src/managed/Nota.App/AudioClipEditorView.csindex 45bbb229..b3ea8778 100644--- a/src/managed/Nota.App/AudioClipEditorView.cs+++ b/src/managed/Nota.App/AudioClipEditorView.cs@@ -3,7 +3,7 @@//// Detail · Clip for AUDIO clips (nota-design "Nota Clip Editor" 1b): the same frame as the// MIDI editor — a 38px header (clip cell, Sample | Envelope, the envelope target while-// editing one, the Snap switch, the file's format) over the 232px inspector (CLIP,+// editing one, the snap-grid chip, the file's format) over the 232px inspector (CLIP,// PLAYBACK, WARP) and the waveform canvas: a beat ruler, a 22px warp-marker strip, and// the wave in the track colour, everything past the clip's played region darkened rather// than hidden. Envelope and ADSR are modes of the canvas, not checkboxes. ADSR edits the@@ -20,6 +20,7 @@ using Avalonia.Layout;using Avalonia.Media;using Avalonia.Threading;using Nota.Application;+using Nota.Application.Editing;using static Nota.App.ClipEditorKit;namespace Nota.App;@@ -42,7 +43,7 @@ public sealed class AudioClipEditorView : UserControlprivate readonly TextBlock _envTargetText = new() { Text = "Volume", FontSize = NotaType.Body, Foreground = NotaPalette.TextPrimary };private readonly TextBlock _hint = Hint("");private readonly Border _envTargetDrop;- private Action _syncGain = () => { }, _syncReverse = () => { }, _syncWarp = () => { }, _syncSnap = () => { };+ private Action _syncGain = () => { }, _syncReverse = () => { }, _syncWarp = () => { };private Action _syncAttack = () => { }, _syncDecay = () => { }, _syncSustain = () => { }, _syncRelease = () => { };private ClipAdsr _adsr = ClipAdsr.Identity;private int _mode; // 0 = Sample, 1 = Envelope, 2 = ADSR@@ -56,7 +57,6 @@ public sealed class AudioClipEditorView : UserControlprivate bool _reversed;private bool _warpEnabled;private int _warpMode = 3; // Complex- private bool _snapToGrid = true; // trim brackets snap to whole beats (default on)private double _detectedBpm;private long _srcFrames; // the whole sample's frames (unwarped detail peaks)private bool _envMode;@@ -194,7 +194,6 @@ public sealed class AudioClipEditorView : UserControlvar col1 = new Grid { RowDefinitions = new RowDefinitions("*,Auto"), Background = NotaPalette.BgSunken };col1.Children.Add(waveHost);Grid.SetRow(_hScroll, 1); col1.Children.Add(_hScroll);- _wave.SetSnapToGrid(_snapToGrid);var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*") };grid.Children.Add(inspector);@@ -205,8 +204,10 @@ public sealed class AudioClipEditorView : UserControlvar tabs = Segments(new[] { "Sample", "Envelope", "ADSR" }, 0, SetMode, out _);_envTargetDrop = Dropdown(_envTargetText, a => ShowMenu(a, EnvTargets, _envTarget, SetEnvTarget));_envTargetDrop.IsVisible = false;- var snap = SwitchRow("Snap", () => _snapToGrid, ToggleSnap, out _syncSnap);- ToolTip.SetTip(snap, "Trim brackets land on the beat grid");+ // The clip editors' snap grid (shared with the piano roll): trim brackets, warp markers+ // and envelope points land on the lines drawn in the wave.+ var (snap, chip) = SnapChip.Create(EditorKind.PianoRoll, () => _wave.DrawnGrid);+ _wave.GridChanged += chip.Refresh;var right = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 12, Children = { snap, HeaderDivider(), _fileText } };var name = engine.GetClipName(trackId, clipIndex);var header = Header(clipColor, string.IsNullOrWhiteSpace(name) ? $"Audio {trackId}" : name, "AUDIO", tabs, _envTargetDrop, right);@@ -217,6 +218,9 @@ public sealed class AudioClipEditorView : UserControlReload();}+ /// <summary>The snap grid of the axis the wave draws (for the status line of ⌘1–⌘5).</summary>+ internal ResolvedGrid SnapGridState => _wave.DrawnGrid;+private readonly TextBox _bpmBox;private readonly Canvas _overlay;private readonly ScrollBar _hScroll;@@ -397,12 +401,6 @@ public sealed class AudioClipEditorView : UserControlprivate string GainText() => _gain <= 0.0011 ? "−∞\u2009dB" : string.Format(NotaNum.Culture, "{0:+0.0;−0.0;0.0}\u2009dB", AudioMath.LinToDb(_gain));- private void ToggleSnap()- {- _snapToGrid = !_snapToGrid;- _wave.SetSnapToGrid(_snapToGrid);- }-private void ToggleReverse(){_engine.SetClipReverse(TrackId, ClipIndex, !_reversed);@@ -583,7 +581,35 @@ public sealed class AudioClipEditorView : UserControlprivate double _trimStart, _trimEnd, _trimTotal;private bool _trimMode;private int _trimDrag = -1; // 0 = start, 1 = end- private bool _snapGrid = true; // trim brackets snap to whole beats (toggle above the wave)+ // Snap grid (specs/003-adaptive-snap-grid, US4): the clip editors' shared setting,+ // resolved per axis — warp beats for brackets / markers / the wave grid, the+ // envelope's played beats in Envelope mode. Alt held during a drag moves freely.+ private bool _free;+ private ResolvedGrid _lastDrawn;+ private static GridSetting GridSetting => EditorGrids.Shared.Get(EditorKind.PianoRoll);+ private ResolvedGrid WarpGrid => SnapGrid.Resolve(GridSetting, _zoom * Math.Max(1, Bounds.Width) / TotalBeats, BeatsPerBar);+ private ResolvedGrid EnvGrid => SnapGrid.Resolve(GridSetting, _zoom * Math.Max(1, Bounds.Width) / _clipBeats, BeatsPerBar);+ /// <summary>The grid of the axis being drawn (and edited) — what the header chip shows.+ /// An unwarped clip has no beat grid of its own, so its only snapping is the envelope's.</summary>+ public ResolvedGrid DrawnGrid => _envMode || _mk.Count < 2 ? EnvGrid : WarpGrid;+ /// <summary>The drawn step changed (zoom, mode, the setting) — the header chip relabels.</summary>+ public event Action? GridChanged;+ private double SnapOn(double beat, ResolvedGrid g)+ => _free || !g.SnapOn ? beat : SnapGrid.SnapBeat(beat, g.Snap.Beats(BeatsPerBar), BeatsPerBar);+ private double SnapWarp(double beat) => SnapOn(beat, WarpGrid);+ private double SnapEnv(double beat) => SnapOn(beat, EnvGrid);++ private void OnGrid(EditorKind k) { if (k == EditorKind.PianoRoll) InvalidateVisual(); }+ protected override void OnAttachedToVisualTree(VisualTreeAttachmentEventArgs e)+ {+ base.OnAttachedToVisualTree(e);+ EditorGrids.Shared.Changed += OnGrid;+ }+ protected override void OnDetachedFromVisualTree(VisualTreeAttachmentEventArgs e)+ {+ base.OnDetachedFromVisualTree(e);+ EditorGrids.Shared.Changed -= OnGrid;+ }private const double MinSrcFrames = 256;private static readonly Cursor ArrowCur = new(StandardCursorType.Arrow);private static readonly Cursor ResizeCur = new(StandardCursorType.SizeWestEast);@@ -683,7 +709,6 @@ public sealed class AudioClipEditorView : UserControl}public void SetSegmentBpm(int seg, double bpm) => ApplySegmentBpm(seg, bpm, commit: true);- public void SetSnapToGrid(bool on) { _snapGrid = on; }public void SetSourceRate(double sr) { _srcSR = sr; }// Whole-sample source-region view (unwarped). totalFrames <= 0 disables the brackets.public void SetSourceRegion(double offsetFrames, double lengthFrames, double totalFrames)@@ -802,8 +827,6 @@ public sealed class AudioClipEditorView : UserControlprivate double TotalBeats => _mk.Count > 1 ? Math.Max(1e-6, _mk[^1].beat) : 1;private double BeatToX(double beat, double w) => FracToX(beat / TotalBeats, w);private double XToBeat(double x, double w) => Math.Clamp(XToFrac(x, w), 0, 1) * TotalBeats;- // Snap a beat to the nearest whole-beat grid line (the 1.1, 1.2 … grid).- private static double SnapBeat(double beat) => Math.Round(beat);private int HitMarker(double x, double w){@@ -815,6 +838,7 @@ public sealed class AudioClipEditorView : UserControlprotected override void OnPointerPressed(PointerPressedEventArgs e){double W = Bounds.Width, H = Bounds.Height;+ _free = (e.KeyModifiers & KeyModifiers.Alt) != 0;// ADSR mode takes over the pointer: grab a handle (double-click resets its stage).if (_adsrMode)@@ -882,7 +906,7 @@ public sealed class AudioClipEditorView : UserControlreturn;}if (right) return;- var np = new EnvPt { beat = EnvXToBeat(p.X, W), val = EnvYToVal(p.Y, H) }; // add + grab+ var np = new EnvPt { beat = SnapEnv(EnvXToBeat(p.X, W)), val = EnvYToVal(p.Y, H) }; // add + grab_env.Add(np);_envDrag = _env.IndexOf(np);e.Pointer.Capture(this);@@ -921,7 +945,7 @@ public sealed class AudioClipEditorView : UserControl{int hit = HitMarker(x, w);if (hit > 0 && hit < _mk.Count - 1) { _mk.RemoveAt(hit); Commit(); } // delete interior- else AddMarker(SnapBeat(XToBeat(x, w))); // add on the grid+ else AddMarker(SnapWarp(XToBeat(x, w))); // add on the gride.Handled = true;return;}@@ -957,6 +981,7 @@ public sealed class AudioClipEditorView : UserControlprotected override void OnPointerMoved(PointerEventArgs e){+ _free = (e.KeyModifiers & KeyModifiers.Alt) != 0; // live, so Alt can toggle mid-dragif (_adsrDrag != AdsrHandle.None){var p = e.GetPosition(this);@@ -994,7 +1019,7 @@ public sealed class AudioClipEditorView : UserControlif (_envDrag >= 0){var p = e.GetPosition(this);- _env[_envDrag].beat = EnvXToBeat(p.X, Bounds.Width);+ _env[_envDrag].beat = SnapEnv(EnvXToBeat(p.X, Bounds.Width));_env[_envDrag].val = EnvYToVal(p.Y, Bounds.Height);InvalidateVisual();return;@@ -1031,7 +1056,7 @@ public sealed class AudioClipEditorView : UserControl{const double minBeat = 0.05;double bt = XToBeat(e.GetPosition(this).X, Bounds.Width);- if (_snapGrid) bt = SnapBeat(bt); // land the edge exactly on the beat grid+ bt = SnapWarp(bt); // land the edge exactly on the grid (Alt / snap off: free)if (_trimDrag == 0) _trimStart = Math.Clamp(bt, 0, _trimEnd - minBeat);else _trimEnd = Math.Clamp(bt, _trimStart + minBeat, _trimTotal);InvalidateVisual();@@ -1050,7 +1075,7 @@ public sealed class AudioClipEditorView : UserControlreturn;}double w = Bounds.Width;- double b = SnapBeat(XToBeat(e.GetPosition(this).X, w)); // align to the beat grid+ double b = SnapWarp(XToBeat(e.GetPosition(this).X, w)); // align to the griddouble lo = _mk[_drag - 1].beat + 1e-3, hi = _mk[_drag + 1].beat - 1e-3; // stay between neighbours_mk[_drag] = (_mk[_drag].src, Math.Clamp(b, lo, hi)); // source fixed; beat moves (warp)InvalidateVisual();@@ -1249,11 +1274,9 @@ public sealed class AudioClipEditorView : UserControl}// ---- ruler / grid density ----------------------------------------------- private const double GridMinPx = 8; // closest two grid lines may sitprivate const double TickMinPx = 6; // closest two ruler ticks may sitprivate const double LabelPadPx = 12; // gap after a ruler label// Beat steps the ruler and grid choose from: sub-beats (power-of-two), beats, then bars ×2ⁿ.- private const double GridFinest = 1.0 / 16; // the wave grid stops at 64ths (ruler ticks go finer)private static readonly double[] BeatSteps = BuildBeatSteps();private static double[] BuildBeatSteps(){@@ -1308,20 +1331,27 @@ public sealed class AudioClipEditorView : UserControlctx.DrawLine(StripEdge, new Point(0, top - 0.5), new Point(w, top - 0.5));DrawRuler(ctx, w);- // Beat grid through the wave (warped: the beats are known), thinned to the zoom so- // a long clip doesn't turn into a solid comb; only the visible slice is walked.- if (_mk.Count > 1)+ // The snap grid through the wave: one line per snap position at the drawn step+ // (SnapGrid.GridLines, the same set the drags land on). Envelope mode draws the+ // envelope's played timeline; otherwise the warp beats (warped clips only — an+ // unwarped clip has no beat grid). Only the visible slice is walked.+ var drawn = DrawnGrid;+ if (_envMode || _mk.Count > 1){- double tb = TotalBeats;- double step = Math.Max(GridFinest, BeatStep(_zoom * w / tb, GridMinPx));- var (b0, b1) = VisibleBeats(w);- for (double b = Math.Max(step, Math.Floor(b0 / step) * step); b <= Math.Min(b1, tb - 1e-6); b += step)+ double step = drawn.Draw.Beats(BeatsPerBar);+ double total = _envMode ? _clipBeats : TotalBeats;+ double b0, b1;+ if (_envMode) { b0 = EnvXToBeat(0, w); b1 = EnvXToBeat(w, w); }+ else (b0, b1) = VisibleBeats(w);+ foreach (double b in SnapGrid.GridLines(b0, Math.Min(b1, total - 1e-6), step, BeatsPerBar)){- double x = BeatToX(b, w);+ if (b < 1e-9) continue; // the clip's own left edge+ double x = _envMode ? EnvBeatToX(b, w) : BeatToX(b, w);bool bar = IsMultiple(b, BeatsPerBar);ctx.DrawLine(bar ? GridBarPen : GridBeatPen, new Point(x + 0.5, top), new Point(x + 0.5, h));}}+ if (drawn != _lastDrawn) { _lastDrawn = drawn; Dispatcher.UIThread.Post(() => GridChanged?.Invoke()); }// Peaks span the whole clip (frac 0..1); route through the zoom/scroll axis so// zooming magnifies the waveform and only the visible slice is drawn.diff --git a/src/managed/Nota.App/MainWindow.Commands.cs b/src/managed/Nota.App/MainWindow.Commands.csindex 8ca5aeeb..7a228339 100644--- a/src/managed/Nota.App/MainWindow.Commands.cs+++ b/src/managed/Nota.App/MainWindow.Commands.cs@@ -8,8 +8,10 @@using System;using System.Linq;+using Avalonia;using Avalonia.Controls;using Avalonia.Interactivity;+using Avalonia.VisualTree;using Microsoft.Extensions.DependencyInjection;using Nota.Application;using Nota.Application.Editing;@@ -185,22 +187,33 @@ public partial class MainWindow: "Envelopes follow clips";}- // The grid shortcuts act on the piano roll when the detail area (docked or floating) was- // used last and a MIDI clip is open in it; otherwise on the arrangement.+ // The grid shortcuts act on the clip editor (piano roll or audio — they share one setting)+ // when the detail area (docked or floating) was used last and one is open in it; otherwise+ // on the arrangement.private EditorKind GridTarget(){- bool rollOpen = _editorRoll is { } roll && _clipEditor is not null && roll.IsEffectivelyVisible;+ bool clipOpen = (_editorRoll is { } roll && _clipEditor is not null && roll.IsEffectivelyVisible)+ || _audioEditor is { IsEffectivelyVisible: true };bool detailLast = _detailWasLastFocused || _detailWindow?.IsActive == true;- return rollOpen && detailLast ? EditorKind.PianoRoll : EditorKind.Arrangement;+ return clipOpen && detailLast ? EditorKind.PianoRoll : EditorKind.Arrangement;}private void StepGrid(Func<GridSetting, GridSetting> step){+ // Typing in a field: the macOS menu would still fire ⌘1–⌘5 — leave the grid alone.+ // The command palette's own field is the exception: running the command from there is+ // the point.+ var focused = (_detailWindow?.IsActive == true ? _detailWindow.FocusManager : FocusManager)?.GetFocusedElement() as Visual;+ bool typing = focused?.FindAncestorOfType<TextBox>(includeSelf: true) is not null+ || focused?.FindAncestorOfType<NumericUpDown>(includeSelf: true) is not null;+ if (typing && focused?.FindAncestorOfType<CommandPaletteView>() is null) return;var kind = GridTarget();var grids = EditorGrids.Shared;grids.Set(kind, step(grids.Get(kind)));- var r = kind == EditorKind.PianoRoll && _editorRoll is { } roll ? roll.SnapGridState : Timeline.SnapGridState;+ var r = kind == EditorKind.Arrangement ? Timeline.SnapGridState+ : _audioEditor is { IsEffectivelyVisible: true } audio ? audio.SnapGridState+ : _editorRoll?.SnapGridState ?? Timeline.SnapGridState;string label = r.SnapOn ? SnapGrid.Label(grids.Get(kind), r) : "Snap off";- if (_vm is not null) _vm.StatusText = $"{(kind == EditorKind.PianoRoll ? "Piano roll" : "Arrangement")} grid: {label}";+ if (_vm is not null) _vm.StatusText = $"{(kind == EditorKind.PianoRoll ? "Clip editor" : "Arrangement")} grid: {label}";}}diff --git a/src/managed/Nota.App/MainWindow.Input.cs b/src/managed/Nota.App/MainWindow.Input.csindex 8d290b42..a973ee5a 100644--- a/src/managed/Nota.App/MainWindow.Input.cs+++ b/src/managed/Nota.App/MainWindow.Input.cs@@ -108,9 +108,28 @@ public partial class MainWindowe.Handled = true;return;}+ // The floating window has no native menu, so ⌘1–⌘5 (the grid) never arrive as menu key+ // equivalents there: run them here. Windows / Linux stop here too, so their in-window+ // menu path below doesn't run them a second time.+ if (meta && (e.KeyModifiers & (KeyModifiers.Alt | KeyModifiers.Shift)) == 0 && GridCommandFor(e.Key) is { } grid)+ {+ _commands.Run(grid);+ e.Handled = true;+ return;+ }HandleKeyDown(e);}+ private static string? GridCommandFor(Key key) => key switch+ {+ Key.D1 or Key.NumPad1 => "grid.narrower",+ Key.D2 or Key.NumPad2 => "grid.wider",+ Key.D3 or Key.NumPad3 => "grid.triplets",+ Key.D4 or Key.NumPad4 => "grid.snap",+ Key.D5 or Key.NumPad5 => "grid.adaptive",+ _ => null,+ };+// --- live play from the computer keyboard + basic shortcuts (M7-3) ---protected override void OnKeyDown(KeyEventArgs e) => HandleKeyDown(e);diff --git a/src/managed/Nota.App/MainWindow.axaml b/src/managed/Nota.App/MainWindow.axamlindex 9ffa3ffd..0440e726 100644--- a/src/managed/Nota.App/MainWindow.axaml+++ b/src/managed/Nota.App/MainWindow.axaml@@ -247,11 +247,11 @@</StackPanel></Button><!-- Clip snap grid (SnapChip.cs): the step in effect, live with the zoom in Auto;- click for the grid menu. MinWidth fits the widest value (1/16T). -->+ click for the grid menu. SnapChip sizes the value to its widest label. --><Button x:Name="SnapChip" Classes="cell"><StackPanel Spacing="2"><TextBlock x:Name="SnapLabel" Classes="Mono" Text="1/4" FontSize="14" LineHeight="16"- MinWidth="46" TextAlignment="Center" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.TextPrimary}"/>+ MinWidth="36" TextAlignment="Center" HorizontalAlignment="Center" Foreground="{DynamicResource Brush.TextPrimary}"/><TextBlock x:Name="SnapCaption" Classes="CellLabel" Text="GRID" HorizontalAlignment="Center"/></StackPanel></Button>diff --git a/src/managed/Nota.App/PianoRollView.cs b/src/managed/Nota.App/PianoRollView.csindex 6f2971e4..1f3b8a59 100644--- a/src/managed/Nota.App/PianoRollView.cs+++ b/src/managed/Nota.App/PianoRollView.cs@@ -967,7 +967,7 @@ public sealed partial class PianoRollView : UserControlprivate readonly Dictionary<int, (double start, int pitch, double len)> _orig = new();private int _primary = -1;private double _grabBeat; // pointer-beat minus primary start, at grab (Move)- private double _resizeAnchor; // snapped pointer-beat at grab (Resize)+ private double _edgeGrab; // pointer beat minus the grabbed edge at press (Resize / ResizeLeft)// Marquee (grid coords) + the selection to union with when additive.private Point _marqueeA, _marqueeB;@@ -1191,7 +1191,13 @@ public sealed partial class PianoRollView : UserControlforeach (int i in _o._selection)if (i >= 0 && i < _o._notes.Count) { var nn = _o._notes[i]; _orig[i] = (nn.StartBeat, nn.Pitch, nn.LengthBeats); }_preDrag.Clear(); _preDrag.AddRange(_o._notes); _liveStarted = false;- if (edge != 0) { _drag = edge > 0 ? Mode.Resize : Mode.ResizeLeft; _resizeAnchor = Snap(XToBeat(p.X)); Cursor = ResizeCursor; _cursorKind = 1; }+ if (edge != 0)+ {+ _drag = edge > 0 ? Mode.Resize : Mode.ResizeLeft;+ var g = _orig[hit];+ _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; }_lastGrid = p;_o.Invalidate(); _o.Changed?.Invoke();@@ -1245,7 +1251,10 @@ public sealed partial class PianoRollView : UserControl}else if (_drag == Mode.Resize){- double dLen = Snap(XToBeat(p.X)) - _resizeAnchor;+ // The grabbed note's end lands on the grid (not just the drag distance); the+ // rest of the selection changes by the same amount.+ var pr = _orig[_primary];+ double dLen = Snap(XToBeat(p.X) - _edgeGrab) - (pr.start + pr.len);foreach (var kv in _orig){var n = _o._notes[kv.Key];@@ -1259,7 +1268,8 @@ public sealed partial class PianoRollView : UserControl{// Move the start, keep the end: clamp so no note passes its own end (minus// one grid step) or the clip's start.- double dStart = Snap(XToBeat(p.X)) - _resizeAnchor;+ var pr = _orig[_primary];+ double dStart = Snap(XToBeat(p.X) - _edgeGrab) - pr.start;foreach (var v in _orig.Values)dStart = Math.Clamp(dStart, -v.start, Math.Max(-v.start, v.len - _o.MinNoteLen));foreach (var kv in _orig)diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.csindex f5388224..2d464cf1 100644--- a/src/managed/Nota.App/PreferencesWindow.cs+++ b/src/managed/Nota.App/PreferencesWindow.cs@@ -1040,7 +1040,7 @@ public sealed partial class PreferencesWindow : NotaWindow("0", "Deactivate / activate the selected clip(s)"),("Delete", "Delete the selected clip / range"),}),- ("GRID (ARRANGEMENT OR PIANO ROLL — WHICHEVER YOU USED LAST)", new[]+ ("GRID (ARRANGEMENT OR CLIP EDITOR — WHICHEVER YOU USED LAST)", new[]{("⌘1 ⌘2", "Narrow / widen the grid · in Auto, change the density"),("⌘3", "Triplet grid on / off"),diff --git a/src/managed/Nota.App/SnapChip.cs b/src/managed/Nota.App/SnapChip.csindex 47047be8..ceb8ca2a 100644--- a/src/managed/Nota.App/SnapChip.cs+++ b/src/managed/Nota.App/SnapChip.cs@@ -37,7 +37,7 @@ internal sealed class SnapChipbutton.Click += (_, _) => OpenMenu();// Subscribed only while on screen: piano-roll chips come and go with every clip.void OnChanged(EditorKind k) { if (k == _kind) Refresh(); }- button.AttachedToVisualTree += (_, _) => { Grids.Changed += OnChanged; Refresh(); };+ button.AttachedToVisualTree += (_, _) => { Grids.Changed += OnChanged; FitWidest(); Refresh(); };button.DetachedFromVisualTree += (_, _) => Grids.Changed -= OnChanged;Refresh();}@@ -52,13 +52,42 @@ internal sealed class SnapChipvar value = new TextBlock{FontFamily = NotaFonts.MonoFamily, FontSize = 11, VerticalAlignment = VerticalAlignment.Center,- // Fixed to the longest label so the header doesn't shift while zooming.- MinWidth = 82, TextAlignment = TextAlignment.Center,+ TextAlignment = TextAlignment.Center,};- var b = new Button { Classes = { "chip" }, Padding = new Avalonia.Thickness(10, 0), Content = value };+ // A grid glyph names the control and a chevron says it opens a menu, like the other+ // header dropdowns — the value alone read as a static label.+ var content = new StackPanel+ {+ Orientation = Orientation.Horizontal, Spacing = 7,+ Children =+ {+ new Glyph(GlyphKind.Grid, 11) { Foreground = NotaPalette.TextSecondary, VerticalAlignment = VerticalAlignment.Center },+ value,+ new Glyph(GlyphKind.ChevronDown, 8) { Foreground = NotaPalette.TextDisabled, VerticalAlignment = VerticalAlignment.Center },+ },+ };+ var b = new Button { Classes = { "chip" }, Padding = new Avalonia.Thickness(10, 0), Content = content };return (b, new SnapChip(b, value, null, kind, current));}+ // The value keeps the width of its longest possible label ("Auto · 4 bars", "1/16T"), in+ // its own font, so the toolbar and the header never shift while zooming.+ private void FitWidest()+ {+ var face = new Typeface(_value.FontFamily, _value.FontStyle, _value.FontWeight);+ double widest = 0;+ for (int i = 0; i < GridStep.Count; i++)+ foreach (bool t in new[] { false, true })+ {+ string label = GridStep.Of(i, t).Label;+ if (_caption is null) label = "Auto · " + label;+ var ft = new FormattedText(label, NotaNum.Culture,+ FlowDirection.LeftToRight, face, _value.FontSize, null);+ widest = Math.Max(widest, ft.WidthIncludingTrailingWhitespace);+ }+ _value.MinWidth = Math.Ceiling(widest) + 2;+ }+/// <summary>Relabels from the live setting and zoom; cheap, and a no-op when nothing changed.</summary>public void Refresh(){