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.

Follow clip geometry in the editor, clear the panel on track delete

Egor Khindikaynen3592248b249e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index dca19969..0f57cada 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -124,6 +124,16 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
around at the ends. The preset list marks the one currently loaded.
### Fixed
+- **Resizing a clip in the arrangement now updates its open editor.** Dragging a clip's edge
+ left the clip editor showing the old length — its Start/Length read-outs, the piano roll's
+ own span and the envelope editor's beat axis all kept the length they had when the editor
+ was opened. Moving a clip likewise leaves its Start read-out correct now.
+- **Editing a clip in the arrangement no longer throws you out of the Clip tab.** Clicking a
+ clip — or grabbing its edge to resize it — selects its track, which used to switch the
+ detail panel to Devices. The panel now stays on Clip and follows the clip you picked.
+- **Deleting the selected track clears the device panel.** Its instrument and effect cards
+ stayed on screen, still editing a track that no longer existed; the Modular view kept the
+ removed track's nodes the same way.
- **A device card keeps showing its preset name.** Switching to another track and back no
longer resets the name to Init. The name stays with its device when devices are
reordered, deleted or copied, and presets loaded from the browser now show their name on
diff --git a/src/managed/Nota.App/ArrangementView.LaneControl.cs b/src/managed/Nota.App/ArrangementView.LaneControl.cs
index 1e2bfae3..1cf37943 100644
--- a/src/managed/Nota.App/ArrangementView.LaneControl.cs
+++ b/src/managed/Nota.App/ArrangementView.LaneControl.cs
@@ -460,6 +460,9 @@ public sealed partial class ArrangementView
keptDeviceAuto |= eng.LastMoveKeptDeviceAutomation();
}
else eng.MoveClip(m.track, m.clip, m.vm.StartBeat);
+ // Same-track moves keep their clip index, so an open editor on one of
+ // them stays valid — but its START read-out is now off.
+ if (rowDelta == 0) _o.RaiseClipGeometryChanged(m.track, m.clip);
}
if (keptDeviceAuto) // explicit hint: only Volume/Pan followed across tracks (req 8.3.4)
_o.StatusMessage?.Invoke("Moved across tracks — device automation stayed on the source");
@@ -483,6 +486,8 @@ public sealed partial class ArrangementView
eng.TrimClip(_dragTrackId, _dragClipIndex, _dragClip.StartBeat, _dragClip.LengthBeats);
else
eng.ResizeAudioClip(_dragTrackId, _dragClipIndex, _dragClip.StartBeat, _dragClip.LengthBeats);
+ // An editor open on this clip still holds the pre-drag geometry.
+ _o.RaiseClipGeometryChanged(_dragTrackId, _dragClipIndex);
}
_drag = Drag.None;
_dragClip = null;
diff --git a/src/managed/Nota.App/ArrangementView.cs b/src/managed/Nota.App/ArrangementView.cs
index 948cc4e0..c7ff59f5 100644
--- a/src/managed/Nota.App/ArrangementView.cs
+++ b/src/managed/Nota.App/ArrangementView.cs
@@ -123,6 +123,12 @@ public sealed partial class ArrangementView : UserControl
public event Action<BrowserItem, int, double>? ItemDropped;
/// <summary>Audio-clip context-menu "Convert / Slice to New MIDI Track" (track id, clip index, mode).</summary>
public event Action<int, int, ClipConvertMode>? ConvertClipRequested;
+ /// <summary>Raised after a clip's start/length changed in place (edge-drag trim or
+ /// stretch): track id, clip index. An open clip editor re-reads its geometry from this.</summary>
+ public event Action<int, int>? ClipGeometryChanged;
+
+ internal void RaiseClipGeometryChanged(int trackId, int clipIndex)
+ => ClipGeometryChanged?.Invoke(trackId, clipIndex);
public ArrangementView()
{
diff --git a/src/managed/Nota.App/ClipEditorView.cs b/src/managed/Nota.App/ClipEditorView.cs
index a98387d5..899ae08d 100644
--- a/src/managed/Nota.App/ClipEditorView.cs
+++ b/src/managed/Nota.App/ClipEditorView.cs
@@ -30,7 +30,8 @@ public sealed class ClipEditorView : UserControl
public PianoRollView Roll { get; }
private readonly ContentControl _rightHost;
- private readonly Control? _envPanel;
+ private readonly EnvPanel? _envPanel;
+ private readonly ClipPropsView _props;
private Border _notesTab = null!, _envTab = null!;
public ClipEditorView(PianoRollView roll, string clipName, double startBeat,
@@ -43,8 +44,8 @@ public sealed class ClipEditorView : UserControl
_envPanel = new EnvPanel(engine, trackId, clipIndex, lengthBeats);
var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("Auto,*") };
- var props = new ClipPropsView(roll, clipName, startBeat);
- grid.Children.Add(props);
+ _props = new ClipPropsView(roll, clipName, startBeat);
+ grid.Children.Add(_props);
Grid.SetColumn(_rightHost, 1);
grid.Children.Add(_rightHost);
@@ -56,6 +57,16 @@ public sealed class ClipEditorView : UserControl
Content = dock;
}
+ /// <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
+ /// otherwise keep their construction-time snapshot.</summary>
+ public void SetClipBounds(double startBeat, double lengthBeats)
+ {
+ _props.SetStart(startBeat);
+ _envPanel?.SetLength(lengthBeats);
+ }
+
private void ShowTab(bool envelopes)
{
if (envelopes && _envPanel is null) return;
@@ -199,6 +210,8 @@ public sealed class ClipEditorView : UserControl
Load();
}
+ public void SetLength(double lengthBeats) => _canvas.SetLength(lengthBeats);
+
private void CycleTarget()
{
_target = _target == MidiClipEnvelope.Velocity ? MidiClipEnvelope.Volume : MidiClipEnvelope.Velocity;
@@ -233,7 +246,7 @@ public sealed class ClipEditorView : UserControl
private static readonly IBrush GridBeat = new SolidColorBrush(Color.FromArgb(0x50, 0x3A, 0x36, 0x2D));
private static readonly IBrush EnvLine = NotaPalette.AccentBright;
private readonly System.Collections.Generic.List<EnvPt> _pts = new();
- private readonly double _clipBeats;
+ private double _clipBeats;
private int _drag = -1;
private EnvPt? _bend;
private const double HandlePx = 7;
@@ -241,6 +254,16 @@ public sealed class ClipEditorView : UserControl
public Action<double[], double[], float[]>? Committed;
public EnvCanvas(double clipBeats) { _clipBeats = Math.Max(1e-6, clipBeats); }
+ // 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.
+ public void SetLength(double clipBeats)
+ {
+ double v = Math.Max(1e-6, clipBeats);
+ if (Math.Abs(v - _clipBeats) < 1e-9) return;
+ _clipBeats = v;
+ InvalidateVisual();
+ }
+
public void SetPoints(double[] beats, double[] values, float[] curves)
{
_pts.Clear();
diff --git a/src/managed/Nota.App/ClipPropsView.cs b/src/managed/Nota.App/ClipPropsView.cs
index 04058772..bf048519 100644
--- a/src/managed/Nota.App/ClipPropsView.cs
+++ b/src/managed/Nota.App/ClipPropsView.cs
@@ -39,7 +39,7 @@ 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 double _startBeat;
+ private readonly TextBlock _startText;
private readonly TextBlock _lengthText;
private readonly TextBlock _loopText;
private readonly TextBlock _selInfo;
@@ -52,12 +52,12 @@ public sealed class ClipPropsView : UserControl
public ClipPropsView(PianoRollView roll, string clipName, double startBeat)
{
_roll = roll;
- _startBeat = startBeat;
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;
@@ -69,7 +69,8 @@ public sealed class ClipPropsView : UserControl
body.Children.Add(Section("CLIP", ReadoutBox(clipName, TextPrimary, 24, 11, false)));
var startLen = new Grid { ColumnDefinitions = new ColumnDefinitions("*,*"), ColumnSpacing = 6 };
- startLen.Children.Add(Labeled("START", ReadoutBox(Position(startBeat), TextPrimary, 22, 10, true)));
+ 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);
@@ -148,6 +149,10 @@ public sealed class ClipPropsView : UserControl
_roll.Changed += OnRollChanged;
}
+ /// <summary>Re-points the START read-out after the clip moved or was trimmed from the
+ /// left in the arrangement. LENGTH / LOOP follow the roll's own Changed event.</summary>
+ public void SetStart(double startBeat) => _startText.Text = Position(startBeat);
+
private void OnRollChanged()
{
_selInfo.Text = _roll.SelectionInfo;
diff --git a/src/managed/Nota.App/MainWindow.Browser.cs b/src/managed/Nota.App/MainWindow.Browser.cs
index 4710710e..56267181 100644
--- a/src/managed/Nota.App/MainWindow.Browser.cs
+++ b/src/managed/Nota.App/MainWindow.Browser.cs
@@ -25,8 +25,17 @@ public partial class MainWindow
{
private int _lastInstrumentTrackId;
+ /// <summary>The fallback target when nothing is selected: the last instrument track added,
+ /// but only while it still exists — it may have been deleted, cut or undone since, and
+ /// acting on a dead track id silently edits nothing (or re-shows its stale device chain).</summary>
+ private int LastInstrumentTrack()
+ {
+ if (_lastInstrumentTrackId > 0 && TrackIndexOf(_lastInstrumentTrackId) < 0) _lastInstrumentTrackId = 0;
+ return _lastInstrumentTrackId;
+ }
+
// Effects target the selected track, else the last instrument track added.
- private int EffectTarget() => Timeline.SelectedTrackId > 0 ? Timeline.SelectedTrackId : _lastInstrumentTrackId;
+ private int EffectTarget() => Timeline.SelectedTrackId > 0 ? Timeline.SelectedTrackId : LastInstrumentTrack();
// Applies a preset browser row: factory presets (Path "factory:<id>") resolve through
// the shipped catalog; user presets load from disk. Instrument presets create a new
diff --git a/src/managed/Nota.App/MainWindow.Detail.cs b/src/managed/Nota.App/MainWindow.Detail.cs
index c328566b..1f11f8b6 100644
--- a/src/managed/Nota.App/MainWindow.Detail.cs
+++ b/src/managed/Nota.App/MainWindow.Detail.cs
@@ -83,9 +83,19 @@ public partial class MainWindow
// in the popped-out Devices/Clip window, whose top pane isn't touched by ShowDevices.
if (_editorTrackId != trackId && _audioEditorTrackId != trackId)
ResetClipEditor();
- ShowDevices(trackId);
+
+ // Selecting a clip in the arrangement also selects its track — including the select
+ // that an edge-drag does before it trims. That must not pull a user who is working in
+ // the Clip tab over to Devices, so refresh the chain underneath and re-point the Clip
+ // tab at the newly selected clip. With no clip to show, Devices takes the panel as before.
+ bool keepClipTab = !DetailFloating && DetailPanel.IsVisible
+ && DetailBody.Content is ClipEditorView or AudioClipEditorView
+ && SelectedClip(out _, out _, out _);
+
+ ShowDevices(trackId, takeOverPanel: !keepClipTab);
if (_modular?.IsVisible == true) _modular.Show(trackId); // keep the graph on the selected track
SyncClipTab();
+ if (keepClipTab) OnDetailClip(this, new RoutedEventArgs());
}
// Clear all clip-editor state and blank the clip pane (placeholder while floating, so the
@@ -122,14 +132,30 @@ public partial class MainWindow
? _clipEditor is not null
: SelectedClip(out _, out _, out _);
- private void ShowDevices(int trackId)
+ // takeOverPanel: false shows the chain without claiming the docked panel, for callers that
+ // only follow the selection (see OnTrackSelected). Explicit "show me the devices" callers
+ // — a browser drop, Convert, the Devices tab — leave it true.
+ private void ShowDevices(int trackId, bool takeOverPanel = true)
{
- if (_vm is null || _deviceChain is null || trackId <= 0) return;
+ if (_vm is null || _deviceChain is null) return;
+ // No track (the selected one was just deleted): empty the chain instead of leaving the
+ // dead track's instrument/effect cards on screen — they'd still edit a removed track.
+ // Don't pop the panel open for it; just clear whatever is already showing.
+ if (trackId <= 0)
+ {
+ _deviceChain.Show(-1);
+ SetDetailChip(-1, "Devices");
+ ApplyFrozenChainDim(-1);
+ return;
+ }
_deviceChain.Show(trackId);
- SetHost(DeviceHost, _deviceChain);
SetDetailChip(trackId);
ApplyFrozenChainDim(trackId); // M7: dim the chain while frozen
- if (DetailFloating) return; // floating: bottom pane only, don't touch the docked row/tabs
+ // Docked, both tabs share one host, so hosting the chain *is* the switch to Devices —
+ // skip it when we're only following the selection. Floating has its own pane, so the
+ // chain always goes there and no tab is at stake.
+ if (DetailFloating || takeOverPanel) SetHost(DeviceHost, _deviceChain);
+ if (DetailFloating || !takeOverPanel) return; // floating: bottom pane only, don't touch the docked row/tabs
DetailDevicesBtn.IsChecked = true;
DetailClipBtn.IsChecked = false;
ShowDetail(320, honorPersist: false); // Devices: natural card-fitting height
@@ -243,6 +269,29 @@ public partial class MainWindow
ShowDetail(250, honorPersist: true);
}
+ // A clip was trimmed / stretched / moved in the arrangement. Both clip editors snapshot the
+ // clip's geometry when they're built, so push the new start+length into whichever one is
+ // open on that clip — otherwise the editor keeps drawing the pre-drag length until it's
+ // rebuilt (double-click, track switch, undo).
+ private void OnClipGeometryChanged(int trackId, int clipIndex)
+ {
+ if (trackId <= 0 || clipIndex < 0 || !Engine.TryGetClipInfo(trackId, clipIndex, out var ci)) return;
+
+ if (_editorRoll is not null && _editorTrackId == trackId && _editorClipIndex == clipIndex)
+ {
+ double len = ci.LengthBeats > 0 ? ci.LengthBeats : _editorRoll.LengthBeats;
+ // SetNotes resets the roll's selection, so only re-seed it when the span really moved;
+ // a pure move leaves the notes (clip-local) untouched.
+ if (Math.Abs(len - _editorRoll.LengthBeats) > 1e-9)
+ _editorRoll.SetNotes(Engine.GetClipNotes(trackId, clipIndex), len);
+ _clipEditor?.SetClipBounds(ci.StartBeat, len);
+ }
+ else if (_audioEditor is not null && _audioEditorTrackId == trackId && _audioEditorClipIndex == clipIndex)
+ {
+ _audioEditor.Reload();
+ }
+ }
+
private void ReloadEditorNotes()
{
if (_vm is null || _editorRoll is null || _editorTrackId < 0) return;
@@ -265,7 +314,7 @@ public partial class MainWindow
private void OnDetailDevices(object? sender, RoutedEventArgs e)
{
- int t = Timeline.SelectedTrackId > 0 ? Timeline.SelectedTrackId : _lastInstrumentTrackId;
+ int t = Timeline.SelectedTrackId > 0 ? Timeline.SelectedTrackId : LastInstrumentTrack();
if (t > 0) ShowDevices(t);
else { DetailDevicesBtn.IsChecked = false; if (_vm is not null) _vm.StatusText = "Select a track first."; }
}
diff --git a/src/managed/Nota.App/MainWindow.DetailWindow.cs b/src/managed/Nota.App/MainWindow.DetailWindow.cs
index 37a43765..1c384ce8 100644
--- a/src/managed/Nota.App/MainWindow.DetailWindow.cs
+++ b/src/managed/Nota.App/MainWindow.DetailWindow.cs
@@ -66,7 +66,7 @@ public partial class MainWindow
_detailWindow = null;
if (_shuttingDown) return;
// Re-open docked on the Devices tab; the clip editor stays reachable via the Clip tab.
- int t = Timeline.SelectedTrackId > 0 ? Timeline.SelectedTrackId : _lastInstrumentTrackId;
+ int t = Timeline.SelectedTrackId > 0 ? Timeline.SelectedTrackId : LastInstrumentTrack();
if (t > 0) ShowDevices(t);
SyncClipTab();
}
diff --git a/src/managed/Nota.App/MainWindow.axaml.cs b/src/managed/Nota.App/MainWindow.axaml.cs
index 2432056e..63da8e06 100644
--- a/src/managed/Nota.App/MainWindow.axaml.cs
+++ b/src/managed/Nota.App/MainWindow.axaml.cs
@@ -232,6 +232,7 @@ public partial class MainWindow : Window
_deviceChain.RackPresetSaveRequested += OnSaveRackChainPreset;
_deviceChain.ItemDropped += OnDevicePanelDrop; // browser drag onto the device panel
Timeline.TrackSelected += OnTrackSelected;
+ Timeline.ClipGeometryChanged += OnClipGeometryChanged; // clip trimmed/moved → follow it in the open editor
Timeline.StatusMessage += msg => { if (_vm is not null) _vm.StatusText = msg; }; // automation-follow hints etc.
_session = new SessionView(vm.Engine) { IsVisible = false };
@@ -423,7 +424,7 @@ public partial class MainWindow : Window
if (session) _session.Refresh();
if (modular)
{
- int t = Timeline.SelectedTrackId > 0 ? Timeline.SelectedTrackId : _lastInstrumentTrackId;
+ int t = Timeline.SelectedTrackId > 0 ? Timeline.SelectedTrackId : LastInstrumentTrack();
if (t > 0) _modular.Show(t);
}
SyncClipTab(); // Clip tab availability is per-context (arrangement vs session)
diff --git a/src/managed/Nota.App/ModularView.cs b/src/managed/Nota.App/ModularView.cs
index dba4d70c..f06431d4 100644
--- a/src/managed/Nota.App/ModularView.cs
+++ b/src/managed/Nota.App/ModularView.cs
@@ -184,10 +184,12 @@ public sealed class ModularView : UserControl
// ---- public API (mirrors DeviceChainView.Show / MixerView.Refresh) ---
- /// <summary>Point the graph at a track and rebuild it.</summary>
+ /// <summary>Point the graph at a track and rebuild it. A non-positive id means "no track"
+ /// (the selected one was just deleted) and empties the canvas rather than leaving the
+ /// removed track's nodes on screen still wired to a dead track id.</summary>
public void Show(int trackId)
{
- if (trackId <= 0) return;
+ if (trackId <= 0) { _trackId = -1; Rebuild(); RefreshSidebar(); return; }
bool changed = trackId != _trackId;
_trackId = trackId;
Rebuild();