diff --git a/README.md b/README.md
index 30ec3236..03f3a4f4 100644
--- a/README.md
+++ b/README.md
@@ -188,6 +188,7 @@ macOS the system's buttons and edges stay. It holds, from the left:
- The live control: **GO LIVE** off air, which opens the
[go-live sheet](#going-live); on air, **LIVE** and how long the stream has
run, which reads **END STREAM** under the pointer.
+- Search, which opens the [command palette](#command-palette).
- The gear, which opens [Settings](#settings).
- Minimize, maximize, and close, except on macOS.
@@ -348,6 +349,35 @@ 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.
+### Command palette
+
+**Ctrl+K** (**Cmd+K** on macOS), or the search button in the title bar, opens
+a search box over any page that runs anything the studio can do. Type a few
+letters of what you want, pick a row with the arrows or the pointer, and
+press Enter or click it; Escape, a click outside it, or Ctrl+K again closes
+it. It lists:
+
+- Every action a [hotkey](#hotkeys) can do, by what it is for, each with the
+ key bound to it: going live, ending the stream, the panic key, recording,
+ Studio mode, TAKE and AUTO, taking or cueing each scene, muting or
+ unmuting each sound, and replay and clips. One that cannot run now stays
+ listed, dimmed, saying why, such as TAKE with nothing cued or a scene that
+ cannot go on program. **Go live** opens the go-live sheet, as GO LIVE does;
+ the rest act at once, as their keys do.
+- Selecting each layer of the scene BUILD edits, by its source's name.
+- Adding a camera, screen, window, or input: the first time, **Find cameras,
+ screens, windows, and inputs to add** lists them, then each is a row of its
+ own, added as a layer as the Add tab adds it. **Add a source** opens the
+ Add tab on any kind of source, to fill in by hand.
+- The pages, each Settings pane, and each setting by its name, such as
+ **Frame rate** or **Room key**, which opens its pane at that setting.
+- Undo and redo, naming the edit, the multiview, the stream's health in
+ detail, and the scene graph.
+
+A row is found by the words of its name, what it is for, and a few more it
+answers to, such as `fps` for the frame rate or `mic` for a mute, so `mute
+desk` finds **Mute `desk`**.
+
### Multiview
**Open the multiview**, in the show's menu, opens a window for another
@@ -439,7 +469,7 @@ setting costs. Escape or a click outside closes it.
| Show | Pick the format, landscape or portrait, which swaps the canvas's sides; the canvas size as 720p, 1080p, 1440p, or 4K, with the upload each wants, or **Custom** for exact numbers; the frame rate as 30, 60, or **Custom**; and, under **Scene sizes**, each scene's own size (see [Published scenes](#published-scenes)). Saved in the scene file, and undone like any edit. |
| Stream | Set the relay, its token, the failover relay, the broadcast's name, and on demand (see [Stream settings](#stream-settings)). |
| Recording | Change or open the recordings folder, and pick the picture and the audio scene a recording holds, and whether each source records a file of its own too (see [Recording](#recording)). |
-| Hotkeys | Bind keys, by what they are for: going live, ending the stream, the panic key, and recording; Studio mode, TAKE, and AUTO; each scene; and replay and clips (see [Hotkeys](#hotkeys)). |
+| Hotkeys | Bind keys, by what they are for: going live, ending the stream, the panic key, and recording; Studio mode, TAKE, and AUTO; each scene; each sound's mute; and replay and clips (see [Hotkeys](#hotkeys)). |
| Guests | Set the room guests join, its key, the join page, how long a link lasts, and whether guests appear on their own (see [Guests](#guests)). |
| Advanced | Publish scenes as broadcasts of their own and sources independently, turn the virtual camera of the program or of each published scene on, pick how the window's [effects](#effects) move, and open the [scene graph](#scene-graph). |
@@ -1586,8 +1616,10 @@ a WebGL page runs slower.
Settings, Hotkeys 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, **Go live**,
-**End stream**, 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
+**End stream**, each scene, which its key takes, or cues in Studio mode,
+as its pad does (the tab says which), and each sound, which its key mutes or
+unmutes, as its strip's button does. The [command palette](#command-palette)
+lists the same actions with their keys. 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
diff --git a/quest/m2/command-palette.md b/quest/m2/command-palette.md
deleted file mode 100644
index 159cb2b1..00000000
--- a/quest/m2/command-palette.md
+++ /dev/null
@@ -1,19 +0,0 @@
-# [M] A command palette
-
-## Goal
-
-One key opens a search box that runs anything the studio can do: take a
-scene, mute a sound, add a window, start a recording, open a setting. It
-lists each action with its key, and it is how a setting is found by name.
-
-## Plan
-
-Planned 2026-11-09 (maintainer, /quest-plan), and held for later: ✅ m2
-(rejected: m1).
-
-- Every action is registered once, with its name and the words it answers
- to, and that one table feeds the palette, the Hotkeys settings, and the
- tooltips, so they cannot disagree. Today the bindable actions are a fixed
- enum (`rs/moq-studio/src/controls.rs`).
-- Scenes, sources, and settings are found by their own names.
-- An action that cannot run now is shown with the reason, not hidden.
diff --git a/rs/moq-studio/assets/icons/search.svg b/rs/moq-studio/assets/icons/search.svg
new file mode 100644
index 00000000..3364372a
--- /dev/null
+++ b/rs/moq-studio/assets/icons/search.svg
@@ -0,0 +1,15 @@
+
+
diff --git a/rs/moq-studio/src/controls.rs b/rs/moq-studio/src/controls.rs
index f3382dca..b46e9d45 100644
--- a/rs/moq-studio/src/controls.rs
+++ b/rs/moq-studio/src/controls.rs
@@ -1,5 +1,6 @@
-//! What the operator does from a button or a hotkey: take a scene, panic,
-//! replay, save a clip, record, and go live and end the stream. Hotkeys fire
+//! What the operator does from a button, a hotkey, or the command palette:
+//! take a scene, mute a sound, panic, replay, save a clip, record, and go live
+//! and end the stream, each registered once in the table here. Hotkeys fire
//! from outside the window's frames, so a key pressed while a game has focus
//! acts at once, even while the window is hidden and draws nothing.
@@ -13,7 +14,8 @@ use crate::engine::{Engine, OnAir, State};
use crate::replay;
use crate::stream::{Stream, Switched};
-/// Something a hotkey can be bound to.
+/// Something the studio does, from a hotkey, the command palette, or a
+/// button. Bindings are saved by the variant's name.
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord, serde::Serialize, serde::Deserialize)]
pub enum Action {
/// TAKE: put the cued scene on program at once.
@@ -37,19 +39,178 @@ pub enum Action {
GoLive,
/// End the stream, handing the relays its tail first.
EndStream,
+ /// Mute a sound, by its source's name, or unmute it.
+ Mute(String),
}
+/// What an action is for, which the Hotkeys pane and the palette group it by.
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum Group {
+ Live,
+ StudioMode,
+ Scenes,
+ Sounds,
+ Review,
+}
+
+impl Group {
+ /// Each group, in the order the Hotkeys pane and the palette list them.
+ pub const ALL: [Self; 5] = [Self::Live, Self::StudioMode, Self::Scenes, Self::Sounds, Self::Review];
+
+ pub fn name(self) -> &'static str {
+ match self {
+ Self::Live => "Live",
+ Self::StudioMode => "Studio mode",
+ Self::Scenes => "Scenes",
+ Self::Sounds => "Sounds",
+ Self::Review => "Review",
+ }
+ }
+}
+
+/// An action every show has, as the table registers it.
+struct Fixed {
+ action: Action,
+ group: Group,
+ /// What the desktop's shortcut settings keep its key under, the same
+ /// across runs, so a key the operator picked there stays.
+ id: &'static str,
+ name: &'static str,
+ /// A word or two the Hotkeys pane shows beside the name.
+ detail: Option<&'static str>,
+ /// What else the palette finds it by.
+ words: &'static [&'static str],
+}
+
+/// The actions every show has, each registered once, in the order the
+/// Hotkeys pane and the palette list them within their group. Each scene and
+/// sound adds its own: see [`Action::listed`].
+const FIXED: [Fixed; 9] = [
+ Fixed {
+ action: Action::GoLive,
+ group: Group::Live,
+ id: "go-live",
+ name: "Go live",
+ detail: None,
+ words: &["start", "stream", "broadcast"],
+ },
+ Fixed {
+ action: Action::EndStream,
+ group: Group::Live,
+ id: "end-stream",
+ name: "End stream",
+ detail: Some("held"),
+ words: &["stop", "off air", "finish"],
+ },
+ Fixed {
+ action: Action::Panic,
+ group: Group::Live,
+ id: "panic",
+ name: "Panic",
+ detail: Some("safe scene, mics muted"),
+ words: &["safe", "emergency", "mute all", "hide"],
+ },
+ Fixed {
+ action: Action::Record,
+ group: Group::Live,
+ id: "record",
+ name: "Start or stop recording",
+ detail: None,
+ words: &["rec"],
+ },
+ Fixed {
+ action: Action::StudioMode,
+ group: Group::StudioMode,
+ id: "studio-mode",
+ name: "Turn Studio mode on or off",
+ detail: None,
+ words: &["preview", "cue"],
+ },
+ Fixed {
+ action: Action::Cut,
+ group: Group::StudioMode,
+ id: "cut",
+ name: "Take the cued scene",
+ detail: None,
+ words: &["cut"],
+ },
+ Fixed {
+ action: Action::Transition,
+ group: Group::StudioMode,
+ id: "transition",
+ name: "Auto: take the cued scene by the transition",
+ detail: None,
+ words: &["fade"],
+ },
+ Fixed {
+ action: Action::Replay,
+ group: Group::Review,
+ id: "replay",
+ name: "Replay",
+ detail: None,
+ words: &["instant", "play back"],
+ },
+ Fixed {
+ action: Action::SaveClip,
+ group: Group::Review,
+ id: "save-clip",
+ name: "Save clip",
+ detail: None,
+ words: &["highlight"],
+ },
+];
+
impl Action {
- /// The actions every scene file has, by what they are for, as the
- /// Hotkeys pane lists them, each scene's after the first two.
- pub const FIXED: [(&'static str, &'static [Self]); 3] = [
- ("Live", &[Self::GoLive, Self::EndStream, Self::Panic, Self::Record]),
- ("Studio mode", &[Self::StudioMode, Self::Cut, Self::Transition]),
- ("Review", &[Self::Replay, Self::SaveClip]),
- ];
-
- /// What it does with Studio mode on or off, as the Hotkeys tab and a
- /// hotkey's message name it.
+ /// Every action `state`'s show has, by group, in the order the Hotkeys
+ /// pane and the palette list them: the table's, a scene's for each scene,
+ /// and a mute for each sound.
+ pub fn listed(state: &State) -> Vec {
+ let scenes = state
+ .collection()
+ .scenes
+ .iter()
+ .map(|scene| Self::Scene(scene.name.clone()));
+ let sounds = state
+ .sources
+ .iter()
+ .filter(|(_, feed)| feed.strip().is_some())
+ .map(|(name, _)| Self::Mute(name.to_string()));
+ let mut listed: Vec = FIXED.iter().map(|fixed| fixed.action.clone()).collect();
+ listed.extend(scenes.chain(sounds));
+ // Stable, so each group keeps its order.
+ listed.sort_by_key(|action| Group::ALL.iter().position(|group| *group == action.group()));
+ listed
+ }
+
+ fn fixed(&self) -> &'static Fixed {
+ FIXED
+ .iter()
+ .find(|fixed| fixed.action == *self)
+ .expect("every action without a name is in the table")
+ }
+
+ /// What it is for.
+ pub fn group(&self) -> Group {
+ match self {
+ Self::Scene(_) => Group::Scenes,
+ Self::Mute(_) => Group::Sounds,
+ fixed => fixed.fixed().group,
+ }
+ }
+
+ /// What the desktop's shortcut settings keep its key under, the same
+ /// across runs, or `None` for a scene's, which is named for its key so
+ /// it follows the scene through renames. A source is never renamed.
+ pub fn id(&self) -> Option {
+ match self {
+ Self::Scene(_) => None,
+ Self::Mute(name) => Some(format!("mute/{name}")),
+ fixed => Some(fixed.fixed().id.into()),
+ }
+ }
+
+ /// What it does with Studio mode on or off, as the Hotkeys tab, the
+ /// palette, 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}`"),
@@ -57,22 +218,34 @@ impl Action {
_ => self.to_string(),
}
}
+
+ /// A word or two the Hotkeys pane shows beside the name, with Studio mode
+ /// on or off.
+ pub fn detail(&self, studio: bool) -> Option<&'static str> {
+ match self {
+ Self::Scene(_) => studio.then_some("cues"),
+ Self::Mute(_) => None,
+ fixed => fixed.fixed().detail,
+ }
+ }
+
+ /// What else the palette finds it by, besides its name and group.
+ pub fn words(&self) -> &'static [&'static str] {
+ match self {
+ Self::Scene(_) => &["take", "cue", "pad", "switch"],
+ Self::Mute(_) => &["unmute", "sound", "audio", "mic", "silence"],
+ fixed => fixed.fixed().words,
+ }
+ }
}
impl std::fmt::Display for Action {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
- 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"),
- Self::Panic => write!(f, "Panic"),
- Self::GoLive => write!(f, "Go live"),
- Self::EndStream => write!(f, "End stream"),
+ Self::Mute(name) => write!(f, "Mute or unmute `{name}`"),
+ fixed => f.write_str(fixed.fixed().name),
}
}
}
@@ -253,6 +426,36 @@ impl Controls {
}
Action::GoLive => self.go_live(),
Action::EndStream => self.end_stream(),
+ Action::Mute(name) => mute(&mut self.engine.state.lock().unwrap(), name),
+ }
+ }
+
+ /// Why `action` cannot run now, under `state` locked by the caller, if it
+ /// cannot, as the palette shows it beside the action.
+ pub fn refused(&self, state: &State, action: &Action) -> Option {
+ let collection = state.collection();
+ match action {
+ Action::GoLive if self.engine.on_air() != OnAir::Off => Some("the program is already on air".into()),
+ Action::GoLive if self.going() => Some("already going live".into()),
+ Action::GoLive if self.closing.load(Ordering::Acquire) => Some("the show is closing".into()),
+ Action::EndStream if self.engine.on_air().live().is_none() => Some("the program is not on air".into()),
+ Action::Cut | Action::Transition => match state.cued() {
+ None => Some("nothing is cued".into()),
+ Some(scene) => collection.refuses(scene),
+ },
+ Action::Scene(name) => collection.refuses(name),
+ Action::Mute(name) if !collection.sources.contains_key(name) => {
+ Some(format!("there is no source `{name}`"))
+ }
+ // Whichever is picked, any replay source plays it.
+ Action::Replay => replay_source(collection, None).err().map(|err| err.to_string()),
+ Action::Record => self
+ .engine
+ .recorder
+ .status()
+ .is_some_and(|status| status.stopping && !status.done)
+ .then(|| "the last recording is still finishing".into()),
+ _ => None,
}
}
@@ -593,22 +796,9 @@ impl Controls {
Ok((saving, Some(save)))
}
- /// The replay source a replay plays in: `picked`, or the first there is
- /// while the panel has picked none, or one since removed.
+ /// The replay source a replay plays in, as [`replay_source`] picks it.
fn replay_source(&self, picked: Option<&str>) -> anyhow::Result {
- let state = self.engine.state.lock().unwrap();
- let sources = &state.collection().sources;
- let replays = || {
- sources
- .iter()
- .filter(|(_, source)| matches!(source, Source::Replay))
- .map(|(name, _)| name)
- };
- let name = replays()
- .find(|name| Some(name.as_str()) == picked)
- .or_else(|| replays().next())
- .context("no replay source; add one in Sources")?;
- Ok(name.clone())
+ replay_source(self.engine.state.lock().unwrap().collection(), picked)
}
/// Keep how `action`, fired by a hotkey, went for the status bar.
@@ -623,6 +813,40 @@ impl Controls {
}
}
+/// The replay source a replay plays in: `picked`, or the first there is
+/// while REVIEW has picked none, or one since removed.
+fn replay_source(collection: &moq_scene::Collection, picked: Option<&str>) -> anyhow::Result {
+ let replays = || {
+ collection
+ .sources
+ .iter()
+ .filter(|(_, source)| matches!(source, Source::Replay))
+ .map(|(name, _)| name)
+ };
+ let name = replays()
+ .find(|name| Some(name.as_str()) == picked)
+ .or_else(|| replays().next())
+ .context("no replay source; add one in Sources")?;
+ Ok(name.clone())
+}
+
+/// Mute the sound called `name`, or unmute it, under `state` locked by the
+/// caller, as its strip's button does.
+pub fn mute(state: &mut State, name: &str) -> anyhow::Result {
+ let collection = state.collection();
+ anyhow::ensure!(collection.sources.contains_key(name), "there is no source `{name}`");
+ let mut audio = collection.audio.get(name).cloned().unwrap_or_default();
+ audio.muted = !audio.muted;
+ let (verb, done) = match audio.muted {
+ true => ("Mute", "muted"),
+ false => ("Unmute", "unmuted"),
+ };
+ let mut draft = collection.draft(format!("{verb} `{name}`"));
+ draft.set_audio(name, Some(audio))?;
+ state.commit(draft, None)?;
+ Ok(format!("{done} `{name}`"))
+}
+
/// Take the scene called `name` on program, under `state` locked by the
/// caller, following any rename the window has yet to move its key through.
pub fn take(state: &mut State, name: &str) -> anyhow::Result {
@@ -639,3 +863,59 @@ pub fn cue(state: &mut State, name: &str) -> anyhow::Result {
None => format!("`{scene}` is on air; nothing is cued"),
})
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ /// Each action without a name of its own is in the table once, under an
+ /// id no other has, so the desktop never confuses two keys.
+ #[test]
+ fn every_action_is_registered_once() {
+ // Every variant, so a new one fails to build here until it is placed.
+ let registered = |action: &Action| match action {
+ Action::Scene(_) | Action::Mute(_) => false,
+ Action::Cut
+ | Action::Transition
+ | Action::StudioMode
+ | Action::Replay
+ | Action::SaveClip
+ | Action::Record
+ | Action::Panic
+ | Action::GoLive
+ | Action::EndStream => true,
+ };
+ for (index, fixed) in FIXED.iter().enumerate() {
+ assert!(registered(&fixed.action), "{:?}", fixed.action);
+ for other in &FIXED[index + 1..] {
+ assert_ne!(fixed.action, other.action);
+ assert_ne!(fixed.id, other.id);
+ }
+ assert_eq!(fixed.action.to_string(), fixed.name);
+ }
+ let scene = Action::Scene("Gameplay".into());
+ let mute = Action::Mute("Gameplay".into());
+ assert_eq!(scene.id(), None, "named for its key");
+ assert_ne!(mute.id(), Some("scene/Gameplay".into()));
+ assert_eq!((scene.group(), mute.group()), (Group::Scenes, Group::Sounds));
+ }
+
+ /// Each group lists its actions in the table's order, the groups in
+ /// theirs.
+ #[test]
+ fn groups_keep_the_tables_order() {
+ let order = |group: Group| {
+ FIXED
+ .iter()
+ .filter(move |fixed| fixed.group == group)
+ .map(|fixed| &fixed.action)
+ };
+ let mut seen = Vec::new();
+ for group in Group::ALL {
+ seen.extend(order(group));
+ }
+ assert_eq!(seen.len(), FIXED.len(), "every action has a group the pane lists");
+ let live: Vec<_> = order(Group::Live).cloned().collect();
+ assert_eq!(live, [Action::GoLive, Action::EndStream, Action::Panic, Action::Record]);
+ }
+}
diff --git a/rs/moq-studio/src/engine.rs b/rs/moq-studio/src/engine.rs
index 0417a302..cb0dede0 100644
--- a/rs/moq-studio/src/engine.rs
+++ b/rs/moq-studio/src/engine.rs
@@ -4022,6 +4022,51 @@ mod tests {
assert_eq!(state.compositor.program_scene(), Some("Guest"), "otherwise it takes");
assert_eq!(state.cued(), None);
}
+
+ // The palette says why an action cannot run now, and what it says is
+ // what running it would.
+ {
+ use crate::controls::Action;
+ let state = engine.state.lock().unwrap();
+ let refused = |action: Action| controls.refused(&state, &action);
+ assert_eq!(refused(Action::Cut).as_deref(), Some("nothing is cued"));
+ assert_eq!(refused(Action::Transition).as_deref(), Some("nothing is cued"));
+ assert_eq!(
+ refused(Action::Scene("Portrait".into())),
+ state.collection().refuses("Portrait")
+ );
+ assert!(refused(Action::Scene("Portrait".into())).is_some());
+ assert_eq!(refused(Action::Scene("Guest".into())), None);
+ assert_eq!(refused(Action::EndStream).as_deref(), Some("the program is not on air"));
+ assert_eq!(refused(Action::GoLive), None);
+ assert_eq!(
+ refused(Action::Replay).as_deref(),
+ Some("no replay source; add one in Sources")
+ );
+ assert_eq!(refused(Action::Mute("red".into())), None);
+ assert!(refused(Action::Mute("nobody".into())).is_some());
+ assert!(Action::listed(&state).contains(&Action::Scene("Portrait".into())));
+ }
+ for (action, why) in [
+ (crate::controls::Action::Cut, "nothing is cued"),
+ (crate::controls::Action::EndStream, "the program is not on air"),
+ ] {
+ let err = controls.fire(&action).unwrap_err();
+ assert_eq!(format!("{err:#}"), why);
+ }
+
+ // A sound's key or palette row flips its mute, an edit undo takes back.
+ let mute = crate::controls::Action::Mute("red".into());
+ assert_eq!(controls.fire(&mute).unwrap(), "muted `red`");
+ assert!(engine.state.lock().unwrap().collection().audio["red"].muted);
+ assert_eq!(controls.fire(&mute).unwrap(), "unmuted `red`");
+ assert!(!engine.state.lock().unwrap().collection().audio["red"].muted);
+ assert_eq!(
+ engine.state.lock().unwrap().undo().unwrap().as_deref(),
+ Some("Unmute `red`")
+ );
+ assert!(engine.state.lock().unwrap().collection().audio["red"].muted);
+ assert!(controls.fire(&crate::controls::Action::Mute("nobody".into())).is_err());
let stopping = engine.clone();
tokio::task::spawn_blocking(move || stopping.stop()).await.unwrap();
}
diff --git a/rs/moq-studio/src/hotkeys/portal.rs b/rs/moq-studio/src/hotkeys/portal.rs
index e4494391..7b696498 100644
--- a/rs/moq-studio/src/hotkeys/portal.rs
+++ b/rs/moq-studio/src/hotkeys/portal.rs
@@ -122,8 +122,6 @@ async fn run(
/// for the key bound to it, which follows the scene through renames.
fn id(action: &Action, binding: &Binding) -> String {
match action {
- Action::Cut => "cut".into(),
- Action::Transition => "transition".into(),
Action::Scene(_) => {
let held = binding.modifiers;
let mut id = "scene/".to_string();
@@ -143,13 +141,7 @@ fn id(action: &Action, binding: &Binding) -> String {
}
id
}
- Action::Replay => "replay".into(),
- Action::SaveClip => "save-clip".into(),
- Action::Record => "record".into(),
- Action::Panic => "panic".into(),
- Action::StudioMode => "studio-mode".into(),
- Action::GoLive => "go-live".into(),
- Action::EndStream => "end-stream".into(),
+ action => action.id().expect("only a scene's is named for its key"),
}
}
diff --git a/rs/moq-studio/src/kit/icon.rs b/rs/moq-studio/src/kit/icon.rs
index 6da89955..307e2dae 100644
--- a/rs/moq-studio/src/kit/icon.rs
+++ b/rs/moq-studio/src/kit/icon.rs
@@ -77,12 +77,14 @@ pub enum Icon {
/// Opens in a window of its own.
Detach,
Info,
+ /// Opens the command palette.
+ Search,
}
impl Icon {
/// Every icon, for the gallery.
#[cfg(test)]
- pub const ALL: [Self; 65] = [
+ pub const ALL: [Self; 66] = [
Self::Undo,
Self::Redo,
Self::Settings,
@@ -148,6 +150,7 @@ impl Icon {
Self::Advanced,
Self::Detach,
Self::Info,
+ Self::Search,
];
fn source(self) -> ImageSource<'static> {
@@ -217,6 +220,7 @@ impl Icon {
Self::Advanced => include_image!("../../assets/icons/sliders-horizontal.svg"),
Self::Detach => include_image!("../../assets/icons/external-link.svg"),
Self::Info => include_image!("../../assets/icons/info.svg"),
+ Self::Search => include_image!("../../assets/icons/search.svg"),
}
}
diff --git a/rs/moq-studio/src/shots.rs b/rs/moq-studio/src/shots.rs
index f70e5e51..9880b848 100644
--- a/rs/moq-studio/src/shots.rs
+++ b/rs/moq-studio/src/shots.rs
@@ -130,6 +130,9 @@ enum View {
/// BUILD's Add tab on the drop views' show, with a file dragged or
/// dropped on the picture.
Drop(Drop),
+ /// The command palette, open by its key over LIVE with a few keys bound,
+ /// with what is typed into it.
+ Palette(&'static str),
}
/// A file over the picture, at the pointer.
@@ -359,6 +362,15 @@ views! {
settings_advanced: Still, studio(View::Setting(Setting::Advanced));
/// The scene graph, in a window of its own.
graph: Still, studio(View::Graph);
+ /// The command palette as its key opens it: every action, each with its
+ /// key and why it cannot run now, before the pages, settings, and what
+ /// can be added.
+ palette: Still, studio(View::Palette(""));
+ /// The palette finding what `take` names: the scenes and TAKE, which says
+ /// nothing is cued.
+ palette_found: Still, studio(View::Palette("take"));
+ /// The palette finding a setting by its name.
+ palette_setting: Still, studio(View::Palette("frame"));
/// The show's menu: its file, Reload, Copy, Paste, and Close show, which
/// returns to the library.
show_menu: Still, studio(View::ShowMenu);
@@ -605,6 +617,146 @@ fn a_click_takes_and_the_panic_key_cuts() {
quit(&engine, &runtime);
}
+/// The command palette as a person uses it: its key opens it from LIVE,
+/// what is typed finds a scene, a sound, and a setting, and Enter runs the
+/// one picked, taking the scene, muting the sound, and opening Settings at
+/// the setting. An action that cannot run now says why and stays open.
+/// Every setting the palette finds by name is a row of its pane. It draws
+/// no view.
+#[test]
+#[ignore = "draws on a GPU; run with `just shots`"]
+fn the_palette_finds_and_runs_anything() {
+ let (_show, runtime, gpu) = lavapipe();
+ let _entered = runtime.enter();
+ let fixture = Path::new(env!("CARGO_MANIFEST_DIR"));
+ let mut show = std::fs::read_to_string(fixture.join("shots/show.toml")).unwrap();
+ // Failed in a build without `capture`, which leaves it a sound to mute.
+ show.push_str("\n[sources.mic]\nkind = \"microphone\"\n");
+ std::fs::write("show.toml", show).unwrap();
+ let app = start(launch(&gpu), stream(None), &runtime);
+ let (mut harness, started, _) = window(app, &gpu, &runtime, SIZE, library::Recent::default());
+ 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");
+ let program = || {
+ let state = engine.state.lock().unwrap();
+ state.compositor.program_scene().map(str::to_string)
+ };
+ let muted = |name: &str| {
+ let state = engine.state.lock().unwrap();
+ state.collection().audio.get(name).is_some_and(|audio| audio.muted)
+ };
+ let run = |harness: &mut Harness<'_, Window>, query: &str| {
+ harness.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::K);
+ harness.run_steps(2);
+ harness.get_by_role(Role::TextInput).type_text(query);
+ harness.run_steps(2);
+ harness.key_press(egui::Key::Enter);
+ harness.run_steps(2);
+ };
+ assert_eq!(program().as_deref(), Some("Main"));
+
+ run(&mut harness, "interview");
+ assert_eq!(program().as_deref(), Some("Interview"), "the palette took the scene");
+ assert!(harness.query_by_role(Role::TextInput).is_none(), "and closed");
+
+ // Typed and run in one frame, Enter runs what was typed.
+ harness.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::K);
+ harness.run_steps(2);
+ let enter = egui::Event::Key {
+ key: egui::Key::Enter,
+ physical_key: None,
+ pressed: true,
+ repeat: false,
+ modifiers: egui::Modifiers::NONE,
+ };
+ let events = &mut harness.input_mut().events;
+ events.extend([egui::Event::Text("take scene break".into()), enter]);
+ harness.run_steps(2);
+ assert_eq!(program().as_deref(), Some("Break"), "the palette ran what was typed");
+
+ assert!(!muted("mic"));
+ run(&mut harness, "mute mic");
+ assert!(muted("mic"), "the palette muted the sound");
+ run(&mut harness, "unmute mic");
+ assert!(!muted("mic"), "and unmuted it");
+
+ // TAKE with nothing cued says why, and Enter leaves it open.
+ run(&mut harness, "take the cued");
+ let take = harness.get_by_label("Take the cued scene");
+ assert!(take.accesskit_node().is_disabled(), "it cannot run");
+ assert_eq!(program().as_deref(), Some("Break"));
+ assert!(harness.query_by_role(Role::TextInput).is_some(), "still open");
+ harness.key_press(egui::Key::Escape);
+ harness.run_steps(2);
+ assert!(harness.query_by_role(Role::TextInput).is_none(), "Escape closes it");
+
+ // A setting under a disclosure opens it.
+ run(&mut harness, "scene sizes");
+ assert!(
+ harness.query_by_label("Give a scene its own size").is_some(),
+ "Scene sizes opened"
+ );
+ harness.key_press(egui::Key::Escape);
+ harness.run_steps(2);
+
+ run(&mut harness, "fps");
+ assert!(
+ harness.query_by_label("Frame rate").is_some(),
+ "Settings opened at the frame rate"
+ );
+ harness.key_press(egui::Key::Escape);
+ harness.run_steps(2);
+
+ // A key bound to a source with no sound, which the MIX lists no strip for,
+ // is still a sound of the show; only one the file lacks is no such sound.
+ {
+ let App::Studio(studio) = &mut harness.state_mut().app else {
+ unreachable!("the studio is open")
+ };
+ let key = |code, name: &str| hotkeys::Binding {
+ modifiers: egui::Modifiers::NONE,
+ key: winit::keyboard::PhysicalKey::Code(code),
+ name: winit::keyboard::Key::Character(name.into()),
+ };
+ use crate::controls::Action;
+ use winit::keyboard::KeyCode;
+ studio.bind(&Action::Mute("host".into()), key(KeyCode::F7, "F7"));
+ studio.bind(&Action::Mute("nope".into()), key(KeyCode::F8, "F8"));
+ studio.open(Setting::Hotkeys);
+ }
+ harness.run_steps(2);
+ assert!(
+ harness.query_by_label("host").is_some(),
+ "the silent source's key is listed"
+ );
+ assert_eq!(
+ harness.query_all_by_label("no such sound").count(),
+ 1,
+ "only the missing source is no such sound"
+ );
+
+ // Each setting the palette finds by name is a row of its pane.
+ for setting in Setting::ALL {
+ let App::Studio(studio) = &mut harness.state_mut().app else {
+ unreachable!("the studio is open")
+ };
+ studio.open(setting);
+ harness.run_steps(2);
+ for (name, _) in setting.rows() {
+ assert!(
+ harness.query_by_label(name).is_some(),
+ "{setting:?} has no row called `{name}`"
+ );
+ }
+ }
+
+ drop(harness);
+ quit(&engine, &runtime);
+}
+
/// Settings changes the show as a person would: a canvas size by name and
/// the format turn the program, keeping its frame rate. A show whose room
/// key is missing still opens, and once the key is back, Try again joins its
@@ -1467,6 +1619,18 @@ fn shoot(open: &Open, gpu: &engine::Gpu, runtime: &tokio::runtime::Runtime, show
}
}
View::Drop(_) => studio.build(Side::Add, Inspect::Layer, None),
+ View::Palette(_) => {
+ let key = |code, name: &str| hotkeys::Binding {
+ modifiers: egui::Modifiers::NONE,
+ key: winit::keyboard::PhysicalKey::Code(code),
+ name: winit::keyboard::Key::Character(name.into()),
+ };
+ use crate::controls::Action;
+ use winit::keyboard::KeyCode;
+ studio.bind(&Action::Panic, key(KeyCode::F9, "F9"));
+ studio.bind(&Action::Scene("Main".into()), key(KeyCode::F1, "F1"));
+ studio.bind(&Action::Cut, key(KeyCode::Numpad0, "0"));
+ }
View::Review { picked, .. } => {
studio.turn(Page::Review);
studio.seed_shelf(shelf());
@@ -1595,6 +1759,14 @@ fn shoot(open: &Open, gpu: &engine::Gpu, runtime: &tokio::runtime::Runtime, show
harness.run_steps(4);
}
View::Drop(drop) => drag(&mut harness, &engine, *drop),
+ View::Palette(query) => {
+ harness.key_press_modifiers(egui::Modifiers::COMMAND, egui::Key::K);
+ harness.run_steps(2);
+ if !query.is_empty() {
+ harness.get_by_role(Role::TextInput).type_text(query);
+ }
+ harness.run_steps(4);
+ }
View::History => {
harness
.get_all_by_label("Mute")
diff --git a/rs/moq-studio/src/ui.rs b/rs/moq-studio/src/ui.rs
index 98a23733..510c0fc8 100644
--- a/rs/moq-studio/src/ui.rs
+++ b/rs/moq-studio/src/ui.rs
@@ -17,7 +17,7 @@ use moq_scene::{
};
use winit::keyboard::{KeyCode, PhysicalKey};
-use crate::controls::{Action, Controls};
+use crate::controls::{Action, Controls, Group};
use crate::devices::{self, Listing, Pick};
use crate::engine::{Engine, Lost, State};
use crate::fx::{Fx, Mark};
@@ -41,6 +41,7 @@ mod levels;
mod live;
mod mixer;
mod multiview;
+mod palette;
mod review;
mod settings;
mod shell;
@@ -112,7 +113,7 @@ pub(crate) enum Setting {
}
impl Setting {
- const ALL: [Self; 6] = [
+ pub(crate) const ALL: [Self; 6] = [
Self::Show,
Self::Stream,
Self::Recording,
@@ -143,6 +144,57 @@ impl Setting {
}
}
+ /// Each setting in its pane by the name its row shows, which the palette
+ /// finds it by, with what else it answers to.
+ pub(crate) fn rows(self) -> &'static [(&'static str, &'static [&'static str])] {
+ match self {
+ Self::Show => &[
+ ("Format", &["portrait", "landscape", "vertical"]),
+ ("Canvas size", &["resolution", "1080p", "720p"]),
+ ("Frame rate", &["fps"]),
+ (settings::SCENE_SIZES, &[]),
+ ],
+ Self::Stream => &[
+ ("Relay", &["token", "server", "url"]),
+ ("Failover relay", &["backup"]),
+ ("Broadcast name", &["path"]),
+ ("Encode only while someone watches", &["on demand", "viewers"]),
+ ],
+ Self::Recording => &[
+ ("Each source too", &["iso", "separate", "files"]),
+ ("Picture", &["video"]),
+ ("Sound", &["audio"]),
+ ],
+ Self::Hotkeys => &[],
+ Self::Guests => &[
+ ("Room", &[]),
+ ("Room key", &[]),
+ ("Join page", &[]),
+ ("Link lifetime", &["expiry", "expires"]),
+ ("Appear on their own", &["tile"]),
+ ],
+ Self::Advanced => &[
+ ("Publish a scene as its own broadcast", &[]),
+ ("Publish a source independently", &[]),
+ ("Virtual camera", &["webcam", "video call"]),
+ ("Effects", &["animation", "glow", "motion"]),
+ ("Scene graph", &["wires", "nodes", "map"]),
+ ],
+ }
+ }
+
+ /// What else the palette finds the pane by, besides its name and lead.
+ fn words(self) -> &'static [&'static str] {
+ match self {
+ Self::Show => &["canvas"],
+ Self::Stream => &["relay", "token"],
+ Self::Recording => &["folder", "record"],
+ Self::Hotkeys => &["keys", "shortcuts", "bind"],
+ Self::Guests => &["invite", "join", "room"],
+ Self::Advanced => &["publish"],
+ }
+ }
+
/// The line under the pane's title.
fn lead(self) -> &'static str {
match self {
@@ -287,6 +339,7 @@ impl Studio {
multiview,
dropping: drop::Dropping::default(),
keyboard: None,
+ palette: None,
};
if dropped > 0 {
panels.report(Err(anyhow::anyhow!(dropped_message(dropped))));
@@ -409,6 +462,12 @@ impl Studio {
replay::Stretch::Between(now.saturating_sub(picked.0), now.saturating_sub(picked.1));
}
+ /// Bind `key` to `action`, as the Hotkeys pane would.
+ pub(crate) fn bind(&mut self, action: &Action, key: hotkeys::Binding) {
+ let hotkeys = self.panels.hotkeys.as_mut().expect("the window handed over its keys");
+ hotkeys.bind(action, Some(key)).expect("a key bound to nothing else");
+ }
+
/// 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);
@@ -540,6 +599,7 @@ impl Studio {
true => panels.multiview.ui(ui),
false => {
panels.window(ui, fx, &snapshot);
+ panels.palette(ui.ctx());
panels.drops_elsewhere(ui.ctx());
panels.multiview.show(ui.ctx());
}
@@ -728,6 +788,8 @@ struct Panels {
/// The keys the window hears before egui, which say when a paste was
/// pressed, once the window has handed them over.
keyboard: Option,
+ /// The command palette, while open.
+ palette: Option,
}
/// A layer, by the list it is in and its place there, back to front.
@@ -950,6 +1012,11 @@ fn dropped_message(dropped: usize) -> String {
impl Panels {
/// The keyboard shortcuts, and the clipboard.
fn shortcuts(&mut self, ctx: &egui::Context) {
+ // From anywhere, a text field included, and while the palette's own
+ // search box has the keyboard, where it closes it again.
+ if ctx.input_mut(|input| input.consume_shortcut(&palette::OPEN)) {
+ self.toggle_palette();
+ }
// egui pastes only text, so a paste it does not report may be a picture.
let pressed = self.keyboard.as_ref().is_some_and(hotkeys::Keyboard::pasted);
let text = ctx.input(|input| input.events.iter().any(|event| matches!(event, egui::Event::Paste(_))));
diff --git a/rs/moq-studio/src/ui/build.rs b/rs/moq-studio/src/ui/build.rs
index 7724d50c..0d99b295 100644
--- a/rs/moq-studio/src/ui/build.rs
+++ b/rs/moq-studio/src/ui/build.rs
@@ -195,7 +195,7 @@ impl Panels {
}
/// Stop passing input to a page, letting go of what it holds.
- fn stop_interacting(&mut self, state: &State) {
+ pub(super) fn stop_interacting(&mut self, state: &State) {
self.interacting = false;
self.rebind(&state.sources);
deliver(&state.sources, self.interact.release());
diff --git a/rs/moq-studio/src/ui/layers.rs b/rs/moq-studio/src/ui/layers.rs
index 2cdf91e3..078bf52b 100644
--- a/rs/moq-studio/src/ui/layers.rs
+++ b/rs/moq-studio/src/ui/layers.rs
@@ -707,7 +707,7 @@ impl Panels {
}
/// Follow an added source to its layer, or show why it was not added.
- fn added(&mut self, result: anyhow::Result) {
+ pub(super) fn added(&mut self, result: anyhow::Result) {
match result {
Ok(name) => {
let state = self.engine.state.lock().unwrap();
diff --git a/rs/moq-studio/src/ui/mixer.rs b/rs/moq-studio/src/ui/mixer.rs
index ae50e1cb..8062ba77 100644
--- a/rs/moq-studio/src/ui/mixer.rs
+++ b/rs/moq-studio/src/ui/mixer.rs
@@ -641,7 +641,9 @@ impl Panels {
(false, true) => (Icon::Mic, "Mute"),
(false, false) => (Icon::Sound, "Mute"),
};
+ let key = self.key(&Action::Mute(name.clone()), ui.ctx());
let button = IconButton::new(icon, verb)
+ .key(key.as_deref())
.look(kit::Look::Boxed)
.lit(muted, kit::CUE)
.width(parts.buttons.width());
diff --git a/rs/moq-studio/src/ui/palette.rs b/rs/moq-studio/src/ui/palette.rs
new file mode 100644
index 00000000..d2ce1b4c
--- /dev/null
+++ b/rs/moq-studio/src/ui/palette.rs
@@ -0,0 +1,609 @@
+//! The command palette: one key opens a search box that runs anything the
+//! studio can do. Its actions are the table in `controls`, each with its key
+//! and, when it cannot run now, why; beside them are the pages, the
+//! settings, and what can be added or selected, each found by its own name.
+
+use egui::{Align2, Rect, RichText, Sense, Stroke, pos2, vec2};
+
+use super::*;
+use crate::devices::Pick;
+
+/// The key that opens the palette, and closes it again.
+pub(super) const OPEN: egui::KeyboardShortcut = egui::KeyboardShortcut::new(egui::Modifiers::COMMAND, egui::Key::K);
+
+/// The palette's width, and the most of the window its list takes.
+const WIDTH: f32 = 600.0;
+const LIST: f32 = 420.0;
+
+/// The palette, while open: what is typed, and the row the arrows picked
+/// among those it finds.
+#[derive(Default)]
+pub(super) struct Palette {
+ query: String,
+ picked: usize,
+}
+
+/// What a row does.
+#[derive(Clone, Debug)]
+enum Command {
+ /// An action from the table, as its hotkey fires it.
+ Act(Action),
+ Page(Page),
+ /// Open Settings at a pane, at the row named, if any.
+ Setting(Setting, Option<&'static str>),
+ /// Select a layer on BUILD.
+ Layer(Picked),
+ /// Add a device the last listing found as a layer of the scene BUILD
+ /// edits.
+ Device(Pick),
+ /// List this machine's devices, which then show as rows of their own.
+ Devices,
+ /// Open BUILD's Add tab on a kind of source.
+ Kind(Kind),
+ Undo,
+ Redo,
+ Multiview,
+ Health,
+ Graph,
+}
+
+/// A row of the palette.
+struct Row {
+ command: Command,
+ name: String,
+ /// What it is for, shown beside it.
+ group: String,
+ /// What else finds it.
+ words: Vec<&'static str>,
+ /// The key bound to it.
+ key: Option,
+ /// Why it cannot run now.
+ refused: Option,
+}
+
+impl Row {
+ fn new(command: Command, name: impl Into, group: impl Into, words: &[&'static str]) -> Self {
+ Self {
+ command,
+ name: name.into(),
+ group: group.into(),
+ words: words.to_vec(),
+ key: None,
+ refused: None,
+ }
+ }
+
+ /// How well `query` finds it, or `None` if it does not.
+ fn score(&self, query: &str) -> Option {
+ let also = format!("{} {}", self.group, self.words.join(" "));
+ score(query, &self.name, &also)
+ }
+}
+
+/// How well `query` finds a row called `name` that also answers to `also`:
+/// each of its words must start a word there, or else appear inside one,
+/// and a word starting one of the name's counts most. `None` if a word is
+/// found nowhere.
+fn score(query: &str, name: &str, also: &str) -> Option {
+ let (name, also) = (name.to_lowercase(), also.to_lowercase());
+ let starts = |text: &str, term: &str| words(text).any(|word| word.starts_with(term));
+ let mut score = 0;
+ for term in words(&query.to_lowercase()) {
+ score += if starts(&name, term) {
+ 3
+ } else if starts(&also, term) {
+ 2
+ } else if name.contains(term) || also.contains(term) {
+ 1
+ } else {
+ return None;
+ };
+ }
+ Some(score)
+}
+
+/// The words of `text`, which punctuation and spaces split.
+fn words(text: &str) -> impl Iterator {
+ text.split(|c: char| !c.is_alphanumeric())
+ .filter(|word| !word.is_empty())
+}
+
+/// The rows `query` finds, best first, and in the order listed among equals.
+fn found(rows: Vec, query: &str) -> Vec {
+ let mut scored: Vec<(u32, Row)> = rows
+ .into_iter()
+ .filter_map(|row| row.score(query).map(|score| (score, row)))
+ .collect();
+ scored.sort_by_key(|(score, _)| std::cmp::Reverse(*score));
+ scored.into_iter().map(|(_, row)| row).collect()
+}
+
+impl Panels {
+ /// Open the palette, or close it if open.
+ pub(super) fn toggle_palette(&mut self) {
+ if self.palette.take().is_some() {
+ return;
+ }
+ // The search box takes the keyboard from a page the picture passed it
+ // to, which would type into both.
+ if self.interacting {
+ let engine = self.engine.clone();
+ self.stop_interacting(&engine.state.lock().unwrap());
+ }
+ self.palette = Some(Palette::default());
+ }
+
+ /// Everything the palette offers now, in the order it lists them before
+ /// anything is typed.
+ fn palette_rows(&self, ctx: &egui::Context) -> Vec {
+ let studio = self.controls.studio();
+ let bindings = self.hotkeys.as_ref().map(Hotkeys::bindings).unwrap_or_default();
+ let state = self.engine.state.lock().unwrap();
+ let collection = state.collection();
+ let mut rows = Vec::new();
+
+ for action in Action::listed(&state) {
+ let name = match &action {
+ Action::Mute(name) if collection.audio.get(name).is_some_and(|audio| audio.muted) => {
+ format!("Unmute `{name}`")
+ }
+ Action::Mute(name) => format!("Mute `{name}`"),
+ action => action.name(studio),
+ };
+ let mut row = Row::new(
+ Command::Act(action.clone()),
+ name,
+ action.group().name(),
+ action.words(),
+ );
+ row.key = bindings.get(&action).map(|bound| bound.shown(ctx));
+ row.refused = self.controls.refused(&state, &action);
+ rows.push(row);
+ }
+
+ // The layers BUILD edits, by the source each shows: off air, only the
+ // scene's own, as the always-on-top ones are drawn on program.
+ if let Ok(layer) = self.scene(&state) {
+ let off_air = self.off_air(&state).is_some();
+ let layers = [(!off_air).then(Layer::top), Some(layer)];
+ for top in layers.into_iter().flatten() {
+ let items = collection.items(&top).unwrap_or_default();
+ for (index, item) in items.iter().enumerate().rev() {
+ let picked = Picked {
+ layer: top.clone(),
+ index,
+ };
+ let group = match top.scene {
+ Some(_) => "Layers",
+ None => "Layers, always on top",
+ };
+ let name = format!("Select `{}`", item.source);
+ rows.push(Row::new(
+ Command::Layer(picked),
+ name,
+ group,
+ &["layer", "source", "inspect"],
+ ));
+ }
+ }
+ }
+
+ // What can be added: each device the last listing found, or else a
+ // listing, and each kind of source by hand.
+ let devices = &["device", "source", "layer"];
+ match &self.devices.listing {
+ Some(listing) => {
+ let kinds = [
+ ("Cameras", &listing.cameras),
+ ("Displays", &listing.displays),
+ ("Windows", &listing.windows),
+ ("Audio inputs", &listing.audio),
+ ];
+ // Never the studio's own virtual cameras, which would feed what
+ // one shows back into itself.
+ let own: Vec = state.cameras().map(|camera| camera.id).collect();
+ let own = |pick: &&Pick| matches!(&pick.source, Source::Camera { id: Some(id) } if own.contains(id));
+ for (kind, picks) in kinds {
+ for pick in picks.iter().flatten().filter(|pick| !own(pick)) {
+ let name = format!("Add `{}`", pick.name);
+ rows.push(Row::new(
+ Command::Device(pick.clone()),
+ name,
+ format!("Add, {kind}"),
+ devices,
+ ));
+ }
+ }
+ }
+ None => {
+ let mut row = Row::new(
+ Command::Devices,
+ "Find cameras, screens, windows, and inputs to add",
+ "Add",
+ &["device", "camera", "display", "screen", "window", "microphone", "list"],
+ );
+ if self.devices.pending.is_some() {
+ row.refused = Some("listing them now".into());
+ }
+ rows.push(row);
+ }
+ }
+ let picker =
+ |kind: &Kind| cfg!(target_os = "linux") || !matches!(kind, Kind::PickedDisplay | Kind::PickedWindow);
+ for kind in Kind::ALL.into_iter().filter(picker) {
+ let name = format!("Add a source: {}", kind.label());
+ rows.push(Row::new(Command::Kind(kind), name, "Add", &["new", "layer", "by hand"]));
+ }
+
+ for page in Page::ALL {
+ rows.push(Row::new(
+ Command::Page(page),
+ format!("Go to {}", page.name()),
+ "Pages",
+ &["page"],
+ ));
+ }
+ for setting in Setting::ALL {
+ let mut words = vec!["settings", "preferences"];
+ words.extend(setting.words());
+ let row = Row::new(Command::Setting(setting, None), setting.name(), "Settings", &words);
+ rows.push(row);
+ for (name, words) in setting.rows() {
+ let group = format!("Settings, {}", setting.name());
+ rows.push(Row::new(Command::Setting(setting, Some(name)), *name, group, words));
+ }
+ }
+
+ let history = state.history();
+ let position = history.position();
+ let undo = position.checked_sub(1).and_then(|at| history.entries().nth(at));
+ let redo = history.entries().nth(position);
+ for (command, entry, verb) in [(Command::Undo, undo, "Undo"), (Command::Redo, redo, "Redo")] {
+ let mut row = match entry {
+ Some(edit) => Row::new(command, format!("{verb}: {}", edit.label), "Edit", &["history"]),
+ None => Row::new(command, verb, "Edit", &["history"]),
+ };
+ row.refused = entry.is_none().then(|| format!("nothing to {}", verb.to_lowercase()));
+ rows.push(row);
+ }
+ let multiview = match self.multiview.open() {
+ true => "Close the multiview",
+ false => "Open the multiview",
+ };
+ rows.push(Row::new(
+ Command::Multiview,
+ multiview,
+ "Windows",
+ &["monitor", "tiles", "sources"],
+ ));
+ rows.push(Row::new(
+ Command::Health,
+ "Stream health in detail",
+ "Windows",
+ &["encoder", "viewers", "problems"],
+ ));
+ rows.push(Row::new(
+ Command::Graph,
+ "Open the scene graph",
+ "Windows",
+ &["wires", "nodes", "map"],
+ ));
+ rows
+ }
+
+ /// The palette, while open: the search box, and under it the rows it
+ /// finds, each with its key, and why it cannot run if it cannot. The
+ /// arrows pick a row, Enter or a click runs it, and Escape closes.
+ pub(super) fn palette(&mut self, ctx: &egui::Context) {
+ let Some(mut palette) = self.palette.take() else { return };
+ // A listing asked for from here arrives on any page.
+ self.devices.poll();
+ let all = self.palette_rows(ctx);
+ // Taken before the search box sees them, which would move its cursor
+ // or lose focus on them.
+ let (up, down, enter) = ctx.input_mut(|input| {
+ (
+ input.consume_key(egui::Modifiers::NONE, egui::Key::ArrowUp),
+ input.consume_key(egui::Modifiers::NONE, egui::Key::ArrowDown),
+ input.consume_key(egui::Modifiers::NONE, egui::Key::Enter),
+ )
+ });
+
+ let frame = egui::Frame::new()
+ .fill(kit::P1)
+ .stroke(Stroke::new(1.0, egui::Color32::from_rgb(0x3b, 0x3b, 0x4a)))
+ .corner_radius(14)
+ .shadow(egui::Shadow {
+ offset: [0, 24],
+ blur: 80,
+ spread: 0,
+ color: egui::Color32::BLACK,
+ });
+ let top = (ctx.content_rect().height() * 0.12).min(96.0);
+ let area = egui::Modal::default_area(egui::Id::new("palette")).anchor(Align2::CENTER_TOP, vec2(0.0, top));
+ let width = WIDTH.min(ctx.content_rect().width() - 24.0);
+ let modal = egui::Modal::new(egui::Id::new("palette"))
+ .area(area)
+ .frame(frame)
+ .backdrop_color(egui::Color32::from_rgba_unmultiplied(6, 6, 11, 0x99))
+ .show(ctx, |ui| {
+ ui.set_width(width);
+ ui.add_space(12.0);
+ ui.horizontal(|ui| {
+ ui.add_space(14.0);
+ ui.add(Icon::Search.image(18.0, kit::DIM));
+ let field = egui::TextEdit::singleline(&mut palette.query)
+ .hint_text("Run anything: a scene, a sound, an action, a setting")
+ .font(kit::ui(16.0))
+ .frame(egui::Frame::NONE)
+ .desired_width(ui.available_width() - 14.0);
+ let field = ui.add(field);
+ field.request_focus();
+ if field.changed() {
+ palette.picked = 0;
+ }
+ });
+ // Found from what the box holds after this frame's typing, so
+ // Enter pressed with it runs what was typed, not what was before.
+ let rows = found(all, &palette.query);
+ let last = rows.len().saturating_sub(1);
+ palette.picked = match (up, down) {
+ (true, false) => palette.picked.saturating_sub(1),
+ (false, true) => (palette.picked + 1).min(last),
+ _ => palette.picked.min(last),
+ };
+ let mut run = enter.then_some(palette.picked);
+ ui.add_space(10.0);
+ let y = ui.cursor().top();
+ ui.painter()
+ .hline(ui.max_rect().x_range(), y, Stroke::new(1.0, kit::LINE));
+ ui.add_space(6.0);
+ let height = LIST.min(ctx.content_rect().height() - top - 140.0).max(120.0);
+ egui::ScrollArea::vertical()
+ .max_height(height)
+ .auto_shrink([false, true])
+ .show(ui, |ui| {
+ if rows.is_empty() {
+ ui.add_space(10.0);
+ ui.vertical_centered(|ui| {
+ ui.label(RichText::new("Nothing found").font(kit::ui(13.0)).color(kit::DIM));
+ });
+ ui.add_space(10.0);
+ }
+ for (index, row) in rows.iter().enumerate() {
+ let response = row_ui(ui, row, index == palette.picked);
+ if (up || down) && index == palette.picked {
+ response.scroll_to_me(None);
+ }
+ if response.hovered() && ui.input(|input| input.pointer.delta() != egui::Vec2::ZERO) {
+ palette.picked = index;
+ }
+ if response.clicked() {
+ run = Some(index);
+ }
+ }
+ });
+ ui.add_space(6.0);
+ let hint = "↑ ↓ pick · Enter runs · Esc closes";
+ ui.horizontal(|ui| {
+ ui.add_space(14.0);
+ ui.label(RichText::new(hint).font(kit::ui(11.0)).color(kit::FAINT));
+ });
+ ui.add_space(8.0);
+ run.and_then(|index| rows.into_iter().nth(index))
+ });
+ let mut open = !modal.should_close();
+ if let Some(row) = modal.inner {
+ match &row.refused {
+ // Shown on its row already; the palette stays open on it.
+ Some(_) => {}
+ None => {
+ // A listing keeps the palette open, to show what it finds.
+ open = matches!(row.command, Command::Devices);
+ self.run(ctx, row.command);
+ }
+ }
+ }
+ if open {
+ self.palette = Some(palette);
+ }
+ }
+
+ /// Do what a row of the palette does. One that turns to a page or opens
+ /// a window closes Settings, which would hide it.
+ fn run(&mut self, ctx: &egui::Context, command: Command) {
+ if matches!(
+ command,
+ Command::Act(Action::GoLive)
+ | Command::Page(_)
+ | Command::Layer(_)
+ | Command::Device(_)
+ | Command::Kind(_)
+ | Command::Health
+ | Command::Graph
+ ) {
+ self.close_settings();
+ }
+ match command {
+ // The window's GO LIVE: the sheet, with its checks and relays.
+ Command::Act(Action::GoLive) => self.open_going(),
+ Command::Act(action) => self.controls.press(&action),
+ Command::Page(page) => self.page = page,
+ Command::Setting(setting, row) => {
+ self.setting = Some(setting);
+ if let Some(row) = row {
+ super::settings::seek(ctx, row);
+ }
+ }
+ Command::Layer(picked) => {
+ self.page = Page::Build;
+ self.side = Side::Layers;
+ self.select(Some(picked));
+ }
+ Command::Device(pick) => {
+ self.page = Page::Build;
+ let mut state = self.engine.state.lock().unwrap();
+ // Two cameras of the same model share a name; number the later ones.
+ let name = state.collection().unused_name(&pick.name);
+ let layer = self.scene(&state).ok();
+ let result = add(&mut state, layer, name, pick.source, None);
+ drop(state);
+ self.added(result);
+ if let Some(fault) = self.fault(&Spot::Add) {
+ let fault = fault.to_string();
+ self.say(Err(fault));
+ }
+ }
+ Command::Devices => {
+ let refreshed = self.devices.refresh(&self.runtime).context("cannot list devices");
+ self.check(refreshed);
+ }
+ Command::Kind(kind) => {
+ self.page = Page::Build;
+ self.side = Side::Add;
+ self.add.kind = kind;
+ }
+ Command::Undo => self.undo(),
+ Command::Redo => self.redo(),
+ Command::Multiview => self.multiview.set_open(!self.multiview.open()),
+ Command::Health => self.details = true,
+ Command::Graph => self.graph_open = true,
+ }
+ }
+}
+
+/// A row of the palette, lit while `picked`: its name, what it is for, and
+/// its key, with why it cannot run under it, if it cannot.
+fn row_ui(ui: &mut Ui, row: &Row, picked: bool) -> egui::Response {
+ let height = if row.refused.is_some() { 48.0 } else { 34.0 };
+ let width = ui.available_width();
+ let (rect, response) = ui.allocate_exact_size(vec2(width, height), Sense::click());
+ let enabled = row.refused.is_none();
+ response.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, enabled, &row.name));
+ if !ui.is_rect_visible(rect) {
+ return response;
+ }
+ let inner = rect.shrink2(vec2(8.0, 0.0));
+ if picked {
+ ui.painter().rect_filled(inner, 8, kit::P3);
+ }
+ let inner = inner.shrink2(vec2(10.0, 0.0));
+ let mut right = inner.right();
+ if let Some(key) = &row.key {
+ let cap = ui.painter().layout_no_wrap(key.clone(), kit::mono(10.0), kit::TEXT);
+ let size = cap.size() + vec2(10.0, 6.0);
+ let at = Rect::from_min_size(pos2(right - size.x, rect.top() + 17.0 - size.y / 2.0), size);
+ ui.painter().rect(
+ at,
+ 4,
+ egui::Color32::from_black_alpha(0x66),
+ Stroke::new(1.0, egui::Color32::from_white_alpha(0x22)),
+ egui::StrokeKind::Inside,
+ );
+ ui.painter().galley(at.center() - cap.size() / 2.0, cap, kit::TEXT);
+ right = at.left() - 10.0;
+ }
+ let group = ui
+ .painter()
+ .layout_no_wrap(row.group.clone(), kit::ui(11.5), kit::FAINT);
+ let group_at = pos2(right - group.size().x, rect.top() + 17.0 - group.size().y / 2.0);
+ right = group_at.x - 12.0;
+ ui.painter().galley(group_at, group, kit::FAINT);
+ let ink = if enabled { kit::TEXT } else { kit::DIM };
+ let name = ui.painter().layout(
+ row.name.clone(),
+ kit::ui_medium(13.5),
+ ink,
+ (right - inner.left()).max(40.0),
+ );
+ let rows = name.rows.len().max(1) as f32;
+ let name_at = pos2(inner.left(), rect.top() + 17.0 - name.size().y / rows / 2.0);
+ ui.painter()
+ .with_clip_rect(Rect::from_x_y_ranges(inner.left()..=right, rect.y_range()))
+ .galley(name_at, name, ink);
+ if let Some(why) = &row.refused {
+ let why = ui
+ .painter()
+ .layout_no_wrap(format!("Cannot now: {why}"), kit::ui(11.5), kit::CUE);
+ ui.painter()
+ .with_clip_rect(rect)
+ .galley(pos2(inner.left(), rect.top() + 30.0), why, kit::CUE);
+ }
+ response
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ fn names(rows: Vec, query: &str) -> Vec {
+ found(rows, query).into_iter().map(|row| row.name).collect()
+ }
+
+ fn rows() -> Vec {
+ let act = |action: Action| {
+ let name = action.name(false);
+ Row::new(
+ Command::Act(action.clone()),
+ name,
+ action.group().name(),
+ action.words(),
+ )
+ };
+ vec![
+ act(Action::GoLive),
+ act(Action::EndStream),
+ act(Action::Record),
+ act(Action::Scene("Gameplay".into())),
+ act(Action::Mute("desk mic".into())),
+ Row::new(
+ Command::Setting(Setting::Show, Some("Frame rate")),
+ "Frame rate",
+ "Settings, Show",
+ &["fps"],
+ ),
+ Row::new(
+ Command::Setting(Setting::Recording, None),
+ "Recording",
+ "Settings",
+ &["folder"],
+ ),
+ ]
+ }
+
+ /// Each word typed must be found, at the start of a word or inside one,
+ /// in the name, what it is for, or what else it answers to.
+ #[test]
+ fn every_word_typed_is_found() {
+ assert_eq!(names(rows(), "mute desk"), ["Mute or unmute `desk mic`"]);
+ assert_eq!(names(rows(), "fps"), ["Frame rate"]);
+ assert_eq!(names(rows(), "game"), ["Take scene `Gameplay`"]);
+ assert_eq!(names(rows(), "folder"), ["Recording"]);
+ assert!(names(rows(), "mute nobody").is_empty());
+ // Inside a word, as a last resort.
+ assert_eq!(names(rows(), "play"), ["Take scene `Gameplay`"]);
+ }
+
+ /// A word of the name beats what else a row answers to, which beats a
+ /// match inside a word; equals keep the order listed, actions first, as
+ /// does an empty query.
+ #[test]
+ fn the_name_ranks_first() {
+ assert_eq!(names(rows(), "rec"), ["Start or stop recording", "Recording"]);
+ assert_eq!(
+ names(rows(), "st"),
+ ["End stream", "Start or stop recording", "Go live"]
+ );
+ // The scene's name over its group's, which every scene shares.
+ assert_eq!(names(rows(), "scene"), ["Take scene `Gameplay`"]);
+ assert_eq!(names(rows(), "").len(), rows().len());
+ assert_eq!(names(rows(), " ")[0], "Go live");
+ }
+
+ /// Punctuation typed is no part of a word, as in `go-live`.
+ #[test]
+ fn punctuation_splits_words() {
+ assert_eq!(names(rows(), "go-live")[0], "Go live");
+ assert_eq!(names(rows(), "`gameplay`")[0], "Take scene `Gameplay`");
+ }
+}
diff --git a/rs/moq-studio/src/ui/settings.rs b/rs/moq-studio/src/ui/settings.rs
index 8048f512..546e1f8f 100644
--- a/rs/moq-studio/src/ui/settings.rs
+++ b/rs/moq-studio/src/ui/settings.rs
@@ -5,6 +5,7 @@
//! the show, this user's settings for what belongs to the operator, and
//! `.stream.toml` for where it streams and who joins it.
+use std::collections::HashSet;
use std::path::PathBuf;
use egui::{Align, Layout, Rect, RichText, Sense, Stroke, StrokeKind, Vec2, pos2, vec2};
@@ -198,6 +199,12 @@ impl Panels {
self.confirm_restart(ctx);
}
+ /// Close Settings, dropping a restart it was asking about.
+ pub(super) fn close_settings(&mut self) {
+ self.setting = None;
+ self.restart = None;
+ }
+
/// The categories, the one shown lit: by name, or by `icons` alone.
fn settings_nav(&mut self, ui: &mut Ui, rect: Rect, icons: bool, setting: &mut Setting) {
let painter = ui.painter();
@@ -408,9 +415,15 @@ impl Panels {
};
let mut action = None;
let id = ui.make_persistent_id("scene sizes");
- egui::collapsing_header::CollapsingState::load_with_default_open(ui.ctx(), id, false)
+ let top = ui.cursor().top();
+ let mut sizes = egui::collapsing_header::CollapsingState::load_with_default_open(ui.ctx(), id, false);
+ // Found by the palette, it opens to show what it holds.
+ if seeking(ui.ctx(), SCENE_SIZES) {
+ sizes.set_open(true);
+ }
+ sizes
.show_header(ui, |ui| {
- ui.label(RichText::new("Scene sizes").font(kit::ui_strong(13.5)).color(kit::TEXT));
+ ui.label(RichText::new(SCENE_SIZES).font(kit::ui_strong(13.5)).color(kit::TEXT));
ui.with_layout(Layout::right_to_left(Align::Center), |ui| {
ui.label(RichText::new(count).font(kit::ui(12.0)).color(kit::DIM));
});
@@ -472,6 +485,8 @@ impl Panels {
"A scene of another size cannot go on air. Publish it as its own broadcast instead, under Advanced.",
);
});
+ let rect = Rect::from_x_y_ranges(ui.max_rect().x_range(), top..=ui.cursor().top());
+ sought(ui, SCENE_SIZES, rect);
action
}
@@ -1098,29 +1113,29 @@ impl Panels {
});
});
});
- let scenes: Vec = {
+ // A source can be in the scene file yet unlisted, such as a clip with no
+ // audio, so a sound is gone only once the file lacks it, as firing it checks.
+ let (listed, sources): (Vec, HashSet) = {
let state = self.engine.state.lock().unwrap();
- state
- .collection()
- .scenes
- .iter()
- .map(|scene| scene.name.clone())
- .collect()
+ let sources = state.collection().sources.keys().cloned().collect();
+ (Action::listed(&state), sources)
};
let bindings = hotkeys.bindings();
- // A key bound to a scene the file no longer has, so it can be cleared.
- let gone: Vec = bindings
+ // A key bound to an action not listed, so it can still be seen and cleared.
+ let unlisted: Vec = bindings
.keys()
- .filter(|action| matches!(action, Action::Scene(name) if !scenes.contains(name)))
+ .filter(|action| !listed.contains(action))
.cloned()
.collect();
- let mut scene_actions: Vec = scenes.iter().cloned().map(Action::Scene).collect();
- scene_actions.extend(gone.iter().cloned());
- let mut groups: Vec<(&str, Vec)> = Action::FIXED
- .iter()
- .map(|(caption, actions)| (*caption, actions.to_vec()))
- .collect();
- groups.insert(2, ("Scenes", scene_actions));
+ let groups = Group::ALL.map(|group| {
+ let actions: Vec = listed
+ .iter()
+ .chain(&unlisted)
+ .filter(|action| action.group() == group)
+ .cloned()
+ .collect();
+ (group.name(), actions)
+ });
let mut bind = None;
let mut clear = None;
@@ -1139,15 +1154,13 @@ impl Panels {
for (column, actions) in columns.iter_mut().zip(actions.chunks(half)) {
for action in actions {
let name = match action {
- Action::Scene(name) => name.clone(),
+ Action::Scene(name) | Action::Mute(name) => name.clone(),
action => action.name(studio),
};
let detail = match action {
- Action::EndStream => Some("held"),
- Action::Panic => Some("safe scene, mics muted"),
- Action::Scene(_) if studio => Some("cues"),
- Action::Scene(name) if !scenes.contains(name) => Some("no such scene"),
- _ => None,
+ Action::Scene(_) if unlisted.contains(action) => Some("no such scene"),
+ Action::Mute(name) if !sources.contains(name) => Some("no such sound"),
+ action => action.detail(studio),
};
let refusal = self
.refusal
@@ -1416,6 +1429,7 @@ pub(super) fn field_row(ui: &mut Ui, name: &str, help: &str, flag: Option<&str>,
/// A row under a line: `name` and `help` in `share` of its width with
/// `control` beside them, or `control` under them in a pane too narrow.
fn labeled(ui: &mut Ui, name: &str, help: &str, share: f32, control: impl FnOnce(&mut Ui)) {
+ let top = ui.cursor().top();
rule(ui);
ui.add_space(14.0);
let width = ui.available_width();
@@ -1440,6 +1454,67 @@ fn labeled(ui: &mut Ui, name: &str, help: &str, share: f32, control: impl FnOnce
});
}
ui.add_space(14.0);
+ let rect = Rect::from_x_y_ranges(ui.max_rect().x_range(), top..=ui.cursor().top());
+ sought(ui, name, rect);
+}
+
+/// The setting the palette found, by its row's name, and when, which its
+/// pane scrolls to once and lights for a moment.
+#[derive(Clone)]
+struct Sought {
+ name: String,
+ since: f64,
+ scrolled: bool,
+}
+
+/// The Show pane's disclosure of each scene's own size, by its name.
+pub(super) const SCENE_SIZES: &str = "Scene sizes";
+
+/// Whether the palette found the setting called `name`, which its pane has
+/// yet to light.
+fn seeking(ctx: &egui::Context, name: &str) -> bool {
+ let sought = ctx.data(|data| data.get_temp::(egui::Id::new("sought setting")));
+ sought.is_some_and(|sought| sought.name == name)
+}
+
+/// How long a setting the palette found stays lit.
+const LIT: f64 = 1.5;
+
+/// Scroll Settings to the row called `name` and light it, as the palette
+/// does for a setting it found.
+pub(super) fn seek(ctx: &egui::Context, name: &str) {
+ let since = ctx.input(|input| input.time);
+ let sought = Sought {
+ name: name.to_string(),
+ since,
+ scrolled: false,
+ };
+ ctx.data_mut(|data| data.insert_temp(egui::Id::new("sought setting"), sought));
+}
+
+/// Scroll to the row called `name` at `rect` once, and light it a moment, if
+/// the palette found it.
+fn sought(ui: &mut Ui, name: &str, rect: Rect) {
+ let id = egui::Id::new("sought setting");
+ let Some(mut sought) = ui.ctx().data(|data| data.get_temp::(id)) else {
+ return;
+ };
+ if sought.name != name {
+ return;
+ }
+ if !std::mem::replace(&mut sought.scrolled, true) {
+ ui.scroll_to_rect(rect, Some(Align::Min));
+ }
+ let age = ui.input(|input| input.time) - sought.since;
+ if age > LIT {
+ ui.ctx().data_mut(|data| data.remove::(id));
+ return;
+ }
+ let alpha = (1.0 - age / LIT) as f32;
+ ui.painter()
+ .rect_filled(rect, 8, kit::ACCENT.gamma_multiply(0.12 * alpha));
+ ui.ctx().request_repaint();
+ ui.ctx().data_mut(|data| data.insert_temp(id, sought));
}
/// That `flag` sets a setting for this run, over the show's own.
diff --git a/rs/moq-studio/src/ui/shell.rs b/rs/moq-studio/src/ui/shell.rs
index 50433600..93f49681 100644
--- a/rs/moq-studio/src/ui/shell.rs
+++ b/rs/moq-studio/src/ui/shell.rs
@@ -349,6 +349,11 @@ impl Panels {
false => Some(Setting::default()),
};
}
+ let key = ui.ctx().format_shortcut(&super::palette::OPEN);
+ let search = IconButton::new(Icon::Search, "Search and run anything").key(Some(&key));
+ if ui.add(search).clicked() {
+ self.toggle_palette();
+ }
self.live_control(ui);
self.record_button(ui, fx);
self.health_dot(ui, fx, compact);