Nota — a free DAW for macOS, Windows and Linux. No subscription, no account — just open it and make music.
C# audioaudio-unitavaloniacpp20cross-platformdawdigital-audio-workstationdspjucelinux-audiomcp-servermidimusicmusic-productionpiano-rollplugin-hostsequencersynthesizervstvst3
(feat) Turn version history off, clean it up
Egor Khindikaynen28e21e97016b
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 2eeec13c..4aca13f6 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -25,7 +25,10 @@ Entry categories: `Added`, `Changed`, `Fixed`, `Removed`.Each version describes itself — "Added Bass · Tempo 120.00 → 124.00", "Mix of Vocals" — sothe list reads without notes. Name, note, star and delete versions from the right-click menu. **File → Save Version withNote…** (⌥⌘S) asks what changed. Versions share their audio, so a version costs only what it- adds. **Save As** takes the whole history to the new project.+ adds. **Save As** takes the whole history to the new project. The tab's menu clears out+ every unnamed version at once (named, starred, noted and branch-tip versions stay). History+ is on by default; **Settings → Library → Version history** turns it off after a warning —+ that erases the open project's history, and other projects' on their next save.### Changed- **Faster saves of projects with audio:** a save now writes only new recordings anddiff --git a/FEATURES.md b/FEATURES.mdindex ffa51535..a2992897 100644--- a/FEATURES.md+++ b/FEATURES.md@@ -49,7 +49,8 @@ JUCE module; the engine core is JUCE-free.**History** tab draws them as a branching tree (the current one has a brass dot), eachdescribed by what it changed ("Added Bass · Tempo 120.00 → 124.00"); switchto any version, open one as a copy, or name, note, star and delete versions. Saving on top- of an older version branches. **Save Version with Note…** (⌥⌘S). Versions share their+ of an older version branches. **Save Version with Note…** (⌥⌘S). The tab's menu deletes all+ unnamed versions at once; Settings → Library turns history off (erasing it, after a warning). Versions share theiraudio, so each costs only what it adds; **Save As** carries the history along.- **Start window**: the logo follows the theme, recent projects sit in one compact list withtheir dates — click to select, double-click (or the arrow keys and Return) to open.diff --git a/src/managed/Nota.App/HistoryView.cs b/src/managed/Nota.App/HistoryView.csindex 57a84334..2c7019d0 100644--- a/src/managed/Nota.App/HistoryView.cs+++ b/src/managed/Nota.App/HistoryView.cs@@ -51,6 +51,11 @@ internal sealed class HistoryView : UserControlMaxWidth = 220, Margin = new Thickness(20, 0),};private readonly Border _details = new() { BorderThickness = new Thickness(0, 1, 0, 0), Padding = new Thickness(10, 8, 10, 10) };+ private readonly Button _options = new()+ {+ Classes = { "ghost" }, Width = 22, Height = 22, Padding = new Thickness(0), Margin = new Thickness(6, 0, 0, 0),+ Content = new Path { Data = Geometry.Parse("M4 7 H20 M7 12 H17 M10 17 H14"), Stretch = Stretch.Uniform, Width = 12, Height = 10, StrokeThickness = 1.6, StrokeLineCap = PenLineCap.Round },+ };private ProjectHistoryState _state = ProjectHistoryState.Empty;private Dictionary<string, int> _numbers = new(); // version id -> 1-based number in save orderprivate string? _dir;@@ -62,10 +67,15 @@ internal sealed class HistoryView : UserControlvar caption = new TextBlock { Text = "VERSIONS", Classes = { "GroupLabel" }, VerticalAlignment = VerticalAlignment.Center };_summary.BindResource(TextBlock.ForegroundProperty, "Brush.TextTertiary");- var header = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), Height = RowH, Margin = new Thickness(10, 8, 10, 4) };+ var header = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto,Auto"), Height = RowH, Margin = new Thickness(10, 8, 6, 4) };header.Children.Add(caption);Grid.SetColumn(_summary, 1);header.Children.Add(_summary);+ Grid.SetColumn(_options, 2);+ header.Children.Add(_options);+ _options.Click += (_, _) => BuildOptionsMenu().ShowAt(_options);+ ((Path)_options.Content!).BindResource(Shape.StrokeProperty, "Brush.TextTertiary");+ ToolTip.SetTip(_options, "Clean up the history");_empty.BindResource(TextBlock.ForegroundProperty, "Brush.TextTertiary");_details.BindResource(Border.BackgroundProperty, "Brush.Panel");@@ -126,6 +136,7 @@ internal sealed class HistoryView : UserControl_empty.IsVisible = _empty.Text.Length > 0;ToolTip.SetTip(_empty, problem is null ? null : "Its versions can't be listed until the file .history/versions.json is repaired.");+ _options.IsVisible = rows.Count > 1;if (rows.Count == 0 || _dir is null) _summary.Text = "";else{@@ -290,6 +301,43 @@ internal sealed class HistoryView : UserControlreturn menu;}+ private MenuFlyout BuildOptionsMenu()+ {+ var menu = new MenuFlyout();+ var unnamed = UnnamedVersions();+ var clean = new MenuItem+ {+ Header = unnamed.Count == 0 ? "Delete unnamed versions…" : $"Delete {unnamed.Count} unnamed version{(unnamed.Count == 1 ? "" : "s")}…",+ Icon = MenuKit.Icon(GlyphKind.Trash),+ IsEnabled = unnamed.Count > 0,+ };+ clean.Click += (_, _) => _ = DeleteUnnamed(unnamed);+ menu.Items.Add(clean);+ return menu;+ }++ // Versions nobody marked as worth keeping: not current, unnamed, unstarred, without a note,+ // and not the latest version of a branch (that would lose the branch's last state).+ private List<ProjectVersion> UnnamedVersions()+ {+ var parents = _state.Versions.Select(v => v.Parent).OfType<string>().ToHashSet();+ return _state.Versions+ .Where(v => v.Id != _state.Head && v.Label is null && !v.Starred && v.Note is null && parents.Contains(v.Id))+ .ToList();+ }++ private async Task DeleteUnnamed(IReadOnlyList<ProjectVersion> versions)+ {+ if (TopLevel.GetTopLevel(this) is not Window owner || _dir is null || versions.Count == 0) return;+ bool ok = await new ConfirmWindow("Delete unnamed versions",+ $"Delete {versions.Count} version{(versions.Count == 1 ? "" : "s")} and the audio only they use? The current version, the latest version of each branch, and every named, starred or noted version stay. This can't be undone.",+ "Delete", "Cancel").ShowDialog<bool>(owner);+ if (!ok) return;+ long freed = 0;+ Apply(() => freed = _history.DeleteMany(_dir, versions.Select(v => v.Id).ToList()));+ _host.ReportStatus($"Deleted {versions.Count} version{(versions.Count == 1 ? "" : "s")} · {NotaNum.Bytes(freed)} freed");+ }+private async Task Prompt(string title, string prompt, string? initial, Action<string> apply){if (TopLevel.GetTopLevel(this) is not Window owner) return;diff --git a/src/managed/Nota.App/MainWindow.History.cs b/src/managed/Nota.App/MainWindow.History.csindex e8b8f470..9b3c28a4 100644--- a/src/managed/Nota.App/MainWindow.History.cs+++ b/src/managed/Nota.App/MainWindow.History.cs@@ -45,7 +45,12 @@ public partial class MainWindow : IHistoryHost// status-bar suffix when the version couldn't be recorded (the save itself stands).private string RecordVersion(string dir, string? previousPath, string? note){- if (!KeepVersionHistory) return "";+ if (!KeepVersionHistory)+ {+ // History is off: a project that still has one loses it on save (Settings warned).+ if (_history.Exists(dir)) EraseHistory(dir);+ return "";+ }try{// Save As: the new bundle gets the whole history and the audio its versions use.@@ -64,6 +69,26 @@ public partial class MainWindow : IHistoryHost}}+ // Settings → Version history was turned off (and confirmed): erase the open project's.+ private void OnVersionHistoryTurnedOff()+ {+ if (_projectPath is not { } dir || !_history.Exists(dir)) { HistoryChanged?.Invoke(); return; }+ long freed = EraseHistory(dir);+ if (_vm is not null) _vm.StatusText = $"Version history turned off · {NotaNum.Bytes(freed)} freed";+ }++ private long EraseHistory(string dir)+ {+ long freed = 0;+ try { freed = _history.Erase(dir); }+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)+ {+ App.Services.GetRequiredService<ILogSink>().Error("Erasing the project's version history failed", ex);+ }+ HistoryChanged?.Invoke();+ return freed;+ }+// Save As over an existing project replaces it, and its history with it — the new// project's own history (if any) is carried over after the save.private void DropReplacedHistory(string dir)diff --git a/src/managed/Nota.App/MainWindow.axaml.cs b/src/managed/Nota.App/MainWindow.axaml.csindex 4657d45e..5508a583 100644--- a/src/managed/Nota.App/MainWindow.axaml.cs+++ b/src/managed/Nota.App/MainWindow.axaml.cs@@ -321,6 +321,7 @@ public partial class MainWindow : WindowMainContent.Children.Add(_modular);vm.AutosaveRequested += OnAutosaveTick;+ vm.VersionHistoryTurnedOff += OnVersionHistoryTurnedOff;InitGamepad(); // poll pad buttons on each UI tick (live note source)Closing += OnMainWindowClosing; // clean-shutdown marker (M7-7)Opened += OnOpenedRecoveryCheck; // offer recovery snapshot (M7-7)diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.csindex 625514a4..6a4377e1 100644--- a/src/managed/Nota.App/PreferencesWindow.cs+++ b/src/managed/Nota.App/PreferencesWindow.cs@@ -71,7 +71,7 @@ public sealed partial class PreferencesWindow : NotaWindow}),("GENERAL", new[]{- new Page("Library", "Default save and sample locations", "M3 7 A1 1 0 0 1 4 6 H9 L11 8 H20 A1 1 0 0 1 21 9 V18 A1 1 0 0 1 20 19 H4 A1 1 0 0 1 3 18 Z"),+ new Page("Library", "Content folders and version history", "M3 7 A1 1 0 0 1 4 6 H9 L11 8 H20 A1 1 0 0 1 21 9 V18 A1 1 0 0 1 20 19 H4 A1 1 0 0 1 3 18 Z"),new Page("Appearance", "Theme and AI control", "M12 4 A8 8 0 1 0 12 20 Z M12 4 A8 8 0 0 1 12 20"),new Page("Shortcuts", "Keyboard reference", "M3 7 H21 V17 H3 Z M7 11 H7.01 M11 11 H11.01 M15 11 H15.01 M8 14 H16"),}),@@ -678,7 +678,25 @@ public sealed partial class PreferencesWindow : NotaWindowFolderRow("Projects",() => settings.Current.ProjectsFolder, () => settings.ResolvedProjectsFolder(),path => { settings.Current.ProjectsFolder = path; settings.Save(); _main.Browser.RebuildProjects(); }),- })));+ })), VersionHistorySection(_main));+ }++ // On by default. Turning it off erases history, so it asks first — and stays on if not confirmed.+ private Control VersionHistorySection(MainWindowViewModel main)+ {+ var row = (StackPanel)SwitchRow("Keep a version history of each project", main.Settings.Current.KeepVersionHistory, _ => { });+ var sw = (ToggleSwitch)row.Children[0];+ sw.Changed += async on =>+ {+ if (on) { main.SetKeepVersionHistory(true); return; }+ bool ok = await new ConfirmWindow("Turn off version history",+ "This erases the version history of the open project now, and of any other project the next time you save it. Older versions can't be brought back.",+ "Turn off and erase", "Cancel").ShowDialog<bool>(this);+ if (ok) main.SetKeepVersionHistory(false);+ else sw.IsOn = true;+ };+ return Section("VERSION HISTORY", 10, row,+ Caption("Every save records a version, listed in the browser's History tab. Versions share their audio, so each one costs only what it adds."));}private Control FolderRow(string label, Func<string> get, Func<string> resolved, Action<string> set)diff --git a/src/managed/Nota.Application/Ports/IProjectHistory.cs b/src/managed/Nota.Application/Ports/IProjectHistory.csindex 007cba34..9799ea0c 100644--- a/src/managed/Nota.Application/Ports/IProjectHistory.cs+++ b/src/managed/Nota.Application/Ports/IProjectHistory.cs@@ -75,6 +75,9 @@ public sealed class ProjectHistoryException(string message, Exception? inner = n/// (the caller then reopens the project). Saving on top of an older version branches.</summary>public interface IProjectHistory{+ /// <summary>Does the bundle keep a version history (even a damaged one)?</summary>+ bool Exists(string bundleDir);+/// <summary>All versions and the head. Empty when the bundle has no history yet.</summary>ProjectHistoryState Read(string bundleDir);@@ -94,6 +97,9 @@ public interface IProjectHistory/// Returns the bytes freed.</summary>long Delete(string bundleDir, string versionId);+ /// <summary>Deletes several versions at once (none of them the head). Returns the bytes freed.</summary>+ long DeleteMany(string bundleDir, IReadOnlyCollection<string> versionIds);+/// <summary>Deletes the whole history and every file only it needed.</summary>long Erase(string bundleDir);diff --git a/src/managed/Nota.Infrastructure/Persistence/ProjectHistory.cs b/src/managed/Nota.Infrastructure/Persistence/ProjectHistory.csindex 2cce9baa..6d8b6563 100644--- a/src/managed/Nota.Infrastructure/Persistence/ProjectHistory.cs+++ b/src/managed/Nota.Infrastructure/Persistence/ProjectHistory.cs@@ -176,16 +176,27 @@ public sealed partial class ProjectHistory : IProjectHistorypublic void SetStarred(string bundleDir, string versionId, bool starred)=> Edit(bundleDir, versionId, n => n.Starred = starred);- public long Delete(string bundleDir, string versionId)+ public bool Exists(string bundleDir) => File.Exists(Path.Combine(bundleDir, HistoryDir, VersionsFile));++ public long Delete(string bundleDir, string versionId) => DeleteMany(bundleDir, [versionId]);++ public long DeleteMany(string bundleDir, IReadOnlyCollection<string> versionIds){lock (Gate){var doc = Load(bundleDir) ?? throw new ProjectHistoryException("This project has no version history.");- var node = Find(doc, versionId) ?? throw new ProjectHistoryException("That version no longer exists.");- if (node.Id == doc.Head)+ var nodes = versionIds.Distinct().Select(id => Find(doc, id) ?? throw new ProjectHistoryException("That version no longer exists.")).ToList();+ if (nodes.Any(n => n.Id == doc.Head))throw new ProjectHistoryException("The current version can't be deleted — switch to another one first.");- foreach (var child in doc.Versions.Where(v => v.Parent == node.Id)) child.Parent = node.Parent;- doc.Versions.Remove(node);+ foreach (var node in nodes)+ {+ foreach (var child in doc.Versions.Where(v => v.Parent == node.Id))+ {+ child.Parent = node.Parent;+ child.Changes = null; // re-described against its new parent on the next read+ }+ doc.Versions.Remove(node);+ }Store(bundleDir, doc);return Collect(bundleDir, doc);}@@ -244,7 +255,7 @@ public sealed partial class ProjectHistory : IProjectHistory}/// <summary>Does the bundle keep a version history?</summary>- public static bool Exists(string bundleDir) => File.Exists(Path.Combine(bundleDir, HistoryDir, VersionsFile));+ internal static bool HasHistory(string bundleDir) => File.Exists(Path.Combine(bundleDir, HistoryDir, VersionsFile));/// <summary>Binaries any version references, for the save's prune to keep. Empty when/// there is no history; null when it can't be read — then nothing may be pruned.</summary>diff --git a/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs b/src/managed/Nota.Infrastructure/Persistence/ProjectService.csindex 8f057aed..692e687c 100644--- a/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs+++ b/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs@@ -871,7 +871,7 @@ public sealed class ProjectService}string manifest = Path.Combine(bundleDir, ManifestName);- if (File.Exists(manifest) && !ProjectHistory.Exists(bundleDir)) // the version history supersedes backups/+ if (File.Exists(manifest) && !ProjectHistory.HasHistory(bundleDir)) // the version history supersedes backups/{string backups = Path.Combine(bundleDir, "backups");Directory.CreateDirectory(backups);diff --git a/src/managed/Nota.Presentation/ViewModels/MainWindowViewModel.cs b/src/managed/Nota.Presentation/ViewModels/MainWindowViewModel.csindex 2ff6b40f..44abb0f5 100644--- a/src/managed/Nota.Presentation/ViewModels/MainWindowViewModel.cs+++ b/src/managed/Nota.Presentation/ViewModels/MainWindowViewModel.cs@@ -30,6 +30,19 @@ public sealed partial class MainWindowViewModel : ObservableObject, IDisposablepublic event Action? RecordingTick;/// <summary>Fired every ~30 s so the window can autosave a crash-recovery snapshot (M7-7).</summary>public event Action? AutosaveRequested;+ /// <summary>Version history was just turned off in Settings: the window erases the open+ /// project's history.</summary>+ public event Action? VersionHistoryTurnedOff;++ /// <summary>Turns version history on or off and persists it. Turning it off (the caller has+ /// confirmed) erases the open project's history; other projects lose theirs on their next save.</summary>+ public void SetKeepVersionHistory(bool on)+ {+ if (Settings.Current.KeepVersionHistory == on) return;+ Settings.Current.KeepVersionHistory = on;+ Settings.Save();+ if (!on) VersionHistoryTurnedOff?.Invoke();+ }[ObservableProperty] private string _engineInfo = "";[ObservableProperty] private string _statusText = "";diff --git a/tests/Nota.SmokeTest/HistoryTests.cs b/tests/Nota.SmokeTest/HistoryTests.csindex e6949e53..094f2a50 100644--- a/tests/Nota.SmokeTest/HistoryTests.cs+++ b/tests/Nota.SmokeTest/HistoryTests.cs@@ -114,6 +114,42 @@ internal static class HistoryTestsyield return (VersionSummary.Headline(new VersionChanges(), Bpm) is null, "nothing nameable → no headline");}+ /// <summary>Bulk delete (History tab clean-up) and Exists.</summary>+ public static IEnumerable<(bool Ok, string Label)> RunCleanup()+ {+ string dir = Path.Combine(Path.GetTempPath(), "nota-smoke-cleanup-" + Guid.NewGuid().ToString("N") + ".nota");+ IProjectHistory history = new ProjectHistory("0.0.0-test");+ try+ {+ using var e = new NotaEngine();+ yield return (!history.Exists(dir), "a fresh bundle has no history");+ var ids = new List<string>();+ var names = new[] { "Drums", "Bass", "Keys", "Pad" };+ foreach (var n in names)+ {+ e.SetTrackName(e.AddInstrumentTrack(), n);+ ProjectService.Save(ProjectService.Capture(e, new TransportState(120, 1, false, false), new List<string>()), dir, e);+ ids.Add(history.Commit(dir)!.Id);+ }+ yield return (history.Exists(dir), "a commit creates the history");++ bool refused = false;+ try { history.DeleteMany(dir, [ids[1], ids[3]]); } catch (ProjectHistoryException) { refused = true; }+ yield return (refused && history.Read(dir).Versions.Count == 4, "a batch with the current version is refused whole");++ history.DeleteMany(dir, [ids[1], ids[2]]);+ var left = history.Read(dir).Versions;+ var last = left.Single(v => v.Id == ids[3]);+ yield return (left.Count == 2 && last.Parent == ids[0], "deleting a run of versions links the rest up");+ yield return (last.Changes?.TracksAdded.SequenceEqual(["Bass", "Keys", "Pad"]) == true,+ $"the survivor is re-described against its new parent ({string.Join(", ", last.Changes?.TracksAdded ?? [])})");+ }+ finally+ {+ try { Directory.Delete(dir, true); } catch { }+ }+ }+public static IEnumerable<(bool Ok, string Label)> Run(){string tmp = Path.GetTempPath();diff --git a/tests/Nota.SmokeTest/Program.cs b/tests/Nota.SmokeTest/Program.csindex f9c2b0eb..49421791 100644--- a/tests/Nota.SmokeTest/Program.cs+++ b/tests/Nota.SmokeTest/Program.cs@@ -148,6 +148,7 @@ if (args.Length >= 1 && args[0] == "--history")foreach (var (ok, label) in HistoryTests.Run()) Check(ok, label);foreach (var (ok, label) in HistoryTests.RunGraph()) Check(ok, label);foreach (var (ok, label) in HistoryTests.RunSummary()) Check(ok, label);+ foreach (var (ok, label) in HistoryTests.RunCleanup()) Check(ok, label);Console.WriteLine(failures == 0 ? "HISTORY PASSED" : $"HISTORY FAILED ({failures})");return failures == 0 ? 0 : 1;}@@ -13605,6 +13606,7 @@ Console.WriteLine("-- project: version history --");foreach (var (ok, label) in HistoryTests.Run()) Check(ok, label);foreach (var (ok, label) in HistoryTests.RunGraph()) Check(ok, label);foreach (var (ok, label) in HistoryTests.RunSummary()) Check(ok, label);+foreach (var (ok, label) in HistoryTests.RunCleanup()) Check(ok, label);// --- get plug-ins: registry index, install/uninstall from local archives ---Console.WriteLine("-- get plug-ins: registry store --");