test(app): editor history, saver retry, merge, preview re-solve and capture scenes

- Tests for undo after adopted changes, run ending, saver retries and stop,
  the local source refusing unsaved writes, re-solves without decoding and equal
  to a fresh preparation, 1:1 pictures, waveform, crop margins and the values of
  the Optimise toast; the Windows smoke test checks Render, Batch, the waveform,
  1:1, the window title and the hidden idle job bar.
- The capture sample has a manual value and camera keyframes; the capture adds
  the overlays, the waveform, the Optimise toast and Export.html's tool state.
- Crop margins live in a WPF-free class; a discarded change stops retrying.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
This commit is contained in:
Claude committed 2026-10-03 10:44:21 +00:00
1 parent 25e85aee57
commit fa5699e6f3
15 files changed
+462 -53

No files matched your search

+11 -2
View File
@@ -15,6 +15,7 @@ using Titano.Core.Imaging;
using Titano.Core.Imaging.Decoders;
using Titano.Core.Metadata;
using Titano.Core.Model;
using Titano.Core.Project;
using Titano.Core.Video;
using Titano.Data;
using Titano.Data.Archiving;
@@ -91,7 +92,8 @@ public sealed class SampleData
/// <summary>
/// The sequence editor's sample: a second archive holding a synthetic harbour sunset of real JPEG frames with Exif
/// (flicker, two received exposure steps, white-balance drift, a horizon), indexed by a scan, analysed (light and
/// deep, saved as <c>analysis.json</c>), advised into <c>project.json</c> and given two past renders.
/// deep, saved as <c>analysis.json</c>), advised into <c>project.json</c> with one manual value and three camera
/// keyframes, and given two past renders.
/// </summary>
/// <returns>The sequence id to open in the editor.</returns>
public async Task<Guid> FillEditorAsync()
@@ -119,7 +121,14 @@ public sealed class SampleData
var sequence = content.Sequence;
deep.Save(new ArchivePaths(root).Sequence(sequence.Folder).AnalysisPath);
var advice = Advisor.Recommend(content.Light, deep, SequenceContext.FromFrames(content.Frames));
await source.SaveProjectAsync(Advisor.Apply(content.Project, advice), content.Project, CancellationToken.None);
// As a user leaves it: the advice applied, one value taken over by hand (Sun track) and a slow push-in.
var advised = Advisor.Apply(content.Project, advice);
var project = advised with
{
Exposure = advised.Exposure with { DeflickerStrength = advised.Exposure.DeflickerStrength.WithManual(0.8) },
Camera = advised.Camera with { Keyframes = [new CameraKey(0, 0.5, 0.5, 1, 0), new CameraKey(48, 0.6, 0.46, 1.4, 0), new CameraKey(95, 0.64, 0.4, 1.9, 0)] },
};
await source.SaveProjectAsync(project, content.Project, CancellationToken.None);
await db.Sequences.RecordAnalysisAsync(id, SequenceStatus.AnalyzedLight | SequenceStatus.AnalyzedDeep | SequenceStatus.HasWarnings, SequenceStatus.None,
advice.Findings.Count(f => f.Severity >= FindingSeverity.Warning), AnalysisSummary.From(deep).ToJson());
foreach (var (preset, codec, width, height, daysAgo, bytes) in new[] { ("4K archive", "hevc", 3840, 2160, 7, 2_210_000_000L), ("1080p share", "h264", 1920, 1080, 3, 412_000_000L) })
+3 -32
View File
@@ -12,15 +12,6 @@ using Titano.Ui.Visuals;
namespace Titano.App.Editor;
/// <summary>Margins of the free crop, in the order of <c>CameraTab.Margins</c> (opposites differ in the lowest bit).</summary>
public enum CropSide
{
Left,
Right,
Top,
Bottom,
}
/// <summary>
/// Camera (BRIEF §12.3): the free crop of the frame (margins), the output aspect and its placement inside the crop, and
/// virtual-camera keyframes edited as a zoom curve over the sequence (X = frame, Y = zoom) with the selected keyframe's
@@ -31,11 +22,6 @@ public sealed class CameraTab : EditorTab
/// <summary>Zoom at the top of the curve editor.</summary>
public const double MaxZoom = 4;
/// <summary>Largest crop margin; opposite margins together leave at least <see cref="MinCropSize"/> of the frame.</summary>
public const double MaxCropMargin = 0.45;
public const double MinCropSize = 0.1;
private int _selectedKey = -1;
public CameraTab(EditorViewModel editor)
@@ -169,25 +155,10 @@ public sealed class CameraTab : EditorTab
OnPropertyChanged(nameof(RemoveKeyToolTip));
}
/// <summary>A margin of the free crop (<see cref="CameraSettings.Crop"/>, normalised x, y, width, height); all zero = the whole frame.</summary>
/// <summary>A margin of the free crop (<see cref="CropMargins"/>); all zero = the whole frame.</summary>
private static NumberRow CropRow(EditorSession session, CropSide side, string headerKey) => new(session, headerKey, "Tooltips.Editor.Camera.Crop", 0,
MaxCropMargin, 0.01, p => Margins(p.Camera.Crop)[(int)side], (p, v) => p with { Camera = p.Camera with { Crop = WithMargin(p.Camera.Crop, side, v) } },
v => Formatting.Percent(v));
/// <summary>Left, right, top and bottom margins of a crop rectangle.</summary>
private static double[] Margins(double[]? crop) => crop is [var x, var y, var w, var h] && new[] { x, y, w, h }.All(double.IsFinite)
? [double.Clamp(x, 0, 1), double.Clamp(1 - x - w, 0, 1), double.Clamp(y, 0, 1), double.Clamp(1 - y - h, 0, 1)]
: [0, 0, 0, 0];
private static double[]? WithMargin(double[]? crop, CropSide side, double value)
{
var margins = Margins(crop);
var opposite = (int)side ^ 1;
margins[(int)side] = double.Clamp(value, 0, double.Min(MaxCropMargin, 1 - MinCropSize - margins[opposite]));
if (margins.All(m => m == 0)) return null;
var (left, right, top, bottom) = (margins[0], margins[1], margins[2], margins[3]);
return [left, top, 1 - left - right, 1 - top - bottom];
}
CropMargins.MaxMargin, 0.01, p => CropMargins.Of(p.Camera.Crop)[(int)side],
(p, v) => p with { Camera = p.Camera with { Crop = CropMargins.With(p.Camera.Crop, side, v) } }, v => Formatting.Percent(v));
private Point ToPoint(CameraKey key) => new(Editor.FrameCount > 1 ? (double)key.Frame / (Editor.FrameCount - 1) : 0, (key.Zoom - 1) / (MaxZoom - 1));
+37
View File
@@ -0,0 +1,37 @@
namespace Titano.App.Editor;
/// <summary>Margins of the free crop, in the order of <see cref="CropMargins.Of"/> (opposites differ in the lowest bit).</summary>
public enum CropSide
{
Left,
Right,
Top,
Bottom,
}
/// <summary>
/// The Camera tab's crop margins over <c>CameraSettings.Crop</c> (a normalised x, y, width, height rectangle, null for the
/// whole frame): each margin at most <see cref="MaxMargin"/>, opposite margins leaving at least <see cref="MinSize"/>.
/// </summary>
public static class CropMargins
{
public const double MaxMargin = 0.45;
public const double MinSize = 0.1;
/// <summary>Left, right, top and bottom margins of <paramref name="crop"/> (zeros for none or an invalid one, which the render ignores too).</summary>
public static double[] Of(double[]? crop) => crop is [var x, var y, var w, var h] && double.IsFinite(x + y + w + h)
? [double.Clamp(x, 0, 1), double.Clamp(1 - x - w, 0, 1), double.Clamp(y, 0, 1), double.Clamp(1 - y - h, 0, 1)]
: [0, 0, 0, 0];
/// <summary><paramref name="crop"/> with one margin changed; null when no margin is left (the whole frame).</summary>
public static double[]? With(double[]? crop, CropSide side, double value)
{
var margins = Of(crop);
var opposite = (int)side ^ 1;
margins[(int)side] = double.Clamp(value, 0, double.Min(MaxMargin, 1 - MinSize - margins[opposite]));
if (margins.All(m => m == 0)) return null;
var (left, right, top, bottom) = (margins[0], margins[1], margins[2], margins[3]);
return [left, top, 1 - left - right, 1 - top - bottom];
}
}
+5 -1
View File
@@ -156,11 +156,15 @@ public sealed class EditorSession : IAsyncDisposable
/// <summary>Stores pending changes now; false when the save failed (the change stays pending and is retried).</summary>
public Task<bool> FlushAsync() => _saver.FlushAsync();
/// <summary>Stores what is pending one last time and releases the source; callers that must not lose an edit flush and ask first.</summary>
/// <summary>
/// Stores what is pending one last time, stops retrying and releases the source; callers that must not lose an edit
/// flush and ask first (<c>SequenceViewModel.ConfirmCloseAsync</c>).
/// </summary>
public async ValueTask DisposeAsync()
{
History.Changed -= OnProjectChanged;
if (!await _saver.FlushAsync()) Log.Warning("editor", $"The last change of {Content.Sequence.DisplayTitle} was not saved", _saver.LastError);
_saver.Stop();
await Source.DisposeAsync();
}
+1 -1
View File
@@ -152,7 +152,7 @@ public sealed class ExposureTab : EditorTab
if (content.Deep is { Regions: not null } withSky && withSky.Frames.SkyLogLuminance.Any(v => v is not null))
{
series.Add(new ChartSeries(Loc.L("Editor.Chart.Sky"), withSky.Frames.SkyLogLuminance.Select(v => v ?? double.NaN).ToArray(), "Brush.Region")
{ Dash = LineDash.Dashed });
{ Dash = LineDash.Dashed });
legend.Add(new ChartLegendItem(Loc.L("Editor.Chart.Sky"), "Brush.Region", LegendSwatch.DashedLine));
}
}
+3
View File
@@ -113,9 +113,12 @@ public sealed class PreviewRenderer(SequenceContent content, ISequenceSource sou
if (Cached(project) is { } cached) return cached;
var key = Key(project);
var measured = await MeasureAsync(project, cancellationToken).ConfigureAwait(false);
// Nothing is measured again: white balance comes from the measuring preparation, and a stabilisation it could
// not solve (its warning is kept) is not tried again.
var solveProject = project with
{
Exposure = project.Exposure with { WhiteBalanceSmoothing = project.Exposure.WhiteBalanceSmoothing.WithManual(false) },
Motion = measured.Stabilization is null ? project.Motion with { Stabilize = project.Motion.Stabilize.WithManual(false) } : project.Motion,
};
var solved = await RenderPreparation.PrepareAsync(Input(solveProject, Reuse(measured, project)), Options, null, cancellationToken).ConfigureAwait(false);
var corrections = solved with
+16 -2
View File
@@ -18,6 +18,7 @@ public sealed class ProjectSaver(Func<ProjectSettings, Task> save, TimeSpan dela
private ProjectSettings? _pending;
private bool _running;
private bool _flushRequested;
private bool _stopped;
private int _failures;
private CancellationTokenSource? _wait;
@@ -42,6 +43,7 @@ public sealed class ProjectSaver(Func<ProjectSettings, Task> save, TimeSpan dela
TaskCompletionSource start;
lock (_gate)
{
if (_stopped) return;
_pending = project;
if (_running) return;
_running = true;
@@ -67,6 +69,17 @@ public sealed class ProjectSaver(Func<ProjectSettings, Task> save, TimeSpan dela
}
}
/// <summary>Drops what is pending and stops retrying (the editor closed and the user chose to discard the change).</summary>
public void Stop()
{
lock (_gate)
{
_stopped = true;
_pending = null;
_wait?.Cancel();
}
}
private async Task LoopAsync(Task started)
{
await started;
@@ -118,13 +131,14 @@ public sealed class ProjectSaver(Func<ProjectSettings, Task> save, TimeSpan dela
lock (_gate)
{
// A newer change contains this one (projects are whole snapshots); otherwise this one waits for the retry.
_pending ??= next;
if (!_stopped) _pending ??= next;
failures = ++_failures;
Complete(false);
}
LastError = ex;
wait = TimeSpan.FromSeconds(double.Min(MaxRetryDelay.TotalSeconds, double.Pow(2, failures)));
Failed?.Invoke(ex, failures);
// Flushes learn the outcome after the failure was reported.
lock (_gate) Complete(false);
}
}
}
+30 -6
View File
@@ -114,8 +114,12 @@ public static class ScreenCapture
}
}
/// <summary>The sequence editor on the synthetic sunset: every section in both themes (<c>sequence-&lt;tab&gt;-&lt;theme&gt;.png</c>).</summary>
private static async Task<int> CaptureEditorAsync(Window window, ShellViewModel shell, SampleData sample, string directory)
/// <summary>
/// The sequence editor on the synthetic sunset: every section in both themes (<c>sequence-&lt;tab&gt;-&lt;theme&gt;.png</c>,
/// the Camera tab with a keyframe selected, the Export tab as Export.html with the crop mask and no compare), then
/// the preview overlays, the waveform and the "what changed" toast of Optimise all.
/// </summary>
private static async Task<int> CaptureEditorAsync(MainWindow window, ShellViewModel shell, SampleData sample, string directory)
{
var written = 0;
var id = await sample.FillEditorAsync();
@@ -126,22 +130,42 @@ public static class ScreenCapture
Log.Warning("capture", "The editor sample did not open");
return 0;
}
foreach (var camera in editor.Tabs.OfType<CameraTab>()) camera.SelectedKey = 1;
foreach (var theme in Themes)
{
ThemeManager.Apply(theme);
foreach (var tab in editor.Tabs)
{
editor.SelectedTab = tab;
editor.IsCompare = tab is not ExportTab;
editor.CurrentIndex = tab is ExportTab ? 40 : 45;
await Settle(window);
if (!await editor.WhenIdleAsync(TimeSpan.FromSeconds(30))) Log.Warning("capture", $"The {tab.Key} section was still busy");
written += await SaveAsync(window, directory, "sequence-" + tab.Key.ToLowerInvariant(), theme);
written += await SaveEditorAsync(window, editor, directory, "sequence-" + tab.Key.ToLowerInvariant(), theme);
}
editor.SelectedTab = editor.Exposure;
editor.IsCompare = true;
editor.ShowVectors = editor.ShowRegions = true;
written += await SaveEditorAsync(window, editor, directory, "sequence-exposure-overlays", theme);
editor.ShowVectors = editor.ShowRegions = false;
editor.Exposure.ChartMode = ExposureChart.Waveform;
written += await SaveEditorAsync(window, editor, directory, "sequence-exposure-waveform", theme);
editor.Exposure.ChartMode = ExposureChart.Luminance;
editor.OptimiseAllCommand.Execute(null);
written += await SaveEditorAsync(window, editor, directory, "sequence-optimise", theme);
editor.Session.Undo();
foreach (var toast in window.Toasts.Toasts.ToList()) window.Toasts.Dismiss(toast);
}
editor.SelectedTab = editor.Exposure;
return written;
}
private static async Task<int> SaveEditorAsync(Window window, EditorViewModel editor, string directory, string screen, AppTheme theme)
{
await Settle(window);
if (!await editor.WhenIdleAsync(TimeSpan.FromSeconds(30))) Log.Warning("capture", $"{screen} was still busy");
return await SaveAsync(window, directory, screen, theme);
}
private static async Task<int> SaveAsync(Window window, string directory, string screen, AppTheme theme, ShellViewModel? waitForThumbnails = null)
{
await Settle(window);