From 7701fcac3e940bd48a5cd8f65a6d03378ac15357 Mon Sep 17 00:00:00 2001 From: Alberto Balbo Date: Thu, 5 Nov 2026 02:18:24 +0100 Subject: [PATCH] feat(P5): Render menu with grouped presets, Save frame and a fixed-width header The editor header's button now reads "Render" whatever the preset, so its width stays the same in every language, and the tooltip carries the preset, size, codec, fps and estimates (owner review 1, R3, decisions 1, 2 and 12). Its menu is rebuilt every time it opens. Top to bottom it lists: - Recommended, the batch and up to three recent presets (taken from the render history); - Other presets, grouped by Video, Social, Intermediate, Sequence and Web, each entry with a details line; - Render batch, Add to queue, Save frame (PNG, JPEG or TIFF 16-bit) and Videos. SplitButton learns hierarchical, two-line menu entries. Still jobs come from EditorSession.StillRequests and carry the frame index and the photo hash. Save frame stays disabled, with the reason in its tooltip, in these cases: - the sequence is read-only; - there is no renderable frame; - the server is older than settings format 3; - the project is a workspace one, which has no still route yet (the IProjectStills hook is left for it). A playback render is now gated on the format of the job's own export. The project menu gains "Save project file". Refs #21 Co-Authored-By: Claude Opus 5.5 --- src/Chronos.App/Editor/EditorSession.cs | 40 +++ src/Chronos.App/Editor/EditorViewModel.cs | 150 ++++++++- src/Chronos.App/Editor/RenderMenu.cs | 308 ++++++++++++++++++ src/Chronos.App/Editor/ServerJobs.cs | 21 ++ src/Chronos.App/Sections/SequenceView.xaml | 7 +- src/Chronos.Ui/Themes/Visuals.xaml | 21 ++ src/Chronos.Ui/Visuals/SplitButton.cs | 175 +++++++++- .../Editor/RenderHeaderTests.cs | 144 ++++++++ .../Editor/RenderMenuTests.cs | 300 +++++++++++++++++ 9 files changed, 1137 insertions(+), 29 deletions(-) create mode 100644 src/Chronos.App/Editor/RenderMenu.cs create mode 100644 tests/Chronos.App.Tests/Editor/RenderHeaderTests.cs create mode 100644 tests/Chronos.App.Tests/Editor/RenderMenuTests.cs diff --git a/src/Chronos.App/Editor/EditorSession.cs b/src/Chronos.App/Editor/EditorSession.cs index 4d6b152a..06006324 100644 --- a/src/Chronos.App/Editor/EditorSession.cs +++ b/src/Chronos.App/Editor/EditorSession.cs @@ -2,6 +2,7 @@ using Chronos.Core.Advice; using Chronos.Core.Diagnostics; using Chronos.Core.Export; using Chronos.Core.Imaging.Geometry; +using Chronos.Core.Model; using Chronos.Core.Project; using Chronos.Core.Render; using Chronos.Core.Video; @@ -263,6 +264,34 @@ public sealed class EditorSession : IAsyncDisposable _ => [RenderRequest(export)], }; + /// + /// A source can save one frame as an image (owner review 1, R8, "Save frame"): a sequence of this PC or of a server, or a + /// source that makes its own still jobs (). A workspace project renders at its home with + /// its portable settings () and saves no frame until it makes still jobs of its own. + /// + public bool CanSaveFrames => Source is IProjectStills or not IProjectRenders; + + /// + /// The job that saves frame as one image (one of + /// ) at the output size of , with every correction of the + /// project as it is now and no playback (): routed as is, + /// on this PC's engine or on the server, as one job. The frame is named by its position and by its photo, whose hash + /// wins when frames moved meanwhile. Null when the source saves no frames (). + /// + /// is not a frame of the sequence, or is no still format. + public IReadOnlyList? StillRequests(ExportSettings export, VideoCodec codec, int frameIndex) + { + ArgumentNullException.ThrowIfNull(export); + ArgumentOutOfRangeException.ThrowIfGreaterThanOrEqual((uint)frameIndex, (uint)Content.Count, nameof(frameIndex)); + var photo = Content.Frames[frameIndex].Sha256; + return Source switch + { + IProjectStills stills => stills.StillRequests(Content.Sequence, Project, export, codec, frameIndex, photo, Content.SourceWidth, Content.SourceHeight), + IProjectRenders => null, + _ => [ProcessingJobs.Still(Content.Sequence, export, codec, frameIndex, photo, Content.SourceWidth, Content.SourceHeight, Project with { Export = export })], + }; + } + /// /// Makes a "Save both" copy of this PC's settings the project, as one undoable step; null when it stores the same values. /// @@ -608,6 +637,17 @@ public sealed class EditorSession : IAsyncDisposable } } +/// +/// A source whose saved frames are made otherwise than from the project as the editor holds it (as +/// for renders): a workspace project would name the frame and its settings as its home reads them. +/// +public interface IProjectStills +{ + /// The jobs that save frame (photo ) of with . + IReadOnlyList StillRequests(Sequence sequence, ProjectSettings project, ExportSettings export, VideoCodec codec, int frameIndex, string? photoSha256, + int sourceWidth, int sourceHeight); +} + /// /// A "Save both" copy made the project (). Its Undo brings back the project from /// before as a new step, and only while the restore is still the last change: after another edit, an undo or a merged diff --git a/src/Chronos.App/Editor/EditorViewModel.cs b/src/Chronos.App/Editor/EditorViewModel.cs index d127af5f..05d26029 100644 --- a/src/Chronos.App/Editor/EditorViewModel.cs +++ b/src/Chronos.App/Editor/EditorViewModel.cs @@ -49,6 +49,9 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable private readonly SequenceJobs _jobs; private readonly AsyncRelayCommand _analyse; private readonly AsyncRelayCommand _render; + private readonly AsyncRelayCommand _renderBatch; + private readonly AsyncRelayCommand _addToQueue; + private readonly AsyncRelayCommand _saveFrame; private readonly AsyncRelayCommand _cancelServerJob; private PreviewRenderer _renderer; private int _currentIndex; @@ -117,10 +120,19 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable _player = new DispatcherTimer(DispatcherPriority.Background, _dispatcher); _player.Tick += (_, _) => Advance(); + RenderChoices = [.. ExportPresets.BuiltIn.Select(p => new Choice(p.Id, p.NameKey))]; BackCommand = new RelayCommand(() => Shell.Navigate(SectionKey.Library)); _analyse = new AsyncRelayCommand(AnalyseAsync, () => !IsLocked && !IsAnalysing); OptimiseAllCommand = new RelayCommand(OptimiseAll, () => !IsLocked); _render = new AsyncRelayCommand(() => RenderAsync(JobPriority.User, batch: false), () => CanRender); + _renderBatch = new AsyncRelayCommand(() => RenderAsync(JobPriority.User, batch: true), () => CanRender && RenderMenu.BatchPresets(RenderExport).Count > 0); + _addToQueue = new AsyncRelayCommand(() => RenderAsync(JobPriority.Normal, batch: false), () => CanRender); + _saveFrame = new AsyncRelayCommand((p, _) => SaveFrameAsync(p), p => p is VideoCodec codec && RenderRules.StillCodecs.Contains(codec) && SaveFrameBlockedReason is null); + SelectPresetCommand = new RelayCommand(p => + { + if (p is string id) SelectedRenderChoice = RenderChoices.FirstOrDefault(c => string.Equals((string)c.Value, id, StringComparison.OrdinalIgnoreCase)); + }); + ShowVideosCommand = new RelayCommand(ShowVideos, () => VideosSection is not null); _cancelServerJob = new AsyncRelayCommand(CancelServerJobAsync, () => ServerJob is not null); UndoCommand = new RelayCommand(() => Session.Undo(), () => !IsLocked && Session.History.CanUndo); RedoCommand = new RelayCommand(() => Session.Redo(), () => !IsLocked && Session.History.CanRedo); @@ -141,7 +153,8 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable Analysis = new AnalysisTab(this); Frames = new FramesTab(this); Exposure = new ExposureTab(this); - Tabs = [Analysis, Frames, Exposure, new MotionTab(this), new CameraTab(this), new TimeTab(this), new StackTab(this), new ExportTab(this)]; + Export = new ExportTab(this); + Tabs = [Analysis, Frames, Exposure, new MotionTab(this), new CameraTab(this), new TimeTab(this), new StackTab(this), Export]; for (var i = 0; i < Tabs.Count; i++) { Tabs[i].Number = i + 1; @@ -154,7 +167,6 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable _currentFrameId = FrameId(_currentIndex); // Until the link is read (AttachJobsAsync), a sequence of this PC cannot send its renders. _syncGate = session.IsRemote ? ExportSyncGate.Remote : ExportSyncGate.SignedOut; - RenderChoices = [.. ExportPresets.BuiltIn.Select(p => new Choice(p.Id, p.NameKey))]; _shownOrientation = OrientationOf(session.Project.Camera); UpdateCropBox(); @@ -272,6 +284,9 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable public ExposureTab Exposure { get; } + /// The last step; the project ▾ menu's "Save project file" is its command (owner review 1, R3). + public ExportTab Export { get; } + /// The steps of the Edit path, in order (owner review 1, R7). public IReadOnlyList Tabs { get; } @@ -624,29 +639,107 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable ? Session.ExportFor(id) with { Batch = Session.Project.Export.Batch } : Session.Project.Export; - /// "Render · 4K archive". - public string RenderText => Loc.L("Editor.Render", Plan?.PresetName ?? string.Empty); + /// "Render" whatever the preset (owner review 1, R3, decision 1): the header keeps its width; the tooltip and the menu's check say which. + public string RenderText => Loc.L("Editor.RenderButton"); - public string RenderToolTip => RenderBlockedReason ?? (IsRemote ? Loc.L("Tooltips.Editor.RenderServer", ServerName) : Loc.L("Tooltips.Editor.Render")); + /// Why Render waits, then what it renders: preset, size, codec, frame rate, estimated size and time (). + public string RenderToolTip => RenderMenu.RenderToolTip(Plan, RenderBlockedReason, IsRemote ? ServerName : null); /// The ▾ part of Render: another preset for the project, or only for this render when the project cannot change. public string RenderChoiceToolTip => Loc.L(IsReadOnly ? "Tooltips.Editor.RenderChoiceReadOnly" : "Tooltips.Editor.RenderChoice"); + /// + /// The Render ▾ menu (): made again whenever it is read, so the menu, which reads it each time it + /// opens, shows the presets, the batch, the history and the reasons as they are then. + /// + public IReadOnlyList RenderMenuItems + { + get + { + var export = RenderExport; + var batch = RenderMenu.BatchPresets(export); + var (camera, width, height) = (Session.Project.Camera, Session.Content.SourceWidth, Session.Content.SourceHeight); + return RenderMenu.Build(new RenderMenuState + { + CurrentPresetId = RenderPresetId(basis: false), + BasePresetId = RenderPresetId(basis: true), + RecommendedPresetId = Session.Advice.Find(AdvisorParameters.ExportPreset)?.Value as string, + Batch = batch, + Recent = RenderMenu.RecentPresets(Session.Content.Renders), + Details = preset => RenderMenu.PresetDetails(export, preset.Id, camera, width, height), + SelectPreset = SelectPresetCommand, + RenderBatch = _renderBatch, + RenderBatchToolTip = RenderBlockedReason, + AddToQueue = _addToQueue, + AddToQueueToolTip = RenderBlockedReason, + SaveFrame = _saveFrame, + SaveFrameBlocked = SaveFrameBlockedReason, + ShowVideos = ShowVideosCommand, + }); + } + } + + /// Chooses the preset Render renders (); its parameter is the preset id. + public ICommand SelectPresetCommand { get; } + + /// Render batch (n): the export and each preset of its batch. + public ICommand RenderBatchCommand => _renderBatch; + + /// Add to queue: the render at a normal priority, the editing goes on. + public ICommand AddToQueueCommand => _addToQueue; + + /// Save frame › PNG, JPEG or TIFF 16-bit (decision 12); its parameter is the . + public ICommand SaveFrameCommand => _saveFrame; + + /// The videos of this sequence (decision 20); disabled until this Chronos has a Videos section. + public ICommand ShowVideosCommand { get; } + + /// + /// Why the frame under the cursor cannot be saved now (): out of date or + /// read-only, no frame the render keeps under the cursor, a workspace project, no right to render on the server or a + /// server too old for still jobs (format 3), a wrong file name; null when it can. + /// + public string? SaveFrameBlockedReason + { + get + { + var hasFrame = FrameCount > 0 && !Session.Project.ExcludedFrames.Contains(CurrentIndex) && !Session.Content.NotRenderable().Contains(CurrentIndex); + string? server = null; + if (IsRemote && Session.CanSaveFrames) + { + var sync = Shell.Services.Sync; + server = !sync.CanRender ? Loc.L("Tooltips.Editor.Render.NoRight", ServerName) + : ServerJobs.StillNeedsNewerServer(sync.SettingsFormat) + ?? ServerJobs.RenderNeedsNewerServer(Session.Project, RenderExport, Session.Content.SourceWidth, Session.Content.SourceHeight, sync.SettingsFormat); + } + return RenderMenu.SaveFrameBlockedReason(IsOutdated, ServerName, IsReadOnly, hasFrame, Session.CanSaveFrames, server, Plan?.NameError); + } + } + public bool CanRender => RenderBlockedReason is null; - /// The settings format a render of needs (). - private int RenderFormat => - Chronos.Data.Processing.ProcessingJobs.RequiredFormat(Session.Project, RenderExport, Session.Content.SourceWidth, Session.Content.SourceHeight); + /// + /// The preset Render renders (: the one its values start from, a custom export's included), as + /// chosen for this render in a read-only session, else as planned, else as the project names it. + /// + private string? RenderPresetId(bool basis) => + (IsReadOnly ? _renderPreset : null) ?? (basis ? Plan?.Export.BasePresetId : Plan?.Export.PresetId) ?? EditorSettings.ExportPreset.Effective(Session.Project, null); + + /// The Videos section of this Chronos (owner review 1, R9; P7 adds it); null while there is none. + private SectionKey? VideosSection => + Enum.TryParse("Videos", out var key) && Shell.AllSections.Any(s => s.Key == key) ? key : null; /// Why the project's export cannot be rendered now, localised; null when it can. public string? RenderBlockedReason => Plan switch { _ when IsRemote && !Shell.Services.Sync.CanRender => Loc.L("Tooltips.Editor.Render.NoRight", ServerName), - // Settings or proportions the server would render otherwise (owner review 1, phase 4: an older server, Send and render too). - // A workspace project rendered on this PC from its originals (phase 5c) renders with this PC's engine: the server's - // format does not decide (sending its version home is held by the workspace's own gate). + // Settings or proportions the server would render otherwise (owner review 1, phase 4: an older server, Send and render too; + // phase 5: playback needs format 3, read from the export rendered). A workspace project rendered on this PC from its + // originals (phase 5c) renders with this PC's engine: the server's format does not decide (sending its version home is + // held by the workspace's own gate). _ when IsRemote && Session.Source is not IProjectRenders { RendersLocally: true } - && ServerJobs.NeedsNewerServer(RenderFormat, Shell.Services.Sync.SettingsFormat) is { } newer => newer, + && ServerJobs.RenderNeedsNewerServer(Session.Project, RenderExport, Session.Content.SourceWidth, Session.Content.SourceHeight, + Shell.Services.Sync.SettingsFormat) is { } newer => newer, _ when IsOutdated => Loc.L("Tooltips.Editor.Outdated", ServerName), null when _planned => Loc.L("Tooltips.Editor.Render.NoSource"), null => Loc.L("Tooltips.Editor.Render.Planning"), @@ -732,11 +825,42 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable else Shell.Notify(Loc.L("Editor.Render.Queued"), requests[0].Label, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs)); } + /// + /// "Save frame ›" (owner review 1, R8, decision 12): queues the frame under the cursor as one + /// image (a of ) at the export's output size, with every + /// correction and no playback; on this PC's engine, or as one server job for a server sequence. The frame is the one on + /// screen wherever frames read again before the job put it. + /// + public async Task SaveFrameAsync(object? parameter) + { + if (parameter is not VideoCodec codec || !RenderRules.StillCodecs.Contains(codec) || SaveFrameBlockedReason is not null) return; + var frame = _currentFrameId; + await Session.EnsureFramesAsync(); + if (IsOutdated || IndexOfFrame(frame) is not { } index) return; + if (Session.StillRequests(RenderExport with { Batch = [] }, codec, index) is not [_, ..] requests) return; + foreach (var request in requests) await Session.SubmitAsync(request); + var label = requests[0].Label + Loc.Separator + EditorText.Position(index, FrameCount); + if (IsRemote) Shell.Notify(Loc.L("Editor.Still.Queued"), label); + else Shell.Notify(Loc.L("Editor.Still.Queued"), label, Loc.L("Shell.Nav.Jobs"), Loc.L("Tooltips.Nav.Jobs"), () => Shell.Navigate(SectionKey.Jobs)); + } + + /// + /// The videos of this sequence (Render ▾ › Videos). Until the Videos section takes a sequence filter (P7), it opens the + /// section as it is. + /// + private void ShowVideos() + { + if (VideosSection is { } key) Shell.Navigate(key); + } + /// Re-reads the enabled state of every command (the async ones keep their own event). public void RefreshCommands() { _analyse.RaiseCanExecuteChanged(); _render.RaiseCanExecuteChanged(); + _renderBatch.RaiseCanExecuteChanged(); + _addToQueue.RaiseCanExecuteChanged(); + _saveFrame.RaiseCanExecuteChanged(); _cancelServerJob.RaiseCanExecuteChanged(); foreach (var tab in Tabs) tab.RefreshCommands(); CommandManager.InvalidateRequerySuggested(); @@ -1523,6 +1647,8 @@ public sealed class EditorViewModel : LocalizedViewModel, IAsyncDisposable OnPropertyChanged(nameof(RenderToolTip)); OnPropertyChanged(nameof(RenderBlockedReason)); OnPropertyChanged(nameof(CanRender)); + OnPropertyChanged(nameof(SaveFrameBlockedReason)); + OnPropertyChanged(nameof(RenderMenuItems)); } /// A rendered preview as frozen bitmaps and overlays in picture pixels (built off the UI thread). diff --git a/src/Chronos.App/Editor/RenderMenu.cs b/src/Chronos.App/Editor/RenderMenu.cs new file mode 100644 index 00000000..502de2b6 --- /dev/null +++ b/src/Chronos.App/Editor/RenderMenu.cs @@ -0,0 +1,308 @@ +using System.IO; +using System.Text.Json; +using System.Windows.Input; +using Chronos.App.Infrastructure; +using Chronos.Core.Export; +using Chronos.Core.Localization; +using Chronos.Core.Model; +using Chronos.Core.Project; +using Chronos.Core.Render; +using Chronos.Core.Video; +using Chronos.Ui.Visuals; + +namespace Chronos.App.Editor; + +/// +/// What the editor's Render ▾ menu is made from (owner review 1, R3, decision 2): the presets to put first, the commands +/// of its lower part and why Save frame waits, when it does. +/// +public sealed record RenderMenuState +{ + /// The preset the export renders (checked); null for values that match no preset ("Custom"). + public string? CurrentPresetId { get; init; } + + /// The preset the export starts from (Custom included): listed at the top when no section below lists it. + public string? BasePresetId { get; init; } + + /// The advisor's pick for this sequence; null when it has none. + public string? RecommendedPresetId { get; init; } + + /// The export's batch presets besides its own (). + public IReadOnlyList Batch { get; init; } = []; + + /// Presets the sequence was rendered with, newest first (). + public IReadOnlyList Recent { get; init; } = []; + + /// The details line of a preset: "3840×2160 · HEVC Main10 · 24 fps" (). + public Func Details { get; init; } = _ => string.Empty; + + /// Chooses a preset; its parameter is the preset id. + public ICommand? SelectPreset { get; init; } + + public ICommand? RenderBatch { get; init; } + + /// Why Render batch waits; null shows what it does. + public string? RenderBatchToolTip { get; init; } + + public ICommand? AddToQueue { get; init; } + + /// Why Add to queue waits; null shows what it does. + public string? AddToQueueToolTip { get; init; } + + /// Saves the frame under the cursor; its parameter is one of . + public ICommand? SaveFrame { get; init; } + + /// Why no frame can be saved now (); null when one can. + public string? SaveFrameBlocked { get; init; } + + /// Opens the videos of this sequence. + public ICommand? ShowVideos { get; init; } +} + +/// +/// The editor's Render ▾ menu (owner review 1, R3, decisions 1 and 2): short and structured instead of every preset in a +/// row. In order: the current preset when no section lists it, the advisor's pick, the batch presets, up to three presets +/// this sequence was rendered with, "Other presets ›" grouped as the Export step groups them; then Render batch (n), Add to +/// queue, Save frame › (PNG, JPEG, TIFF 16-bit) and the videos of the sequence. Each preset reads as two lines, its name +/// and a muted "size · codec · fps"; estimates stay out of the menu (they cost a plan per preset) and live in the Render +/// button's tooltip (). Every entry has a tooltip; a disabled one says why. +/// +public static class RenderMenu +{ + /// The presets of the render history the menu puts first, at most. + public const int RecentCount = 3; + + /// The preset groups in the order the menu and the Export step list them; another group follows them. + public static IReadOnlyList GroupOrder { get; } = ["video", "social", "intermediate", "sequence", "web"]; + + /// The menu for . + public static IReadOnlyList Build(RenderMenuState state) + { + ArgumentNullException.ThrowIfNull(state); + var shown = new HashSet(StringComparer.OrdinalIgnoreCase); + var recommended = Find(state.RecommendedPresetId); + var batch = state.Batch.Select(Find).OfType().Where(p => !Same(p, recommended)).DistinctBy(p => p.Id).ToList(); + var recent = state.Recent.Select(Find).OfType().Where(p => !Same(p, recommended) && !batch.Contains(p)).DistinctBy(p => p.Id) + .Take(RecentCount).ToList(); + var items = new List(); + + if (Find(state.BasePresetId) is { } current && !Same(current, recommended) && !batch.Contains(current) && !recent.Contains(current)) + items.Add(Preset(current, null)); + if (recommended is not null) + { + items.Add(RenderMenuItem.Header(Loc.L("Editor.RenderMenu.Recommended"))); + items.Add(Preset(recommended, Loc.L("Tooltips.Editor.RenderMenu.Recommended"))); + } + if (batch.Count > 0) + { + // The count is the batch's (as Render batch says), a preset listed above among them. + items.Add(RenderMenuItem.Header(Loc.L("Export.Footer.Batch", state.Batch.Count))); + items.AddRange(batch.Select(p => Preset(p, null))); + } + if (recent.Count > 0) + { + items.Add(RenderMenuItem.Header(Loc.L("Editor.RenderMenu.Recent"))); + items.AddRange(recent.Select(p => Preset(p, Loc.L("Tooltips.Editor.RenderMenu.Recent")))); + } + + var others = new List(); + foreach (var group in ExportPresets.BuiltIn.Where(p => !shown.Contains(p.Id)).GroupBy(p => p.Group, StringComparer.OrdinalIgnoreCase).OrderBy(g => GroupRank(g.Key))) + { + others.Add(RenderMenuItem.Header(GroupLabel(group.Key))); + others.AddRange(group.Select(p => Preset(p, null))); + } + if (others.Count > 0) + { + items.Add(new RenderMenuItem + { + Kind = RenderMenuItemKind.Submenu, + Id = "other", + Label = Loc.L("Editor.RenderMenu.Other"), + ToolTip = Loc.L("Tooltips.Editor.RenderMenu.Other"), + Children = others, + }); + } + + items.Add(RenderMenuItem.Separator); + items.Add(new RenderMenuItem + { + Kind = RenderMenuItemKind.Command, + Id = "batch", + Label = Loc.L("Editor.RenderMenu.Batch", state.Batch.Count), + Command = state.RenderBatch, + ToolTip = state.RenderBatchToolTip ?? Loc.L(state.Batch.Count == 0 ? "Tooltips.Editor.RenderMenu.BatchEmpty" : "Tooltips.Editor.RenderMenu.Batch"), + }); + items.Add(new RenderMenuItem + { + Kind = RenderMenuItemKind.Command, + Id = "queue", + Label = Loc.L("Editor.Export.AddToQueue"), + Command = state.AddToQueue, + ToolTip = state.AddToQueueToolTip ?? Loc.L("Tooltips.Editor.RenderMenu.AddToQueue"), + }); + items.Add(new RenderMenuItem + { + Kind = RenderMenuItemKind.Submenu, + Id = "frame", + Label = Loc.L("Editor.RenderMenu.SaveFrame"), + IsEnabled = state.SaveFrameBlocked is null, + ToolTip = state.SaveFrameBlocked ?? Loc.L("Tooltips.Editor.RenderMenu.SaveFrame"), + Children = [.. RenderRules.StillCodecs.Select(codec => new RenderMenuItem + { + Kind = RenderMenuItemKind.Command, + Id = "frame:" + Data.Processing.ProcessingJobs.CodecName(codec), + Label = StillFormatName(codec), + Command = state.SaveFrame, + CommandParameter = codec, + IsEnabled = state.SaveFrameBlocked is null, + ToolTip = state.SaveFrameBlocked ?? Loc.L("Tooltips.Editor.RenderMenu.SaveFormat", StillFormatName(codec)), + })], + }); + items.Add(new RenderMenuItem + { + Kind = RenderMenuItemKind.Command, + Id = "videos", + Label = Loc.L("Editor.RenderMenu.Videos"), + Command = state.ShowVideos, + ToolTip = Loc.L("Tooltips.Editor.RenderMenu.Videos"), + }); + return items; + + RenderMenuItem Preset(ExportPreset preset, string? why) + { + shown.Add(preset.Id); + var name = Loc.L(preset.NameKey); + var details = state.Details(preset); + var tip = Loc.L("Tooltips.Editor.RenderMenu.Preset", name, details); + return new RenderMenuItem + { + Kind = RenderMenuItemKind.Preset, + Id = "preset:" + preset.Id, + Label = name, + Details = details.Length > 0 ? details : null, + IsChecked = string.Equals(preset.Id, state.CurrentPresetId, StringComparison.OrdinalIgnoreCase), + Command = state.SelectPreset, + CommandParameter = preset.Id, + ToolTip = why is null ? tip : tip + Loc.Separator + why, + }; + } + } + + /// "Video", "Social"…: the name of a preset group. + public static string GroupLabel(string group) + { + ArgumentException.ThrowIfNullOrEmpty(group); + return Loc.L("Export.Preset.Group." + char.ToUpperInvariant(group[0]) + group[1..].ToLowerInvariant()); + } + + /// "PNG", "JPEG", "TIFF 16-bit": a Save frame format. + public static string StillFormatName(VideoCodec codec) => Loc.L("Export.Codec." + codec); + + /// + /// "3840×2160 · HEVC Main10 · 24 fps": the size renders this sequence at (the preset's box + /// fitted to the chosen proportions, as the render does), its codec and its frame rate, with the export's own values + /// for the rest (as choosing it in the menu makes it); the preset's own size without a source size. + /// + public static string PresetDetails(ExportSettings export, string presetId, CameraSettings camera, int sourceWidth, int sourceHeight) + { + ArgumentNullException.ThrowIfNull(export); + ArgumentNullException.ThrowIfNull(camera); + var resolved = ExportResolver.Resolve(export with { Preset = export.Preset.WithManual(presetId), Overrides = new ExportOverrides(), Batch = [] }); + var (width, height) = sourceWidth > 0 && sourceHeight > 0 ? RenderSize.Of(camera, resolved, sourceWidth, sourceHeight) : (resolved.Width, resolved.Height); + var size = width > 0 && height > 0 ? EditorText.Size(width, height) : Loc.L("Export.Resolution.Source"); + return Loc.L("Editor.RenderMenu.Details", size, EditorText.CodecName(resolved.Codec, resolved.Profile, resolved.BitDepth), + Loc.L("Editor.Value.Fps", EditorText.FrameRate(resolved.FrameRate))); + } + + /// + /// The Render button's tooltip (decision 1): why it waits, when it does, then what it renders, "Render 4K HEVC · + /// 3840×2160 · HEVC Main10 · 24 fps · ~1.2 GB · ~4 min · Ctrl+R" (the size the encoder makes); for a server sequence, + /// where it renders. + /// + public static string RenderToolTip(ExportPlan? plan, string? blocked, string? server) + { + var lines = new List(3); + if (blocked is { Length: > 0 }) lines.Add(blocked); + if (plan is not null) + { + var (width, height) = plan.EncodedSize; + lines.Add(Loc.L("Tooltips.Editor.RenderDetails", plan.PresetName, width > 0 && height > 0 ? EditorText.Size(width, height) : Loc.L("Export.Resolution.Source"), + EditorText.CodecName(plan.Export.Codec, plan.Export.Profile, plan.Export.BitDepth), Loc.L("Editor.Value.Fps", EditorText.FrameRate(plan.Setup.Plan.FrameRate)), + Formatting.Bytes(plan.Estimate.Bytes), Formatting.Duration(plan.Estimate.Time))); + } + if (blocked is null && server is not null) lines.Add(Loc.L("Tooltips.Editor.RenderServer", server)); + if (lines.Count == 0) lines.Add(Loc.L("Tooltips.Editor.Render")); + return string.Join(Environment.NewLine, lines); + } + + /// The batch presets of an export besides its own, each once, in the order ticked (blank entries skipped). + public static IReadOnlyList BatchPresets(ExportSettings export) + { + ArgumentNullException.ThrowIfNull(export); + var own = ExportResolver.Resolve(export).BasePresetId; + return [.. export.Batch.Where(id => !string.IsNullOrWhiteSpace(id) && !id.Equals(own, StringComparison.OrdinalIgnoreCase)).Distinct(StringComparer.OrdinalIgnoreCase)]; + } + + /// + /// The presets (newest first, as ) were made with, newest + /// first and each once, at most ; saved frames do not count. + /// + public static IReadOnlyList RecentPresets(IReadOnlyList renders, int count = RecentCount) + { + ArgumentNullException.ThrowIfNull(renders); + return [.. renders.Where(r => RenderKind.Of(r) != RenderKind.Still).Select(PresetOf).OfType().Distinct(StringComparer.OrdinalIgnoreCase).Take(count)]; + } + + /// + /// The built-in preset a render was made with: from the settings it recorded, else from its preset name in the language + /// of the moment; null when neither tells (a custom export, settings no longer readable). + /// + public static string? PresetOf(Render render) + { + ArgumentNullException.ThrowIfNull(render); + if (render.SettingsJson is { Length: > 0 } json) + { + try + { + var resolved = ExportResolver.Resolve(ProjectSettings.FromJson(json, allowNewer: true).Export); + if (!resolved.IsCustom && Find(resolved.BasePresetId) is { } preset) return preset.Id; + } + catch (Exception ex) when (ex is JsonException or InvalidDataException or ArgumentException) + { + // Settings no longer readable say nothing: the name may still tell. + } + } + return ExportPresets.BuiltIn.FirstOrDefault(p => string.Equals(Loc.L(p.NameKey), render.PresetName, StringComparison.OrdinalIgnoreCase))?.Id; + } + + /// + /// Why Save frame waits (decision 12), in this order: the frames changed on the server, the project is shown read-only, + /// there is no frame to save under the cursor (none, or one the render leaves out), the source cannot save frames, the + /// server cannot (: no right, or an older Chronos), the file name is wrong; null when a + /// frame can be saved. + /// + public static string? SaveFrameBlockedReason(bool outdated, string? server, bool readOnly, bool hasFrame, bool sourceSavesFrames, string? serverReason, + string? nameError) + { + if (outdated) return Loc.L("Tooltips.Editor.Outdated", server); + if (readOnly) return Loc.L("Tooltips.Export.StillReadOnly"); + if (!hasFrame) return Loc.L("Tooltips.Export.StillNeedsFrame"); + // Missing key Tooltips.Export.StillWorkspace (a workspace project saves no frame yet): the closest reason until P8 adds it. + if (!sourceSavesFrames) return Loc.L("Tooltips.Export.StillReadOnly"); + if (serverReason is not null) return serverReason; + return nameError is null ? null : Loc.L("Tooltips.Editor.Render.NameError", nameError); + } + + private static ExportPreset? Find(string? id) => id is { Length: > 0 } ? ExportPresets.Find(id) : null; + + private static bool Same(ExportPreset preset, ExportPreset? other) => other is not null && preset.Id.Equals(other.Id, StringComparison.OrdinalIgnoreCase); + + private static int GroupRank(string group) + { + for (var i = 0; i < GroupOrder.Count; i++) + { + if (GroupOrder[i].Equals(group, StringComparison.OrdinalIgnoreCase)) return i; + } + return GroupOrder.Count; + } +} diff --git a/src/Chronos.App/Editor/ServerJobs.cs b/src/Chronos.App/Editor/ServerJobs.cs index 890c3ff9..90f779c1 100644 --- a/src/Chronos.App/Editor/ServerJobs.cs +++ b/src/Chronos.App/Editor/ServerJobs.cs @@ -5,8 +5,11 @@ using System.Text.Json; using Chronos.Core.Diagnostics; using Chronos.Core.Localization; using Chronos.Core.Model; +using Chronos.Core.Project; +using Chronos.Core.Render; using Chronos.Data.Archiving.Jobs; using Chronos.Data.Jobs; +using Chronos.Data.Processing; using Chronos.Protocol; using Chronos.Protocol.Client; @@ -63,6 +66,24 @@ internal sealed class ServerJobs : IAsyncDisposable /// public static string? NeedsNewerServer(int required, int serverFormat) => required > serverFormat ? Loc.L("Tooltips.Server.NeedsNewerServer") : null; + /// + /// Why a render of with cannot go to a server that reads + /// (owner review 1, phase 5: playback needs format 3); null when it can. The format is the + /// one of the job's own export, its playback included, never the project's export alone (). + /// + public static string? RenderNeedsNewerServer(ProjectSettings settings, ExportSettings export, int sourceWidth, int sourceHeight, int serverFormat) + { + ArgumentNullException.ThrowIfNull(settings); + ArgumentNullException.ThrowIfNull(export); + return NeedsNewerServer(ProcessingJobs.RequiredFormat(settings with { Export = export }, export, sourceWidth, sourceHeight), serverFormat); + } + + /// + /// Why "Save frame" cannot go to a server that reads : a still job needs + /// , which an older server's nodes would render as a whole video; null when it can. + /// + public static string? StillNeedsNewerServer(int serverFormat) => NeedsNewerServer(RenderRules.StillFormat, serverFormat); + /// Queues on the server (its priority set after, when it is not the user's); returns the job id. /// The sequence is gone from the server. public async Task SubmitAsync(ArchiveJobRequest request, CancellationToken cancellationToken) diff --git a/src/Chronos.App/Sections/SequenceView.xaml b/src/Chronos.App/Sections/SequenceView.xaml index 00762e8e..84743c60 100644 --- a/src/Chronos.App/Sections/SequenceView.xaml +++ b/src/Chronos.App/Sections/SequenceView.xaml @@ -121,6 +121,9 @@ ToolTip="{Binding Project.SaveVersionToolTip}" ToolTipService.ShowOnDisabled="True" /> + + @@ -162,8 +165,10 @@