feat(chroma): opt-in auto key, and alert clips key like any other clip
TASK 64 slice F — the two things left after the feature worked by hand. - App Settings → **Video clips → Auto Green/Blue Screen** (off by default). When on, a high-confidence detected screen is keyed as soon as the clip is added; the panel says "Removed automatically" so an automatic change is never silent. Medium confidence still asks, low says nothing — a wrong automatic key eats the picture. - **A clip is a clip:** the alert box's own replacement clip keys through the same settings block (one alert box per layout, so its settings are the ones the next alert uses), and choosing an alert clip runs the same detector. The Green/Blue Screen panel now appears for a video layer *or* an alert box with a custom clip (`Source.ShowsChromaKey`). - Spill ships as the creator-facing **Fringe** switch; nothing further to tune behind it. Test: `ChromaKeyApplyTests` gains the auto-apply case (no click, still explicit in the panel) and an alert-clip case (its pipe asks ffmpeg for colorkey+despill with the blue screen type). Docs: TASK 64 complete in TASKS.md, known limits recorded in the task file, HANDOFF rewritten. verify.sh: 546 passed, 0 failed, 0 warnings.
This commit is contained in:
@@ -140,7 +140,10 @@ public partial class MainViewModel : ViewModelBase
|
||||
path, width, height,
|
||||
new FfmpegLocator(),
|
||||
() => new FfmpegDecodeProcess(),
|
||||
frameRateProbe: new FfmpegFrameRateProbe(new FfmpegLocator(), () => new FfmpegDecodeProcess()));
|
||||
frameRateProbe: new FfmpegFrameRateProbe(new FfmpegLocator(), () => new FfmpegDecodeProcess()),
|
||||
// TASK 64: an alert clip is a clip — it keys through the same settings block. The
|
||||
// layout has one alert box, so its settings are the ones the next alert uses.
|
||||
chromaKey: AlertBoxChromaKey());
|
||||
|
||||
/// <summary>Stamp the shipped llama placeholder into the Asset table at startup
|
||||
/// (idempotent — hash-keyed UpsertAsset dedupes). Best-effort: if it fails the
|
||||
@@ -179,6 +182,13 @@ public partial class MainViewModel : ViewModelBase
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The alert zone's own green/blue screen settings (one alert box per layout).</summary>
|
||||
private ChromaKeyOptions? AlertBoxChromaKey()
|
||||
=> Scenes.SelectMany(scene => scene.Elements).OfType<Source>()
|
||||
.FirstOrDefault(source => source.IsAlertBox)?.ChromaKey is { Enabled: true } key
|
||||
? key
|
||||
: null;
|
||||
|
||||
private void BrowseAlertVideo(Source? box)
|
||||
{
|
||||
if (box == null || box.Type != SourceType.AlertBox) return;
|
||||
@@ -190,6 +200,8 @@ public partial class MainViewModel : ViewModelBase
|
||||
if (dialog.ShowDialog() != true) return;
|
||||
box.AlertVideoPath = dialog.FileName;
|
||||
box.AlertUseDefaultVideo = false;
|
||||
// Offer the key for the chosen clip (same detector as a media layer).
|
||||
_ = SuggestChromaKeyAsync(box);
|
||||
}
|
||||
|
||||
private void BrowseAlertAudio(Source? box)
|
||||
|
||||
@@ -37,6 +37,21 @@ public partial class MainViewModel
|
||||
// One probe per file per launch — the answer belongs to the file, not to the layer.
|
||||
private readonly HashSet<string> _chromaProbedPaths = new(StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
private bool _autoChromaScreen;
|
||||
|
||||
/// <summary>"Auto Green/Blue Screen": apply a detected screen without asking. Off by default —
|
||||
/// the app offers, and only a creator who turns this on gets it done for them. Fires only on
|
||||
/// high-confidence detections, because a wrong automatic key eats the picture.</summary>
|
||||
public bool AutoChromaScreen
|
||||
{
|
||||
get => _autoChromaScreen;
|
||||
set
|
||||
{
|
||||
if (!SetProperty(ref _autoChromaScreen, value)) return;
|
||||
_layoutStore.SaveAutoChromaScreen(value);
|
||||
}
|
||||
}
|
||||
|
||||
// One subscription per media Source, so removing a layer stops the listener as
|
||||
// well as the decoder (a scene element outlives its layer list row).
|
||||
private readonly Dictionary<string, PropertyChangedEventHandler> _mediaHandlers = new();
|
||||
@@ -102,19 +117,37 @@ public partial class MainViewModel
|
||||
// ---------- green / blue screen detection (TASK 64) ----------
|
||||
|
||||
/// <summary>Looks at one frame of the clip and stores the offer on the layer. Runs off the
|
||||
/// UI thread through the probe seam; a file that cannot be read simply gets no offer.</summary>
|
||||
/// UI thread through the probe seam; a file that cannot be read simply gets no offer.
|
||||
/// Works for a video layer and for the alert box's own clip — a clip is a clip.</summary>
|
||||
private async System.Threading.Tasks.Task SuggestChromaKeyAsync(Source source)
|
||||
{
|
||||
if (!source.IsMediaSource || source.MediaPath is not { } path) return;
|
||||
if (source.ChromaKeyEnabled) return;
|
||||
if (ClipPathFor(source) is not { } path) return;
|
||||
if (_chromaProbe == null) return;
|
||||
|
||||
var frame = await _chromaProbe.ProbeAsync(path).ConfigureAwait(true);
|
||||
if (frame == null) return;
|
||||
if (!string.Equals(source.MediaPath, path, StringComparison.OrdinalIgnoreCase)) return;
|
||||
if (!string.Equals(ClipPathFor(source), path, StringComparison.OrdinalIgnoreCase)) return;
|
||||
|
||||
source.ChromaSuggestion = ChromaKeyDetector.Detect(frame);
|
||||
var suggestion = ChromaKeyDetector.Detect(frame);
|
||||
source.ChromaSuggestion = suggestion;
|
||||
|
||||
if (AutoChromaScreen && suggestion.IsHighConfidence)
|
||||
{
|
||||
AcceptChromaSuggestion(source);
|
||||
source.ChromaKeyAutoApplied = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>The file a layer plays: a video layer's clip, or the alert box's replacement clip.
|
||||
/// The shipped alert default is not probed — it is ours, and it is not a screen shoot.</summary>
|
||||
private static string? ClipPathFor(Source source)
|
||||
=> source.IsMediaSource
|
||||
? source.MediaPath
|
||||
: source.Type == SourceType.AlertBox && !source.AlertUseDefaultVideo
|
||||
? source.AlertVideoPath
|
||||
: null;
|
||||
|
||||
/// <summary>Accepts the detector's offer: the layer keys the colour the camera actually saw.</summary>
|
||||
private void AcceptChromaSuggestion(Source? source)
|
||||
{
|
||||
@@ -126,6 +159,7 @@ public partial class MainViewModel
|
||||
source.ChromaKeySoftness = key.Softness;
|
||||
source.ChromaKeySpill = key.Spill;
|
||||
source.ChromaScreen = key.Screen;
|
||||
source.ChromaKeyAutoApplied = false;
|
||||
source.ChromaKeyEnabled = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -344,6 +344,7 @@ public partial class MainViewModel : ViewModelBase
|
||||
MicSourceName = _layoutStore.LoadMicSourceName();
|
||||
AudioSyncOffsetMs = _layoutStore.LoadAudioSyncOffsetMs();
|
||||
_zoomFollowsBox = _layoutStore.LoadZoomFollowBox();
|
||||
_autoChromaScreen = _layoutStore.LoadAutoChromaScreen();
|
||||
MonoOutput = _layoutStore.LoadMonoOutput(); // applied to the mixer by the setter
|
||||
_musicPlayer.UserGain = (float)Helpers.GainDb.FromDb(TraxDefaultDb); // background by default
|
||||
InitScoreboard();
|
||||
|
||||
Reference in New Issue
Block a user