Skip to content

armgit / nota

Public Imported from GitHub
0

Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.

Add pattern view for drum rack

Egor Khindikaynen41d09eec0b35
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fe5a4500..69df6cb6 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -19,6 +19,14 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
## [Unreleased]
### Added
+- **A Pattern tab for the Drum Rack.** Select a MIDI clip on a Drum Rack track and the
+ detail panel offers **Pattern** between Devices and Clip: a drum-machine step grid with
+ one row per loaded pad. Click a step to place a hit, shift-click it for an accent, drag
+ across the grid to paint a run, and ride the velocity lane under the selected row; click
+ a pad name to hear it. The grid runs from 1/4 to 1/32, follows the clip's length (long
+ clips page in bar windows), and lights the step being played. The pattern is not a copy —
+ the grid *is* the clip, so what you step shows up in the piano roll and notes drawn there
+ show up as steps. Tab now cycles Devices → Pattern → Clip.
- **Song sections.** A lane over the ruler holds named spans — Intro, Verse, Drop — so the
timeline says where you are in the song rather than only which bar you are on. Drag on
the empty lane to mark one, click it to jump the playhead there, double-click to rename,
diff --git a/FEATURES.md b/FEATURES.md
index 194ee8a7..af7569c9 100644
--- a/FEATURES.md
+++ b/FEATURES.md
@@ -135,6 +135,14 @@ the mixer opens as a separate floating window (**View → Mixer**, ⌘M).
- A MIDI clip trimmed in the arrangement mutes note tails at its boundary.
- Live edits (moving a note, changing its length) reach the engine immediately, and a
whole drag is a single undo step.
+- **Pattern (step sequencer)**: on a Drum Rack track the detail panel gains a **Pattern**
+ tab between Devices and Clip — a drum-machine grid with one row per loaded pad. Click a
+ step to place a hit, shift-click for an accent, drag across the grid to paint, and use
+ the velocity lane under the selected row. The grid is 1/4 to 1/32, it follows the clip's
+ length (paging in 64-step windows on long clips), the playing step lights up, and the
+ pads audition by name. It is not a second copy of the pattern: the grid **is** the MIDI
+ clip, so steps written here appear in the piano roll and notes drawn there light up as
+ steps.
- **Input**: MIDI keyboard (live play and recording), and the **computer keyboard** plays
MIDI (the S–K row, sharps on W E T Y U) — including while a hosted plugin window has
focus.
@@ -359,7 +367,8 @@ and user presets, automation, persistence and cloning.
with **key and velocity zones**, gain/meter/M·S, horizontal device cards (GUI / Params),
a zone map, rack output (Volume/Glide), Fold/Save.
- **Nota Drum Rack** — 4×4 pads (banks C1–C4, up to 64 pads), Pads and Mixer views, per-pad
- Volume/Pan/Tune/Decay, choke groups (monophonic cut), Swing/Humanize, hot-swap.
+ Volume/Pan/Tune/Decay, choke groups (monophonic cut), Swing/Humanize, hot-swap. Its clips
+ can be stepped in the detail panel's **Pattern** tab (see below).
- **Nota Audio Effect Rack** — **Parallel / Series / Select** modes (by input level),
Dry/Wet + Gain, PDC, Fold, Save; chains with gain/meter/M·S; named macros and mappings;
the "+ Device" menu lists built-in effects and a Plug-ins submenu.
diff --git a/src/managed/Nota.App/DrumPatternView.cs b/src/managed/Nota.App/DrumPatternView.cs
new file mode 100644
index 00000000..acd7bc12
--- /dev/null
+++ b/src/managed/Nota.App/DrumPatternView.cs
@@ -0,0 +1,670 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Detail · Pattern — the Drum Rack step sequencer. It borrows the look and the feel of
+// the Nota Rhythm card (beat-grouped step buttons, shift-click accents, a velocity lane,
+// a teal playhead) but lists one row per loaded pad instead of stepping a single voice.
+//
+// It owns no pattern state: the grid IS the MIDI clip. A lit cell is a note at the pad's
+// trigger note, so an edit here rewrites the clip (one undo entry per click, and one per
+// drag) and a note drawn in the piano roll lights up here on the next Reload — the two
+// views are the same data seen two ways. Only the cells the user actually touches are
+// added or removed, so a note that doesn't sit on the grid is drawn in its nearest cell
+// and otherwise left exactly as the roll left it.
+
+using System;
+using System.Collections.Generic;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using Avalonia.Input;
+using Avalonia.Layout;
+using Avalonia.Media;
+using Nota.Application;
+using static Nota.App.DeviceCardKit;
+
+namespace Nota.App;
+
+public sealed class DrumPatternView : UserControl
+{
+ private const int BeatsPerBar = 4; // as everywhere else in the app (transport, props rails)
+ private const int MaxCells = 64; // steps drawn at once; a longer clip pages in windows
+ private const double NameW = 156;
+ private const double RowH = 20;
+ private const double StepW = 28; // target step width — the grid shrinks below it on a narrow panel
+ private const double VelH = 26;
+ private const float DefaultVel = 0.78f;
+ private const float AccentVel = 1.0f;
+ private const float AccentFloor = 0.95f; // at/above this a hit reads as an accent
+
+ private static readonly int[] Resolutions = { 1, 2, 4, 8 }; // steps per beat
+ private static readonly string[] ResNames = { "1/4", "1/8", "1/16", "1/32" };
+ // The chosen grid outlives a single clip — switching clips shouldn't reset it.
+ private static int _resPersist = 4;
+
+ private readonly IAudioEngine _e;
+ private readonly Func<NotaNote[]> _getNotes;
+ private readonly Action<NotaNote[]> _setNotes;
+ private readonly Action<NotaNote[]>? _setNotesLive;
+ private readonly Func<double> _getLength;
+ private readonly string _title;
+
+ private List<Pad> _pads = new();
+ private readonly List<NotaNote> _notes = new();
+ private readonly Dictionary<int, int> _rowOfPitch = new();
+
+ private int _res = _resPersist;
+ private int _steps, _winStart, _win;
+ private int _selRow = -1;
+ private int _paint; // 0 = idle, 1 = painting hits in, 2 = painting them out
+ private bool _dragging; // a paint / velocity gesture owns the grid
+ private int _playStep = -1;
+
+ private Border[,] _cells = new Border[0, 0];
+ private int[,] _cellNote = new int[0, 0]; // index into _notes of the hit in a cell, -1 = empty
+ private int[,] _shown = new int[0, 0]; // last painted cell signature (-1 = empty)
+ private bool[,] _shownPlay = new bool[0, 0];
+ private Border[] _velFills = Array.Empty<Border>();
+ private Panel[] _velSlots = Array.Empty<Panel>();
+ private Border[] _nameCells = Array.Empty<Border>();
+ private TextBlock[] _nameLabels = Array.Empty<TextBlock>();
+ private TextBlock? _velLabel;
+ private readonly List<Grid> _stepGrids = new(); // ruler + rows + velocity lane, all one width
+
+ /// <summary>The clip was rewritten — refresh the arrangement and any open piano roll.</summary>
+ public event Action? Changed;
+
+ public int TrackId { get; }
+
+ private readonly record struct Pad(int Chain, int Note, string Name);
+
+ /// <param name="setNotesLive">Optional no-undo write used for every frame of a drag
+ /// after its first edit, so a painted run or a velocity sweep is one undo step and not
+ /// one per cell. Falls back to <paramref name="setNotes"/> when the source has none.</param>
+ public DrumPatternView(IAudioEngine engine, int trackId, string title,
+ Func<NotaNote[]> getNotes, Action<NotaNote[]> setNotes, Func<double> getLength,
+ Action<NotaNote[]>? setNotesLive = null)
+ {
+ _e = engine;
+ TrackId = trackId;
+ _title = title;
+ _getNotes = getNotes;
+ _setNotes = setNotes;
+ _setNotesLive = setNotesLive;
+ _getLength = getLength;
+ PointerReleased += (_, _) => { _paint = 0; _dragging = false; };
+ SizeChanged += (_, _) => ApplyGridWidth();
+ Rebuild();
+ }
+
+ // ---- outside world ----------------------------------------------------
+
+ /// <summary>Re-read the clip (a piano-roll edit, recording, undo, a project load) and
+ /// repaint. Cheap when nothing moved — only cells whose content changed are touched —
+ /// and falls back to a full rebuild when the pad set or the clip length changed.</summary>
+ public void Reload()
+ {
+ if (_dragging) return; // mid drag: our own writes are already on screen
+ var pads = ScanPads();
+ if (StepCount() != _steps || !SamePads(pads)) { Rebuild(); return; }
+ ReadNotes();
+ MapCells();
+ StyleAll();
+ }
+
+ /// <summary>Clip-local playback position, in beats (negative / past the end = silent).</summary>
+ public void SetPlayhead(double localBeats, bool playing)
+ {
+ int step = playing && localBeats >= 0 && localBeats < _getLength() ? (int)Math.Floor(localBeats * _res) : -1;
+ if (step == _playStep) return;
+ int prev = _playStep;
+ _playStep = step;
+ RestyleColumn(prev);
+ RestyleColumn(step);
+ }
+
+ // ---- pads -------------------------------------------------------------
+
+ private List<Pad> ScanPads()
+ {
+ var pads = new List<Pad>();
+ int n = _e.RackChainCount(TrackId);
+ for (int c = 0; c < n; c++)
+ {
+ int note = _e.RackChainTriggerNote(TrackId, c);
+ if (note >= 0) pads.Add(new Pad(c, note, _e.RackChainInstrumentName(TrackId, c)));
+ }
+ pads.Sort((x, y) => x.Note.CompareTo(y.Note)); // kick (lowest pad) on top, as on the pad grid
+ return pads;
+ }
+
+ private bool SamePads(List<Pad> pads)
+ {
+ if (pads.Count != _pads.Count) return false;
+ for (int i = 0; i < pads.Count; i++) if (pads[i] != _pads[i]) return false;
+ return true;
+ }
+
+ // ---- model ------------------------------------------------------------
+
+ private int StepCount() => Math.Max(1, (int)Math.Round(_getLength() * _res));
+ private int StepOf(double beat) => (int)Math.Round(beat * _res);
+ private double BeatOf(int step) => step / (double)_res;
+
+ private void ReadNotes()
+ {
+ _notes.Clear();
+ _notes.AddRange(_getNotes());
+ }
+
+ // (row, step) → the first note sitting in that cell. Notes outside the window, past the
+ // clip end or on a pitch no pad claims are simply not mapped — they stay untouched.
+ private void MapCells()
+ {
+ for (int r = 0; r < _cellNote.GetLength(0); r++)
+ for (int s = 0; s < _cellNote.GetLength(1); s++) _cellNote[r, s] = -1;
+ for (int i = 0; i < _notes.Count; i++)
+ {
+ var n = _notes[i];
+ if (!_rowOfPitch.TryGetValue(n.Pitch, out int r)) continue;
+ int s = StepOf(n.StartBeat);
+ if (s < _winStart || s >= _winStart + _win || s >= _steps) continue;
+ if (_cellNote[r, s - _winStart] < 0) _cellNote[r, s - _winStart] = i;
+ }
+ }
+
+ // live: a continuing drag — write without an undo checkpoint, the way the piano roll
+ // streams a note drag (the gesture's first edit already seeded one).
+ private void Commit(bool live = false)
+ {
+ var arr = _notes.ToArray();
+ if (live && _setNotesLive is not null) _setNotesLive(arr); else _setNotes(arr);
+ MapCells();
+ StyleAll();
+ Changed?.Invoke();
+ }
+
+ private void AddHit(int r, int step, float velocity)
+ => _notes.Add(new NotaNote(_pads[r].Note, BeatOf(step), 1.0 / _res, velocity));
+
+ // Clears the cell completely: a step the user switches off must go quiet even when two
+ // notes landed in it (a doubled hit drawn in the piano roll, say).
+ private void ClearCell(int r, int step)
+ {
+ int pitch = _pads[r].Note;
+ for (int i = _notes.Count - 1; i >= 0; i--)
+ if (_notes[i].Pitch == pitch && StepOf(_notes[i].StartBeat) == step) _notes.RemoveAt(i);
+ }
+
+ private void PaintCell(int r, int step, bool on, bool live = false)
+ {
+ bool isOn = _cellNote[r, step - _winStart] >= 0;
+ if (on == isOn) return;
+ if (on) AddHit(r, step, DefaultVel); else ClearCell(r, step);
+ Commit(live);
+ }
+
+ private void AccentCell(int r, int step)
+ {
+ int idx = _cellNote[r, step - _winStart];
+ if (idx < 0) AddHit(r, step, AccentVel);
+ else
+ {
+ var n = _notes[idx];
+ n.Velocity = n.Velocity >= AccentFloor ? DefaultVel : AccentVel;
+ _notes[idx] = n;
+ }
+ Commit();
+ }
+
+ private void SetCellVelocity(int r, int step, float velocity, bool live = false)
+ {
+ int idx = _cellNote[r, step - _winStart];
+ if (idx < 0) AddHit(r, step, velocity);
+ else { var n = _notes[idx]; n.Velocity = velocity; _notes[idx] = n; }
+ Commit(live);
+ }
+
+ private void ClearPattern()
+ {
+ int before = _notes.Count;
+ for (int i = _notes.Count - 1; i >= 0; i--)
+ if (_rowOfPitch.ContainsKey(_notes[i].Pitch)) _notes.RemoveAt(i);
+ if (_notes.Count != before) Commit();
+ }
+
+ // ---- build ------------------------------------------------------------
+
+ private void Rebuild()
+ {
+ _pads = ScanPads();
+ _steps = StepCount();
+ int pages = Math.Max(1, (_steps + MaxCells - 1) / MaxCells);
+ _winStart = Math.Clamp(_winStart / MaxCells, 0, pages - 1) * MaxCells;
+ _win = Math.Max(1, Math.Min(MaxCells, _steps - _winStart));
+ _selRow = _pads.Count == 0 ? -1 : Math.Clamp(_selRow, 0, _pads.Count - 1);
+ _playStep = -1; // the cells are about to be rebuilt; the next tick relights it
+
+ _rowOfPitch.Clear();
+ for (int r = 0; r < _pads.Count; r++) _rowOfPitch.TryAdd(_pads[r].Note, r);
+
+ int rows = Math.Max(1, _pads.Count);
+ _cells = new Border[rows, _win];
+ _cellNote = new int[rows, _win];
+ _shown = new int[rows, _win];
+ _shownPlay = new bool[rows, _win];
+ _nameCells = new Border[rows];
+ _nameLabels = new TextBlock[rows];
+ _velFills = new Border[_win];
+ _velSlots = new Panel[_win];
+
+ ReadNotes();
+ _stepGrids.Clear();
+ Content = _pads.Count == 0 ? EmptyState() : Body();
+ ApplyGridWidth();
+ MapCells();
+ StyleAll(force: true);
+ }
+
+ private Control EmptyState()
+ => new Border
+ {
+ Background = NotaPalette.BgApp,
+ Child = new StackPanel
+ {
+ Spacing = 6,
+ HorizontalAlignment = HorizontalAlignment.Center,
+ VerticalAlignment = VerticalAlignment.Center,
+ Children =
+ {
+ new TextBlock { Text = "No pads loaded", FontSize = 12, Foreground = TextSecondary, HorizontalAlignment = HorizontalAlignment.Center },
+ new TextBlock { Text = "Drop samples on the Drum Rack pads in Devices, then step them here.", FontSize = 10, Foreground = TextTertiary, HorizontalAlignment = HorizontalAlignment.Center },
+ },
+ },
+ };
+
+ private Control Body()
+ {
+ var rows = new StackPanel { Spacing = 2 };
+ for (int r = 0; r < _pads.Count; r++) rows.Children.Add(PadRow(r));
+ var scroll = new ScrollViewer
+ {
+ Content = rows,
+ VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
+ HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
+ Padding = new Thickness(10, 5, 10, 5),
+ };
+
+ var header = Header();
+ var ruler = RulerRow();
+ var velocity = VelocityRow();
+ DockPanel.SetDock(header, Dock.Top);
+ DockPanel.SetDock(ruler, Dock.Top);
+ DockPanel.SetDock(velocity, Dock.Bottom);
+ return new DockPanel { LastChildFill = true, Background = NotaPalette.BgApp, Children = { header, ruler, velocity, scroll } };
+ }
+
+ // ---- header: title · pad count · grid · page · clear ----
+ private Control Header()
+ {
+ var left = new StackPanel
+ {
+ Orientation = Orientation.Horizontal, Spacing = 8, VerticalAlignment = VerticalAlignment.Center,
+ Children =
+ {
+ Cap("PATTERN"),
+ new TextBlock { Text = _title, FontSize = 11, FontWeight = FontWeight.SemiBold, Foreground = TextPrimary, VerticalAlignment = VerticalAlignment.Center },
+ Mono($"{_pads.Count} pad{(_pads.Count == 1 ? "" : "s")} · {_steps} steps", TextTertiary),
+ Mono("click to place · shift-click accents · drag to paint", NotaPalette.TextDisabled),
+ },
+ };
+
+ var right = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 8, VerticalAlignment = VerticalAlignment.Center, [DockPanel.DockProperty] = Dock.Right };
+ right.Children.Add(Cap("GRID"));
+ right.Children.Add(Seg(ResNames, Array.IndexOf(Resolutions, _res), i =>
+ {
+ _res = _resPersist = Resolutions[i];
+ _winStart = 0;
+ Rebuild();
+ }));
+ if (_steps > MaxCells)
+ {
+ int pages = (_steps + MaxCells - 1) / MaxCells;
+ var names = new string[pages];
+ double barSteps = _res * BeatsPerBar;
+ for (int p = 0; p < pages; p++)
+ {
+ int firstBar = (int)(p * MaxCells / barSteps) + 1;
+ int lastBar = (int)Math.Ceiling(Math.Min(_steps, (p + 1) * MaxCells) / barSteps);
+ names[p] = firstBar == lastBar ? $"{firstBar}" : $"{firstBar}–{lastBar}";
+ }
+ right.Children.Add(Cap("BARS"));
+ right.Children.Add(Seg(names, _winStart / MaxCells, p => { _winStart = p * MaxCells; Rebuild(); }));
+ }
+ right.Children.Add(Chip("Clear", ClearPattern));
+
+ var dp = new DockPanel { LastChildFill = false, Margin = new Thickness(12, 0), Children = { left, right } };
+ return new Border { Height = 30, Background = NotaPalette.SurfaceCard, BorderBrush = NotaPalette.BorderDefault, BorderThickness = new Thickness(0, 0, 0, 1), Child = dp };
+ }
+
+ // ---- the beat ruler above the grid ----
+ private Control RulerRow()
+ {
+ int groups = (_win + _res - 1) / _res;
+ var outer = new Grid { ColumnSpacing = 5, Height = 12, VerticalAlignment = VerticalAlignment.Center };
+ for (int g = 0; g < groups; g++) outer.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star));
+ for (int g = 0; g < groups; g++)
+ {
+ int beat = (_winStart + g * _res) / _res;
+ bool bar = beat % BeatsPerBar == 0;
+ var tb = Mono(bar ? $"{beat / BeatsPerBar + 1}" : $"{beat / BeatsPerBar + 1}.{beat % BeatsPerBar + 1}",
+ bar ? NotaPalette.AccentBright : NotaPalette.TextDisabled, 7);
+ tb.HorizontalAlignment = HorizontalAlignment.Left;
+ Grid.SetColumn(tb, g);
+ outer.Children.Add(tb);
+ }
+ SizeGrid(outer);
+ var grid = new Grid { ColumnDefinitions = new ColumnDefinitions($"{NameW},*"), ColumnSpacing = 8, Margin = new Thickness(10, 4, 10, 0) };
+ Grid.SetColumn(outer, 1);
+ grid.Children.Add(outer);
+ return grid;
+ }
+
+ // ---- one pad row: name cell + its steps ----
+ private Control PadRow(int r)
+ {
+ var grid = new Grid { ColumnDefinitions = new ColumnDefinitions($"{NameW},*"), ColumnSpacing = 8, Height = RowH };
+ var name = PadName(r);
+ var steps = BeatGrid(s => StepCell(r, s));
+ Grid.SetColumn(steps, 1);
+ grid.Children.Add(name);
+ grid.Children.Add(steps);
+ return grid;
+ }
+
+ private Control PadName(int r)
+ {
+ var pad = _pads[r];
+ var swatch = new Border { Width = 4, Height = 11, CornerRadius = new CornerRadius(1), Background = Hue(pad.Chain), VerticalAlignment = VerticalAlignment.Center };
+ var name = new TextBlock
+ {
+ Text = pad.Name, FontSize = 9, Foreground = TextPrimary, VerticalAlignment = VerticalAlignment.Center,
+ TextTrimming = TextTrimming.CharacterEllipsis,
+ };
+ var note = Mono(NoteName(pad.Note), TextTertiary, 7);
+ note.HorizontalAlignment = HorizontalAlignment.Right;
+ var inner = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto"), ColumnSpacing = 6, Margin = new Thickness(6, 0) };
+ Grid.SetColumn(name, 1);
+ Grid.SetColumn(note, 2);
+ inner.Children.Add(swatch);
+ inner.Children.Add(name);
+ inner.Children.Add(note);
+
+ var cell = new Border { CornerRadius = new CornerRadius(4), BorderThickness = new Thickness(1), Cursor = new Cursor(StandardCursorType.Hand), Child = inner };
+ ToolTip.SetTip(cell, $"{pad.Name} · {NoteName(pad.Note)} — click to play it and pick its velocity lane");
+ cell.PointerPressed += (_, e) =>
+ {
+ e.Handled = true;
+ SelectRow(r);
+ _e.SetAuditionTrack(TrackId); // audition without arming, as the pad grid does
+ _e.NoteOn(pad.Note, 1.0f);
+ e.Pointer.Capture(cell);
+ };
+ cell.PointerReleased += (_, e) => { _e.NoteOff(pad.Note); e.Pointer.Capture(null); };
+ _nameCells[r] = cell;
+ _nameLabels[r] = name;
+ return cell;
+ }
+
+ private Control StepCell(int r, int step)
+ {
+ var cell = new Border { CornerRadius = new CornerRadius(3), BorderThickness = new Thickness(1), Cursor = new Cursor(StandardCursorType.Hand) };
+ _cells[r, step - _winStart] = cell;
+ cell.PointerPressed += (_, e) =>
+ {
+ e.Handled = true;
+ SelectRow(r);
+ if ((e.KeyModifiers & KeyModifiers.Shift) != 0) { AccentCell(r, step); return; }
+ bool wasOn = _cellNote[r, step - _winStart] >= 0;
+ _paint = wasOn ? 2 : 1; // the first cell decides what the drag does
+ _dragging = true;
+ PaintCell(r, step, !wasOn);
+ };
+ cell.PointerEntered += (_, e) =>
+ {
+ if (_paint == 0) return;
+ // A release outside the grid never reaches us, so re-check the button here.
+ if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) { _paint = 0; _dragging = false; return; }
+ PaintCell(r, step, _paint == 1, live: true);
+ };
+ return cell;
+ }
+
+ // ---- velocity lane for the selected row ----
+ private Control VelocityRow()
+ {
+ _velLabel = Mono("", TextTertiary);
+ var label = new StackPanel
+ {
+ Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center,
+ Children = { Cap("VELOCITY"), _velLabel },
+ };
+ var lane = BeatGrid(VelocityCell);
+ var grid = new Grid { ColumnDefinitions = new ColumnDefinitions($"{NameW},*"), ColumnSpacing = 8, Height = VelH, Margin = new Thickness(10, 0, 10, 0) };
+ Grid.SetColumn(lane, 1);
+ grid.Children.Add(label);
+ grid.Children.Add(lane);
+ return new Border
+ {
+ Height = VelH + 12, Background = NotaPalette.SurfaceDeep, BorderBrush = NotaPalette.BorderDefault,
+ BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(0, 6), Child = grid,
+ };
+ }
+
+ private Control VelocityCell(int step)
+ {
+ int local = step - _winStart;
+ var fill = new Border { VerticalAlignment = VerticalAlignment.Bottom, Background = NotaPalette.Accent, CornerRadius = new CornerRadius(2) };
+ var slot = new Panel { Background = NotaPalette.SurfaceAbyss, Cursor = new Cursor(StandardCursorType.SizeNorthSouth), ClipToBounds = true, Children = { fill } };
+ _velFills[local] = fill;
+ _velSlots[local] = slot;
+ void SetFromY(PointerEventArgs pe, bool live)
+ {
+ if (_selRow < 0) return;
+ double h = Math.Max(1, slot.Bounds.Height);
+ float v = (float)Math.Clamp(1.0 - pe.GetPosition(slot).Y / h, 0.02, 1.0);
+ SetCellVelocity(_selRow, step, v, live);
+ }
+ slot.PointerPressed += (_, e) => { e.Handled = true; e.Pointer.Capture(slot); _dragging = true; SetFromY(e, live: false); };
+ slot.PointerMoved += (_, e) => { if (e.GetCurrentPoint(slot).Properties.IsLeftButtonPressed) SetFromY(e, live: true); };
+ slot.PointerReleased += (_, e) => { e.Pointer.Capture(null); _dragging = false; };
+ return new Border { CornerRadius = new CornerRadius(2), ClipToBounds = true, Child = slot };
+ }
+
+ // Beat-grouped columns: one flexible column per beat, each holding its steps, so any
+ // grid resolution reads as beats at a glance and the whole row stretches to the panel.
+ private Control BeatGrid(Func<int, Control> makeCell)
+ {
+ int groups = (_win + _res - 1) / _res;
+ var outer = new Grid { ColumnSpacing = 5 };
+ for (int g = 0; g < groups; g++) outer.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star));
+ for (int g = 0; g < groups; g++)
+ {
+ int count = Math.Min(_res, _win - g * _res);
+ var inner = new Grid { ColumnSpacing = 2 };
+ for (int k = 0; k < count; k++) inner.ColumnDefinitions.Add(new ColumnDefinition(GridLength.Star));
+ for (int k = 0; k < count; k++)
+ {
+ var c = makeCell(_winStart + g * _res + k);
+ Grid.SetColumn(c, k);
+ inner.Children.Add(c);
+ }
+ Grid.SetColumn(inner, g);
+ outer.Children.Add(inner);
+ }
+ SizeGrid(outer);
+ return outer;
+ }
+
+ // Steps stay drum-machine sized instead of stretching a 16-step bar across a 1500px
+ // panel. Star columns inside a left-aligned grid would collapse to nothing (nothing in
+ // them has a width of its own), so every step grid — the ruler, the rows, the velocity
+ // lane — is given the same explicit width and divides it between its beats.
+ private void SizeGrid(Grid outer)
+ {
+ outer.HorizontalAlignment = HorizontalAlignment.Left;
+ _stepGrids.Add(outer);
+ }
+
+ private void ApplyGridWidth()
+ {
+ if (_stepGrids.Count == 0) return;
+ int groups = (_win + _res - 1) / _res;
+ double natural = (groups - 1) * 5;
+ for (int g = 0; g < groups; g++)
+ {
+ int count = Math.Min(_res, _win - g * _res);
+ natural += count * StepW + (count - 1) * 2;
+ }
+ double avail = Bounds.Width - NameW - 28; // name column + its gap + the row margins
+ double w = avail > 60 ? Math.Min(natural, avail) : natural;
+ // An unset Width is NaN, and every comparison against it is false — check for it.
+ foreach (var g in _stepGrids) if (double.IsNaN(g.Width) || Math.Abs(g.Width - w) > 0.5) g.Width = w;
+ }
+
+ // ---- painting ---------------------------------------------------------
+
+ private void SelectRow(int r)
+ {
+ if (r == _selRow || r < 0 || r >= _pads.Count) return;
+ _selRow = r;
+ for (int i = 0; i < _pads.Count; i++) StyleName(i);
+ StyleVelocityLane();
+ }
+
+ private void StyleAll(bool force = false)
+ {
+ for (int r = 0; r < _pads.Count; r++)
+ {
+ StyleName(r);
+ for (int s = _winStart; s < _winStart + _win; s++) StyleCell(r, s, force);
+ }
+ StyleVelocityLane();
+ }
+
+ private void StyleName(int r)
+ {
+ var cell = _nameCells[r];
+ if (cell is null) return;
+ bool sel = r == _selRow;
+ cell.Background = sel ? NotaPalette.AccentSubtle : NotaPalette.SurfaceInset;
+ cell.BorderBrush = sel ? NotaPalette.AccentTint : NotaPalette.BorderDefault;
+ _nameLabels[r].Foreground = sel ? NotaPalette.AccentBright : NotaPalette.TextPrimary;
+ }
+
+ private void StyleCell(int r, int step, bool force = false)
+ {
+ int local = step - _winStart;
+ var cell = _cells[r, local];
+ if (cell is null) return;
+ int idx = _cellNote[r, local];
+ float vel = idx >= 0 ? Math.Clamp(_notes[idx].Velocity, 0f, 1f) : 0f;
+ bool on = idx >= 0;
+ bool accent = on && vel >= AccentFloor;
+ // Velocity is drawn in 8 steps of fill so the washes stay a small cached set —
+ // NotaPalette.Wash registers every (slot, alpha) pair for the lifetime of the app.
+ int level = on ? Math.Clamp((int)Math.Round(vel * 7), 0, 7) : -1;
+ int sig = on ? level * 2 + (accent ? 1 : 0) : -1;
+ bool play = step == _playStep;
+ if (!force && sig == _shown[r, local] && play == _shownPlay[r, local]) return;
+ _shown[r, local] = sig;
+ _shownPlay[r, local] = play;
+
+ cell.Background = on
+ ? NotaPalette.Wash(Hue(_pads[r].Chain), (byte)(0x50 + level * 0x18))
+ : step % (_res * BeatsPerBar) == 0 ? NotaPalette.SurfaceInset
+ : step % _res == 0 ? NotaPalette.SurfaceDeep
+ : NotaPalette.SurfaceAbyss;
+ cell.BorderBrush = play ? NotaPalette.TealBright
+ : accent ? NotaPalette.AccentBright
+ : on ? Hue(_pads[r].Chain)
+ : step % (_res * BeatsPerBar) == 0 ? NotaPalette.BorderDefault
+ : NotaPalette.GraphBorder;
+ cell.BorderThickness = new Thickness(play ? 2 : 1);
+ }
+
+ private void RestyleColumn(int step)
+ {
+ if (step < _winStart || step >= _winStart + _win) return;
+ for (int r = 0; r < _pads.Count; r++) StyleCell(r, step);
+ }
+
+ private void StyleVelocityLane()
+ {
+ if (_velLabel is not null)
+ _velLabel.Text = _selRow >= 0 && _selRow < _pads.Count ? _pads[_selRow].Name : "—";
+ for (int s = 0; s < _win; s++)
+ {
+ var fill = _velFills[s];
+ var slot = _velSlots[s];
+ if (fill is null || slot is null) continue;
+ int idx = _selRow >= 0 ? _cellNote[_selRow, s] : -1;
+ float vel = idx >= 0 ? Math.Clamp(_notes[idx].Velocity, 0f, 1f) : 0f;
+ fill.Height = idx >= 0 ? Math.Max(2, VelH * vel) : 0;
+ fill.Background = vel >= AccentFloor ? NotaPalette.AccentBright : NotaPalette.Accent;
+ int step = _winStart + s;
+ slot.Background = step % (_res * BeatsPerBar) == 0 ? NotaPalette.SurfaceInset : NotaPalette.SurfaceAbyss;
+ }
+ }
+
+ // ---- small shared bits ------------------------------------------------
+
+ // The palette slot itself, so a theme change repaints the pad hues (a copy would freeze them).
+ private static SolidColorBrush Hue(int chain) => NotaPalette.TrackBrushes[((chain % 8) + 8) % 8];
+
+ private static TextBlock Cap(string text)
+ => new() { Text = text, FontSize = 8, FontWeight = FontWeight.Bold, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center };
+
+ private static TextBlock Mono(string text, IBrush colour, double size = 8)
+ {
+ var tb = new TextBlock { Text = text, FontSize = size, Foreground = colour, VerticalAlignment = VerticalAlignment.Center };
+ tb.BindResource(TextBlock.FontFamilyProperty, "Font.Mono");
+ return tb;
+ }
+
+ private static Control Seg(string[] names, int sel, Action<int> onSelect)
+ {
+ var row = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 1 };
+ for (int i = 0; i < names.Length; i++)
+ {
+ int iv = i;
+ bool on = i == sel;
+ var chip = new Border
+ {
+ CornerRadius = new CornerRadius(2), Padding = new Thickness(6, 1), Cursor = new Cursor(StandardCursorType.Hand),
+ Background = on ? NotaPalette.Accent : Brushes.Transparent,
+ Child = new TextBlock { Text = names[i], FontSize = 8, FontWeight = on ? FontWeight.SemiBold : FontWeight.Normal, Foreground = on ? NotaPalette.TextOnAccent : NotaPalette.TextTertiary },
+ };
+ chip.PointerPressed += (_, e) => { e.Handled = true; onSelect(iv); };
+ row.Children.Add(chip);
+ }
+ return new Border
+ {
+ Background = NotaPalette.BgSunken, BorderBrush = NotaPalette.BorderDefault, BorderThickness = new Thickness(1),
+ CornerRadius = new CornerRadius(3), Padding = new Thickness(1), VerticalAlignment = VerticalAlignment.Center, Child = row,
+ };
+ }
+
+ private static Control Chip(string text, Action onClick)
+ {
+ var b = new Border
+ {
+ BorderThickness = new Thickness(1), BorderBrush = NotaPalette.BorderStrong, Background = NotaPalette.SurfaceRaised,
+ CornerRadius = new CornerRadius(4), Padding = new Thickness(8, 2), Cursor = new Cursor(StandardCursorType.Hand),
+ VerticalAlignment = VerticalAlignment.Center,
+ Child = new TextBlock { Text = text, FontSize = 9, Foreground = NotaPalette.TextSecondary },
+ };
+ b.PointerPressed += (_, e) => { e.Handled = true; onClick(); };
+ return b;
+ }
+}
diff --git a/src/managed/Nota.App/MainWindow.Detail.cs b/src/managed/Nota.App/MainWindow.Detail.cs
index 50e35ec0..95465b5e 100644
--- a/src/managed/Nota.App/MainWindow.Detail.cs
+++ b/src/managed/Nota.App/MainWindow.Detail.cs
@@ -89,13 +89,17 @@ public partial class MainWindow
// the Clip tab over to Devices, so refresh the chain underneath and re-point the Clip
// tab at the newly selected clip. With no clip to show, Devices takes the panel as before.
bool keepClipTab = !DetailFloating && DetailPanel.IsVisible
- && DetailBody.Content is ClipEditorView or AudioClipEditorView
+ && DetailBody.Content is ClipEditorView or AudioClipEditorView or DrumPatternView
&& SelectedClip(out _, out _, out _);
+ bool wasPattern = keepClipTab && DetailBody.Content is DrumPatternView;
ShowDevices(trackId, takeOverPanel: !keepClipTab);
if (_modular?.IsVisible == true) _modular.Show(trackId); // keep the graph on the selected track
SyncClipTab();
- if (keepClipTab) OnDetailClip(this, new RoutedEventArgs());
+ // The new clip may be on a track with no Drum Rack, so a pattern user falls back to
+ // the piano roll rather than to Devices.
+ if (wasPattern && DetailPatternBtn.IsEnabled) OnDetailPattern(this, new RoutedEventArgs());
+ else if (keepClipTab) OnDetailClip(this, new RoutedEventArgs());
}
// Clear all clip-editor state and blank the clip pane (placeholder while floating, so the
@@ -110,6 +114,12 @@ public partial class MainWindow
_editorClipIndex = -1;
_audioEditorTrackId = -1;
_audioEditorClipIndex = -1;
+ _patternView = null;
+ _patternTrackId = -1;
+ _patternClipIndex = -1;
+ _patternScene = -1;
+ _sessionSlotTrack = -1;
+ _sessionSlotScene = -1;
if (DetailFloating) _detailWindow!.ClipHost.Content = ClipPlaceholder();
}
@@ -126,11 +136,124 @@ public partial class MainWindow
}
// Enable the Clip tab for the current context: in the arrangement, whenever a
- // clip is selected; in Session, when a slot editor has been opened.
+ // clip is selected; in Session, when a slot editor has been opened. The Pattern tab
+ // rides along on the same target, narrowed to Drum Rack MIDI.
internal void SyncClipTab()
- => DetailClipBtn.IsEnabled = _session?.IsVisible == true
+ {
+ DetailClipBtn.IsEnabled = _session?.IsVisible == true
? _clipEditor is not null
: SelectedClip(out _, out _, out _);
+ DetailPatternBtn.IsEnabled = PatternTarget(out _, out _, out _);
+ }
+
+ // --- Detail · Pattern (Drum Rack step grid) -----------------------------
+
+ // The Pattern tab edits the same notes as the Clip tab, so it targets the same clip —
+ // but only when those notes drive a Drum Rack, since the rows are its pads.
+ private bool PatternTarget(out int trackId, out int clipIndex, out int scene)
+ {
+ trackId = -1; clipIndex = -1; scene = -1;
+ if (_session?.IsVisible == true)
+ {
+ if (_sessionSlotTrack <= 0 || _sessionSlotScene < 0 || !IsDrumRackTrack(_sessionSlotTrack)) return false;
+ trackId = _sessionSlotTrack; scene = _sessionSlotScene;
+ return true;
+ }
+ if (!SelectedClip(out int tid, out int ci, out bool isMidi) || !isMidi || !IsDrumRackTrack(tid)) return false;
+ trackId = tid; clipIndex = ci;
+ return true;
+ }
+
+ private bool IsDrumRackTrack(int trackId) => trackId > 0 && Engine.TrackInstrumentKind(trackId) == 4;
+
+ // Build the step grid over one clip (scene >= 0: a Session slot). Both note sources are
+ // wrapped here rather than inside the view, so the view stays a plain editor of "some
+ // notes over some beats" and the staleness guard lives with the other editors.
+ private void BuildPatternView(int trackId, int clipIndex, int scene)
+ {
+ Func<NotaNote[]> get;
+ Action<NotaNote[]> set;
+ Action<NotaNote[]>? setLive = null;
+ Func<double> length;
+ string title;
+ if (scene >= 0)
+ {
+ title = $"Track {trackId} · Scene {scene + 1}";
+ get = () => Engine.GetSessionNotes(trackId, scene);
+ set = notes => { Engine.SetSessionNotes(trackId, scene, notes); _session?.Refresh(); };
+ length = () => { double l = Engine.SessionSlotLength(trackId, scene); return l > 0 ? l : 4; };
+ }
+ else
+ {
+ title = $"Track {trackId} clip";
+ get = () => Engine.GetClipNotes(trackId, clipIndex);
+ // Same staleness guard as the piano roll: the clip can be deleted, undone or
+ // reloaded under an editor that is still on screen.
+ set = notes =>
+ {
+ if (!Engine.TryGetClipInfo(trackId, clipIndex, out var live) || !live.IsMidi) { InvalidatePatternView(); return; }
+ Engine.SetClipNotes(trackId, clipIndex, notes);
+ };
+ // Painting a run of steps / sweeping the velocity lane streams through the
+ // no-checkpoint write, so the whole gesture is one undo step (as in the roll).
+ setLive = notes =>
+ {
+ if (!Engine.TryGetClipInfo(trackId, clipIndex, out var live) || !live.IsMidi) { InvalidatePatternView(); return; }
+ Engine.SetClipNotesLive(trackId, clipIndex, notes);
+ };
+ length = () => Engine.TryGetClipInfo(trackId, clipIndex, out var ci) && ci.LengthBeats > 0 ? ci.LengthBeats : 4;
+ }
+
+ var view = new DrumPatternView(Engine, trackId, title, get, set, length, setLive);
+ // A step written here is a note written to the clip: show it on the timeline and in
+ // the piano roll straight away, the same way a roll edit shows up in the grid.
+ view.Changed += () => { Timeline.Refresh(rebuildHeaders: false); ReloadEditorNotes(); };
+ _patternView = view;
+ _patternTrackId = trackId;
+ _patternClipIndex = clipIndex;
+ _patternScene = scene;
+ }
+
+ private void ShowPatternPanel()
+ {
+ _lastClipEditor = _patternView;
+ SetHost(ClipDetailHost, _patternView);
+ SetDetailChip(_patternTrackId);
+ if (DetailFloating) return; // floating: top pane only
+ DetailPatternBtn.IsEnabled = true;
+ DetailPatternBtn.IsChecked = true;
+ DetailDevicesBtn.IsChecked = false;
+ DetailClipBtn.IsChecked = false;
+ ShowDetail(260, honorPersist: true);
+ }
+
+ private void OnDetailPattern(object? sender, RoutedEventArgs e)
+ {
+ if (!PatternTarget(out int tid, out int ci, out int scene))
+ {
+ DetailPatternBtn.IsChecked = false;
+ if (_vm is not null) _vm.StatusText = "Select a MIDI clip on a Drum Rack track to step it.";
+ return;
+ }
+ if (_patternView is null || _patternTrackId != tid || _patternClipIndex != ci || _patternScene != scene)
+ BuildPatternView(tid, ci, scene);
+ else
+ _patternView.Reload(); // follow anything the piano roll / arrangement changed
+ ShowPatternPanel();
+ }
+
+ // Drop a pattern grid whose clip no longer exists, mirroring InvalidateClipEditor.
+ private void InvalidatePatternView()
+ {
+ bool onScreen = DetailBody.Content is DrumPatternView;
+ _patternView = null;
+ _patternTrackId = -1;
+ _patternClipIndex = -1;
+ _patternScene = -1;
+ DetailPatternBtn.IsEnabled = false;
+ DetailPatternBtn.IsChecked = false;
+ if (onScreen) DetailPanel.IsVisible = false;
+ }
// takeOverPanel: false shows the chain without claiming the docked panel, for callers that
// only follow the selection (see OnTrackSelected). Explicit "show me the devices" callers
@@ -157,6 +280,7 @@ public partial class MainWindow
if (DetailFloating || takeOverPanel) SetHost(DeviceHost, _deviceChain);
if (DetailFloating || !takeOverPanel) return; // floating: bottom pane only, don't touch the docked row/tabs
DetailDevicesBtn.IsChecked = true;
+ DetailPatternBtn.IsChecked = false;
DetailClipBtn.IsChecked = false;
ShowDetail(320, honorPersist: false); // Devices: natural card-fitting height
}
@@ -192,6 +316,7 @@ public partial class MainWindow
DetailClipBtn.IsEnabled = true;
DetailClipBtn.IsChecked = true;
DetailDevicesBtn.IsChecked = false;
+ DetailPatternBtn.IsChecked = false;
ShowDetail(250, honorPersist: true);
}
@@ -266,6 +391,7 @@ public partial class MainWindow
DetailClipBtn.IsEnabled = true;
DetailClipBtn.IsChecked = true;
DetailDevicesBtn.IsChecked = false;
+ DetailPatternBtn.IsChecked = false;
ShowDetail(250, honorPersist: true);
}
@@ -277,6 +403,10 @@ public partial class MainWindow
{
if (trackId <= 0 || clipIndex < 0 || !Engine.TryGetClipInfo(trackId, clipIndex, out var ci)) return;
+ // The step grid snapshots the clip length too — a trim adds or drops steps.
+ if (_patternView is not null && _patternTrackId == trackId && _patternClipIndex == clipIndex && _patternScene < 0)
+ _patternView.Reload();
+
if (_editorRoll is not null && _editorTrackId == trackId && _editorClipIndex == clipIndex)
{
double len = ci.LengthBeats > 0 ? ci.LengthBeats : _editorRoll.LengthBeats;
@@ -294,6 +424,7 @@ public partial class MainWindow
private void ReloadEditorNotes()
{
+ _patternView?.Reload(); // the step grid is a second view of the same notes
if (_vm is null || _editorRoll is null || _editorTrackId < 0) return;
double len = Engine.TryGetClipInfo(_editorTrackId, _editorClipIndex, out var ci) && ci.LengthBeats > 0 ? ci.LengthBeats : _editorRoll.LengthBeats;
_editorRoll.SetNotes(Engine.GetClipNotes(_editorTrackId, _editorClipIndex), len);
@@ -302,13 +433,21 @@ public partial class MainWindow
// Tab (when the detail panel was last used) flips between Devices and Clip.
private void ToggleDetailTab()
{
+ var e = new RoutedEventArgs();
+ // Devices → Pattern → Clip → Devices, skipping tabs the current selection can't fill.
if (DetailBody.Content is DeviceChainView)
{
- if (DetailClipBtn.IsEnabled) OnDetailClip(this, new RoutedEventArgs());
+ if (DetailPatternBtn.IsEnabled) OnDetailPattern(this, e);
+ else if (DetailClipBtn.IsEnabled) OnDetailClip(this, e);
+ }
+ else if (DetailBody.Content is DrumPatternView)
+ {
+ if (DetailClipBtn.IsEnabled) OnDetailClip(this, e);
+ else OnDetailDevices(this, e);
}
else
{
- OnDetailDevices(this, new RoutedEventArgs());
+ OnDetailDevices(this, e);
}
}
@@ -370,6 +509,8 @@ public partial class MainWindow
// Audio slot → the compact audio-slot editor; MIDI slot → the piano roll.
if (Engine.TryGetSessionAudioSlot(trackId, scene, out var _))
{
+ _sessionSlotTrack = -1; _sessionSlotScene = -1; // audio slot: no pattern to step
+ SyncClipTab();
var audioEd = new SessionAudioSlotEditor(Engine, trackId, scene, new SolidColorBrush(TrackColor(trackId)));
_editorRoll = null; _clipEditor = null;
_editorTrackId = -1; _editorClipIndex = -1;
@@ -384,6 +525,9 @@ public partial class MainWindow
return;
}
+ _sessionSlotTrack = trackId; // so the Pattern tab can target this slot
+ _sessionSlotScene = scene;
+ SyncClipTab(); // a Drum Rack slot lights the Pattern tab up
var roll = new PianoRollView
{
Commit = notes =>
@@ -392,6 +536,7 @@ public partial class MainWindow
for (int i = 0; i < notes.Count; i++) arr[i] = notes[i];
Engine.SetSessionNotes(trackId, scene, arr);
_session?.Refresh();
+ _patternView?.Reload();
},
PollHeldNotes = buf => Engine.LiveHeldNotes(buf),
};
@@ -411,6 +556,7 @@ public partial class MainWindow
DetailClipBtn.IsEnabled = true; // a clip is now available to edit
DetailClipBtn.IsChecked = true;
DetailDevicesBtn.IsChecked = false;
+ DetailPatternBtn.IsChecked = false;
ShowDetail(250, honorPersist: true);
}
}
diff --git a/src/managed/Nota.App/MainWindow.DetailWindow.cs b/src/managed/Nota.App/MainWindow.DetailWindow.cs
index d9961e36..f17da8df 100644
--- a/src/managed/Nota.App/MainWindow.DetailWindow.cs
+++ b/src/managed/Nota.App/MainWindow.DetailWindow.cs
@@ -46,7 +46,7 @@ public partial class MainWindow
// Move current content across: device chain → bottom pane, current clip editor → top.
if (_deviceChain is not null) SetHost(win.ChainHost, _deviceChain);
- Control? clip = DetailBody.Content is ClipEditorView or AudioClipEditorView
+ Control? clip = DetailBody.Content is ClipEditorView or AudioClipEditorView or DrumPatternView
? (Control)DetailBody.Content! : _lastClipEditor;
if (clip is not null) SetHost(win.ClipHost, clip);
else win.ClipHost.Content = ClipPlaceholder();
diff --git a/src/managed/Nota.App/MainWindow.Input.cs b/src/managed/Nota.App/MainWindow.Input.cs
index e0578efb..a333dc3b 100644
--- a/src/managed/Nota.App/MainWindow.Input.cs
+++ b/src/managed/Nota.App/MainWindow.Input.cs
@@ -85,7 +85,7 @@ public partial class MainWindow
// sound a note. Bare letters still play via the KeyToPitch map below.
bool mod = (e.KeyModifiers & (KeyModifiers.Meta | KeyModifiers.Control | KeyModifiers.Alt)) != 0;
- // Tab toggles the detail panel's Devices/Clip tabs when it was the last area used.
+ // Tab cycles the detail panel's Devices/Pattern/Clip tabs when it was the last area used.
if (!mod && e.Key == Key.Tab && DetailPanel.IsVisible && _detailWasLastFocused)
{
ToggleDetailTab();
diff --git a/src/managed/Nota.App/MainWindow.axaml b/src/managed/Nota.App/MainWindow.axaml
index 3317dac4..3af8ccbb 100644
--- a/src/managed/Nota.App/MainWindow.axaml
+++ b/src/managed/Nota.App/MainWindow.axaml
@@ -324,6 +324,9 @@
<Border Classes="segmented" VerticalAlignment="Center">
<StackPanel Orientation="Horizontal" Spacing="2">
<ToggleButton x:Name="DetailDevicesBtn" Classes="seg" Content="Devices" Click="OnDetailDevices"/>
+ <ToggleButton x:Name="DetailPatternBtn" Classes="seg" Content="Pattern" IsEnabled="False"
+ ToolTip.Tip="Step the selected MIDI clip on a Drum Rack track"
+ Click="OnDetailPattern"/>
<ToggleButton x:Name="DetailClipBtn" Classes="seg" Content="Clip" IsEnabled="False"
ToolTip.Tip="Select a MIDI clip to edit it" Click="OnDetailClip"/>
</StackPanel>
diff --git a/src/managed/Nota.App/MainWindow.axaml.cs b/src/managed/Nota.App/MainWindow.axaml.cs
index 560ee112..ca7e0b54 100644
--- a/src/managed/Nota.App/MainWindow.axaml.cs
+++ b/src/managed/Nota.App/MainWindow.axaml.cs
@@ -57,6 +57,15 @@ public partial class MainWindow : Window
private int _audioEditorTrackId = -1;
private int _audioEditorClipIndex = -1;
private PianoRollView? _editorRoll;
+ // Detail · Pattern (Drum Rack step grid) — targets the same clip as the Clip tab, or the
+ // open Session slot (scene >= 0, clip index unused).
+ private DrumPatternView? _patternView;
+ private int _patternTrackId = -1;
+ private int _patternClipIndex = -1;
+ private int _patternScene = -1;
+ // The Session slot whose editor is open, so the Pattern tab can target it too.
+ private int _sessionSlotTrack = -1;
+ private int _sessionSlotScene = -1;
// Remembered detail-panel height once the user drags the splitter, so reopening the
// panel keeps their size instead of snapping back to the per-mode default. 0 = unset.
@@ -216,6 +225,10 @@ public partial class MainWindow : Window
if (_clipEditor is { IsEffectivelyVisible: true } && _editorRoll is not null
&& _editorTrackId > 0 && Engine.TryGetClipInfo(_editorTrackId, _editorClipIndex, out var pci) && pci.IsMidi)
_editorRoll.SetPlayhead(beats - pci.StartBeat, vm.Engine.IsPlaying);
+ // Same for the Drum Rack step grid (Session slots run their own clock → skipped).
+ if (_patternView is { IsEffectivelyVisible: true } && _patternTrackId > 0 && _patternScene < 0
+ && Engine.TryGetClipInfo(_patternTrackId, _patternClipIndex, out var ppi) && ppi.IsMidi)
+ _patternView.SetPlayhead(beats - ppi.StartBeat, vm.Engine.IsPlaying);
double load = Math.Clamp(vm.Engine.CpuLoad, 0, 1); // live DSP load (Phase 11)
CpuFill.Width = load * 56;
@@ -243,7 +256,8 @@ public partial class MainWindow : Window
Browser.EditTagsRequested += OnBrowserEditTags;
_deviceChain = new DeviceChainView(vm.Engine, _factory, App.Services.GetService<IPluginCatalog>());
- _deviceChain.Changed += () => { Timeline.Refresh(); if (_modular?.IsVisible == true) _modular.Refresh(); };
+ // A pad added / removed / renamed in the Drum Rack card changes the pattern grid's rows.
+ _deviceChain.Changed += () => { Timeline.Refresh(); _patternView?.Reload(); if (_modular?.IsVisible == true) _modular.Refresh(); };
_deviceChain.PresetSaveRequested += OnSavePreset;
_deviceChain.RackPresetSaveRequested += OnSaveRackChainPreset;
_deviceChain.ItemDropped += OnDevicePanelDrop; // browser drag onto the device panel
@@ -293,14 +307,14 @@ public partial class MainWindow : Window
// ignored; only a real drag differs).
DetailPanel.SizeChanged += (_, e) =>
{
- bool clipActive = DetailBody.Content is ClipEditorView or AudioClipEditorView;
+ bool clipActive = DetailBody.Content is ClipEditorView or AudioClipEditorView or DrumPatternView;
if (clipActive && DetailPanel.IsVisible && e.NewSize.Height > 120
&& Math.Abs(e.NewSize.Height - _lastSetDetailHeight) > 1.0)
_detailHeight = e.NewSize.Height;
};
// Track whether the detail panel was the last area the user clicked into, so Tab
- // can toggle its Devices/Clip tabs (see OnKeyDown). Tunnel + handledEventsToo so it
+ // can cycle its Devices/Pattern/Clip tabs (see OnKeyDown). Tunnel + handledEventsToo so it
// sees every press regardless of what consumes it.
AddHandler(PointerPressedEvent, (_, e) =>
{
diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.cs
index c9e7f9a0..4e5eff1d 100644
--- a/src/managed/Nota.App/PreferencesWindow.cs
+++ b/src/managed/Nota.App/PreferencesWindow.cs
@@ -575,7 +575,7 @@ public sealed class PreferencesWindow : NotaWindow
("⌘Z ⌘⇧Z", "Undo / redo"),
("⌘A", "Toggle automation mode"),
("⌘M", "Toggle the Mixer view"),
- ("Tab", "Switch Devices / Clip in the detail panel"),
+ ("Tab", "Cycle Devices / Pattern / Clip in the detail panel"),
("Esc", "Cancel the current gesture / clear the selection · close the patch-bay overlay"),
("⌘G ⌘⇧G", "Group / ungroup selected tracks"),
("⌘C ⌘X ⌘V", "Copy / cut / paste clip (or automation range)"),