Skip to content

armgit / nota

Public Imported from GitHub
0

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

Add preset stepping and keep preset names on device cards

Egor Khindikaynenb8f29a78870e
diff --git a/CHANGELOG.md b/CHANGELOG.md
index aa960326..dca19969 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -119,8 +119,15 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
edits** while you're editing, plus **Unfreeze (wake source)** and **Flatten (remove
source)**. Each command selects its track, so the Devices panel follows along; **Edit**
always jumps to the source, where the notes and devices live.
+- **Step through presets from a device card.** The preset box in a card's header now has ‹
+ and › buttons on either side that load the previous or next factory preset, wrapping
+ around at the ends. The preset list marks the one currently loaded.
### Fixed
+- **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
+ the card too.
- Applying a built-in effect's factory preset now resets the parameters the preset doesn't
name to their defaults, so switching presets no longer keeps leftovers from the last one.
- **Preferences: the end of long sections can be scrolled into view.** The last rows of
diff --git a/src/managed/Nota.App/DeviceChainView.Clipboard.cs b/src/managed/Nota.App/DeviceChainView.Clipboard.cs
index ce03c8ea..51ed348f 100644
--- a/src/managed/Nota.App/DeviceChainView.Clipboard.cs
+++ b/src/managed/Nota.App/DeviceChainView.Clipboard.cs
@@ -50,6 +50,7 @@ public sealed partial class DeviceChainView
public int MidiKind; // MIDI effect kind
public float[]? MidiParams; // MIDI effect param snapshot
public bool Bypassed;
+ public string Preset = "", PresetId = ""; // the source card's preset label follows the paste
}
private DeviceClip? _clip;
@@ -72,6 +73,7 @@ public sealed partial class DeviceChainView
for (int i = 0; i < n; i++) p[i] = _engine.MidiEffectGetParam(_trackId, di, i);
_clip = new DeviceClip { Kind = ChainKind.Midi, MidiKind = _engine.MidiEffectKind(_trackId, di), MidiParams = p, Bypassed = _engine.MidiEffectBypassed(_trackId, di) };
}
+ if (_clip != null) { var ex = Extra(_selChainKind, di); _clip.Preset = ex.Preset; _clip.PresetId = ex.PresetId; }
}
private void DeleteSelectedDevice()
@@ -81,6 +83,7 @@ public sealed partial class DeviceChainView
if (k == ChainKind.Effect) _engine.RemoveDevice(_trackId, di);
else if (k == ChainKind.Midi) _engine.RemoveMidiEffect(_trackId, di);
else return;
+ ExtrasRemoved(k, di);
_selDeviceIndex = -1;
Rebuild(); Changed?.Invoke();
}
@@ -110,9 +113,10 @@ public sealed partial class DeviceChainView
}
if (newIdx < 0) return;
if (c.Bypassed) _engine.SetDeviceBypassed(_trackId, newIdx, true);
+ TrackExtras().Remove(ExtraKey(ChainKind.Effect, newIdx)); // a fresh slot: drop any stale entry
// Drop it right after the selected effect, else leave it appended.
if (_selChainKind == ChainKind.Effect && _selDeviceIndex >= 0 && _selDeviceIndex < newIdx)
- { int to = _selDeviceIndex + 1; _engine.MoveDevice(_trackId, newIdx, to); newIdx = to; }
+ { int to = _selDeviceIndex + 1; _engine.MoveDevice(_trackId, newIdx, to); ExtrasMoved(ChainKind.Effect, newIdx, to); newIdx = to; }
_selChainKind = ChainKind.Effect;
}
else if (c.Kind == ChainKind.Midi)
@@ -125,11 +129,13 @@ public sealed partial class DeviceChainView
for (int i = 0; i < n; i++) _engine.MidiEffectSetParam(_trackId, newIdx, i, c.MidiParams[i]);
}
if (c.Bypassed) _engine.SetMidiEffectBypassed(_trackId, newIdx, true);
+ TrackExtras().Remove(ExtraKey(ChainKind.Midi, newIdx));
if (_selChainKind == ChainKind.Midi && _selDeviceIndex >= 0 && _selDeviceIndex < newIdx)
- { int to = _selDeviceIndex + 1; _engine.MoveMidiEffect(_trackId, newIdx, to); newIdx = to; }
+ { int to = _selDeviceIndex + 1; _engine.MoveMidiEffect(_trackId, newIdx, to); ExtrasMoved(ChainKind.Midi, newIdx, to); newIdx = to; }
_selChainKind = ChainKind.Midi;
}
else return;
+ var pasted = Extra(c.Kind, newIdx); pasted.Preset = c.Preset; pasted.PresetId = c.PresetId;
_selDeviceIndex = newIdx;
Rebuild(); Changed?.Invoke();
}
@@ -220,6 +226,7 @@ public sealed partial class DeviceChainView
if (to == from) return;
if (kindL == ChainKind.Midi) _engine.MoveMidiEffect(_trackId, from, to);
else _engine.MoveDevice(_trackId, from, to);
+ ExtrasMoved(kindL, from, to);
_selChainKind = kindL; _selDeviceIndex = to;
Rebuild(); Changed?.Invoke();
};
diff --git a/src/managed/Nota.App/DeviceChainView.Shell.cs b/src/managed/Nota.App/DeviceChainView.Shell.cs
index f948bca5..361a17bb 100644
--- a/src/managed/Nota.App/DeviceChainView.Shell.cs
+++ b/src/managed/Nota.App/DeviceChainView.Shell.cs
@@ -33,16 +33,47 @@ public sealed partial class DeviceChainView
// reorder / preset API, branched on below.
internal enum ChainKind { Instrument, Effect, Midi }
- // A/B snapshots + last-applied preset per card, keyed so a MIDI effect and an audio
- // effect at the same index don't collide. Survives Rebuild(); cleared on track switch.
- private sealed class CardExtra { public float[]? A, B; public int Active; public string Preset = ""; }
- private readonly System.Collections.Generic.Dictionary<int, CardExtra> _cardExtra = new();
+ // A/B snapshots + last-applied preset per card, kept per track so switching tracks and
+ // back restores them, and keyed so a MIDI effect and an audio effect at the same index
+ // don't collide. Sig ties an entry to the device it was made for: when that slot now
+ // holds a different device (swapped, removed behind our back, undo), the card starts fresh.
+ private sealed class CardExtra { public string Sig = ""; public float[]? A, B; public int Active; public string Preset = "", PresetId = ""; }
+ private readonly System.Collections.Generic.Dictionary<int, System.Collections.Generic.Dictionary<int, CardExtra>> _cardExtra = new(); // trackId → key → extra
private static int ExtraKey(ChainKind k, int di) => k switch { ChainKind.Instrument => -1, ChainKind.Midi => -1000 - di, _ => di };
- private CardExtra Extra(int key)
+ private static ChainKind KeyKind(int key) => key >= 0 ? ChainKind.Effect : key == -1 ? ChainKind.Instrument : ChainKind.Midi;
+ private static int KeyIndex(int key) => key >= 0 ? key : key == -1 ? -1 : -1000 - key;
+ private string CardSig(int t, ChainKind k, int di) => k switch
{
- if (!_cardExtra.TryGetValue(key, out var e)) { e = new CardExtra(); _cardExtra[key] = e; }
+ ChainKind.Instrument => $"{_engine.TrackInstrumentKind(t)}|{_engine.DeviceName(t, -1)}",
+ ChainKind.Midi => $"{_engine.MidiEffectKind(t, di)}|{_engine.MidiEffectName(t, di)}",
+ _ => $"{_engine.TrackDeviceBuiltinKind(t, di)}|{_engine.DeviceName(t, di)}",
+ };
+ private System.Collections.Generic.Dictionary<int, CardExtra> TrackExtras(int t)
+ {
+ if (!_cardExtra.TryGetValue(t, out var d)) { d = new(); _cardExtra[t] = d; }
+ return d;
+ }
+ private System.Collections.Generic.Dictionary<int, CardExtra> TrackExtras() => TrackExtras(_trackId);
+ private CardExtra ExtraFor(int t, ChainKind k, int di)
+ {
+ var d = TrackExtras(t); int key = ExtraKey(k, di); string sig = CardSig(t, k, di);
+ if (!d.TryGetValue(key, out var e) || e.Sig != sig) { e = new CardExtra { Sig = sig }; d[key] = e; }
return e;
}
+ private CardExtra Extra(ChainKind k, int di) => ExtraFor(_trackId, k, di);
+
+ // Keep each card's extra glued to its device when this view reorders / removes devices.
+ // map: old index → new index, or -1 when the device is gone.
+ private void RemapExtras(ChainKind k, Func<int, int> map)
+ {
+ if (k == ChainKind.Instrument || !_cardExtra.TryGetValue(_trackId, out var d)) return;
+ var domain = d.Where(kv => KeyKind(kv.Key) == k).ToList();
+ foreach (var kv in domain) d.Remove(kv.Key);
+ foreach (var kv in domain) { int ni = map(KeyIndex(kv.Key)); if (ni >= 0) d[ExtraKey(k, ni)] = kv.Value; }
+ }
+ private void ExtrasMoved(ChainKind k, int from, int to) => RemapExtras(k, i =>
+ i == from ? to : from < to && i > from && i <= to ? i - 1 : to < from && i >= to && i < from ? i + 1 : i);
+ private void ExtrasRemoved(ChainKind k, int di) => RemapExtras(k, i => i == di ? -1 : i > di ? i - 1 : i);
private int ParamCount(ChainKind k, int di) => k switch
{ ChainKind.Instrument => _engine.PluginParamCount(_trackId, -1), ChainKind.Midi => _engine.MidiEffectParamCount(_trackId, di), _ => _engine.DeviceParamCount(_trackId, di) };
@@ -67,7 +98,7 @@ public sealed partial class DeviceChainView
private Border BuildCardShell(ShellSpec s, Control body)
{
int di = s.DeviceIndex;
- var extra = Extra(ExtraKey(s.Kind, di));
+ var extra = Extra(s.Kind, di);
// Rich chrome (preset picker · A/B · meter) needs room; narrow effect cards get
// the essential chrome only. Instruments (≥700) and wide effects show everything.
bool full = !double.IsNaN(s.Width) && s.Width >= 520;
@@ -97,13 +128,13 @@ public sealed partial class DeviceChainView
if (full) { right.Children.Add(ABControl(s, extra)); right.Children.Add(MeterBadge()); }
- void Move(int to) { if (s.Kind == ChainKind.Midi) _engine.MoveMidiEffect(_trackId, di, to); else _engine.MoveDevice(_trackId, di, to); Rebuild(); Changed?.Invoke(); }
+ void Move(int to) { if (s.Kind == ChainKind.Midi) _engine.MoveMidiEffect(_trackId, di, to); else _engine.MoveDevice(_trackId, di, to); ExtrasMoved(s.Kind, di, to); Rebuild(); Changed?.Invoke(); }
if (s.CanMove)
{
right.Children.Add(Glyph("◀", di > 0, () => Move(di - 1)));
right.Children.Add(Glyph("▶", di < s.Count - 1, () => Move(di + 1)));
}
- if (s.CanDelete) right.Children.Add(Glyph("✕", true, () => { if (s.Kind == ChainKind.Midi) _engine.RemoveMidiEffect(_trackId, di); else _engine.RemoveDevice(_trackId, di); Rebuild(); Changed?.Invoke(); }));
+ if (s.CanDelete) right.Children.Add(Glyph("✕", true, () => { if (s.Kind == ChainKind.Midi) _engine.RemoveMidiEffect(_trackId, di); else _engine.RemoveDevice(_trackId, di); ExtrasRemoved(s.Kind, di); Rebuild(); Changed?.Invoke(); }));
var handle = new TextBlock
{
Text = "⠿", FontSize = 11, Foreground = TextDisabled, VerticalAlignment = VerticalAlignment.Center,
@@ -155,32 +186,74 @@ public sealed partial class DeviceChainView
private int IndexOfId(string id)
{ int n = _engine.PluginParamCount(_trackId, -1); for (int i = 0; i < n; i++) if (_engine.PluginParamId(_trackId, -1, i) == id) return i; return -1; }
- // Preset box "Name ▾" → flyout of factory presets for this kind, applied in place.
+ // Preset picker "‹ Name ▾ ›": the name opens a flyout of factory presets for this kind
+ // (current one checked); ‹ › step to the previous / next preset, wrapping. From Init,
+ // › goes to the first preset and ‹ to the last. Always applied in place.
private Control PresetPicker(ShellSpec s, CardExtra extra)
{
+ var presets = _factory.All().Where(p => p.BuiltinKind == s.PresetKind
+ && (s.Kind == ChainKind.Midi ? p.IsMidiEffect : (p.IsInstrument == s.IsInstrument && !p.IsMidiEffect))).ToList();
+ int cur = presets.FindIndex(p => p.Id == extra.PresetId);
+ void Apply(FactoryPresetInfo p)
+ {
+ _factory.ApplyInPlace(_engine, p.Id, _trackId, s.DeviceIndex);
+ extra.PresetId = p.Id; extra.Preset = p.DisplayName;
+ Rebuild();
+ }
+
var label = new TextBlock { Text = string.IsNullOrEmpty(extra.Preset) ? "Init" : extra.Preset, FontSize = 10, Foreground = TextPrimary, VerticalAlignment = VerticalAlignment.Center, TextTrimming = TextTrimming.CharacterEllipsis, MaxWidth = 90 };
var box = new Border
{
- Height = 18, MinWidth = 96, Background = ShellInset, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(4),
- Padding = new Thickness(6, 0), Cursor = new Cursor(StandardCursorType.Hand), VerticalAlignment = VerticalAlignment.Center,
+ MinWidth = 96, Background = Brushes.Transparent, Padding = new Thickness(6, 0), Cursor = new Cursor(StandardCursorType.Hand),
Child = new DockPanel { Children = { new TextBlock { Text = "▾", FontSize = 8, Foreground = TextTertiary, VerticalAlignment = VerticalAlignment.Center, [DockPanel.DockProperty] = Dock.Right }, label } },
};
- var presets = _factory.All().Where(p => p.BuiltinKind == s.PresetKind
- && (s.Kind == ChainKind.Midi ? p.IsMidiEffect : (p.IsInstrument == s.IsInstrument && !p.IsMidiEffect))).ToList();
box.PointerPressed += (_, _) =>
{
var flyout = new MenuFlyout();
if (presets.Count == 0) flyout.Items.Add(new MenuItem { Header = "No presets", IsEnabled = false });
- foreach (var p in presets)
+ for (int i = 0; i < presets.Count; i++)
{
- var mi = new MenuItem { Header = p.DisplayName };
- var info = p;
- mi.Click += (_, _) => { _factory.ApplyInPlace(_engine, info.Id, _trackId, s.DeviceIndex); Extra(ExtraKey(s.Kind, s.DeviceIndex)).Preset = info.DisplayName; Rebuild(); };
+ var info = presets[i];
+ var mi = new MenuItem { Header = info.DisplayName, ToggleType = MenuItemToggleType.CheckBox, IsChecked = i == cur };
+ mi.Click += (_, _) => Apply(info);
flyout.Items.Add(mi);
}
flyout.ShowAt(box, showAtPointer: true);
};
- return box;
+
+ Border Step(int dir)
+ {
+ bool on = presets.Count > 0;
+ var chevron = new Path
+ {
+ Data = Geometry.Parse(dir < 0 ? "M3.5,0 L0,3.5 L3.5,7" : "M0,0 L3.5,3.5 L0,7"),
+ Stroke = on ? TextTertiary : TextDisabled, StrokeThickness = 1.2,
+ StrokeLineCap = PenLineCap.Round, StrokeJoin = PenLineJoin.Round,
+ HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center,
+ };
+ var b = new Border { Width = 16, Background = Brushes.Transparent, Child = chevron };
+ if (!on) return b;
+ b.Cursor = new Cursor(StandardCursorType.Hand);
+ ToolTip.SetTip(b, dir < 0 ? "Previous preset" : "Next preset");
+ b.PointerEntered += (_, _) => chevron.Stroke = TextPrimary;
+ b.PointerExited += (_, _) => chevron.Stroke = TextTertiary;
+ b.PointerPressed += (_, e) =>
+ {
+ if (!e.GetCurrentPoint(b).Properties.IsLeftButtonPressed) return;
+ e.Handled = true;
+ int n = presets.Count;
+ Apply(presets[cur < 0 ? (dir > 0 ? 0 : n - 1) : ((cur + dir) % n + n) % n]);
+ };
+ return b;
+ }
+ Border Divider() => new() { Width = 1, Background = BorderDef };
+
+ return new Border
+ {
+ Height = 18, Background = ShellInset, BorderBrush = BorderDef, BorderThickness = new Thickness(1), CornerRadius = new CornerRadius(4),
+ ClipToBounds = true, VerticalAlignment = VerticalAlignment.Center,
+ Child = new StackPanel { Orientation = Orientation.Horizontal, Children = { Step(-1), Divider(), box, Divider(), Step(+1) } },
+ };
}
// A | B compare of two full-param snapshots + copy-active-to-other.
diff --git a/src/managed/Nota.App/DeviceChainView.cs b/src/managed/Nota.App/DeviceChainView.cs
index 3d42cb09..54f13a78 100644
--- a/src/managed/Nota.App/DeviceChainView.cs
+++ b/src/managed/Nota.App/DeviceChainView.cs
@@ -102,7 +102,27 @@ public sealed partial class DeviceChainView : UserControl
});
}
- public void Show(int trackId) { _trackId = trackId; _rackSelChain = 0; _selDeviceIndex = -1; _cardExtra.Clear(); Rebuild(); }
+ public void Show(int trackId) { _trackId = trackId; _rackSelChain = 0; _selDeviceIndex = -1; Rebuild(); }
+
+ /// <summary>Forgets every card's remembered preset label + A/B slots (a project was
+ /// opened / created, so track ids no longer mean the same tracks).</summary>
+ public void ForgetCardState() => _cardExtra.Clear();
+
+ /// <summary>Forgets the instrument card's remembered preset label + A/B slots on a
+ /// track (its instrument was just swapped in place, possibly for one of the same kind).</summary>
+ public void ForgetInstrumentState(int trackId)
+ { if (_cardExtra.TryGetValue(trackId, out var d)) d.Remove(ExtraKey(ChainKind.Instrument, -1)); }
+
+ /// <summary>Records a preset applied outside the card (from the browser) so its card shows
+ /// the name and ‹ › continue from it. <paramref name="presetId"/> is the factory id, or ""
+ /// for a user preset. The card's A/B slots start fresh for the new device.</summary>
+ internal void RememberPreset(int trackId, ChainKind kind, int deviceIndex, string name, string presetId)
+ {
+ if (trackId <= 0) return;
+ TrackExtras(trackId).Remove(ExtraKey(kind, deviceIndex)); // a new device: drop any stale entry
+ var e = ExtraFor(trackId, kind, deviceIndex);
+ e.Preset = name; e.PresetId = presetId;
+ }
public void Refresh() { if (_trackId > 0) Rebuild(); }
public int TrackId => _trackId;
diff --git a/src/managed/Nota.App/MainWindow.Browser.cs b/src/managed/Nota.App/MainWindow.Browser.cs
index 0256ed08..4710710e 100644
--- a/src/managed/Nota.App/MainWindow.Browser.cs
+++ b/src/managed/Nota.App/MainWindow.Browser.cs
@@ -5,6 +5,7 @@ using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
+using System.Linq;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Controls.Primitives;
@@ -31,9 +32,36 @@ public partial class MainWindow
// the shipped catalog; user presets load from disk. Instrument presets create a new
// track (targetTrackId is ignored for them); effect presets target the track.
private string ApplyPresetItem(BrowserItem item, int targetTrackId)
- => item.Path.StartsWith("factory:", StringComparison.Ordinal)
- ? _factory.Apply(Engine, item.Path["factory:".Length..], targetTrackId)
+ {
+ bool factory = item.Path.StartsWith("factory:", StringComparison.Ordinal);
+ string factoryId = factory ? item.Path["factory:".Length..] : "";
+ // Apply doesn't say where the preset landed, so diff the chain around it: a new track
+ // (instrument preset) or one more device / MIDI effect on the target (appended last).
+ var tracksBefore = TrackIds();
+ int fxBefore = targetTrackId > 0 ? Engine.TrackDeviceCount(targetTrackId) : 0;
+ int midiBefore = targetTrackId > 0 ? Engine.TrackMidiEffectCount(targetTrackId) : 0;
+ string warn = factory
+ ? _factory.Apply(Engine, factoryId, targetTrackId)
: _presets.ApplyFromFile(Engine, item.Path, targetTrackId);
+ if (warn.Length > 0 || _deviceChain is null) return warn;
+
+ int newTrack = TrackIds().FirstOrDefault(id => !tracksBefore.Contains(id));
+ if (newTrack > 0)
+ _deviceChain.RememberPreset(newTrack, DeviceChainView.ChainKind.Instrument, -1, item.Name, factoryId);
+ else if (targetTrackId > 0 && Engine.TrackDeviceCount(targetTrackId) is var fx && fx > fxBefore)
+ _deviceChain.RememberPreset(targetTrackId, DeviceChainView.ChainKind.Effect, fx - 1, item.Name, factoryId);
+ else if (targetTrackId > 0 && Engine.TrackMidiEffectCount(targetTrackId) is var midi && midi > midiBefore)
+ _deviceChain.RememberPreset(targetTrackId, DeviceChainView.ChainKind.Midi, midi - 1, item.Name, factoryId);
+ return warn;
+ }
+
+ private HashSet<int> TrackIds()
+ {
+ var ids = new HashSet<int>();
+ for (int i = 0; i < Engine.TrackCount; i++)
+ if (Engine.TryGetTrackInfo(i, out var ti)) ids.Add(ti.Id);
+ return ids;
+ }
private void OnBrowserItemActivated(BrowserItem item)
{
diff --git a/src/managed/Nota.App/MainWindow.Dnd.cs b/src/managed/Nota.App/MainWindow.Dnd.cs
index dfe3c803..8a6ef9b9 100644
--- a/src/managed/Nota.App/MainWindow.Dnd.cs
+++ b/src/managed/Nota.App/MainWindow.Dnd.cs
@@ -265,9 +265,11 @@ public partial class MainWindow
}
// Refresh the device panel after an in-place instrument swap, but only when it's already
- // open on that track (never force it open).
+ // open on that track (never force it open). The old instrument's preset label is dropped
+ // either way so it doesn't reappear on the new one.
private void RefreshDeviceChainIfShowing(int trackId)
{
+ _deviceChain?.ForgetInstrumentState(trackId);
if (_deviceChain?.IsVisible == true && _deviceChain.TrackId == trackId) _deviceChain.Show(trackId);
}
diff --git a/src/managed/Nota.App/MainWindow.Files.cs b/src/managed/Nota.App/MainWindow.Files.cs
index 1ada16b8..6216847f 100644
--- a/src/managed/Nota.App/MainWindow.Files.cs
+++ b/src/managed/Nota.App/MainWindow.Files.cs
@@ -357,6 +357,7 @@ public partial class MainWindow
_editorTrackId = -1;
_editorClipIndex = -1;
DetailPanel.IsVisible = false;
+ _deviceChain?.ForgetCardState(); // per-track preset labels belong to the old project
Timeline.Refresh();
_session?.Refresh();
}