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:
15 files changed
+2666
-6
No files matched your search
@@ -0,0 +1,675 @@
|
||||
using System.Collections;
|
||||
using System.Globalization;
|
||||
using System.Windows;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Threading;
|
||||
using Titano.App.Shell;
|
||||
using Titano.Core.Advice;
|
||||
using Titano.Core.Analysis;
|
||||
using Titano.Core.Diagnostics;
|
||||
using Titano.Core.Export;
|
||||
using Titano.Core.Localization;
|
||||
using Titano.Core.Model;
|
||||
using Titano.Core.Project;
|
||||
using Titano.Core.Render;
|
||||
using Titano.Core.Video;
|
||||
using Titano.Ui.Mvvm;
|
||||
using Titano.Ui.Visuals;
|
||||
|
||||
namespace Titano.App.Editor;
|
||||
|
||||
/// <summary>
|
||||
/// The sequence editor of one open sequence (BRIEF §12.3, Editor.html): header actions, the preview with its tools
|
||||
/// (wipe compare, zoom, overlays) rendered through the pipeline at preview size, the filmstrip with markers, the
|
||||
/// section tabs and the keyboard (space, arrows, Ctrl+Z/Y, Ctrl+0/1, Ctrl+R). Preview frames, corrections, the export
|
||||
/// plan and the card estimates are computed off the UI thread; each request cancels the previous one. While an analysis
|
||||
/// or render of this sequence runs, settings are disabled and viewing tools stay live.
|
||||
/// </summary>
|
||||
public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable
|
||||
{
|
||||
public const int DefaultPreviewEdge = 1280;
|
||||
private static readonly TimeSpan Debounce = TimeSpan.FromMilliseconds(150);
|
||||
|
||||
private readonly IReadOnlyList<IVideoEncoderProvider> _encoders;
|
||||
private readonly EncoderHost _host;
|
||||
private readonly Dispatcher _dispatcher;
|
||||
private readonly LatestRunner _preview = new(Debounce);
|
||||
private readonly LatestRunner _corrections = new(Debounce);
|
||||
private readonly LatestRunner _plans = new(Debounce);
|
||||
private readonly DispatcherTimer _player;
|
||||
private readonly Dictionary<Guid, Job> _jobs = [];
|
||||
private PreviewRenderer _renderer;
|
||||
private int _currentIndex;
|
||||
private EditorTab _selectedTab;
|
||||
private ImageSource? _previewImage;
|
||||
private ImageSource? _originalImage;
|
||||
private bool _isCompare = true;
|
||||
private bool _showVectors;
|
||||
private bool _showRegions;
|
||||
private bool _showCropMask;
|
||||
private PreviewZoomMode _zoomMode = PreviewZoomMode.Fit;
|
||||
private Rect _cropRect = new(0, 0, 1, 1);
|
||||
private IReadOnlyList<Point>? _regionBoundary;
|
||||
private IReadOnlyList<MotionVector>? _motionVectors;
|
||||
private int _previewEdge = DefaultPreviewEdge;
|
||||
private int _previewVersion;
|
||||
private bool _previewBusy;
|
||||
private RenderCorrections? _correctionsValue;
|
||||
private ExportPlan? _plan;
|
||||
private IReadOnlyList<TimelineMarker> _markers = [];
|
||||
private IThumbnailSource _thumbnails;
|
||||
private int _playLimit;
|
||||
private bool _disposed;
|
||||
|
||||
public EditorViewModel(ShellViewModel shell, EditorSession session, IReadOnlyList<IVideoEncoderProvider> encoders, EncoderHost host)
|
||||
{
|
||||
Shell = shell;
|
||||
Session = session;
|
||||
_encoders = encoders;
|
||||
_host = host;
|
||||
_dispatcher = Dispatcher.CurrentDispatcher;
|
||||
_renderer = new PreviewRenderer(session.Content, session.Source);
|
||||
Planner = new ExportPlanner(session.Content, encoders, host);
|
||||
_thumbnails = new EditorThumbnails(session.Source, session.Content.Count);
|
||||
_player = new DispatcherTimer(DispatcherPriority.Background, _dispatcher);
|
||||
_player.Tick += (_, _) => Advance();
|
||||
|
||||
Frames = new FramesTab(this);
|
||||
Exposure = new ExposureTab(this);
|
||||
Tabs = [Frames, Exposure, new MotionTab(this), new CameraTab(this), new TimeTab(this), new StackTab(this), new ExportTab(this)];
|
||||
_selectedTab = Exposure;
|
||||
_currentIndex = session.Project.HeroFrame is { } hero && (uint)hero < (uint)FrameCount ? hero : 0;
|
||||
RenderChoices = [.. ExportPresets.BuiltIn.Select(p => new Choice(p.Id, p.NameKey))];
|
||||
|
||||
BackCommand = new RelayCommand(() => Shell.Navigate(SectionKey.Library));
|
||||
AnalyseCommand = new AsyncRelayCommand(AnalyseAsync, () => !IsBusy);
|
||||
OptimiseAllCommand = new RelayCommand(OptimiseAll, () => !IsBusy);
|
||||
RenderCommand = new AsyncRelayCommand(() => RenderAsync(JobPriority.User, batch: false), () => CanRender);
|
||||
UndoCommand = new RelayCommand(() => Session.Undo(), () => !IsBusy && Session.History.CanUndo);
|
||||
RedoCommand = new RelayCommand(() => Session.Redo(), () => !IsBusy && Session.History.CanRedo);
|
||||
PlayCommand = new RelayCommand(() => TogglePlay(limit: 0));
|
||||
PreviewClipCommand = new RelayCommand(() => TogglePlay(limit: ClipFrames()));
|
||||
StepBackCommand = new RelayCommand(() => CurrentIndex--);
|
||||
StepForwardCommand = new RelayCommand(() => CurrentIndex++);
|
||||
FitCommand = new RelayCommand(() => ZoomMode = PreviewZoomMode.Fit);
|
||||
ActualSizeCommand = new RelayCommand(() => ZoomMode = PreviewZoomMode.Actual);
|
||||
|
||||
session.ProjectChanged += OnProjectChanged;
|
||||
session.ContentChanged += OnContentChanged;
|
||||
session.SaveFailed += OnSaveFailed;
|
||||
if (shell.Services.Jobs is { } jobs) jobs.JobChanged += OnJobChanged;
|
||||
UpdateMarkers();
|
||||
RequestCorrections();
|
||||
RequestPlan();
|
||||
RequestPreview(immediate: true);
|
||||
}
|
||||
|
||||
public ShellViewModel Shell { get; }
|
||||
|
||||
public EditorSession Session { get; }
|
||||
|
||||
public ExportPlanner Planner { get; private set; }
|
||||
|
||||
public string Title => Session.Content.Sequence.DisplayTitle;
|
||||
|
||||
/// <summary>"3,600 frames · Canon EOS R5 · 2 s interval · 2 h 00 m · 3 warnings".</summary>
|
||||
public string Summary => EditorText.Summary(Session.Content, Session.Advice.Findings.Count(f => f.Severity >= FindingSeverity.Warning));
|
||||
|
||||
public FramesTab Frames { get; }
|
||||
|
||||
public ExposureTab Exposure { get; }
|
||||
|
||||
public IReadOnlyList<EditorTab> Tabs { get; }
|
||||
|
||||
public EditorTab SelectedTab
|
||||
{
|
||||
get => _selectedTab;
|
||||
set
|
||||
{
|
||||
if (value is null || !Set(ref _selectedTab, value)) return;
|
||||
OnPropertyChanged(nameof(IsExportTab));
|
||||
if (IsExportTab && !ShowCropMask) ShowCropMask = true;
|
||||
UpdateInfo();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The Export tab swaps the preview tools for compare, crop mask and a 10-second preview (Export.html).</summary>
|
||||
public bool IsExportTab => SelectedTab is ExportTab;
|
||||
|
||||
// ---- Frames ----
|
||||
|
||||
public int FrameCount => Session.Content.Count;
|
||||
|
||||
/// <summary>The frame on screen; the filmstrip, the charts and the frame table seek it.</summary>
|
||||
public int CurrentIndex
|
||||
{
|
||||
get => _currentIndex;
|
||||
set
|
||||
{
|
||||
var clamped = FrameCount == 0 ? 0 : int.Clamp(value, 0, FrameCount - 1);
|
||||
if (!Set(ref _currentIndex, clamped)) return;
|
||||
Frames.OnCurrentFrameChanged();
|
||||
foreach (var tab in Tabs.OfType<CameraTab>()) tab.OnCurrentFrameChanged();
|
||||
foreach (var tab in Tabs.OfType<TimeTab>()) tab.OnCurrentFrameChanged();
|
||||
UpdateInfo();
|
||||
RequestPreview(immediate: _player.IsEnabled);
|
||||
}
|
||||
}
|
||||
|
||||
public IThumbnailSource Thumbnails { get => _thumbnails; private set => Set(ref _thumbnails, value); }
|
||||
|
||||
/// <summary>Exposure steps (as received), warnings and keyframes above the filmstrip.</summary>
|
||||
public IReadOnlyList<TimelineMarker> Markers { get => _markers; private set => Set(ref _markers, value); }
|
||||
|
||||
// ---- Preview ----
|
||||
|
||||
public ImageSource? PreviewImage { get => _previewImage; private set => Set(ref _previewImage, value); }
|
||||
|
||||
public ImageSource? OriginalImage { get => _originalImage; private set => Set(ref _originalImage, value); }
|
||||
|
||||
public bool IsCompare { get => _isCompare; set => Set(ref _isCompare, value); }
|
||||
|
||||
public bool ShowVectors
|
||||
{
|
||||
get => _showVectors;
|
||||
set
|
||||
{
|
||||
if (Set(ref _showVectors, value)) RequestPreview(immediate: true);
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowRegions
|
||||
{
|
||||
get => _showRegions;
|
||||
set
|
||||
{
|
||||
if (Set(ref _showRegions, value)) RequestPreview(immediate: true);
|
||||
}
|
||||
}
|
||||
|
||||
public bool ShowCropMask
|
||||
{
|
||||
get => _showCropMask;
|
||||
set
|
||||
{
|
||||
if (Set(ref _showCropMask, value)) RequestPreview(immediate: true);
|
||||
}
|
||||
}
|
||||
|
||||
public PreviewZoomMode ZoomMode
|
||||
{
|
||||
get => _zoomMode;
|
||||
set
|
||||
{
|
||||
if (Set(ref _zoomMode, value)) OnPropertyChanged(nameof(IsActualSize));
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The 1:1 tool (raw pixels).</summary>
|
||||
public bool IsActualSize
|
||||
{
|
||||
get => _zoomMode == PreviewZoomMode.Actual;
|
||||
set => ZoomMode = value ? PreviewZoomMode.Actual : PreviewZoomMode.Fit;
|
||||
}
|
||||
|
||||
public Rect CropRect { get => _cropRect; private set => Set(ref _cropRect, value); }
|
||||
|
||||
public IReadOnlyList<Point>? RegionBoundary { get => _regionBoundary; private set => Set(ref _regionBoundary, value); }
|
||||
|
||||
public IReadOnlyList<MotionVector>? MotionVectors { get => _motionVectors; private set => Set(ref _motionVectors, value); }
|
||||
|
||||
/// <summary>Gain on vector lengths so a pixel of motion stays visible.</summary>
|
||||
public double VectorScale => 4;
|
||||
|
||||
public string WipeLabel => Loc.L("Editor.Preview.Wipe");
|
||||
|
||||
/// <summary>Shot data (bottom-right pill): frame, time, exposure; on the Export tab output time and size.</summary>
|
||||
public string? InfoText { get; private set; }
|
||||
|
||||
/// <summary>Long edge of the preview picture in device pixels (the view reports its size).</summary>
|
||||
public int PreviewEdge
|
||||
{
|
||||
get => _previewEdge;
|
||||
set
|
||||
{
|
||||
var rounded = int.Clamp((value + 63) / 64 * 64, 256, 4096);
|
||||
if (Set(ref _previewEdge, rounded)) RequestPreview();
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Analysis, plan, jobs ----
|
||||
|
||||
/// <summary>The corrections of the current exposure settings, once prepared (target curves).</summary>
|
||||
public RenderCorrections? Corrections { get => _correctionsValue; private set => Set(ref _correctionsValue, value); }
|
||||
|
||||
/// <summary>What the project's export will produce (size, time, encoder, name).</summary>
|
||||
public ExportPlan? Plan { get => _plan; private set => Set(ref _plan, value); }
|
||||
|
||||
/// <summary>An analysis or render of this sequence is running: settings wait, viewing tools stay live.</summary>
|
||||
public bool IsBusy => _jobs.Values.Any(j => j.State == JobState.Running);
|
||||
|
||||
public bool IsEditable => !IsBusy;
|
||||
|
||||
public string? BusyToolTip => IsBusy ? Loc.L("Tooltips.Editor.Busy") : null;
|
||||
|
||||
public bool IsPlaying => _player.IsEnabled;
|
||||
|
||||
public string PlayToolTip => Loc.L(IsPlaying ? "Tooltips.Editor.Pause" : "Tooltips.Editor.Play");
|
||||
|
||||
// ---- Render ----
|
||||
|
||||
public IReadOnlyList<Choice> RenderChoices { get; }
|
||||
|
||||
/// <summary>The export preset the Render button renders (choosing another one sets it).</summary>
|
||||
public Choice? SelectedRenderChoice
|
||||
{
|
||||
get => RenderChoices.FirstOrDefault(c => string.Equals((string)c.Value, Plan?.Export.PresetId ?? EditorSettings.ExportPreset.Effective(Session.Project, null),
|
||||
StringComparison.OrdinalIgnoreCase));
|
||||
set
|
||||
{
|
||||
if (value?.Value is not string id) return;
|
||||
Session.Edit(p => p with { Export = p.Export with { Preset = p.Export.Preset.WithManual(id), Overrides = new ExportOverrides() } });
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>"Render · 4K archive".</summary>
|
||||
public string RenderText => Loc.L("Editor.Render", Plan?.PresetName ?? string.Empty);
|
||||
|
||||
public string RenderToolTip => Plan is { } plan && !plan.Setup.Encoder.IsReady && plan.Setup.Encoder.Notices.LastOrDefault() is { } notice
|
||||
? Loc.L(notice.Key, [.. notice.Args])
|
||||
: Loc.L("Tooltips.Editor.Render");
|
||||
|
||||
public bool CanRender => Plan is { NameError: null, Setup: { Encoder.IsReady: true, Plan.Frames.Count: > 0 } };
|
||||
|
||||
public ICommand BackCommand { get; }
|
||||
public ICommand AnalyseCommand { get; }
|
||||
public ICommand OptimiseAllCommand { get; }
|
||||
public ICommand RenderCommand { get; }
|
||||
public ICommand UndoCommand { get; }
|
||||
public ICommand RedoCommand { get; }
|
||||
public ICommand PlayCommand { get; }
|
||||
public ICommand PreviewClipCommand { get; }
|
||||
public ICommand StepBackCommand { get; }
|
||||
public ICommand StepForwardCommand { get; }
|
||||
public ICommand FitCommand { get; }
|
||||
public ICommand ActualSizeCommand { get; }
|
||||
|
||||
/// <summary>Exposure steps of the sequence: as received by the pixels when the deep analysis measured them, else from the metadata.</summary>
|
||||
public static IReadOnlyList<TimelineMarker> StepMarkers(SequenceContent content)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(content);
|
||||
if (content.Deep is { } deep)
|
||||
{
|
||||
return [.. deep.Exposure.Steps.Select(s => new TimelineMarker(s.Index, s.Received ? MarkerKind.ExposureStep : MarkerKind.Warning,
|
||||
Loc.L(s.Received ? "Editor.Marker.Step" : "Editor.Marker.StepIgnored", Ev(s.MeasuredEv ?? s.ExpectedEv))))];
|
||||
}
|
||||
return [.. content.Light.ExposureSteps.Select(s => new TimelineMarker(s.Index, MarkerKind.ExposureStep, Loc.L("Editor.Marker.Step", Ev(s.DeltaEv))))];
|
||||
}
|
||||
|
||||
/// <summary>"Optimise section": the advisor's heavier decisions, reported in a toast (what changed, from what to what).</summary>
|
||||
public void Optimise(AdvisorSection section) => Report(Session.Optimise(section));
|
||||
|
||||
/// <summary>Queues a render of the project's export (with its batch presets when <paramref name="batch"/>).</summary>
|
||||
public async Task RenderAsync(JobPriority priority, bool batch)
|
||||
{
|
||||
var export = batch ? Session.Project.Export : Session.Project.Export with { Batch = [] };
|
||||
var request = Session.RenderRequest(export) with { Priority = priority };
|
||||
await Session.SubmitAsync(request);
|
||||
Shell.Notify(Loc.L("Editor.Render.Queued"), request.Label, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs));
|
||||
}
|
||||
|
||||
/// <summary>Loads the jobs of this sequence already queued or running (busy state).</summary>
|
||||
public async Task AttachJobsAsync()
|
||||
{
|
||||
if (Shell.Services.Jobs is not { } jobs) return;
|
||||
var page = await jobs.ListAsync(null, 200);
|
||||
foreach (var job in page.Items) Track(job);
|
||||
OnBusyChanged();
|
||||
}
|
||||
|
||||
public async ValueTask DisposeAsync()
|
||||
{
|
||||
if (_disposed) return;
|
||||
_disposed = true;
|
||||
_player.Stop();
|
||||
_preview.Dispose();
|
||||
_corrections.Dispose();
|
||||
_plans.Dispose();
|
||||
Session.ProjectChanged -= OnProjectChanged;
|
||||
Session.ContentChanged -= OnContentChanged;
|
||||
Session.SaveFailed -= OnSaveFailed;
|
||||
if (Shell.Services.Jobs is { } jobs) jobs.JobChanged -= OnJobChanged;
|
||||
foreach (var tab in Tabs) tab.Dispose();
|
||||
base.Dispose();
|
||||
await Session.DisposeAsync();
|
||||
}
|
||||
|
||||
public override void Dispose() => _ = DisposeAsync().AsTask();
|
||||
|
||||
// ---- Preview pipeline ----
|
||||
|
||||
private void RequestPreview(bool immediate = false)
|
||||
{
|
||||
if (_disposed || FrameCount == 0) return;
|
||||
var framing = ShowCropMask || ShowRegions ? PreviewFraming.Source : PreviewFraming.Output;
|
||||
var request = new PreviewRequest(CurrentIndex, Session.Project, PreviewEdge, framing, ShowVectors);
|
||||
var version = ++_previewVersion;
|
||||
_ = RunPreviewAsync(request, version, immediate);
|
||||
}
|
||||
|
||||
private async Task RunPreviewAsync(PreviewRequest request, int version, bool immediate)
|
||||
{
|
||||
var renderer = _renderer;
|
||||
PreviewResult? result = null;
|
||||
_previewBusy = true;
|
||||
try
|
||||
{
|
||||
await _preview.Schedule(async token =>
|
||||
{
|
||||
using var frame = await renderer.RenderAsync(request, renderer.Cached(request.Project) ?? renderer.Latest, token);
|
||||
if (frame is not null) result = PreviewResult.From(frame);
|
||||
}, immediate);
|
||||
}
|
||||
catch (Exception ex) when (ex is not OperationCanceledException)
|
||||
{
|
||||
Log.Warning("editor", $"Preview of frame {request.Index + 1} failed", ex);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if (version == _previewVersion) _previewBusy = false;
|
||||
}
|
||||
if (result is not { } r || version != _previewVersion || _disposed) return;
|
||||
PreviewImage = r.Corrected;
|
||||
OriginalImage = r.Original;
|
||||
CropRect = r.Crop;
|
||||
RegionBoundary = ShowRegions ? r.Horizon : null;
|
||||
MotionVectors = ShowVectors ? r.Vectors : null;
|
||||
}
|
||||
|
||||
private void RequestCorrections()
|
||||
{
|
||||
if (_disposed) return;
|
||||
var renderer = _renderer;
|
||||
var project = Session.Project;
|
||||
if (renderer.Cached(project) is { } cached)
|
||||
{
|
||||
Corrections = cached;
|
||||
NotifyCorrections();
|
||||
return;
|
||||
}
|
||||
_ = RunCorrectionsAsync(renderer, project);
|
||||
}
|
||||
|
||||
private async Task RunCorrectionsAsync(PreviewRenderer renderer, ProjectSettings project)
|
||||
{
|
||||
RenderCorrections? prepared = null;
|
||||
try
|
||||
{
|
||||
await _corrections.Schedule(async token => prepared = await renderer.PrepareAsync(project, token));
|
||||
}
|
||||
catch (Exception ex) when (ex is not OperationCanceledException)
|
||||
{
|
||||
Log.Warning("editor", "Preparing the preview corrections failed", ex);
|
||||
}
|
||||
if (prepared is null || _disposed || !ReferenceEquals(renderer, _renderer) || !ReferenceEquals(project, Session.Project)) return;
|
||||
Corrections = prepared;
|
||||
NotifyCorrections();
|
||||
RequestPreview(immediate: true);
|
||||
}
|
||||
|
||||
private void NotifyCorrections()
|
||||
{
|
||||
foreach (var tab in Tabs) tab.OnCorrectionsChanged();
|
||||
}
|
||||
|
||||
private void RequestPlan() => _ = RunPlanAsync(Planner, Session.Project);
|
||||
|
||||
private async Task RunPlanAsync(ExportPlanner planner, ProjectSettings project)
|
||||
{
|
||||
ExportPlan? plan = null;
|
||||
try
|
||||
{
|
||||
await _plans.Schedule(_ =>
|
||||
{
|
||||
plan = planner.Plan(project);
|
||||
return Task.CompletedTask;
|
||||
});
|
||||
}
|
||||
catch (Exception ex) when (ex is ArgumentException or InvalidOperationException or RenderException)
|
||||
{
|
||||
Log.Warning("editor", "Planning the export failed", ex);
|
||||
}
|
||||
if (_disposed || !ReferenceEquals(planner, Planner) || !ReferenceEquals(project, Session.Project)) return;
|
||||
Plan = plan;
|
||||
OnPropertyChanged(nameof(RenderText));
|
||||
OnPropertyChanged(nameof(RenderToolTip));
|
||||
OnPropertyChanged(nameof(SelectedRenderChoice));
|
||||
foreach (var tab in Tabs) tab.OnPlanChanged();
|
||||
UpdateInfo();
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
|
||||
// ---- Playback ----
|
||||
|
||||
private void TogglePlay(int limit)
|
||||
{
|
||||
if (_player.IsEnabled)
|
||||
{
|
||||
_player.Stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CurrentIndex >= FrameCount - 1) CurrentIndex = 0;
|
||||
_playLimit = limit;
|
||||
var fps = double.Clamp(Plan?.Setup.Plan.FrameRate.Value ?? 24, 5, 30);
|
||||
_player.Interval = TimeSpan.FromSeconds(1 / fps);
|
||||
_player.Start();
|
||||
}
|
||||
OnPropertyChanged(nameof(IsPlaying));
|
||||
OnPropertyChanged(nameof(PlayToolTip));
|
||||
}
|
||||
|
||||
/// <summary>Next frame while playing; frames are skipped rather than queued when the preview is slower than the clock.</summary>
|
||||
private void Advance()
|
||||
{
|
||||
if (_previewBusy) return;
|
||||
if (CurrentIndex >= FrameCount - 1 || (_playLimit > 0 && --_playLimit == 0))
|
||||
{
|
||||
TogglePlay(0);
|
||||
return;
|
||||
}
|
||||
CurrentIndex++;
|
||||
}
|
||||
|
||||
/// <summary>Source frames that make ten seconds of video.</summary>
|
||||
private int ClipFrames()
|
||||
{
|
||||
if (Plan is not { } plan || plan.Setup.Plan.DurationSeconds <= 0) return 240;
|
||||
return int.Max(1, (int)(plan.Setup.Plan.IncludedFrames.Count * double.Min(1, 10 / plan.Setup.Plan.DurationSeconds)));
|
||||
}
|
||||
|
||||
// ---- Changes ----
|
||||
|
||||
private void OnProjectChanged()
|
||||
{
|
||||
foreach (var tab in Tabs) tab.Refresh();
|
||||
UpdateMarkers();
|
||||
RequestCorrections();
|
||||
RequestPlan();
|
||||
RequestPreview();
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
|
||||
private void OnContentChanged()
|
||||
{
|
||||
_renderer = new PreviewRenderer(Session.Content, Session.Source);
|
||||
Planner = new ExportPlanner(Session.Content, _encoders, _host);
|
||||
if (Thumbnails.Count != FrameCount) Thumbnails = new EditorThumbnails(Session.Source, FrameCount);
|
||||
Corrections = null;
|
||||
foreach (var tab in Tabs) tab.OnContentChanged();
|
||||
OnPropertyChanged(nameof(Summary));
|
||||
OnPropertyChanged(nameof(FrameCount));
|
||||
CurrentIndex = int.Min(CurrentIndex, int.Max(0, FrameCount - 1));
|
||||
UpdateMarkers();
|
||||
RequestCorrections();
|
||||
RequestPlan();
|
||||
RequestPreview(immediate: true);
|
||||
}
|
||||
|
||||
private void OnSaveFailed(Exception ex) => Shell.ReportError(ex);
|
||||
|
||||
private void UpdateMarkers()
|
||||
{
|
||||
var content = Session.Content;
|
||||
var markers = new List<TimelineMarker>(StepMarkers(content));
|
||||
foreach (var finding in Session.Advice.Findings.Where(f => f.Severity >= FindingSeverity.Warning))
|
||||
{
|
||||
var text = Loc.L(finding.Key, finding.Arguments);
|
||||
markers.AddRange(finding.Frames.Take(64).Select(i => new TimelineMarker(i, finding.Severity == FindingSeverity.Error ? MarkerKind.Error : MarkerKind.Warning, text)));
|
||||
}
|
||||
markers.AddRange(Session.Project.Camera.Keyframes.Select(k => new TimelineMarker(k.Frame, MarkerKind.Keyframe, Loc.L("Editor.Marker.Keyframe"))));
|
||||
if (!markers.SequenceEqual(Markers)) Markers = markers;
|
||||
}
|
||||
|
||||
private void UpdateInfo()
|
||||
{
|
||||
if (FrameCount == 0)
|
||||
{
|
||||
InfoText = null;
|
||||
}
|
||||
else if (IsExportTab && Plan is { } plan)
|
||||
{
|
||||
var settings = plan.Setup.Encoder.Settings;
|
||||
var position = plan.Setup.Plan.DurationSeconds * CurrentIndex / double.Max(1, FrameCount - 1);
|
||||
InfoText = string.Join(" · ", EditorText.Position(CurrentIndex, FrameCount),
|
||||
Loc.L("Editor.Preview.OutputTime", Clock(position), Clock(plan.Setup.Plan.DurationSeconds)),
|
||||
Loc.L("Editor.Preview.OutputSize", EditorText.Size(settings.Width, settings.Height)));
|
||||
}
|
||||
else
|
||||
{
|
||||
InfoText = EditorText.Shot(Session.Content.Frames[CurrentIndex], CurrentIndex, FrameCount);
|
||||
}
|
||||
OnPropertyChanged(nameof(InfoText));
|
||||
}
|
||||
|
||||
private void OptimiseAll() => Report(Session.OptimiseAll());
|
||||
|
||||
private void Report(IReadOnlyList<SettingChange> changes)
|
||||
{
|
||||
if (changes.Count == 0)
|
||||
{
|
||||
Shell.Notify(Loc.L("Editor.Optimise.Nothing"));
|
||||
return;
|
||||
}
|
||||
var lines = changes.Select(c => Loc.L("Editor.Optimise.Change", ParameterLabel(c.Parameter), ValueText(c.Before), ValueText(c.After)));
|
||||
Shell.Notify(Loc.Plural("Editor.Optimise.Done", changes.Count), string.Join(Environment.NewLine, lines));
|
||||
}
|
||||
|
||||
private async Task AnalyseAsync()
|
||||
{
|
||||
await Session.SubmitAsync(Session.AnalysisRequest());
|
||||
Shell.Notify(Loc.L("Editor.Analyse.Queued"), Title, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs));
|
||||
}
|
||||
|
||||
private void OnJobChanged(Job job)
|
||||
{
|
||||
if (!job.TargetIds.Contains(Session.Content.Sequence.Id) || job.Kind is not (JobKind.DeepAnalyse or JobKind.LightAnalyse or JobKind.Render)) return;
|
||||
_dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
if (_disposed) return;
|
||||
var wasActive = _jobs.ContainsKey(job.Id);
|
||||
Track(job);
|
||||
OnBusyChanged();
|
||||
if (wasActive && job.State == JobState.Done) _ = ReloadAsync();
|
||||
});
|
||||
}
|
||||
|
||||
private void Track(Job job)
|
||||
{
|
||||
if (!job.TargetIds.Contains(Session.Content.Sequence.Id) || job.Kind is not (JobKind.DeepAnalyse or JobKind.LightAnalyse or JobKind.Render)) return;
|
||||
if (job.State is JobState.Queued or JobState.Running) _jobs[job.Id] = job;
|
||||
else _jobs.Remove(job.Id);
|
||||
}
|
||||
|
||||
private async Task ReloadAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
await Session.ReloadAsync();
|
||||
}
|
||||
catch (Exception ex) when (ex is System.IO.IOException or System.IO.InvalidDataException or InvalidOperationException)
|
||||
{
|
||||
Shell.ReportError(ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBusyChanged()
|
||||
{
|
||||
OnPropertyChanged(nameof(IsBusy));
|
||||
OnPropertyChanged(nameof(IsEditable));
|
||||
OnPropertyChanged(nameof(BusyToolTip));
|
||||
CommandManager.InvalidateRequerySuggested();
|
||||
}
|
||||
|
||||
private static string Clock(double seconds)
|
||||
{
|
||||
var t = TimeSpan.FromSeconds(double.Max(0, seconds));
|
||||
return ((int)t.TotalMinutes).ToString("00", Loc.Culture) + ":" + t.Seconds.ToString("00", Loc.Culture) + Loc.Culture.NumberFormat.NumberDecimalSeparator
|
||||
+ (t.Milliseconds / 100).ToString(Loc.Culture);
|
||||
}
|
||||
|
||||
private static string Ev(double ev) => ev.ToString("+0.0;−0.0;0.0", Loc.Culture);
|
||||
|
||||
private static string ParameterLabel(string parameter) => parameter switch
|
||||
{
|
||||
AdvisorParameters.Hero => Loc.L("Editor.Frames.HeroLabel"),
|
||||
AdvisorParameters.Excluded => Loc.L("Editor.Frames.ExcludedLabel"),
|
||||
AdvisorParameters.TimingMode => Loc.L("Editor.Time.Mode"),
|
||||
AdvisorParameters.FrameRate => Loc.L("Editor.Time.Rate"),
|
||||
AdvisorParameters.FitToSeconds => Loc.L("Editor.Time.Fit"),
|
||||
AdvisorParameters.Deflicker => Loc.L("Editor.Exposure.Deflicker"),
|
||||
AdvisorParameters.DeflickerWindow => Loc.L("Editor.Exposure.Window"),
|
||||
AdvisorParameters.DeflickerStrength => Loc.L("Editor.Exposure.Strength"),
|
||||
AdvisorParameters.Regions => Loc.L("Editor.Exposure.Regions"),
|
||||
AdvisorParameters.HolyGrail => Loc.L("Editor.Exposure.HolyGrail"),
|
||||
AdvisorParameters.TransitionLength => Loc.L("Editor.Exposure.Transitions"),
|
||||
AdvisorParameters.WhiteBalanceSmoothing => Loc.L("Editor.Exposure.WhiteBalance"),
|
||||
AdvisorParameters.MotionBlur => Loc.L("Editor.Motion.Blur"),
|
||||
AdvisorParameters.TargetShutterAngle => Loc.L("Editor.Motion.Shutter"),
|
||||
AdvisorParameters.FlowQuality => Loc.L("Editor.Motion.Flow"),
|
||||
AdvisorParameters.Stabilize => Loc.L("Editor.Motion.Stabilize"),
|
||||
AdvisorParameters.StabilizeSmoothing => Loc.L("Editor.Motion.Smoothing"),
|
||||
AdvisorParameters.Aspect => Loc.L("Editor.Camera.Aspect"),
|
||||
AdvisorParameters.OffsetY => Loc.L("Editor.Camera.OffsetY"),
|
||||
AdvisorParameters.ExportPreset => Loc.L("Editor.Export.Preset"),
|
||||
AdvisorParameters.Resolution => Loc.L("Editor.Export.Resolution"),
|
||||
_ => parameter,
|
||||
};
|
||||
|
||||
private static string ValueText(object? value) => value switch
|
||||
{
|
||||
null => Loc.L("Editor.Value.None"),
|
||||
bool b => Loc.L(b ? "Editor.Value.On" : "Editor.Value.Off"),
|
||||
TimingMode m => Loc.L("Editor.Timing." + m),
|
||||
RegionMode m => m == RegionMode.Off ? Loc.L("Editor.Value.Off") : Loc.L("Editor.Regions." + m),
|
||||
FlowQualitySetting q => Loc.L("Editor.Flow." + q),
|
||||
string id when ExportPresets.Find(id) is { } preset => Loc.L(preset.NameKey),
|
||||
string text => text,
|
||||
double d => d.ToString("0.##", Loc.Culture),
|
||||
IEnumerable list => Loc.Plural("Editor.Value.Frames", list.Cast<object>().LongCount()),
|
||||
IFormattable f => f.ToString(null, Loc.Culture),
|
||||
_ => value.ToString() ?? string.Empty,
|
||||
};
|
||||
|
||||
/// <summary>A rendered preview as frozen bitmaps and overlays in picture pixels (built off the UI thread).</summary>
|
||||
private sealed record PreviewResult(ImageSource Corrected, ImageSource Original, Rect Crop, IReadOnlyList<Point> Horizon, IReadOnlyList<MotionVector> Vectors)
|
||||
{
|
||||
public static PreviewResult From(PreviewFrame frame) => new(
|
||||
EditorImages.ToBitmap(frame.Corrected),
|
||||
EditorImages.ToBitmap(frame.Original),
|
||||
new Rect(frame.Crop.X, frame.Crop.Y, frame.Crop.Width, frame.Crop.Height),
|
||||
[.. frame.Horizon.Select(p => new Point(p.X, p.Y))],
|
||||
[.. frame.Vectors.Select(v => new MotionVector(v.X, v.Y, v.Dx, v.Dy))]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user