Files
Chronos/src/Chronos.App/Editor/EditorSettings.cs
T
Alby96andClaude Opus 5.5 503b5f766a feat(P6): grouped Export panel with preset table, encoding and playback rows
The Export step's cards and long form gave no room for the advanced
encoding settings and the new playback contract. The Output panel is now
four collapsible groups (Output, Encoding, Playback, File) with a muted
summary while closed and a fixed footer (result line, Render now, Add to
queue, Batch (n), Videos (n), Reveal, Send again). Presets become a 28 px
table grouped by preset group.

- Encoding: rate control, bit rate or quality, keyframes in seconds kept
  across a frame rate change, B-frames and profile, each gated per codec
  and depth with the reason in the tooltip.
- Resolution: Preset, Source, the standard boxes fitted to the chosen
  proportions (4K at 9:16 renders 2160 x 3840) and Custom.
- Playback: direction (Boomerang gated with star trails), loops, fades
  and hold; a non-default playback writes settings format 3.
- Group open state is kept by the app through EditorSettings.Groups
  (bound to the app settings later), not in the project.
- ExportPlan carries the output program for duration and frame count.
- The tab resolves the export at once instead of from a stale plan.

Refs #21

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-05 02:26:04 +01:00

206 lines
11 KiB
C#

using Chronos.Core.Advice;
using Chronos.Core.Analysis;
using Chronos.Core.Analysis.Deep;
using Chronos.Core.Export;
using Chronos.Core.Motion;
using Chronos.Core.Project;
namespace Chronos.App.Editor;
/// <summary>An advisor-decided setting of the editor, whatever its value type.</summary>
public interface IAutoSetting
{
/// <summary><see cref="AdvisorParameters"/> id.</summary>
string Id { get; }
AdvisorSection Section { get; }
bool IsAuto(ProjectSettings project);
/// <summary>Drops the manual value so the advice applies.</summary>
ProjectSettings Reset(ProjectSettings project);
}
/// <summary>
/// One <see cref="Auto{T}"/> member of the project (BRIEF §10.4) and the value the engine uses when the advisor has
/// none (<see cref="Fallback"/>, from the deep analysis when it measured one).
/// </summary>
public sealed class AutoSetting<T>(
string id,
AdvisorSection section,
Func<ProjectSettings, Auto<T>> get,
Func<ProjectSettings, Auto<T>, ProjectSettings> set,
Func<ProjectSettings, DeepAnalysisReport?, T> fallback) : IAutoSetting
where T : notnull
{
public string Id { get; } = id;
public AdvisorSection Section { get; } = section;
public Auto<T> Get(ProjectSettings project) => get(project);
public bool IsAuto(ProjectSettings project) => get(project).IsAuto;
/// <summary>The advisor's value, else what the engine uses without advice.</summary>
public T AutoValue(ProjectSettings project, DeepAnalysisReport? deep) => get(project) is { HasAdvice: true, AutoValue: { } advised } ? advised : fallback(project, deep);
/// <summary>The value in force.</summary>
public T Effective(ProjectSettings project, DeepAnalysisReport? deep) => get(project).Resolve(fallback(project, deep));
/// <summary>Touching the control: the value becomes manual.</summary>
public ProjectSettings WithManual(ProjectSettings project, T value) => set(project, get(project).WithManual(value));
public ProjectSettings Reset(ProjectSettings project) => set(project, get(project).Reset());
}
/// <summary>
/// Which collapsible groups of the editor are open, by group key ("export.encoding", "preset.social"): a group nobody
/// toggled opens as its default says. Until <see cref="Bind"/> attaches the app's settings the state lives for the run;
/// bound, each toggle is written there and saved.
/// </summary>
public sealed class GroupStates
{
private readonly Lock _lock = new();
private IDictionary<string, bool> _store = new Dictionary<string, bool>(StringComparer.Ordinal);
private Action? _save;
/// <summary>Keeps the state in <paramref name="store"/> (the app's settings), calling <paramref name="save"/> after each toggle.</summary>
public void Bind(IDictionary<string, bool> store, Action? save)
{
ArgumentNullException.ThrowIfNull(store);
lock (_lock)
{
// What was toggled before the settings were attached stays.
foreach (var (key, open) in _store)
{
if (!store.ContainsKey(key)) store[key] = open;
}
(_store, _save) = (store, save);
}
}
/// <summary>Whether the group <paramref name="key"/> is open; <paramref name="fallback"/> when it was never toggled.</summary>
public bool IsExpanded(string key, bool fallback)
{
lock (_lock) return _store.TryGetValue(key, out var open) ? open : fallback;
}
/// <summary>Remembers that the group <paramref name="key"/> is open or closed.</summary>
public void Set(string key, bool expanded)
{
ArgumentNullException.ThrowIfNull(key);
Action? save;
lock (_lock)
{
if (_store.TryGetValue(key, out var open) && open == expanded) return;
_store[key] = expanded;
save = _save;
}
save?.Invoke();
}
}
/// <summary>The Auto settings of the editor's sections, in panel order.</summary>
public static class EditorSettings
{
public static readonly AutoSetting<TimingMode> TimingMode = new(AdvisorParameters.TimingMode, AdvisorSection.Timing,
p => p.Timing.Mode, (p, a) => p with { Timing = p.Timing with { Mode = a } }, (_, _) => Core.Project.TimingMode.Constant);
/// <summary>Playback rate; without a value it equals the export frame rate (DECISIONS: export fps vs playback rate).</summary>
public static readonly AutoSetting<string> FrameRate = new(AdvisorParameters.FrameRate, AdvisorSection.Timing,
p => p.Timing.FrameRate, (p, a) => p with { Timing = p.Timing with { FrameRate = a } },
(p, _) => FrameRateText.Format(ExportResolver.Resolve(p.Export).FrameRate));
public static readonly AutoSetting<bool> Deflicker = new(AdvisorParameters.Deflicker, AdvisorSection.Exposure,
p => p.Exposure.Deflicker, (p, a) => p with { Exposure = p.Exposure with { Deflicker = a } }, (_, _) => false);
public static readonly AutoSetting<int> DeflickerWindow = new(AdvisorParameters.DeflickerWindow, AdvisorSection.Exposure,
p => p.Exposure.DeflickerWindow, (p, a) => p with { Exposure = p.Exposure with { DeflickerWindow = a } },
(_, deep) => deep?.Flicker.RecommendedWindow ?? DeflickerOptions.Default.Window);
public static readonly AutoSetting<double> DeflickerStrength = new(AdvisorParameters.DeflickerStrength, AdvisorSection.Exposure,
p => p.Exposure.DeflickerStrength, (p, a) => p with { Exposure = p.Exposure with { DeflickerStrength = a } }, (_, _) => DeflickerOptions.Default.Strength);
public static readonly AutoSetting<RegionMode> Regions = new(AdvisorParameters.Regions, AdvisorSection.Exposure,
p => p.Exposure.Regions, (p, a) => p with { Exposure = p.Exposure with { Regions = a } }, (_, _) => RegionMode.Off);
public static readonly AutoSetting<bool> HolyGrail = new(AdvisorParameters.HolyGrail, AdvisorSection.Exposure,
p => p.Exposure.HolyGrail, (p, a) => p with { Exposure = p.Exposure with { HolyGrail = a } }, (_, _) => false);
public static readonly AutoSetting<int> TransitionLength = new(AdvisorParameters.TransitionLength, AdvisorSection.Exposure,
p => p.Exposure.TransitionLength, (p, a) => p with { Exposure = p.Exposure with { TransitionLength = a } },
(_, deep) => deep?.Exposure.TransitionLength ?? new HolyGrailOptions().SingleStepTransitionFrames);
public static readonly AutoSetting<bool> WhiteBalance = new(AdvisorParameters.WhiteBalanceSmoothing, AdvisorSection.Exposure,
p => p.Exposure.WhiteBalanceSmoothing, (p, a) => p with { Exposure = p.Exposure with { WhiteBalanceSmoothing = a } }, (_, _) => false);
public static readonly AutoSetting<bool> MotionBlur = new(AdvisorParameters.MotionBlur, AdvisorSection.Motion,
p => p.Motion.MotionBlur, (p, a) => p with { Motion = p.Motion with { MotionBlur = a } }, (_, _) => false);
public static readonly AutoSetting<double> ShutterAngle = new(AdvisorParameters.TargetShutterAngle, AdvisorSection.Motion,
p => p.Motion.TargetShutterAngle, (p, a) => p with { Motion = p.Motion with { TargetShutterAngle = a } }, (_, _) => 180.0);
public static readonly AutoSetting<FlowQualitySetting> FlowQuality = new(AdvisorParameters.FlowQuality, AdvisorSection.Motion,
p => p.Motion.FlowQuality, (p, a) => p with { Motion = p.Motion with { FlowQuality = a } }, (_, _) => FlowQualitySetting.Balanced);
public static readonly AutoSetting<bool> Stabilize = new(AdvisorParameters.Stabilize, AdvisorSection.Motion,
p => p.Motion.Stabilize, (p, a) => p with { Motion = p.Motion with { Stabilize = a } }, (_, _) => false);
public static readonly AutoSetting<double> StabilizeSmoothing = new(AdvisorParameters.StabilizeSmoothing, AdvisorSection.Motion,
p => p.Motion.StabilizeSmoothing, (p, a) => p with { Motion = p.Motion with { StabilizeSmoothing = a } }, (_, _) => new StabilizerOptions().SmoothingSigma);
public static readonly AutoSetting<string> Aspect = new(AdvisorParameters.Aspect, AdvisorSection.Camera,
p => p.Camera.Aspect, (p, a) => p with { Camera = p.Camera with { Aspect = a } }, (_, _) => "source");
public static readonly AutoSetting<string> ExportPreset = new(AdvisorParameters.ExportPreset, AdvisorSection.Export,
p => p.Export.Preset, (p, a) => p with { Export = p.Export with { Preset = a } }, (_, _) => ExportResolver.DefaultPresetId);
public static IReadOnlyList<IAutoSetting> All { get; } =
[
TimingMode, FrameRate, Deflicker, DeflickerWindow, DeflickerStrength, Regions, HolyGrail, TransitionLength, WhiteBalance,
MotionBlur, ShutterAngle, FlowQuality, Stabilize, StabilizeSmoothing, Aspect, ExportPreset,
];
/// <summary>"Reset": every Auto setting of <paramref name="section"/> back to Auto; stacking (no advice) back to off.</summary>
public static ProjectSettings ResetSection(ProjectSettings project, AdvisorSection section)
{
ArgumentNullException.ThrowIfNull(project);
foreach (var setting in All)
{
if (setting.Section == section) project = setting.Reset(project);
}
return section == AdvisorSection.Stack ? project with { Stack = new StackSettings() } : project;
}
/// <summary>True when every Auto setting of <paramref name="section"/> is in Auto.</summary>
public static bool IsSectionAuto(ProjectSettings project, AdvisorSection section) =>
All.Where(s => s.Section == section).All(s => s.IsAuto(project));
/// <summary>
/// The collapse state of the Export step's setting groups and preset groups (owner review 1, R3; DESIGN §4 collapsible
/// group): this user's, kept by the app and not in the project.
/// </summary>
public static GroupStates Groups { get; } = new();
/// <summary>
/// Whether <paramref name="setting"/> applies under the switches in force: the deflicker window, strength and regions
/// with deflicker on, the transition length with holy grail on, the shutter angle with motion blur on, the flow quality
/// with motion blur or interpolated timing, the stabiliser's smoothing with stabilisation on. A setting that does not
/// apply shows n/a in its row (which cannot be taken over by hand then), and the Edit path asks nothing about it.
/// </summary>
public static bool Applies(IAutoSetting setting, ProjectSettings project, DeepAnalysisReport? deep)
{
ArgumentNullException.ThrowIfNull(setting);
ArgumentNullException.ThrowIfNull(project);
return setting.Id switch
{
AdvisorParameters.DeflickerWindow or AdvisorParameters.DeflickerStrength or AdvisorParameters.Regions => Deflicker.Effective(project, deep),
AdvisorParameters.TransitionLength => HolyGrail.Effective(project, deep),
AdvisorParameters.TargetShutterAngle => MotionBlur.Effective(project, deep),
AdvisorParameters.FlowQuality => MotionBlur.Effective(project, deep) || TimingMode.Effective(project, deep) == Core.Project.TimingMode.Interpolated,
AdvisorParameters.StabilizeSmoothing => Stabilize.Effective(project, deep),
_ => true,
};
}
}