using Titano.Core.Advice; using Titano.Core.Localization; using Titano.Core.Project; using Titano.Ui.Visuals; namespace Titano.App.Editor; /// Motion (BRIEF §12.3): motion blur, flow quality and stabilisation, with the measured camera path (shake) chart. public sealed class MotionTab : EditorTab { private IReadOnlyList _series = []; private IReadOnlyList _legend = []; private string? _summary; public MotionTab(EditorViewModel editor) : base(editor, "Motion", AdvisorSection.Motion) { var s = editor.Session; // The same rule as the Edit path's (EditorSettings.Applies): a row shown n/a is never asked for. string? NoBlur(ProjectSettings p) => EditorSettings.Applies(EditorSettings.ShutterAngle, p, s.Content.Deep) ? null : Loc.L("Tooltips.Editor.NotApplicable.BlurOff"); string? NoFlow(ProjectSettings p) => EditorSettings.Applies(EditorSettings.FlowQuality, p, s.Content.Deep) ? null : Loc.L("Tooltips.Editor.NotApplicable.NoFlow"); string? NoStabilize(ProjectSettings p) => EditorSettings.Applies(EditorSettings.StabilizeSmoothing, p, s.Content.Deep) ? null : Loc.L("Tooltips.Editor.NotApplicable.StabilizeOff"); Rows = [ new AutoSwitchRow(s, EditorSettings.MotionBlur, "Editor.Motion.Blur", "Tooltips.Editor.Motion.Blur"), new AutoNumberRow(s, EditorSettings.ShutterAngle, "Editor.Motion.Shutter", "Tooltips.Editor.Motion.Shutter", 0, 360, 15, "0", NoBlur), new AutoChoiceRow(s, EditorSettings.FlowQuality, "Editor.Motion.Flow", "Tooltips.Editor.Motion.Flow", [ new Choice(FlowQualitySetting.Draft, "Editor.Flow.Draft"), new Choice(FlowQualitySetting.Balanced, "Editor.Flow.Balanced"), new Choice(FlowQualitySetting.Best, "Editor.Flow.Best"), ], NoFlow), new AutoSwitchRow(s, EditorSettings.Stabilize, "Editor.Motion.Stabilize", "Tooltips.Editor.Motion.Stabilize"), new AutoNumberRow(s, EditorSettings.StabilizeSmoothing, "Editor.Motion.Smoothing", "Tooltips.Editor.Motion.Smoothing", 2, 60, 1, "0", NoStabilize), ]; Refresh(); BuildChart(); } public IReadOnlyList Series { get => _series; private set => Set(ref _series, value); } public IReadOnlyList Legend { get => _legend; private set => Set(ref _legend, value); } /// "shake 0.42 px · crop 1.8 %". public string? Summary { get => _summary; private set => Set(ref _summary, value); } public Func YFormatter { get; } = v => Loc.L("Editor.Value.Pixels", v.ToString("0.#", Loc.Culture)); public override void OnContentChanged() { base.OnContentChanged(); BuildChart(); } /// The camera path: per-frame content shifts accumulated from the first frame (gaps hold the last position). private void BuildChart() { if (Editor.Session.Content.Deep is not { } deep) { Series = []; Legend = []; Summary = Loc.L("Editor.Chart.NotAnalysed"); return; } var x = Accumulate(deep.Frames.ShiftX); var y = Accumulate(deep.Frames.ShiftY); Series = [ new ChartSeries(Loc.L("Editor.Chart.PathX"), x, "Brush.Accent"), new ChartSeries(Loc.L("Editor.Chart.PathY"), y, "Brush.TextMuted") { Dash = LineDash.Dashed }, ]; Legend = [new ChartLegendItem(Loc.L("Editor.Chart.PathX"), "Brush.Accent"), new ChartLegendItem(Loc.L("Editor.Chart.PathY"), "Brush.TextMuted", LegendSwatch.DashedLine)]; var shake = deep.Shake; var parts = new List { Loc.L("Editor.Motion.ShakeValue", shake.RmsPx.ToString("0.00", Loc.Culture)), Loc.L("Editor.Motion.CropValue", (shake.CropCost * 100).ToString("0.0", Loc.Culture)), }; if (shake.PanDetected) parts.Add(Loc.L("Editor.Motion.PanValue", shake.PanPxPerFrame.ToString("0.0", Loc.Culture))); Summary = string.Join(Loc.Separator, parts); } private static double[] Accumulate(double?[] shifts) { var path = new double[shifts.Length]; double position = 0; for (var i = 0; i < shifts.Length; i++) { position += shifts[i] ?? 0; path[i] = position; } return path; } } /// Stack (BRIEF §12.3): median, mean or star-trail stacking; the chart shows the star field and cloud measurements. public sealed class StackTab : EditorTab { private IReadOnlyList _series = []; private IReadOnlyList _legend = []; private string? _summary; public StackTab(EditorViewModel editor) : base(editor, "Stack", AdvisorSection.Stack) { var s = editor.Session; Rows = [ new ChoiceRow(s, "Editor.Stack.Mode", "Tooltips.Editor.Stack.Mode", [ new Choice(StackSetting.None, "Editor.Value.Off"), new Choice(StackSetting.Median, "Editor.Stack.Median"), new Choice(StackSetting.Mean, "Editor.Stack.Mean"), new Choice(StackSetting.StarTrails, "Editor.Stack.StarTrails"), ], p => p.Stack.Mode, (p, v) => p with { Stack = p.Stack with { Mode = (StackSetting)v } }), new NumberRow(s, "Editor.Stack.Length", "Tooltips.Editor.Stack.Length", 3, 199, 2, p => p.Stack.Length, (p, v) => p with { Stack = p.Stack with { Length = (int)v } }, v => Loc.Plural("Editor.Value.Frames", (long)v), p => p.Stack.Mode == StackSetting.None ? Loc.L("Tooltips.Editor.NotApplicable.StackOff") : null), ]; Refresh(); BuildChart(); } /// The advisor never stacks on its own (a temporal median erases moving stars). public override bool CanOptimise => false; public IReadOnlyList Series { get => _series; private set => Set(ref _series, value); } public IReadOnlyList Legend { get => _legend; private set => Set(ref _legend, value); } public string? Summary { get => _summary; private set => Set(ref _summary, value); } public Func YFormatter { get; } = v => v.ToString("0.#", Loc.Culture); public override void OnContentChanged() { base.OnContentChanged(); BuildChart(); } private void BuildChart() { if (Editor.Session.Content.Deep is not { } deep) { Series = []; Legend = []; Summary = Loc.L("Editor.Chart.NotAnalysed"); return; } Series = [ new ChartSeries(Loc.L("Editor.Chart.Stars"), deep.Frames.StarDensity.Select(v => v ?? double.NaN).ToArray(), "Brush.Accent"), new ChartSeries(Loc.L("Editor.Chart.Clouds"), deep.Frames.CloudCoverage.Select(v => v is { } c ? c * 100 : double.NaN).ToArray(), "Brush.TextMuted") { Dash = LineDash.Dashed }, ]; Legend = [new ChartLegendItem(Loc.L("Editor.Chart.Stars"), "Brush.Accent"), new ChartLegendItem(Loc.L("Editor.Chart.Clouds"), "Brush.TextMuted", LegendSwatch.DashedLine)]; Summary = Loc.L(deep.Sky.StarField ? "Editor.Stack.StarField" : "Editor.Stack.NoStarField"); } }