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.

(fix) Review leftovers from #413 and #425 (#497)

Chris Laupamaf295a21d15f5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 788afb71..e3589b8a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -258,6 +258,10 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.
returns, then the master.
### Fixed
+- **Leftovers from the History multi-delete and MIDI CC lane changes** (#496): a failed delete
+ of several versions no longer reports success over its error; drawing a controller curve
+ while recording is no longer cancelled by the recording's refresh, in any lane; the main
+ window's minimum height follows the interface scale again when the clip editor is fitted.
- **Take one track out of a group** (#488, #489): **Remove from group** in a grouped track's
menu, and ⌘⇧G (Ctrl+Shift+G) on it, take just that track out — it lands right after the
group, which keeps its other tracks and its effects. Before, **Ungroup** there dissolved the
diff --git a/src/managed/Nota.App/HistoryView.cs b/src/managed/Nota.App/HistoryView.cs
index a3d475de..05bc8a06 100644
--- a/src/managed/Nota.App/HistoryView.cs
+++ b/src/managed/Nota.App/HistoryView.cs
@@ -154,8 +154,7 @@ internal sealed class HistoryView : UserControl
.ToList()
: all;
_list.ItemsSource = rows;
- for (int i = 0; i < rows.Count; i++)
- if (keep.Contains(rows[i].Version.Id)) _list.Selection.Select(i);
+ foreach (int i in HistoryGraph.KeptSelection(rows, keep)) _list.Selection.Select(i);
ShowSelection();
_empty.Text = problem
@@ -404,17 +403,15 @@ internal sealed class HistoryView : UserControl
var menu = new MenuFlyout();
menu.Items.Add(MenuKit.Header(Loc.Plural("history.versions_n", rows.Count), null, ""));
menu.Items.Add(new Separator());
- var del = new MenuItem { Header = DeleteManyLabel(deletable.Count), Icon = MenuKit.Icon(GlyphKind.Trash), IsEnabled = deletable.Count > 0 };
- del.Classes.Add("danger");
+ var del = MenuKit.Danger(DeleteManyLabel(deletable.Count), GlyphKind.Trash, () => _ = DeleteSelected(deletable),
+ enabled: deletable.Count > 0);
if (deletable.Count < rows.Count) ToolTip.SetTip(del, Loc.T("history.the_current_version_stays"));
- del.Click += (_, _) => _ = DeleteSelected(deletable);
menu.Items.Add(del);
return menu;
}
// Every selected version but the current one, which can't be deleted.
- private static List<ProjectVersion> Deletable(IEnumerable<HistoryRow> rows)
- => rows.Where(r => !r.IsHead).Select(r => r.Version).ToList();
+ private static List<ProjectVersion> Deletable(IEnumerable<HistoryRow> rows) => HistoryGraph.Deletable(rows);
private static string DeleteManyLabel(int count) => count == 1 ? Loc.T("history.delete_version_2") : Loc.Plural("history.delete_versions_n", count);
@@ -452,8 +449,9 @@ internal sealed class HistoryView : UserControl
Loc.T("common.delete"), Loc.T("common.cancel")).ShowDialog<bool>(owner);
if (!ok) return;
long freed = 0;
- Apply(() => freed = _history.DeleteMany(_dir, versions.Select(v => v.Id).ToList()));
- _host.ReportStatus(Loc.F("history.freed", Loc.Plural("history.deleted_versions", versions.Count), NotaNum.Bytes(freed)));
+ // A failed delete keeps Apply's error on the status line instead of claiming success.
+ if (Apply(() => freed = _history.DeleteMany(_dir, versions.Select(v => v.Id).ToList())))
+ _host.ReportStatus(Loc.F("history.freed", Loc.Plural("history.deleted_versions", versions.Count), NotaNum.Bytes(freed)));
}
private async Task DeleteSelected(IReadOnlyList<ProjectVersion> versions)
@@ -465,8 +463,9 @@ internal sealed class HistoryView : UserControl
Loc.T("common.delete"), Loc.T("common.cancel")).ShowDialog<bool>(owner);
if (!ok) return;
long freed = 0;
- Apply(() => freed = _history.DeleteMany(_dir, versions.Select(v => v.Id).ToList()));
- _host.ReportStatus(Loc.F("history.freed", Loc.Plural("history.deleted_versions", versions.Count), NotaNum.Bytes(freed)));
+ // A failed delete keeps Apply's error on the status line instead of claiming success.
+ if (Apply(() => freed = _history.DeleteMany(_dir, versions.Select(v => v.Id).ToList())))
+ _host.ReportStatus(Loc.F("history.freed", Loc.Plural("history.deleted_versions", versions.Count), NotaNum.Bytes(freed)));
}
private async Task Prompt(string title, string prompt, string? initial, Action<string> apply)
@@ -485,16 +484,20 @@ internal sealed class HistoryView : UserControl
if (ok) Apply(() => _history.Delete(_dir, v.Id));
}
- // Runs a history edit, reporting a failure on the status line, then rebuilds.
- private void Apply(Action edit)
+ // Runs a history edit, reporting a failure on the status line, then rebuilds. True when
+ // the edit went through.
+ private bool Apply(Action edit)
{
- if (_dir is null) return;
+ if (_dir is null) return false;
+ bool ok = true;
try { edit(); }
catch (Exception ex) when (ex is ProjectHistoryException or System.IO.IOException or UnauthorizedAccessException)
{
+ ok = false;
_host.ReportStatus(Loc.F("history.couldnt_change_the_version", ex.Message));
}
Refresh();
+ return ok;
}
// --- text ----------------------------------------------------------------
diff --git a/src/managed/Nota.App/MainWindow.Detail.cs b/src/managed/Nota.App/MainWindow.Detail.cs
index 8b610e1c..cbad4ad4 100644
--- a/src/managed/Nota.App/MainWindow.Detail.cs
+++ b/src/managed/Nota.App/MainWindow.Detail.cs
@@ -1322,7 +1322,7 @@ public partial class MainWindow
// minimum. The Mixer grows back toward the height the user chose; a fit never changes it.
private void FitBottomPanels()
{
- if (_detailMaximized) { MinHeight = _baseWindowMinHeight; return; } // the Detail row is all there is
+ if (_detailMaximized) { SetWindowDesignMinHeight(_baseWindowMinHeight); return; } // the Detail row is all there is
double total = BodyGrid.Bounds.Height;
double mixer = _mixerDocked ? Math.Max(_mixerWanted, _mixerRow.MinHeight) : 0;
if (total > 0)
@@ -1332,7 +1332,11 @@ public partial class MainWindow
double minimumBody = _mainRow.MinHeight
+ (DetailPanel.IsVisible ? _detailRow.MinHeight + _detailSplitRow.ActualHeight : 0)
+ (_mixerDocked ? _mixerRow.MinHeight + _mixerSplitRow.ActualHeight : 0);
- MinHeight = Math.Max(_baseWindowMinHeight, ClientSize.Height - total + minimumBody);
+ // BodyGrid and its rows measure in design units, the window's frame in screen units:
+ // bring the frame back to design units and let NotaUiScale scale the minimum, so
+ // it stays right at any interface scale and after the scale changes.
+ double chrome = ClientSize.Height / NotaUiScale.Factor - total;
+ SetWindowDesignMinHeight(Math.Max(_baseWindowMinHeight, chrome + minimumBody));
double room = total - _mainRow.MinHeight;
double detail = !DetailPanel.IsVisible ? 0 : _detailWanted > 0 ? Math.Max(_detailWanted, _detailRow.MinHeight) : Height(_detailRow);
double over = mixer + detail - room;
@@ -1350,6 +1354,17 @@ public partial class MainWindow
}
+ // The window's minimum height in design units; applied only when it changes, since the
+ // panels refit on every resize.
+ private double _windowDesignMinHeight = double.NaN;
+ private void SetWindowDesignMinHeight(double height)
+ {
+ height = Math.Round(height);
+ if (height == _windowDesignMinHeight) return;
+ _windowDesignMinHeight = height;
+ NotaUiScale.SetDesignMinHeight(this, height);
+ }
+
private void CloseDetail()
{
DetailPanel.IsVisible = false;
diff --git a/src/managed/Nota.App/PianoRollView.Controllers.cs b/src/managed/Nota.App/PianoRollView.Controllers.cs
index 8098252c..901a46f3 100644
--- a/src/managed/Nota.App/PianoRollView.Controllers.cs
+++ b/src/managed/Nota.App/PianoRollView.Controllers.cs
@@ -647,7 +647,7 @@ public sealed partial class PianoRollView
// The curve may have gained points while the button was down (a recording
// reload). Read it again and paint the stroke onto that, not onto the copy
// from pointer-down.
- _o.DropControllerCache();
+ _o.DropControllerCache(cancelGestures: false); // this gesture is the one finishing
_orig = _o.ControllerPoints(Ctl).ToList();
// A click without a drag is not a stroke. Committing it would write a point
// that the second press of a double-click then deletes.
diff --git a/src/managed/Nota.App/PianoRollView.cs b/src/managed/Nota.App/PianoRollView.cs
index 30cb9564..ff82d6bf 100644
--- a/src/managed/Nota.App/PianoRollView.cs
+++ b/src/managed/Nota.App/PianoRollView.cs
@@ -842,8 +842,11 @@ public sealed partial class PianoRollView : UserControl
for (int i = 0; i < _notes.Count; i++)
burstVel.Add((_notes[i].Pitch, _notes[i].StartBeat, _notes[i].Velocity));
}
- DropControllerCache();
+ // A reload of the same clip (recording reloads ~60 Hz) keeps a lane's drag going on
+ // the fresh curve; another clip cancels every lane's gesture.
+ DropControllerCache(cancelGestures: !sameController);
_ctlLane.OnClipReloaded(sameController);
+ foreach (var item in _controllerLanes) item.Lane.OnClipReloaded(sameController);
_ctlClip = (_set.ActiveClip.TrackId, _set.ActiveClip.ClipIndex);
ReplaceAll(notes, owners);
// What the engine holds is what was just loaded, before a held burst's velocities go
diff --git a/src/managed/Nota.Presentation/ViewModels/HistoryGraph.cs b/src/managed/Nota.Presentation/ViewModels/HistoryGraph.cs
index 5ca4eda5..82a20259 100644
--- a/src/managed/Nota.Presentation/ViewModels/HistoryGraph.cs
+++ b/src/managed/Nota.Presentation/ViewModels/HistoryGraph.cs
@@ -23,6 +23,15 @@ public sealed record HistoryRow(
public static class HistoryGraph
{
+ /// <summary>The selected versions a delete may remove: all but the current one (#228).</summary>
+ public static List<ProjectVersion> Deletable(IEnumerable<HistoryRow> selected)
+ => selected.Where(r => !r.IsHead).Select(r => r.Version).ToList();
+
+ /// <summary>After a refresh, the rows (by index) whose versions were selected before and
+ /// still exist.</summary>
+ public static List<int> KeptSelection(IReadOnlyList<HistoryRow> rows, IReadOnlySet<string> selectedIds)
+ => Enumerable.Range(0, rows.Count).Where(i => selectedIds.Contains(rows[i].Version.Id)).ToList();
+
public static IReadOnlyList<HistoryRow> Layout(ProjectHistoryState state)
{
var order = NewestFirst(state.Versions);
diff --git a/tests/Nota.SmokeTest/HistoryTests.cs b/tests/Nota.SmokeTest/HistoryTests.cs
index 39822f33..a68c5767 100644
--- a/tests/Nota.SmokeTest/HistoryTests.cs
+++ b/tests/Nota.SmokeTest/HistoryTests.cs
@@ -42,6 +42,14 @@ internal static class HistoryTests
var skew = Nota.Presentation.HistoryGraph.Layout(new ProjectHistoryState([V("a", null, 10), V("b", "a", 5)], "b"));
yield return (string.Concat(skew.Select(r => r.Version.Id)) == "ba" && skew.All(r => r.Lane == 0),
"a child is never drawn below its parent");
+
+ // Several selected versions (#228): a delete never takes the current one, and a refresh
+ // keeps every selected version that still exists.
+ yield return (string.Concat(Nota.Presentation.HistoryGraph.Deletable(linear).Select(v => v.Id)) == "ba",
+ "deleting a selection keeps the current version");
+ var after = Nota.Presentation.HistoryGraph.Layout(new ProjectHistoryState([V("a", null, 0), V("c", "a", 2)], "c"));
+ yield return (Nota.Presentation.HistoryGraph.KeptSelection(after, new HashSet<string> { "b", "a" }).SequenceEqual([1]),
+ "a refresh keeps the selected versions that still exist");
}
/// <summary>What each version changed (VersionDiff) and how it reads (VersionSummary).</summary>