feat(app): editor view models for every section, preset cards and render actions

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-02 17:14:48 +00:00
1 parent e6d1317aab
commit f6ad822fbb
15 files changed
+2666 -6

No files matched your search

+265
View File
@@ -0,0 +1,265 @@
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;
namespace Titano.App.Editor;
/// <summary>
/// Camera (BRIEF §12.3): output aspect and crop placement, 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 =
[
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 } }, 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 } }, Placement),
];
AddKeyCommand = new RelayCommand(AddKey, () => !Editor.IsBusy && Keys.All(k => k.Frame != Editor.CurrentIndex));
RemoveKeyCommand = new RelayCommand(RemoveKey, () => !Editor.IsBusy && SelectedKey >= 0);
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; }
private IReadOnlyList<CameraKey> Keys => Editor.Session.Project.Camera.Keyframes;
public override void Refresh()
{
base.Refresh();
var points = Keys.OrderBy(k => k.Frame).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.OrderBy(k => k.Frame).ToList();
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 void OnCurrentFrameChanged() => OnPropertyChanged(nameof(Playhead));
private static string Placement(double value) => value == 0 ? Loc.L("Editor.Value.Centred") : value.ToString("+0.00;−0.00", Loc.Culture);
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.Select((k, i) => (k, i)).First(t => t.k.Frame == frame).i;
}
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(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 and the time-remap curve (output time → source
/// position, Fritsch–Carlson as the render evaluates it), with the plan in numbers.
/// </summary>
public sealed class TimeTab : EditorTab
{
private Func<double, double>? _evaluator;
private string? _planText;
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")),
];
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>"3,600 frames → 2 min 30 s · 24 fps".</summary>
public string? PlanText { get => _planText; private set => Set(ref _planText, value); }
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;
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));
}
/// <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 void OnCurrentFrameChanged() => OnPropertyChanged(nameof(Playhead));
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);
}
}