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.

(feat) Settings → Downloads → AI Models: install and remove htdemucs and basic-pitch

Egor Khindikaynen174c5bbf02e4
diff --git a/src/managed/Nota.App/PreferencesWindow.Downloads.cs b/src/managed/Nota.App/PreferencesWindow.Downloads.cs
index fd297732..53a05252 100644
--- a/src/managed/Nota.App/PreferencesWindow.Downloads.cs
+++ b/src/managed/Nota.App/PreferencesWindow.Downloads.cs
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: AGPL-3.0-only
// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
//
-// Preferences → Downloads: one page for both registries, Plug-ins and Sample Packs, picked
-// with a switch beside the title (PreferencesWindow.Store.cs / .Samples.cs build each half).
+// Preferences → Downloads: one page for Plug-ins, Sample Packs and AI Models, picked with a
+// switch beside the title (PreferencesWindow.Store.cs / .Samples.cs / .Models.cs build each).
// The title, switch and intro scroll away; the filter / search / Refresh toolbar sticks to the
// top of the pane. It lives in an overlay above the ScrollViewer, held level with a spacer in
// the scrolled content until the spacer passes the top edge, and gets a hairline underneath
@@ -20,13 +20,13 @@ namespace Nota.App;
public sealed partial class PreferencesWindow
{
private const int DownloadsIndex = 4;
- private static readonly string[] DownloadSources = { "Plug-ins", "Sample Packs" };
- private int _downloadSource; // 0 = plug-ins, 1 = sample packs; kept for the window's life
+ private static readonly string[] DownloadSources = { "Plug-ins", "Sample Packs", "AI Models" };
+ private int _downloadSource; // 0 = plug-ins, 1 = sample packs, 2 = AI models; kept for the window's life
private Control DownloadsPane(Control header)
{
- var (toolbar, body) = _downloadSource == 0 ? StoreParts() : PackParts();
- var intro = Caption(_downloadSource == 0 ? StoreIntro : PacksIntro, muted: true);
+ var (toolbar, body) = _downloadSource switch { 0 => StoreParts(), 1 => PackParts(), _ => ModelParts() };
+ var intro = Caption(_downloadSource switch { 0 => StoreIntro, 1 => PacksIntro, _ => ModelsIntro }, muted: true);
intro.MaxWidth = 600;
intro.HorizontalAlignment = HorizontalAlignment.Left;
intro.Margin = new Thickness(0, 0, 0, 4);
@@ -63,6 +63,7 @@ public sealed partial class PreferencesWindow
VerticalAlignment = VerticalAlignment.Top, Child = toolbar,
RenderTransform = new TranslateTransform(),
};
+ if (toolbar is null) intro.Margin = new Thickness(0, 0, 0, 18); // no toolbar: the list follows the intro
var content = new StackPanel { Children = { titleRow, intro, spacer, body } };
var scroll = new ScrollViewer
{
@@ -78,6 +79,7 @@ public sealed partial class PreferencesWindow
((TranslateTransform)pinned.RenderTransform!).Y = Math.Max(0, top);
pinned.BorderBrush = top < 0 ? Hairline : Brushes.Transparent;
}
+ if (toolbar is null) return scroll;
scroll.ScrollChanged += (_, _) => Place();
pinned.SizeChanged += (_, _) => Place();
content.LayoutUpdated += (_, _) => Place();
diff --git a/src/managed/Nota.App/PreferencesWindow.Models.cs b/src/managed/Nota.App/PreferencesWindow.Models.cs
new file mode 100644
index 00000000..977b24d7
--- /dev/null
+++ b/src/managed/Nota.App/PreferencesWindow.Models.cs
@@ -0,0 +1,182 @@
+// SPDX-License-Identifier: AGPL-3.0-only
+// Copyright (c) 2026 Egor Khindikaynen (Nota). See LICENSES/ for license terms.
+//
+// Preferences → Downloads → AI Models: install / remove the models behind Separate Stems and
+// Convert to MIDI (IModelStore), and see the ONNX Runtime they share, which comes with the first
+// model and goes with the last. Shares the store's job state with Plug-ins and Sample Packs: one
+// download at a time, shown in the same dock. A model's busy key is "model:<id>".
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+using Avalonia;
+using Avalonia.Controls;
+using Avalonia.Layout;
+using Avalonia.Media;
+using Microsoft.Extensions.DependencyInjection;
+using Nota.Application;
+
+namespace Nota.App;
+
+public sealed partial class PreferencesWindow
+{
+ private readonly IModelStore _models = App.Services.GetRequiredService<IModelStore>();
+ private ContentControl? _modelList; // null while another pane is showing
+
+ private static string ModelKey(string id) => "model:" + id;
+
+ private const string ModelsIntro = "AI models that run on this computer: the audio you give them never leaves it. Each downloads once from where its authors publish it and is checked against the checksum Nota pins for it.";
+
+ // The AI Models third of Downloads (PreferencesWindow.Downloads.cs). No toolbar: the list is short.
+ private (Control? Toolbar, Control Body) ModelParts()
+ {
+ var list = _modelList = new ContentControl();
+ var body = new StackPanel { Spacing = 14, Children = { list } };
+ body.DetachedFromVisualTree += (_, _) => { if (_modelList == list) _modelList = null; };
+ RenderModelList();
+ return (null, body);
+ }
+
+ private void RenderModelList()
+ {
+ if (_modelList is null) return;
+ var rows = new List<Control>();
+ foreach (var m in _models.Models) rows.Add(ModelRow(m, runtime: false));
+ if (_models.Runtime is { } rt) rows.Add(ModelRow(rt, runtime: true));
+ else rows.Add(new TextBlock
+ {
+ Text = "ONNX Runtime has no build for this computer, so the models can't run here.",
+ FontSize = 12, Foreground = TextTertiary, Margin = new Thickness(16, 14),
+ });
+ _modelList.Content = Table(rows);
+ }
+
+ private Control ModelRow(StoreModel m, bool runtime)
+ {
+ bool installed = _models.IsInstalled(m.Id);
+ var text = new StackPanel
+ {
+ Spacing = 4,
+ Children =
+ {
+ new WrapPanel
+ {
+ Children =
+ {
+ new TextBlock { Text = m.Name, FontSize = 13, FontWeight = FontWeight.SemiBold, Foreground = TextPrimary, Margin = new Thickness(0, 0, 8, 0), VerticalAlignment = VerticalAlignment.Center },
+ new TextBlock { Text = m.Feature.ToUpperInvariant(), FontSize = 9, LetterSpacing = 0.7, FontFamily = NotaFonts.MonoFamily, Foreground = TextMuted, VerticalAlignment = VerticalAlignment.Center },
+ },
+ },
+ new TextBlock { Text = $"{m.Author} · {m.License}", FontSize = 10, FontFamily = NotaFonts.MonoFamily, Foreground = TextTertiary },
+ new TextBlock { Text = m.Description, FontSize = 12, LineHeight = 18, Foreground = TextSecondary, TextWrapping = TextWrapping.Wrap },
+ },
+ };
+
+ var actions = new StackPanel { Spacing = 8, MinWidth = 96, HorizontalAlignment = HorizontalAlignment.Right, VerticalAlignment = VerticalAlignment.Top };
+ bool busy = _storeBusyId is not null;
+ if (_storeBusyId == ModelKey(m.Id))
+ actions.Children.Add(StoreButton(installed ? "Removing…" : "Installing…", enabled: false, () => { }));
+ else if (installed)
+ {
+ actions.Children.Add(new StackPanel
+ {
+ Orientation = Orientation.Horizontal, Spacing = 6, Height = 26, HorizontalAlignment = HorizontalAlignment.Right,
+ Children = { Dot(Brass), new TextBlock { Text = "Installed", FontSize = 11, FontWeight = FontWeight.Medium, Foreground = Brass, VerticalAlignment = VerticalAlignment.Center } },
+ });
+ if (!runtime) actions.Children.Add(StoreLink("Remove", null, busy ? null : () => RemoveModel(m)));
+ }
+ else if (!runtime)
+ actions.Children.Add(StoreButton("Install", enabled: !busy && _models.Runtime is not null, () => InstallModel(m)));
+ else
+ actions.Children.Add(new TextBlock { Text = "Comes with a model", FontSize = 11, Foreground = TextTertiary, HorizontalAlignment = HorizontalAlignment.Right, Height = 26 });
+
+ long download = runtime || installed || _models.Runtime is null ? m.Size : _models.DownloadSize(m.Id);
+ var size = new TextBlock
+ {
+ Text = installed ? Megabytes(m.UnpackedSize) : Megabytes(download),
+ FontSize = 10, FontFamily = NotaFonts.MonoFamily, Foreground = TextTertiary, HorizontalAlignment = HorizontalAlignment.Right,
+ };
+ ToolTip.SetTip(size, installed ? "On disk"
+ : download > m.Size ? $"{Megabytes(m.Size)} model + {Megabytes(download - m.Size)} AI runtime, downloaded once"
+ : "Download");
+ actions.Children.Add(size);
+ var source = StoreLink("Source", GlyphKind.PopOut, () => _ = Launcher.LaunchUriAsync(new Uri(m.Source)));
+ ToolTip.SetTip(source, "Open the model's project page");
+ actions.Children.Add(source);
+
+ var grid = new Grid { ColumnDefinitions = new ColumnDefinitions("*,Auto"), ColumnSpacing = 16, Margin = new Thickness(16, 14, 14, 14) };
+ grid.Children.Add(text);
+ Grid.SetColumn(actions, 1);
+ grid.Children.Add(actions);
+ return grid;
+ }
+
+ private async void InstallModel(StoreModel m)
+ {
+ if (_storeBusyId is not null) return;
+ _storeBusyId = ModelKey(m.Id);
+ _storeBusySize = _models.DownloadSize(m.Id);
+ _storeProgress = new StoreProgress(0, "Downloading…");
+ SetStoreResult(null, sticky: true);
+ _storeCts ??= new CancellationTokenSource();
+ var job = _storeJobCts = CancellationTokenSource.CreateLinkedTokenSource(_storeCts.Token);
+ RenderStoreLists();
+ var progress = new Progress<StoreProgress>(r =>
+ {
+ if (job.IsCancellationRequested) return;
+ // Each download reports its own fraction; the dock's byte count would mix two files.
+ _storeBusySize = 0;
+ _storeProgress = r;
+ UpdateDock();
+ });
+ try
+ {
+ await _models.InstallAsync(m.Id, progress, job.Token);
+ SetStoreResult(m.Id == AiModels.Stems
+ ? $"{m.Name} is installed — right-click an audio clip and choose Separate Stems."
+ : $"{m.Name} is installed — Convert Melody and Convert Harmony now use it.", sticky: false);
+ }
+ catch (OperationCanceledException)
+ {
+ if (_storeCts is { IsCancellationRequested: false }) SetStoreResult($"Installing {m.Name} was cancelled.", sticky: false);
+ }
+ catch (StoreException e) { SetStoreResult(e.Message, sticky: true); }
+ catch (Exception e)
+ {
+ App.Services.GetRequiredService<ILogSink>().Error($"Installing model {m.Id} failed", e);
+ SetStoreResult($"Installing {m.Name} failed: {e.Message}", sticky: true);
+ }
+ finally
+ {
+ _storeBusyId = null;
+ _storeJobCts = null;
+ job.Dispose();
+ }
+ RenderStoreLists();
+ }
+
+ private async void RemoveModel(StoreModel m)
+ {
+ if (_storeBusyId is not null) return;
+ bool last = _models.Models.Count(x => _models.IsInstalled(x.Id)) == 1;
+ var ok = await new ConfirmWindow("Remove AI model",
+ $"Remove {m.Name}? {m.Feature} will offer to download it again." + (last ? " The AI runtime goes too." : ""),
+ "Remove", "Cancel").ShowDialog<bool>(this);
+ if (!ok) return;
+ _storeBusyId = ModelKey(m.Id);
+ _storeBusySize = 0;
+ _storeProgress = new StoreProgress(-1, $"Removing {m.Name}…");
+ SetStoreResult(null, sticky: true);
+ RenderStoreLists();
+ try
+ {
+ await Task.Run(() => _models.Uninstall(m.Id));
+ SetStoreResult($"{m.Name} was removed.", sticky: false);
+ }
+ catch (StoreException e) { SetStoreResult(e.Message, sticky: true); }
+ finally { _storeBusyId = null; }
+ RenderStoreLists();
+ }
+}
diff --git a/src/managed/Nota.App/PreferencesWindow.Samples.cs b/src/managed/Nota.App/PreferencesWindow.Samples.cs
index d9fde784..642380d1 100644
--- a/src/managed/Nota.App/PreferencesWindow.Samples.cs
+++ b/src/managed/Nota.App/PreferencesWindow.Samples.cs
@@ -374,11 +374,12 @@ public sealed partial class PreferencesWindow
RenderStoreLists();
}
- // Both lists, since a job in one disables the Install buttons of the other.
+ // Every list, since a job in one disables the Install buttons of the others.
private void RenderStoreLists()
{
RenderStoreList();
RenderPackList();
+ RenderModelList();
UpdateDock(); // RenderStoreList only reaches the dock while the Downloads pane is showing
}
}
diff --git a/src/managed/Nota.App/PreferencesWindow.cs b/src/managed/Nota.App/PreferencesWindow.cs
index 06bf57d4..479ce008 100644
--- a/src/managed/Nota.App/PreferencesWindow.cs
+++ b/src/managed/Nota.App/PreferencesWindow.cs
@@ -68,7 +68,7 @@ public sealed partial class PreferencesWindow : NotaWindow
("PLUG-INS", new[]
{
new Page("Plug-ins", "Where Nota looks for VST3", "M9 3 V7 M15 3 V7 M6 7 H18 V11 A6 6 0 0 1 6 11 Z M12 17 V21"),
- new Page("Downloads", "Plug-ins and sample packs", "M12 4 V15 M7 10 L12 15 L17 10 M5 19 H19"),
+ new Page("Downloads", "Plug-ins, sample packs and AI models", "M12 4 V15 M7 10 L12 15 L17 10 M5 19 H19"),
}),
("GENERAL", new[]
{