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) Record project versions on save
Egor Khindikaynen7bff4b53d1b5
diff --git a/src/managed/Nota.App/App.axaml.cs b/src/managed/Nota.App/App.axaml.csindex 2af1b4f2..d877db5a 100644--- a/src/managed/Nota.App/App.axaml.cs+++ b/src/managed/Nota.App/App.axaml.cs@@ -38,6 +38,7 @@ public partial class App : Avalonia.Applicationservices.AddSingleton<IPluginStore, PluginStore>();services.AddSingleton<IPresetLibrary, PresetLibrary>();services.AddSingleton<IProjectStore, ProjectStore>();+ services.AddSingleton<IProjectHistory>(_ => new ProjectHistory(AppInfo.Version));services.AddSingleton<IPresetStore, PresetStore>();services.AddSingleton<IFactoryPresets, FactoryPresetCatalog>();services.AddSingleton<IPresetAudition, PresetAudition>();diff --git a/src/managed/Nota.App/MainWindow.Files.cs b/src/managed/Nota.App/MainWindow.Files.csindex 106d27d8..c902e4a0 100644--- a/src/managed/Nota.App/MainWindow.Files.cs+++ b/src/managed/Nota.App/MainWindow.Files.cs@@ -184,6 +184,7 @@ public partial class MainWindowprivate void OnMenuOpen(object? sender, EventArgs e) => _ = DoOpenAsync();private void OnMenuSave(object? sender, EventArgs e) => _ = DoSaveAsync(saveAs: false);private void OnMenuSaveAs(object? sender, EventArgs e) => _ = DoSaveAsync(saveAs: true);+ private void OnMenuSaveVersion(object? sender, EventArgs e) => _ = SaveVersionWithNoteAsync();private async Task DoOpenAsync(){@@ -275,52 +276,42 @@ public partial class MainWindow});}- /// <summary>Saves the project (prompting for a location when unnamed or Save As).+ /// <summary>Saves the project (prompting for a location when unnamed or Save As) and+ /// records a version in its history, with <paramref name="note"/> if given./// Returns true only if the bundle was actually written.</summary>- private async Task<bool> DoSaveAsync(bool saveAs)+ private async Task<bool> DoSaveAsync(bool saveAs, string? note = null){if (_vm is null) return false;string? dir = _projectPath;if (saveAs || dir is null){- Activate();- var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions- {- Title = "Save Nota project",- DefaultExtension = "nota",- SuggestedFileName = "Untitled.nota",- FileTypeChoices = new[]- {- new FilePickerFileType("Nota project") { Patterns = new[] { "*.nota" } }- },- });- var chosen = file?.TryGetLocalPath();- if (chosen is null) return false;- if (!chosen.EndsWith(".nota", StringComparison.OrdinalIgnoreCase)) chosen += ".nota";- // The save panel may drop an empty placeholder file at the path; the- // bundle is a folder, so clear it before writing.- if (System.IO.File.Exists(chosen)) System.IO.File.Delete(chosen);- dir = chosen;+ dir = await PickProjectPathAsync("Save Nota project", "Untitled.nota");+ if (dir is null) return false;}+ string? previousPath = _projectPath;try{+ // Save As over another project replaces it — its history goes with it.+ if (previousPath is null || !SamePath(previousPath, dir)) DropReplacedHistory(dir);var warnings = _projects.Save(Engine, TransportSnapshot(), dir);_learn?.SaveMappings(dir); // MIDI-learn mappings ride in the bundle sidecar_modular?.SaveLayout(dir); // modular-editor node/island positions (sidecar)Timeline.SaveSections(dir); // arrangement song sections (sidecar)SaveFreezeLinks(dir); // live-freeze links (v1.1) ride in the bundle sidecar_analysis.AdoptInto(dir); // analysis cached while unsaved moves into the bundle+ string? historyNote = RecordVersion(dir, previousPath, note); // after every sidecar is written_projectPath = dir;RecordRecentProject(dir); // surface it on the welcome screen next launchUpdateWindowTitle();MarkProjectClean();App.Services.GetRequiredService<ILogSink>().Info($"Saved project '{System.IO.Path.GetFileName(dir)}' · {warnings.Count} warning(s)");- _vm.StatusText = warnings.Count == 0+ _vm.StatusText = (warnings.Count == 0? $"Saved {System.IO.Path.GetFileName(dir)}"- : $"Saved {System.IO.Path.GetFileName(dir)} — {warnings.Count} unsupported item(s) skipped: {warnings[0]}";+ : $"Saved {System.IO.Path.GetFileName(dir)} — {warnings.Count} unsupported item(s) skipped: {warnings[0]}")+ + historyNote;return true;}catch (Exception ex)@@ -331,6 +322,29 @@ public partial class MainWindow}}+ /// <summary>Asks where to put a new <c>.nota</c> bundle. Null if the panel was dismissed.</summary>+ private async Task<string?> PickProjectPathAsync(string title, string suggestedName)+ {+ Activate();+ var file = await StorageProvider.SaveFilePickerAsync(new FilePickerSaveOptions+ {+ Title = title,+ DefaultExtension = "nota",+ SuggestedFileName = suggestedName,+ FileTypeChoices = new[]+ {+ new FilePickerFileType("Nota project") { Patterns = new[] { "*.nota" } }+ },+ });+ var chosen = file?.TryGetLocalPath();+ if (chosen is null) return null;+ if (!chosen.EndsWith(".nota", StringComparison.OrdinalIgnoreCase)) chosen += ".nota";+ // The save panel may drop an empty placeholder file at the path; the+ // bundle is a folder, so clear it before writing.+ if (System.IO.File.Exists(chosen)) System.IO.File.Delete(chosen);+ return chosen;+ }+// --- unsaved-changes tracking ------------------------------------------// Manifest fingerprint as of the last New / Open / Save (null = never clean, e.g. adiff --git a/src/managed/Nota.App/MainWindow.History.cs b/src/managed/Nota.App/MainWindow.History.csnew file mode 100644index 00000000..8654cd7f--- /dev/null+++ b/src/managed/Nota.App/MainWindow.History.cs@@ -0,0 +1,157 @@+// SPDX-License-Identifier: AGPL-3.0-only+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.+//+// Project version history in the window: every save records a version (Save As carries+// the history to the new bundle), "Save Version with Note…" attaches a note, and a version+// can be switched to in place or opened as a copy. Switching writes the version's files+// into the bundle and reopens it, so undo starts fresh — as after Open.++using System;+using System.IO;+using System.Linq;+using System.Threading.Tasks;+using Microsoft.Extensions.DependencyInjection;+using Nota.Application;++namespace Nota.App;++public partial class MainWindow+{+ private IProjectHistory _history = default!;++ /// <summary>The open project's history changed (a version was recorded, switched to, or+ /// the project itself changed). The History tab listens.</summary>+ internal event Action? HistoryChanged;++ private bool KeepVersionHistory+ => App.Services.GetRequiredService<ISettingsService>().Current.KeepVersionHistory;++ // Called by the save after the manifest and every sidecar are written. Returns a+ // 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 "";+ try+ {+ // Save As: the new bundle gets the whole history and the audio its versions use.+ if (previousPath is not null && !SamePath(previousPath, dir)) _history.CopyTo(previousPath, dir);+ var version = _history.Commit(dir, note);+ // Nothing changed since the current version: the note goes onto that version.+ if (version is null && note is not null && _history.Read(dir).HeadVersion is { } head)+ _history.SetNote(dir, head.Id, head.Note is { Length: > 0 } old ? old + "\n" + note : note);+ HistoryChanged?.Invoke();+ return "";+ }+ catch (Exception ex) when (ex is ProjectHistoryException or IOException or UnauthorizedAccessException)+ {+ App.Services.GetRequiredService<ILogSink>().Error("Recording a project version failed", ex);+ return $" · version not recorded: {ex.Message}";+ }+ }++ // 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)+ {+ if (!Directory.Exists(dir)) return;+ try { _history.Erase(dir); }+ catch (Exception ex) when (ex is IOException or UnauthorizedAccessException)+ {+ App.Services.GetRequiredService<ILogSink>().Error("Clearing a replaced project's history failed", ex);+ }+ }++ private async Task SaveVersionWithNoteAsync()+ {+ if (_vm is null) return;+ if (!KeepVersionHistory)+ {+ _vm.StatusText = "Version history is turned off in Settings.";+ return;+ }+ var note = await new TextPromptWindow("Save version", "What changed in this version?")+ .ShowDialog<string?>(this);+ if (note is null) return;+ await DoSaveAsync(saveAs: false, note);+ }++ /// <summary>Switches the open project to <paramref name="versionId"/>: offers to save+ /// unsaved changes first, restores the version's files and reopens the bundle.</summary>+ internal async Task<bool> SwitchToVersionAsync(string versionId)+ {+ if (_vm is null || _projectPath is not { } dir) return false;+ if (!await ConfirmLeaveChangesAsync("Switch version",+ "Save your changes as a new version before switching?")) return false;+ try+ {+ _history.Checkout(dir, versionId);+ }+ catch (Exception ex) when (ex is ProjectHistoryException or IOException or UnauthorizedAccessException)+ {+ App.Services.GetRequiredService<ILogSink>().Error("Switching project version failed", ex);+ _vm.StatusText = $"Couldn't switch version: {ex.Message}";+ return false;+ }+ OpenProject(dir);+ HistoryChanged?.Invoke();+ if (_history.Read(dir).HeadVersion is { } v) _vm.StatusText = $"Switched to {DescribeVersion(v)}";+ return true;+ }++ /// <summary>Opens <paramref name="versionId"/> as a new project next to this one — a full+ /// copy (history included) whose current version is the chosen one.</summary>+ internal async Task<bool> OpenVersionAsCopyAsync(string versionId)+ {+ if (_vm is null || _projectPath is not { } src) return false;+ if (!await ConfirmLeaveChangesAsync("Open version as copy",+ "Save your changes before opening the copy?")) return false;+ var version = _history.Read(src).Versions.FirstOrDefault(v => v.Id == versionId);+ if (version is null) return false;++ string suggested = $"{Path.GetFileNameWithoutExtension(src)} ({version.CreatedAt.LocalDateTime:yyyy-MM-dd HH.mm}).nota";+ var dst = await PickProjectPathAsync("Open version as a new project", suggested);+ if (dst is null) return false;+ if (SamePath(src, dst) || (Directory.Exists(dst) && Directory.EnumerateFileSystemEntries(dst).Any()))+ {+ _vm.StatusText = "Choose a new name for the copy — it can't replace an existing project.";+ return false;+ }+ try+ {+ _history.CopyTo(src, dst);+ _history.Checkout(dst, versionId);+ }+ catch (Exception ex) when (ex is ProjectHistoryException or IOException or UnauthorizedAccessException)+ {+ App.Services.GetRequiredService<ILogSink>().Error("Opening a project version as a copy failed", ex);+ _vm.StatusText = $"Couldn't open the version: {ex.Message}";+ return false;+ }+ OpenProject(dst);+ HistoryChanged?.Invoke();+ _vm.StatusText = $"Opened {DescribeVersion(version)} as {Path.GetFileName(dst)}";+ return true;+ }++ // Save / Don't Save / Cancel when leaving a project with unsaved edits. True to go on.+ private async Task<bool> ConfirmLeaveChangesAsync(string title, string message)+ {+ if (!HasUnsavedChanges()) return true;+ var choice = await new SaveChangesWindow(title, message, ProjectDisplayName(), UnsavedAgeText(),+ () => DoSaveAsync(saveAs: false))+ .ShowDialog<SaveChoice>(this);+ return choice != SaveChoice.Cancel;+ }++ // "the version “With bass” (12 Oct, 14:32)" / "the version of 12 Oct, 14:32".+ private static string DescribeVersion(ProjectVersion v)+ {+ string when = v.CreatedAt.LocalDateTime.ToString("d MMM, HH:mm", NotaNum.Culture);+ return v.Label is { Length: > 0 } label ? $"the version “{label}” ({when})" : $"the version of {when}";+ }++ private static bool SamePath(string a, string b)+ => string.Equals(Path.GetFullPath(a).TrimEnd(Path.DirectorySeparatorChar),+ Path.GetFullPath(b).TrimEnd(Path.DirectorySeparatorChar),+ OperatingSystem.IsLinux() ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase);+}diff --git a/src/managed/Nota.App/MainWindow.axaml b/src/managed/Nota.App/MainWindow.axamlindex 213bd20d..66dee2bb 100644--- a/src/managed/Nota.App/MainWindow.axaml+++ b/src/managed/Nota.App/MainWindow.axaml@@ -25,6 +25,7 @@<NativeMenuItem Header="Open…" Click="OnMenuOpen" Gesture="Cmd+O"/><NativeMenuItem Header="Save" Click="OnMenuSave" Gesture="Cmd+S"/><NativeMenuItem Header="Save As…" Click="OnMenuSaveAs" Gesture="Shift+Cmd+S"/>+ <NativeMenuItem Header="Save Version with Note…" Click="OnMenuSaveVersion" Gesture="Alt+Cmd+S"/><NativeMenuItemSeparator/><NativeMenuItem Header="Import audio…" Click="OnMenuImport" Gesture="Cmd+I"/><NativeMenuItem Header="Export audio…" Click="OnMenuExport" Gesture="Shift+Cmd+E"/>diff --git a/src/managed/Nota.App/MainWindow.axaml.cs b/src/managed/Nota.App/MainWindow.axaml.csindex b2a9dd6a..779c6729 100644--- a/src/managed/Nota.App/MainWindow.axaml.cs+++ b/src/managed/Nota.App/MainWindow.axaml.cs@@ -160,6 +160,7 @@ public partial class MainWindow : WindowMidiLearn.Bind(RecordBtn, MidiTarget.TransportRecord, "Record");_projects = App.Services.GetRequiredService<IProjectStore>();+ _history = App.Services.GetRequiredService<IProjectHistory>();_presets = App.Services.GetRequiredService<IPresetStore>();_factory = App.Services.GetRequiredService<IFactoryPresets>();_kits = App.Services.GetRequiredService<IDrumKits>();diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.csindex 4c071918..625514a4 100644--- a/src/managed/Nota.App/PreferencesWindow.cs+++ b/src/managed/Nota.App/PreferencesWindow.cs@@ -886,6 +886,13 @@ public sealed partial class PreferencesWindow : NotaWindow// keys (see IsKeyToken) is drawn as one key-cap per token; a gesture is plain text.private static readonly (string Title, (string Key, string Action)[] Rows)[] ShortcutGroups ={+ ("FILE", new[]+ {+ ("⌘N ⌘O", "New project / open a project"),+ ("⌘S ⌘⇧S", "Save (records a version) / save as"),+ ("⌥⌘S", "Save a version with a note"),+ ("⌘I ⌘⇧E", "Import audio / export audio"),+ }),("TRANSPORT", new[]{("Space", "Play / Stop"),diff --git a/src/managed/Nota.Application/Settings.cs b/src/managed/Nota.Application/Settings.csindex b394b7bc..81349c5f 100644--- a/src/managed/Nota.Application/Settings.cs+++ b/src/managed/Nota.Application/Settings.cs@@ -34,6 +34,8 @@ public sealed class Settings/// <summary>Show the welcome screen (recent projects launcher) on startup. On by default;/// toggled from the welcome screen's "Show on startup" checkbox.</summary>public bool ShowWelcomeOnStartup { get; set; } = true;+ /// <summary>Record a project version on every save (the History tab). On by default.</summary>+ public bool KeepVersionHistory { get; set; } = true;/// <summary>Run the built-in MCP server so an AI (Claude Desktop / Claude Code) can drive the/// live app. Off by default; loopback-only. Toggled in Preferences.</summary>public bool McpEnabled { get; set; }diff --git a/src/managed/Nota.Infrastructure/Persistence/ProjectHistory.cs b/src/managed/Nota.Infrastructure/Persistence/ProjectHistory.csindex 7aeead5e..e72380e2 100644--- a/src/managed/Nota.Infrastructure/Persistence/ProjectHistory.cs+++ b/src/managed/Nota.Infrastructure/Persistence/ProjectHistory.cs@@ -238,6 +238,9 @@ 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));+/// <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>internal static IReadOnlySet<string>? PinnedBinaries(string bundleDir)diff --git a/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs b/src/managed/Nota.Infrastructure/Persistence/ProjectService.csindex 6011b872..8f057aed 100644--- a/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs+++ b/src/managed/Nota.Infrastructure/Persistence/ProjectService.cs@@ -842,7 +842,8 @@ public sealed class ProjectService/// <summary>Writes the document (and its referenced samples) into the `.nota`/// bundle folder. Binaries are content-named, so ones already on disk are skipped;/// each new one is written temp + rename. Atomic manifest (temp + rename); backs up- /// any existing manifest into <c>backups/</c>; then deletes binaries the manifest no+ /// any existing manifest into <c>backups/</c> (unless the bundle keeps a version history);+ /// then deletes binaries the manifest no/// longer references. Sample data is read from <paramref name="engine"/> (the one/// <see cref="Capture"/> read from).</summary>public static void Save(ProjectDocument doc, string bundleDir, IAudioEngine engine)@@ -870,7 +871,7 @@ public sealed class ProjectService}string manifest = Path.Combine(bundleDir, ManifestName);- if (File.Exists(manifest))+ if (File.Exists(manifest) && !ProjectHistory.Exists(bundleDir)) // the version history supersedes backups/{string backups = Path.Combine(bundleDir, "backups");Directory.CreateDirectory(backups);