diff --git a/README.md b/README.md index 07b2d321..c167c06d 100644 --- a/README.md +++ b/README.md @@ -153,18 +153,21 @@ macOS the system's buttons and edges stay. It holds, from the left: The **strip** holds: - A **pad** for each scene, its picture redrawn a few times a second, with its - name, its hotkey, and an ON AIR tag on the scene on program. Click a pad to - take its scene on air by the show's transition (see - [Transitions](#transitions)); taking the scene already on air does nothing. - A scene that cannot go on air, of another size or showing the program, has - a dimmed pad that says why under the pointer. Right-click a pad to take its - scene, mark it the safe scene, rename it, duplicate it, move it left or + name, its hotkey, an ON AIR tag on the scene on program, and a NEXT tag on + the scene cued or open off air. Click a pad to take its scene on air by the + show's transition (see [Transitions](#transitions)), or to cue it in + [Studio mode](#off-air-and-studio-mode); clicking the scene already on air + leaves nothing cued. A scene that cannot go on air, of another size or + showing the program, has a dimmed pad that says why under the pointer. + Right-click a pad to take its scene, cue it in Studio mode, **Edit off + air**, mark it the safe scene, rename it, duplicate it, move it left or right, or remove it. **Duplicate** adds a scene after it showing the same sources, linked, so an edit to a source's look shows in both; **Duplicate with its own copies** gives each of its layers a copy of its source to edit apart (a scene or the program drawn in it stays one picture). A pad ringed in red says what just failed on it under the pointer. The last pad, **+**, - adds an empty scene without taking it. + adds an empty scene without taking it, and the switch after it turns + [Studio mode](#off-air-and-studio-mode) on and off. - The **panic key**, amber and named for the safe scene: it mutes every microphone and every guest (their camera's sound and their screen's), hides every always-on-top layer, whatever it shows, in one edit undo takes back, @@ -178,8 +181,8 @@ The **strip** holds: | Page | Use it to | | --- | --- | -| LIVE | Watch the program while on air. | -| BUILD | Edit the scene on program, shown in the middle, with its layers and what can be added on the left and the inspector on the right (see [BUILD](#build)). | +| LIVE | Watch the program while on air, and TAKE or AUTO a cued scene. | +| BUILD | Edit the scene on program, or the one open off air, shown in the middle, with its layers and what can be added on the left and the inspector on the right (see [BUILD](#build)). | | MIX | Add, rename, reorder, and remove audio scenes, pick the audio scene on program and the one to listen to and on which output, set each sound's gain, pan, mute, and delay, and send each sound and audio scene into audio scenes, with a meter on every one. The program shows small in the strip's place for the sound. | | REVIEW | Replay the last moments of the program or a source in a replay source, slowed down if you like, or save them as a clip (see [Replay](#replay)), and start and stop recording and pick the picture and the audio scene it records (see [Recording](#recording)), beside the program. | @@ -198,13 +201,13 @@ edit there succeeds. ### BUILD -BUILD edits the scene on air as viewers see it: every change is live at once. -What a scene draws is a stack of **layers**, each placing one source. +BUILD edits the scene on air as viewers see it: every change is live at once, +unless a scene is open [off air](#off-air-and-studio-mode). What a scene draws is a stack of **layers**, each placing one source. **Layers**, on the left, lists them front first in two groups: **Always on top**, drawn over every scene on program and staying on through a cut or transition (a downstream keyer for a logo or a lower third), and **This -scene**, the scene on program's own. Each row has an icon for the source's +scene**, the edited scene's own: the one on program, or the one open off air. Each row has an icon for the source's kind, its name, what it shows (and **linked ×3** when three layers show the source), and its eye, which shows or hides it. A lock shows on a locked row, and on the selected or pointed-at one to lock it. A dot says a source is not @@ -218,12 +221,12 @@ its own copy), make it independent, copy it, or remove it. **Add a layer** (A) turns to Add. **Add** lists what can be placed: the sources no layer shows, no audio scene -hears, and nothing reads, each with **Add**, to place it in the scene on -program, or the bin, to remove it for good; this machine's cameras, displays, +hears, and nothing reads, each with **Add**, to place it in the edited +scene, or the bin, to remove it for good; this machine's cameras, displays, windows, and audio inputs; any source by hand; and, with a room, guests: invite one, show their join link as a QR code in a sheet over the window, see who joined, and take a guest out of every scene. A new source with a picture -is placed in front of the scene on program, and selected. +is placed in front of the edited scene, and selected. On the **picture**, click a layer to select it, drag it to move it, and drag its edges or corners to resize it (see [Placing layers](#placing-layers)). A @@ -255,7 +258,7 @@ is named for it, with these sections: | Source | See what the source is and whether it and its own track are live. A camera or broadcast without a new picture, or a microphone or system audio without new sound, for a second reads as stalled; a broadcast says how far behind it plays, and a web page whether it is copied on the GPU or, as a fallback, uploaded from memory, saying why. A media file reads as ended once it plays to its end without looping: **Play** plays it from its start, **Stop** stops it at once, blank and silent, until played again, and **Reload** reads the file again; **Reload** restarts a web page, and opens a picked display or window again, as after the picker was cancelled or sharing stopped. Publish it independently (see [Published independently](#published-independently)), and set its own crop and filters, before the layer's, on every layer showing it. | Its **Animate** tab holds the layer's keyframes (see [Keyframes](#keyframes)). -With no layer selected, the inspector shows the scene on program: rename it, +With no layer selected, the inspector shows the edited scene: rename it, see its size, mark it **Safe**, switch on **Publish** and pick the audio scene it carries (see [Published scenes](#published-scenes)), and pick the show's transition and how long it takes, or for a stinger its media source and cut @@ -264,12 +267,37 @@ it in a transition, cannot be removed, even by an undo, until program cuts away from it. In a narrow window, the inspector is a tab beside Layers and Add. +### Off air and Studio mode + +**Edit off air**, in a pad's menu, opens its scene on BUILD without taking it: +the frame turns amber and reads OFF AIR, and the program shrinks to a corner +beside a banner. **Take it live** puts the scene on air by the show's +transition; **Back to live** goes back to editing the scene on air. Any scene +opens off air, even one that cannot go on air. One viewers see anyway, still +leaving program in a transition, published or recorded on its own, or shown +by a scene they see through a scene source, reads NOT ON PROGRAM instead, and +the banner says how they see it, since an edit reaches them. Off air, Layers +lists the scene's own layers alone: the always-on-top ones are drawn on +program, so editing them, or keeping a layer always on top, waits for **Back +to live**. + +**Studio mode**, off by default, is for an operator running a show: with its +switch at the end of the scene strip on, a pad or a scene's hotkey cues its +scene instead of taking it. A NEXT card docks on the program, on LIVE and on +BUILD, with the cued scene as it will go on air, its keyframes and overlays +started over. **TAKE** puts it on air at once and **AUTO** by the show's +transition; **Edit** opens it off air, from where **Back to live** leaves it +cued; and the close clears the cue. On BUILD the card moves to the opposite +corner while the selected layer is under it, so it hides neither the layer +nor its toolbar, even mid-drag. Studio mode is kept per user, with +the [hotkeys](#hotkeys), not in the scene file. + ### Settings | Tab | Use it to | | --- | --- | | Show | Set the canvas size and frame rate and each scene's size, see the broadcast path, whether the program is encoding, the encoder sessions open, and the encoder work of the program, the recording, and each published scene, and turn the virtual camera of the program or of each published scene on. | -| Hotkeys | Bind keys to the panic key, replay, save a clip, start or stop recording, and take each scene, and clear them (see [Hotkeys](#hotkeys)). | +| Hotkeys | Bind keys to the panic key, TAKE, AUTO, Studio mode, replay, save a clip, start or stop recording, and take or cue each scene, and clear them (see [Hotkeys](#hotkeys)). | | Effects | Pick how the window's [effects](#effects) move. | | Advanced | See the sources, scenes, and audio scenes as nodes, wired left to right to what draws or holds them, and wire them there (see [Scene graph](#scene-graph)). | @@ -395,9 +423,9 @@ Keyframes play once, from when the layer's scene goes on program, and hold the last keyframe; before the first, the layer holds the first. A cut or transition starts them again, while a scene leaving in a transition carries on with its own. Press **Play** in the Animate tab to play the scene on program's again -from now. They are drawn on the program clock, so the stream, a recording, and -a replay of the program show the same frames. Always-on-top layers have none, -since they never go on. +from now, or a scene open off air's in its own picture alone. They are drawn +on the program clock, so the stream, a recording, and a replay of the program +show the same frames. Always-on-top layers have none, since they never go on. Dragging a layer on BUILD grabs it where its keyframes have it and moves where it rests, so its whole animation moves with it. @@ -1268,14 +1296,15 @@ a WebGL page runs slower. ## Hotkeys -The Hotkeys tab in Settings binds a key to the **Panic** key, **Replay**, -**Save clip**, starting or stopping a recording, and taking each scene, as its -pad does. Press **Bind**, then the key with any modifiers; Escape, or leaving +The Hotkeys tab in Settings binds a key to the **Panic** key, TAKE and AUTO +for the cued scene, turning [Studio mode](#off-air-and-studio-mode) on or off, +**Replay**, **Save clip**, starting or stopping a recording, and each scene, +which its key takes, or cues in Studio mode, as its pad does; the tab says +which. Press **Bind**, then the key with any modifiers; Escape, or leaving the window or the tab, cancels. Every action starts unbound, so no key a game uses is taken unasked, and a key bound to one action is refused for another until it is cleared there. Replay, Save clip, and a recording use REVIEW's -picks. A key bound to **Cut** or **Transition**, which have no preview to act -on, is kept in the settings but neither shown nor fired. +picks. The key pressed is the key that fires, wherever it sits, on any keyboard layout and after a layout change: the tab names it as the layout printed it when it @@ -1317,7 +1346,8 @@ published scene, or a recording: - The program's tally frame glows blue while the studio is connected to a relay, the record dot pulses, and each cut or transition, from a pad, the - panic key, or a hotkey, bursts on the frame. + panic key, or a hotkey, bursts on the frame. Studio mode's TAKE is polished + metal that ripples under the pointer. - The Hotkeys tab shows each bound key on a dark plastic keycap, the title bar, the strip, and BUILD's columns have a faint grain, and first launch draws its screen over a soft gradient. diff --git a/quest/m0/ux/studio-mode.md b/quest/m0/ux/studio-mode.md deleted file mode 100644 index c9e5cd18..00000000 --- a/quest/m0/ux/studio-mode.md +++ /dev/null @@ -1,41 +0,0 @@ -# [M] Editing off air, and Studio mode - -## Goal - -Any scene can be opened for editing without going on air: the frame turns -amber, the tag reads OFF AIR, the live picture shrinks to a corner, and one -button takes the scene live or returns to the live one. See the -[off-air frame](/quest/m0/ux/mock/shell-offair.webp). - -Studio mode, off by default, uses the same staging for a show run by an -operator. A switch at the end of the scene strip turns it on, and then a -scene click cues instead of taking: the pad turns amber, a NEXT monitor docks -on the picture, and TAKE or AUTO puts the cued scene on air, as in the -[Studio mode frame](/quest/m0/ux/mock/shell-studio.webp). - -## Plan - -Decided 2026-11-09 (maintainer, /quest-plan): ✅ cue and take (rejected: a -Preview and Program split, which halves the live picture and is what the -studio had; no mode at all, leaving only off-air editing). - -- Both are the compositor's existing preview scene: off-air editing shows it - large with the program small, and Studio mode shows it small with the - program large. One mechanism, two arrangements. -- With Studio mode on, a scene's hotkey cues it, and the Cut and Transition - actions are TAKE and AUTO. With it off, a scene's hotkey takes it. The - Hotkeys settings say which, and the switch itself can be bound. -- Studio mode is kept per user with the other editor settings, not in the - scene file: it is how one operator works, not part of the show. -- The NEXT monitor never covers the same corner as the item being dragged; - it moves to the opposite one. -- Keyframes and overlays restart in the cued scene as they do today when a - scene goes into preview, so NEXT shows the entrance the audience will see. -- The LIVE page left two things ready: the compositor draws no preview - (`set_previewing(false)` in `Studio::new`, `rs/moq-studio/src/ui.rs`), and - keys bound to Cut and Transition are kept unshown (`Studio::hidden`). Turn - the preview on while a scene is cued, and show both actions again. The - metal TAKE button's effect (`Fx::button`) waits in `rs/moq-studio/src/fx.rs`. - -Human check: an operator's judgment that cue, TAKE, and AUTO feel like a -switcher, on a real show with several scenes. diff --git a/quest/m1/multiview.md b/quest/m1/multiview.md index c0d2641c..7ea23e0b 100644 --- a/quest/m1/multiview.md +++ b/quest/m1/multiview.md @@ -24,7 +24,3 @@ It is the operator's view a broadcast studio expects beside Studio mode. [the privacy shield](/quest/m1/privacy-shield.md) keeps it out of capture. Human check: on a real second monitor, at a distance. - -## Required - -- [Editing off air, and Studio mode](/quest/m0/ux/studio-mode.md) - cue, take, and the amber and accent it shows diff --git a/rs/moq-studio/src/controls.rs b/rs/moq-studio/src/controls.rs index e5a316ad..73fa847d 100644 --- a/rs/moq-studio/src/controls.rs +++ b/rs/moq-studio/src/controls.rs @@ -15,15 +15,15 @@ use crate::replay; /// Something a hotkey can be bound to. #[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)] pub enum Action { - /// Put the preview on program at once. Studio mode's TAKE - /// (quest/m0/ux/studio-mode.md); until then the preview is always the - /// scene on program, so it is not offered. + /// TAKE: put the cued scene on program at once. Cut, - /// Take the preview to program by the show's transition: Studio mode's - /// AUTO, not offered until then either. + /// AUTO: take the cued scene to program by the show's transition. Transition, - /// Take a scene, by name, on program by the show's transition. + /// Take a scene, by name, on program by the show's transition, or cue it + /// while Studio mode is on. Scene(String), + /// Turn Studio mode on or off. + StudioMode, /// Play the recent past the Replay panel picks in its replay source. Replay, /// Save the recent past the Replay panel picks as a clip. @@ -35,21 +35,36 @@ pub enum Action { } impl Action { - /// The actions every scene file has, as the Hotkeys panel lists them. - pub const FIXED: [Self; 4] = [Self::Panic, Self::Replay, Self::SaveClip, Self::Record]; + /// The actions every scene file has, as the Hotkeys tab lists them. + pub const FIXED: [Self; 7] = [ + Self::Panic, + Self::Cut, + Self::Transition, + Self::StudioMode, + Self::Replay, + Self::SaveClip, + Self::Record, + ]; - /// Whether a key can be bound to it: a fixed action, or a scene. - pub fn offered(&self) -> bool { - matches!(self, Self::Scene(_)) || Self::FIXED.contains(self) + /// What it does with Studio mode on or off, as the Hotkeys tab and a + /// hotkey's message name it. + pub fn name(&self, studio: bool) -> String { + match (self, studio) { + (Self::Scene(name), true) => format!("Cue scene `{name}`"), + (Self::Scene(name), false) => format!("Take scene `{name}`"), + _ => self.to_string(), + } } } impl std::fmt::Display for Action { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { - Self::Cut => write!(f, "Cut"), - Self::Transition => write!(f, "Transition"), - Self::Scene(name) => write!(f, "Take scene `{name}`"), + Self::Cut => write!(f, "Take the cued scene"), + Self::Transition => write!(f, "Auto: take the cued scene by the transition"), + // The desktop's shortcut settings show it whichever mode is on. + Self::Scene(name) => write!(f, "Take or cue scene `{name}`"), + Self::StudioMode => write!(f, "Turn Studio mode on or off"), Self::Replay => write!(f, "Replay"), Self::SaveClip => write!(f, "Save clip"), Self::Record => write!(f, "Start or stop recording"), @@ -66,6 +81,9 @@ pub struct Controls { pub replay: Mutex, /// Whether the next recording gives each source a file of its own too. pub record_sources: AtomicBool, + /// Whether Studio mode is on: a scene's pad or key cues it rather than + /// taking it. + studio: AtomicBool, /// How the last action a hotkey fired went, until the status bar takes it. fired: Arc>>>, } @@ -100,25 +118,51 @@ impl Controls { runtime, replay: Mutex::default(), record_sources: AtomicBool::new(false), + studio: AtomicBool::new(false), fired: Arc::default(), } } + /// Whether Studio mode is on. + pub fn studio(&self) -> bool { + self.studio.load(Ordering::Relaxed) + } + + /// Turn Studio mode on or off. + pub fn set_studio(&self, on: bool) { + self.studio.store(on, Ordering::Relaxed); + } + + /// Do what a scene's key does to the scene called `name`, under `state` + /// locked by the caller: cue it in Studio mode, or else take it. + pub fn scene(&self, state: &mut State, name: &str) -> anyhow::Result { + match self.studio() { + true => cue(state, name), + false => take(state, name), + } + } + /// Do `action`, saying what it did. pub fn fire(&self, action: &Action) -> anyhow::Result { match action { Action::Cut => { - let mut state = self.engine.state.lock().unwrap(); - state.cut()?; - Ok(format!("cut to {}", on_program(state.compositor.program_scene()))) + let scene = self.engine.state.lock().unwrap().take_cued(None)?; + Ok(format!("took `{scene}`")) } Action::Transition => { let mut state = self.engine.state.lock().unwrap(); let transition = state.collection().transition.clone(); - state.transition(transition, kio::clock::Instant::now())?; - Ok(format!("took {}", on_program(state.compositor.program_scene()))) + let scene = state.take_cued(Some((transition, kio::clock::Instant::now())))?; + Ok(format!("took `{scene}`")) + } + Action::Scene(name) => self.scene(&mut self.engine.state.lock().unwrap(), name), + Action::StudioMode => { + let on = !self.studio.fetch_xor(true, Ordering::Relaxed); + Ok(match on { + true => "Studio mode on: a scene's pad or key cues it".into(), + false => "Studio mode off: a scene's pad or key takes it".into(), + }) } - Action::Scene(name) => take(&mut self.engine.state.lock().unwrap(), name), Action::Panic => self.engine.state.lock().unwrap().panic(self.engine.room.as_deref()), Action::Replay => self.replay(true, false), Action::SaveClip => self.replay(false, false), @@ -225,6 +269,7 @@ impl Controls { /// Keep how `action`, fired by a hotkey, went for the status bar. pub fn report(&self, action: &Action, result: Result) { + let action = action.name(self.studio()); *self.fired.lock().unwrap() = Some(result.map_err(|err| format!("{action}: {err}"))); } @@ -241,9 +286,12 @@ pub fn take(state: &mut State, name: &str) -> anyhow::Result { Ok(format!("took `{scene}`")) } -fn on_program(scene: Option<&str>) -> String { - match scene { - Some(scene) => format!("`{scene}`"), - None => "nothing".into(), - } +/// Cue the scene called `name`, under `state` locked by the caller, as +/// [`take`] takes it. +pub fn cue(state: &mut State, name: &str) -> anyhow::Result { + let scene = state.cue(name)?; + Ok(match state.cued() { + Some(_) => format!("cued `{scene}`; TAKE or AUTO puts it on air"), + None => format!("`{scene}` is on air; nothing is cued"), + }) } diff --git a/rs/moq-studio/src/engine.rs b/rs/moq-studio/src/engine.rs index 92653bb9..390e6d81 100644 --- a/rs/moq-studio/src/engine.rs +++ b/rs/moq-studio/src/engine.rs @@ -236,6 +236,8 @@ impl State { } self.compositor.retain(&collection); self.collection = collection; + // A removed scene may have been the one cued. + self.preview_cued(); self.renamed .extend(renames.into_iter().filter(|renames| !renames.is_empty())); Ok(()) @@ -311,6 +313,7 @@ impl State { pub fn cut(&mut self) -> anyhow::Result<()> { self.compositor.cut(&self.collection, &self.sources)?; self.takes += 1; + self.preview_cued(); Ok(()) } @@ -320,23 +323,22 @@ impl State { self.compositor .transition(&self.collection, transition, &self.sources, now)?; self.takes += 1; + self.preview_cued(); Ok(()) } /// Take the scene called `scene` on program by the show's transition, as /// its pad or hotkey does, following any rename the window has yet to move /// a key through; the name it went on by. The scene on program stays as it - /// is. The preview follows, so the scene in preview is always the one - /// last taken. + /// is, leaving nothing [cued](Self::cued). The preview follows, so nothing + /// is cued after a take either. /// /// Refused, changing nothing, unless the scene can go on program, as /// [`Collection::takes`] says. pub fn take(&mut self, scene: &str, now: Instant) -> anyhow::Result { - let scene = self - .follow(scene) - .filter(|scene| self.collection.scene(scene).is_some()) - .with_context(|| format!("no scene is called `{scene}`"))?; + let scene = self.named(scene)?; if self.compositor.program_scene() == Some(scene.as_str()) { + self.uncue(); return Ok(scene); } self.collection.takes(&scene)?; @@ -350,6 +352,120 @@ impl State { Ok(scene) } + /// The scene cued for Studio mode's TAKE and AUTO, or open for editing off + /// air: the one in preview, unless it is the one on program. + pub fn cued(&self) -> Option<&str> { + let preview = self.compositor.preview_scene()?; + (self.compositor.program_scene() != Some(preview)).then_some(preview) + } + + /// Cue the scene called `scene`, as its pad or hotkey does in Studio mode, + /// following renames as [`take`](Self::take) does; the name it was cued + /// by. Its keyframes and overlays start over, as the audience will see + /// them, unless it was cued already. Cueing the scene on program leaves + /// nothing cued. + /// + /// Refused, changing nothing, unless the scene can go on program. + pub fn cue(&mut self, scene: &str) -> anyhow::Result { + let scene = self.named(scene)?; + self.collection.takes(&scene)?; + self.stage(&scene); + Ok(scene) + } + + /// Open the scene called `scene` for editing off air: cue it as + /// [`cue`](Self::cue) does, even one that cannot go on program. + pub fn open_off_air(&mut self, scene: &str) -> anyhow::Result { + let scene = self.named(scene)?; + self.stage(&scene); + Ok(scene) + } + + /// Why viewers see the scene called `scene`, which is not on program, if + /// they do, so an edit to it off air reaches them: it is leaving program + /// in a transition, published or recorded on its own, or drawn through a + /// scene source by a scene they see or by an always-on-top layer. + pub fn seen(&self, scene: &str) -> Option { + let collection = &self.collection; + let program = self.compositor.program_scene(); + if self.compositor.on_air().any(|on| on == scene) && program != Some(scene) { + return Some("it is leaving program in a transition".into()); + } + if collection.scene(scene).is_some_and(|found| found.published) { + return Some("it is published as a broadcast of its own".into()); + } + if self.compositor.live().any(|drawn| drawn == scene) { + return Some("it is recorded".into()); + } + let published = collection.scenes.iter().filter(|found| found.published); + let roots = self.compositor.live().chain(published.map(|found| found.name.as_str())); + let roots = roots.map(Some).chain([None]); + for root in roots { + let layer = moq_scene::Layer { + scene: root.map(str::to_string), + }; + let items = collection.drawn([layer]); + if items + .iter() + .any(|item| collection.nested(&item.source) == Some(moq_scene::Nested::Scene(scene))) + { + return Some(match root { + Some(root) => format!("`{root}` shows it"), + None => "an always-on-top layer shows it".into(), + }); + } + } + None + } + + /// Leave nothing cued, back to editing the scene on program. + pub fn uncue(&mut self) { + if self.cued().is_some() { + let program = self.compositor.program_scene().map(str::to_string); + self.compositor.set_preview(program); + } + self.preview_cued(); + } + + /// Put the cued scene on program: at once without a `transition`, or by + /// it, starting at its instant. The name it went on by. + /// + /// Refused, changing nothing, while nothing is cued or the cued scene + /// cannot go on program. + pub fn take_cued(&mut self, transition: Option<(moq_scene::Transition, Instant)>) -> anyhow::Result { + let scene = self.cued().context("nothing is cued")?.to_string(); + match transition { + None => self.cut()?, + Some((transition, now)) => self.transition(transition, now)?, + } + Ok(scene) + } + + /// Put the scene called `scene` in preview, unless it is there already, + /// where its keyframes play on. + fn stage(&mut self, scene: &str) { + if self.compositor.preview_scene() != Some(scene) { + self.compositor.set_preview(Some(scene.to_string())); + } + self.preview_cued(); + } + + /// Draw the preview while a scene is cued, which the window shows, and + /// not otherwise. Called on every change to what is cued, so a new cue is + /// drawn from the next render and never shows the one before, and a take + /// from a hotkey while the window is hidden stops drawing it. + fn preview_cued(&mut self) { + self.compositor.set_previewing(self.cued().is_some()); + } + + /// The scene called `scene`, following any rename the window has yet to + /// move a key through, if the collection has it. + fn named(&self, scene: &str) -> anyhow::Result { + self.follow(scene) + .filter(|scene| self.collection.scene(scene).is_some()) + .with_context(|| format!("no scene is called `{scene}`")) + } + /// The panic key: mute every microphone and every guest in `room`, hide /// every item of the top layer, in one edit undo takes back, and cut at /// once to the scene the show marks safe, if it marks one. Says what it @@ -1085,6 +1201,8 @@ impl Engine { .find(|scene| collection.takes(&scene.name).is_ok()); compositor.set_preview(first.map(|scene| scene.name.clone())); compositor.cut(&collection, &sources)?; + // Nothing is cued, so nothing shows the preview. + compositor.set_previewing(false); let engine = Arc::new(Self { gpu, @@ -3753,6 +3871,129 @@ mod tests { tokio::task::spawn_blocking(move || stopping.stop()).await.unwrap(); } + /// A cue waits in preview until TAKE or AUTO. Only a scene that can go on + /// air is cued, but any opens off air, + /// and the scene on program is never cued: cueing it, or taking it, + /// clears the cue. + #[tokio::test(flavor = "multi_thread")] + #[ignore = "needs a Vulkan device; run by just render-sw"] + async fn a_cue_waits_for_take() { + let dir = tempfile::tempdir().unwrap(); + let mut loaded = red_canvas(); + let collection = &mut loaded.collection; + collection.transition = moq_scene::Transition::Fade { + duration: Duration::from_secs(60), + }; + let main = collection.scenes[0].name.clone(); + let mut portrait = moq_scene::Scene::new("Portrait"); + portrait.size = Some(moq_scene::Size { + width: 360, + height: 640, + }); + collection.scenes.extend([moq_scene::Scene::new("Guest"), portrait]); + let gpu = Gpu::new(wgpu::Backends::all()).await.expect("a GPU"); + let (autosave, _) = Autosave::open(dir.path().join("show.toml")).unwrap(); + let engine = Engine::start(launch(gpu, Vec::new(), dir.path()), autosave, loaded) + .await + .expect("the studio starts"); + { + let mut state = engine.state.lock().unwrap(); + let now = kio::clock::now(); + let takes = state.takes; + assert_eq!(state.cued(), None); + assert!(state.take_cued(None).is_err(), "nothing to take"); + + assert_eq!(state.cue("Guest").unwrap(), "Guest"); + assert_eq!(state.cued(), Some("Guest")); + assert_eq!(state.compositor.program_scene(), Some(main.as_str()), "still on air"); + assert_eq!(state.takes, takes); + assert!(state.cue("Portrait").is_err(), "it cannot go on air"); + assert_eq!(state.cued(), Some("Guest"), "a refused cue changes nothing"); + assert_eq!(state.cue(&main).unwrap(), main); + assert_eq!(state.cued(), None, "cueing the scene on air clears the cue"); + + assert_eq!(state.open_off_air("Portrait").unwrap(), "Portrait"); + assert_eq!(state.cued(), Some("Portrait"), "any scene opens off air"); + let refused = state.take_cued(None).unwrap_err(); + assert!(format!("{refused:#}").contains("cannot go on program"), "{refused:#}"); + assert_eq!(state.compositor.program_scene(), Some(main.as_str())); + assert_eq!(state.take(&main, now).unwrap(), main); + assert_eq!(state.cued(), None, "taking the scene on air goes back to live"); + + state.cue("Guest").unwrap(); + let fade = state.collection().transition.clone(); + assert_eq!(state.take_cued(Some((fade, now))).unwrap(), "Guest"); + assert_eq!(state.compositor.program_scene(), Some("Guest")); + assert!(state.compositor.transitioning(), "AUTO, by the show's fade"); + assert_eq!(state.cued(), None); + state.cue(&main).unwrap(); + assert_eq!(state.take_cued(None).unwrap(), main); + assert!(!state.compositor.transitioning(), "TAKE, at once"); + assert_eq!(state.takes, takes + 2); + + state.cue("Guest").unwrap(); + state.uncue(); + assert_eq!(state.cued(), None); + assert_eq!(state.compositor.program_scene(), Some(main.as_str())); + + // Viewers still see a scene leaving in a transition, a published + // one, and one a scene they see shows, so an edit off air would + // reach them. + assert_eq!(state.seen("Guest"), None); + state.take("Guest", now).unwrap(); + let leaving = state.seen(&main).expect("leaving in the fade"); + assert!(leaving.contains("transition"), "{leaving}"); + state.cue(&main).unwrap(); + state.take_cued(None).unwrap(); + let collection = state.collection(); + let index = collection + .scenes + .iter() + .position(|scene| scene.name == "Guest") + .unwrap(); + let guest = moq_scene::Scene { + published: true, + ..collection.scenes[index].clone() + }; + let mut draft = collection.draft("Publish `Guest`"); + draft.set_scene(index, guest).unwrap(); + state.commit(draft, None).unwrap(); + let published = state.seen("Guest").expect("published"); + assert!(published.contains("published"), "{published}"); + assert_eq!(state.seen("Portrait"), None); + let mut draft = state.collection().draft("Show `Portrait` in the program"); + let nested = moq_scene::Source::Scene { + scene: "Portrait".into(), + }; + draft.set_source("portrait", Some(nested)).unwrap(); + let fill = moq_scene::Rect::fill(&state.collection().canvas); + let item = moq_scene::Item::new("portrait", fill); + draft.insert_item(&moq_scene::Layer::scene(&main), 0, item).unwrap(); + state.commit(draft, None).unwrap(); + assert_eq!(state.seen("Portrait"), Some(format!("`{main}` shows it"))); + } + + // A scene's key, from the hotkey thread or a button, cues in Studio + // mode and takes otherwise. + let controls = crate::controls::Controls::new(engine.clone(), tokio::runtime::Handle::current()); + controls.set_studio(true); + controls.scene(&mut engine.state.lock().unwrap(), "Guest").unwrap(); + { + let state = engine.state.lock().unwrap(); + assert_eq!(state.cued(), Some("Guest"), "Studio mode cues"); + assert_eq!(state.compositor.program_scene(), Some(main.as_str())); + } + controls.set_studio(false); + controls.fire(&crate::controls::Action::Scene("Guest".into())).unwrap(); + { + let state = engine.state.lock().unwrap(); + assert_eq!(state.compositor.program_scene(), Some("Guest"), "otherwise it takes"); + assert_eq!(state.cued(), None); + } + let stopping = engine.clone(); + tokio::task::spawn_blocking(move || stopping.stop()).await.unwrap(); + } + /// The panic key's edit mutes each microphone and each source playing a /// guest in the room that is on, keeping the rest of their settings, and /// no other source, and hides every visible top-layer item, whatever it diff --git a/rs/moq-studio/src/fx.rs b/rs/moq-studio/src/fx.rs index 6b59c3a5..fe562760 100644 --- a/rs/moq-studio/src/fx.rs +++ b/rs/moq-studio/src/fx.rs @@ -224,11 +224,9 @@ impl Fx { } /// The text color over a [`button`](Self::button). - #[expect(dead_code, reason = "Studio mode's TAKE: quest/m0/ux/studio-mode.md")] pub const INK: Color32 = Color32::from_gray(24); /// A button of polished metal that ripples while the pointer is on it. - #[expect(dead_code, reason = "Studio mode's TAKE: quest/m0/ux/studio-mode.md")] pub fn button(&mut self, spot: &Spot) { let hovered = spot .painter @@ -359,7 +357,6 @@ const WRAP: f64 = 3600.0; struct Look { on_air: Light, /// The metal [`button`](Fx::button)'s ripple. - #[expect(dead_code, reason = "Studio mode's TAKE: quest/m0/ux/studio-mode.md")] ripple: Light, /// The take count last seen, and when each burst it fired started, with /// its seed. diff --git a/rs/moq-studio/src/hotkeys.rs b/rs/moq-studio/src/hotkeys.rs index 7f21acff..763de07b 100644 --- a/rs/moq-studio/src/hotkeys.rs +++ b/rs/moq-studio/src/hotkeys.rs @@ -13,7 +13,7 @@ use std::sync::{Arc, Mutex, mpsc}; use winit::keyboard::{Key, KeyCode, ModifiersState, NativeKeyCode, PhysicalKey}; -use crate::controls::{self, Action, Controls}; +use crate::controls::{Action, Controls}; // Tested on macOS too, which global-hotkey builds for. #[cfg(any(windows, all(test, target_os = "macos")))] @@ -306,7 +306,7 @@ impl Hotkeys { }; match &action { Action::Scene(name) => { - let result = controls::take(&mut state, name); + let result = controls.scene(&mut state, name); drop(state); controls.report(&action, result.map_err(|err| format!("{err:#}"))); } diff --git a/rs/moq-studio/src/hotkeys/portal.rs b/rs/moq-studio/src/hotkeys/portal.rs index e744a236..dd314968 100644 --- a/rs/moq-studio/src/hotkeys/portal.rs +++ b/rs/moq-studio/src/hotkeys/portal.rs @@ -144,6 +144,7 @@ fn id(action: &Action, binding: &Binding) -> String { Action::SaveClip => "save-clip".into(), Action::Record => "record".into(), Action::Panic => "panic".into(), + Action::StudioMode => "studio-mode".into(), } } diff --git a/rs/moq-studio/src/kit/icon.rs b/rs/moq-studio/src/kit/icon.rs index bbbc0d79..02869bf6 100644 --- a/rs/moq-studio/src/kit/icon.rs +++ b/rs/moq-studio/src/kit/icon.rs @@ -18,10 +18,6 @@ pub enum Icon { Shown, Hidden, Panic, - #[cfg_attr( - not(test), - expect(dead_code, reason = "Studio mode's switch: quest/m0/ux/studio-mode.md") - )] StudioMode, Add, Close, diff --git a/rs/moq-studio/src/shots.rs b/rs/moq-studio/src/shots.rs index aca809ce..9e7dabf0 100644 --- a/rs/moq-studio/src/shots.rs +++ b/rs/moq-studio/src/shots.rs @@ -66,6 +66,10 @@ enum View { /// The LIVE page after a mute, with the health dot's popover open and the /// pointer on undo, which names the mute. Hover, + /// A page in Studio mode, with `Interview` cued. + Cued(Page), + /// A scene, by name, open for editing off air on BUILD. + OffAir(&'static str), } /// BUILD with the host's layer, the middle of the scene on program's three, @@ -126,6 +130,9 @@ views! { /// A window snapped beside a game stacks the picture, the scenes, and the /// sound. live_compact: Still, Open::Studio { view: View::Page(Page::Live), size: HALF, show: "show.toml" }; + /// Studio mode: the cued scene's pad turns amber, and NEXT docks on the + /// live picture with TAKE and AUTO. + live_studio: Still, studio(View::Cued(Page::Live)); /// BUILD with the host's layer selected: its row in Layers, its handles /// and toolbar on the picture, and its inspector. build: Still, studio(BUILD); @@ -141,6 +148,17 @@ views! { /// BUILD in a window snapped beside a game: the inspector is a tab beside /// Layers and Add. build_compact: Still, Open::Studio { view: BUILD, size: HALF, show: "show.toml" }; + /// BUILD in Studio mode edits the scene on air, with NEXT docked on it. + build_studio: Still, studio(View::Cued(Page::Build)); + /// A scene open off air: the frame turns amber, and the live picture + /// shrinks to a corner beside the banner that takes it live or goes back. + /// Layers lists the scene's own, as always on top is drawn on program. + build_off_air: Still, studio(View::OffAir("Break")); + /// A scene that cannot go on air opens off air too, its Take it live + /// dimmed, saying why under the pointer. + build_off_air_refused: Still, studio(View::OffAir("Vertical")); + /// Too narrow for the banner beside the live picture, it goes under it. + build_off_air_compact: Still, Open::Studio { view: View::OffAir("Break"), size: HALF, show: "show.toml" }; /// MIX holds the mixer, and a small live picture in the sound's place. mix: Still, studio(View::Page(Page::Mix)); /// MIX in a stacked window, its live picture as tall as the sound's slot @@ -425,6 +443,82 @@ fn a_layer_menu_edits_its_layer() { quit(&engine, &runtime); } +/// Studio mode, driven as a person does: its switch turns it on, a pad then +/// cues its scene rather than taking it, and TAKE puts it on air. NEXT's Edit +/// opens the cued scene off air on BUILD, Back to live keeps it cued, and +/// the card's close clears it. Off again, a pad's menu opens a scene off air, +/// whose own layers BUILD lists and selects, and the banner's Take it live +/// takes it, keeping the selection on the scene now live. It draws no view. +#[test] +#[ignore = "draws on a GPU; run with `just shots`"] +fn studio_mode_cues_and_takes() { + let (_show, runtime, gpu) = lavapipe(); + let _entered = runtime.enter(); + let fixture = Path::new(env!("CARGO_MANIFEST_DIR")); + std::fs::copy(fixture.join("shots/show.toml"), "show.toml").unwrap(); + let (mut harness, started, _) = window(start(launch(&gpu), &runtime), &gpu, &runtime, SIZE); + harness.step(); + let engine = started.get().expect("the studio started").clone(); + runtime + .block_on(kio::clock::timeout(SETTLE, settle(&mut harness, &engine))) + .expect("the sources and pictures settle"); + // The scene on program, and the one cued. + let staged = || { + let state = engine.state.lock().unwrap(); + let program = state.compositor.program_scene().map(str::to_string); + (program, state.cued().map(str::to_string)) + }; + let scenes = |program: &str, cued: Option<&str>| (Some(program.to_string()), cued.map(str::to_string)); + let selected = |harness: &mut Harness<'_, Window>| { + let App::Studio(studio) = &mut harness.state_mut().app else { + unreachable!() + }; + studio.selected() + }; + assert_eq!(staged(), scenes("Main", None)); + + harness.get_by_label("Studio mode").click(); + harness.run_steps(2); + harness.get_by_label("Interview").click(); + harness.run_steps(2); + assert_eq!(staged(), scenes("Main", Some("Interview")), "the pad cued its scene"); + harness.get_by_label("TAKE").click(); + harness.run_steps(2); + assert_eq!(staged(), scenes("Interview", None), "TAKE put it on air"); + + harness.get_by_label("Main").click(); + harness.run_steps(2); + harness.get_by_label("Edit").click(); + harness.run_steps(2); + harness.get_by_label("Back to live").click(); + harness.run_steps(2); + assert_eq!(staged(), scenes("Interview", Some("Main")), "Studio mode keeps it cued"); + harness.get_by_label("Clear the cue").click(); + harness.run_steps(2); + assert_eq!(staged(), scenes("Interview", None)); + + harness.get_by_label("Studio mode").click(); + harness.run_steps(2); + harness.get_by_label("Main").click_secondary(); + harness.run_steps(2); + harness.get_by_label("Edit off air").click(); + harness.run_steps(2); + assert_eq!(staged(), scenes("Interview", Some("Main")), "open off air, not taken"); + // BUILD lists the layers of the scene open off air, and + // leaves always on top to the program. + harness.get_by_label_contains("Always on top is drawn on program"); + harness.get_all_by_label("bar").next().unwrap().click(); + harness.run_steps(2); + assert!(selected(&mut harness), "the click selected Main's bar off air"); + harness.get_by_label("Take it live").click(); + harness.run_steps(2); + assert_eq!(staged(), scenes("Main", None), "taken live"); + assert!(selected(&mut harness), "the bar stays selected, its scene now live"); + + drop(harness); + quit(&engine, &runtime); +} + /// Draw what `open` opens on a fresh engine, from a scene file in `shows`. fn shoot(open: &Open, gpu: &engine::Gpu, runtime: &tokio::runtime::Runtime, shows: &Path) -> image::RgbaImage { if let &Open::Kit { sheet } = open { @@ -463,6 +557,12 @@ fn shoot(open: &Open, gpu: &engine::Gpu, runtime: &tokio::runtime::Runtime, show View::Setting(setting) => studio.open(*setting), View::Health => studio.details(), View::Hover | View::History => {} + View::Cued(page) => { + studio.studio_mode(true); + studio.cue("Interview"); + studio.turn(*page); + } + View::OffAir(scene) => studio.edit_off_air(scene), } let engine = started.get().expect("the studio started").clone(); runtime diff --git a/rs/moq-studio/src/ui.rs b/rs/moq-studio/src/ui.rs index 52d3672f..c1ab40d9 100644 --- a/rs/moq-studio/src/ui.rs +++ b/rs/moq-studio/src/ui.rs @@ -30,6 +30,7 @@ use crate::snap::{self, Grab, Snap}; use crate::{mix, record}; mod build; +mod cue; mod graph; mod inspector; mod layers; @@ -144,9 +145,6 @@ pub(crate) enum Inspect { /// The studio window. pub struct Studio { panels: Panels, - /// Keys saved for actions this version does not offer, such as Studio - /// mode's Cut and Transition, kept for the version that does. - hidden: Bindings, } impl Studio { @@ -159,13 +157,16 @@ impl Studio { ) -> Self { // egui samples whatever the compositor's textures hold each frame, so // they are registered again only when a resize replaces them, or the - // program starts or stops showing layers over it. - let (program, dropped) = { - let mut state = engine.state.lock().unwrap(); - // Nothing shows the preview: the scene edited is the one on air, - // until Studio mode (quest/m0/ux/studio-mode.md). - state.compositor.set_previewing(false); - (Registered::new(render, state.compositor.layered()), state.dropped) + // program starts or stops showing layers over it. The engine draws the + // preview only while a scene is cued or open off air, which shows it. + let (program, preview, dropped) = { + let state = engine.state.lock().unwrap(); + let program = Registered::new(render, state.compositor.layered()); + ( + program, + Registered::new(render, state.compositor.preview()), + state.dropped, + ) }; let controls = Arc::new(Controls::new(engine.clone(), runtime.clone())); let mut panels = Panels { @@ -178,6 +179,8 @@ impl Studio { refusal: None, program, program_drawn: Canvas::default(), + preview, + editing: None, framed, page: Page::default(), setting: None, @@ -222,10 +225,7 @@ impl Studio { if dropped > 0 { panels.report(Err(anyhow::anyhow!(dropped_message(dropped)))); } - Self { - panels, - hidden: Bindings::new(), - } + Self { panels } } } @@ -246,6 +246,23 @@ impl Studio { self.panels.details = true; } + /// Turn Studio mode on or off, as its switch would. + pub(crate) fn studio_mode(&mut self, on: bool) { + self.panels.controls.set_studio(on); + } + + /// Cue the scene called `scene`, as its pad would in Studio mode. + pub(crate) fn cue(&mut self, scene: &str) { + let mut state = self.panels.engine.state.lock().unwrap(); + state.cue(scene).expect("a scene that can go on air"); + } + + /// Open the scene called `scene` off air on BUILD, as its pad's menu would. + pub(crate) fn edit_off_air(&mut self, scene: &str) { + let result = self.panels.open_off_air(scene); + result.expect("a scene to open"); + } + /// Whether a layer is selected. pub(crate) fn selected(&self) -> bool { self.panels.selection.is_some() @@ -277,6 +294,8 @@ impl Studio { const SPEAKER: &str = "speaker"; const SNAPPING: &str = "snapping"; const HOTKEYS: &str = "hotkeys"; +/// How this operator runs a show, not part of the show. +const STUDIO_MODE: &str = "studio_mode"; impl Studio { /// Take up what this user picked last time, and start hearing the keys @@ -288,34 +307,20 @@ impl Studio { panels.speaker = eframe::get_value::>(storage, SPEAKER).flatten(); panels.snapping = eframe::get_value(storage, SNAPPING).unwrap_or_default(); bindings = eframe::get_value(storage, HOTKEYS).unwrap_or_default(); + let studio = eframe::get_value(storage, STUDIO_MODE).unwrap_or_default(); + panels.controls.set_studio(studio); } - // A key bound to an action not offered does nothing until it is. - let (offered, hidden) = bindings.into_iter().partition(|(action, _)| action.offered()); - self.hidden = hidden; - let hotkeys = Hotkeys::new(window, self.panels.controls.clone(), &self.panels.runtime, offered); + let hotkeys = Hotkeys::new(window, self.panels.controls.clone(), &self.panels.runtime, bindings); self.panels.hotkeys = Some(hotkeys); } -} -/// Put back in `bindings` the key of each action not offered, which `hidden` -/// held, unless another action took that key meanwhile. -fn keep_hidden(bindings: &mut Bindings, hidden: &Bindings) { - for (action, key) in hidden { - if !bindings.values().any(|bound| bound.same(key)) { - bindings.insert(action.clone(), key.clone()); - } - } -} - -impl Studio { pub fn save(&mut self, storage: &mut dyn eframe::Storage) { let panels = &self.panels; eframe::set_value(storage, SPEAKER, &panels.speaker); eframe::set_value(storage, SNAPPING, &panels.snapping); + eframe::set_value(storage, STUDIO_MODE, &panels.controls.studio()); if let Some(hotkeys) = &panels.hotkeys { - let mut bindings = hotkeys.bindings(); - keep_hidden(&mut bindings, &self.hidden); - eframe::set_value(storage, HOTKEYS, &bindings); + eframe::set_value(storage, HOTKEYS, &hotkeys.bindings()); } } @@ -427,6 +432,11 @@ struct Panels { program: Registered, /// The program's size this frame, as its texture was drawn. program_drawn: Canvas, + /// The cued scene, or the one open off air, which the compositor draws + /// while there is one. + preview: Registered, + /// The scene open for editing off air on BUILD, while it is the one cued. + editing: Option, /// Whether the title bar is the window's frame, which moves, resizes, /// and closes it. framed: bool, @@ -758,16 +768,17 @@ impl Panels { /// way, whose index it may have given to another. Called under every lock /// that uses one, since the autosave can reload between two. /// - /// Let go of a layer of a scene no longer on program too, which a pad or - /// hotkey took away from BUILD, so a paste, the inspector, and the picture - /// never act on a scene the picture does not show. + /// Let go of a layer of a scene BUILD no longer edits too, which a pad, + /// a hotkey, or opening a scene off air took away from it, so a paste, + /// the inspector, and the picture never act on a scene the picture does + /// not show. Off air, that includes the always-on-top layers, which are + /// drawn on program. fn follow_reloads(&mut self, state: &State) { - if let Some(Picked { - layer: Layer { scene: Some(scene) }, - .. - }) = &self.selection - && state.compositor.program_scene() != Some(scene.as_str()) - { + let gone = self.selection.as_ref().is_some_and(|picked| match &picked.layer.scene { + Some(scene) => self.edited(state) != Some(scene.as_str()), + None => self.off_air(state).is_some(), + }); + if gone { self.selection = None; self.drag = None; self.moving = None; @@ -870,15 +881,45 @@ impl Panels { self.selection = picked; } - /// The layers BUILD edits, and new sources go in: the scene on program's. - /// The always-on-top layers over it are [`Layer::top`]. + /// The layers BUILD edits, and new sources go in: the scene open off + /// air's, or else the scene on program's. The always-on-top layers over + /// the program are [`Layer::top`]. fn scene(&self, state: &State) -> Result { - match state.compositor.program_scene() { + match self.edited(state) { Some(name) => Ok(Layer::scene(name)), None => Err("Take a scene to edit what it shows.".into()), } } + /// The scene open for editing off air, if one is. + fn off_air<'a>(&self, state: &'a State) -> Option<&'a str> { + state.cued().filter(|cued| self.editing.as_deref() == Some(*cued)) + } + + /// The scene BUILD edits: the one open off air, or else the one on + /// program. + fn edited<'a>(&self, state: &'a State) -> Option<&'a str> { + self.edited_since(state).0 + } + + /// The scene BUILD edits, and how long it had been on as of the last + /// render, the moment of its keyframes the picture shows. + fn edited_since<'a>(&self, state: &'a State) -> (Option<&'a str>, Duration) { + match self.off_air(state) { + Some(cued) => (Some(cued), state.compositor.preview_since()), + None => (state.compositor.program_scene(), state.compositor.program_since()), + } + } + + /// Open the scene called `scene` for editing off air, on BUILD. + fn open_off_air(&mut self, scene: &str) -> anyhow::Result<()> { + let mut state = self.engine.state.lock().unwrap(); + let scene = state.open_off_air(scene)?; + self.editing = state.cued().is_some().then_some(scene); + self.page = Page::Build; + Ok(()) + } + /// Copy the selected layer, with what it shows, to the clipboard. fn copy(&mut self, ctx: &egui::Context) { let engine = self.engine.clone(); @@ -1846,14 +1887,21 @@ struct Drag { /// How far, in points on screen, the pointer reaches to an edge or a line. const REACH: f32 = 8.0; -/// Where the visible layers of the scene on program and the always-on-top -/// ones over it show `since` the scene went on program, other than -/// `dragged`: what a dragged layer snaps to. -fn others(state: &State, dragged: &Picked, since: Duration) -> Vec { - let scene = state.compositor.program_scene(); +/// Where the visible layers of `scene` and the always-on-top ones over it, +/// if they are drawn over that scene, show `since` the scene went on, other +/// than `dragged`: what a dragged layer snaps to. A scene open off air still +/// snaps to the always-on-top ones: its picture draws them, as the program +/// will, though BUILD leaves them to the program to edit. +fn others(state: &State, scene: Option<&str>, dragged: &Picked, since: Duration) -> Vec { let collection = state.collection(); + // The top layer goes over a scene of the program's size, as the + // compositor draws it. + let top = collection + .canvas(scene) + .is_none_or(|canvas| canvas.size() == collection.canvas.size()); let mut rects = Vec::new(); - for shown in scene.map(Layer::scene).into_iter().chain([Layer::top()]) { + let layers = scene.map(Layer::scene).into_iter().chain(top.then(Layer::top)); + for shown in layers { let items = collection.items(&shown).unwrap_or_default(); for (at, item) in items.iter().enumerate() { if item.visible && !(shown == dragged.layer && at == dragged.index) { @@ -2493,33 +2541,6 @@ mod tests { } } - /// A key bound to Cut or Transition, which the window no longer offers, - /// is kept across a save for when they come back, unless the operator - /// bound that key to something else meanwhile. - #[test] - fn a_hidden_action_keeps_its_key() { - let key = |code| hotkeys::Binding { - modifiers: egui::Modifiers::NONE, - key: PhysicalKey::Code(code), - name: winit::keyboard::Key::Named(winit::keyboard::NamedKey::F1), - }; - let saved = Bindings::from([ - (Action::Cut, key(KeyCode::F5)), - (Action::Transition, key(KeyCode::F6)), - (Action::Panic, key(KeyCode::F1)), - ]); - let (mut bindings, hidden): (Bindings, Bindings) = saved.into_iter().partition(|(action, _)| action.offered()); - assert_eq!(bindings, Bindings::from([(Action::Panic, key(KeyCode::F1))])); - bindings.insert(Action::Replay, key(KeyCode::F6)); - keep_hidden(&mut bindings, &hidden); - let kept = Bindings::from([ - (Action::Panic, key(KeyCode::F1)), - (Action::Replay, key(KeyCode::F6)), - (Action::Cut, key(KeyCode::F5)), - ]); - assert_eq!(bindings, kept, "Transition lost F6 to Replay"); - } - /// The gain field shows a boost past its range without cutting it, and /// takes an exact level, so a sound can go back to exactly 0 dB. #[test] diff --git a/rs/moq-studio/src/ui/build.rs b/rs/moq-studio/src/ui/build.rs index 11c529e7..4039f17b 100644 --- a/rs/moq-studio/src/ui/build.rs +++ b/rs/moq-studio/src/ui/build.rs @@ -1,6 +1,9 @@ -//! The BUILD page: the live picture, edited where it shows, with the scene's -//! layers on the left and the selected layer's inspector on the right. +//! The BUILD page: the live picture, or a scene open off air, edited where +//! it shows, with the scene's layers on the left and the selected layer's +//! inspector on the right. +use super::cue::Corner; +use super::shell::Snapshot; use super::*; /// The inspector's width, and the layers' column's. @@ -9,11 +12,16 @@ const SIDE: std::ops::RangeInclusive = 260.0..=320.0; /// Room between the selected layer and its toolbar. const TOOLBAR_GAP: f32 = 8.0; +/// Why nothing goes always on top, or comes off it, while a scene is open +/// off air. +pub(super) const OFF_AIR_TOP: &str = "Always on top is drawn on program; go back to live to change it"; + impl Panels { - /// The BUILD page: the layers and Add on the left, the live picture in - /// the middle, and the inspector on the right, or among the left's tabs - /// when the window is narrow. - pub(super) fn build(&mut self, ui: &mut Ui, fx: &mut Fx, stage: egui::Rect, shape: f32) { + /// The BUILD page: the layers and Add on the left, the live picture, or + /// the scene open off air under its banner, in the middle, and the + /// inspector on the right, or among the left's tabs when the window is + /// narrow. + pub(super) fn build(&mut self, ui: &mut Ui, fx: &mut Fx, stage: egui::Rect, snapshot: &Snapshot) { let side = (stage.width() * 0.22).clamp(*SIDE.start(), *SIDE.end()); let wide = stage.width() >= side * 2.0 + 360.0; let left = stage.with_max_x(stage.left() + side); @@ -33,8 +41,13 @@ impl Panels { self.inspector(ui, right); } kit::wash(ui.painter(), middle); - let room = middle.shrink(28.0); - self.stage(ui, fx, super::layout::fit(room, shape)); + let mut room = middle.shrink(28.0); + let mut shape = snapshot.shape; + if let Some(cued) = snapshot.cued.as_ref().filter(|cued| cued.off_air) { + room.min.y = self.off_air_header(ui, cued, room, snapshot.shape); + shape = cued.shape(); + } + self.stage(ui, fx, snapshot, super::layout::fit(room, shape)); self.build_keys(ui); } @@ -61,19 +74,38 @@ impl Panels { } } - /// The live picture at `at`: a click selects the layer under it, a drag - /// moves, resizes, or crops it, and a right click offers what applies - /// there. While interacting, the pointer and keyboard pass to the - /// selected layer's web page instead, until Escape. - fn stage(&mut self, ui: &mut Ui, fx: &mut Fx, at: egui::Rect) { + /// The live picture at `at`, or the scene open off air: a click selects + /// the layer under it, a drag moves, resizes, or crops it, and a right + /// click offers what applies there. While interacting, the pointer and + /// keyboard pass to the selected layer's web page instead, until Escape. + /// The NEXT card docks on the live picture while a scene is cued. + fn stage(&mut self, ui: &mut Ui, fx: &mut Fx, snapshot: &Snapshot, at: egui::Rect) { self.staged = true; let engine = self.engine.clone(); let mut state = engine.state.lock().unwrap(); self.follow_reloads(&state); - let canvas = self.program_drawn; - // It is the live picture, so the accent frame stays while editing it. - let frame = TallyFrame::new(Tally::Air).tag("On air"); - let id = self.program.id; + // Decided under this lock, as the edits below are, so the picture + // shown is the one they edit even if a key took a scene since the + // snapshot. + let off_air = self.off_air(&state).map(|cued| { + let collection = state.collection(); + let canvas = collection.canvas(Some(cued)).unwrap_or(collection.canvas); + // Viewers may see it anyway, such as a published scene. + let tag = match state.seen(cued) { + Some(_) => "Not on program", + None => "Off air", + }; + (canvas, tag) + }); + let (canvas, id, frame) = match off_air { + Some((canvas, tag)) => (canvas, self.preview.id, TallyFrame::new(Tally::Cue).tag(tag)), + // It is the live picture, so the accent frame stays while editing it. + None => ( + self.program_drawn, + self.program.id, + TallyFrame::new(Tally::Air).tag("On air"), + ), + }; let builder = egui::UiBuilder::new().max_rect(at.expand(10.0)); if self.interacting { let page = self.interacted(&state); @@ -85,8 +117,8 @@ impl Panels { }) .inner .rect; - let since = state.compositor.program_since(); - let scene = state.compositor.program_scene().map(|scene| (scene, since)); + let (scene, since) = self.edited_since(&state); + let scene = scene.map(|scene| (scene, since)); self.rebind(&state.sources); // `interacted` found the page through the selection, so one is. let picked = self.selection.clone().expect("interacting with the selected layer"); @@ -114,10 +146,24 @@ impl Panels { Some(acted) => acted, None => (spot, result), }; + // Docked on the live picture, away from the selected layer and its + // toolbar, which a drag moves with it. + let (width, height) = (canvas.width.max(1) as f32, canvas.height.max(1) as f32); + let selected = self.shown(&state).into_iter().find_map(|(picked, item)| { + (Some(&picked) == self.selection.as_ref()).then(|| { + [ + (item.rect.x + item.rect.width / 2.0) / width, + (item.rect.y + item.rect.height / 2.0) / height, + ] + }) + }); drop(state); if let Some(spot) = spot { self.fail(spot, result); } + if let Some(cued) = snapshot.cued.as_ref().filter(|_| off_air.is_none()) { + self.next(ui, fx, cued, response.rect, Corner::away_from(selected)); + } } /// The web page the selected layer shows, while it is a visible layer of @@ -127,8 +173,8 @@ impl Panels { let collection = state.collection(); let item = picked.item(collection).filter(|item| item.visible)?; let shown = match &picked.layer.scene { - Some(scene) => state.compositor.program_scene() == Some(scene.as_str()), - None => true, + Some(scene) => self.edited(state) == Some(scene.as_str()), + None => self.off_air(state).is_none(), }; let page = collection.capture(&item.source); let web = matches!(collection.sources.get(page), Some(Source::Browser { .. })); @@ -142,12 +188,14 @@ impl Panels { deliver(&state.sources, self.interact.release()); } - /// The layers the picture shows, front last, each with its place: the - /// scene on program's, then the always-on-top ones over it. + /// The layers the picture edits, front last, each with its place: the + /// scene's, then the always-on-top ones over it, unless the scene is open + /// off air, as they are drawn on program. fn shown(&self, state: &State) -> Vec<(Picked, Item)> { - let since = state.compositor.program_since(); + let (_, since) = self.edited_since(state); let collection = state.collection(); - let layers = self.scene(state).ok().into_iter().chain([Layer::top()]); + let top = self.off_air(state).is_none().then(Layer::top); + let layers = self.scene(state).ok().into_iter().chain(top); layers .flat_map(|layer| { let items = collection.items(&layer).unwrap_or_default(); @@ -239,7 +287,8 @@ impl Panels { let mut spot = None; let mut result = Ok(()); - let since = state.compositor.program_since(); + let (scene, since) = self.edited_since(state); + let scene = scene.map(str::to_string); if let Some(drag) = &mut self.drag && let Some(pos) = response.interact_pointer_pos() { @@ -272,7 +321,7 @@ impl Panels { height: shown.height - rest.height, }, }; - let others = others(state, &drag.picked, since); + let others = others(state, scene.as_deref(), &drag.picked, since); snap.apply(drag.grab, rect, &others, &canvas) }); let rect = drag.hints.as_ref().map_or(rect, |snapped| snapped.rect); @@ -423,6 +472,7 @@ impl Panels { ) -> Option<(Option, anyhow::Result<()>)> { let view = View::new(response.rect, canvas); let shown = self.shown(state); + let off_air = self.off_air(state).is_some(); let selected = shown .iter() .find(|(picked, item)| Some(picked) == self.selection.as_ref() && item.visible); @@ -430,13 +480,13 @@ impl Panels { if let Some((picked, item)) = selected && self.drag.is_none() && response.rect.is_positive() - && let Some(menu) = Menu::of(state, picked) + && let Some(menu) = Menu::of(state, picked, off_air) { let at = view.screen(&item.rect).intersect(response.rect); let cropping = self.cropping; action = toolbar(ui, response.rect, at, &menu, cropping); } - let context = Menu::of_selected(state, self.selection.as_ref(), &shown); + let context = Menu::of_selected(state, self.selection.as_ref(), &shown, off_air); let mut picture = None; response.context_menu(|ui| match &context { Some(menu) => { @@ -580,6 +630,7 @@ impl Panels { } result } + LayerAction::Top(_) if self.off_air(state).is_some() => Err(anyhow::anyhow!(OFF_AIR_TOP)), LayerAction::Top(top) => { let to = match top { true => Layer::top(), @@ -725,11 +776,14 @@ pub(super) struct Menu { cut: Option, /// How many lists of layers show its source. linked: usize, + /// Whether its scene is open off air, where nothing goes always on top, + /// as that is drawn on program. + off_air: bool, } impl Menu { - /// What `picked` offers, if it is still there. - pub(super) fn of(state: &State, picked: &Picked) -> Option { + /// What `picked` offers, if it is still there, `off_air` or not. + pub(super) fn of(state: &State, picked: &Picked, off_air: bool) -> Option { let collection = state.collection(); let item = picked.item(collection)?.clone(); let capture = collection.sources.get(collection.capture(&item.source)); @@ -745,14 +799,15 @@ impl Menu { web: matches!(capture, Some(Source::Browser { .. })), cut, linked: shown_in(collection, &item.source).len(), + off_air, item, }) } /// What the selected layer offers, if it is shown on the picture. - fn of_selected(state: &State, selection: Option<&Picked>, shown: &[(Picked, Item)]) -> Option { + fn of_selected(state: &State, selection: Option<&Picked>, shown: &[(Picked, Item)], off_air: bool) -> Option { let picked = selection.filter(|picked| shown.iter().any(|(shown, _)| shown == *picked))?; - Self::of(state, picked) + Self::of(state, picked, off_air) } } @@ -803,7 +858,11 @@ pub(super) fn layer_menu(ui: &mut Ui, menu: &Menu) -> Option { true => "Show it in the scene on program alone, under the always-on-top layers", false => "Draw it over every scene on program, through every cut; it loses its keyframes", }; - if ui.button(top).on_hover_text(hover).clicked() { + let button = ui + .add_enabled(!menu.off_air, egui::Button::new(top)) + .on_hover_text(hover) + .on_disabled_hover_text(OFF_AIR_TOP); + if button.clicked() { action = Some(LayerAction::Top(!menu.top)); } ui.separator(); diff --git a/rs/moq-studio/src/ui/cue.rs b/rs/moq-studio/src/ui/cue.rs new file mode 100644 index 00000000..1aca9a96 --- /dev/null +++ b/rs/moq-studio/src/ui/cue.rs @@ -0,0 +1,461 @@ +//! Staging a scene that is not on air: the NEXT card Studio mode cues into, +//! with TAKE and AUTO, and the banner and small live picture over a scene open +//! for editing off air. Both show the compositor's preview. + +use egui::{Rect, Sense, Stroke, Vec2, pos2, vec2}; + +use super::*; + +/// The scene cued, or open off air, as a frame shows it. +pub(super) struct Cued { + pub(super) name: String, + /// Why it cannot go on air, if it cannot. + pub(super) refused: Option, + /// Its size, which its picture is drawn at. + pub(super) canvas: Canvas, + /// Whether it is open for editing off air, rather than only cued. + pub(super) off_air: bool, + /// Why viewers see it anyway, if they do, such as being published. + pub(super) live: Option, + /// The show's transition, which AUTO takes it by, in words. + pub(super) transition: String, +} + +impl Cued { + /// Its picture's shape, width over height. + pub(super) fn shape(&self) -> f32 { + self.canvas.width as f32 / self.canvas.height.max(1) as f32 + } +} + +/// A corner of the live picture, where the NEXT card docks. +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub(super) enum Corner { + TopRight, + BottomLeft, +} + +impl Corner { + /// Where the NEXT card docks while the selected layer is centered at + /// `selected`, as a fraction of the picture across and down: top right, + /// or the opposite corner while the layer is in that one, so it never + /// hides the layer or its toolbar. + pub(super) fn away_from(selected: Option<[f32; 2]>) -> Self { + match selected { + Some([x, y]) if x >= 0.5 && y < 0.5 => Self::BottomLeft, + _ => Self::TopRight, + } + } +} + +/// What the NEXT card or the off-air banner asked for. +enum Ask { + Take, + Auto, + /// Open the cued scene off air on BUILD. + Edit, + /// Leave nothing cued. + Clear, + /// Stop editing off air, leaving the scene cued in Studio mode. + BackToLive, +} + +/// The least room the off-air banner's words get beside the live picture +/// before it moves under it. +const MIN_TEXT: f32 = 160.0; +/// Room inside the card around what it holds. +const PADDING: f32 = 10.0; +/// How far in from the picture's edges the card docks. +const INSET: f32 = 12.0; + +impl Panels { + /// The NEXT card docked in `corner` of `picture`: the cued scene's own + /// picture, with TAKE, AUTO, Edit, and a close that clears the cue. + pub(super) fn next(&mut self, ui: &mut Ui, fx: &mut Fx, cued: &Cued, picture: Rect, corner: Corner) { + let width = (picture.width() * 0.26).clamp(200.0, 300.0); + let inner = width - 2.0 * PADDING; + // The rest of the card is about 120 points tall; the picture gets what + // the live picture leaves. + let tall = (inner / cued.shape()) + .min(picture.height() - 2.0 * INSET - 120.0) + .max(24.0); + let (header, buttons, hint) = (24.0, 40.0, 14.0); + let height = PADDING + header + 6.0 + tall + 8.0 + buttons + 6.0 + hint + PADDING; + let at = match corner { + Corner::TopRight => pos2(picture.right() - INSET - width, picture.top() + INSET), + Corner::BottomLeft => pos2(picture.left() + INSET, picture.bottom() - INSET - height), + }; + let card = Rect::from_min_size(at, vec2(width, height)); + // Under the card's controls, so a click on it never reaches the picture. + ui.interact(card, ui.id().with("next card"), Sense::click_and_drag()); + let painter = ui.painter(); + let shadow = egui::Shadow { + offset: [0, 8], + blur: 24, + spread: 0, + color: Color32::from_black_alpha(0x90), + }; + painter.add(shadow.as_shape(card, egui::CornerRadius::same(12))); + painter.rect( + card, + 12, + kit::POPOVER, + Stroke::new(1.0, kit::LINE), + egui::StrokeKind::Inside, + ); + + let mut ask = None; + let mut y = card.top() + PADDING; + let row = Rect::from_min_size(pos2(card.left() + PADDING, y), vec2(inner, header)); + let close = Rect::from_center_size(pos2(row.right() - 11.0, row.center().y), Vec2::splat(22.0)); + if ui + .put(close, IconButton::new(Icon::Close, "Clear the cue").small()) + .clicked() + { + ask = Some(Ask::Clear); + } + let edit = Rect::from_min_max( + pos2(close.left() - 52.0, row.top() + 1.0), + pos2(close.left() - 6.0, row.bottom() - 1.0), + ); + let edit = ui + .put(edit, egui::Button::new(egui::RichText::new("Edit").font(kit::ui(12.0)))) + .on_hover_text("Open it on Build to edit it off air"); + if edit.clicked() { + ask = Some(Ask::Edit); + } + let painter = ui.painter(); + let next = kit::caps_galley(painter, "Next", kit::display_bold(11.0), kit::CUE, None); + painter.galley( + pos2(row.left(), row.center().y - next.size().y / 2.0), + next.clone(), + kit::CUE, + ); + let left = row.left() + next.size().x + 8.0; + let room = (edit.rect.left() - 8.0 - left).max(0.0); + let name = kit::caps_galley(painter, &cued.name, kit::display_bold(15.0), kit::TEXT, Some(room)); + painter.galley(pos2(left, row.center().y - name.size().y / 2.0), name, kit::TEXT); + y = row.bottom() + 6.0; + + // The cued scene as it will go on air, framed in amber. + let frame = Rect::from_min_size(pos2(card.left() + PADDING, y), vec2(inner, tall)); + painter.rect_filled(frame, 8, kit::BG); + let shown = vec2(cued.canvas.width as f32, cued.canvas.height as f32); + let fit = shown * (frame.shrink(3.0).size() / shown).min_elem(); + egui::Image::new((self.preview.id, fit)) + .corner_radius(6) + .paint_at(ui, Rect::from_center_size(frame.center(), fit)); + ui.painter() + .rect_stroke(frame, 8, Stroke::new(2.0, kit::CUE), egui::StrokeKind::Inside); + y = frame.bottom() + 8.0; + + let enabled = cued.refused.is_none(); + let why = cued.refused.as_deref(); + let half = (inner - 8.0) / 2.0; + let take_at = Rect::from_min_size(pos2(card.left() + PADDING, y), vec2(half, buttons)); + let auto_at = Rect::from_min_size(pos2(take_at.right() + 8.0, y), vec2(half, buttons)); + let take_key = self.key(&Action::Cut, ui.ctx()); + let auto_key = self.key(&Action::Transition, ui.ctx()); + let take = Big { + text: "Take", + note: why.unwrap_or("Put it on air at once"), + key: take_key.as_deref(), + enabled, + metal: true, + }; + if big_button(ui, fx, take_at, take).clicked() { + ask = Some(Ask::Take); + } + let auto_note = format!("Put it on air by the show's transition: {}", cued.transition); + let auto = Big { + text: "Auto", + note: why.unwrap_or(&auto_note), + key: auto_key.as_deref(), + enabled, + metal: false, + }; + if big_button(ui, fx, auto_at, auto).clicked() { + ask = Some(Ask::Auto); + } + y = take_at.bottom() + 6.0; + + let mut words: Vec = Vec::new(); + words.extend(take_key.map(|key| format!("{key} take"))); + words.extend(auto_key.map(|key| format!("{key} auto"))); + words.push(match why { + Some(_) => "cannot go on air".into(), + None => format!("auto: {}", cued.transition), + }); + let hint = ui.painter().layout(words.join(" · "), kit::ui(11.0), kit::DIM, inner); + let at = pos2(card.center().x - hint.size().x / 2.0, y); + ui.painter().galley(at, hint, kit::DIM); + + if let Some(ask) = ask { + self.ask(ask, &cued.name); + } + } + + /// Over the picture of a scene open off air, in `room`'s top: the banner + /// saying so, with Back to live and Take it live, and the live picture + /// small at its right. Where the room left for the picture starts. + pub(super) fn off_air_header(&mut self, ui: &mut Ui, cued: &Cued, room: Rect, shape: f32) -> f32 { + // No taller than a fifth of the room, so a portrait show's picture + // leaves the scene open off air most of it. + let width = (room.width() * 0.24).clamp(140.0, 240.0); + let size = vec2(width, width / shape.max(0.1)); + let size = size * (room.height() * 0.2 / size.y).min(1.0); + let live = Rect::from_min_size(pos2(room.right() - size.x, room.top()), size); + self.on_air(ui, None, live); + + let painter = ui.painter(); + let font = kit::display_bold(14.0); + let back = kit::caps_galley(painter, "Back to live", kit::ui_strong(12.5), kit::CUE, None); + let take = kit::caps_galley(painter, "Take it live", kit::ui_strong(12.5), Color32::WHITE, None); + let buttons = back.size().x + take.size().x + 2.0 * 20.0 + 8.0; + // One row beside the live picture where it fits; or else under it, the + // words over the buttons, as in a narrow window. + let beside = Rect::from_min_max(room.left_top(), pos2(live.left() - 24.0, live.bottom())); + let one_row = beside.width() >= 12.0 + MIN_TEXT + 12.0 + buttons + 6.0; + let area = match one_row { + true => beside, + false => Rect::from_min_size(pos2(room.left(), live.bottom() + 18.0), vec2(room.width(), 68.0)), + }; + let room_for_text = match one_row { + true => area.width() - buttons - 12.0 - 12.0 - 6.0, + false => area.width() - 24.0, + }; + let text = match cued.live { + None => format!("Editing {}, not on air", cued.name), + Some(_) => format!("Editing {}, not on program", cued.name), + }; + let text = kit::caps_galley(painter, &text, font, kit::ON_CUE, Some(room_for_text.max(40.0))); + let width = match one_row { + true => 12.0 + text.size().x + 12.0 + buttons + 6.0, + false => (12.0 + text.size().x + 12.0).max(buttons + 12.0), + }; + let height = if one_row { 38.0 } else { 68.0 }; + let banner = Rect::from_center_size(area.center(), vec2(width.min(area.width()), height)); + painter.rect_filled(banner, 8, kit::CUE); + // An edit here reaches viewers anyway, so say how. + let mut bottom = banner.bottom().max(live.bottom()); + if let Some(why) = &cued.live { + let why = painter.layout( + format!("Viewers still see it: {why}."), + kit::ui(12.0), + kit::CUE, + area.width(), + ); + let at = pos2(banner.center().x - why.size().x / 2.0, banner.bottom() + 6.0); + bottom = bottom.max(at.y + why.size().y); + painter.galley(at, why, kit::CUE); + } + let (text_at, buttons_right, buttons_top) = match one_row { + true => ( + pos2(banner.left() + 12.0, banner.center().y - text.size().y / 2.0), + banner.right() - 6.0, + banner.top() + 6.0, + ), + false => ( + pos2( + banner.center().x - text.size().x / 2.0, + banner.top() + 15.0 - text.size().y / 2.0, + ), + banner.center().x + buttons / 2.0, + banner.top() + 32.0, + ), + }; + painter.galley(text_at, text, kit::ON_CUE); + let mut ask = None; + let take_at = Rect::from_min_size( + pos2(buttons_right - take.size().x - 20.0, buttons_top), + vec2(take.size().x + 20.0, 26.0), + ); + let back_at = Rect::from_min_size( + pos2(take_at.left() - 8.0 - back.size().x - 20.0, take_at.top()), + vec2(back.size().x + 20.0, take_at.height()), + ); + let enabled = cued.refused.is_none(); + let (fill, ink) = match enabled { + true => (kit::ACCENT, Color32::WHITE), + false => (kit::ACCENT.gamma_multiply(0.4), Color32::from_white_alpha(0x99)), + }; + for (at, galley, label, fill, ink) in [ + (back_at, back, "Back to live", kit::ON_CUE, kit::CUE), + (take_at, take, "Take it live", fill, ink), + ] { + let live = label == "Take it live"; + let sense = if live && !enabled { + Sense::hover() + } else { + Sense::click() + }; + let response = ui.interact(at, ui.id().with(("off air", label)), sense); + response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, !live || enabled, label)); + let note = match (live, cued.refused.as_deref()) { + (true, Some(why)) => why.to_string(), + (true, None) => format!("Put it on air by the show's transition: {}", cued.transition), + (false, _) => "Stop editing it and edit the scene on air".to_string(), + }; + let response = kit::tip(response, ¬e, None); + let fill = if response.hovered() { + fill.gamma_multiply(0.85) + } else { + fill + }; + ui.painter().rect_filled(at, 6, fill); + ui.painter().galley(at.center() - galley.size() / 2.0, galley, ink); + if response.clicked() { + ask = Some(if live { Ask::Auto } else { Ask::BackToLive }); + } + } + if let Some(ask) = ask { + self.ask(ask, &cued.name); + } + bottom + 22.0 + } + + /// Studio mode's switch at `at`, lit while it is `on`. + pub(super) fn studio_switch(&mut self, ui: &mut Ui, on: bool, at: Rect) { + let key = self.key(&Action::StudioMode, ui.ctx()); + let note = match on { + true => "On: a scene's pad or key cues it, and TAKE or AUTO puts it on air", + false => "Off: a scene's pad or key takes it. Turn on to cue a scene, then TAKE or AUTO it.", + }; + let button = IconButton::new(Icon::StudioMode, "Studio mode") + .lit(on, kit::CUE) + .look(kit::Look::Boxed) + .key(key.as_deref()) + .note(Some(note)); + if ui.put(at, button).clicked() { + self.controls.press(&Action::StudioMode); + } + } + + /// Do what the NEXT card or the off-air banner asked for, about the scene + /// called `scene`. + fn ask(&mut self, ask: Ask, scene: &str) { + match ask { + Ask::Take => self.controls.press(&Action::Cut), + Ask::Auto => self.controls.press(&Action::Transition), + Ask::Edit => { + let result = self.open_off_air(scene); + self.check(result); + } + Ask::Clear => { + self.editing = None; + self.engine.state.lock().unwrap().uncue(); + } + Ask::BackToLive => { + self.editing = None; + // Studio mode keeps it cued for TAKE; otherwise it is done with. + if !self.controls.studio() { + self.engine.state.lock().unwrap().uncue(); + } + } + } + } +} + +/// TAKE or AUTO. +struct Big<'a> { + text: &'a str, + /// What it does, or why it cannot, under the pointer with its key. + note: &'a str, + key: Option<&'a str>, + enabled: bool, + /// Polished metal, as TAKE is, rather than plain. + metal: bool, +} + +/// `big` at `rect`. +fn big_button(ui: &mut Ui, fx: &mut Fx, rect: Rect, big: Big<'_>) -> egui::Response { + let Big { + text, + note, + key, + enabled, + metal, + } = big; + let sense = if enabled { Sense::click() } else { Sense::hover() }; + let response = ui.interact(rect, ui.id().with(("big button", text)), sense); + response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, enabled, text.to_uppercase())); + let response = kit::tip(response, &format!("{text}: {note}"), key); + let effects = metal && enabled && fx.on(); + let mark = effects.then(|| Mark::new(ui.painter())); + let painter = ui.painter(); + let ink = match (metal, enabled) { + (_, false) => { + painter.rect(rect, 8, kit::P2, Stroke::new(1.0, kit::LINE), egui::StrokeKind::Inside); + kit::FAINT + } + (true, true) if effects => Fx::INK, + (true, true) => { + let fill = if response.hovered() { + kit::ACCENT.gamma_multiply(0.85) + } else { + kit::ACCENT + }; + painter.rect_filled(rect, 8, fill); + Color32::WHITE + } + (false, true) => { + let fill = if response.hovered() { + kit::P3.gamma_multiply(1.3) + } else { + kit::P3 + }; + painter.rect(rect, 8, fill, Stroke::new(1.0, kit::LINE), egui::StrokeKind::Inside); + kit::TEXT + } + }; + let galley = kit::caps_galley(painter, text, kit::display_bold(17.0), ink, None); + painter.galley(rect.center() - galley.size() / 2.0, galley, ink); + if let Some(mark) = mark { + fx.button(&mark.around(rect)); + } + response +} + +/// `transition` in a few words, such as "fade, 300 ms". +pub(super) fn transition_words(transition: &Transition) -> String { + let name = transition_name(transition); + match transition.duration() { + Some(duration) if !matches!(transition, Transition::Stinger { .. }) => { + format!("{name}, {} ms", duration.as_millis()) + } + _ => name.to_string(), + } +} + +#[cfg(test)] +mod tests { + use super::*; + + /// The card stays top right unless the selected layer is there, when it + /// moves to the opposite corner. + #[test] + fn the_card_docks_away_from_the_selected_layer() { + assert_eq!(Corner::away_from(None), Corner::TopRight); + assert_eq!(Corner::away_from(Some([0.9, 0.1])), Corner::BottomLeft); + assert_eq!( + Corner::away_from(Some([0.5, 0.0])), + Corner::BottomLeft, + "the middle counts as right" + ); + assert_eq!(Corner::away_from(Some([0.1, 0.1])), Corner::TopRight); + assert_eq!( + Corner::away_from(Some([0.9, 0.5])), + Corner::TopRight, + "the middle counts as bottom" + ); + assert_eq!(Corner::away_from(Some([0.1, 0.9])), Corner::TopRight); + } + + #[test] + fn a_transition_in_words() { + let fade = Transition::Fade { + duration: Duration::from_millis(300), + }; + assert_eq!(transition_words(&fade), "fade, 300 ms"); + } +} diff --git a/rs/moq-studio/src/ui/graph.rs b/rs/moq-studio/src/ui/graph.rs index c718f53f..37d464ec 100644 --- a/rs/moq-studio/src/ui/graph.rs +++ b/rs/moq-studio/src/ui/graph.rs @@ -617,6 +617,9 @@ impl Panels { if state.compositor.program_scene() == Some(name) { ui.add(kit::Tag::new("On air", kit::Tally::Air)); } + if state.cued() == Some(name) { + ui.add(kit::Tag::new("Next", kit::Tally::Cue)); + } }); if let Some(size) = scene.size { ui.weak(format!("{}x{}", size.width, size.height)); diff --git a/rs/moq-studio/src/ui/inspector.rs b/rs/moq-studio/src/ui/inspector.rs index 96fad2e3..d66ac25f 100644 --- a/rs/moq-studio/src/ui/inspector.rs +++ b/rs/moq-studio/src/ui/inspector.rs @@ -46,7 +46,7 @@ impl Panels { let collection = state.collection(); let layer = self.selection.as_ref().and_then(|picked| picked.item(collection)); let layer = layer.map(|item| item.source.clone()); - (layer, state.compositor.program_scene().map(str::to_string)) + (layer, self.edited(&state).map(str::to_string)) }; let Some(name) = layer else { let name = scene.unwrap_or_else(|| "Scene".into()); @@ -572,14 +572,14 @@ impl Panels { Some((next, label, gesture)) } - /// The scene on program's own settings, with no layer selected: its + /// The settings of the scene BUILD edits, with no layer selected: its /// name, whether it is safe or published, and how every scene goes on air. fn scene_inspector(&mut self, ui: &mut Ui) { let engine = self.engine.clone(); let mut state = engine.state.lock().unwrap(); self.follow_reloads(&state); let collection = state.collection(); - let program = state.compositor.program_scene().map(str::to_string); + let program = self.edited(&state).map(str::to_string); let found = program .as_deref() .and_then(|name| collection.scenes.iter().position(|scene| scene.name == name)); @@ -833,13 +833,15 @@ impl Panels { let spot = Spot::Layer(layer.clone(), item.source.clone()); let what = format!("`{}`", item.source); let mut play = false; + // Play replays a scene open off air in its own picture, never on air. + let replays = match self.off_air(&state) { + Some(_) => "Play the keyframes of the scene open off air again from the start, in its own picture only", + None => "Play the keyframes of the scene on air again from the start, on air", + }; ui.horizontal(|ui| { ui.strong(format!("Keyframes of {what}")); ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| { - play = ui - .add(kit::button(Icon::Play, "Play")) - .on_hover_text("Play the keyframes of the scene on air again from the start, on air") - .clicked(); + play = ui.add(kit::button(Icon::Play, "Play")).on_hover_text(replays).clicked(); }); }); ui.label( @@ -977,7 +979,11 @@ impl Panels { } if play { - state.compositor.set_program_start(kio::clock::now()); + match self.off_air(&state).map(str::to_string) { + // Replayed where it is drawn, never on program. + Some(cued) => state.compositor.set_preview(Some(cued)), + None => state.compositor.set_program_start(kio::clock::now()), + } } let Some((label, gesture)) = action else { return }; let result = edit(&mut state, label, gesture, |draft| { diff --git a/rs/moq-studio/src/ui/layers.rs b/rs/moq-studio/src/ui/layers.rs index 1ff7abac..3830ae90 100644 --- a/rs/moq-studio/src/ui/layers.rs +++ b/rs/moq-studio/src/ui/layers.rs @@ -3,7 +3,7 @@ use egui::{Align2, Rect, Sense, Stroke, Vec2, pos2, vec2}; -use super::build::{LayerAction, Menu, layer_menu, shown_in}; +use super::build::{LayerAction, Menu, OFF_AIR_TOP, layer_menu, shown_in}; use super::*; /// A layer row's height. @@ -38,8 +38,9 @@ impl Panels { }); } - /// The layers of the scene on program and the always-on-top ones over - /// it, front first, with Add a layer under them. + /// The layers of the scene BUILD edits and the always-on-top ones over + /// it, front first, with Add a layer under them. A scene open off air + /// has only its own, as the always-on-top ones are drawn on program. fn layers(&mut self, ui: &mut Ui) { let footer = 40.0; let list = ui @@ -56,7 +57,14 @@ impl Panels { .show(ui, |ui| { ui.spacing_mut().item_spacing.y = 0.0; let groups = [(Layer::top(), "Always on top"), (Layer::scene(""), "This scene")]; + let off_air = self.off_air(&state).is_some(); for (layer, caption) in groups { + if off_air && layer.scene.is_none() { + caption_row(ui, caption); + ui.label(egui::RichText::new(OFF_AIR_TOP).color(kit::DIM)); + ui.add_space(8.0); + continue; + } let layer = match layer.scene { None => layer, Some(_) => match self.scene(&state) { @@ -135,7 +143,7 @@ impl Panels { if response.drag_started() { self.moving = Some(index); } - if let Some(menu) = Menu::of(state, &picked) { + if let Some(menu) = Menu::of(state, &picked, self.off_air(state).is_some()) { response.context_menu(|ui| { if let Some(chosen) = layer_menu(ui, &menu) { action = Some((picked.clone(), chosen)); diff --git a/rs/moq-studio/src/ui/settings.rs b/rs/moq-studio/src/ui/settings.rs index 1f55ba33..3d5bbffa 100644 --- a/rs/moq-studio/src/ui/settings.rs +++ b/rs/moq-studio/src/ui/settings.rs @@ -252,9 +252,11 @@ impl Panels { let mut bind = None; let mut clear = None; + // A scene's key takes it, or cues it in Studio mode. + let studio = self.controls.studio(); egui::Grid::new("hotkeys").striped(true).show(ui, |ui| { for action in &actions { - ui.label(action.to_string()); + ui.label(action.name(studio)); let bound = bindings.get(action); if self.binding.as_ref() == Some(action) { ui.strong("press a key, or Escape"); diff --git a/rs/moq-studio/src/ui/shell.rs b/rs/moq-studio/src/ui/shell.rs index a142abe7..14309108 100644 --- a/rs/moq-studio/src/ui/shell.rs +++ b/rs/moq-studio/src/ui/shell.rs @@ -7,6 +7,7 @@ use egui::{ }; use super::build::duplicate_scene; +use super::cue::{Corner, Cued, transition_words}; use super::layout::{Arrangement, Layout, SOUND_ROW, fit}; use super::levels::reading; use super::*; @@ -31,7 +32,11 @@ pub(super) struct Snapshot { /// How many scenes have been taken, which the effects burst on. pub(super) takes: u64, /// The program's shape, width over height. - shape: f32, + pub(super) shape: f32, + /// The scene cued, or open off air. + pub(super) cued: Option, + /// Whether Studio mode is on: a scene's pad cues it. + pub(super) studio: bool, } /// A scene as its pad shows it. @@ -63,11 +68,13 @@ const FAILED: Duration = Duration::from_secs(10); /// Room on the title bar's left for macOS's own window buttons. const TRAFFIC_LIGHTS: f32 = 64.0; -/// What a pad's menu asked for. /// What a pad asked for, naming its scene: the pads are drawn from the /// frame's snapshot, and a reload since may have moved or removed it. enum PadAction { Take(String), + Cue(String), + /// Open it for editing off air. + Edit(String), /// Make it the safe scene, or stop. Safe(String, bool), Remove(String), @@ -97,6 +104,7 @@ impl Panels { self.program_drawn = state.compositor.canvas(); if let Some(render) = frame.wgpu_render_state() { self.program.follow(render, state.compositor.layered()); + self.preview.follow(render, state.compositor.preview()); self.follow_thumbnails(render, &state.compositor); } // Redraw at the canvas rate, so the picture and the pads are live. @@ -112,6 +120,16 @@ impl Panels { hotkeys.rename(renames); } } + // So does the scene open off air, which stays open while it is cued. + for renames in &renames { + if let Some(to) = self.editing.as_ref().and_then(|editing| renames.get(editing)) { + self.editing = to.clone(); + } + } + let cued = state.cued().map(str::to_string); + if self.editing != cued { + self.editing = None; + } // So does a size being typed, a renamed scene's winning its new name. for renames in &renames { let pending = std::mem::take(&mut self.sizes); @@ -172,6 +190,14 @@ impl Panels { }) }) .collect(); + let cued = cued.map(|name| Cued { + refused: collection.refuses(&name), + canvas: collection.canvas(Some(name.as_str())).unwrap_or(collection.canvas), + off_air: self.editing.as_ref() == Some(&name), + live: state.seen(&name), + transition: transition_words(&collection.transition), + name, + }); let path = self.engine.autosave.path(); let show = path .file_stem() @@ -189,6 +215,8 @@ impl Panels { stream, takes: state.takes, shape: self.program_drawn.width as f32 / self.program_drawn.height.max(1) as f32, + cued, + studio: self.controls.studio(), } } @@ -227,9 +255,12 @@ impl Panels { match self.page { Page::Live => { kit::wash(ui.painter(), stage); - self.on_air(ui, Some(fx), layout.picture); + let picture = self.on_air(ui, Some(fx), layout.picture).rect; + if let Some(cued) = &snapshot.cued { + self.next(ui, fx, cued, picture, Corner::TopRight); + } } - Page::Build => self.build(ui, fx, stage, snapshot.shape), + Page::Build => self.build(ui, fx, stage, snapshot), // The sound slot holds the live picture instead. Page::Mix => region(ui, stage, |ui| { self.audio_scenes(ui); @@ -676,6 +707,19 @@ impl Panels { /// a row down a `column`. fn scenes_strip(&mut self, ui: &mut Ui, snapshot: &Snapshot, rect: Rect, column: bool) { let room = rect.shrink(MARGIN); + // Studio mode's switch at the strip's end: right of a row, under a + // column. + let (room, switch) = match column { + true => ( + room.with_max_y(room.bottom() - 30.0 - GAP), + Rect::from_min_size(pos2(room.right() - 30.0, room.bottom() - 30.0), Vec2::splat(30.0)), + ), + false => ( + room.with_max_x(room.right() - 30.0 - GAP), + Rect::from_center_size(pos2(room.right() - 15.0, room.center().y), Vec2::splat(30.0)), + ), + }; + self.studio_switch(ui, snapshot.studio, switch); let mut action = None; ui.scope_builder(UiBuilder::new().max_rect(room), |ui| { ui.spacing_mut().item_spacing = Vec2::splat(GAP); @@ -723,6 +767,8 @@ impl Panels { }; let spot = match &action { PadAction::Take(name) + | PadAction::Cue(name) + | PadAction::Edit(name) | PadAction::Safe(name, _) | PadAction::Remove(name) | PadAction::Rename(name) @@ -733,6 +779,13 @@ impl Panels { }; let result = match action { PadAction::Take(name) => crate::controls::take(&mut state, &name).map(drop), + PadAction::Cue(name) => crate::controls::cue(&mut state, &name).map(drop), + PadAction::Edit(name) => { + drop(state); + let result = self.open_off_air(&name); + self.fail(Spot::Pad(name), result); + return; + } PadAction::Safe(name, safe) => { at(&state, &name).and_then(|index| self.scene_action(&mut state, SceneAction::Safe(index, safe))) } @@ -823,15 +876,37 @@ impl Panels { return response.clicked().then_some(PadAction::Add); }; let on_air = snapshot.program.as_deref() == Some(pad.name.as_str()); - let tally = if on_air { Tally::Air } else { Tally::Off }; + let cued = snapshot.cued.as_ref().is_some_and(|cued| cued.name == pad.name); + let tally = match (on_air, cued) { + (true, _) => Tally::Air, + (false, true) => Tally::Cue, + (false, false) => Tally::Off, + }; let response = self.pad(ui, pad, tally, width, snapshot.shape); - let mut action = (response.clicked() && pad.refused.is_none()).then(|| PadAction::Take(pad.name.clone())); + let click = match snapshot.studio { + true => PadAction::Cue(pad.name.clone()), + false => PadAction::Take(pad.name.clone()), + }; + let mut action = (response.clicked() && pad.refused.is_none()).then_some(click); response.context_menu(|ui| { let takeable = pad.refused.is_none() || on_air; let take = ui.add_enabled(!on_air && pad.refused.is_none(), egui::Button::new("Take it on air")); if take.clicked() { action = Some(PadAction::Take(pad.name.clone())); } + if snapshot.studio { + let cue = ui.add_enabled(!on_air && !cued && pad.refused.is_none(), egui::Button::new("Cue it")); + if cue.clicked() { + action = Some(PadAction::Cue(pad.name.clone())); + } + } + let edit = ui + .add_enabled(!on_air, egui::Button::new("Edit off air")) + .on_hover_text("Open it on Build without going on air") + .on_disabled_hover_text("On air; Build edits it live"); + if edit.clicked() { + action = Some(PadAction::Edit(pad.name.clone())); + } let mut safe = snapshot.safe.as_deref() == Some(pad.name.as_str()); let toggle = ui .add_enabled(takeable || safe, kit::Toggle::new(&mut safe).label("Safe scene")) @@ -912,7 +987,7 @@ impl Panels { } /// The key bound to `action`, as its tooltip shows it. - fn key(&self, action: &Action, ctx: &egui::Context) -> Option { + pub(super) fn key(&self, action: &Action, ctx: &egui::Context) -> Option { let hotkeys = self.hotkeys.as_ref()?; let bindings = hotkeys.bindings(); Some(bindings.get(action)?.shown(ctx))