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.

(feat) redesign of clip editor

Egor Khindikaynen73255ac380d6
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 9a0ff011..1e135644 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -17,6 +17,15 @@ created, and the build-and-publish run starts.
Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
### Fixed
+- In the piano roll you can now drag a note's left edge to change where it starts; its end
+ stays put.
+- Stacked notes (a chord) no longer hide each other's velocity. Grab a stem by its cap to
+ pick one, or select several notes and drag any of their stems to move them all together.
+ ⇧-click a stem to add it to the selection.
+- Duplicating notes (⌘D) now replaces the notes the copy lands on, like duplicating a clip in
+ the arrangement. Before, the copy was stacked on top of them.
+- When you zoom out in the piano roll, the area past the clip's end is darkened and marked
+ with a line, so you can see where the clip ends.
- Right-clicking empty space on a track now always opens a menu. It used to show nothing
when there was no copied clip.
@@ -52,6 +61,14 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
tempo detection.
### Changed
+- **The clip editor has a new look.** MIDI and audio clips now share one layout: a header
+ with the clip's name and modes, an inspector on the left, and the canvas. The piano-roll
+ keyboard is dark, so the notes stand out, and selected notes are brass. The ruler shows
+ beats only, with the loop as a brass strip along the top. Clip Tools previews show as
+ brass outlines over your notes, and **Apply** lights up only when there is something to
+ apply. Envelopes draw over the dimmed notes instead of replacing the roll. In audio
+ clips, the on/off buttons are switches, Envelope is a tab next to Sample, warp markers
+ have their own strip above the waveform, and the audio past the clip's end is darkened.
- The audio engine now has its own version (starting at 0.2.5, shown in About) instead of a
fixed 0.1.0; it's bumped with each release that changes the engine.
- Record and Metronome now need ⌘ / Ctrl: **⌘R** toggles Record and **⌘M** the metronome, so
diff --git a/DESIGN.md b/DESIGN.md
index e29c48a5..1420df5a 100644
--- a/DESIGN.md
+++ b/DESIGN.md
@@ -402,6 +402,15 @@ redesign) and the host-plugin / parameter-list stubs (230, 190). Rhythm moved on
- **Arrangement:** track rows 64 (the header carries every control), group rows 26 (open to
64 while selected), header column 228, default zoom 28 px per beat. Every y ↔ row
conversion goes through `ArrangementView.RowTop` / `RowAtY`.
+- **Clip editor** (MIDI and audio share one frame, `ClipEditorKit`): header 38 whose first
+ 232 is the clip cell (3 px track-colour bar, name, mono kind badge), modes as shell
+ segments after it; inspector 232 on the left, sections split by hairlines and ending in
+ one Ink 5 hint line; the canvas sits in the well. MIDI: keys 48, rows 12, a beats-only
+ ruler 24 with the loop as a 3 px brass strip, notes in the track colour quieter by
+ velocity, selected notes brass, tool previews as brass outlines; the tools panel is 272
+ and Apply is its one solid-brass action, lit only while a preview is pending. Audio: a
+ ruler 24, a 22 px warp-marker strip, and everything outside the played region darkened.
+ Envelopes are a mode (a tab), drawn in brass over a wash of the canvas.
## Enforced by tests
diff --git a/src/managed/Nota.App/AudioClipEditorView.cs b/src/managed/Nota.App/AudioClipEditorView.cs
index ffb6b663..301c4152 100644
--- a/src/managed/Nota.App/AudioClipEditorView.cs
+++ b/src/managed/Nota.App/AudioClipEditorView.cs
@@ -1,10 +1,12 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// Detail · Clip for AUDIO clips: a waveform view with a live playback cursor
-// beside a 200px props rail (name / start / length / gain / pitch / file info,
-// plus a Warp placeholder for a later milestone). Mirrors ClipEditorView's
-// layout so the Clip tab looks the same for MIDI and audio.
+// 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,
+// 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 is a mode of the canvas, not a checkbox.
using System;
using System.Globalization;
@@ -15,56 +17,43 @@ using Avalonia.Input;
using Avalonia.Layout;
using Avalonia.Media;
using Nota.Application;
+using static Nota.App.ClipEditorKit;
namespace Nota.App;
public sealed class AudioClipEditorView : UserControl
{
- // Ember Graphite palette (matches the MIDI editor's props rail).
- private static readonly IBrush Panel = NotaPalette.SurfaceCard;
- private static readonly IBrush BorderDef = NotaPalette.BorderDefault;
- private static readonly IBrush BorderStrong = NotaPalette.BorderStrong;
- private static readonly IBrush Sunken = NotaPalette.BgSunken;
- private static readonly IBrush Raised = NotaPalette.SurfaceRaised;
- private static readonly IBrush Brass = NotaPalette.Accent;
- private static readonly IBrush AccentBright = NotaPalette.AccentBright;
- private static readonly IBrush AccentSubtle = NotaPalette.AccentSubtle;
- private static readonly IBrush TextPrimary = NotaPalette.TextPrimary;
- private static readonly IBrush TextSecondary = NotaPalette.TextSecondary;
- private static readonly IBrush TextTertiary = NotaPalette.TextTertiary;
-
private readonly IAudioEngine _engine;
private readonly Action _onChanged;
public int TrackId { get; }
public int ClipIndex { get; }
private readonly WaveformView _wave = new();
- private readonly TextBlock _lengthText;
- private readonly TextBlock _pitchText;
- private readonly TextBlock _gainText;
- private readonly TextBlock _fileText;
- private readonly MiniFader _gain;
+ private readonly TextBlock _startText = Mono("");
+ private readonly TextBlock _lengthText = Mono("");
+ private readonly TextBlock _pitchText = Mono("");
+ private readonly TextBlock _fileText = Meta("—");
+ private readonly TextBlock _warpModeText = new() { FontSize = NotaType.Body };
+ private readonly TextBlock _detectedText = Mono("—");
+ private readonly TextBlock _markerCount = Meta("");
+ private 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 double _startBeat;
private double _lengthBeats = 4;
+ private double _gain = 1;
private int _pitch;
private bool _reversed;
- private readonly TextBlock _reverseToggleText;
private bool _warpEnabled;
private int _warpMode = 3; // Complex
private bool _snapToGrid = true; // trim brackets snap to whole beats (default on)
- private readonly TextBlock _snapToggleText;
- private readonly TextBlock _warpToggleText;
- private readonly TextBlock _warpModeText;
- private readonly TextBlock _autoText;
- private readonly TextBlock _transientText;
- private readonly TextBlock _detectedText;
private double _detectedBpm;
- private readonly TextBlock _envToggleText;
- private readonly TextBlock _envTargetText;
private bool _envMode;
private int _envTarget; // 0 = Volume (0..1), 1 = Pan (-1..1)
private static readonly string[] WarpModes = { "Beats", "Tones", "Texture", "Complex", "Complex Pro", "Re-Pitch" };
+ private static readonly string[] EnvTargets = { "Volume", "Pan" };
public AudioClipEditorView(IAudioEngine engine, int trackId, int clipIndex, IBrush clipColor, Action onChanged)
{
@@ -99,123 +88,49 @@ public sealed class AudioClipEditorView : UserControl
else _engine.SetClipVolumeEnvelope(TrackId, ClipIndex, pts);
_onChanged();
};
- _envToggleText = new TextBlock { Text = "Edit envelope: Off", FontSize = 10, Foreground = TextSecondary, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
- _envTargetText = new TextBlock { Text = "Volume", FontSize = 10, Foreground = TextSecondary, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
-
- _lengthText = Mono("—");
- _pitchText = Mono("0\u2009st");
- _gainText = Mono("0.0\u2009dB"); _gainText.Foreground = TextSecondary;
- _fileText = new TextBlock { Text = "—", FontSize = 9, Foreground = TextTertiary, TextWrapping = TextWrapping.Wrap };
- _gain = new MiniFader(1.0, 2.0) { VerticalAlignment = VerticalAlignment.Center };
- _gain.ValueChanged += v => { _engine.SetClipGain(TrackId, ClipIndex, (float)v); ShowGain(v); _wave.SetGain(v); _onChanged(); };
- _reverseToggleText = new TextBlock { Text = "Reverse: Off", FontSize = 10, Foreground = TextSecondary, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
- _snapToggleText = new TextBlock { Text = "Grid snap: On", FontSize = 10, Foreground = AccentBright, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
- _warpToggleText = new TextBlock { Text = "Warp: Off", FontSize = 10, Foreground = TextSecondary, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
- _warpModeText = new TextBlock { Text = "Complex", FontSize = 10, Foreground = TextSecondary, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
- _autoText = new TextBlock { Text = "Auto-warp to tempo", FontSize = 10, Foreground = AccentBright, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
- _transientText = new TextBlock { Text = "Warp to transients", FontSize = 10, Foreground = AccentBright, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
- _detectedText = new TextBlock { Text = "Detected: —", FontSize = 9, Foreground = TextTertiary };
-
- var body = new StackPanel { Spacing = 10, Margin = new Thickness(10) };
- body.Children.Add(Section("CLIP", ReadoutBox($"Audio {trackId}", TextPrimary, 24, 11, false)));
-
- var startLen = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 6 };
- startLen.Children.Add(Labeled("START", ReadoutBox(Position(0), TextPrimary, 22, 10, true, out var startBox)));
- _startBox = startBox;
- var lenBox = FieldBox(22); lenBox.Child = _lengthText;
- var lenWrap = Labeled("LENGTH", lenBox);
- Grid.SetColumn(lenWrap, 1); startLen.Children.Add(lenWrap);
- body.Children.Add(startLen);
-
- // Length steppers (trim the clip end, ± one beat).
- var lenMinus = StepBtn("−", () => Resize(-1));
- var lenPlus = StepBtn("+", () => Resize(1));
- var lenStep = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto"), ColumnSpacing = 6 };
- lenStep.Children.Add(lenMinus);
- var lenHint = new TextBlock { Text = "length ± 1 beat", FontSize = 9, Foreground = TextTertiary, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
- Grid.SetColumn(lenHint, 1); lenStep.Children.Add(lenHint);
- Grid.SetColumn(lenPlus, 2); lenStep.Children.Add(lenPlus);
- body.Children.Add(Section("DURATION", lenStep));
-
- // Gain fader + dB readout.
- var gainRow = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto") };
- gainRow.Children.Add(_gain);
- Grid.SetColumn(_gainText, 1); _gainText.VerticalAlignment = VerticalAlignment.Center; _gainText.Margin = new Thickness(6, 0, 0, 0);
- gainRow.Children.Add(_gainText);
- body.Children.Add(Section("GAIN", gainRow));
-
- // Pitch (varispeed transpose) stepper.
- var pMinus = StepBtn("−", () => Pitch(-1));
- var pPlus = StepBtn("+", () => Pitch(1));
- var pStep = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto"), ColumnSpacing = 6 };
- pStep.Children.Add(pMinus);
- var pBox = FieldBox(22); pBox.Child = _pitchText;
- Grid.SetColumn(pBox, 1); pStep.Children.Add(pBox);
- Grid.SetColumn(pPlus, 2); pStep.Children.Add(pPlus);
- body.Children.Add(Section("PITCH (semitones)", pStep));
-
- // Reverse: play the clip's region back-to-front. Non-destructive (the file is
- // untouched) and free to toggle, so it doubles as an audition switch.
- var revChip = Chip(_reverseToggleText);
- revChip.PointerPressed += (_, e) => { e.Handled = true; ToggleReverse(); };
- var revHint = new TextBlock
- {
- Text = "Plays the clip backwards · the waveform below mirrors with it, so it always reads left to right in playing order",
- FontSize = 9, Foreground = TextTertiary, TextWrapping = TextWrapping.Wrap,
- };
- body.Children.Add(Section("DIRECTION", new StackPanel { Spacing = 4, Children = { revChip, revHint } }));
-
- // Warp: on/off + mode (time-stretch to project tempo, Signalsmith Stretch).
- var warpToggle = Chip(_warpToggleText);
- warpToggle.PointerPressed += (_, e) => { e.Handled = true; ToggleWarp(); };
- var warpModeChip = Chip(Glyph.WithChevron(_warpModeText));
- warpModeChip.PointerPressed += (_, e) => { e.Handled = true; CycleWarpMode(); };
- var warpRow = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*"), ColumnSpacing = 6 };
- warpToggle.MinWidth = 74;
- warpRow.Children.Add(warpToggle);
- Grid.SetColumn(warpModeChip, 1); warpRow.Children.Add(warpModeChip);
- var autoChip = Chip(_autoText);
- autoChip.PointerPressed += (_, e) => { e.Handled = true; AutoWarp(); };
- var transientChip = Chip(_transientText);
- transientChip.PointerPressed += (_, e) => { e.Handled = true; TransientWarp(); };
- var warpHint = new TextBlock { Text = "Auto detects tempo · Transients locks drum hits to the grid (Beats) · double-click waveform to add markers · drag to align", FontSize = 9, Foreground = TextTertiary, TextWrapping = TextWrapping.Wrap };
- body.Children.Add(Section("WARP", new StackPanel { Spacing = 4, Children = { warpRow, autoChip, transientChip, _detectedText, warpHint } }));
-
- // Clip envelopes: toggle edit mode on the waveform + pick Volume / Pan target.
- var envToggle = Chip(_envToggleText);
- envToggle.PointerPressed += (_, e) => { e.Handled = true; ToggleEnvMode(); };
- var envTargetChip = Chip(Glyph.WithChevron(_envTargetText));
- envTargetChip.PointerPressed += (_, e) => { e.Handled = true; CycleEnvTarget(); };
- var envRow = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*"), ColumnSpacing = 6 };
- envToggle.MinWidth = 96;
- envRow.Children.Add(envToggle);
- Grid.SetColumn(envTargetChip, 1); envRow.Children.Add(envTargetChip);
- var envHint = new TextBlock { Text = "Draw a curve over the clip · click to add · drag to move · right-click to delete", FontSize = 9, Foreground = TextTertiary, TextWrapping = TextWrapping.Wrap };
- body.Children.Add(Section("CLIP ENVELOPES", new StackPanel { Spacing = 4, Children = { envRow, envHint } }));
-
- body.Children.Add(Section("FILE", _fileText));
-
- var props = new Border
- {
- Width = 200, Background = Panel, BorderBrush = BorderDef, BorderThickness = new Thickness(0, 0, 1, 0),
- Child = new ScrollViewer
- {
- Content = body,
- HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
- VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
- },
- };
- var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*") };
- grid.Children.Add(props);
+ // CLIP — where it sits, and its length (± one beat).
+ var clip = Section("CLIP",
+ Pair(Labeled("Start", Field(_startText)), Labeled("Length", Stepper(_lengthText, () => Resize(-1), () => Resize(1)))));
+
+ // PLAYBACK — gain, varispeed pitch, direction.
+ var gain = SliderRow("GAIN", 44, () => _gain / 2.0, v => SetGain(v * 2.0), GainText, out _syncGain,
+ reset: () => SetGain(1.0), valueW: 44);
+ var pitchRow = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*"), ColumnSpacing = 10 };
+ pitchRow.Children.Add(new TextBlock
+ {
+ Text = "PITCH", Width = 44, FontSize = 9, FontWeight = FontWeight.Bold, LetterSpacing = 0.72,
+ Foreground = NotaPalette.TextTertiary, VerticalAlignment = VerticalAlignment.Center,
+ });
+ var pitch = Stepper(_pitchText, () => Pitch(-1), () => Pitch(1), zone: 24);
+ Grid.SetColumn(pitch, 1); pitchRow.Children.Add(pitch);
+ // Reverse is non-destructive (the file is untouched) and free to toggle, so it
+ // doubles as an audition switch; the wave mirrors so it always reads in playing order.
+ var reverse = SwitchRow("Reverse", () => _reversed, ToggleReverse, out _syncReverse, height: 22);
+ var playback = Section(SectionTitle("PLAYBACK"), 10, gain, pitchRow, reverse);
+
+ // WARP — on/off and the stretch mode, the two detectors, what they found.
+ var warpSwitch = SwitchRow("Warp", () => _warpEnabled, ToggleWarp, out _syncWarp);
+ var mode = Dropdown(_warpModeText, a => ShowMenu(a, WarpModes, _warpMode, SetWarpMode));
+ mode.Width = 104;
+ var warpRow = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 8 };
+ warpRow.Children.Add(warpSwitch);
+ Grid.SetColumn(mode, 1); warpRow.Children.Add(mode);
+ var detect = ClipEditorKit.Button("Detect tempo", AutoWarp);
+ ToolTip.SetTip(detect, "Detect the file's tempo and conform it to the project");
+ var transients = ClipEditorKit.Button("To transients", TransientWarp);
+ ToolTip.SetTip(transients, "Pin a marker on every hit so drums lock to the grid");
+ var warp = Section(SectionTitle("WARP", _markerCount), 8,
+ warpRow, Pair(detect, transients), Card(KeyValue("Detected", _detectedText)));
+
+ var inspector = Inspector(Sections(clip, playback, warp), _hint);
// Column 1: the waveform (row 0), a horizontal zoom scrollbar (row 1), and a
// floating overlay (Canvas with null background → clicks pass through except the
// inline BPM editor).
_bpmBox = new TextBox
{
- IsVisible = false, Width = 56, Height = 20, FontSize = 10, Padding = new Thickness(4, 0),
- Background = Sunken, Foreground = TextPrimary, BorderBrush = Brass, BorderThickness = new Thickness(1),
+ Classes = { "field" }, IsVisible = false, Width = 56, Height = 20, FontSize = 10, Padding = new Thickness(4, 0),
VerticalContentAlignment = VerticalAlignment.Center,
};
_bpmBox.KeyDown += OnBpmKey;
@@ -231,45 +146,38 @@ public sealed class AudioClipEditorView : UserControl
var waveHost = new Grid();
waveHost.Children.Add(_wave);
waveHost.Children.Add(_overlay);
-
- // Toolbar above the waveform: a grid-snap toggle for the trim brackets (on by
- // default). When on, dragging a blue bracket snaps its edge to the beat grid so
- // the clip trims exactly on the bar/beat.
- var snapChip = Chip(_snapToggleText); snapChip.MinWidth = 96;
- snapChip.PointerPressed += (_, e) => { e.Handled = true; ToggleSnap(); };
- var toolbar = new Border
- {
- Height = 26, Background = Panel, BorderBrush = BorderDef, BorderThickness = new Thickness(0, 0, 0, 1),
- Padding = new Thickness(6, 0),
- Child = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center, Children = { snapChip } },
- };
-
- var col1 = new Grid { RowDefinitions = new RowDefinitions("Auto,*,Auto") };
- Grid.SetRow(toolbar, 0); col1.Children.Add(toolbar);
- Grid.SetRow(waveHost, 1); col1.Children.Add(waveHost);
- Grid.SetRow(_hScroll, 2); col1.Children.Add(_hScroll);
+ var 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 waveWrap = new Border { Background = Sunken, Margin = new Thickness(0), Child = col1 };
- Grid.SetColumn(waveWrap, 1);
- grid.Children.Add(waveWrap);
- var header = Header();
+ var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*") };
+ grid.Children.Add(inspector);
+ Grid.SetColumn(col1, 1);
+ grid.Children.Add(col1);
+
+ // Header: Sample | Envelope, the target while editing an envelope, Snap, the format.
+ var tabs = Segments(new[] { "Sample", "Envelope" }, 0, i => SetEnvMode(i == 1), 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");
+ 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);
DockPanel.SetDock(header, Dock.Top);
- var dock = new DockPanel();
- dock.Children.Add(header);
- dock.Children.Add(grid);
- Content = dock;
+ Content = new DockPanel { Background = NotaPalette.Gutter, Children = { header, grid } };
+ PaintHint();
Reload();
}
- private Border _startBox = null!;
private readonly TextBox _bpmBox;
private readonly Canvas _overlay;
private readonly ScrollBar _hScroll;
private int _bpmSeg = -1;
- // Inline BPM editor over the warp bar: position + focus a small field.
+ // Inline BPM editor over the warp strip: position + focus a small field.
private void ShowBpmEditor(int seg, double bpm, double xCenter, double yTop)
{
_bpmSeg = seg;
@@ -308,36 +216,36 @@ public sealed class AudioClipEditorView : UserControl
_hScroll.Value = Math.Clamp(_wave.ScrollFrac, 0, _wave.MaxScrollFrac);
}
- // Re-reads clip geometry + peaks + sample metadata and refreshes the rail.
+ // Re-reads clip geometry + peaks + sample metadata and refreshes the inspector.
public void Reload()
{
if (_engine.TryGetClipInfo(TrackId, ClipIndex, out var ci))
{
_startBeat = ci.StartBeat;
_lengthBeats = ci.LengthBeats > 0 ? ci.LengthBeats : _lengthBeats;
- if (_startBox.Child is TextBlock sb) sb.Text = Position(_startBeat);
+ _startText.Text = Position(_startBeat);
_lengthText.Text = Duration(_lengthBeats);
}
if (_engine.TryGetAudioClipInfo(TrackId, ClipIndex, out var ai))
{
_pitch = (int)Math.Round(ai.PitchSemitones);
- _pitchText.Text = $"{_pitch}\u2009st";
- _gain.Value = ai.Gain;
- ShowGain(ai.Gain);
+ _pitchText.Text = Semis(_pitch);
+ _pitchText.Foreground = _pitch != 0 ? NotaPalette.AccentBright : NotaPalette.TextPrimary;
+ _gain = ai.Gain;
+ _syncGain();
_wave.SetGain(ai.Gain);
_reversed = ai.Reversed != 0;
_wave.SetReversed(_reversed); // draw the waveform the way the clip now plays
- _reverseToggleText.Text = _reversed ? "Reverse: On" : "Reverse: Off";
- _reverseToggleText.Foreground = _reversed ? AccentBright : TextSecondary;
+ _syncReverse();
_warpEnabled = ai.WarpEnabled != 0;
_warpMode = Math.Clamp(ai.WarpMode, 0, WarpModes.Length - 1);
- _warpToggleText.Text = _warpEnabled ? "Warp: On" : "Warp: Off";
- _warpToggleText.Foreground = _warpEnabled ? AccentBright : TextSecondary;
+ _syncWarp();
_warpModeText.Text = WarpModes[_warpMode];
+ _warpModeText.Foreground = _warpEnabled ? NotaPalette.TextPrimary : NotaPalette.TextDisabled;
if (ai.SampleId != 0 && _engine.TryGetSampleInfo(ai.SampleId, out var si) && si.SampleRate > 0)
{
double secs = si.Frames / si.SampleRate;
- string ch = si.Channels == 1 ? "Mono" : si.Channels == 2 ? "Stereo" : $"{si.Channels}ch";
+ string ch = si.Channels == 1 ? "Mono" : si.Channels == 2 ? "Stereo" : $"{si.Channels} ch";
_fileText.Text = string.Format(NotaNum.Culture,
"{0} · {1:0.0}\u2009kHz · {2:0.00}\u2009s", ch, si.SampleRate / 1000.0, secs);
}
@@ -354,6 +262,7 @@ public sealed class AudioClipEditorView : UserControl
// Warp markers (only meaningful while warping). Unwarped clips instead show the
// whole sample with draggable Start/End brackets (source-region editing).
var peaks = new float[1024 * 2];
+ int markers = 0;
if (_warpEnabled)
{
// Show the FULL warp with markers + Start/End trim brackets (trim the played
@@ -361,8 +270,8 @@ public sealed class AudioClipEditorView : UserControl
int n = _engine.GetClipWarpFullPeaks(TrackId, ClipIndex, peaks, 1024);
_wave.SetPeaks(peaks, n);
var ms = new double[128]; var mb = new double[128];
- int mn = Math.Min(_engine.GetClipWarpMarkers(TrackId, ClipIndex, ms, mb), 128);
- _wave.SetMarkers(ms, mb, mn);
+ markers = Math.Min(_engine.GetClipWarpMarkers(TrackId, ClipIndex, ms, mb), 128);
+ _wave.SetMarkers(ms, mb, markers);
_wave.SetSourceRegion(0, 0, 0); // source-frame brackets off (warped)
_wave.SetWarpTrim(gi.WarpPlayStart, gi.WarpPlayEnd, gi.WarpBeats);
}
@@ -379,6 +288,7 @@ public sealed class AudioClipEditorView : UserControl
}
else _wave.SetSourceRegion(0, 0, 0);
}
+ _markerCount.Text = _warpEnabled ? $"{markers} {(markers == 1 ? "marker" : "markers")}" : "off";
// Clip envelope: clip-local domain = warpBeats when warped, else clip length.
LoadEnvelope();
@@ -404,11 +314,19 @@ public sealed class AudioClipEditorView : UserControl
_onChanged();
}
+ private void SetGain(double g)
+ {
+ _gain = Math.Clamp(g, 0, 2);
+ _engine.SetClipGain(TrackId, ClipIndex, (float)_gain);
+ _wave.SetGain(_gain);
+ _onChanged();
+ }
+
+ private 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;
- _snapToggleText.Text = _snapToGrid ? "Grid snap: On" : "Grid snap: Off";
- _snapToggleText.Foreground = _snapToGrid ? AccentBright : TextSecondary;
_wave.SetSnapToGrid(_snapToGrid);
}
@@ -427,9 +345,9 @@ public sealed class AudioClipEditorView : UserControl
_onChanged();
}
- private void CycleWarpMode()
+ private void SetWarpMode(int mode)
{
- _warpMode = (_warpMode + 1) % WarpModes.Length;
+ _warpMode = Math.Clamp(mode, 0, WarpModes.Length - 1);
_engine.SetClipWarp(TrackId, ClipIndex, _warpEnabled, _warpMode);
Reload();
_onChanged();
@@ -440,8 +358,7 @@ public sealed class AudioClipEditorView : UserControl
// material, in which case the clip is left as-is.
private void AutoWarp()
{
- double bpm = _engine.AutoWarpClip(TrackId, ClipIndex);
- _detectedBpm = bpm;
+ _detectedBpm = _engine.AutoWarpClip(TrackId, ClipIndex);
ShowDetected();
Reload();
_onChanged();
@@ -451,33 +368,38 @@ public sealed class AudioClipEditorView : UserControl
// percussion locks tightly to the grid ("Beats"). Fails on flat material.
private void TransientWarp()
{
- double bpm = _engine.BeatWarpClip(TrackId, ClipIndex);
- _detectedBpm = bpm;
+ _detectedBpm = _engine.BeatWarpClip(TrackId, ClipIndex);
ShowDetected();
Reload();
_onChanged();
}
private void ShowDetected()
- => _detectedText.Text = _detectedBpm > 0
- ? string.Format(NotaNum.Culture, "Detected: {0:0.0}\u2009BPM", _detectedBpm)
- : "Detected: —";
+ {
+ bool found = _detectedBpm > 0;
+ _detectedText.Text = found ? string.Format(NotaNum.Culture, "{0:0.00}\u2009BPM", _detectedBpm) : "—";
+ _detectedText.Foreground = found ? NotaPalette.TextPrimary : NotaPalette.TextDisabled;
+ }
- private void ToggleEnvMode()
+ private void SetEnvMode(bool on)
{
- _envMode = !_envMode;
- _envToggleText.Text = _envMode ? "Edit envelope: On" : "Edit envelope: Off";
- _envToggleText.Foreground = _envMode ? AccentBright : TextSecondary;
- _wave.SetEnvMode(_envMode);
+ _envMode = on;
+ _envTargetDrop.IsVisible = on;
+ _wave.SetEnvMode(on);
+ PaintHint();
}
- private void CycleEnvTarget()
+ private void SetEnvTarget(int target)
{
- _envTarget = _envTarget == 0 ? 1 : 0;
- _envTargetText.Text = _envTarget == 1 ? "Pan" : "Volume";
+ _envTarget = target;
+ _envTargetText.Text = EnvTargets[target];
LoadEnvelope();
}
+ private void PaintHint() => _hint.Text = _envMode
+ ? "Click — point · drag — move · right-click — delete"
+ : "Double-click the wave — marker · drag — align";
+
// Loads the active target's envelope into the waveform with its value axis.
private void LoadEnvelope()
{
@@ -498,91 +420,6 @@ public sealed class AudioClipEditorView : UserControl
_onChanged();
}
- private void ShowGain(double v) => _gainText.Text = v <= 0.0011 ? "−∞" : $"{AudioMath.LinToDb(v):+0.0;−0.0}\u2009dB";
-
- // --- helpers (mirror ClipPropsView) -----------------------------------
-
- private Control Header()
- {
- var tab = new Border
- {
- Height = 22, Background = AccentSubtle, BorderBrush = Brass, BorderThickness = new Thickness(1),
- CornerRadius = NotaRadius.Tile, Padding = new Thickness(10, 0), VerticalAlignment = VerticalAlignment.Center,
- Child = new TextBlock { Text = "Audio", FontSize = 11, Foreground = AccentBright, VerticalAlignment = VerticalAlignment.Center },
- };
- return new Border
- {
- Height = 30, Background = Panel, BorderBrush = BorderDef, BorderThickness = new Thickness(0, 0, 0, 1),
- Padding = new Thickness(10, 0),
- Child = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center, Children = { tab } },
- };
- }
-
- private static TextBlock Mono(string text)
- {
- var t = new TextBlock { Text = text, FontSize = 10, Foreground = NotaPalette.TextPrimary, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(7, 0, 0, 0) };
- t.BindResource(FontFamilyProperty, "Font.Mono");
- return t;
- }
-
- private static Control Section(string title, Control content) => new StackPanel
- {
- Spacing = 4,
- Children = { new TextBlock { Text = title, FontSize = 9, FontWeight = FontWeight.Bold, Foreground = TextTertiary }, content },
- };
-
- private static Control Labeled(string title, Control content) => new StackPanel
- {
- Spacing = 2, Children = { new TextBlock { Text = title, FontSize = 9, Foreground = TextTertiary }, content },
- };
-
- private static Border FieldBox(double h) => new()
- {
- Height = h, Background = Sunken, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
- };
-
- private static Border ReadoutBox(string text, IBrush fg, double h, double fs, bool mono)
- => ReadoutBox(text, fg, h, fs, mono, out _);
-
- private static Border ReadoutBox(string text, IBrush fg, double h, double fs, bool mono, out Border box)
- {
- var t = new TextBlock { Text = text, FontSize = fs, Foreground = fg, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(mono ? 7 : 8, 0, 0, 0) };
- if (mono) t.BindResource(FontFamilyProperty, "Font.Mono");
- box = FieldBox(h);
- box.Child = t;
- return box;
- }
-
- private static Border Chip(Control child) => new()
- {
- Height = 22, Background = Raised, BorderBrush = BorderStrong, BorderThickness = new Thickness(1),
- CornerRadius = NotaRadius.Tile, Cursor = new Cursor(StandardCursorType.Hand), Child = child,
- };
-
- private static Border StepBtn(string glyph, Action onClick)
- {
- var b = new Border
- {
- Width = 22, Height = 22, Background = Raised, BorderBrush = BorderStrong, BorderThickness = new Thickness(1),
- CornerRadius = NotaRadius.Tile, Cursor = new Cursor(StandardCursorType.Hand),
- Child = new TextBlock { Text = glyph, FontSize = 11, Foreground = TextSecondary, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center },
- };
- b.PointerPressed += (_, e) => { e.Handled = true; onClick(); };
- return b;
- }
-
- private static string Position(double beat)
- {
- int bar = (int)(beat / 4) + 1, be = (int)(beat % 4) + 1, six = (int)Math.Round(beat % 1 * 4) + 1;
- return string.Format(NotaNum.Culture, "{0}. {1}. {2}", bar, be, six);
- }
-
- private static string Duration(double beats)
- {
- int bars = (int)(beats / 4), be = (int)(beats % 4), six = (int)Math.Round(beats % 1 * 4);
- return string.Format(NotaNum.Culture, "{0}. {1}. {2}", bars, be, six);
- }
-
// ---- waveform + playback cursor + warp markers -----------------------
// The waveform is drawn in SOURCE time; markers tie a source point to a beat.
// Interior markers drag along source (aligning audio to their fixed beat);
@@ -590,17 +427,29 @@ public sealed class AudioClipEditorView : UserControl
private sealed class WaveformView : Control
{
private static readonly IBrush Bg = NotaPalette.BgSunken;
- private static readonly IBrush Mid = NotaPalette.Wash(NotaPalette.TextSecondary, 0x40);
- private static readonly IBrush PlayheadCursor = NotaPalette.Accent;
- private static readonly IBrush Marker = NotaPalette.Marker;
- private static readonly IBrush GridBeat = NotaPalette.Wash(NotaPalette.BorderStrong, 0x50);
- private static readonly IBrush GridBar = NotaPalette.Wash(NotaPalette.BorderStrong, 0xC0);
- private static readonly IBrush GridLabel = NotaPalette.TextTertiary;
- private static readonly Typeface GridFace = NotaFonts.Sans;
- // BPM chip on the warp bar (drag to scrub the segment tempo).
- private static readonly IBrush BpmChipBg = NotaPalette.Wash(NotaPalette.Ink("#12181B"), 0xDE);
- private static readonly IBrush BpmChipBgHot = NotaPalette.Wash(NotaPalette.Ink("#1A2B31"), 0xF2);
- private static readonly IBrush BpmSuffix = NotaPalette.Wash(NotaPalette.Marker, 0x99);
+ private static readonly IBrush RulerBg = NotaPalette.Panel;
+ private static readonly IPen RulerEdge = new Pen(NotaPalette.BorderDefault, 1);
+ private static readonly IPen StripEdge = new Pen(NotaPalette.GraphBorder, 1);
+ private static readonly IBrush RulerBar = NotaPalette.TextStrong;
+ private static readonly IBrush RulerBeat = NotaPalette.TextDisabled;
+ private static readonly IPen MidPen = new Pen(NotaPalette.GridBeat, 1);
+ private static readonly IPen PlayheadPen = new Pen(NotaPalette.Accent, 1);
+ private static readonly IBrush MarkerInk = NotaPalette.TextMuted;
+ private static readonly IBrush MarkerHot = NotaPalette.Accent;
+ private static readonly IPen SelLine = new Pen(NotaPalette.AccentDim, 1);
+ private static readonly IPen GridBeatPen = new Pen(NotaPalette.GridSubBeat, 1);
+ private static readonly IPen GridBarPen = new Pen(NotaPalette.BorderDefault, 1);
+ private static readonly Typeface GridFace = NotaFonts.Mono;
+ // BPM chip in the marker strip (drag to scrub the segment tempo); the hot one and the
+ // selected marker's position chip take Brass Wash with a brass edge.
+ private static readonly IBrush ChipBg = NotaPalette.Panel;
+ private static readonly IPen ChipEdge = new Pen(NotaPalette.BorderDefault, 1);
+ private static readonly IBrush ChipInk = NotaPalette.TextSecondary;
+ private static readonly IBrush ChipBgHot = NotaPalette.AccentSubtle;
+ private static readonly IPen ChipEdgeHot = new Pen(NotaPalette.BorderBrass, 1);
+ private static readonly IBrush ChipInkHot = NotaPalette.AccentBright;
+ // Ruler 24, marker strip 22, then the wave.
+ private const double RulerH = 24, StripH = 22, WaveTop = RulerH + StripH;
private const int BeatsPerBar = 4; // matches the props-rail bar.beat readouts
private IBrush _wave = NotaPalette.TrackBrushes[1];
private float[]? _peaks;
@@ -615,9 +464,9 @@ public sealed class AudioClipEditorView : UserControl
// Source-region brackets (unwarped clips): whole sample drawn, Start/End handles
// pick the playable region [_srcOff, _srcOff+_srcLen] within _srcTotal frames.
- private static readonly IBrush Bracket = NotaPalette.Marker;
- private static readonly IBrush BracketHot = NotaPalette.MarkerHot;
- private static readonly IBrush OutsideDim = NotaPalette.Wash(NotaPalette.BgSunken, 0xAA);
+ private static readonly IBrush Bracket = NotaPalette.TextStrong;
+ private static readonly IBrush BracketHot = NotaPalette.TextPrimary;
+ private static readonly IBrush OutsideDim = NotaPalette.Wash(NotaPalette.SurfaceAbyss, 0xD9);
private double _srcOff, _srcLen, _srcTotal;
private bool _srcMode;
private int _srcDrag = -1; // 0 = start bracket, 1 = end bracket, -1 = none
@@ -640,14 +489,19 @@ public sealed class AudioClipEditorView : UserControl
private double _bpmScrubStartY, _bpmScrubStartBpm;
// Volume envelope (M9 follow-up): points (beat, value 0..1) in clip-local beats.
- private static readonly IBrush EnvLine = NotaPalette.AccentBright;
- private static readonly IBrush EnvLineDim = NotaPalette.Wash(NotaPalette.AccentBright, 0x60);
+ private static readonly IPen EnvPen = new Pen(NotaPalette.Accent, 1.8);
+ private static readonly IPen EnvPenDim = new Pen(NotaPalette.Wash(NotaPalette.Accent, 0x60), 1);
+ private static readonly IBrush EnvWash = NotaPalette.Wash(NotaPalette.BgSunken, 0x99);
+ private static readonly IBrush NodeFill = NotaPalette.TextSecondary;
+ private static readonly IBrush NodeHot = NotaPalette.Accent;
+ private static readonly IPen NodeRing = new Pen(NotaPalette.BgSunken, 2);
private sealed class EnvPt { public double beat; public double val; public float curve; }
private readonly System.Collections.Generic.List<EnvPt> _env = new();
private double _clipBeats = 1;
private double _envMin, _envMax = 1; // value axis (Volume 0..1, Pan -1..1)
private bool _envMode;
- private int _envDrag = -1;
+ private int _envDrag = -1, _envHover = -1;
+ private int _selMk = -1; // marker picked by a click (its position shows in the strip)
private EnvPt? _envBend; // segment being bent (M9-D)
/// <summary>Raised when markers change (drag/add/delete) with the full sorted list.</summary>
@@ -744,8 +598,9 @@ public sealed class AudioClipEditorView : UserControl
// waveform. It stays on the view axis directly.
private double EnvBeatToX(double beat, double w) => FracToXView(beat / _clipBeats, w);
private double EnvXToBeat(double x, double w) => Math.Clamp(XToFracView(x, w), 0, 1) * _clipBeats;
- private double EnvValToY(double v, double h) { double pad = 4; double t = (Math.Clamp(v, _envMin, _envMax) - _envMin) / (_envMax - _envMin); return pad + (1 - t) * (h - 2 * pad); }
- private double EnvYToVal(double y, double h) { double pad = 4; double t = (h - pad - y) / Math.Max(1, h - 2 * pad); return _envMin + Math.Clamp(t, 0, 1) * (_envMax - _envMin); }
+ // The value axis spans the wave area below the ruler and the marker strip.
+ private double EnvValToY(double v, double h) { double pad = 6, top = WaveTop + pad; double t = (Math.Clamp(v, _envMin, _envMax) - _envMin) / (_envMax - _envMin); return top + (1 - t) * Math.Max(1, h - pad - top); }
+ private double EnvYToVal(double y, double h) { double pad = 6, top = WaveTop + pad; double t = (h - pad - y) / Math.Max(1, h - pad - top); return _envMin + Math.Clamp(t, 0, 1) * (_envMax - _envMin); }
private static double EnvShape(double t, float curve) => curve == 0f ? t : Math.Pow(t, Math.Pow(2.0, -curve * 4.0));
private int HitEnv(double x, double y, double w, double h)
{
@@ -795,6 +650,7 @@ public sealed class AudioClipEditorView : UserControl
{
_mk.Clear();
for (int i = 0; i < count; i++) _mk.Add((src[i], beat[i]));
+ if (_selMk >= _mk.Count) _selMk = -1;
InvalidateVisual();
}
public void SetGain(double g) { if (Math.Abs(g - _gain) < 1e-4) return; _gain = g; InvalidateVisual(); }
@@ -903,6 +759,7 @@ public sealed class AudioClipEditorView : UserControl
return;
}
int h = HitMarker(x, w);
+ if (h != _selMk) { _selMk = h; InvalidateVisual(); } // a click picks a marker (or clears the pick)
if (h > 0 && h < _mk.Count - 1) { _drag = h; e.Pointer.Capture(this); e.Handled = true; }
}
@@ -986,6 +843,13 @@ public sealed class AudioClipEditorView : UserControl
InvalidateVisual();
return;
}
+ if (_envMode && _drag < 0) // envelope mode: light the node under the pointer
+ {
+ var ep = e.GetPosition(this);
+ int hv = HitEnv(ep.X, ep.Y, Bounds.Width, Bounds.Height);
+ if (hv != _envHover) { _envHover = hv; InvalidateVisual(); }
+ return;
+ }
if (_drag < 0) // no active drag: track hover for marker/bracket highlight + cursor
{
UpdateHover(e.GetPosition(this), Bounds.Width);
@@ -1020,7 +884,7 @@ public sealed class AudioClipEditorView : UserControl
protected override void OnPointerExited(PointerEventArgs e)
{
- if (_hoverMk != -1 || _bpmHoverSeg != -1) { _hoverMk = -1; _bpmHoverSeg = -1; InvalidateVisual(); }
+ if (_hoverMk != -1 || _bpmHoverSeg != -1 || _envHover != -1) { _hoverMk = -1; _bpmHoverSeg = -1; _envHover = -1; InvalidateVisual(); }
SetCursorKind(StandardCursorType.Arrow);
base.OnPointerExited(e);
}
@@ -1093,16 +957,36 @@ public sealed class AudioClipEditorView : UserControl
public override void Render(DrawingContext ctx)
{
double w = Bounds.Width, h = Bounds.Height;
+ double top = WaveTop, wh = Math.Max(0, h - top);
ctx.FillRectangle(Bg, new Rect(0, 0, w, h));
- double mid = h / 2;
- ctx.DrawLine(new Pen(Mid, 1), new Point(0, mid), new Point(w, mid));
_bpmHot.Clear();
+ // Ruler (24) and the warp-marker strip (22) above the wave.
+ ctx.FillRectangle(RulerBg, new Rect(0, 0, w, RulerH));
+ ctx.DrawLine(RulerEdge, new Point(0, RulerH - 0.5), new Point(w, RulerH - 0.5));
+ ctx.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).
+ if (_mk.Count > 1)
+ {
+ double tb = TotalBeats;
+ int last = (int)Math.Floor(tb + 1e-6);
+ for (int b = 1; b <= last; b++)
+ {
+ double x = BeatToX(b, w);
+ if (x < -0.5 || x > w + 0.5) continue;
+ ctx.DrawLine(b % BeatsPerBar == 0 ? GridBarPen : GridBeatPen, new Point(x + 0.5, top), new Point(x + 0.5, h));
+ }
+ }
+
// 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.
- if (_peaks is not null && _count > 0 && h > 4)
+ double mid = top + wh / 2;
+ ctx.DrawLine(MidPen, new Point(0, mid), new Point(w, mid));
+ if (_peaks is not null && _count > 0 && wh > 4)
{
- double amp = h / 2 - 3;
+ double amp = wh / 2 - 6;
double bw = Math.Max(1, _zoom * w / _count);
for (int i = 0; i < _count; i++)
{
@@ -1117,54 +1001,28 @@ public sealed class AudioClipEditorView : UserControl
}
}
- // Beat grid (only meaningful while warping): bar lines are brighter/
- // thicker, interior beats faint. Labels read "bar.beat" (1.1, 1.2 …)
- // and are skipped when beats are too close to fit legibly.
- if (_mk.Count > 1)
- {
- double tb = TotalBeats;
- double beatW = _zoom * w / tb; // pixel width of one beat (zoom-aware)
- bool label = beatW >= 20;
- int last = (int)Math.Floor(tb + 1e-6);
- for (int b = 0; b <= last; b++)
- {
- double x = BeatToX(b, w);
- if (x < -0.5) continue;
- if (x > w + 0.5) break;
- bool bar = b % BeatsPerBar == 0;
- ctx.DrawLine(new Pen(bar ? GridBar : GridBeat, bar ? 1 : 0.6), new Point(x, 0), new Point(x, h));
- if (label && b < last)
- {
- int barNo = b / BeatsPerBar + 1, beatNo = b % BeatsPerBar + 1;
- var ft = new FormattedText($"{barNo}.{beatNo}", CultureInfo.InvariantCulture,
- FlowDirection.LeftToRight, GridFace, 8.5, GridLabel);
- // Keep the label inside its own beat: that's the other side when mirrored.
- ctx.DrawText(ft, new Point(_reversed ? x - 2 - ft.Width : x + 2, h - ft.Height - 2));
- }
- }
- }
-
- // Warp markers: accent line + triangle handle for all. End markers are
- // clamped just inside the edges (so they're visible) and aren't draggable.
- // The hovered / dragged marker lights up (brighter + thicker + larger grip).
+ // Warp markers: a triangle in the strip (Ink 4; brass under the hand or selected).
+ // The selected one carries its position and a dim brass line through the wave.
for (int i = 0; i < _mk.Count; i++)
{
- bool end = i == 0 || i == _mk.Count - 1;
- bool hot = i == _hoverMk || i == _drag;
- var brush = hot ? BracketHot : Marker;
double xr = BeatToX(_mk[i].beat, w);
if (xr < -6 || xr > w + 6) continue; // scrolled off-screen
- double x = Math.Clamp(xr, 2, Math.Max(2, w - 2));
- ctx.DrawLine(new Pen(brush, hot ? 2.4 : (end ? 1 : 1.6)), new Point(x, 0), new Point(x, h));
- double hw = hot ? 5.5 : 4;
+ double x = Math.Clamp(xr, 5, Math.Max(5, w - 5));
+ bool hot = i == _hoverMk || i == _drag || i == _selMk;
+ if (i == _selMk || i == _drag) ctx.DrawLine(SelLine, new Point(x + 0.5, top), new Point(x + 0.5, h));
var g = new StreamGeometry();
- using (var gc = g.Open()) { gc.BeginFigure(new Point(x - hw, 0), true); gc.LineTo(new Point(x + hw, 0)); gc.LineTo(new Point(x, hot ? 11 : 8)); gc.EndFigure(true); }
- ctx.DrawGeometry(brush, null, g);
+ using (var gc = g.Open())
+ {
+ gc.BeginFigure(new Point(x - 5, RulerH + 6), true);
+ gc.LineTo(new Point(x + 5, RulerH + 6));
+ gc.LineTo(new Point(x, RulerH + 14));
+ gc.EndFigure(true);
+ }
+ ctx.DrawGeometry(hot ? MarkerHot : MarkerInk, null, g);
}
- // Per-segment local BPM (the warp bar): a rounded chip showing the tempo
- // the audio plays at between consecutive markers. Drag it up/down to scrub.
- // Centred over each segment, hidden when the segment is too narrow.
+ // Per-segment local BPM, centred in the strip between two markers: drag it
+ // up/down to scrub, double-click to type. Hidden when the segment is too narrow.
if (_srcSR > 0)
for (int i = 0; i + 1 < _mk.Count; i++)
{
@@ -1172,33 +1030,66 @@ public sealed class AudioClipEditorView : UserControl
double srcSpan = _mk[i + 1].src - _mk[i].src;
if (beatSpan <= 0 || srcSpan <= 0) continue;
double x0 = BeatToX(_mk[i].beat, w), x1 = BeatToX(_mk[i + 1].beat, w);
- if (Math.Abs(x1 - x0) < 46) continue; // mirrored: x1 sits left of x0
+ if (Math.Abs(x1 - x0) < 72) continue; // mirrored: x1 sits left of x0
double bpm = beatSpan * _srcSR * 60.0 / srcSpan;
bool hotChip = i == _bpmHoverSeg || i == _bpmScrubSeg;
- var txtBrush = hotChip ? BracketHot : Marker;
- var num = new FormattedText($"{bpm:0.0}", CultureInfo.InvariantCulture, FlowDirection.LeftToRight, GridFace, 10, txtBrush);
- var suf = new FormattedText("BPM", CultureInfo.InvariantCulture, FlowDirection.LeftToRight, GridFace, NotaType.Floor, BpmSuffix);
- double padX = 6, padY = 2.5, gap = 3;
- double cw = num.Width + gap + suf.Width + 2 * padX, chH = num.Height + 2 * padY;
+ var num = new FormattedText(bpm.ToString("0.00", NotaNum.Culture), NotaNum.Culture, FlowDirection.LeftToRight, GridFace, 9, hotChip ? ChipInkHot : ChipInk);
+ double cw = num.Width + 12, chH = 16;
double cx = Math.Clamp((x0 + x1) / 2, cw / 2 + 2, w - cw / 2 - 2);
if (cx < 0 || cx > w) continue;
- var chip = new Rect(cx - cw / 2, 5, cw, chH);
- ctx.DrawRectangle(hotChip ? BpmChipBgHot : BpmChipBg, new Pen(txtBrush, 1), chip, 4, 4);
- ctx.DrawText(num, new Point(chip.X + padX, chip.Y + padY));
- ctx.DrawText(suf, new Point(chip.X + padX + num.Width + gap, chip.Y + chH - suf.Height - padY + 0.5));
+ var chip = new Rect(cx - cw / 2, RulerH + 3, cw, chH);
+ ctx.DrawRectangle(hotChip ? ChipBgHot : ChipBg, hotChip ? ChipEdgeHot : ChipEdge, chip.Deflate(0.5), 3, 3);
+ ctx.DrawText(num, new Point(chip.X + 6, chip.Y + (chH - num.Height) / 2));
_bpmHot.Add((chip, i, bpm));
}
- // Clip envelope: brass polyline + points, brighter in edit mode. A centre
- // reference line is drawn for a bipolar (pan) axis.
- if (_envMode && _envMin < 0)
+ // The selected marker's position, in a brass chip beside its triangle.
+ if (_selMk >= 0 && _selMk < _mk.Count)
+ {
+ double x = BeatToX(_mk[_selMk].beat, w);
+ if (x >= -6 && x <= w + 6)
+ {
+ var ft = new FormattedText(Position(_mk[_selMk].beat), NotaNum.Culture, FlowDirection.LeftToRight, GridFace, 9, ChipInkHot);
+ double cw = ft.Width + 12;
+ double lx = x + 9 + cw > w ? x - 9 - cw : x + 9;
+ var chip = new Rect(lx, RulerH + 3, cw, 16);
+ ctx.DrawRectangle(ChipBgHot, ChipEdgeHot, chip.Deflate(0.5), 3, 3);
+ ctx.DrawText(ft, new Point(chip.X + 6, chip.Y + (16 - ft.Height) / 2));
+ }
+ }
+
+ // Everything outside the played region is darkened, not hidden; its edges are Ink 2
+ // lines with grips pointing into the region.
+ if (_srcMode && _srcTotal > 0)
+ {
+ double xs = SrcToX(_srcOff, w), xe = SrcToX(_srcOff + _srcLen, w);
+ DimOutside(ctx, xs, xe, w, h);
+ // The grips point INTO the region, which is the other way round when mirrored.
+ if (xs >= -1 && xs <= w + 1) DrawBracket(ctx, xs, h, !_reversed, _srcDrag == 0);
+ if (xe >= -1 && xe <= w + 1) DrawBracket(ctx, xe, h, _reversed, _srcDrag == 1);
+ }
+ if (_trimMode && _trimTotal > 0)
+ {
+ double xs = BeatToX(_trimStart, w), xe = BeatToX(_trimEnd, w);
+ DimOutside(ctx, xs, xe, w, h);
+ if (xs >= -1 && xs <= w + 1) DrawBracket(ctx, xs, h, !_reversed, _trimDrag == 0);
+ if (xe >= -1 && xe <= w + 1) DrawBracket(ctx, xe, h, _reversed, _trimDrag == 1);
+ }
+
+ // Clip envelope: in Envelope mode the wave dims under a wash and the curve is drawn
+ // in brass with its nodes; otherwise a quiet line keeps it in view.
+ if (_envMode)
{
- double cy = EnvValToY(0, h);
- ctx.DrawLine(new Pen(GridBeat, 1), new Point(0, cy), new Point(w, cy));
+ ctx.FillRectangle(EnvWash, new Rect(0, top, w, wh));
+ if (_envMin < 0)
+ {
+ double cy = EnvValToY(0, h);
+ ctx.DrawLine(GridBeatPen, new Point(0, cy), new Point(w, cy));
+ }
}
if (_env.Count > 0)
{
- var pen = new Pen(_envMode ? EnvLine : EnvLineDim, _envMode ? 1.6 : 1);
+ var pen = _envMode ? EnvPen : EnvPenDim;
var ord = EnvSorted();
double fy = EnvValToY(ord[0].val, h);
ctx.DrawLine(pen, new Point(0, fy), new Point(EnvBeatToX(ord[0].beat, w), fy)); // hold before first
@@ -1219,66 +1110,102 @@ public sealed class AudioClipEditorView : UserControl
double ly = EnvValToY(ord[^1].val, h);
ctx.DrawLine(pen, new Point(EnvBeatToX(ord[^1].beat, w), ly), new Point(w, ly)); // hold after last
if (_envMode)
- foreach (var p in ord)
- ctx.DrawEllipse(EnvLine, null, new Point(EnvBeatToX(p.beat, w), EnvValToY(p.val, h)), 3, 3);
- }
-
- // Source-region Start/End brackets (unwarped whole-sample view): dim the
- // trimmed-off audio and draw a grabbable bracket at each edge of the region.
- if (_srcMode && _srcTotal > 0)
- {
- double xs = SrcToX(_srcOff, w), xe = SrcToX(_srcOff + _srcLen, w);
- DimOutside(ctx, xs, xe, w, h);
- // The grips point INTO the region, which is the other way round when mirrored.
- if (xs >= -1 && xs <= w + 1) DrawBracket(ctx, xs, h, !_reversed, _srcDrag == 0);
- if (xe >= -1 && xe <= w + 1) DrawBracket(ctx, xe, h, _reversed, _srcDrag == 1);
- }
-
- // Warped-clip trim brackets (beat domain over the full warp): dim the trimmed
- // beats and draw a grabbable bracket at each edge of the played window.
- if (_trimMode && _trimTotal > 0)
- {
- double xs = BeatToX(_trimStart, w), xe = BeatToX(_trimEnd, w);
- DimOutside(ctx, xs, xe, w, h);
- if (xs >= -1 && xs <= w + 1) DrawBracket(ctx, xs, h, !_reversed, _trimDrag == 0);
- if (xe >= -1 && xe <= w + 1) DrawBracket(ctx, xe, h, _reversed, _trimDrag == 1);
+ for (int i = 0; i < _env.Count; i++)
+ {
+ var p = _env[i];
+ bool hot = i == _envDrag || i == _envHover;
+ ctx.DrawEllipse(hot ? NodeHot : NodeFill, NodeRing, new Point(EnvBeatToX(p.beat, w), EnvValToY(p.val, h)), 4.5, 4.5);
+ }
}
if (_frac >= 0 && _frac <= 1)
{
- // _frac is relative to the played window; map it into the current domain.
// _frac runs over the PLAYED window, so on a reversed clip it walks the region
// from its end back to its start (which the mirror then draws left-to-right).
double pf = _reversed ? 1 - _frac : _frac;
double x = (_srcMode && _srcTotal > 0) ? SrcToX(_srcOff + pf * _srcLen, w)
: (_trimMode && _trimTotal > 0) ? BeatToX(_trimStart + pf * (_trimEnd - _trimStart), w)
: FracToX(pf, w);
- ctx.DrawLine(new Pen(PlayheadCursor, 1), new Point(x, 0), new Point(x, h));
+ ctx.DrawLine(PlayheadPen, new Point(x, 0), new Point(x, h));
}
}
+ // Ruler: bar.beat over the warp's beats, or seconds over the source when unwarped.
+ // Bars in Ink 2, beats in Ink 6, mono 9 on the baseline right of each tick.
+ private void DrawRuler(DrawingContext ctx, double w)
+ {
+ if (_mk.Count > 1)
+ {
+ double tb = TotalBeats;
+ double beatW = _zoom * w / tb;
+ int step = beatW >= 30 ? 1 : BeatsPerBar;
+ int last = (int)Math.Floor(tb + 1e-6);
+ for (int b = 0; b <= last; b += step)
+ {
+ double x = BeatToX(b, w);
+ if (x < -40 || x > w + 0.5) continue;
+ bool bar = b % BeatsPerBar == 0;
+ ctx.DrawLine(bar ? GridBarPen : GridBeatPen, new Point(x + 0.5, 0), new Point(x + 0.5, RulerH));
+ if (b >= last) continue;
+ int barNo = b / BeatsPerBar + 1, beatNo = b % BeatsPerBar + 1;
+ string label = bar ? barNo.ToString(NotaNum.Culture) : $"{barNo}.{beatNo}";
+ var ft = new FormattedText(label, NotaNum.Culture, FlowDirection.LeftToRight, GridFace, 9, bar ? RulerBar : RulerBeat);
+ ctx.DrawText(ft, new Point(_reversed ? x - 4 - ft.Width : x + 4, RulerH - 5 - ft.Height));
+ }
+ return;
+ }
+ if (!(_srcMode && _srcTotal > 0 && _srcSR > 0)) return;
+ double secs = _srcTotal / _srcSR;
+ double pxPerSec = _zoom * w / Math.Max(1e-6, secs);
+ double[] steps = { 0.1, 0.25, 0.5, 1, 2, 5, 10, 15, 30, 60 };
+ double stepS = 60;
+ foreach (var s in steps) if (s * pxPerSec >= 56) { stepS = s; break; }
+ for (int k = 0; k * stepS <= secs + 1e-9; k++)
+ {
+ double t = k * stepS;
+ double x = SrcToX(t * _srcSR, w);
+ if (x < -40 || x > w + 0.5) continue;
+ ctx.DrawLine(GridBeatPen, new Point(x + 0.5, 0), new Point(x + 0.5, RulerH));
+ var ft = new FormattedText(string.Format(NotaNum.Culture, stepS < 1 ? "{0:0.0#} s" : "{0:0} s", t),
+ NotaNum.Culture, FlowDirection.LeftToRight, GridFace, 9, k == 0 ? RulerBar : RulerBeat);
+ ctx.DrawText(ft, new Point(_reversed ? x - 4 - ft.Width : x + 4, RulerH - 5 - ft.Height));
+ }
+ }
+
+ // bar.beat.16th of a warp beat (1-based) for the selected marker's chip.
+ private static string Position(double beat)
+ {
+ int bar = (int)Math.Floor(beat / BeatsPerBar) + 1;
+ double inBar = beat - Math.Floor(beat / BeatsPerBar) * BeatsPerBar;
+ int be = (int)Math.Floor(inBar) + 1, six = (int)Math.Round((inBar - Math.Floor(inBar)) * 4) + 1;
+ if (six > 4) { six = 1; be++; }
+ return $"{bar}.{be}.{six}";
+ }
+
// Shade everything outside the region's two edges. They arrive in content order, which
// is right-to-left on a mirrored (reversed) view, so normalise before filling.
private void DimOutside(DrawingContext ctx, double xa, double xb, double w, double h)
{
double lo = Math.Clamp(Math.Min(xa, xb), 0, w), hi = Math.Clamp(Math.Max(xa, xb), 0, w);
- if (lo > 0.5) ctx.FillRectangle(OutsideDim, new Rect(0, 0, lo, h));
- if (hi < w - 0.5) ctx.FillRectangle(OutsideDim, new Rect(hi, 0, w - hi, h));
+ double top = WaveTop;
+ if (lo > 0.5) ctx.FillRectangle(OutsideDim, new Rect(0, top, lo, h - top));
+ if (hi < w - 0.5) ctx.FillRectangle(OutsideDim, new Rect(hi, top, w - hi, h - top));
}
- // A trim bracket: vertical line + grips at top and bottom pointing into the region.
- // Which screen side that is depends on the draw order, so the caller passes it —
- // a mirrored (reversed) view has the region's start on the right.
+ // A trim edge: an Ink 2 line through the wave, grips at top and bottom pointing into
+ // the region. Which screen side that is depends on the draw order, so the caller
+ // passes it — a mirrored (reversed) view has the region's start on the right.
private void DrawBracket(DrawingContext ctx, double x, double h, bool gripRight, bool hot)
{
var brush = hot ? BracketHot : Bracket;
- ctx.DrawLine(new Pen(brush, hot ? 2.4 : 1.6), new Point(x, 0), new Point(x, h));
+ double top = WaveTop;
+ ctx.DrawLine(new Pen(brush, hot ? 2 : 1), new Point(x, top), new Point(x, h));
double dir = gripRight ? 1 : -1;
var g = new StreamGeometry();
using (var gc = g.Open())
{
- gc.BeginFigure(new Point(x, 0), true); gc.LineTo(new Point(x + dir * 8, 0)); gc.LineTo(new Point(x, 10)); gc.EndFigure(true);
- gc.BeginFigure(new Point(x, h), true); gc.LineTo(new Point(x + dir * 8, h)); gc.LineTo(new Point(x, h - 10)); gc.EndFigure(true);
+ gc.BeginFigure(new Point(x, top), true); gc.LineTo(new Point(x + dir * 7, top)); gc.LineTo(new Point(x, top + 8)); gc.EndFigure(true);
+ gc.BeginFigure(new Point(x, h), true); gc.LineTo(new Point(x + dir * 7, h)); gc.LineTo(new Point(x, h - 8)); gc.EndFigure(true);
}
ctx.DrawGeometry(brush, null, g);
}
diff --git a/src/managed/Nota.App/ClipEditorKit.cs b/src/managed/Nota.App/ClipEditorKit.cs
new file mode 100644
index 00000000..6d112341
--- /dev/null
+++ b/src/managed/Nota.App/ClipEditorKit.cs
@@ -0,0 +1,381 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Shared shell pieces of the clip editor (nota-design "Nota Clip Editor"): one frame for
+// MIDI and audio — a 38px header whose first 232px is the clip cell (track-colour bar,
+// name, kind badge), mode segments after it, and a 232px inspector on the left whose
+// sections are split by hairlines and end in a single hint line. Everything here is the
+// shell scale (11px words, 10px caps section labels); the theme's Button / .primary /
+// ToggleButton.seg carry the states.
+
+using System;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Controls.Primitives;
+using Avalonia.Input;
+using Avalonia.Layout;
+using Avalonia.Media;
+
+namespace Nota.App;
+
+internal static class ClipEditorKit
+{
+ public const double HeaderH = 38, InspectorW = 232, ToolsW = 272, FieldH = 26;
+
+ // ---- header -----------------------------------------------------------
+
+ /// <summary>The 38px header: clip cell | modes | (flex) | right-hand controls.</summary>
+ public static Border Header(IBrush trackColor, string name, string kind, Control modes, Control? afterModes, Control? right)
+ {
+ var cell = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 9 };
+ var nameText = new TextBlock
+ {
+ Text = name, FontSize = NotaType.Name, FontWeight = FontWeight.Medium, Foreground = NotaPalette.TextPrimary,
+ VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis,
+ };
+ var badge = new TextBlock
+ {
+ Text = kind, FontFamily = NotaFonts.MonoFamily, FontSize = 9, FontWeight = FontWeight.Medium, LetterSpacing = 0.9,
+ Foreground = NotaPalette.TextTertiary, VerticalAlignment = VerticalAlignment.Center,
+ };
+ cell.Children.Add(nameText);
+ Grid.SetColumn(badge, 1); cell.Children.Add(badge);
+ var cellHost = new Border
+ {
+ Width = InspectorW, BorderBrush = NotaPalette.BorderDefault, BorderThickness = new Thickness(0, 0, 1, 0),
+ Child = new Grid
+ {
+ Children =
+ {
+ new Border { Width = 3, HorizontalAlignment = HorizontalAlignment.Left, Background = trackColor },
+ new Border { Padding = new Thickness(14, 0), Child = cell },
+ },
+ },
+ };
+
+ var row = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,Auto,*,Auto"), ColumnSpacing = 12 };
+ row.Children.Add(cellHost);
+ modes.VerticalAlignment = VerticalAlignment.Center;
+ Grid.SetColumn(modes, 1); row.Children.Add(modes);
+ if (afterModes is not null) { afterModes.VerticalAlignment = VerticalAlignment.Center; Grid.SetColumn(afterModes, 2); row.Children.Add(afterModes); }
+ if (right is not null) { right.VerticalAlignment = VerticalAlignment.Center; Grid.SetColumn(right, 4); row.Children.Add(right); }
+ return new Border
+ {
+ Height = HeaderH, Background = NotaPalette.Panel, BorderBrush = NotaPalette.BorderDefault,
+ BorderThickness = new Thickness(0, 0, 0, 1), Padding = new Thickness(0, 0, 12, 0), Child = row,
+ };
+ }
+
+ /// <summary>A 1×18 hairline between header groups.</summary>
+ public static Border HeaderDivider() => new()
+ {
+ Width = 1, Height = 18, Background = NotaPalette.BorderDefault, VerticalAlignment = VerticalAlignment.Center,
+ };
+
+ /// <summary>Shell segments (theme <c>Border.segmented</c> + <c>ToggleButton.seg</c>): the
+ /// chosen one solid brass. Behaves as a radio group; <paramref name="set"/> repaints
+ /// from outside without raising <paramref name="pick"/>.</summary>
+ public static Border Segments(string[] names, int initial, Action<int> pick, out Action<int> set, bool fill = false)
+ {
+ var buttons = new ToggleButton[names.Length];
+ Panel row = fill ? new Grid { ColumnSpacing = 2 } : new StackPanel { Orientation = Orientation.Horizontal, Spacing = 2 };
+ void Paint(int idx) { for (int i = 0; i < buttons.Length; i++) buttons[i].IsChecked = i == idx; }
+ for (int i = 0; i < names.Length; i++)
+ {
+ int iv = i;
+ var b = new ToggleButton { Content = names[i], Classes = { "seg" }, Padding = new Thickness(12, 0) };
+ if (fill)
+ {
+ ((Grid)row).ColumnDefinitions.Add(new ColumnDefinition(1, GridUnitType.Star));
+ Grid.SetColumn(b, i);
+ b.HorizontalAlignment = HorizontalAlignment.Stretch;
+ b.HorizontalContentAlignment = HorizontalAlignment.Center;
+ }
+ b.Click += (_, _) => { Paint(iv); pick(iv); };
+ buttons[i] = b;
+ row.Children.Add(b);
+ }
+ Paint(initial);
+ set = Paint;
+ return new Border { Classes = { "segmented" }, Child = row, HorizontalAlignment = fill ? HorizontalAlignment.Stretch : HorizontalAlignment.Left };
+ }
+
+ // ---- inspector --------------------------------------------------------
+
+ /// <summary>The 232px inspector: scrolling sections with the hint line pinned below.</summary>
+ public static Border Inspector(Control sections, TextBlock hint)
+ {
+ DockPanel.SetDock(hint, Dock.Bottom);
+ hint.Margin = new Thickness(14, 6, 14, 12);
+ return new Border
+ {
+ Width = InspectorW, Background = NotaPalette.Panel, BorderBrush = NotaPalette.BorderDefault,
+ BorderThickness = new Thickness(0, 0, 1, 0),
+ Child = new DockPanel
+ {
+ Children =
+ {
+ hint,
+ new ScrollViewer
+ {
+ Content = new Border { Padding = new Thickness(14, 16, 14, 8), Child = sections },
+ HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
+ VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
+ },
+ },
+ },
+ };
+ }
+
+ /// <summary>A vertical run of sections split by hairlines (gap 18 around each rule).</summary>
+ public static StackPanel Sections(params Control[] sections)
+ {
+ var s = new StackPanel { Spacing = 18 };
+ for (int i = 0; i < sections.Length; i++)
+ {
+ if (i > 0) s.Children.Add(Rule());
+ s.Children.Add(sections[i]);
+ }
+ return s;
+ }
+
+ public static Border Rule() => new() { Height = 1, Background = NotaPalette.GraphBorder };
+
+ /// <summary>A caps section title, with an optional mono read-out on the right.</summary>
+ public static Grid SectionTitle(string title, TextBlock? right = null)
+ {
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto") };
+ g.Children.Add(new TextBlock
+ {
+ Text = title, FontSize = NotaType.SectionLabel, FontWeight = FontWeight.Bold,
+ LetterSpacing = NotaType.SectionLabelTracking, Foreground = NotaPalette.TextTertiary, VerticalAlignment = VerticalAlignment.Center,
+ });
+ if (right is not null) { Grid.SetColumn(right, 1); g.Children.Add(right); }
+ return g;
+ }
+
+ public static StackPanel Section(string title, params Control[] body) => Section(SectionTitle(title), 8, body);
+
+ public static StackPanel Section(Control title, double spacing, params Control[] body)
+ {
+ var s = new StackPanel { Spacing = spacing };
+ s.Children.Add(title);
+ foreach (var c in body) s.Children.Add(c);
+ return s;
+ }
+
+ /// <summary>The one line of Ink 5 at the foot of the inspector.</summary>
+ public static TextBlock Hint(string text) => new()
+ {
+ Text = text, FontSize = 10, LineHeight = 16, Foreground = NotaPalette.TextTertiary, TextWrapping = TextWrapping.Wrap,
+ };
+
+ public static TextBlock Mono(string text, double size = 11, IBrush? fg = null) => new()
+ {
+ Text = text, FontFamily = NotaFonts.MonoFamily, FontSize = size, Foreground = fg ?? NotaPalette.TextPrimary,
+ VerticalAlignment = VerticalAlignment.Center,
+ };
+
+ /// <summary>A mono read-out for a section title's right side.</summary>
+ public static TextBlock Meta(string text) => Mono(text, 10, NotaPalette.TextMuted);
+
+ public static Grid Pair(Control a, Control b)
+ {
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 6 };
+ g.Children.Add(a);
+ Grid.SetColumn(b, 1); g.Children.Add(b);
+ return g;
+ }
+
+ /// <summary>A small Ink 4 label above a field.</summary>
+ public static StackPanel Labeled(string label, Control field) => new()
+ {
+ Spacing = 4,
+ Children = { new TextBlock { Text = label, FontSize = 10, Foreground = NotaPalette.TextMuted }, field },
+ };
+
+ // ---- fields and buttons -----------------------------------------------
+
+ /// <summary>A 26px sunken field.</summary>
+ public static Border Field(Control? child = null, double padX = 9)
+ {
+ var b = new Border
+ {
+ Height = FieldH, Background = NotaPalette.BgSunken, BorderBrush = NotaPalette.GraphBorder, BorderThickness = new Thickness(1),
+ CornerRadius = NotaRadius.Control, Padding = new Thickness(padX, 0), Child = child, VerticalAlignment = VerticalAlignment.Center,
+ };
+ b.BindResource(Border.BoxShadowProperty, "Shadow.Sunken");
+ return b;
+ }
+
+ /// <summary>A sunken dropdown: value left, an Ink 6 chevron right. Opens on a left click.</summary>
+ public static Border Dropdown(TextBlock value, Action<Control> open)
+ {
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 14 };
+ value.VerticalAlignment = VerticalAlignment.Center;
+ g.Children.Add(value);
+ var chev = new Glyph(GlyphKind.ChevronDown, 8) { Foreground = NotaPalette.TextDisabled, VerticalAlignment = VerticalAlignment.Center };
+ Grid.SetColumn(chev, 1); g.Children.Add(chev);
+ var f = Field(g);
+ f.Cursor = new Cursor(StandardCursorType.Hand);
+ f.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(f).Properties.IsLeftButtonPressed) return;
+ e.Handled = true;
+ open(f);
+ };
+ return f;
+ }
+
+ public static void ShowMenu(Control anchor, string[] items, int current, Action<int> pick)
+ {
+ var f = new MenuFlyout();
+ for (int i = 0; i < items.Length; i++)
+ {
+ int idx = i;
+ var mi = new MenuItem { Header = items[i] };
+ if (i == current) mi.Icon = new Glyph(GlyphKind.Dot, 6) { Foreground = NotaPalette.AccentBright };
+ mi.Click += (_, _) => pick(idx);
+ f.Items.Add(mi);
+ }
+ f.ShowAt(anchor);
+ }
+
+ /// <summary>A raised 26px shell button (theme <c>Button</c>).</summary>
+ public static Button Button(string text, Action click)
+ {
+ var b = new Button { Content = text, Padding = new Thickness(11, 0), HorizontalAlignment = HorizontalAlignment.Stretch };
+ b.Click += (_, _) => click();
+ return b;
+ }
+
+ /// <summary>A 26×26 raised button carrying a glyph (transpose −/+).</summary>
+ public static Button GlyphButton(GlyphKind kind, Action click)
+ {
+ var b = new Button { Width = FieldH, Padding = new Thickness(0), Content = new Glyph(kind, 9) };
+ b.Click += (_, _) => click();
+ return b;
+ }
+
+ /// <summary>A switch with its word to the right (shell: 11px, Ink 2). <paramref name="trailing"/>
+ /// rides the far right of the row (e.g. "8 beats").</summary>
+ public static Border SwitchRow(string label, Func<bool> get, Action toggle, out Action sync, Control? trailing = null, double height = FieldH)
+ {
+ var track = new SwitchTrack();
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,Auto,*,Auto"), ColumnSpacing = 8 };
+ g.Children.Add(track);
+ var word = new TextBlock { Text = label, FontSize = NotaType.Body, Foreground = NotaPalette.TextStrong, VerticalAlignment = VerticalAlignment.Center };
+ Grid.SetColumn(word, 1); g.Children.Add(word);
+ if (trailing is not null) { Grid.SetColumn(trailing, 3); g.Children.Add(trailing); }
+ var host = new Border { Height = height, Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand), Child = g };
+ void Paint() => track.IsOn = get();
+ host.PointerPressed += (_, e) =>
+ {
+ if (!host.IsEffectivelyEnabled || !e.GetCurrentPoint(host).Properties.IsLeftButtonPressed) return;
+ toggle(); Paint(); e.Handled = true;
+ };
+ sync = Paint;
+ Paint();
+ return host;
+ }
+
+ /// <summary>A sunken field with − and + zones either side of a centred mono value.</summary>
+ public static Border Stepper(TextBlock value, Action dec, Action inc, double zone = 22)
+ {
+ var g = new Grid { ColumnDefinitions = new ColumnDefinitions($"{zone},*,{zone}") };
+ g.Children.Add(StepZone(GlyphKind.Minus, dec));
+ value.HorizontalAlignment = HorizontalAlignment.Center;
+ Grid.SetColumn(value, 1); g.Children.Add(value);
+ var plus = StepZone(GlyphKind.Plus, inc);
+ Grid.SetColumn(plus, 2); g.Children.Add(plus);
+ return Field(g, 0);
+ }
+
+ private static Border StepZone(GlyphKind kind, Action click)
+ {
+ var glyph = new Glyph(kind, 8) { Foreground = NotaPalette.TextMuted, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
+ var z = new Border { Background = Brushes.Transparent, Cursor = new Cursor(StandardCursorType.Hand), Child = glyph };
+ z.PointerEntered += (_, _) => glyph.Foreground = NotaPalette.TextPrimary;
+ z.PointerExited += (_, _) => glyph.Foreground = NotaPalette.TextMuted;
+ z.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(z).Properties.IsLeftButtonPressed) return;
+ e.Handled = true;
+ click();
+ };
+ return z;
+ }
+
+ /// <summary>A 26px key · value row on Card (the Detected read-out, a selection line).</summary>
+ public static Grid KeyValue(string key, TextBlock value)
+ {
+ var g = new Grid { Height = FieldH, ColumnDefinitions = new ColumnDefinitions("*,Auto") };
+ g.Children.Add(new TextBlock { Text = key, FontSize = NotaType.Body, Foreground = NotaPalette.TextSecondary, VerticalAlignment = VerticalAlignment.Center });
+ Grid.SetColumn(value, 1); g.Children.Add(value);
+ return g;
+ }
+
+ /// <summary>The Card frame key · value rows sit in.</summary>
+ public static Border Card(Control child) => new()
+ {
+ Background = NotaPalette.SurfaceCard, BorderBrush = NotaPalette.BorderDefault, BorderThickness = new Thickness(1),
+ CornerRadius = NotaRadius.Control, Padding = new Thickness(10, 0), Child = child,
+ };
+
+ /// <summary>A shell slider row: caps label · 3px track · fixed-width mono value.</summary>
+ public static Grid SliderRow(string label, double labelW, Func<double> norm, Action<double> setNorm, Func<string> text,
+ out Action sync, Action? reset = null, double valueW = 36, Func<bool>? dim = null)
+ {
+ Action repaint = () => { };
+ var track = new SliderTrack { Reset = reset is null ? null : () => { reset(); repaint(); } };
+ var lbl = new TextBlock
+ {
+ Text = label, Width = labelW, FontSize = 9, FontWeight = FontWeight.Bold, LetterSpacing = 0.72,
+ VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis,
+ };
+ var val = Mono("", 10);
+ val.Width = valueW;
+ val.TextAlignment = TextAlignment.Right;
+ void Paint()
+ {
+ bool d = dim?.Invoke() ?? false;
+ track.Norm = norm();
+ track.IsDim = d;
+ val.Text = text();
+ val.Foreground = d ? NotaPalette.TextDisabled : NotaPalette.TextStrong;
+ lbl.Foreground = d ? NotaPalette.TextAxis : NotaPalette.TextTertiary;
+ }
+ repaint = Paint;
+ track.Changed += v => { setNorm(v); val.Text = text(); };
+ var g = new Grid { Height = 20, ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto"), ColumnSpacing = 10 };
+ g.Children.Add(lbl);
+ Grid.SetColumn(track, 1); g.Children.Add(track);
+ Grid.SetColumn(val, 2); g.Children.Add(val);
+ sync = () => { if (!track.Dragging) Paint(); };
+ Paint();
+ return g;
+ }
+
+ // ---- positions --------------------------------------------------------
+
+ /// <summary>bar.beat.16th (4/4), 1-based: 11.1.1.</summary>
+ public static string Position(double beat)
+ {
+ int bar = (int)Math.Floor(beat / 4) + 1, be = (int)Math.Floor(beat % 4) + 1, six = (int)Math.Round(beat % 1 * 4) + 1;
+ if (six > 4) { six = 1; be++; }
+ if (be > 4) { be = 1; bar++; }
+ return string.Format(NotaNum.Culture, "{0}.{1}.{2}", bar, be, six);
+ }
+
+ /// <summary>bars.beats.16ths as a duration (0-based): 2.0.0.</summary>
+ public static string Duration(double beats)
+ {
+ int bars = (int)Math.Floor(beats / 4), be = (int)Math.Floor(beats % 4), six = (int)Math.Round(beats % 1 * 4);
+ if (six > 3) { six = 0; be++; }
+ if (be > 3) { be = 0; bars++; }
+ return string.Format(NotaNum.Culture, "{0}.{1}.{2}", bars, be, six);
+ }
+
+ /// <summary>Signed semitones with the display minus: +3 st, −2 st, 0 st.</summary>
+ public static string Semis(int st) => st == 0 ? "0\u2009st" : string.Format(NotaNum.Culture, "{0:+0;−0}\u2009st", st);
+}
diff --git a/src/managed/Nota.App/ClipEditorView.cs b/src/managed/Nota.App/ClipEditorView.cs
index 090eb7f5..6f7c8d9a 100644
--- a/src/managed/Nota.App/ClipEditorView.cs
+++ b/src/managed/Nota.App/ClipEditorView.cs
@@ -1,253 +1,189 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// Detail · Clip (mockup 1e): composes the 200px props rail (ClipPropsView) with
-// the piano roll (PianoRollView). A header row carries the Notes | Envelopes
-// tabs; Envelopes (M9 follow-up) swaps in a per-clip envelope editor with a
-// Velocity / Volume target selector.
+// Detail · Clip for MIDI clips (nota-design "Nota Clip Editor" 1a): a 38px header — the clip
+// cell, Notes | Envelopes, then the Scale switch with its key and mode, and the Tools
+// toggle — over the 232px inspector (ClipPropsView), the piano roll (PianoRollView) and
+// the 272px clip-tools panel (MidiToolsView). Envelopes is a mode of the same canvas: the
+// notes dim under a wash and the clip envelope (Velocity / Volume) is drawn over them in
+// brass, on the roll's own beat axis so zoom and scroll carry over.
using System;
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.ClipEditorKit;
namespace Nota.App;
public sealed class ClipEditorView : UserControl
{
- private static readonly IBrush Panel = NotaPalette.SurfaceCard;
- private static readonly IBrush Sunken = NotaPalette.BgSunken;
- private static readonly IBrush BorderDef = NotaPalette.BorderDefault;
- private static readonly IBrush AccentSubtle = NotaPalette.AccentSubtle;
- private static readonly IBrush Brass = NotaPalette.Accent;
- private static readonly IBrush AccentBright = NotaPalette.AccentBright;
- private static readonly IBrush TextSecondary = NotaPalette.TextSecondary;
- private static readonly IBrush TextTertiary = NotaPalette.TextTertiary;
-
public PianoRollView Roll { get; }
- private readonly ContentControl _rightHost;
- private readonly EnvPanel? _envPanel;
+ private readonly EnvOverlay? _envOverlay;
private readonly ClipPropsView _props;
private readonly MidiToolsView _tools;
- private Border _notesTab = null!, _envTab = null!, _toolsChip = null!;
+ private readonly ToggleButton _toolsToggle;
+ private Action<int> _setTab = _ => { };
+ private bool _envMode;
public ClipEditorView(PianoRollView roll, string clipName, double startBeat,
IAudioEngine? engine = null, int trackId = -1, int clipIndex = -1, double lengthBeats = 4)
{
Roll = roll;
-
- _rightHost = new ContentControl { Content = roll };
if (engine is not null && trackId > 0 && clipIndex >= 0)
- _envPanel = new EnvPanel(engine, trackId, clipIndex, lengthBeats);
+ {
+ _envOverlay = new EnvOverlay(roll, engine, trackId, clipIndex, lengthBeats);
+ var named = engine.GetClipName(trackId, clipIndex);
+ if (!string.IsNullOrWhiteSpace(named)) clipName = named;
+ }
- // Props rail | editor | clip-tools rail. The tools rail is a toggle rather than a
+ // Inspector | roll | clip-tools panel. The tools panel is a toggle rather than a
// tab because its whole point is watching the roll change while you turn a knob.
var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto") };
- _props = new ClipPropsView(roll, clipName, startBeat);
+ _props = new ClipPropsView(roll, startBeat);
grid.Children.Add(_props);
- Grid.SetColumn(_rightHost, 1);
- grid.Children.Add(_rightHost);
+ Grid.SetColumn(roll, 1);
+ grid.Children.Add(roll);
_tools = new MidiToolsView(roll) { IsVisible = false };
Grid.SetColumn(_tools, 2);
grid.Children.Add(_tools);
- var header = TabsHeader();
+ _toolsToggle = new ToggleButton { Content = "Tools", Padding = new Thickness(12, 0), Classes = { "chip" } };
+ _toolsToggle.Click += (_, _) => SetTools(_toolsToggle.IsChecked == true);
+
+ var tabs = Segments(new[] { "Notes", "Envelopes" }, 0, i => ShowTab(i == 1), out _setTab);
+ if (_envOverlay is null) Inactive.Set(tabs, true); // session slots carry no clip envelope
+ var right = new StackPanel
+ {
+ Orientation = Orientation.Horizontal, Spacing = 12,
+ Children = { ScaleControls(), HeaderDivider(), _toolsToggle },
+ };
+ var header = Header(roll.TrackBrush, clipName, "MIDI", tabs, null, right);
DockPanel.SetDock(header, Dock.Top);
- var dock = new DockPanel();
- dock.Children.Add(header);
- dock.Children.Add(grid);
- Content = dock;
+ Content = new DockPanel { Background = NotaPalette.Gutter, Children = { header, grid } };
}
/// <summary>Follows a clip that was moved or resized in the arrangement while this editor
/// stayed on screen. The roll's own length is pushed by <c>PianoRollView.SetNotes</c>
- /// (which also refreshes the props rail's LENGTH/LOOP); this carries the pieces that
+ /// (which also refreshes the inspector's LENGTH/LOOP); this carries the pieces that
/// otherwise keep their construction-time snapshot.</summary>
public void SetClipBounds(double startBeat, double lengthBeats)
{
_props.SetStart(startBeat);
- _envPanel?.SetLength(lengthBeats);
+ _envOverlay?.SetLength(lengthBeats);
}
private void ShowTab(bool envelopes)
{
- if (envelopes && _envPanel is null) return;
- _rightHost.Content = envelopes ? _envPanel : Roll;
- PaintTab(_notesTab, !envelopes);
- PaintTab(_envTab, envelopes);
- if (envelopes && _tools.IsVisible) ToggleTools();
+ if (envelopes && _envOverlay is null) { _setTab(0); return; }
+ _envMode = envelopes;
+ Roll.SetOverlay(envelopes ? _envOverlay : null);
+ if (envelopes && _tools.IsVisible) SetTools(false);
}
- /// <summary>Shows or hides the clip-tools rail. Hiding drops the tool's preview, so
+ /// <summary>Shows or hides the clip-tools panel. Hiding drops the tool's preview, so
/// walking away from a half-tweaked generator leaves the clip as it was.</summary>
- private void ToggleTools()
+ private void SetTools(bool show)
{
- bool show = !_tools.IsVisible;
- if (show && _rightHost.Content != Roll) ShowTab(false);
+ if (show && _envMode) { _setTab(0); ShowTab(false); }
_tools.IsVisible = show;
- SetChip(_toolsChip, "Tools", show);
+ _toolsToggle.IsChecked = show;
_tools.SetActive(show);
}
- private static void PaintTab(Border tab, bool active)
- {
- tab.Background = active ? AccentSubtle : Brushes.Transparent;
- tab.BorderBrush = active ? Brass : Brushes.Transparent;
- ((TextBlock)tab.Child!).Foreground = active ? AccentBright : TextTertiary;
- }
-
- private Control TabsHeader()
- {
- _notesTab = Tab("Notes");
- _notesTab.PointerPressed += (_, _) => ShowTab(false);
- _envTab = Tab("Envelopes");
- _envTab.PointerPressed += (_, _) => ShowTab(true);
- _envTab.IsEnabled = _envPanel is not null;
- PaintTab(_notesTab, true);
- PaintTab(_envTab, false);
- Inactive.Set(_envTab, _envPanel is null);
- var tabs = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center, Children = { _notesTab, _envTab } };
- _toolsChip = Chip();
- SetChip(_toolsChip, "Tools", false);
- _toolsChip.PointerPressed += (_, e) => { e.Handled = true; ToggleTools(); };
- var right = new StackPanel
- {
- Orientation = Orientation.Horizontal, Spacing = 10, VerticalAlignment = VerticalAlignment.Center,
- Children = { ScaleControls(), _toolsChip },
- };
- DockPanel.SetDock(right, Dock.Right);
- return new Border
- {
- Height = 30, Background = Panel, BorderBrush = BorderDef, BorderThickness = new Thickness(0, 0, 0, 1),
- Padding = new Thickness(10, 0),
- Child = new DockPanel { LastChildFill = true, Children = { right, tabs } },
- };
- }
-
- // ---- scale overlay pickers ("Set Scale") ----------------
- private Border _scaleToggle = null!, _keyChip = null!, _scaleChip = null!;
+ // ---- scale overlay ("Set Scale"): a switch, then the key and the mode ----
+ private Action _syncScale = () => { };
+ private TextBlock _keyText = null!, _modeText = null!;
private Control ScaleControls()
{
- _scaleToggle = Chip();
- _keyChip = Chip(dropdown: true);
- _scaleChip = Chip(dropdown: true);
- _scaleToggle.PointerPressed += (_, e) => { e.Handled = true; Roll.SetScale(!Roll.ScaleOn, Roll.ScaleRoot, Roll.ScaleIndex); UpdateScaleChips(); };
- _keyChip.PointerPressed += (_, e) => { e.Handled = true; ShowMenu(_keyChip, PianoRollView.KeyNames, Roll.ScaleRoot, i => { Roll.SetScale(true, i, Roll.ScaleIndex); UpdateScaleChips(); }); };
- _scaleChip.PointerPressed += (_, e) => { e.Handled = true; ShowMenu(_scaleChip, PianoRollView.ScaleNames, Roll.ScaleIndex, i => { Roll.SetScale(true, Roll.ScaleRoot, i); UpdateScaleChips(); }); };
- UpdateScaleChips();
- return new StackPanel
- {
- Orientation = Orientation.Horizontal, Spacing = 6, VerticalAlignment = VerticalAlignment.Center,
- Children =
- {
- new TextBlock { Text = "SCALE", FontSize = 8, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(0, 0, 2, 0) },
- _scaleToggle, _keyChip, _scaleChip,
- },
- };
- }
-
- private void UpdateScaleChips()
- {
- bool on = Roll.ScaleOn;
- SetChip(_scaleToggle, on ? "On" : "Off", on);
- SetChip(_keyChip, PianoRollView.KeyNames[Roll.ScaleRoot], on);
- SetChip(_scaleChip, PianoRollView.ScaleNames[Roll.ScaleIndex], on);
- Inactive.Set(_keyChip, !on, interactive: true);
- Inactive.Set(_scaleChip, !on, interactive: true);
- }
-
- private static Border Chip(bool dropdown = false)
- {
- var tb = new TextBlock { FontSize = 10, VerticalAlignment = VerticalAlignment.Center, Foreground = TextSecondary };
- return new Border
- {
- Height = 22, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
- Background = NotaPalette.SurfaceRaised, BorderBrush = NotaPalette.BorderStrong,
- Padding = new Thickness(9, 0), VerticalAlignment = VerticalAlignment.Center, Cursor = new Cursor(StandardCursorType.Hand),
- Child = dropdown ? Glyph.WithChevron(tb) : tb,
- };
- }
-
- private static void SetChip(Border chip, string text, bool active)
- {
- var tb = chip.Child as TextBlock ?? (TextBlock)((StackPanel)chip.Child!).Children[0];
- tb.Text = text;
- tb.Foreground = active ? AccentBright : TextSecondary;
- chip.Background = active ? AccentSubtle : NotaPalette.SurfaceRaised;
- chip.BorderBrush = active ? Brass : NotaPalette.BorderStrong;
+ _keyText = Mono("");
+ _modeText = new TextBlock { FontSize = NotaType.Body };
+ var sw = SwitchRow("Scale", () => Roll.ScaleOn, () => { Roll.SetScale(!Roll.ScaleOn, Roll.ScaleRoot, Roll.ScaleIndex); PaintScale(); }, out _syncScale);
+ var key = Dropdown(_keyText, a => ShowMenu(a, PianoRollView.KeyNames, Roll.ScaleRoot, i => { Roll.SetScale(true, i, Roll.ScaleIndex); PaintScale(); }));
+ var mode = Dropdown(_modeText, a => ShowMenu(a, PianoRollView.ScaleNames, Roll.ScaleIndex, i => { Roll.SetScale(true, Roll.ScaleRoot, i); PaintScale(); }));
+ PaintScale();
+ return new StackPanel { Orientation = Orientation.Horizontal, Spacing = 8, Children = { sw, key, mode } };
}
- private static void ShowMenu(Control anchor, string[] items, int current, Action<int> pick)
+ private void PaintScale()
{
- var f = new MenuFlyout();
- for (int i = 0; i < items.Length; i++)
- {
- int idx = i;
- var mi = new MenuItem { Header = items[i] };
- if (i == current) mi.Icon = new TextBlock { Text = "•", Foreground = AccentBright };
- mi.Click += (_, _) => pick(idx);
- f.Items.Add(mi);
- }
- f.ShowAt(anchor);
+ _syncScale();
+ _keyText.Text = PianoRollView.KeyNames[Roll.ScaleRoot];
+ _modeText.Text = PianoRollView.ScaleNames[Roll.ScaleIndex];
+ var ink = Roll.ScaleOn ? NotaPalette.TextPrimary : NotaPalette.TextDisabled;
+ _keyText.Foreground = ink;
+ _modeText.Foreground = ink;
}
- private static Border Tab(string text) => new()
- {
- Height = 22, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
- Padding = new Thickness(10, 0), VerticalAlignment = VerticalAlignment.Center, Cursor = new Cursor(StandardCursorType.Hand),
- Child = new TextBlock { Text = text, FontSize = 11, VerticalAlignment = VerticalAlignment.Center },
- };
-
- // ---- envelope panel: target selector + editable curve -----------------
- private sealed class EnvPanel : UserControl
+ // ---- envelope overlay: a wash over the notes, the curve, a target picker ----------
+ private sealed class EnvOverlay : UserControl
{
+ private static readonly string[] Targets = { "Velocity", "Volume" };
private readonly IAudioEngine _engine;
private readonly int _trackId, _clipIndex;
private readonly EnvCanvas _canvas;
private readonly TextBlock _targetText;
private MidiClipEnvelope _target = MidiClipEnvelope.Velocity;
- public EnvPanel(IAudioEngine engine, int trackId, int clipIndex, double lengthBeats)
+ public EnvOverlay(PianoRollView roll, IAudioEngine engine, int trackId, int clipIndex, double lengthBeats)
{
_engine = engine; _trackId = trackId; _clipIndex = clipIndex;
- _canvas = new EnvCanvas(lengthBeats) { Committed = OnCommitted };
- _targetText = new TextBlock { Text = "Velocity", FontSize = 10, Foreground = AccentBright, VerticalAlignment = VerticalAlignment.Center };
+ _canvas = new EnvCanvas(roll, lengthBeats) { Committed = OnCommitted };
+ _targetText = new TextBlock { Text = Targets[0], FontSize = NotaType.Body, Foreground = NotaPalette.TextPrimary, VerticalAlignment = VerticalAlignment.Center };
var chip = new Border
{
- Height = 22, Background = NotaPalette.SurfaceRaised, BorderBrush = NotaPalette.BorderStrong,
- BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile, Padding = new Thickness(10, 0),
- Cursor = new Cursor(StandardCursorType.Hand), Child = Glyph.WithChevron(_targetText),
+ Height = 22, Background = NotaPalette.Panel, BorderBrush = NotaPalette.BorderDefault, BorderThickness = new Thickness(1),
+ CornerRadius = NotaRadius.Control, Padding = new Thickness(8, 0), Margin = new Thickness(10, 8, 0, 0),
+ HorizontalAlignment = HorizontalAlignment.Left, VerticalAlignment = VerticalAlignment.Top,
+ Cursor = new Cursor(StandardCursorType.Hand),
+ Child = new StackPanel
+ {
+ Orientation = Orientation.Horizontal, Spacing = 10,
+ Children =
+ {
+ new TextBlock
+ {
+ Text = "ENV", FontSize = 9, FontWeight = FontWeight.Bold, LetterSpacing = 1.08,
+ Foreground = NotaPalette.TextTertiary, VerticalAlignment = VerticalAlignment.Center,
+ },
+ _targetText,
+ new Glyph(GlyphKind.ChevronDown, 8) { Foreground = NotaPalette.TextDisabled, VerticalAlignment = VerticalAlignment.Center },
+ },
+ },
};
- chip.PointerPressed += (_, e) => { e.Handled = true; CycleTarget(); };
- var hint = new TextBlock { Text = "click to add · drag to move · right-click to delete", FontSize = 9, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(10, 0, 0, 0) };
- var bar = new Border
+ chip.PointerPressed += (_, e) =>
{
- Height = 30, Background = Panel, BorderBrush = BorderDef, BorderThickness = new Thickness(0, 0, 0, 1), Padding = new Thickness(10, 0),
- Child = new StackPanel { Orientation = Orientation.Horizontal, VerticalAlignment = VerticalAlignment.Center, Children = { chip, hint } },
+ if (!e.GetCurrentPoint(chip).Properties.IsLeftButtonPressed) return;
+ e.Handled = true;
+ ShowMenu(chip, Targets, _target == MidiClipEnvelope.Volume ? 1 : 0, i =>
+ {
+ _target = i == 1 ? MidiClipEnvelope.Volume : MidiClipEnvelope.Velocity;
+ _targetText.Text = Targets[i];
+ Load();
+ });
+ };
+ ToolTip.SetTip(chip, "Click to add a point · drag to move · right-click to delete");
+ Content = new Grid
+ {
+ Children =
+ {
+ new Border { Background = NotaPalette.Wash(NotaPalette.BgSunken, 0xB3), IsHitTestVisible = false },
+ _canvas,
+ chip,
+ },
};
- DockPanel.SetDock(bar, Dock.Top);
- var dock = new DockPanel();
- dock.Children.Add(bar);
- dock.Children.Add(new Border { Background = Sunken, Child = _canvas });
- Content = dock;
Load();
}
public void SetLength(double lengthBeats) => _canvas.SetLength(lengthBeats);
- private void CycleTarget()
- {
- _target = _target == MidiClipEnvelope.Velocity ? MidiClipEnvelope.Volume : MidiClipEnvelope.Velocity;
- _targetText.Text = _target == MidiClipEnvelope.Volume ? "Volume" : "Velocity";
- Load();
- }
-
private void Load()
{
var pts = _engine.GetMidiClipEnvelope(_trackId, _clipIndex, _target);
@@ -266,22 +202,33 @@ public sealed class ClipEditorView : UserControl
private sealed class EnvPt { public double Beat; public double Val; public float Curve; }
- // Custom-drawn envelope editor (0..1 over clip-local beats). Points carry a
- // per-segment curve (M9-D): drag a point to move it, drag a segment line to bend
- // it, right-click/double-click a point or segment to delete / reset to linear.
+ // Custom-drawn envelope editor (0..1 over clip-local beats) on the roll's beat axis.
+ // Points carry a per-segment curve (M9-D): drag a point to move it, drag a segment
+ // line to bend it, right-click/double-click a point or segment to delete / reset to
+ // linear. A brass line; nodes in Ink 3 ringed with the well, the one in hand in brass.
private sealed class EnvCanvas : Control
{
- private static readonly IBrush Bg = NotaPalette.BgSunken;
- private static readonly IBrush GridBeat = NotaPalette.Wash(NotaPalette.BorderStrong, 0x50);
- private static readonly IBrush EnvLine = NotaPalette.AccentBright;
+ private static readonly IPen EnvPen = new Pen(NotaPalette.Accent, 1.8);
+ private static readonly IBrush NodeFill = NotaPalette.TextSecondary;
+ private static readonly IBrush NodeHot = NotaPalette.Accent;
+ private static readonly IPen NodeRing = new Pen(NotaPalette.BgSunken, 2);
+ private static readonly IBrush EmptyInk = NotaPalette.TextTertiary;
+ private readonly PianoRollView _roll;
private readonly System.Collections.Generic.List<EnvPt> _pts = new();
private double _clipBeats;
- private int _drag = -1;
+ private int _drag = -1, _hover = -1;
private EnvPt? _bend;
private const double HandlePx = 7;
public Action<double[], double[], float[]>? Committed;
- public EnvCanvas(double clipBeats) { _clipBeats = Math.Max(1e-6, clipBeats); }
+ public EnvCanvas(PianoRollView roll, double clipBeats)
+ {
+ _roll = roll;
+ _clipBeats = Math.Max(1e-6, clipBeats);
+ Background = Brushes.Transparent; // take the pointer across the whole grid
+ }
+
+ public IBrush? Background { get; init; }
// The clip was trimmed/stretched in the arrangement: re-span the beat axis. Points keep
// their beats (the engine clamps them to the new length), so only the mapping changes.
@@ -300,8 +247,8 @@ public sealed class ClipEditorView : UserControl
InvalidateVisual();
}
- private double BeatToX(double beat, double w) => beat / _clipBeats * w;
- private double XToBeat(double x, double w) => Math.Clamp(x / Math.Max(1, w), 0, 1) * _clipBeats;
+ private double BeatToX(double beat, double w) => _roll.BeatToX(beat);
+ private double XToBeat(double x, double w) => Math.Clamp(_roll.XToBeat(x), 0, _clipBeats);
private static double ValToY(double v, double h) { double pad = 6; return pad + (1 - Math.Clamp(v, 0, 1)) * (h - 2 * pad); }
private static double YToVal(double y, double h) { double pad = 6; return Math.Clamp((h - pad - y) / Math.Max(1, h - 2 * pad), 0, 1); }
private static double Shape(double t, float curve) => curve == 0f ? t : Math.Pow(t, Math.Pow(2.0, -curve * 4.0));
@@ -372,9 +319,21 @@ public sealed class ClipEditorView : UserControl
InvalidateVisual();
}
+ protected override void OnPointerWheelChanged(PointerWheelEventArgs e) => _roll.RouteWheel(e, e.GetPosition(this).X);
+
+ protected override void OnPointerExited(PointerEventArgs e)
+ {
+ if (_hover != -1) { _hover = -1; InvalidateVisual(); }
+ }
+
protected override void OnPointerMoved(PointerEventArgs e)
{
var p = e.GetPosition(this);
+ if (_drag < 0 && _bend is null)
+ {
+ int hv = HitPoint(p.X, p.Y, Bounds.Width, Bounds.Height);
+ if (hv != _hover) { _hover = hv; InvalidateVisual(); }
+ }
if (_drag >= 0)
{
_pts[_drag].Beat = XToBeat(p.X, Bounds.Width);
@@ -405,18 +364,18 @@ public sealed class ClipEditorView : UserControl
public override void Render(DrawingContext ctx)
{
double w = Bounds.Width, h = Bounds.Height;
- ctx.FillRectangle(Bg, new Rect(0, 0, w, h));
- for (int b = 0; b <= (int)Math.Floor(_clipBeats + 1e-6); b++)
+ if (Background is not null) ctx.FillRectangle(Background, new Rect(0, 0, w, h));
+ if (_pts.Count == 0) // empty state: one Ink 5 line
{
- double x = BeatToX(b, w);
- if (x > w) break;
- ctx.DrawLine(new Pen(GridBeat, b % 4 == 0 ? 1 : 0.6), new Point(x, 0), new Point(x, h));
+ var ft = new FormattedText("Click to add a point", NotaNum.Culture, FlowDirection.LeftToRight, NotaFonts.Sans, NotaType.Body, EmptyInk);
+ ctx.DrawText(ft, new Point((w - ft.Width) / 2, (h - ft.Height) / 2));
+ return;
}
if (_pts.Count == 0) return;
var ord = Sorted();
- var pen = new Pen(EnvLine, 1.6);
+ var pen = EnvPen;
double fy = ValToY(ord[0].Val, h);
- ctx.DrawLine(pen, new Point(0, fy), new Point(BeatToX(ord[0].Beat, w), fy));
+ ctx.DrawLine(pen, new Point(Math.Max(0, BeatToX(0, w)), fy), new Point(BeatToX(ord[0].Beat, w), fy));
for (int i = 1; i < ord.Count; i++)
{
var a = ord[i - 1]; var b = ord[i];
@@ -432,9 +391,13 @@ public sealed class ClipEditorView : UserControl
}
}
double ly = ValToY(ord[^1].Val, h);
- ctx.DrawLine(pen, new Point(BeatToX(ord[^1].Beat, w), ly), new Point(w, ly));
- foreach (var p in ord)
- ctx.DrawEllipse(EnvLine, null, new Point(BeatToX(p.Beat, w), ValToY(p.Val, h)), 3, 3);
+ ctx.DrawLine(pen, new Point(BeatToX(ord[^1].Beat, w), ly), new Point(Math.Min(w, BeatToX(_clipBeats, w)), ly));
+ for (int i = 0; i < _pts.Count; i++)
+ {
+ var p = _pts[i];
+ bool hot = i == _drag || i == _hover;
+ ctx.DrawEllipse(hot ? NodeHot : NodeFill, NodeRing, new Point(BeatToX(p.Beat, w), ValToY(p.Val, h)), 4.5, 4.5);
+ }
}
}
}
diff --git a/src/managed/Nota.App/ClipPropsView.cs b/src/managed/Nota.App/ClipPropsView.cs
index 6e0729dc..3469abd4 100644
--- a/src/managed/Nota.App/ClipPropsView.cs
+++ b/src/managed/Nota.App/ClipPropsView.cs
@@ -1,37 +1,23 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// The 200px clip props rail beside the piano roll (mockup 1e): clip name,
-// Start/Length in bars.beats.16ths (mono), a Loop chip, a grid picker with a
-// one-tap Quantize + strength, a transpose stepper and a live selection line.
-// Edits drive the PianoRollView (grid / quantize / transpose); read-outs follow
-// its Changed event.
+// The 232px inspector beside the piano roll (nota-design "Nota Clip Editor" 1a): CLIP
+// (Start / Length in bars.beats.16ths, the Loop switch and its length), GRID (grid
+// dropdown, Quantize, strength), TRANSPOSE (− value +) and SELECTION (the selected note's
+// pitch / start / length / velocity, or the range of several), ending in one hint line.
+// Edits drive the PianoRollView; read-outs follow its Changed event.
using System;
-using System.Globalization;
+using System.Linq;
using Avalonia;
using Avalonia.Controls;
-using Avalonia.Controls.Primitives;
-using Avalonia.Input;
-using Avalonia.Layout;
using Avalonia.Media;
+using static Nota.App.ClipEditorKit;
namespace Nota.App;
public sealed class ClipPropsView : UserControl
{
- private static readonly IBrush Panel = NotaPalette.SurfaceCard;
- private static readonly IBrush Sunken = NotaPalette.BgSunken;
- private static readonly IBrush Raised = NotaPalette.SurfaceRaised;
- private static readonly IBrush BorderDef = NotaPalette.BorderDefault;
- private static readonly IBrush BorderStrong = NotaPalette.BorderStrong;
- private static readonly IBrush Brass = NotaPalette.Accent;
- private static readonly IBrush AccentBright = NotaPalette.AccentBright;
- private static readonly IBrush AccentSubtle = NotaPalette.AccentSubtle;
- private static readonly IBrush TextPrimary = NotaPalette.TextPrimary;
- private static readonly IBrush TextSecondary = NotaPalette.TextSecondary;
- private static readonly IBrush TextTertiary = NotaPalette.TextTertiary;
-
// Grid steps in beats (4/4, one beat = a 1/4 note). Straight divisions then triplets.
private static readonly double[] GridValues =
{ 4.0, 2.0, 1.0, 0.5, 0.25, 0.125, 0.0625, 2.0 / 3, 1.0 / 3, 1.0 / 6, 1.0 / 12 };
@@ -39,113 +25,74 @@ public sealed class ClipPropsView : UserControl
{ "1/1", "1/2", "1/4", "1/8", "1/16", "1/32", "1/64", "1/4T", "1/8T", "1/16T", "1/32T" };
private readonly PianoRollView _roll;
- private readonly TextBlock _startText;
- private readonly TextBlock _lengthText;
- private readonly TextBlock _loopText;
- private readonly TextBlock _selInfo;
- private readonly TextBlock _transposeText;
- private readonly TextBlock _gridText;
+ private readonly TextBlock _startText = Mono("");
+ private readonly TextBlock _lengthText = Mono("");
+ private readonly TextBlock _loopText = Mono("", 10, NotaPalette.TextStrong);
+ private readonly TextBlock _transposeText = Mono("");
+ private readonly TextBlock _gridText = Mono("");
+ private readonly TextBlock _selCount = Meta("—");
+ private readonly StackPanel _selRows = new();
+ private readonly Border _selCard;
+ private readonly Border _selEmpty;
private int _gridIndex = 4; // 1/16
private int _transpose;
private double _strength = 0.8;
- public ClipPropsView(PianoRollView roll, string clipName, double startBeat)
+ public ClipPropsView(PianoRollView roll, double startBeat)
{
_roll = roll;
- Width = 200;
- Background = Panel;
- BorderBrush = BorderDef;
- BorderThickness = new Thickness(0, 0, 1, 0);
-
- _startText = Mono(Position(startBeat));
- _lengthText = Mono(Duration(roll.LengthBeats));
- _loopText = Mono($"{roll.LengthBeats:0.#}b");
- _loopText.Foreground = AccentBright;
- _selInfo = new TextBlock { Text = roll.SelectionInfo, FontSize = 9, Foreground = TextTertiary, TextWrapping = TextWrapping.Wrap };
- _transposeText = Mono("0\u2009st");
- _gridText = new TextBlock { Text = GridLabels[_gridIndex], FontSize = 10, Foreground = TextPrimary, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
-
- var body = new StackPanel { Spacing = 10, Margin = new Thickness(10) };
- body.Children.Add(Section("CLIP", ReadoutBox(clipName, TextPrimary, 24, 11, false)));
-
- var startLen = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 6 };
- var startBox = FieldBox(22); startBox.Child = _startText;
- startLen.Children.Add(Labeled("START", startBox));
- var lenBox = FieldBox(22); lenBox.Child = _lengthText;
- var lenWrap = Labeled("LENGTH", lenBox);
- Grid.SetColumn(lenWrap, 1);
- startLen.Children.Add(lenWrap);
- body.Children.Add(startLen);
-
- // Loop chip (clips loop by default in this model).
- body.Children.Add(new Border
+ _startText.Text = Position(startBeat);
+ _gridText.Text = GridLabels[_gridIndex];
+
+ // CLIP — clips always loop in this model; the switch waits for a per-clip loop.
+ var loop = SwitchRow("Loop", () => true, () => { }, out _, _loopText);
+ loop.IsEnabled = false;
+ ToolTip.SetTip(loop, "Clips always loop");
+ var clip = Section("CLIP",
+ Pair(Labeled("Start", Field(_startText)), Labeled("Length", Field(_lengthText))),
+ loop);
+
+ // GRID — the grid step, one-tap Quantize at the strength below.
+ var grid = Section("GRID",
+ Pair(Dropdown(_gridText, a => ShowMenu(a, GridLabels, _gridIndex, i =>
+ {
+ _gridIndex = i;
+ _gridText.Text = GridLabels[i];
+ _roll.Grid = GridValues[i];
+ })),
+ ClipEditorKit.Button("Quantize", () => _roll.Quantize(_strength))),
+ SliderRow("STRENGTH", 64, () => _strength, v => _strength = v,
+ () => string.Format(NotaNum.Culture, "{0:0}\u2009%", _strength * 100), out _, reset: () => _strength = 0.8, valueW: 34));
+
+ // TRANSPOSE — − value +; the value turns Brass Light while it is off zero.
+ _transposeText.HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center;
+ var tRow = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto"), ColumnSpacing = 6 };
+ tRow.Children.Add(GlyphButton(GlyphKind.Minus, () => Transpose(-1)));
+ var tField = Field(_transposeText);
+ Grid.SetColumn(tField, 1); tRow.Children.Add(tField);
+ var plus = GlyphButton(GlyphKind.Plus, () => Transpose(1));
+ Grid.SetColumn(plus, 2); tRow.Children.Add(plus);
+ var transpose = Section("TRANSPOSE", tRow);
+
+ // SELECTION — a card of read-outs, or one empty-state line in the same frame.
+ _selCard = Card(_selRows);
+ _selCard.Padding = new Thickness(0);
+ _selEmpty = new Border
{
- Height = 26, Background = AccentSubtle, BorderBrush = Brass, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
- Child = new StackPanel
+ Height = 104, BorderBrush = NotaPalette.GraphBorder, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Control,
+ Child = new TextBlock
{
- Orientation = Orientation.Horizontal, Spacing = 6, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
- Children = { new TextBlock { Text = "Loop", FontSize = 11, Foreground = AccentBright, VerticalAlignment = VerticalAlignment.Center }, _loopText },
+ Text = "No notes selected", FontSize = NotaType.Body, Foreground = NotaPalette.TextTertiary,
+ HorizontalAlignment = Avalonia.Layout.HorizontalAlignment.Center, VerticalAlignment = Avalonia.Layout.VerticalAlignment.Center,
},
- });
-
- // Grid + quantize.
- var gridChip = Chip(Glyph.WithChevron(_gridText));
- gridChip.PointerPressed += (_, e) =>
- {
- e.Handled = true;
- var f = new MenuFlyout();
- for (int i = 0; i < GridValues.Length; i++)
- {
- int idx = i;
- var mi = new MenuItem { Header = GridLabels[i] };
- if (i == _gridIndex) mi.Icon = new TextBlock { Text = "•", Foreground = AccentBright };
- mi.Click += (_, _) =>
- {
- _gridIndex = idx;
- _gridText.Text = GridLabels[idx];
- _roll.Grid = GridValues[idx];
- };
- f.Items.Add(mi);
- }
- f.ShowAt(gridChip);
- };
- var quantize = Chip(new TextBlock { Text = "Quantize", FontSize = 10, Foreground = TextSecondary, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center });
- quantize.PointerPressed += (_, _) => _roll.Quantize(_strength);
- var gridRow = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 6 };
- gridRow.Children.Add(gridChip);
- Grid.SetColumn(quantize, 1); gridRow.Children.Add(quantize);
-
- var strengthVal = Mono("80%"); strengthVal.Foreground = TextSecondary;
- var strengthBar = new MiniFader(_strength, 1.0) { VerticalAlignment = VerticalAlignment.Center };
- strengthBar.ValueChanged += v => { _strength = v; strengthVal.Text = $"{v * 100:0}\u2009%"; };
- var strengthRow = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto"), Margin = new Thickness(0, 2, 0, 0) };
- strengthRow.Children.Add(new TextBlock { Text = "STRENGTH", FontSize = 9, Foreground = TextTertiary, Width = 52, VerticalAlignment = VerticalAlignment.Center });
- Grid.SetColumn(strengthBar, 1); strengthRow.Children.Add(strengthBar);
- Grid.SetColumn(strengthVal, 2); strengthVal.VerticalAlignment = VerticalAlignment.Center; strengthVal.Margin = new Thickness(4, 0, 0, 0); strengthRow.Children.Add(strengthVal);
-
- body.Children.Add(Section("GRID / QUANTIZE", new StackPanel { Spacing = 4, Children = { gridRow, strengthRow } }));
-
- // Transpose stepper.
- var minus = StepBtn("−", () => Transpose(-1));
- var plus = StepBtn("+", () => Transpose(1));
- var stepper = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*,Auto"), ColumnSpacing = 6 };
- stepper.Children.Add(minus);
- var tBox = FieldBox(22); tBox.Child = _transposeText;
- Grid.SetColumn(tBox, 1); stepper.Children.Add(tBox);
- Grid.SetColumn(plus, 2); stepper.Children.Add(plus);
- body.Children.Add(Section("TRANSPOSE", stepper));
-
- _selInfo.Margin = new Thickness(0, 8, 0, 0);
- var hint = new TextBlock { Text = "Double-click = add · drag edge = length", FontSize = 9, Foreground = TextTertiary, TextWrapping = TextWrapping.Wrap, Margin = new Thickness(0, 2, 0, 6) };
- body.Children.Add(_selInfo);
- body.Children.Add(hint);
- Content = new ScrollViewer
- {
- Content = body,
- HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
- VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
};
+ var selection = Section(SectionTitle("SELECTION", _selCount), 8, _selCard, _selEmpty);
+ Content = Inspector(Sections(clip, grid, transpose, selection),
+ Hint("Double-click — add or delete · edge — length · Shift — add to selection"));
+
+ PaintTranspose();
+ OnRollChanged();
_roll.Changed += OnRollChanged;
}
@@ -155,86 +102,59 @@ public sealed class ClipPropsView : UserControl
private void OnRollChanged()
{
- _selInfo.Text = _roll.SelectionInfo;
- _lengthText.Text = Duration(_roll.LengthBeats);
- _loopText.Text = $"{_roll.LengthBeats:0.#}b";
+ double len = _roll.LengthBeats;
+ _lengthText.Text = Duration(len);
+ _loopText.Text = string.Format(NotaNum.Culture, "{0:0.##} {1}", len, Math.Abs(len - 1) < 1e-9 ? "beat" : "beats");
+ PaintSelection();
}
private void Transpose(int d)
{
_transpose += d;
- _transposeText.Text = $"{_transpose}\u2009st";
+ PaintTranspose();
_roll.TransposeBy(d);
}
- // --- helpers ----------------------------------------------------------
-
- private static TextBlock Mono(string text)
+ private void PaintTranspose()
{
- var t = new TextBlock { Text = text, FontSize = 10, Foreground = NotaPalette.TextPrimary, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(7, 0, 0, 0) };
- t.BindResource(FontFamilyProperty, "Font.Mono");
- return t;
+ _transposeText.Text = Semis(_transpose);
+ _transposeText.Foreground = _transpose != 0 ? NotaPalette.AccentBright : NotaPalette.TextPrimary;
}
- private static Control Section(string title, Control content) => new StackPanel
+ private void PaintSelection()
{
- Spacing = 4,
- Children =
+ var sel = _roll.SelectedNotes();
+ _selCount.Text = sel.Count > 0 ? sel.Count.ToString(NotaNum.Culture) : "—";
+ _selCard.IsVisible = sel.Count > 0;
+ _selEmpty.IsVisible = sel.Count == 0;
+ _selRows.Children.Clear();
+ if (sel.Count == 1)
{
- new TextBlock { Text = title, FontSize = 9, FontWeight = FontWeight.Bold, Foreground = TextTertiary },
- content,
- },
- };
-
- private static Control Labeled(string title, Control content) => new StackPanel
- {
- Spacing = 2,
- Children = { new TextBlock { Text = title, FontSize = 9, Foreground = TextTertiary }, content },
- };
-
- private static Border FieldBox(double h) => new()
- {
- Height = h, Background = Sunken, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
- };
-
- private static Border ReadoutBox(string text, IBrush fg, double h, double fs, bool mono)
- {
- var t = new TextBlock { Text = text, FontSize = fs, Foreground = fg, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(mono ? 7 : 8, 0, 0, 0) };
- if (mono) t.BindResource(FontFamilyProperty, "Font.Mono");
- var box = FieldBox(h);
- box.Child = t;
- return box;
- }
-
- private static Border Chip(Control child) => new()
- {
- Height = 22, Background = Raised, BorderBrush = BorderStrong, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
- Cursor = new Cursor(StandardCursorType.Hand), Child = child,
- };
-
- private static Border StepBtn(string glyph, Action onClick)
- {
- var b = new Border
+ var n = sel[0];
+ Row("Pitch", PianoRollView.NoteName(n.Pitch));
+ Row("Start", Position(n.StartBeat));
+ Row("Length", string.Format(NotaNum.Culture, "{0:0.##}/16", n.LengthBeats * 4));
+ Row("Velocity", Vel(n.Velocity).ToString(NotaNum.Culture), last: true);
+ }
+ else if (sel.Count > 1)
{
- Width = 22, Height = 22, Background = Raised, BorderBrush = BorderStrong, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
- Cursor = new Cursor(StandardCursorType.Hand),
- Child = new TextBlock { Text = glyph, FontSize = 11, Foreground = TextSecondary, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center },
- };
- b.PointerPressed += (_, e) => { e.Handled = true; onClick(); };
- return b;
- }
-
- // bars.beats.16ths (4/4), 1-based position.
- private static string Position(double beat)
- {
- int bar = (int)(beat / 4) + 1, be = (int)(beat % 4) + 1, six = (int)Math.Round(beat % 1 * 4) + 1;
- return string.Format(NotaNum.Culture, "{0}. {1}. {2}", bar, be, six);
+ int lo = sel.Min(n => n.Pitch), hi = sel.Max(n => n.Pitch);
+ int vLo = sel.Min(n => Vel(n.Velocity)), vHi = sel.Max(n => Vel(n.Velocity));
+ Row("Notes", sel.Count.ToString(NotaNum.Culture));
+ Row("Range", lo == hi ? PianoRollView.NoteName(lo) : $"{PianoRollView.NoteName(lo)}–{PianoRollView.NoteName(hi)}");
+ Row("Velocity", vLo == vHi ? vLo.ToString(NotaNum.Culture) : $"{vLo}–{vHi}", last: true);
+ }
+
+ void Row(string key, string value, bool last = false)
+ {
+ var v = Mono(value);
+ _selRows.Children.Add(new Border
+ {
+ Padding = new Thickness(10, 0), BorderBrush = NotaPalette.GraphBorder,
+ BorderThickness = new Thickness(0, 0, 0, last ? 0 : 1), Child = KeyValue(key, v),
+ });
+ }
}
- // bars.beats.16ths as a duration (0-based).
- private static string Duration(double beats)
- {
- int bars = (int)(beats / 4), be = (int)(beats % 4), six = (int)Math.Round(beats % 1 * 4);
- return string.Format(NotaNum.Culture, "{0}. {1}. {2}", bars, be, six);
- }
+ private static int Vel(float v) => (int)Math.Round(Math.Clamp(v, 0, 1) * 127);
}
diff --git a/src/managed/Nota.App/MidiToolsView.cs b/src/managed/Nota.App/MidiToolsView.cs
index d371f8ca..5d3551d2 100644
--- a/src/managed/Nota.App/MidiToolsView.cs
+++ b/src/managed/Nota.App/MidiToolsView.cs
@@ -1,11 +1,13 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// The clip-tools rail on the right of the piano roll: a Generate / Transform
-// picker, a parameter list built from the tool's own descriptor (no per-tool
-// panel), and the seed / blend / apply row. Every knob move re-runs the tool and
-// previews the result in the roll — audible, undo-free — so Apply is a decision
-// the user has already heard.
+// The clip-tools panel on the right of the piano roll (nota-design "Nota Clip Editor" 1a):
+// Generate / Transform segments, the tool list (the chosen one on Brass Wash with a 2px
+// brass bar), a parameter list built from the tool's own descriptor (no per-tool panel),
+// the seed, the Replace / Add output, and at the foot the result line, Apply — solid brass
+// only while something is pending — and Revert / Defaults. Every knob move re-runs the
+// tool and previews the result in the roll (brass outlines over the notes) — audible,
+// undo-free — so Apply is a decision the user has already heard.
using System;
using System.Collections.Generic;
@@ -18,37 +20,25 @@ using Avalonia.Layout;
using Avalonia.Media;
using Nota.Application;
using Nota.Application.Midi;
+using static Nota.App.ClipEditorKit;
namespace Nota.App;
public sealed class MidiToolsView : UserControl
{
- private static IBrush Panel => NotaPalette.SurfaceCard;
- private static IBrush Sunken => NotaPalette.BgSunken;
- private static IBrush Raised => NotaPalette.SurfaceRaised;
- private static IBrush BorderDef => NotaPalette.BorderDefault;
- private static IBrush BorderStrong => NotaPalette.BorderStrong;
- private static IBrush Brass => NotaPalette.Accent;
- private static IBrush AccentBright => NotaPalette.AccentBright;
- private static IBrush AccentSubtle => NotaPalette.AccentSubtle;
- private static IBrush TextPrimary => NotaPalette.TextPrimary;
- private static IBrush TextSecondary => NotaPalette.TextSecondary;
- private static IBrush TextTertiary => NotaPalette.TextTertiary;
-
- public const double RailWidth = 236;
+ public const double RailWidth = ToolsW;
private readonly PianoRollView _roll;
private readonly Dictionary<string, MidiToolSettings> _settings = new(StringComparer.Ordinal);
- private readonly StackPanel _toolList = new() { Spacing = 2 };
- private readonly StackPanel _paramList = new() { Spacing = 5 };
- private readonly TextBlock _blurb;
- private readonly TextBlock _scopeText;
- private readonly TextBlock _seedText;
- private readonly TextBlock _resultText;
- private Border _generateTab = null!, _transformTab = null!;
- private Border _replaceChip = null!, _addChip = null!;
- private Border? _applyButton;
+ private readonly StackPanel _toolList = new();
+ private readonly StackPanel _paramList = new() { Spacing = 9 };
+ private readonly TextBlock _paramTitle = new();
+ private readonly TextBlock _scopeText = Meta("");
+ private readonly TextBlock _seedText = Mono("1");
+ private readonly TextBlock _resultText = Mono("", 10, NotaPalette.TextMuted);
+ private readonly Button _applyButton;
+ private Action<int> _setKind = _ => { };
private MidiToolKind _kind = MidiToolKind.Generate;
private MidiTool? _tool;
@@ -64,37 +54,74 @@ public sealed class MidiToolsView : UserControl
{
_roll = roll;
Width = RailWidth;
- Background = Panel;
- BorderBrush = BorderDef;
+ Background = NotaPalette.Panel;
+ BorderBrush = NotaPalette.BorderDefault;
BorderThickness = new Thickness(1, 0, 0, 0);
- _blurb = new TextBlock { FontSize = 9, Foreground = TextTertiary, TextWrapping = TextWrapping.Wrap, MinHeight = 24 };
- _scopeText = new TextBlock { FontSize = 9, Foreground = TextSecondary, TextWrapping = TextWrapping.Wrap };
- _resultText = Mono("—");
- _resultText.Foreground = TextTertiary;
- _seedText = Mono("1");
+ var kinds = Segments(new[] { "Generate", "Transform" }, 0, i =>
+ {
+ var kind = i == 0 ? MidiToolKind.Generate : MidiToolKind.Transform;
+ if (_kind == kind) return;
+ _kind = kind;
+ SelectTool(null);
+ }, out _setKind, fill: true);
- var body = new StackPanel { Spacing = 9, Margin = new Thickness(10) };
- body.Children.Add(KindTabs());
- body.Children.Add(new Border
+ var title = SectionTitle("");
+ _paramTitle = (TextBlock)title.Children[0];
+ var seedBox = Field(new StackPanel
{
- Background = Sunken, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
- Padding = new Thickness(3), MaxHeight = 236,
- Child = new ScrollViewer { Content = _toolList, HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled },
+ Orientation = Orientation.Horizontal, Spacing = 8,
+ Children = { CapsLabel("SEED"), _seedText },
});
- body.Children.Add(_blurb);
- body.Children.Add(Rule());
- body.Children.Add(Section("PARAMETERS", _paramList));
- body.Children.Add(Rule());
- body.Children.Add(SeedRow());
- body.Children.Add(Section("OUTPUT", new StackPanel { Spacing = 5, Children = { BlendRow(), _scopeText, ResultRow() } }));
- body.Children.Add(ActionRow());
-
- Content = new ScrollViewer
+ var reroll = ClipEditorKit.Button("Reroll", () =>
+ {
+ _seed = Random.Shared.Next(1, 9999);
+ _seedText.Text = _seed.ToString(NotaNum.Culture);
+ Preview();
+ });
+ reroll.HorizontalAlignment = HorizontalAlignment.Right;
+ var seedRow = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 6, Margin = new Thickness(0, 2, 0, 0) };
+ seedRow.Children.Add(seedBox);
+ Grid.SetColumn(reroll, 1); seedRow.Children.Add(reroll);
+ var parameters = Section(title, 9, _paramList, seedRow);
+
+ var output = Section(SectionTitle("OUTPUT", _scopeText), 8,
+ Segments(new[] { "Replace", "Add" }, 0, i =>
+ {
+ _blend = i == 0 ? MidiToolBlend.Replace : MidiToolBlend.Add;
+ Preview();
+ }, out _, fill: true));
+
+ _applyButton = new Button { Content = "Apply", Height = 30, FontSize = NotaType.Name, FontWeight = FontWeight.SemiBold, HorizontalAlignment = HorizontalAlignment.Stretch, Classes = { "primary" } };
+ _applyButton.Click += (_, _) => Apply();
+ _resultText.HorizontalAlignment = HorizontalAlignment.Center;
+ var foot = new StackPanel
{
- Content = body,
- HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
- VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
+ Spacing = 6,
+ Children =
+ {
+ _resultText, _applyButton,
+ Pair(ClipEditorKit.Button("Revert", Revert), ClipEditorKit.Button("Defaults", ResetTool)),
+ },
+ };
+ DockPanel.SetDock(foot, Dock.Bottom);
+ foot.Margin = new Thickness(0, 10, 8, 0);
+
+ // The scroll content keeps 8px clear on the right for the overlay scrollbar.
+ var top = new StackPanel { Spacing = 10, Margin = new Thickness(0, 0, 8, 0), Children = { kinds, _toolList, Rule(), parameters, Rule(), output } };
+ Content = new DockPanel
+ {
+ Margin = new Thickness(14, 12, 6, 12),
+ Children =
+ {
+ foot,
+ new ScrollViewer
+ {
+ Content = top,
+ HorizontalScrollBarVisibility = ScrollBarVisibility.Disabled,
+ VerticalScrollBarVisibility = ScrollBarVisibility.Auto,
+ },
+ },
};
RebuildToolList();
@@ -105,6 +132,7 @@ public sealed class MidiToolsView : UserControl
// back from them.
DetachedFromVisualTree += (_, _) => _roll.CancelPreview();
Resync();
+ PaintResult(null);
}
/// <summary>Called by the clip editor when the rail is shown or hidden. Hiding drops any
@@ -112,7 +140,7 @@ public sealed class MidiToolsView : UserControl
public void SetActive(bool active)
{
if (active) { Resync(); Preview(); }
- else _roll.CancelPreview();
+ else { _roll.CancelPreview(); PaintResult(null); }
}
// --- state ------------------------------------------------------------
@@ -123,6 +151,7 @@ public sealed class MidiToolsView : UserControl
// source and the tool would compound on its own output.
if (_suppressResync || _roll.Previewing) return;
Resync();
+ PaintApply();
}
/// <summary>Re-reads the clip and the selection as the working set for the next run.</summary>
@@ -131,8 +160,8 @@ public sealed class MidiToolsView : UserControl
_source = new List<NotaNote>(_roll.SourceNotes);
_scope = new HashSet<int>(_roll.SelectionIndices.Where(i => i >= 0 && i < _source.Count));
_scopeText.Text = _scope.Count > 0
- ? $"Scope · {_scope.Count} selected note{(_scope.Count == 1 ? "" : "s")}"
- : $"Scope · whole clip ({_source.Count} note{(_source.Count == 1 ? "" : "s")})";
+ ? $"{_scope.Count} selected"
+ : $"clip · {_source.Count}";
}
private MidiToolContext Context() => new()
@@ -153,15 +182,12 @@ public sealed class MidiToolsView : UserControl
private void Preview()
{
- if (_tool is null) { _roll.CancelPreview(); return; }
+ if (_tool is null) { _roll.CancelPreview(); PaintResult(null); return; }
var result = MidiToolRunner.Apply(_tool, _source, _scope, SettingsFor(_tool), Context(), _blend);
_suppressResync = true;
_roll.ShowPreview(result);
_suppressResync = false;
- int delta = result.Count - _source.Count;
- _resultText.Text = $"{result.Count} notes ({delta:+0;−0;\u00b10})";
- _resultText.Foreground = delta == 0 ? TextTertiary : AccentBright;
- PaintApply();
+ PaintResult(result.Count);
}
private void Apply()
@@ -173,9 +199,9 @@ public sealed class MidiToolsView : UserControl
Resync();
// Deliberately no re-preview: the applied result is the new source, so running the
// tool again here would show it applied twice before the user asked for anything.
- // The next knob move (or New seed) arms a fresh preview from the new source.
+ // The next knob move (or Reroll) arms a fresh preview from the new source.
_resultText.Text = $"{_source.Count} notes · applied";
- _resultText.Foreground = TextSecondary;
+ _resultText.Foreground = NotaPalette.TextMuted;
PaintApply();
}
@@ -183,26 +209,43 @@ public sealed class MidiToolsView : UserControl
{
_roll.CancelPreview();
Resync();
- _resultText.Text = "—";
- _resultText.Foreground = TextTertiary;
- PaintApply();
+ PaintResult(null);
+ }
+
+ private void ResetTool()
+ {
+ _seed = 1;
+ _seedText.Text = "1";
+ if (_tool is null) return;
+ SettingsFor(_tool).Reset();
+ RebuildParams();
+ Preview();
}
- /// <summary>Apply reads as available only while something is actually pending.</summary>
- private void PaintApply()
+ /// <summary>The line over Apply: what the pending result does, or what to do first.</summary>
+ private void PaintResult(int? resultCount)
{
- if (_applyButton is null) return;
- bool pending = _roll.Previewing;
- Inactive.Set(_applyButton, !pending, interactive: true);
- _applyButton.Cursor = new Cursor(pending ? StandardCursorType.Hand : StandardCursorType.Arrow);
+ if (resultCount is not int count)
+ _resultText.Text = _tool is null ? "Pick a tool" : "—";
+ else
+ {
+ int delta = count - _source.Count;
+ _resultText.Text = _blend == MidiToolBlend.Add
+ ? $"{delta:+0;−0;\u00b10} notes"
+ : $"{count} notes, was {_source.Count}";
+ }
+ _resultText.Foreground = NotaPalette.TextMuted;
+ PaintApply();
}
+ /// <summary>Apply is solid brass only while something is actually pending.</summary>
+ private void PaintApply() => _applyButton.IsEnabled = _roll.Previewing && _tool is not null;
+
private void SelectTool(MidiTool? tool)
{
_roll.CancelPreview();
Resync();
_tool = tool;
- _blurb.Text = tool?.Blurb ?? "";
RebuildToolList();
RebuildParams();
Preview();
@@ -210,80 +253,62 @@ public sealed class MidiToolsView : UserControl
// --- tool list --------------------------------------------------------
- private Control KindTabs()
- {
- _generateTab = KindTab("Generate", MidiToolKind.Generate);
- _transformTab = KindTab("Transform", MidiToolKind.Transform);
- var g = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 6 };
- g.Children.Add(_generateTab);
- Grid.SetColumn(_transformTab, 1);
- g.Children.Add(_transformTab);
- return g;
- }
-
- private Border KindTab(string label, MidiToolKind kind)
- {
- var t = new TextBlock { Text = label, FontSize = 10, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
- var b = new Border
- {
- Height = 24, CornerRadius = NotaRadius.Tile, BorderThickness = new Thickness(1),
- Cursor = new Cursor(StandardCursorType.Hand), Child = t, Tag = kind,
- };
- b.PointerPressed += (_, e) =>
- {
- e.Handled = true;
- if (_kind == kind) return;
- _kind = kind;
- PaintKindTabs();
- SelectTool(null);
- };
- return b;
- }
-
- private void PaintKindTabs()
- {
- foreach (var b in new[] { _generateTab, _transformTab })
- {
- bool active = (MidiToolKind)b.Tag! == _kind;
- b.Background = active ? AccentSubtle : Raised;
- b.BorderBrush = active ? Brass : BorderStrong;
- ((TextBlock)b.Child!).Foreground = active ? AccentBright : TextSecondary;
- }
- }
-
private void RebuildToolList()
{
- PaintKindTabs();
+ _setKind(_kind == MidiToolKind.Generate ? 0 : 1);
_toolList.Children.Clear();
foreach (var tool in MidiToolCatalog.All.Where(t => t.Kind == _kind))
{
bool active = _tool?.Id == tool.Id;
- var text = new TextBlock
+ var name = new TextBlock
{
- Text = tool.Name, FontSize = 11, VerticalAlignment = VerticalAlignment.Center,
- Foreground = active ? AccentBright : TextPrimary, Margin = new Thickness(8, 0, 0, 0),
+ Text = tool.Name, FontSize = NotaType.Name, FontWeight = FontWeight.Medium, VerticalAlignment = VerticalAlignment.Center,
+ Foreground = active ? NotaPalette.TextPrimary : NotaPalette.TextSecondary,
};
var row = new Border
{
- Height = 24, CornerRadius = NotaRadius.Control,
- Background = active ? AccentSubtle : Brushes.Transparent,
- BorderBrush = active ? Brass : Brushes.Transparent, BorderThickness = new Thickness(1),
- Cursor = new Cursor(StandardCursorType.Hand), Child = text,
+ Height = 26, CornerRadius = NotaRadius.Badge, Padding = new Thickness(10, 0),
+ Background = active ? NotaPalette.AccentSubtle : Brushes.Transparent,
+ Cursor = new Cursor(StandardCursorType.Hand),
+ Child = new Grid
+ {
+ Children =
+ {
+ new Border
+ {
+ Width = 2, Margin = new Thickness(-10, 4, 0, 4), HorizontalAlignment = HorizontalAlignment.Left,
+ Background = active ? NotaPalette.Accent : Brushes.Transparent,
+ },
+ name,
+ },
+ },
};
+ if (!string.IsNullOrEmpty(tool.Blurb)) ToolTip.SetTip(row, tool.Blurb);
+ if (!active)
+ {
+ row.PointerEntered += (_, _) => row.Background = NotaPalette.SurfaceRaised;
+ row.PointerExited += (_, _) => row.Background = Brushes.Transparent;
+ }
var captured = tool;
- row.PointerPressed += (_, e) => { e.Handled = true; SelectTool(captured); };
+ row.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(row).Properties.IsLeftButtonPressed) return;
+ e.Handled = true;
+ SelectTool(captured);
+ };
_toolList.Children.Add(row);
}
}
- // --- parameter rail ---------------------------------------------------
+ // --- parameter list ---------------------------------------------------
private void RebuildParams()
{
_paramList.Children.Clear();
+ _paramTitle.Text = _tool is null ? "PARAMETERS" : _tool.Name.ToUpperInvariant();
if (_tool is null)
{
- _paramList.Children.Add(new TextBlock { Text = "Pick a tool.", FontSize = 9, Foreground = TextTertiary });
+ _paramList.Children.Add(new TextBlock { Text = "Pick a tool to see its parameters", FontSize = NotaType.Body, Foreground = NotaPalette.TextTertiary });
return;
}
var settings = SettingsFor(_tool);
@@ -292,240 +317,60 @@ public sealed class MidiToolsView : UserControl
private Control ParamRow(MidiToolParam p, MidiToolSettings settings)
{
- var value = Mono(p.Display(settings[p.Id]));
- value.Foreground = TextSecondary;
- value.HorizontalAlignment = HorizontalAlignment.Right;
- value.Margin = new Thickness(0);
-
- Control control;
switch (p.Kind)
{
case MidiParamKind.Choice:
{
- value.Text = p.Display(settings[p.Id]) + " \u25be";
- var chip = Chip(value);
- chip.PointerPressed += (_, e) =>
+ var value = Mono(p.Display(settings[p.Id]));
+ var drop = Dropdown(value, a => ShowMenu(a, p.Choices ?? Array.Empty<string>(), (int)Math.Round(settings[p.Id]), i =>
{
- e.Handled = true;
- var flyout = new MenuFlyout();
- for (int i = 0; i < (p.Choices?.Length ?? 0); i++)
- {
- int idx = i;
- var item = new MenuItem { Header = p.Choices![i] };
- if (Math.Abs(settings[p.Id] - i) < 0.5) item.Icon = new TextBlock { Text = "·", Foreground = AccentBright };
- item.Click += (_, _) =>
- {
- settings.Set(p.Id, idx);
- value.Text = p.Display(settings[p.Id]) + " \u25be";
- Preview();
- };
- flyout.Items.Add(item);
- }
- flyout.ShowAt(chip);
- };
- // The chip already carries the read-out, so the row is label + chip.
- return TwoColumn(p.Name, chip);
+ settings.Set(p.Id, i);
+ value.Text = p.Display(settings[p.Id]);
+ Preview();
+ }));
+ return Labelled(p.Name, drop);
}
case MidiParamKind.Toggle:
{
- var chip = Chip(value);
- void Paint()
- {
- bool on = settings.Flag(p.Id);
- chip.Background = on ? AccentSubtle : Raised;
- chip.BorderBrush = on ? Brass : BorderStrong;
- value.Foreground = on ? AccentBright : TextSecondary;
- value.Text = p.Display(settings[p.Id]);
- }
- Paint();
- chip.PointerPressed += (_, e) =>
+ return SwitchRow(p.Name, () => settings.Flag(p.Id), () =>
{
- e.Handled = true;
settings.Set(p.Id, settings.Flag(p.Id) ? 0 : 1);
- Paint();
Preview();
- };
- return TwoColumn(p.Name, chip);
+ }, out _, height: 20);
}
default:
{
double span = Math.Max(1e-9, p.Max - p.Min);
- var fader = new MiniFader((settings[p.Id] - p.Min) / span, 1.0)
- {
- Accent = true,
- Default = (p.Default - p.Min) / span,
- VerticalAlignment = VerticalAlignment.Center,
- };
- fader.ValueChanged += v =>
- {
- double raw = p.Min + v * span;
- if (p.Kind is MidiParamKind.Int or MidiParamKind.Note) raw = Math.Round(raw);
- if (Math.Abs(raw - settings[p.Id]) < 1e-9) return;
- settings.Set(p.Id, raw);
- value.Text = p.Display(settings[p.Id]);
- Preview();
- };
- control = fader;
- break;
+ return SliderRow(p.Name.ToUpperInvariant(), 62,
+ () => (settings[p.Id] - p.Min) / span,
+ v =>
+ {
+ double raw = p.Min + v * span;
+ if (p.Kind is MidiParamKind.Int or MidiParamKind.Note) raw = Math.Round(raw);
+ if (Math.Abs(raw - settings[p.Id]) < 1e-9) return;
+ settings.Set(p.Id, raw);
+ Preview();
+ },
+ () => p.Display(settings[p.Id]), out _,
+ reset: () => { settings.Set(p.Id, p.Default); Preview(); });
}
}
-
- var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("72,*,50"), ColumnSpacing = 6, Height = 16 };
- grid.Children.Add(new TextBlock { Text = p.Name, FontSize = 9, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center });
- Grid.SetColumn(control, 1); grid.Children.Add(control);
- Grid.SetColumn(value, 2); value.VerticalAlignment = VerticalAlignment.Center; grid.Children.Add(value);
- return grid;
}
- private static Control TwoColumn(string label, Control control)
+ // A caps label in the slider-label column, then a control filling the rest.
+ private static Control Labelled(string label, Control control)
{
- var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("72,*"), ColumnSpacing = 6 };
- grid.Children.Add(new TextBlock { Text = label, FontSize = 9, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center });
+ var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("62,*"), ColumnSpacing = 10 };
+ grid.Children.Add(CapsLabel(label.ToUpperInvariant()));
Grid.SetColumn(control, 1); grid.Children.Add(control);
return grid;
}
- // --- seed / blend / actions -------------------------------------------
-
- private Control SeedRow()
- {
- var box = FieldBox(22);
- _seedText.Text = _seed.ToString();
- box.Child = _seedText;
-
- var reroll = TextChip("New seed");
- reroll.PointerPressed += (_, e) =>
- {
- e.Handled = true;
- _seed = Random.Shared.Next(1, 9999);
- _seedText.Text = _seed.ToString();
- Preview();
- };
-
- var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 6 };
- grid.Children.Add(box);
- Grid.SetColumn(reroll, 1); grid.Children.Add(reroll);
- return Section("SEED", grid);
- }
-
- private Control BlendRow()
- {
- _replaceChip = TextChip("Replace");
- _addChip = TextChip("Add");
- void Paint()
- {
- foreach (var (chip, blend) in new[] { (_replaceChip, MidiToolBlend.Replace), (_addChip, MidiToolBlend.Add) })
- {
- bool active = _blend == blend;
- chip.Background = active ? AccentSubtle : Raised;
- chip.BorderBrush = active ? Brass : BorderStrong;
- ((TextBlock)chip.Child!).Foreground = active ? AccentBright : TextSecondary;
- }
- }
- _replaceChip.PointerPressed += (_, e) => { e.Handled = true; _blend = MidiToolBlend.Replace; Paint(); Preview(); };
- _addChip.PointerPressed += (_, e) => { e.Handled = true; _blend = MidiToolBlend.Add; Paint(); Preview(); };
- Paint();
-
- var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 6 };
- grid.Children.Add(_replaceChip);
- Grid.SetColumn(_addChip, 1); grid.Children.Add(_addChip);
- return grid;
- }
-
- private Control ResultRow()
- {
- var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*"), ColumnSpacing = 6 };
- grid.Children.Add(new TextBlock { Text = "Result", FontSize = 9, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center });
- _resultText.HorizontalAlignment = HorizontalAlignment.Right;
- _resultText.Margin = new Thickness(0);
- Grid.SetColumn(_resultText, 1); grid.Children.Add(_resultText);
- return grid;
- }
-
- private Control ActionRow()
- {
- var apply = new Border
- {
- Height = 26, Background = AccentSubtle, BorderBrush = Brass, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
- Cursor = new Cursor(StandardCursorType.Hand),
- Child = new TextBlock { Text = "Apply", FontSize = 11, Foreground = AccentBright, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center },
- };
- apply.PointerPressed += (_, e) => { e.Handled = true; Apply(); };
- _applyButton = apply;
- PaintApply();
-
- var revert = TextChip("Revert");
- revert.Height = 26;
- revert.PointerPressed += (_, e) => { e.Handled = true; Revert(); };
-
- var reset = TextChip("Defaults");
- reset.Height = 26;
- reset.PointerPressed += (_, e) =>
- {
- e.Handled = true;
- if (_tool is null) return;
- SettingsFor(_tool).Reset();
- RebuildParams();
- Preview();
- };
-
- var top = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 6 };
- top.Children.Add(revert);
- Grid.SetColumn(reset, 1); top.Children.Add(reset);
-
- return new StackPanel
- {
- Spacing = 6, Margin = new Thickness(0, 2, 0, 6),
- Children =
- {
- apply, top,
- new TextBlock
- {
- Text = "Every change is previewed in the roll — Apply keeps it as one undo step.",
- FontSize = 9, Foreground = TextTertiary, TextWrapping = TextWrapping.Wrap,
- },
- },
- };
- }
-
- // --- helpers ----------------------------------------------------------
-
- private static TextBlock Mono(string text)
- {
- var t = new TextBlock { Text = text, FontSize = 10, Foreground = TextPrimary, VerticalAlignment = VerticalAlignment.Center, Margin = new Thickness(7, 0, 0, 0) };
- t.BindResource(FontFamilyProperty, "Font.Mono");
- return t;
- }
-
- private static Control Section(string title, Control content) => new StackPanel
- {
- Spacing = 5,
- Children =
- {
- new TextBlock { Text = title, FontSize = 9, FontWeight = FontWeight.Bold, Foreground = TextTertiary },
- content,
- },
- };
-
- private static Control Rule() => new Border { Height = 1, Background = BorderDef };
-
- private static Border FieldBox(double h) => new()
- {
- Height = h, Background = Sunken, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
- };
-
- private static Border Chip(Control child) => new()
- {
- Height = 20, Background = Raised, BorderBrush = BorderStrong, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
- Cursor = new Cursor(StandardCursorType.Hand), Child = child, Padding = new Thickness(0, 0, 6, 0),
- };
-
- private static Border TextChip(string text) => new()
+ private static TextBlock CapsLabel(string text) => new()
{
- Height = 22, Background = Raised, BorderBrush = BorderStrong, BorderThickness = new Thickness(1), CornerRadius = NotaRadius.Tile,
- Cursor = new Cursor(StandardCursorType.Hand), Padding = new Thickness(8, 0),
- Child = new TextBlock { Text = text, FontSize = 10, Foreground = TextSecondary, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center },
+ Text = text, FontSize = 9, FontWeight = FontWeight.Bold, LetterSpacing = 0.9, Foreground = NotaPalette.TextTertiary,
+ VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis,
};
}
diff --git a/src/managed/Nota.App/PianoRollView.cs b/src/managed/Nota.App/PianoRollView.cs
index 9abd4533..dfc81d10 100644
--- a/src/managed/Nota.App/PianoRollView.cs
+++ b/src/managed/Nota.App/PianoRollView.cs
@@ -54,7 +54,7 @@ public sealed class PianoRollView : UserControl
public void SetClipIdentity(int a, int b) => _clipKey = (a, b);
private const int MinPitch = 21, MaxPitch = 108; // A0..C8 (88 keys)
- private const double KeysW = 56, RowH = 14, RulerH = 20, VelH = 72;
+ private const double KeysW = 48, RowH = 12, RulerH = 24, VelH = 72;
private readonly List<NotaNote> _notes = new();
private double _lengthBeats = 4;
@@ -113,6 +113,8 @@ public sealed class PianoRollView : UserControl
private readonly KeysColumn _keys;
private readonly NoteGrid _gridControl;
private readonly VelocityLane _vel;
+ private readonly Border _velHost;
+ private readonly Border _overlayHost = new() { IsVisible = false, ClipToBounds = true };
private readonly ScrollViewer _bodyScroll;
private readonly ScrollBar _hScroll;
@@ -166,12 +168,27 @@ public sealed class PianoRollView : UserControl
_hScroll.IsVisible = _hScroll.Maximum > 1e-6;
}
+ // The keyboard is dark (nota-design "Nota Clip Editor"): white keys sit one step above
+ // the panel, black keys below the well, and the lanes echo them — so the notes, not the
+ // keys, are the brightest thing in the editor.
private static readonly IBrush Bg = NotaPalette.BgSunken;
- private static readonly IBrush KeysBg = NotaPalette.BgSunken;
- private static readonly IBrush VelBg = NotaPalette.GridRow;
+ private static readonly IBrush KeysBg = NotaPalette.Panel;
+ private static readonly IBrush VelBg = NotaPalette.BgSunken;
private static readonly IBrush KeyWhite = NotaPalette.KeyWhite;
private static readonly IBrush KeyBlack = NotaPalette.KeyBlack;
- private static readonly IBrush RowBlackTint = new SolidColorBrush(Color.FromArgb(0x2E, 0x00, 0x00, 0x00));
+ private static readonly IBrush LaneWhite = NotaPalette.CanvasBg;
+ private static readonly IBrush LaneBlack = NotaPalette.KeyBlack;
+ private static readonly IBrush LoopStrip = NotaPalette.Accent;
+ private static readonly IBrush NoteSel = NotaPalette.Accent;
+ private static readonly IPen NoteSelEdge = new Pen(NotaPalette.AccentBright, 1);
+ private static readonly IBrush GhostFill = NotaPalette.AccentSubtle;
+ private static readonly IPen GhostEdge = new Pen(NotaPalette.AccentBright, 1);
+ private static readonly IBrush GhostStem = NotaPalette.AccentDim;
+ private static readonly IBrush RulerBarText = NotaPalette.TextStrong;
+ // Past the clip's end (seen once you zoom out): a dark wash and an Ink 2 end line, so the
+ // clip's edge reads at a glance.
+ private static readonly IBrush OutsideClip = NotaPalette.Wash(NotaPalette.SurfaceAbyss, 0xC8);
+ private static readonly IPen ClipEndPen = new Pen(NotaPalette.TextStrong, 1);
// Scale overlay: out-of-scale rows/keys get a translucent dark wash (they read
// dimmed / semi-transparent), in-scale rows a faint accent, the root a stronger one.
private static readonly IBrush OutScaleWash = NotaPalette.Wash(NotaPalette.BgSunken, 0xB4);
@@ -180,19 +197,23 @@ public sealed class PianoRollView : UserControl
private static readonly IPen PlayheadPen = new Pen(NotaPalette.Accent, 1); // almanac playhead: 1px brass
private static readonly IBrush KeyHover = NotaPalette.Wash(NotaPalette.AccentBright, 0x66);
// Played-key highlight (currently-pressed keyboard / MIDI note): a solid key tint + a faint row wash.
- private static readonly IBrush HeldKeyFill = NotaPalette.AccentBright;
+ private static readonly IBrush HeldKeyFill = NotaPalette.Accent;
private static readonly IBrush HeldRowTint = NotaPalette.Wash(NotaPalette.AccentBright, 0x30);
private static readonly IPen KeyLine = new Pen(NotaPalette.GraphBorder, 1);
- private static readonly IPen RowLine = new Pen(NotaPalette.GridRow, 1);
- private static readonly IPen BeatPen = new Pen(NotaPalette.GridBeat, 1);
- private static readonly IPen BarPen = new Pen(NotaPalette.GridBar, 1);
+ private static readonly IPen KeyOctaveLine = new Pen(NotaPalette.BorderStrong, 1);
+ private static readonly IPen RowLine = new Pen(NotaPalette.GridSubBeat, 1);
+ private static readonly IPen RowOctaveLine = new Pen(NotaPalette.BorderDefault, 1);
+ private static readonly IPen BeatPen = new Pen(NotaPalette.GraphBorder, 1);
+ private static readonly IPen BarPen = new Pen(NotaPalette.BorderStrong, 1);
private static readonly IPen SubBeatPen = new Pen(NotaPalette.GridSubBeat, 1); // sub-beat grid (finer than a beat)
private static readonly IBrush AccentBright = NotaPalette.AccentBright;
private static readonly IBrush EdgeHighlight = NotaPalette.AccentPale;
private static readonly IBrush MarqueeFill = NotaPalette.Wash(NotaPalette.AccentBright, 0x28);
private static readonly IPen MarqueePen = new Pen(NotaPalette.Wash(NotaPalette.AccentBright, 0xA0), 1);
private static readonly IBrush LabelText = NotaPalette.TextTertiary;
- private static readonly IBrush KeyLabel = NotaPalette.BgSunken;
+ private static readonly IBrush KeyLabel = NotaPalette.TextMuted;
+ private static readonly IBrush KeyLabelHot = NotaPalette.TextPrimary;
+ private static readonly IBrush KeyLabelOnAccent = NotaPalette.TextOnAccent;
private static readonly IBrush Divider = NotaPalette.BorderDefault;
private static readonly Typeface Mono = NotaFonts.Mono;
@@ -206,9 +227,10 @@ public sealed class PianoRollView : UserControl
_keys = new KeysColumn(this) { Height = RangeH };
_gridControl = new NoteGrid(this) { Height = RangeH, ClipToBounds = true };
_vel = new VelocityLane(this) { ClipToBounds = true };
+ _velHost = new Border { BorderBrush = Divider, BorderThickness = new Thickness(0, 1, 0, 0), Child = _vel };
// Body: keys pinned left, grid fills; both scroll vertically together.
- var body = new Grid { ColumnDefinitions = new ColumnDefinitions("56,*") };
+ var body = new Grid { ColumnDefinitions = new ColumnDefinitions($"{KeysW},*") };
body.Children.Add(_keys);
Avalonia.Controls.Grid.SetColumn(_gridControl, 1);
body.Children.Add(_gridControl);
@@ -220,22 +242,26 @@ public sealed class PianoRollView : UserControl
};
// Ruler row (corner + ruler) pinned above; velocity row pinned below.
- var rulerRow = new Grid { ColumnDefinitions = new ColumnDefinitions("56,*"), Height = RulerH };
+ var rulerRow = new Grid { ColumnDefinitions = new ColumnDefinitions($"{KeysW},*"), Height = RulerH };
var corner = new Border { Background = KeysBg, BorderBrush = Divider, BorderThickness = new Thickness(0, 0, 1, 1) };
rulerRow.Children.Add(corner);
Avalonia.Controls.Grid.SetColumn(_ruler, 1);
rulerRow.Children.Add(_ruler);
- var velRow = new Grid { ColumnDefinitions = new ColumnDefinitions("56,*"), Height = VelH };
- var velLabelHost = new Border { Background = KeysBg, BorderBrush = Divider, BorderThickness = new Thickness(0, 1, 1, 0) };
- velLabelHost.Child = new TextBlock { Text = "VEL", FontSize = 8, Foreground = LabelText, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center };
+ var velRow = new Grid { ColumnDefinitions = new ColumnDefinitions($"{KeysW},*"), Height = VelH };
+ var velLabelHost = new Border { Background = KeysBg, BorderBrush = Divider, BorderThickness = new Thickness(0, 1, 1, 0), Padding = new Thickness(0, 8, 0, 0) };
+ velLabelHost.Child = new TextBlock
+ {
+ Text = "VEL", FontSize = 9, FontWeight = FontWeight.Bold, LetterSpacing = 0.9, Foreground = LabelText,
+ HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Top,
+ };
velRow.Children.Add(velLabelHost);
- Avalonia.Controls.Grid.SetColumn(_vel, 1);
- velRow.Children.Add(_vel);
+ Avalonia.Controls.Grid.SetColumn(_velHost, 1);
+ velRow.Children.Add(_velHost);
// Horizontal zoom scrollbar pinned below the velocity lane, aligned under the
// grid (56px keys gutter on the left).
- var scrollRow = new Grid { ColumnDefinitions = new ColumnDefinitions("56,*") };
+ var scrollRow = new Grid { ColumnDefinitions = new ColumnDefinitions($"{KeysW},*") };
_hScroll = new ScrollBar { Orientation = Orientation.Horizontal, Height = 10, IsVisible = false, Minimum = 0 };
_hScroll.Scroll += (_, _) => SetScrollBeats(_hScroll.Value);
Avalonia.Controls.Grid.SetColumn(_hScroll, 1);
@@ -245,6 +271,10 @@ public sealed class PianoRollView : UserControl
root.Children.Add(rulerRow);
Avalonia.Controls.Grid.SetRow(_bodyScroll, 1);
root.Children.Add(_bodyScroll);
+ // Overlay slot over the note grid (the clip editor's Envelopes mode draws there).
+ Avalonia.Controls.Grid.SetRow(_overlayHost, 1);
+ _overlayHost.Margin = new Thickness(KeysW, 0, 0, 0);
+ root.Children.Add(_overlayHost);
Avalonia.Controls.Grid.SetRow(velRow, 2);
root.Children.Add(velRow);
Avalonia.Controls.Grid.SetRow(scrollRow, 3);
@@ -303,6 +333,7 @@ public sealed class PianoRollView : UserControl
public double Grid { get => _grid; set { _grid = Math.Max(1.0 / 32, value); Invalidate(); } }
public void SetTrackColor(ISolidColorBrush b) { _trackBrush = b; Invalidate(); }
+ public ISolidColorBrush TrackBrush => _trackBrush;
public void SetNotes(IEnumerable<NotaNote> notes, double lengthBeats)
{
@@ -382,6 +413,25 @@ public sealed class PianoRollView : UserControl
double cap = Math.Max(0, _lengthBeats - _grid);
var copies = new List<NotaNote>(sel.Count);
foreach (int i in sel) { var n = _notes[i]; n.StartBeat = Math.Min(n.StartBeat + shift, cap); copies.Add(n); }
+ // Like a duplicated clip in the arrangement, the copies overwrite what they land on
+ // instead of stacking: a note of the same pitch that starts under a copy goes, and
+ // one that runs into a copy is cut where the copy starts.
+ var kept = new List<NotaNote>(_notes.Count);
+ foreach (var n in _notes)
+ {
+ var m = n;
+ bool drop = false;
+ foreach (var c in copies)
+ {
+ if (c.Pitch != m.Pitch) continue;
+ double cs = c.StartBeat, ce = c.StartBeat + c.LengthBeats;
+ if (m.StartBeat >= cs - 1e-9 && m.StartBeat < ce - 1e-9) { drop = true; break; }
+ if (m.StartBeat < cs && m.StartBeat + m.LengthBeats > cs + 1e-9) m.LengthBeats = cs - m.StartBeat;
+ }
+ if (!drop) kept.Add(m);
+ }
+ _notes.Clear();
+ _notes.AddRange(kept);
int baseIdx = _notes.Count;
_notes.AddRange(copies);
_selection.Clear();
@@ -413,6 +463,12 @@ public sealed class PianoRollView : UserControl
public bool Previewing => _previewBackup is not null;
+ // Indices into _notes that a running preview added; empty when nothing is previewing.
+ private readonly HashSet<int> _ghosts = new();
+ private bool IsGhost(int i) => _previewBackup is not null && _ghosts.Contains(i);
+ private static (int, long, long, int) NoteKey(NotaNote n)
+ => (n.Pitch, (long)Math.Round(n.StartBeat * 1e4), (long)Math.Round(n.LengthBeats * 1e4), (int)Math.Round(n.Velocity * 127));
+
/// <summary>The clip's notes ignoring any preview in flight — what a tool reads.</summary>
public IReadOnlyList<NotaNote> SourceNotes => _previewBackup ?? _notes;
@@ -426,6 +482,10 @@ public sealed class PianoRollView : UserControl
_previewBackup ??= new List<NotaNote>(_notes);
_notes.Clear();
_notes.AddRange(notes);
+ // What the tool added (not in the clip before) draws as a brass outline over the notes.
+ var before = new HashSet<(int, long, long, int)>(_previewBackup.Select(NoteKey));
+ _ghosts.Clear();
+ for (int i = 0; i < _notes.Count; i++) if (!before.Contains(NoteKey(_notes[i]))) _ghosts.Add(i);
_selection.Clear();
EnsureNotesVisible();
Invalidate();
@@ -611,8 +671,47 @@ public sealed class PianoRollView : UserControl
else if (y + RowH > top + viewH - margin) sv.Offset = new Vector(sv.Offset.X, y + RowH - viewH + margin);
}
+ /// <summary>Puts a control over the note grid (below the ruler, right of the keys) —
+ /// or removes it with null. It is repainted with the roll, so it can map beats through
+ /// <see cref="BeatToX"/> and follow zoom and scroll.</summary>
+ public void SetOverlay(Control? overlay)
+ {
+ _overlayHost.Child = overlay;
+ _overlayHost.IsVisible = overlay is not null;
+ }
+
+ /// <summary>The selected notes, in clip order.</summary>
+ public IReadOnlyList<NotaNote> SelectedNotes()
+ => _selection.Where(i => i >= 0 && i < _notes.Count).OrderBy(i => i).Select(i => _notes[i]).ToList();
+
+ /// <summary>The ⌘/Ctrl-wheel zoom and Shift/horizontal-wheel scroll of the note grid, for an
+ /// overlay that sits on top of it.</summary>
+ internal void RouteWheel(PointerWheelEventArgs e, double x)
+ {
+ var mods = e.KeyModifiers;
+ if ((mods & (KeyModifiers.Control | KeyModifiers.Meta)) != 0)
+ ZoomAt(WheelInput.ZoomFactor(e.Delta.Y, 1.2), XToBeat(x));
+ else if ((mods & KeyModifiers.Shift) != 0)
+ ScrollByBeats(-WheelInput.Pixels(e.Delta.Y) / Math.Max(1e-6, PixelsPerBeat));
+ else if (Math.Abs(e.Delta.X) > Math.Abs(e.Delta.Y))
+ ScrollByBeats(-WheelInput.Pixels(e.Delta.X) / Math.Max(1e-6, PixelsPerBeat));
+ else return;
+ e.Handled = true;
+ }
+
+ /// <summary>Darkens everything right of the clip's end and marks the edge with a line.</summary>
+ private void DrawOutsideClip(DrawingContext ctx, double w, double h)
+ {
+ double x = BeatToX(_lengthBeats);
+ if (x >= w) return;
+ x = Math.Max(0, x);
+ ctx.FillRectangle(OutsideClip, new Rect(x, 0, w - x, h));
+ ctx.DrawLine(ClipEndPen, new Point(x + 0.5, 0), new Point(x + 0.5, h));
+ }
+
private void Invalidate()
{
+ _overlayHost.Child?.InvalidateVisual();
_ruler.InvalidateVisual();
_keys.InvalidateVisual();
_gridControl.InvalidateVisual();
@@ -620,7 +719,7 @@ public sealed class PianoRollView : UserControl
}
private static bool IsBlack(int pitch) { int n = ((pitch % 12) + 12) % 12; return n is 1 or 3 or 6 or 8 or 10; }
- private static string NoteName(int pitch)
+ internal static string NoteName(int pitch)
{
string[] names = { "C", "C#", "D", "D#", "E", "F", "F#", "G", "G#", "A", "A#", "B" };
return names[((pitch % 12) + 12) % 12] + (pitch / 12 - 1);
@@ -673,6 +772,8 @@ public sealed class PianoRollView : UserControl
{
private readonly PianoRollView _o;
public RulerLane(PianoRollView o) { _o = o; }
+ // Beats only: a bar reads "3" in Ink 2, a beat "3.2" in Ink 5, set on the baseline in
+ // mono 9 just right of its tick. The loop is a 3px brass strip along the top.
public override void Render(DrawingContext ctx)
{
double w = Bounds.Width, h = Bounds.Height;
@@ -681,25 +782,26 @@ public sealed class PianoRollView : UserControl
_o.EnsurePpb(w);
double ppb = _o.PixelsPerBeat;
double viewEnd = Math.Min(_o._lengthBeats, _o.ScrollBeats + w / Math.Max(1e-6, ppb));
- // Grid lines subdivide with zoom; labels use a coarser step with room for text.
- double step = _o.GridStepBeats();
+ double loopEnd = Math.Min(w, _o.BeatToX(_o._lengthBeats));
+ double loopStart = Math.Max(0, _o.BeatToX(0));
+ if (loopEnd > loopStart) ctx.FillRectangle(LoopStrip, new Rect(loopStart, 0, loopEnd - loopStart, 3));
+ // Label every beat while there is room for "12.4", else bars only.
+ double step = ppb >= 30 ? 1 : 4;
double startB = Math.Max(0, Math.Floor(_o.ScrollBeats / step) * step);
for (int k = 0; ; k++)
{
double b = startB + k * step;
if (b > viewEnd + 1e-9) break;
double x = _o.BeatToX(b);
- ctx.DrawLine(_o.GridPen(b), new Point(x, 0), new Point(x, h));
- }
- double lstep = _o.LabelStepBeats();
- double startL = Math.Max(0, Math.Ceiling(_o.ScrollBeats / lstep - 1e-9) * lstep);
- for (int k = 0; ; k++)
- {
- double b = startL + k * lstep;
- if (b > viewEnd + 1e-9) break;
- var ft = new FormattedText(GridLabel(b), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, 9, LabelText);
- ctx.DrawText(ft, new Point(_o.BeatToX(b) + 3, 4));
+ bool bar = Math.Abs(b / 4 - Math.Round(b / 4)) < 1e-6;
+ ctx.DrawLine(bar ? BarPen : BeatPen, new Point(x + 0.5, 0), new Point(x + 0.5, h));
+ if (b >= _o._lengthBeats - 1e-9) continue;
+ int barNo = (int)Math.Floor(b / 4) + 1, beatNo = (int)Math.Round(b - Math.Floor(b / 4) * 4) + 1;
+ string label = bar ? barNo.ToString(NotaNum.Culture) : $"{barNo}.{beatNo}";
+ var ft = new FormattedText(label, NotaNum.Culture, FlowDirection.LeftToRight, Mono, 9, bar ? RulerBarText : LabelText);
+ ctx.DrawText(ft, new Point(x + 4, h - 5 - ft.Height));
}
+ _o.DrawOutsideClip(ctx, w, h);
if (_o._playheadBeat >= 0)
{
double px = _o.BeatToX(_o._playheadBeat);
@@ -732,17 +834,14 @@ public sealed class PianoRollView : UserControl
for (int p = MinPitch; p <= MaxPitch; p++)
{
double y = (MaxPitch - p) * RowH;
- ctx.FillRectangle(IsBlack(p) ? KeyBlack : KeyWhite, new Rect(0, y, w, RowH - 1));
+ ctx.FillRectangle(IsBlack(p) ? KeyBlack : KeyWhite, new Rect(0, y, w, RowH));
if (_o._scaleOn)
{
- if (_o.IsRoot(p)) ctx.FillRectangle(RootTint, new Rect(0, y, w, RowH - 1));
- else if (!_o.InScale(p)) ctx.FillRectangle(OutScaleWash, new Rect(0, y, w, RowH - 1));
- }
- if (p % 12 == 0)
- {
- var ft = new FormattedText(NoteName(p), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, 8, KeyLabel);
- ctx.DrawText(ft, new Point(w - ft.Width - 4, y + 2));
+ if (_o.IsRoot(p)) ctx.FillRectangle(RootTint, new Rect(0, y, w, RowH));
+ else if (!_o.InScale(p)) ctx.FillRectangle(OutScaleWash, new Rect(0, y, w, RowH));
}
+ ctx.DrawLine(p % 12 == 0 ? KeyOctaveLine : KeyLine, new Point(0, y + RowH - 0.5), new Point(w, y + RowH - 0.5));
+ if (p % 12 == 0) DrawKeyLabel(ctx, p, y, w, KeyLabel);
}
// Currently-pressed keys (computer keyboard / MIDI): light the key solid + label it.
if (_o._held.Count > 0)
@@ -751,8 +850,7 @@ public sealed class PianoRollView : UserControl
if (hp < MinPitch || hp > MaxPitch) continue;
double y = (MaxPitch - hp) * RowH;
ctx.FillRectangle(HeldKeyFill, new Rect(0, y, w, RowH - 1));
- var ft = new FormattedText(NoteName(hp), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, 9, KeyLabel);
- ctx.DrawText(ft, new Point(w - ft.Width - 4, y + 1));
+ DrawKeyLabel(ctx, hp, y, w, KeyLabelOnAccent);
}
// Hovered key: highlight it and label its note name (works for black keys too,
// where the octave-C label wouldn't otherwise show).
@@ -760,17 +858,22 @@ public sealed class PianoRollView : UserControl
{
double hy = (MaxPitch - _hover) * RowH;
ctx.FillRectangle(KeyHover, new Rect(0, hy, w, RowH - 1));
- var ft = new FormattedText(NoteName(_hover), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, 9, KeyLabel);
- ctx.DrawText(ft, new Point(w - ft.Width - 4, hy + 1));
+ DrawKeyLabel(ctx, _hover, hy, w, KeyLabelHot);
}
}
+
+ private static void DrawKeyLabel(DrawingContext ctx, int pitch, double y, double w, IBrush ink)
+ {
+ var ft = new FormattedText(NoteName(pitch), CultureInfo.InvariantCulture, FlowDirection.LeftToRight, Mono, 8, ink);
+ ctx.DrawText(ft, new Point(w - ft.Width - 5, y + (RowH - ft.Height) / 2));
+ }
}
// ---- note grid (interactive) -----------------------------------------
private sealed class NoteGrid : Control
{
private readonly PianoRollView _o;
- private enum Mode { None, Move, Resize, Marquee }
+ private enum Mode { None, Move, Resize, ResizeLeft, Marquee }
private Mode _drag = Mode.None;
private bool _dragMoved;
@@ -788,6 +891,7 @@ public sealed class PianoRollView : UserControl
// Hover affordance (mirrors the arrangement grid): resize cursor on the trim edge, a
// move/four-arrows cursor over a note body, plain arrow on empty space.
private int _hoverNote = -1;
+ private bool _hoverLeft; // the hovered trim edge is the note's start
private int _cursorKind; // 0 arrow, 1 resize, 2 move
private static readonly Cursor ArrowCursor = new(StandardCursorType.Arrow);
private static readonly Cursor ResizeCursor = new(StandardCursorType.SizeWestEast);
@@ -822,14 +926,14 @@ public sealed class PianoRollView : UserControl
for (int p = MinPitch; p <= MaxPitch; p++)
{
double y = PitchToY(p);
- if (IsBlack(p)) ctx.FillRectangle(RowBlackTint, new Rect(0, y, w, RowH));
+ ctx.FillRectangle(IsBlack(p) ? LaneBlack : LaneWhite, new Rect(0, y, w, RowH));
if (_o._scaleOn)
{
if (_o.IsRoot(p)) ctx.FillRectangle(RootTint, new Rect(0, y, w, RowH));
else if (_o.InScale(p)) ctx.FillRectangle(InScaleTint, new Rect(0, y, w, RowH));
else ctx.FillRectangle(OutScaleWash, new Rect(0, y, w, RowH));
}
- ctx.DrawLine(RowLine, new Point(0, y + RowH), new Point(w, y + RowH));
+ ctx.DrawLine(p % 12 == 0 ? RowOctaveLine : RowLine, new Point(0, y + RowH - 0.5), new Point(w, y + RowH - 0.5));
}
// Played-key rows: a faint wash across the grid so you see where the pressed note sits.
if (_o._held.Count > 0)
@@ -845,7 +949,7 @@ public sealed class PianoRollView : UserControl
double b = startB + k * step;
if (b > viewEnd + 1e-9) break;
double x = BeatToX(b);
- ctx.DrawLine(_o.GridPen(b), new Point(x, 0), new Point(x, h));
+ ctx.DrawLine(_o.GridPen(b), new Point(x + 0.5, 0), new Point(x + 0.5, h));
}
var notes = _o._notes;
for (int i = 0; i < notes.Count; i++)
@@ -855,20 +959,30 @@ public sealed class PianoRollView : UserControl
double x = BeatToX(n.StartBeat), y = PitchToY(n.Pitch);
double nw = Math.Max(3, n.LengthBeats * ppb);
bool sel = _o._selection.Contains(i);
- var c = _o._trackColor;
- IBrush fill;
- if (sel) fill = AccentBright;
+ var r = new Rect(x, y, Math.Max(2, nw - 1), RowH - 1);
+ if (_o.IsGhost(i)) // a tool's preview: brass outline over the clip's own notes
+ {
+ ctx.DrawRectangle(GhostFill, GhostEdge, r.Deflate(0.5), 2, 2);
+ continue;
+ }
+ if (sel) ctx.DrawRectangle(NoteSel, NoteSelEdge, r.Deflate(0.5), 2, 2);
else
{
- double a = 0.35 + 0.60 * Math.Clamp(n.Velocity, 0, 1);
+ // Track colour, quieter the softer the note.
+ var c = _o._trackColor;
+ double a = 0.45 + 0.55 * Math.Clamp(n.Velocity, 0, 1);
if (!_o.InScale(n.Pitch)) a *= 0.4; // out-of-scale notes read faint
- fill = new SolidColorBrush(Color.FromArgb((byte)(255 * a), c.R, c.G, c.B));
+ ctx.FillRectangle(new SolidColorBrush(Color.FromArgb((byte)(255 * a), c.R, c.G, c.B)), r, 2);
}
- ctx.FillRectangle(fill, new Rect(x, y + 1, nw, RowH - 2), 2);
// Resize-edge affordance: a bright bar on the edge a drag would trim.
- bool edgeHi = (_drag == Mode.Resize && sel) || (_drag == Mode.None && _hoverNote == i);
- if (edgeHi) ctx.FillRectangle(EdgeHighlight, new Rect(x + nw - 2.5, y + 1, 2.5, RowH - 2));
+ bool edgeHi = ((_drag == Mode.Resize || _drag == Mode.ResizeLeft) && sel) || (_drag == Mode.None && _hoverNote == i);
+ if (edgeHi)
+ {
+ bool left = _drag == Mode.ResizeLeft || (_drag == Mode.None && _hoverLeft);
+ ctx.FillRectangle(EdgeHighlight, new Rect(left ? x : x + r.Width - 2.5, y + 1, 2.5, RowH - 3));
+ }
}
+ _o.DrawOutsideClip(ctx, w, h);
if (_o._playheadBeat >= 0)
{
double px = BeatToX(_o._playheadBeat);
@@ -885,16 +999,21 @@ public sealed class PianoRollView : UserControl
private static Rect RectOf(Point a, Point b)
=> new(Math.Min(a.X, b.X), Math.Min(a.Y, b.Y), Math.Abs(a.X - b.X), Math.Abs(a.Y - b.Y));
- private int HitTest(Point p, out bool edge)
+ // The note under p, and which trim edge (if any) p is on: +1 end, −1 start, 0 body.
+ // On a short note each edge zone shrinks to a third, so the body stays grabbable.
+ private int HitTest(Point p, out int edge)
{
- edge = false;
+ edge = 0;
var notes = _o._notes;
for (int i = notes.Count - 1; i >= 0; i--)
{
var n = notes[i];
if (n.Pitch < MinPitch || n.Pitch > MaxPitch) continue;
double x = BeatToX(n.StartBeat), y = PitchToY(n.Pitch), nw = Math.Max(3, n.LengthBeats * Ppb);
- if (new Rect(x, y, nw, RowH).Contains(p)) { edge = p.X >= x + nw - EdgePx; return i; }
+ if (!new Rect(x, y, nw, RowH).Contains(p)) continue;
+ double zone = Math.Min(EdgePx, nw / 3);
+ edge = p.X >= x + nw - zone ? 1 : p.X <= x + zone ? -1 : 0;
+ return i;
}
return -1;
}
@@ -905,7 +1024,7 @@ public sealed class PianoRollView : UserControl
if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
var p = e.GetPosition(this);
bool shift = (e.KeyModifiers & KeyModifiers.Shift) != 0;
- int hit = HitTest(p, out bool edge);
+ int hit = HitTest(p, out int edge);
// Double-click: add a note on empty space, delete one under the cursor.
if (e.ClickCount == 2)
@@ -939,7 +1058,7 @@ public sealed class PianoRollView : UserControl
foreach (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) { _drag = Mode.Resize; _resizeAnchor = Snap(XToBeat(p.X)); Cursor = ResizeCursor; _cursorKind = 1; }
+ if (edge != 0) { _drag = edge > 0 ? Mode.Resize : Mode.ResizeLeft; _resizeAnchor = Snap(XToBeat(p.X)); 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();
@@ -1002,6 +1121,23 @@ public sealed class PianoRollView : UserControl
_dragMoved = true;
PushLive();
}
+ else if (_drag == Mode.ResizeLeft)
+ {
+ // 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;
+ foreach (var v in _orig.Values)
+ dStart = Math.Clamp(dStart, -v.start, Math.Max(-v.start, v.len - _o._grid));
+ foreach (var kv in _orig)
+ {
+ var n = _o._notes[kv.Key];
+ n.StartBeat = kv.Value.start + dStart;
+ n.LengthBeats = kv.Value.len - dStart;
+ _o._notes[kv.Key] = n;
+ }
+ _dragMoved = true;
+ PushLive();
+ }
else if (_drag == Mode.Marquee)
{
_marqueeB = p;
@@ -1038,11 +1174,12 @@ public sealed class PianoRollView : UserControl
private void UpdateHover(Point p)
{
- int hit = HitTest(p, out bool edge);
- int kind = hit < 0 ? 0 : edge ? 1 : 2; // 0 arrow, 1 resize edge, 2 move body
+ int hit = HitTest(p, out int edge);
+ int kind = hit < 0 ? 0 : edge != 0 ? 1 : 2; // 0 arrow, 1 resize edge, 2 move body
if (kind != _cursorKind) { _cursorKind = kind; Cursor = kind == 1 ? ResizeCursor : kind == 2 ? MoveCursor : ArrowCursor; }
int hn = kind == 1 ? hit : -1; // the bright trim-edge affordance shows only on the edge
- if (hn != _hoverNote) { _hoverNote = hn; _o.Invalidate(); }
+ bool left = edge < 0;
+ if (hn != _hoverNote || left != _hoverLeft) { _hoverNote = hn; _hoverLeft = left; _o.Invalidate(); }
}
protected override void OnPointerExited(PointerEventArgs e)
@@ -1198,54 +1335,86 @@ public sealed class PianoRollView : UserControl
{
double b = startB + k * step;
if (b > viewEnd + 1e-9) break;
- ctx.DrawLine(_o.GridPen(b), new Point(_o.BeatToX(b), 0), new Point(_o.BeatToX(b), h));
+ ctx.DrawLine(_o.GridPen(b), new Point(_o.BeatToX(b) + 0.5, 0), new Point(_o.BeatToX(b) + 0.5, h));
}
+ // A 2px stem per note with a 6×3 cap — the cap is the drag handle.
var notes = _o._notes;
for (int i = 0; i < notes.Count; i++)
{
var n = notes[i];
- double x = _o.BeatToX(n.StartBeat);
- double bh = Math.Clamp(n.Velocity, 0, 1) * (h - 6);
+ double x = _o.BeatToX(n.StartBeat) + 3;
+ double bh = Math.Clamp(n.Velocity, 0, 1) * (h - 8);
bool sel = _o._selection.Contains(i);
bool hov = i == _hover;
- IBrush b = sel ? AccentBright : new SolidColorBrush(hov ? Brighten(_o._trackColor) : _o._trackColor);
- ctx.FillRectangle(b, new Rect(x, h - bh, 5, bh), 1);
- // Hover / selected: cap the top edge (the velocity drag handle).
- if (hov || sel) ctx.FillRectangle(EdgeHighlight, new Rect(x, h - bh - 1, 5, 2));
+ IBrush b;
+ if (_o.IsGhost(i)) b = GhostStem;
+ else if (sel) b = NoteSel;
+ else
+ {
+ var c = hov ? Brighten(_o._trackColor) : _o._trackColor;
+ double a = 0.45 + 0.55 * Math.Clamp(n.Velocity, 0, 1);
+ b = new SolidColorBrush(Color.FromArgb((byte)(255 * a), c.R, c.G, c.B));
+ }
+ ctx.FillRectangle(b, new Rect(x, h - bh, 2, bh));
+ ctx.FillRectangle(hov && !sel ? EdgeHighlight : b, new Rect(x - 2, h - bh - 2, 6, 3), 1);
}
+ _o.DrawOutsideClip(ctx, w, h);
}
private static Color Brighten(Color c)
=> Color.FromRgb((byte)Math.Min(255, c.R + 48), (byte)Math.Min(255, c.G + 48), (byte)Math.Min(255, c.B + 48));
- private int Nearest(double x)
+ private double Usable => Math.Max(1, Bounds.Height - 8);
+ private double CapY(int i) => Bounds.Height - Math.Clamp(_o._notes[i].Velocity, 0, 1) * Usable;
+
+ // The stem under the pointer. Notes that start together (a chord, stacked pitches)
+ // share one x, so among the stems within reach the one whose cap is nearest the
+ // pointer's height wins — each stem stays reachable by grabbing it at its cap.
+ private int Nearest(Point p)
{
- int best = -1; double bd = 14;
+ int best = -1; double bx = 14, by = double.MaxValue;
for (int i = 0; i < _o._notes.Count; i++)
{
- double d = Math.Abs(_o.BeatToX(_o._notes[i].StartBeat) + 2.5 - x);
- if (d < bd) { bd = d; best = i; }
+ double dx = Math.Abs(_o.BeatToX(_o._notes[i].StartBeat) + 4 - p.X);
+ if (dx > 14) continue;
+ double dy = Math.Abs(CapY(i) - p.Y);
+ // Nearer in x wins outright; stems at (about) the same x go by cap height.
+ if (dx < bx - 2 || (Math.Abs(dx - bx) <= 2 && dy < by)) { best = i; bx = dx; by = dy; }
}
return best;
}
+ // Grab: the stem under the pointer, and — when it is part of the selection — every
+ // selected note with it, each keeping its offset (so a stacked chord moves together).
+ private readonly Dictionary<int, float> _grabbed = new();
+ private double _grabY;
+
protected override void OnPointerPressed(PointerPressedEventArgs e)
{
- int hit = Nearest(e.GetPosition(this).X);
+ if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed) return;
+ var p = e.GetPosition(this);
+ int hit = Nearest(p);
if (hit < 0) return;
- // Keep an existing multi-selection if the grabbed note is part of it;
- // otherwise this note becomes the selection.
- if (!_o._selection.Contains(hit)) { _o._selection.Clear(); _o._selection.Add(hit); }
+ bool shift = (e.KeyModifiers & KeyModifiers.Shift) != 0;
+ if (shift) _o._selection.Add(hit);
+ else if (!_o._selection.Contains(hit)) { _o._selection.Clear(); _o._selection.Add(hit); }
+ _grabbed.Clear();
+ foreach (int i in _o._selection)
+ if (i >= 0 && i < _o._notes.Count) _grabbed[i] = _o._notes[i].Velocity;
_velNote = hit; _drag = true;
- Apply(e.GetPosition(this).Y);
+ // A click on one stem sets it where you clicked; a group moves by the drag distance.
+ if (_grabbed.Count == 1) Apply(p.Y);
+ _grabY = p.Y;
+ e.Pointer.Capture(this);
_o.Invalidate(); _o.Changed?.Invoke();
e.Handled = true;
}
protected override void OnPointerMoved(PointerEventArgs e)
{
- if (_drag) { Apply(e.GetPosition(this).Y); _o.Invalidate(); _o.Changed?.Invoke(); return; }
- int hv = Nearest(e.GetPosition(this).X); // hover highlight (no drag)
+ var p = e.GetPosition(this);
+ if (_drag) { Apply(p.Y); _o.Invalidate(); _o.Changed?.Invoke(); return; }
+ int hv = Nearest(p); // hover highlight (no drag)
if (hv != _hover) { _hover = hv; InvalidateVisual(); }
}
@@ -1256,15 +1425,29 @@ public sealed class PianoRollView : UserControl
protected override void OnPointerReleased(PointerReleasedEventArgs e)
{
- if (_drag) { _drag = false; _o.CommitNotes(); _o.Changed?.Invoke(); }
+ if (!_drag) return;
+ _drag = false; _grabbed.Clear(); e.Pointer.Capture(null);
+ _o.CommitNotes(); _o.Changed?.Invoke();
}
private void Apply(double y)
{
- if (_velNote < 0 || _velNote >= _o._notes.Count) return;
- var n = _o._notes[_velNote];
- n.Velocity = (float)Math.Clamp((Bounds.Height - y) / (Bounds.Height - 6), 0.02, 1.0);
- _o._notes[_velNote] = n;
+ if (_grabbed.Count == 1)
+ {
+ if (_velNote < 0 || _velNote >= _o._notes.Count) return;
+ var n = _o._notes[_velNote];
+ n.Velocity = (float)Math.Clamp((Bounds.Height - y) / Usable, 0.02, 1.0);
+ _o._notes[_velNote] = n;
+ return;
+ }
+ float d = (float)((_grabY - y) / Usable);
+ foreach (var (i, v0) in _grabbed)
+ {
+ if (i < 0 || i >= _o._notes.Count) continue;
+ var n = _o._notes[i];
+ n.Velocity = Math.Clamp(v0 + d, 0.02f, 1f);
+ _o._notes[i] = n;
+ }
}
}
}
diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.cs
index 0b055acc..1433668c 100644
--- a/src/managed/Nota.App/PreferencesWindow.cs
+++ b/src/managed/Nota.App/PreferencesWindow.cs
@@ -674,9 +674,11 @@ public sealed class PreferencesWindow : NotaWindow
("↑ ↓", "Transpose by a semitone"),
("⇧↑ ⇧↓", "Transpose by an octave"),
("⌘A", "Select all notes"),
- ("⌘D", "Duplicate the selection"),
+ ("⌘D", "Duplicate the selection · replaces the notes it lands on"),
("⌘C ⌘X ⌘V", "Copy / cut / paste notes"),
("Delete", "Delete the selected notes"),
+ ("Drag note edge", "Change the note's start or end"),
+ ("Drag velocity stem", "Set velocity · selected notes move together · ⇧ adds a note"),
}),
("PLAY NOTES (COMPUTER KEYBOARD)", new[]
{
diff --git a/src/managed/Nota.App/Theme/NotaPalette.cs b/src/managed/Nota.App/Theme/NotaPalette.cs
index 9f146260..1ca70ec1 100644
--- a/src/managed/Nota.App/Theme/NotaPalette.cs
+++ b/src/managed/Nota.App/Theme/NotaPalette.cs
@@ -283,9 +283,9 @@ internal static class NotaPalette
public static readonly SolidColorBrush TooltipBg = T("#18181E", "#2A251C"); // tooltips stay a dark pill
public static readonly SolidColorBrush TooltipText = T("#F0E4C8", "#F5EEDC");
- // ---- Piano keys (literal keys: white stays light, black stays dark) ---
- public static readonly SolidColorBrush KeyWhite = T("#B7B1A3", "#FFFCF2");
- public static readonly SolidColorBrush KeyBlack = T("#201E1A", "#3A352B");
+ // ---- Piano keys (the clip editor keyboard is dark: keys recede, notes lead) ---
+ public static readonly SolidColorBrush KeyWhite = T("#1C1A16", "#F3EFE4"); // piano-roll keys: dark, never the brightest thing
+ public static readonly SolidColorBrush KeyBlack = T("#0E0D0B", "#DAD3C2"); // black keys and their lanes
public static readonly SolidColorBrush MiniKeyWhite = T("#2A2721", "#F5F1E4"); // device-card mini keyboards
public static readonly SolidColorBrush MiniKeyBlack = T("#151310", "#38332A");