The Server screen offers Open with proxies to viewers; the editor now shows the sequence with every change disabled and the reason in the tooltips, the session refuses edits, undo and Optimise, and the source refuses to store a change. Render says when the account may not render on the server. The event listener stops cleanly when the editor closes and a late progress event no longer brings a finished job back to running. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012iLMBNwBE2GnphAsu4cjaC
340 lines
15 KiB
C#
340 lines
15 KiB
C#
using System.Collections.ObjectModel;
|
||
using System.Windows;
|
||
using System.Windows.Input;
|
||
using Titano.App.Infrastructure;
|
||
using Titano.Core.Advice;
|
||
using Titano.Core.Export;
|
||
using Titano.Core.Localization;
|
||
using Titano.Core.Mathematics;
|
||
using Titano.Core.Project;
|
||
using Titano.Ui.Mvvm;
|
||
using Titano.Ui.Visuals;
|
||
|
||
namespace Titano.App.Editor;
|
||
|
||
/// <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
|
||
/// framing below.
|
||
/// </summary>
|
||
public sealed class CameraTab : EditorTab
|
||
{
|
||
/// <summary>Zoom at the top of the curve editor.</summary>
|
||
public const double MaxZoom = 4;
|
||
|
||
private int _selectedKey = -1;
|
||
|
||
public CameraTab(EditorViewModel editor)
|
||
: base(editor, "Camera", AdvisorSection.Camera)
|
||
{
|
||
var s = editor.Session;
|
||
Rows =
|
||
[
|
||
CropRow(s, CropSide.Left, "Editor.Camera.CropLeft"),
|
||
CropRow(s, CropSide.Right, "Editor.Camera.CropRight"),
|
||
CropRow(s, CropSide.Top, "Editor.Camera.CropTop"),
|
||
CropRow(s, CropSide.Bottom, "Editor.Camera.CropBottom"),
|
||
new AutoChoiceRow<string>(s, EditorSettings.Aspect, "Editor.Camera.Aspect", "Tooltips.Editor.Camera.Aspect",
|
||
[
|
||
new Choice("source", "Editor.Aspect.Source"), new Choice("16:9", "Editor.Aspect.Ratio", "16:9"), new Choice("21:9", "Editor.Aspect.Ratio", "21:9"),
|
||
new Choice("4:3", "Editor.Aspect.Ratio", "4:3"), new Choice("3:2", "Editor.Aspect.Ratio", "3:2"), new Choice("1:1", "Editor.Aspect.Ratio", "1:1"),
|
||
new Choice("9:16", "Editor.Aspect.Ratio", "9:16"), new Choice("4:5", "Editor.Aspect.Ratio", "4:5"),
|
||
]),
|
||
new NumberRow(s, "Editor.Camera.OffsetX", "Tooltips.Editor.Camera.OffsetX", -1, 1, 0.05, p => p.Camera.OffsetX,
|
||
(p, v) => p with { Camera = p.Camera with { OffsetX = v } }, EditorText.Placement),
|
||
new NumberRow(s, "Editor.Camera.OffsetY", "Tooltips.Editor.Camera.OffsetY", -1, 1, 0.05, p => p.Camera.OffsetY,
|
||
(p, v) => p with { Camera = p.Camera with { OffsetY = v } }, EditorText.Placement),
|
||
];
|
||
AddKeyCommand = new RelayCommand(AddKey, () => !Editor.IsLocked && Keys.All(k => k.Frame != Editor.CurrentIndex));
|
||
RemoveKeyCommand = new RelayCommand(RemoveKey, () => !Editor.IsLocked && SelectedKey >= 0);
|
||
CommitCurveCommand = new RelayCommand(CommitCurve);
|
||
Refresh();
|
||
}
|
||
|
||
/// <summary>Keyframes as curve points: X = frame / (count − 1), Y = (zoom − 1) / (<see cref="MaxZoom"/> − 1). Edited in place by the curve editor.</summary>
|
||
public ObservableCollection<Point> KeyPoints { get; } = [];
|
||
|
||
public int SelectedKey
|
||
{
|
||
get => _selectedKey;
|
||
set
|
||
{
|
||
if (!Set(ref _selectedKey, value)) return;
|
||
OnSelectedKeyChanged();
|
||
}
|
||
}
|
||
|
||
public bool HasSelectedKey => SelectedKey >= 0 && SelectedKey < Keys.Count;
|
||
|
||
/// <summary>Framing of the selected keyframe: centre (0–1) and zoom.</summary>
|
||
public double SelectedCenterX
|
||
{
|
||
get => HasSelectedKey ? Keys[SelectedKey].CenterX : 0.5;
|
||
set => EditSelected(k => k with { CenterX = double.Clamp(value, 0, 1) });
|
||
}
|
||
|
||
public double SelectedCenterY
|
||
{
|
||
get => HasSelectedKey ? Keys[SelectedKey].CenterY : 0.5;
|
||
set => EditSelected(k => k with { CenterY = double.Clamp(value, 0, 1) });
|
||
}
|
||
|
||
public double SelectedZoom
|
||
{
|
||
get => HasSelectedKey ? Keys[SelectedKey].Zoom : 1;
|
||
set => EditSelected(k => k with { Zoom = double.Clamp(value, 1, MaxZoom) });
|
||
}
|
||
|
||
public string SelectedZoomText => Loc.L("Editor.Value.Zoom", SelectedZoom.ToString("0.00", Loc.Culture));
|
||
|
||
/// <summary>"Keyframe 2 of 3 · frame 0413".</summary>
|
||
public string KeyText => HasSelectedKey
|
||
? Loc.L("Editor.Camera.KeyOf", SelectedKey + 1, Keys.Count, (Keys[SelectedKey].Frame + 1).ToString("D4", Loc.Culture))
|
||
: Loc.Plural("Editor.Camera.Keys", Keys.Count);
|
||
|
||
public double Playhead => Editor.FrameCount > 1 ? (double)Editor.CurrentIndex / (Editor.FrameCount - 1) : double.NaN;
|
||
|
||
public Func<double, string> XFormatter => x => EditorText.Position((int)double.Round(x * (Editor.FrameCount - 1)), Editor.FrameCount);
|
||
|
||
public Func<double, string> YFormatter { get; } = y => Loc.L("Editor.Value.Zoom", (1 + y * (MaxZoom - 1)).ToString("0.00", Loc.Culture));
|
||
|
||
public ICommand AddKeyCommand { get; }
|
||
|
||
public ICommand RemoveKeyCommand { get; }
|
||
|
||
/// <summary>What Add keyframe does, or why it cannot run now.</summary>
|
||
public string AddKeyToolTip => Editor.LockedToolTip
|
||
?? Loc.L(Keys.Any(k => k.Frame == Editor.CurrentIndex) ? "Tooltips.Editor.Camera.KeyExists" : "Tooltips.Editor.Camera.AddKey");
|
||
|
||
/// <summary>How to edit the keyframe curve, or why it waits.</summary>
|
||
public string CurveToolTip => Editor.LockedToolTip ?? Loc.L("Tooltips.Editor.Camera.Curve");
|
||
|
||
public string RemoveKeyToolTip => Editor.LockedToolTip ?? Loc.L(HasSelectedKey ? "Tooltips.Editor.Camera.RemoveKey" : "Tooltips.Editor.Camera.NoKey");
|
||
|
||
/// <summary>Run by the curve editor after each finished edit.</summary>
|
||
public ICommand CommitCurveCommand { get; }
|
||
|
||
/// <summary>Keyframes in frame order (the order of <see cref="KeyPoints"/>).</summary>
|
||
private List<CameraKey> Keys => [.. Editor.Session.Project.Camera.Keyframes.OrderBy(k => k.Frame)];
|
||
|
||
public override void Refresh()
|
||
{
|
||
base.Refresh();
|
||
var points = Keys.Select(ToPoint).ToList();
|
||
if (!points.SequenceEqual(KeyPoints))
|
||
{
|
||
KeyPoints.Clear();
|
||
foreach (var p in points) KeyPoints.Add(p);
|
||
}
|
||
if (SelectedKey >= Keys.Count) SelectedKey = Keys.Count - 1;
|
||
OnSelectedKeyChanged();
|
||
}
|
||
|
||
/// <summary>The curve editor finished an edit (add, move, delete): the points become the keyframes, keeping each one's framing.</summary>
|
||
public void CommitCurve()
|
||
{
|
||
var old = Keys;
|
||
var keys = new List<CameraKey>();
|
||
foreach (var point in KeyPoints.OrderBy(p => p.X))
|
||
{
|
||
var frame = (int)double.Round(point.X * double.Max(1, Editor.FrameCount - 1));
|
||
var zoom = 1 + double.Clamp(point.Y, 0, 1) * (MaxZoom - 1);
|
||
var nearest = old.MinBy(k => int.Abs(k.Frame - frame));
|
||
keys.Add(nearest is null ? new CameraKey(frame, 0.5, 0.5, zoom, 0) : nearest with { Frame = frame, Zoom = zoom });
|
||
}
|
||
Editor.Session.Edit(p => p with { Camera = p.Camera with { Keyframes = [.. keys.DistinctBy(k => k.Frame)] } });
|
||
}
|
||
|
||
public override void OnCurrentFrameChanged()
|
||
{
|
||
OnPropertyChanged(nameof(Playhead));
|
||
OnPropertyChanged(nameof(AddKeyToolTip));
|
||
}
|
||
|
||
public override void OnBusyChanged()
|
||
{
|
||
base.OnBusyChanged();
|
||
OnPropertyChanged(nameof(AddKeyToolTip));
|
||
OnPropertyChanged(nameof(RemoveKeyToolTip));
|
||
OnPropertyChanged(nameof(CurveToolTip));
|
||
}
|
||
|
||
/// <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,
|
||
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));
|
||
|
||
private void AddKey()
|
||
{
|
||
var frame = Editor.CurrentIndex;
|
||
var key = new CameraKey(frame, 0.5, 0.5, 1, 0);
|
||
Editor.Session.Edit(p => p with { Camera = p.Camera with { Keyframes = [.. p.Camera.Keyframes.Append(key).OrderBy(k => k.Frame)] } });
|
||
SelectedKey = Keys.FindIndex(k => k.Frame == frame);
|
||
}
|
||
|
||
private void RemoveKey()
|
||
{
|
||
if (!HasSelectedKey) return;
|
||
var frame = Keys[SelectedKey].Frame;
|
||
Editor.Session.Edit(p => p with { Camera = p.Camera with { Keyframes = [.. p.Camera.Keyframes.Where(k => k.Frame != frame)] } });
|
||
}
|
||
|
||
private void EditSelected(Func<CameraKey, CameraKey> change)
|
||
{
|
||
if (!HasSelectedKey) return;
|
||
var index = SelectedKey;
|
||
Editor.Session.Edit(p =>
|
||
{
|
||
var keys = p.Camera.Keyframes.OrderBy(k => k.Frame).ToList();
|
||
keys[index] = change(keys[index]);
|
||
return p with { Camera = p.Camera with { Keyframes = keys } };
|
||
}, "Camera.Key");
|
||
}
|
||
|
||
private void OnSelectedKeyChanged()
|
||
{
|
||
OnPropertyChanged(nameof(HasSelectedKey));
|
||
OnPropertyChanged(nameof(RemoveKeyToolTip));
|
||
OnPropertyChanged(nameof(SelectedCenterX));
|
||
OnPropertyChanged(nameof(SelectedCenterY));
|
||
OnPropertyChanged(nameof(SelectedZoom));
|
||
OnPropertyChanged(nameof(SelectedZoomText));
|
||
OnPropertyChanged(nameof(KeyText));
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// Time (BRIEF §12.3): timing mode, playback rate, fit-to duration, the plan chart (video frames each photo gets, cuts
|
||
/// marked, the plan in numbers) and the time-remap curve (output time → source position, Fritsch–Carlson as the render
|
||
/// evaluates it).
|
||
/// </summary>
|
||
public sealed class TimeTab : EditorTab
|
||
{
|
||
private Func<double, double>? _evaluator;
|
||
private string? _planText;
|
||
private IReadOnlyList<ChartSeries> _planSeries = [];
|
||
private IReadOnlyList<TimelineMarker> _planMarkers = [];
|
||
|
||
public TimeTab(EditorViewModel editor)
|
||
: base(editor, "Time", AdvisorSection.Timing)
|
||
{
|
||
var s = editor.Session;
|
||
Rows =
|
||
[
|
||
new AutoChoiceRow<TimingMode>(s, EditorSettings.TimingMode, "Editor.Time.Mode", "Tooltips.Editor.Time.Mode",
|
||
[
|
||
new Choice(TimingMode.Constant, "Editor.Timing.Constant"), new Choice(TimingMode.Adaptive, "Editor.Timing.Adaptive"),
|
||
new Choice(TimingMode.Interpolated, "Editor.Timing.Interpolated"), new Choice(TimingMode.Remapped, "Editor.Timing.Remapped"),
|
||
]),
|
||
new AutoChoiceRow<string>(s, EditorSettings.FrameRate, "Editor.Time.Rate", "Tooltips.Editor.Time.Rate",
|
||
[.. ExportPresets.FrameRates.Select(r => new Choice(FrameRateText.Format(r), "Editor.Value.Fps", EditorText.FrameRate(r)))]),
|
||
new NumberRow(s, "Editor.Time.Fit", "Tooltips.Editor.Time.Fit", 0, 600, 5, p => p.Timing.FitToSeconds ?? 0,
|
||
(p, v) => p with { Timing = p.Timing with { FitToSeconds = v > 0 ? v : null } },
|
||
v => v > 0 ? Formatting.Duration(TimeSpan.FromSeconds(v)) : Loc.L("Editor.Value.Off")),
|
||
];
|
||
CommitCurveCommand = new RelayCommand(CommitCurve);
|
||
Refresh();
|
||
}
|
||
|
||
/// <summary>Remap control points (output fraction → source fraction), edited in place by the curve editor.</summary>
|
||
public ObservableCollection<Point> RemapPoints { get; } = [];
|
||
|
||
/// <summary>The monotone spline through <see cref="RemapPoints"/>.</summary>
|
||
public Func<double, double>? Evaluator { get => _evaluator; private set => Set(ref _evaluator, value); }
|
||
|
||
/// <summary>Run by the curve editor after each finished edit.</summary>
|
||
public ICommand CommitCurveCommand { get; }
|
||
|
||
/// <summary>How to edit the remap curve, or why it waits.</summary>
|
||
public string CurveToolTip => Editor.LockedToolTip ?? Loc.L("Tooltips.Editor.Time.Curve");
|
||
|
||
/// <summary>"3,600 frames → 2 min 30 s · 24 fps".</summary>
|
||
public string? PlanText { get => _planText; private set => Set(ref _planText, value); }
|
||
|
||
/// <summary>Video frames each photo is shown for (0 = skipped by a speed-up, gap = excluded), over the sequence.</summary>
|
||
public IReadOnlyList<ChartSeries> PlanSeries { get => _planSeries; private set => Set(ref _planSeries, value); }
|
||
|
||
/// <summary>Cuts of the plan (deliberate pauses, gaps, long exclusion runs).</summary>
|
||
public IReadOnlyList<TimelineMarker> PlanMarkers { get => _planMarkers; private set => Set(ref _planMarkers, value); }
|
||
|
||
public IReadOnlyList<ChartLegendItem> PlanLegend { get; } = [new(Loc.L("Editor.Chart.Shown"), "Brush.Accent")];
|
||
|
||
public Func<double, string> PlanFormatter { get; } = v => v.ToString("0.#", Loc.Culture);
|
||
|
||
public double Playhead => Editor.FrameCount > 1 ? (double)Editor.CurrentIndex / (Editor.FrameCount - 1) : double.NaN;
|
||
|
||
public Func<double, string> XFormatter { get; } = x => Loc.L("Editor.Time.Output", (x * 100).ToString("0", Loc.Culture));
|
||
|
||
public Func<double, string> YFormatter { get; } = y => Loc.L("Editor.Time.Source", (y * 100).ToString("0", Loc.Culture));
|
||
|
||
public override void Refresh()
|
||
{
|
||
base.Refresh();
|
||
var curve = Editor.Session.Project.Timing.RemapCurve;
|
||
var points = curve.Select(p => new Point(p.X, p.Y)).ToList();
|
||
if (!points.SequenceEqual(RemapPoints))
|
||
{
|
||
RemapPoints.Clear();
|
||
foreach (var p in points) RemapPoints.Add(p);
|
||
}
|
||
Evaluator = Spline(points);
|
||
}
|
||
|
||
public override void OnPlanChanged()
|
||
{
|
||
if (Editor.Plan is not { } plan)
|
||
{
|
||
PlanText = null;
|
||
PlanSeries = [];
|
||
PlanMarkers = [];
|
||
return;
|
||
}
|
||
var render = plan.Setup.Plan;
|
||
PlanText = Loc.Plural("Editor.Time.Plan", render.Frames.Count, Formatting.Duration(TimeSpan.FromSeconds(render.DurationSeconds)),
|
||
EditorText.FrameRate(render.FrameRate));
|
||
var shown = new double[Editor.FrameCount];
|
||
Array.Fill(shown, double.NaN);
|
||
foreach (var index in render.IncludedFrames) shown[index] = 0;
|
||
foreach (var frame in render.Frames)
|
||
{
|
||
var index = int.Clamp((int)double.Round(frame.SourcePosition), 0, shown.Length - 1);
|
||
shown[index] = (double.IsNaN(shown[index]) ? 0 : shown[index]) + frame.Slots;
|
||
}
|
||
PlanSeries = [new ChartSeries(Loc.L("Editor.Chart.Shown"), shown, "Brush.Accent")];
|
||
PlanMarkers = [.. render.IncludedFrames.Where(render.IsCutBefore).Select(i => new TimelineMarker(i, MarkerKind.Warning, Loc.L("Editor.Marker.Cut")))];
|
||
}
|
||
|
||
/// <summary>The curve editor finished an edit: the points become the remap curve, and the timing mode follows it.</summary>
|
||
public void CommitCurve()
|
||
{
|
||
var curve = RemapPoints.OrderBy(p => p.X).Select(p => new CurvePoint(double.Clamp(p.X, 0, 1), double.Clamp(p.Y, 0, 1))).ToList();
|
||
Editor.Session.Edit(p => p with
|
||
{
|
||
Timing = p.Timing with
|
||
{
|
||
RemapCurve = curve,
|
||
Mode = EditorSettings.TimingMode.Effective(p, null) == TimingMode.Remapped ? p.Timing.Mode : p.Timing.Mode.WithManual(TimingMode.Remapped),
|
||
},
|
||
});
|
||
}
|
||
|
||
public override void OnCurrentFrameChanged() => OnPropertyChanged(nameof(Playhead));
|
||
|
||
public override void OnBusyChanged()
|
||
{
|
||
base.OnBusyChanged();
|
||
OnPropertyChanged(nameof(CurveToolTip));
|
||
}
|
||
|
||
private static Func<double, double>? Spline(IReadOnlyList<Point> points)
|
||
{
|
||
if (points.Count < 2) return null;
|
||
var ordered = points.OrderBy(p => p.X).DistinctBy(p => p.X).ToList();
|
||
if (ordered.Count < 2) return null;
|
||
var spline = new MonotoneSpline([.. ordered.Select(p => p.X)], [.. ordered.Select(p => p.Y)]);
|
||
return x => double.Clamp(spline.Evaluate(x), 0, 1);
|
||
}
|
||
}
|