Merge the Stream Studio UI
The studio inside the main window (scenes, sources, preview with LIVE, timer and viewers, the audio mixer with meters and gains, stream chat, stream settings with a simulcast layer editor, Share Window/Screen, Record Clip, Go Live, End Stream), the same studio in its own window, and a phone layout. Also an engine fix: a camera's new background effect is applied instead of being kept from the old one. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
commit
ddc717a9f0
35 files changed
+6538
-20
No files matched your search
@@ -798,8 +798,10 @@ impl Studio {
|
||||
wanted.iter().any(|(w, kind, background)| {
|
||||
w == id
|
||||
&& input.kind().same_input(kind)
|
||||
// A background filter is set up when the input starts.
|
||||
&& input.background().needs_mask() == background.needs_mask()
|
||||
// A background filter is set up when the input starts,
|
||||
// with the effect it applies: another effect (or
|
||||
// strength, image, colour) needs a new input.
|
||||
&& input.background() == background
|
||||
})
|
||||
});
|
||||
}
|
||||
@@ -1196,6 +1198,25 @@ mod tests {
|
||||
assert!(studio.apply(Command::RenameScene { scene: 99, name: "x".into() }).await.is_err());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn a_new_background_effect_reaches_the_input() {
|
||||
let studio = Studio::start(one_colour_scene()).await.unwrap();
|
||||
for background in [
|
||||
Background::Blur { strength: 0.02 },
|
||||
Background::Blur { strength: 0.08 },
|
||||
Background::Colour { colour: Colour::rgb(0, 200, 0) },
|
||||
Background::Keep,
|
||||
] {
|
||||
let change =
|
||||
SourceChange { background: Some(background.clone()), ..Default::default() };
|
||||
let command = Command::UpdateSource { scene: 1, source: 1, change: Box::new(change) };
|
||||
studio.apply(command).await.unwrap();
|
||||
let graph = lock(&studio.graph);
|
||||
assert_eq!(graph.inputs.len(), 1);
|
||||
assert_eq!(graph.inputs[0].1.background(), &background);
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn go_live_and_recording_change_the_status() {
|
||||
let studio = Studio::start(one_colour_scene()).await.unwrap();
|
||||
|
||||
@@ -50,6 +50,7 @@ fn open_settings(dir: &Path, overrides: &[String]) -> Settings {
|
||||
for key in appearance_keys() {
|
||||
prefs.register(key);
|
||||
}
|
||||
prefs.register(&crate::studio::STUDIO_UI);
|
||||
let config = std::env::var_os("VOELIN_CONFIG")
|
||||
.map(PathBuf::from)
|
||||
.or_else(|| Some(dir.join("config.toml")).filter(|p| p.exists()));
|
||||
@@ -389,6 +390,8 @@ pub(crate) struct App {
|
||||
/// Files being uploaded to a channel from the composer: session,
|
||||
/// channel and name, so the link can be posted when they are up.
|
||||
pub uploads: HashMap<u64, (i64, u64, String)>,
|
||||
/// The Stream Studio (studio.rs).
|
||||
pub studio: crate::studio::StudioState,
|
||||
}
|
||||
|
||||
thread_local! {
|
||||
@@ -583,6 +586,7 @@ pub fn run(options: RunOptions) -> Result<()> {
|
||||
open_client_pending: switches.open_client,
|
||||
notices_loaded: false,
|
||||
uploads: HashMap::new(),
|
||||
studio: Default::default(),
|
||||
};
|
||||
APP.with(|a| *a.borrow_mut() = Some(app));
|
||||
crate::bind::wire(&ui);
|
||||
@@ -852,6 +856,13 @@ impl App {
|
||||
Event::SettingRejected { key, message } => {
|
||||
self.set_status(format!("Setting {key}: {message}"));
|
||||
}
|
||||
// The Stream Studio's stream (studio.rs).
|
||||
Event::StreamState { session, state } if self.studio_streams_to(session as i64) => {
|
||||
self.studio_stream_state(state);
|
||||
}
|
||||
Event::StreamViewers { session, viewers } if self.studio_streams_to(session as i64) => {
|
||||
self.studio_viewers(viewers);
|
||||
}
|
||||
event => self.stream_event(event),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,6 +37,7 @@ impl App {
|
||||
image_cache_mb: cache_mb as f32,
|
||||
});
|
||||
bridge.set_image_cache_usage(images::usage_text().into());
|
||||
self.studio_theme();
|
||||
}
|
||||
|
||||
/// The settings page changed the form: store the keys (they apply
|
||||
|
||||
@@ -6,8 +6,11 @@ mod emoji;
|
||||
mod servers;
|
||||
mod settings;
|
||||
mod streams;
|
||||
pub(crate) mod studio;
|
||||
|
||||
use crate::app::MainWindow;
|
||||
use slint::ComponentHandle;
|
||||
|
||||
use crate::app::{MainWindow, StudioBridge};
|
||||
|
||||
/// Connect every callback of the window.
|
||||
pub(crate) fn wire(ui: &MainWindow) {
|
||||
@@ -16,4 +19,5 @@ pub(crate) fn wire(ui: &MainWindow) {
|
||||
streams::wire(ui);
|
||||
settings::wire(ui);
|
||||
emoji::wire(ui);
|
||||
studio::wire(&ui.global::<StudioBridge>());
|
||||
}
|
||||
@@ -0,0 +1,137 @@
|
||||
//! The Stream Studio's callbacks, for the main window and for the studio's
|
||||
//! own window (each has its own StudioBridge global).
|
||||
|
||||
use voelin_core::studio::Command;
|
||||
|
||||
use crate::app::{StudioBridge, with_app};
|
||||
|
||||
/// Slint ids are ints; the studio's are u64.
|
||||
fn id(value: i32) -> u64 {
|
||||
u64::try_from(value).unwrap_or(u64::MAX)
|
||||
}
|
||||
|
||||
fn index(value: i32) -> usize {
|
||||
usize::try_from(value).unwrap_or(usize::MAX)
|
||||
}
|
||||
|
||||
pub(crate) fn wire(bridge: &StudioBridge) {
|
||||
// From a page's init: run it after the page is built, outside of Slint's
|
||||
// update.
|
||||
bridge.on_open(|| {
|
||||
let _ = slint::invoke_from_event_loop(|| {
|
||||
with_app(|app| app.studio_open());
|
||||
});
|
||||
});
|
||||
bridge.on_detach(|| {
|
||||
with_app(|app| app.studio_detach());
|
||||
});
|
||||
bridge.on_dock(|| {
|
||||
with_app(|app| app.studio_dock());
|
||||
});
|
||||
|
||||
bridge.on_select_scene(|scene| {
|
||||
with_app(|app| app.studio_scene_command(Command::SetActiveScene { scene: id(scene) }));
|
||||
});
|
||||
bridge.on_add_scene(|| {
|
||||
with_app(|app| app.studio_add_scene());
|
||||
});
|
||||
bridge.on_rename_scene(|scene, name| {
|
||||
let name = name.trim().to_owned();
|
||||
if !name.is_empty() {
|
||||
with_app(|app| {
|
||||
app.studio_scene_command(Command::RenameScene { scene: id(scene), name })
|
||||
});
|
||||
}
|
||||
});
|
||||
bridge.on_remove_scene(|scene| {
|
||||
with_app(|app| app.studio_scene_command(Command::RemoveScene { scene: id(scene) }));
|
||||
});
|
||||
|
||||
bridge.on_list_sources(|kind| with_app(|app| app.studio_list_sources(&kind)).unwrap_or(false));
|
||||
bridge.on_add_picked(|_, i| {
|
||||
with_app(|app| app.studio_add_picked(index(i)));
|
||||
});
|
||||
bridge.on_add_source(|form| {
|
||||
with_app(|app| app.studio_add_source(&form));
|
||||
});
|
||||
bridge.on_source_form(|source| {
|
||||
with_app(|app| app.studio_source_form(id(source))).unwrap_or_default()
|
||||
});
|
||||
bridge.on_apply_source(|form| {
|
||||
with_app(|app| app.studio_apply_source(&form));
|
||||
});
|
||||
bridge.on_toggle_source(|source| {
|
||||
with_app(|app| app.studio_toggle_source(id(source)));
|
||||
});
|
||||
bridge.on_source_action(|source, action| {
|
||||
with_app(|app| app.studio_source_action(id(source), &action));
|
||||
});
|
||||
bridge.on_main_source(|kind| {
|
||||
with_app(|app| app.studio_main_source(&kind));
|
||||
});
|
||||
|
||||
bridge.on_list_audio(|| {
|
||||
with_app(|app| app.studio_list_audio());
|
||||
});
|
||||
bridge.on_add_audio(|i| {
|
||||
with_app(|app| app.studio_add_audio(index(i)));
|
||||
});
|
||||
bridge.on_set_gain(|i, db, done| {
|
||||
with_app(|app| app.studio_set_gain(index(i), db, done));
|
||||
});
|
||||
bridge.on_toggle_mute(|i| {
|
||||
with_app(|app| app.studio_toggle_mute(index(i)));
|
||||
});
|
||||
bridge.on_remove_audio(|i| {
|
||||
with_app(|app| app.studio_remove_audio(index(i)));
|
||||
});
|
||||
|
||||
bridge.on_edit_form(|key, value| {
|
||||
with_app(|app| app.studio_edit(&key, &value));
|
||||
});
|
||||
bridge.on_set_output(|w, h, fps| {
|
||||
with_app(|app| app.studio_set_output(&w, &h, &fps));
|
||||
});
|
||||
bridge.on_set_layer(|i, layer| {
|
||||
with_app(|app| app.studio_set_layer(index(i), &layer));
|
||||
});
|
||||
bridge.on_add_layer(|| {
|
||||
with_app(|app| app.studio_add_layer());
|
||||
});
|
||||
bridge.on_remove_layer(|i| {
|
||||
with_app(|app| app.studio_remove_layer(index(i)));
|
||||
});
|
||||
bridge.on_advanced_settings(|| {
|
||||
with_app(|app| app.studio_advanced());
|
||||
});
|
||||
|
||||
bridge.on_save_clip(|| {
|
||||
with_app(|app| app.studio_save_clip());
|
||||
});
|
||||
bridge.on_toggle_recording(|| {
|
||||
with_app(|app| app.studio_toggle_recording());
|
||||
});
|
||||
bridge.on_open_recordings(|| {
|
||||
with_app(|app| app.studio_open_recordings());
|
||||
});
|
||||
bridge.on_go_live(|| {
|
||||
with_app(|app| app.studio_go_live());
|
||||
});
|
||||
bridge.on_end_stream(|| {
|
||||
with_app(|app| app.studio_end());
|
||||
});
|
||||
bridge.on_settings_form(|| with_app(|app| app.studio_settings_form()).unwrap_or_default());
|
||||
bridge.on_apply_settings(|form| {
|
||||
with_app(|app| app.studio_apply_settings(&form));
|
||||
});
|
||||
|
||||
bridge.on_respond_viewer(|client, accept| {
|
||||
with_app(|app| app.studio_respond_viewer(u16::try_from(client).unwrap_or(0), accept));
|
||||
});
|
||||
bridge.on_send_chat(|text| {
|
||||
with_app(|app| app.studio_send_chat(text.to_string()));
|
||||
});
|
||||
bridge.on_open_chat(|| {
|
||||
with_app(|app| app.studio_open_chat());
|
||||
});
|
||||
}
|
||||
@@ -170,6 +170,7 @@ impl App {
|
||||
if !shown {
|
||||
self.refresh_servers();
|
||||
}
|
||||
self.studio_chat_changed(id, &message.target);
|
||||
}
|
||||
|
||||
/// Messages the engine stored: added or updated by their local id.
|
||||
@@ -218,6 +219,7 @@ impl App {
|
||||
if fresh > 0 && !shown {
|
||||
self.refresh_servers();
|
||||
}
|
||||
self.studio_chat_changed(id, target);
|
||||
}
|
||||
|
||||
/// The page of messages before the oldest one shown.
|
||||
@@ -235,8 +237,14 @@ impl App {
|
||||
self.refresh_chat();
|
||||
}
|
||||
|
||||
/// The lines of a tab, grouped and with everything the row shows.
|
||||
fn lines_of(&self, view: &SessionView, tab: &Tab, messages: &[Msg]) -> Vec<ChatLine> {
|
||||
/// The lines of a tab, grouped and with everything the row shows (also
|
||||
/// the stream chat of the Stream Studio, studio.rs).
|
||||
pub(crate) fn lines_of(
|
||||
&self,
|
||||
view: &SessionView,
|
||||
tab: &Tab,
|
||||
messages: &[Msg],
|
||||
) -> Vec<ChatLine> {
|
||||
let gateway = view.gateway_has(feature::PINS)
|
||||
|| view.gateway_has(feature::REACTIONS)
|
||||
|| view.gateway_has(feature::TOPICS);
|
||||
|
||||
@@ -19,7 +19,13 @@
|
||||
//! `topic:<id>` (a topic's messages), `member` (the member card of the
|
||||
//! first other client), `watch` (the first stream; with sample data the
|
||||
//! local test pattern in its place), `popout` (the same, popped out),
|
||||
//! `tab:<home|servers|chat|activity|you>` (phone layout).
|
||||
//! `tab:<home|servers|chat|activity|you>` (phone layout),
|
||||
//! `studio[:<what>]`: the Stream Studio (with `VOELIN_DEMO_UI` a demo
|
||||
//! studio from synthetic sources), `studio:window` in a window of its own,
|
||||
//! `studio:live` going live, `studio:record`, or a dialog: `studio:source`,
|
||||
//! `studio:audio`, `studio:camera`, `studio:scene`, `studio:settings`.
|
||||
//! A screenshot also saves the studio's window (`<name>-window.png`) and
|
||||
//! draws it over the main window.
|
||||
//! - `VOELIN_AUTOWATCH=1`: watch the first stream that shows up.
|
||||
//! - `VOELIN_AUTOSHARE=test-pattern`: share the test pattern (accepting
|
||||
//! everyone) once connected to a TeamSpeak 6 server.
|
||||
@@ -28,7 +34,7 @@ use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
|
||||
use anyhow::Result;
|
||||
use slint::ComponentHandle;
|
||||
use slint::{ComponentHandle, Rgba8Pixel, SharedPixelBuffer};
|
||||
use voelin_core::gateway::Pin;
|
||||
use voelin_core::stream::{StreamInfo, StreamKind};
|
||||
use voelin_core::{
|
||||
@@ -170,6 +176,12 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
});
|
||||
ui.global::<Bridge>().set_viewer_popped(what == "popout");
|
||||
}
|
||||
"studio" => {
|
||||
if arg != "window" {
|
||||
nav.invoke_open_studio();
|
||||
}
|
||||
with_app(|app| app.studio_dev(arg));
|
||||
}
|
||||
// Opened once connected (settings_page.rs).
|
||||
"client" => {}
|
||||
other => eprintln!("VOELIN_OPEN: unknown screen {other:?}"),
|
||||
@@ -204,6 +216,8 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
eprintln!("screenshot failed: {e}");
|
||||
}
|
||||
let _ = ui.hide();
|
||||
// Also when the studio's own window is open.
|
||||
let _ = slint::quit_event_loop();
|
||||
}
|
||||
},
|
||||
);
|
||||
@@ -213,7 +227,33 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running {
|
||||
}
|
||||
|
||||
fn save_screenshot(ui: &MainWindow, path: &std::path::Path) -> Result<()> {
|
||||
let image = ui.window().take_snapshot()?;
|
||||
let mut image = ui.window().take_snapshot()?;
|
||||
if let Some(studio) = with_app(|app| app.studio_snapshot()).flatten() {
|
||||
let stem = path.file_stem().unwrap_or_default().to_string_lossy();
|
||||
save_png(&studio, &path.with_file_name(format!("{stem}-window.png")))?;
|
||||
paste(&mut image, &studio);
|
||||
}
|
||||
save_png(&image, path)
|
||||
}
|
||||
|
||||
/// Draw `top` over the bottom right of `image` with a border, as a second
|
||||
/// window sits on a desktop.
|
||||
fn paste(image: &mut SharedPixelBuffer<Rgba8Pixel>, top: &SharedPixelBuffer<Rgba8Pixel>) {
|
||||
let (w, h) = (image.width() as usize, image.height() as usize);
|
||||
let (tw, th) = (top.width() as usize, top.height() as usize);
|
||||
let (x0, y0) = (w.saturating_sub(tw + 24), h.saturating_sub(th + 24));
|
||||
let border = Rgba8Pixel { r: 0x3f, g: 0x7b, b: 0xff, a: 0xff };
|
||||
let pixels = image.make_mut_slice();
|
||||
for y in y0.saturating_sub(1)..(y0 + th + 1).min(h) {
|
||||
for x in x0.saturating_sub(1)..(x0 + tw + 1).min(w) {
|
||||
let (ty, tx) = (y.wrapping_sub(y0), x.wrapping_sub(x0));
|
||||
pixels[y * w + x] =
|
||||
if ty < th && tx < tw { top.as_slice()[ty * tw + tx] } else { border };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn save_png(image: &SharedPixelBuffer<Rgba8Pixel>, path: &std::path::Path) -> Result<()> {
|
||||
let file = std::io::BufWriter::new(std::fs::File::create(path)?);
|
||||
let mut encoder = png::Encoder::new(file, image.width(), image.height());
|
||||
encoder.set_color(png::ColorType::Rgba);
|
||||
|
||||
@@ -13,6 +13,7 @@ mod servers;
|
||||
mod settings;
|
||||
mod settings_page;
|
||||
mod streams;
|
||||
mod studio;
|
||||
mod video;
|
||||
mod vm;
|
||||
|
||||
|
||||
@@ -474,6 +474,11 @@ impl App {
|
||||
if self.share_busy || self.share.is_some() {
|
||||
return;
|
||||
}
|
||||
if self.studio_streams_to(session) {
|
||||
self.share_error = "The Stream Studio is live here: end that stream first.".into();
|
||||
self.refresh_streams();
|
||||
return;
|
||||
}
|
||||
// Typed values (no maximum), else the chosen presets.
|
||||
let choice = |i: i32, choices: &[u32]| {
|
||||
choices[usize::try_from(i).unwrap_or(0).min(choices.len() - 1)]
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -16,7 +16,8 @@ use voelin_core::media::{
|
||||
self, AudioSourceSpec, EncoderPreference, Latest, LocalPreview, Streamer, StreamerConfig,
|
||||
Viewer, peer_config, preferred_codec, stream_codec,
|
||||
};
|
||||
use voelin_core::stream::PeerConfig;
|
||||
use voelin_core::stream::{LayerSpec, PeerConfig};
|
||||
use voelin_core::studio::Studio;
|
||||
use voelin_core::{Engine, StreamSink};
|
||||
|
||||
/// Whether this build can share and decode video.
|
||||
@@ -272,6 +273,45 @@ impl Video {
|
||||
});
|
||||
}
|
||||
|
||||
/// The codecs, for reconfiguring a running streamer.
|
||||
pub fn codecs(&self) -> Arc<Codecs> {
|
||||
self.codecs.clone()
|
||||
}
|
||||
|
||||
/// Encode the Stream Studio's composite ([`Streamer::start_studio`]):
|
||||
/// from the start, so its recording and replay buffer work before it
|
||||
/// goes live, and a stream attaches to it like to a capture. `done` runs
|
||||
/// on the runtime.
|
||||
pub fn start_studio(
|
||||
&self,
|
||||
runtime: &Handle,
|
||||
studio: Arc<Studio>,
|
||||
options: CaptureRequest,
|
||||
layers: Vec<LayerSpec>,
|
||||
done: impl FnOnce(Result<Streamer, String>) + Send + 'static,
|
||||
) {
|
||||
let peer = self.peer_config(PeerConfig::default());
|
||||
let Some(codec) = stream_codec(&self.codecs, &peer) else {
|
||||
done(Err("No video encoder is available.".into()));
|
||||
return;
|
||||
};
|
||||
let codecs = self.codecs.clone();
|
||||
let config = StreamerConfig {
|
||||
fps: options.fps,
|
||||
bitrate_kbps: options.bitrate_kbps,
|
||||
codec,
|
||||
encoder: self.encoder.clone(),
|
||||
audio: options.audio,
|
||||
audio_sources: options.audio_sources,
|
||||
layers,
|
||||
..StreamerConfig::default()
|
||||
};
|
||||
runtime.spawn(async move {
|
||||
let result = Streamer::start_studio(&codecs, config, studio).await;
|
||||
done(result.map_err(|e| e.to_string()));
|
||||
});
|
||||
}
|
||||
|
||||
/// Decode stream `stream_id` of `session`; `wake` is called (on the
|
||||
/// decoder thread) when a picture is ready and none is waiting.
|
||||
pub fn watch(
|
||||
|
||||
@@ -7,4 +7,5 @@ pub mod avatar;
|
||||
pub mod chat;
|
||||
pub mod list;
|
||||
pub mod servers;
|
||||
pub mod studio;
|
||||
pub mod tree;
|
||||
@@ -0,0 +1,734 @@
|
||||
//! The Stream Studio's view models: scene, source, mixer and layer rows,
|
||||
//! the header's numbers, the source dialog's form, where new sources go and
|
||||
//! the overlay sources the stream settings' switches keep in the scenes.
|
||||
|
||||
use std::time::Duration;
|
||||
|
||||
use voelin_core::settings::{AudioSourceKindSetting, AudioSourceSetting, LayerSetting};
|
||||
use voelin_core::studio::SourceChange;
|
||||
use voelin_core::studio::SourceStats;
|
||||
use voelin_core::studio::scene::{
|
||||
Align, Background, Colour, Crop, Fit, Scene, Scenes, Source, SourceKind, Transform,
|
||||
};
|
||||
|
||||
use crate::app::{StudioAudio, StudioLayer, StudioScene, StudioSource, StudioSourceForm};
|
||||
|
||||
/// The scenes; the live one marked, each with what it shows.
|
||||
pub fn scenes(scenes: &Scenes) -> Vec<StudioScene> {
|
||||
let live = scenes.active().map(|s| s.id);
|
||||
scenes
|
||||
.scenes
|
||||
.iter()
|
||||
.map(|scene| StudioScene {
|
||||
id: scene.id as i32,
|
||||
name: scene.name.clone().into(),
|
||||
detail: summary(scene).into(),
|
||||
live: Some(scene.id) == live,
|
||||
kind: scene.sources.first().map_or("", |s| s.kind.label()).into(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// "Screen + Camera": the names of the visible sources, back first (the
|
||||
/// main picture, then what is over it).
|
||||
fn summary(scene: &Scene) -> String {
|
||||
let names: Vec<&str> = scene.sources.iter().filter(|s| s.visible).map(Source::label).collect();
|
||||
if names.is_empty() { "Empty".into() } else { names.join(" + ") }
|
||||
}
|
||||
|
||||
pub fn background_name(background: &Background) -> &'static str {
|
||||
match background {
|
||||
Background::Keep => "keep",
|
||||
Background::Blur { .. } => "blur",
|
||||
Background::Image { .. } => "image",
|
||||
Background::Colour { .. } => "colour",
|
||||
}
|
||||
}
|
||||
|
||||
/// The sources of `scene`, front first, with what the studio reports.
|
||||
pub fn sources(scene: Option<&Scene>, stats: &[SourceStats]) -> Vec<StudioSource> {
|
||||
let Some(scene) = scene else { return Vec::new() };
|
||||
let last = scene.sources.len().saturating_sub(1);
|
||||
scene
|
||||
.sources
|
||||
.iter()
|
||||
.enumerate()
|
||||
.rev()
|
||||
.map(|(i, s)| {
|
||||
let stat = stats.iter().find(|st| st.id == s.id);
|
||||
let info = stat
|
||||
.filter(|st| st.width > 0)
|
||||
.map(|st| format!("{}×{} · {:.0} fps", st.width, st.height, st.fps))
|
||||
.unwrap_or_default();
|
||||
StudioSource {
|
||||
id: s.id as i32,
|
||||
name: s.label().into(),
|
||||
kind: s.kind.label().into(),
|
||||
visible: s.visible,
|
||||
locked: s.locked,
|
||||
background: background_name(&s.background).into(),
|
||||
error: stat.and_then(|st| st.error.clone()).unwrap_or_default().into(),
|
||||
info: info.into(),
|
||||
front: i == last,
|
||||
back: i == 0,
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Linear gain as dB (silence: -60).
|
||||
pub fn gain_db(gain: f32) -> f32 {
|
||||
if gain > 0.001 { 20.0 * gain.log10() } else { -60.0 }
|
||||
}
|
||||
|
||||
/// dB as linear gain.
|
||||
pub fn gain_linear(db: f32) -> f32 {
|
||||
10f32.powf(db / 20.0)
|
||||
}
|
||||
|
||||
/// Name, detail and icon kind of an audio source.
|
||||
pub fn audio_label(kind: &AudioSourceKindSetting) -> (String, String, &'static str) {
|
||||
match kind {
|
||||
AudioSourceKindSetting::Microphone => ("Microphone".into(), String::new(), "microphone"),
|
||||
AudioSourceKindSetting::Desktop => {
|
||||
("Desktop Audio".into(), "without Voelin".into(), "desktop")
|
||||
}
|
||||
AudioSourceKindSetting::App { name: Some(name), .. } => {
|
||||
("App Audio".into(), name.clone(), "app")
|
||||
}
|
||||
AudioSourceKindSetting::App { pid, .. } => {
|
||||
("App Audio".into(), pid.map(|p| format!("process {p}")).unwrap_or_default(), "app")
|
||||
}
|
||||
AudioSourceKindSetting::Window => {
|
||||
("Window Audio".into(), "the shared window".into(), "window-audio")
|
||||
}
|
||||
AudioSourceKindSetting::Synthetic { frequency } => {
|
||||
("Test Tone".into(), format!("{frequency} Hz"), "tone")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// What the mixer says about one source now.
|
||||
#[derive(Clone, Debug, Default, PartialEq)]
|
||||
pub struct AudioLive {
|
||||
/// Peak in dBFS.
|
||||
pub level: f32,
|
||||
pub error: Option<String>,
|
||||
}
|
||||
|
||||
/// The mixer rows: the stream's audio sources with their meters.
|
||||
pub fn audio(sources: &[AudioSourceSetting], live: &[Option<AudioLive>]) -> Vec<StudioAudio> {
|
||||
sources
|
||||
.iter()
|
||||
.enumerate()
|
||||
.map(|(i, s)| {
|
||||
let (name, detail, kind) = audio_label(&s.kind);
|
||||
let live = live.get(i).cloned().flatten();
|
||||
StudioAudio {
|
||||
name: name.into(),
|
||||
detail: detail.into(),
|
||||
kind: kind.into(),
|
||||
gain_db: gain_db(s.gain),
|
||||
muted: s.muted,
|
||||
level: live.as_ref().map_or(-100.0, |l| l.level),
|
||||
error: live.and_then(|l| l.error).unwrap_or_default().into(),
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A number without trailing zeros ("0.5", "1").
|
||||
fn short(value: f32) -> String {
|
||||
let text = format!("{value:.3}");
|
||||
text.trim_end_matches('0').trim_end_matches('.').to_owned()
|
||||
}
|
||||
|
||||
/// The simulcast layers as rows (bitrates in kbit/s).
|
||||
pub fn layers(layers: &[LayerSetting]) -> Vec<StudioLayer> {
|
||||
layers
|
||||
.iter()
|
||||
.map(|l| StudioLayer {
|
||||
size: l.size.map(|(w, h)| format!("{w}x{h}")).unwrap_or_default().into(),
|
||||
scale: short(l.scale).into(),
|
||||
fps: l.max_fps.map(|f| f.to_string()).unwrap_or_default().into(),
|
||||
bitrate: (l.bitrate / 1000).to_string().into(),
|
||||
min_bitrate: (l.min_bitrate / 1000).to_string().into(),
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// A layer as typed into `old`: a size ("1280x720") or a scale ("0.5",
|
||||
/// "0.5×", "50%"), a frame-rate cap (empty: none), kbit/s. Any numbers.
|
||||
pub fn parse_layer(row: &StudioLayer, old: &LayerSetting) -> Result<LayerSetting, String> {
|
||||
let mut layer = old.clone();
|
||||
let size = row.size.trim();
|
||||
let parts: Vec<&str> = size.split(['x', 'X', '×']).map(str::trim).collect();
|
||||
match parts.as_slice() {
|
||||
[w, h] if !w.is_empty() && !h.is_empty() => {
|
||||
let (w, h) = (w.parse::<u32>(), h.parse::<u32>());
|
||||
let (Ok(w), Ok(h)) = (w, h) else { return Err(format!("{size:?} is not a size")) };
|
||||
layer.size = Some((w, h));
|
||||
}
|
||||
_ => {
|
||||
let text = size.trim_end_matches(['x', 'X', '×', '%']).trim();
|
||||
let mut scale: f32 = text.parse().map_err(|_| format!("{size:?} is not a size"))?;
|
||||
if size.ends_with('%') {
|
||||
scale /= 100.0;
|
||||
}
|
||||
layer.size = None;
|
||||
layer.scale = scale;
|
||||
}
|
||||
}
|
||||
let fps = row.fps.trim();
|
||||
layer.max_fps =
|
||||
if fps.is_empty() { None } else { Some(fps.parse().map_err(|_| "a frame rate")?) };
|
||||
let kbps: u64 = row.bitrate.trim().parse().map_err(|_| "kbit/s as a number")?;
|
||||
layer.bitrate = kbps * 1000;
|
||||
Ok(layer)
|
||||
}
|
||||
|
||||
/// A layer below the last one: half its size, a quarter of its bitrate.
|
||||
pub fn next_layer(layers: &[LayerSetting], bitrate_kbps: u32) -> LayerSetting {
|
||||
match layers.last() {
|
||||
None => LayerSetting { bitrate: u64::from(bitrate_kbps) * 1000, ..LayerSetting::default() },
|
||||
Some(last) => LayerSetting {
|
||||
id: None,
|
||||
scale: last.size.map_or(last.scale / 2.0, |_| 0.5),
|
||||
size: last.size.map(|(w, h)| (w / 2, h / 2)),
|
||||
bitrate: (last.bitrate / 4).max(100_000),
|
||||
rid: None,
|
||||
..last.clone()
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// 0: not live, 1 poor … 4 excellent; how the stream gets out. The worse
|
||||
/// of the frame rate made (against the output's) and the bandwidth the
|
||||
/// viewers have (their estimates against the bitrate sent).
|
||||
pub fn quality(
|
||||
live: bool,
|
||||
wanted_fps: u32,
|
||||
fps: f64,
|
||||
bandwidth: Option<f64>,
|
||||
) -> (i32, &'static str) {
|
||||
if !live {
|
||||
return (0, "Not live");
|
||||
}
|
||||
let rate = if wanted_fps == 0 { 1.0 } else { fps / f64::from(wanted_fps) };
|
||||
let worst = rate.min(bandwidth.unwrap_or(1.0));
|
||||
match worst {
|
||||
w if w >= 0.9 => (4, "Excellent Connection"),
|
||||
w if w >= 0.75 => (3, "Good Connection"),
|
||||
w if w >= 0.5 => (2, "Fair Connection"),
|
||||
_ => (1, "Poor Connection"),
|
||||
}
|
||||
}
|
||||
|
||||
/// 8250 → "8,250".
|
||||
pub fn thousands(n: u64) -> String {
|
||||
let digits = n.to_string();
|
||||
let mut out = String::new();
|
||||
for (i, c) in digits.chars().enumerate() {
|
||||
if i > 0 && (digits.len() - i).is_multiple_of(3) {
|
||||
out.push(',');
|
||||
}
|
||||
out.push(c);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// "1080p • 60 FPS • 8,250 kbps".
|
||||
pub fn format_line(height: u32, fps: u32, kbps: u64) -> String {
|
||||
format!("{height}p • {fps} FPS • {} kbps", thousands(kbps))
|
||||
}
|
||||
|
||||
/// "00:12:34".
|
||||
pub fn clock(d: Duration) -> String {
|
||||
let s = d.as_secs();
|
||||
format!("{:02}:{:02}:{:02}", s / 3600, s / 60 % 60, s % 60)
|
||||
}
|
||||
|
||||
/// "#rrggbb" or "#rrggbbaa" (the # optional).
|
||||
pub fn parse_colour(text: &str) -> Option<Colour> {
|
||||
let hex = text.trim().trim_start_matches('#');
|
||||
if !matches!(hex.len(), 6 | 8) || !hex.is_ascii() {
|
||||
return None;
|
||||
}
|
||||
let byte = |i: usize| u8::from_str_radix(&hex[i..i + 2], 16).ok();
|
||||
let a = if hex.len() == 8 { byte(6)? } else { 255 };
|
||||
Some(Colour::rgba(byte(0)?, byte(2)?, byte(4)?, a))
|
||||
}
|
||||
|
||||
pub fn colour_text(c: Colour) -> String {
|
||||
if c.a == 255 {
|
||||
format!("#{:02x}{:02x}{:02x}", c.r, c.g, c.b)
|
||||
} else {
|
||||
format!("#{:02x}{:02x}{:02x}{:02x}", c.r, c.g, c.b, c.a)
|
||||
}
|
||||
}
|
||||
|
||||
fn number(value: f32) -> String {
|
||||
short(value)
|
||||
}
|
||||
|
||||
/// The source dialog's form for `source`.
|
||||
pub fn form(source: &Source) -> StudioSourceForm {
|
||||
let t = &source.transform;
|
||||
let mut form = StudioSourceForm {
|
||||
id: source.id as i32,
|
||||
name: source.name.clone().into(),
|
||||
kind: source.kind.label().into(),
|
||||
x: number(t.x).into(),
|
||||
y: number(t.y).into(),
|
||||
width: t.width.map(number).unwrap_or_default().into(),
|
||||
height: t.height.map(number).unwrap_or_default().into(),
|
||||
scale: number(t.scale).into(),
|
||||
fit: match t.fit {
|
||||
Fit::Contain => "contain",
|
||||
Fit::Cover => "cover",
|
||||
Fit::Stretch => "stretch",
|
||||
}
|
||||
.into(),
|
||||
crop_left: source.crop.left.to_string().into(),
|
||||
crop_top: source.crop.top.to_string().into(),
|
||||
crop_right: source.crop.right.to_string().into(),
|
||||
crop_bottom: source.crop.bottom.to_string().into(),
|
||||
opacity: source.opacity * 100.0,
|
||||
locked: source.locked,
|
||||
visible: source.visible,
|
||||
background: background_name(&source.background).into(),
|
||||
blur: "4".into(),
|
||||
background_colour: "#00b140".into(),
|
||||
..StudioSourceForm::default()
|
||||
};
|
||||
match &source.background {
|
||||
Background::Blur { strength } => form.blur = number(strength * 100.0).into(),
|
||||
Background::Image { path } => form.background_path = path.display().to_string().into(),
|
||||
Background::Colour { colour } => form.background_colour = colour_text(*colour).into(),
|
||||
Background::Keep => {}
|
||||
}
|
||||
match &source.kind {
|
||||
SourceKind::Text { text, size_px, colour, .. } => {
|
||||
form.text = text.replace('\n', "\\n").into();
|
||||
form.text_size = number(*size_px).into();
|
||||
form.colour = colour_text(*colour).into();
|
||||
}
|
||||
SourceKind::Colour { colour, .. } => form.colour = colour_text(*colour).into(),
|
||||
SourceKind::Image { path } => form.path = path.display().to_string().into(),
|
||||
SourceKind::Camera { mirror, .. } => form.mirror = *mirror,
|
||||
_ => {}
|
||||
}
|
||||
form
|
||||
}
|
||||
|
||||
fn parse_f32(text: &str, what: &str) -> Result<f32, String> {
|
||||
text.trim()
|
||||
.parse::<f32>()
|
||||
.ok()
|
||||
.filter(|v| v.is_finite())
|
||||
.ok_or_else(|| format!("{what}: a number"))
|
||||
}
|
||||
|
||||
/// An optional size: empty is `None`.
|
||||
fn parse_size(text: &str, what: &str) -> Result<Option<f32>, String> {
|
||||
if text.trim().is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
let v = parse_f32(text, what)?;
|
||||
if v > 0.0 { Ok(Some(v)) } else { Err(format!("{what}: above 0")) }
|
||||
}
|
||||
|
||||
fn parse_crop(text: &str) -> Result<u32, String> {
|
||||
if text.trim().is_empty() {
|
||||
return Ok(0);
|
||||
}
|
||||
text.trim().parse().map_err(|_| "crop: whole pixels".to_owned())
|
||||
}
|
||||
|
||||
fn transform(form: &StudioSourceForm) -> Result<Transform, String> {
|
||||
let scale = if form.scale.trim().is_empty() { 1.0 } else { parse_f32(&form.scale, "scale")? };
|
||||
if scale <= 0.0 {
|
||||
return Err("scale: above 0".into());
|
||||
}
|
||||
Ok(Transform {
|
||||
x: parse_f32(&form.x, "X").unwrap_or(0.0),
|
||||
y: parse_f32(&form.y, "Y").unwrap_or(0.0),
|
||||
width: parse_size(&form.width, "width")?,
|
||||
height: parse_size(&form.height, "height")?,
|
||||
scale,
|
||||
fit: match form.fit.as_str() {
|
||||
"cover" => Fit::Cover,
|
||||
"stretch" => Fit::Stretch,
|
||||
_ => Fit::Contain,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
fn background(form: &StudioSourceForm) -> Result<Background, String> {
|
||||
Ok(match form.background.as_str() {
|
||||
"blur" => Background::Blur { strength: parse_f32(&form.blur, "blur")?.max(0.0) / 100.0 },
|
||||
"image" if !form.background_path.trim().is_empty() => {
|
||||
Background::Image { path: form.background_path.trim().into() }
|
||||
}
|
||||
"image" => return Err("background image: a file".into()),
|
||||
"colour" => Background::Colour {
|
||||
colour: parse_colour(&form.background_colour).ok_or("background colour: #rrggbb")?,
|
||||
},
|
||||
_ => Background::Keep,
|
||||
})
|
||||
}
|
||||
|
||||
/// What `form` changes in `old` (only what differs).
|
||||
pub fn change(form: &StudioSourceForm, old: &Source) -> Result<SourceChange, String> {
|
||||
let transform = transform(form)?;
|
||||
let crop = Crop {
|
||||
left: parse_crop(&form.crop_left)?,
|
||||
top: parse_crop(&form.crop_top)?,
|
||||
right: parse_crop(&form.crop_right)?,
|
||||
bottom: parse_crop(&form.crop_bottom)?,
|
||||
};
|
||||
let kind = kind(form, Some(&old.kind))?;
|
||||
let background = background(form)?;
|
||||
let opacity = (form.opacity / 100.0).clamp(0.0, 1.0);
|
||||
let differs = |a: bool| a.then_some(());
|
||||
Ok(SourceChange {
|
||||
name: differs(form.name.as_str() != old.name).map(|_| form.name.to_string()),
|
||||
kind: differs(kind != old.kind).map(|_| kind),
|
||||
transform: differs(transform != old.transform).map(|_| transform),
|
||||
crop: differs(crop != old.crop).map(|_| crop),
|
||||
opacity: differs((opacity - old.opacity).abs() > f32::EPSILON).map(|_| opacity),
|
||||
visible: differs(form.visible != old.visible).map(|_| form.visible),
|
||||
locked: differs(form.locked != old.locked).map(|_| form.locked),
|
||||
background: differs(background != old.background).map(|_| background),
|
||||
})
|
||||
}
|
||||
|
||||
/// The kind as the form says: text, colour and image from their fields, a
|
||||
/// camera's mirroring, anything else as it was.
|
||||
fn kind(form: &StudioSourceForm, old: Option<&SourceKind>) -> Result<SourceKind, String> {
|
||||
Ok(match (form.kind.as_str(), old) {
|
||||
("text", old) => {
|
||||
let (font, backdrop, align, padding) = match old {
|
||||
Some(SourceKind::Text { font, backdrop, align, padding, .. }) => {
|
||||
(font.clone(), *backdrop, *align, *padding)
|
||||
}
|
||||
_ => (None, Colour::CLEAR, Align::Left, 0),
|
||||
};
|
||||
let size_px = parse_f32(&form.text_size, "text size")?;
|
||||
if size_px <= 0.0 {
|
||||
return Err("text size: above 0".into());
|
||||
}
|
||||
SourceKind::Text {
|
||||
text: form.text.replace("\\n", "\n"),
|
||||
font,
|
||||
size_px,
|
||||
colour: parse_colour(&form.colour).ok_or("colour: #rrggbb")?,
|
||||
backdrop,
|
||||
align,
|
||||
padding,
|
||||
}
|
||||
}
|
||||
("colour", old) => SourceKind::Colour {
|
||||
colour: parse_colour(&form.colour).ok_or("colour: #rrggbb")?,
|
||||
size: match old {
|
||||
Some(SourceKind::Colour { size, .. }) => *size,
|
||||
_ => (1920, 1080),
|
||||
},
|
||||
},
|
||||
("image", _) if form.path.trim().is_empty() => return Err("image: a file".into()),
|
||||
("image", _) => SourceKind::Image { path: form.path.trim().into() },
|
||||
(_, Some(SourceKind::Camera { device, size, fps, .. })) => SourceKind::Camera {
|
||||
device: device.clone(),
|
||||
size: *size,
|
||||
fps: *fps,
|
||||
mirror: form.mirror,
|
||||
},
|
||||
(_, Some(old)) => old.clone(),
|
||||
(other, None) => return Err(format!("cannot add a {other} source here")),
|
||||
})
|
||||
}
|
||||
|
||||
/// A new text, colour or image source from the dialog (id 0: the
|
||||
/// controller gives it one).
|
||||
pub fn new_source(form: &StudioSourceForm, output: (u32, u32)) -> Result<Source, String> {
|
||||
let kind = kind(form, None)?;
|
||||
let mut source = Source::new(0, kind);
|
||||
source.name = form.name.trim().to_owned();
|
||||
source.transform = if form.kind == "colour" {
|
||||
Transform::full(output.0, output.1)
|
||||
} else {
|
||||
let mut t = placement(&source.kind, output);
|
||||
if let Ok(x) = parse_f32(&form.x, "X") {
|
||||
t.x = x;
|
||||
}
|
||||
if let Ok(y) = parse_f32(&form.y, "Y") {
|
||||
t.y = y;
|
||||
}
|
||||
t
|
||||
};
|
||||
source.opacity = (form.opacity / 100.0).clamp(0.0, 1.0);
|
||||
Ok(source)
|
||||
}
|
||||
|
||||
/// Where a new source goes in a `w` x `h` picture: captures fill it
|
||||
/// (cropping what does not fit), a camera sits in the bottom right corner,
|
||||
/// text at the bottom left, images at their own size in the top left.
|
||||
pub fn placement(kind: &SourceKind, (w, h): (u32, u32)) -> Transform {
|
||||
let (w, h) = (w as f32, h as f32);
|
||||
match kind {
|
||||
SourceKind::Camera { .. } => {
|
||||
let width = (w * 0.25).round();
|
||||
let height = (width * 9.0 / 16.0).round();
|
||||
let margin = (h * 0.03).round();
|
||||
Transform {
|
||||
fit: Fit::Cover,
|
||||
..Transform::box_at(w - width - margin, h - height - margin, width, height)
|
||||
}
|
||||
}
|
||||
SourceKind::Text { .. } => {
|
||||
Transform { x: (w * 0.03).round(), y: (h * 0.8).round(), ..Transform::default() }
|
||||
}
|
||||
SourceKind::Image { .. } => Transform::default(),
|
||||
_ => Transform { fit: Fit::Cover, ..Transform::box_at(0.0, 0.0, w, h) },
|
||||
}
|
||||
}
|
||||
|
||||
/// A source the stream settings' switches keep: its name, and its text
|
||||
/// (`None`: switched off, so it is removed).
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct Overlay {
|
||||
pub name: &'static str,
|
||||
pub text: Option<String>,
|
||||
}
|
||||
|
||||
pub const OVERLAY_VIEWERS: &str = "Viewer count";
|
||||
pub const OVERLAY_CHAT: &str = "Chat overlay";
|
||||
pub const OVERLAY_NOW_PLAYING: &str = "Now playing";
|
||||
|
||||
fn overlay_kind(name: &str, text: &str) -> SourceKind {
|
||||
SourceKind::Text {
|
||||
text: text.to_owned(),
|
||||
font: None,
|
||||
size_px: if name == OVERLAY_CHAT { 26.0 } else { 34.0 },
|
||||
colour: Colour::WHITE,
|
||||
backdrop: Colour::rgba(6, 10, 24, 170),
|
||||
align: Align::Left,
|
||||
padding: 14,
|
||||
}
|
||||
}
|
||||
|
||||
/// Where an overlay starts (people can move it): the viewer count at the
|
||||
/// top right (by an estimate of its width), the chat at the left, what is
|
||||
/// on above the bottom left. Clear of the corners the studio's own badges
|
||||
/// cover in the preview.
|
||||
fn overlay_place(name: &str, text: &str, (w, h): (u32, u32)) -> Transform {
|
||||
let (w, h) = (w as f32, h as f32);
|
||||
let margin = (w * 0.025).round();
|
||||
let (x, y) = match name {
|
||||
OVERLAY_VIEWERS => {
|
||||
let wide = text.chars().count() as f32 * 34.0 * 0.58 + 28.0;
|
||||
(w - margin - wide, h * 0.14)
|
||||
}
|
||||
OVERLAY_CHAT => (margin, h * 0.3),
|
||||
_ => (margin, h * 0.7),
|
||||
};
|
||||
Transform { x: x.max(0.0).round(), y: y.round(), ..Transform::default() }
|
||||
}
|
||||
|
||||
/// Make the scenes hold `wanted`: an overlay that is on is added to the live
|
||||
/// scene if it has none, and its text follows in every scene; one that is
|
||||
/// off is removed everywhere. Overlays are found by their names, so a
|
||||
/// person can move them like any source. Returns whether anything changed.
|
||||
pub fn apply_overlays(scenes: &mut Scenes, wanted: &[Overlay]) -> bool {
|
||||
let size = scenes.size();
|
||||
let live = scenes.active().map(|s| s.id);
|
||||
let mut changed = false;
|
||||
for overlay in wanted {
|
||||
match &overlay.text {
|
||||
None => {
|
||||
for scene in &mut scenes.scenes {
|
||||
let before = scene.sources.len();
|
||||
scene.sources.retain(|s| s.name != overlay.name);
|
||||
changed |= scene.sources.len() != before;
|
||||
}
|
||||
}
|
||||
Some(text) => {
|
||||
for scene in &mut scenes.scenes {
|
||||
for source in scene.sources.iter_mut().filter(|s| s.name == overlay.name) {
|
||||
if let SourceKind::Text { text: shown, .. } = &mut source.kind
|
||||
&& shown != text
|
||||
{
|
||||
shown.clone_from(text);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
let Some(scene) = live.and_then(|id| scenes.scene_mut(id)) else { continue };
|
||||
if !scene.sources.iter().any(|s| s.name == overlay.name) {
|
||||
let id = scene.next_source_id();
|
||||
scene.sources.push(Source {
|
||||
name: overlay.name.into(),
|
||||
transform: overlay_place(overlay.name, text, size),
|
||||
..Source::new(id, overlay_kind(overlay.name, text))
|
||||
});
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
changed
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
fn scene_with(names: &[&str]) -> Scenes {
|
||||
let mut scene = Scene::new(1, "Main");
|
||||
for (i, name) in names.iter().enumerate() {
|
||||
let kind = SourceKind::Colour { colour: Colour::BLACK, size: (16, 16) };
|
||||
scene.sources.push(Source { name: (*name).into(), ..Source::new(i as u64 + 1, kind) });
|
||||
}
|
||||
Scenes { scenes: vec![scene, Scene::new(2, "Break")], active: 1, ..Scenes::default() }
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn rows_show_scenes_and_sources_front_first() {
|
||||
let scenes = scene_with(&["Screen", "Camera"]);
|
||||
let rows = super::scenes(&scenes);
|
||||
assert_eq!(rows.len(), 2);
|
||||
assert!(rows[0].live && !rows[1].live);
|
||||
assert_eq!(rows[0].detail, "Screen + Camera");
|
||||
assert_eq!(rows[1].detail, "Empty");
|
||||
let sources = super::sources(scenes.active(), &[]);
|
||||
assert_eq!(
|
||||
sources.iter().map(|s| s.name.as_str()).collect::<Vec<_>>(),
|
||||
["Camera", "Screen"]
|
||||
);
|
||||
assert!(sources[0].front && !sources[0].back && sources[1].back);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn numbers_for_the_header() {
|
||||
assert_eq!(thousands(8250), "8,250");
|
||||
assert_eq!(thousands(1_234_567), "1,234,567");
|
||||
assert_eq!(thousands(999), "999");
|
||||
assert_eq!(format_line(1080, 60, 8250), "1080p • 60 FPS • 8,250 kbps");
|
||||
assert_eq!(clock(Duration::from_secs(12 * 60 + 34)), "00:12:34");
|
||||
assert_eq!(clock(Duration::from_secs(3 * 3600 + 5)), "03:00:05");
|
||||
assert_eq!(quality(false, 60, 60.0, None).0, 0);
|
||||
assert_eq!(quality(true, 60, 59.0, None).0, 4);
|
||||
assert_eq!(quality(true, 60, 59.0, Some(0.6)).0, 2);
|
||||
assert_eq!(quality(true, 60, 20.0, Some(1.0)).0, 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn gains_and_colours_round_trip() {
|
||||
assert!((gain_db(1.0)).abs() < 1e-6);
|
||||
assert!((gain_db(gain_linear(-6.0)) + 6.0).abs() < 1e-4);
|
||||
assert_eq!(gain_db(0.0), -60.0);
|
||||
let c = parse_colour("#ff8000").unwrap();
|
||||
assert_eq!(c, Colour::rgb(255, 128, 0));
|
||||
assert_eq!(colour_text(c), "#ff8000");
|
||||
assert_eq!(parse_colour("10203040"), Some(Colour::rgba(16, 32, 48, 64)));
|
||||
assert_eq!(parse_colour("#ff80"), None);
|
||||
assert_eq!(parse_colour("#gg0000"), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn layers_as_typed() {
|
||||
let old = LayerSetting::default();
|
||||
let row = |size: &str, fps: &str, kbps: &str| StudioLayer {
|
||||
size: size.into(),
|
||||
fps: fps.into(),
|
||||
bitrate: kbps.into(),
|
||||
..StudioLayer::default()
|
||||
};
|
||||
let l = parse_layer(&row("1280x720", "30", "2500"), &old).unwrap();
|
||||
assert_eq!((l.size, l.max_fps, l.bitrate), (Some((1280, 720)), Some(30), 2_500_000));
|
||||
let l = parse_layer(&row("0.5×", "", "800"), &old).unwrap();
|
||||
assert_eq!((l.size, l.scale, l.max_fps), (None, 0.5, None));
|
||||
assert_eq!(parse_layer(&row("50%", "", "800"), &old).unwrap().scale, 0.5);
|
||||
assert!(parse_layer(&row("big", "", "800"), &old).is_err());
|
||||
assert!(parse_layer(&row("1", "", "fast"), &old).is_err());
|
||||
let rows = layers(&[l]);
|
||||
assert_eq!((rows[0].scale.as_str(), rows[0].bitrate.as_str()), ("0.5", "800"));
|
||||
let below = next_layer(&[LayerSetting { bitrate: 8_000_000, ..old.clone() }], 8000);
|
||||
assert_eq!((below.scale, below.bitrate), (0.5, 2_000_000));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_source_form_changes_only_what_differs() {
|
||||
let mut source = Source::new(
|
||||
3,
|
||||
SourceKind::Text {
|
||||
text: "Hello\nthere".into(),
|
||||
font: None,
|
||||
size_px: 48.0,
|
||||
colour: Colour::WHITE,
|
||||
backdrop: Colour::CLEAR,
|
||||
align: Align::Center,
|
||||
padding: 4,
|
||||
},
|
||||
);
|
||||
source.transform = Transform::box_at(10.0, 20.0, 300.0, 100.0);
|
||||
let mut f = form(&source);
|
||||
assert_eq!(f.text, "Hello\\nthere");
|
||||
assert_eq!((f.x.as_str(), f.width.as_str()), ("10", "300"));
|
||||
assert_eq!(change(&f, &source).unwrap(), SourceChange::default());
|
||||
f.x = "40".into();
|
||||
f.opacity = 50.0;
|
||||
f.text = "Bye".into();
|
||||
let c = change(&f, &source).unwrap();
|
||||
assert_eq!(c.transform.unwrap().x, 40.0);
|
||||
assert_eq!(c.opacity, Some(0.5));
|
||||
let Some(SourceKind::Text { text, align, padding, .. }) = c.kind else { panic!() };
|
||||
assert_eq!((text.as_str(), align, padding), ("Bye", Align::Center, 4));
|
||||
f.width = "-1".into();
|
||||
assert!(change(&f, &source).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn new_sources_are_placed_by_kind() {
|
||||
let camera =
|
||||
SourceKind::Camera { device: String::new(), size: None, fps: None, mirror: false };
|
||||
let t = placement(&camera, (1920, 1080));
|
||||
assert_eq!((t.width, t.height, t.fit), (Some(480.0), Some(270.0), Fit::Cover));
|
||||
assert!(t.x + 480.0 < 1920.0 && t.y + 270.0 < 1080.0);
|
||||
let screen = SourceKind::Screen { monitor: 0, backend: None, cursor: true };
|
||||
assert_eq!(placement(&screen, (1920, 1080)).width, Some(1920.0));
|
||||
let form = StudioSourceForm {
|
||||
kind: "colour".into(),
|
||||
name: "Slate".into(),
|
||||
colour: "#101a3c".into(),
|
||||
opacity: 100.0,
|
||||
..Default::default()
|
||||
};
|
||||
let s = new_source(&form, (1280, 720)).unwrap();
|
||||
assert_eq!((s.name.as_str(), s.transform.width), ("Slate", Some(1280.0)));
|
||||
assert!(new_source(&StudioSourceForm { kind: "image".into(), ..form }, (1, 1)).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn overlays_follow_the_switches() {
|
||||
let mut scenes = scene_with(&["Screen"]);
|
||||
let on = |text: &str| Overlay { name: OVERLAY_VIEWERS, text: Some(text.into()) };
|
||||
assert!(apply_overlays(&mut scenes, &[on("3 watching")]));
|
||||
let live = &scenes.scenes[0];
|
||||
assert_eq!(live.sources.len(), 2);
|
||||
assert_eq!(live.sources[1].name, OVERLAY_VIEWERS);
|
||||
// Nothing to do the second time; the text follows.
|
||||
assert!(!apply_overlays(&mut scenes, &[on("3 watching")]));
|
||||
assert!(apply_overlays(&mut scenes, &[on("4 watching")]));
|
||||
let SourceKind::Text { text, .. } = &scenes.scenes[0].sources[1].kind else { panic!() };
|
||||
assert_eq!(text, "4 watching");
|
||||
// A scene switch adds it to the new live scene too; off removes all.
|
||||
scenes.active = 2;
|
||||
assert!(apply_overlays(&mut scenes, &[on("4 watching")]));
|
||||
assert_eq!(scenes.scenes[1].sources.len(), 1);
|
||||
assert!(apply_overlays(&mut scenes, &[Overlay { name: OVERLAY_VIEWERS, text: None }]));
|
||||
assert_eq!(scenes.scenes[0].sources.len(), 1);
|
||||
assert!(scenes.scenes[1].sources.is_empty());
|
||||
assert!(scenes.check().is_ok());
|
||||
}
|
||||
}
|
||||
@@ -27,11 +27,16 @@ import { SettingsNav, SettingsPage } from "screens/settings.slint";
|
||||
import { HomeNav, HomePage } from "screens/home.slint";
|
||||
import { MobileServers, ActivityPage, YouPage } from "screens/mobile.slint";
|
||||
import { BookmarkDialog, ShareDialog, ClientAudioDialog, AboutDialog } from "screens/dialogs.slint";
|
||||
import { StudioBridge } from "studio-bridge.slint";
|
||||
import { StudioPage, MobileStudio } from "screens/studio.slint";
|
||||
|
||||
// Rust reaches the globals and structs through this file.
|
||||
export * from "bridge.slint";
|
||||
export { Theme } from "theme.slint";
|
||||
export { Nav, Page, MobileTab, SettingsSection } from "nav.slint";
|
||||
// The Stream Studio: its data, and its own window (src/studio.rs).
|
||||
export { StudioBridge, StudioNav, StudioScene, StudioSource, StudioAudio, StudioLayer, StudioViewer, StudioPick, StudioStatus, StudioForm, StudioSourceForm, StudioSettingsForm } from "studio-bridge.slint";
|
||||
export { StudioWindow } from "studio-window.slint";
|
||||
|
||||
export component MainWindow inherits Window {
|
||||
title: Bridge.app-name;
|
||||
@@ -114,7 +119,7 @@ export component MainWindow inherits Window {
|
||||
if !root.chrome: StreamViewer { }
|
||||
|
||||
if !Nav.narrow && root.chrome: DesktopShell {
|
||||
context: Nav.page == Page.settings ? @tr("Settings") : "";
|
||||
context: Nav.page == Page.settings ? @tr("Settings") : Nav.page == Page.studio ? @tr("Stream Studio") : "";
|
||||
if Nav.page == Page.home: Sidebar {
|
||||
HomeNav { }
|
||||
Rectangle { vertical-stretch: 1; }
|
||||
@@ -159,6 +164,9 @@ export component MainWindow inherits Window {
|
||||
horizontal-stretch: 1;
|
||||
SettingsPage { }
|
||||
}
|
||||
if Nav.page == Page.studio && !StudioBridge.status.detached: StudioPage {
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
}
|
||||
|
||||
if Nav.narrow && root.chrome: MobileShell {
|
||||
@@ -174,7 +182,7 @@ export component MainWindow inherits Window {
|
||||
if Nav.page == Page.settings: SettingsPage {
|
||||
compact: true;
|
||||
}
|
||||
if Nav.page != Page.settings && (Nav.page == Page.home || Nav.mobile-tab == MobileTab.home): HomePage { }
|
||||
if Nav.page != Page.settings && Nav.page != Page.studio && (Nav.page == Page.home || Nav.mobile-tab == MobileTab.home): HomePage { }
|
||||
if Nav.page == Page.server && Nav.mobile-tab == MobileTab.servers: MobileServers { }
|
||||
if Nav.page == Page.server && Nav.mobile-tab == MobileTab.chat && Bridge.viewer-open: StreamViewer { }
|
||||
if Nav.page == Page.server && Nav.mobile-tab == MobileTab.chat && !Bridge.viewer-open: ChatView {
|
||||
@@ -182,6 +190,7 @@ export component MainWindow inherits Window {
|
||||
}
|
||||
if Nav.page == Page.server && Nav.mobile-tab == MobileTab.activity: ActivityPage { }
|
||||
if Nav.page == Page.server && Nav.mobile-tab == MobileTab.you: YouPage { }
|
||||
if Nav.page == Page.studio && !StudioBridge.status.detached: MobileStudio { }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
<!-- @license lucide-static v1.48.0 - ISC -->
|
||||
<svg
|
||||
class="lucide lucide-app-window"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<rect x="2" y="4" width="20" height="16" rx="2" />
|
||||
<path d="M10 4v4" />
|
||||
<path d="M2 8h20" />
|
||||
<path d="M6 4v4" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 410 B |
@@ -0,0 +1,16 @@
|
||||
<!-- @license lucide-static v1.48.0 - ISC -->
|
||||
<svg
|
||||
class="lucide lucide-crop"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M6 2v14a2 2 0 0 0 2 2h14" />
|
||||
<path d="M18 22V8a2 2 0 0 0-2-2H2" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 363 B |
@@ -0,0 +1,17 @@
|
||||
<!-- @license lucide-static v1.48.0 - ISC -->
|
||||
<svg
|
||||
class="lucide lucide-layers"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
width="24"
|
||||
height="24"
|
||||
viewBox="0 0 24 24"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
stroke-width="2"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
>
|
||||
<path d="M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z" />
|
||||
<path d="M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12" />
|
||||
<path d="M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17" />
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 587 B |
@@ -5,6 +5,7 @@
|
||||
|
||||
export global Icons {
|
||||
out property <image> activity: @image-url("assets/icons/activity.svg");
|
||||
out property <image> app-window: @image-url("assets/icons/app-window.svg");
|
||||
out property <image> arrow-left: @image-url("assets/icons/arrow-left.svg");
|
||||
out property <image> arrow-right: @image-url("assets/icons/arrow-right.svg");
|
||||
out property <image> at-sign: @image-url("assets/icons/at-sign.svg");
|
||||
@@ -28,6 +29,7 @@ export global Icons {
|
||||
out property <image> coffee: @image-url("assets/icons/coffee.svg");
|
||||
out property <image> compass: @image-url("assets/icons/compass.svg");
|
||||
out property <image> copy: @image-url("assets/icons/copy.svg");
|
||||
out property <image> crop: @image-url("assets/icons/crop.svg");
|
||||
out property <image> crown: @image-url("assets/icons/crown.svg");
|
||||
out property <image> download: @image-url("assets/icons/download.svg");
|
||||
out property <image> more-vertical: @image-url("assets/icons/ellipsis-vertical.svg");
|
||||
@@ -54,6 +56,7 @@ export global Icons {
|
||||
out property <image> image: @image-url("assets/icons/image.svg");
|
||||
out property <image> info: @image-url("assets/icons/info.svg");
|
||||
out property <image> keyboard: @image-url("assets/icons/keyboard.svg");
|
||||
out property <image> layers: @image-url("assets/icons/layers.svg");
|
||||
out property <image> layout-grid: @image-url("assets/icons/layout-grid.svg");
|
||||
out property <image> leaf: @image-url("assets/icons/leaf.svg");
|
||||
out property <image> library: @image-url("assets/icons/library.svg");
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
// development switch VOELIN_OPEN (src/dev.rs).
|
||||
|
||||
import { Bridge, BookmarkForm, ShareForm } from "bridge.slint";
|
||||
import { StudioBridge } from "studio-bridge.slint";
|
||||
|
||||
export enum Page {
|
||||
// Welcome page: servers at a glance.
|
||||
@@ -10,6 +11,8 @@ export enum Page {
|
||||
// A server: channels, chat or the stream viewer, members and streams.
|
||||
server,
|
||||
settings,
|
||||
// The Stream Studio (scenes, preview, mixer, going live).
|
||||
studio,
|
||||
}
|
||||
|
||||
// Sections of the settings page, in the order of its navigation.
|
||||
@@ -116,6 +119,15 @@ export global Nav {
|
||||
}
|
||||
}
|
||||
|
||||
// The Stream Studio: its page, or its window when it has one.
|
||||
public function open-studio() {
|
||||
if StudioBridge.status.detached {
|
||||
StudioBridge.open();
|
||||
} else {
|
||||
show(Page.studio);
|
||||
}
|
||||
}
|
||||
|
||||
// The pins and the topics share the drawer, so opening one closes the
|
||||
// other.
|
||||
public function show-pins(on: bool) {
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,662 @@
|
||||
// The Stream Studio in the main window (desktop and phone). The pieces are
|
||||
// in studio-parts.slint; the detached window is studio-window.slint.
|
||||
|
||||
import { Theme } from "../theme.slint";
|
||||
import { Icons } from "../icons.slint";
|
||||
import { Bridge } from "../bridge.slint";
|
||||
import { Nav, Page } from "../nav.slint";
|
||||
import { StudioBridge, StudioNav } from "../studio-bridge.slint";
|
||||
import { Icon, Button, ButtonKind, IconButton, Avatar, Status, TextField, Select, Slider, Meter, Divider, ScrollView } from "../components/index.slint";
|
||||
import { StudioKinds, StudioPanel, PanelTitle, ScenesCard, SourcesCard, StudioPreview, StudioHeader, StudioMark, MixerCard, StudioChat, StreamSettings, DestinationSelect, StudioActions, ViewerRequests, StudioDialogs } from "studio-parts.slint";
|
||||
|
||||
// Who streams, at the bottom left.
|
||||
component StudioUser inherits HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Avatar {
|
||||
size: 38px;
|
||||
initials: Bridge.nickname != "" ? "" : "?";
|
||||
tint: Theme.accent;
|
||||
label: Bridge.nickname;
|
||||
crown: StudioBridge.status.live;
|
||||
status: Bridge.voice-connected ? Status.online : Status.offline;
|
||||
Icon {
|
||||
source: Icons.user;
|
||||
size: 20px;
|
||||
tint: #ffffff;
|
||||
visible: Bridge.nickname != "";
|
||||
}
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: Bridge.nickname != "" ? Bridge.nickname : Bridge.app-name;
|
||||
color: Theme.text;
|
||||
font-weight: Theme.weight-semibold;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
text: StudioBridge.status.live ? @tr("Live") : Bridge.voice-connected ? @tr("Online") : @tr("Offline");
|
||||
color: StudioBridge.status.live ? Theme.live : Theme.text-muted;
|
||||
font-size: Theme.font-xs;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The studio as a page of the main window: scenes and sources, the
|
||||
// preview with the mixer and the chat, the stream settings, the bottom bar.
|
||||
export component StudioPage inherits Rectangle {
|
||||
init => { StudioBridge.open(); }
|
||||
VerticalLayout {
|
||||
spacing: Theme.space-3;
|
||||
HorizontalLayout {
|
||||
vertical-stretch: 1;
|
||||
spacing: Theme.space-3;
|
||||
VerticalLayout {
|
||||
width: 250px * max(1.0, Theme.font-scale);
|
||||
spacing: Theme.space-3;
|
||||
ScenesCard {
|
||||
vertical-stretch: 1;
|
||||
}
|
||||
SourcesCard {
|
||||
vertical-stretch: 1;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
spacing: Theme.space-3;
|
||||
// As tall as a 16:9 picture across the column needs; the
|
||||
// mixer and the chat get the rest.
|
||||
StudioPanel {
|
||||
vertical-stretch: 0;
|
||||
preferred-height: (self.width - 2 * Theme.space-4) * 9 / 16 + 96px + (StudioBridge.viewers.length > 0 ? 40px : 0px);
|
||||
min-height: 260px;
|
||||
VerticalLayout {
|
||||
padding: Theme.space-4;
|
||||
padding-top: Theme.space-3;
|
||||
spacing: Theme.space-3;
|
||||
StudioHeader { }
|
||||
if StudioBridge.viewers.length > 0: ViewerRequests { }
|
||||
StudioPreview {
|
||||
vertical-stretch: 1;
|
||||
min-height: 160px;
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
vertical-stretch: 1;
|
||||
min-height: 240px;
|
||||
spacing: Theme.space-3;
|
||||
MixerCard {
|
||||
horizontal-stretch: 1.35;
|
||||
}
|
||||
StudioChat {
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
StudioPanel {
|
||||
width: 300px * max(1.0, Theme.font-scale);
|
||||
ScrollView {
|
||||
StreamSettings { }
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
height: 64px;
|
||||
spacing: Theme.space-3;
|
||||
StudioUser {
|
||||
padding-left: Theme.space-3;
|
||||
horizontal-stretch: 0;
|
||||
}
|
||||
StudioActions {
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
Rectangle {
|
||||
width: 150px;
|
||||
Rectangle {
|
||||
y: (parent.height - self.height) / 2;
|
||||
height: 48px;
|
||||
border-radius: Theme.radius-lg;
|
||||
background: settings-touch.has-hover ? Theme.surface-3 : Theme.surface.transparentize(0.08);
|
||||
border-width: 1px;
|
||||
border-color: Theme.border;
|
||||
accessible-role: AccessibleRole.button;
|
||||
accessible-label: @tr("Studio Settings");
|
||||
accessible-action-default => { StudioNav.open-settings(); }
|
||||
settings-touch := TouchArea {
|
||||
mouse-cursor: MouseCursor.pointer;
|
||||
clicked => { StudioNav.open-settings(); }
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
spacing: Theme.space-3;
|
||||
Icon {
|
||||
source: Icons.settings;
|
||||
size: Theme.icon-md;
|
||||
tint: Theme.text-secondary;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: @tr("Studio Settings");
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-sm;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
StudioDialogs {
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
}
|
||||
}
|
||||
|
||||
// A section title of the phone layout with a link at the right.
|
||||
component PhoneSection inherits HorizontalLayout {
|
||||
in property <string> text;
|
||||
in property <image> icon;
|
||||
in property <string> action;
|
||||
callback action-clicked();
|
||||
spacing: Theme.space-3;
|
||||
min-height: 32px;
|
||||
if root.icon.width > 0: Icon {
|
||||
source: root.icon;
|
||||
size: Theme.icon-md;
|
||||
tint: Theme.text-secondary;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: root.text;
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-lg;
|
||||
font-weight: Theme.weight-semibold;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
if root.action != "": Text {
|
||||
text: root.action;
|
||||
color: Theme.accent-text;
|
||||
font-size: Theme.font-sm;
|
||||
vertical-alignment: center;
|
||||
TouchArea {
|
||||
clicked => { root.action-clicked(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// One of the phone's source cards.
|
||||
component SourceCard inherits Rectangle {
|
||||
in property <string> kind;
|
||||
in property <string> title;
|
||||
in property <string> subtitle;
|
||||
in property <image> icon;
|
||||
// A visible source of this kind is in the live scene.
|
||||
in property <bool> shown;
|
||||
height: 104px;
|
||||
horizontal-stretch: 1;
|
||||
border-radius: Theme.radius-lg;
|
||||
background: root.shown ? Theme.accent-soft : touch.has-hover ? Theme.surface-3 : Theme.surface-2;
|
||||
border-width: root.shown ? 2px : 1px;
|
||||
border-color: root.shown ? Theme.accent : Theme.border;
|
||||
accessible-role: AccessibleRole.radio-button;
|
||||
accessible-label: root.title;
|
||||
accessible-description: root.subtitle;
|
||||
accessible-checkable: true;
|
||||
accessible-checked: root.shown;
|
||||
accessible-action-default => { StudioBridge.main-source(root.kind); }
|
||||
touch := TouchArea {
|
||||
clicked => { StudioBridge.main-source(root.kind); }
|
||||
}
|
||||
Rectangle {
|
||||
x: parent.width - 26px;
|
||||
y: 10px;
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
border-radius: 9px;
|
||||
border-width: 2px;
|
||||
border-color: root.shown ? Theme.accent-text : Theme.text-muted;
|
||||
if root.shown: Rectangle {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 4px;
|
||||
background: Theme.accent-text;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
spacing: Theme.space-2;
|
||||
padding: Theme.space-2;
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
Icon {
|
||||
source: root.icon;
|
||||
size: 28px;
|
||||
tint: root.shown ? Theme.accent-text : Theme.icon;
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: root.title;
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-body;
|
||||
font-weight: Theme.weight-medium;
|
||||
horizontal-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
text: root.subtitle;
|
||||
color: Theme.text-muted;
|
||||
font-size: Theme.font-xs;
|
||||
horizontal-alignment: center;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// An audio row of the phone layout.
|
||||
component PhoneAudioRow inherits Rectangle {
|
||||
in property <int> index;
|
||||
property <bool> valid: index < StudioBridge.audio.length;
|
||||
height: 72px;
|
||||
border-radius: Theme.radius-lg;
|
||||
background: Theme.surface-2.transparentize(0.3);
|
||||
border-width: 1px;
|
||||
border-color: Theme.border;
|
||||
HorizontalLayout {
|
||||
padding-left: Theme.space-3;
|
||||
padding-right: Theme.space-2;
|
||||
spacing: Theme.space-3;
|
||||
Rectangle {
|
||||
width: 42px;
|
||||
height: 42px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
border-radius: Theme.radius-md;
|
||||
background: Theme.surface-3;
|
||||
Icon {
|
||||
source: StudioKinds.icon(root.valid ? StudioBridge.audio[root.index].kind : "");
|
||||
size: 22px;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
spacing: Theme.space-2;
|
||||
HorizontalLayout {
|
||||
Text {
|
||||
text: root.valid ? StudioBridge.audio[root.index].name + (StudioBridge.audio[root.index].detail != "" ? " (" + StudioBridge.audio[root.index].detail + ")" : "") : "";
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-sm;
|
||||
horizontal-stretch: 1;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
text: !root.valid ? "" : StudioBridge.audio[root.index].muted ? @tr("muted") : @tr("{} dB", round(StudioBridge.audio[root.index].gain-db * 10) / 10);
|
||||
color: Theme.text-secondary;
|
||||
font-size: Theme.font-xs;
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
Meter {
|
||||
y: (parent.height - self.height) / 2;
|
||||
height: 8px;
|
||||
segments: 14;
|
||||
floor: -60;
|
||||
min-width: 60px;
|
||||
level: root.valid ? StudioBridge.audio[root.index].level : -100;
|
||||
active: root.valid && !StudioBridge.audio[root.index].muted;
|
||||
}
|
||||
Slider {
|
||||
width: 46%;
|
||||
horizontal-stretch: 0;
|
||||
y: (parent.height - self.height) / 2;
|
||||
minimum: -60;
|
||||
maximum: 20;
|
||||
step: 0.5;
|
||||
value: root.valid ? StudioBridge.audio[root.index].gain-db : 0;
|
||||
label: @tr("Gain");
|
||||
changed(v) => { StudioBridge.set-gain(root.index, v, false); }
|
||||
released(v) => { StudioBridge.set-gain(root.index, v, true); }
|
||||
}
|
||||
}
|
||||
}
|
||||
IconButton {
|
||||
icon: root.valid && StudioBridge.audio[root.index].muted ? Icons.volume-x : Icons.volume-2;
|
||||
label: @tr("Mute");
|
||||
checked: root.valid && StudioBridge.audio[root.index].muted;
|
||||
danger: true;
|
||||
size: 34px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { StudioBridge.toggle-mute(root.index); }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The studio in the phone layout: preview, what to share, audio, details,
|
||||
// Go Live.
|
||||
export component MobileStudio inherits Rectangle {
|
||||
init => { StudioBridge.open(); }
|
||||
sv := ScrollView {
|
||||
VerticalLayout {
|
||||
width: sv.visible-width;
|
||||
alignment: start;
|
||||
padding: Theme.space-4;
|
||||
padding-top: Theme.space-2;
|
||||
spacing: Theme.space-4;
|
||||
// Header: back, the mark, title, destination.
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
IconButton {
|
||||
icon: Icons.chevron-left;
|
||||
label: @tr("Back");
|
||||
size: 32px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Nav.show(Page.server); }
|
||||
}
|
||||
StudioMark {
|
||||
size: 40px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
Text {
|
||||
text: @tr("Stream Studio");
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-xl;
|
||||
font-weight: Theme.weight-semibold;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
text: StudioBridge.status.live ? @tr("Live · {}", StudioBridge.status.elapsed) : StudioBridge.chat-name != "" ? @tr("Go live to {}", StudioBridge.chat-name) : StudioBridge.status.hint;
|
||||
color: StudioBridge.status.live ? Theme.live : Theme.accent-text;
|
||||
font-size: Theme.font-sm;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
// The preview.
|
||||
Rectangle {
|
||||
height: (sv.visible-width - 2 * Theme.space-4) * 9 / 16;
|
||||
border-radius: Theme.radius-lg;
|
||||
border-width: 1px;
|
||||
border-color: Theme.accent.transparentize(0.4);
|
||||
clip: true;
|
||||
StudioPreview {
|
||||
large: false;
|
||||
caption: false;
|
||||
}
|
||||
Rectangle {
|
||||
x: Theme.space-3;
|
||||
y: Theme.space-3;
|
||||
width: badge.preferred-width + 16px;
|
||||
height: 24px;
|
||||
border-radius: Theme.radius-xs;
|
||||
background: Theme.live;
|
||||
visible: !StudioBridge.status.live;
|
||||
badge := Text {
|
||||
text: @tr("LIVE PREVIEW");
|
||||
color: #ffffff;
|
||||
font-size: Theme.font-xs;
|
||||
font-weight: Theme.weight-bold;
|
||||
}
|
||||
}
|
||||
if StudioBridge.sources.length > 0: Rectangle {
|
||||
x: Theme.space-3;
|
||||
y: parent.height - self.height - Theme.space-3;
|
||||
width: min(parent.width - 2 * Theme.space-3, caption.preferred-width);
|
||||
height: 46px;
|
||||
border-radius: Theme.radius-md;
|
||||
background: #060a18b0;
|
||||
caption := HorizontalLayout {
|
||||
padding-left: Theme.space-2;
|
||||
padding-right: Theme.space-4;
|
||||
spacing: Theme.space-3;
|
||||
Rectangle {
|
||||
width: 34px;
|
||||
height: 34px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
border-radius: Theme.radius-sm;
|
||||
background: #ffffff18;
|
||||
Icon {
|
||||
source: StudioKinds.icon(StudioBridge.sources[StudioBridge.sources.length - 1].kind);
|
||||
size: 20px;
|
||||
tint: #ffffff;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Text {
|
||||
text: StudioBridge.form.title != "" ? StudioBridge.form.title : StudioBridge.sources[StudioBridge.sources.length - 1].name;
|
||||
color: #ffffff;
|
||||
font-size: Theme.font-body;
|
||||
font-weight: Theme.weight-medium;
|
||||
overflow: elide;
|
||||
}
|
||||
Text {
|
||||
text: StudioBridge.sources[StudioBridge.sources.length - 1].name + " • " + (StudioBridge.status.output-height * 16 == StudioBridge.status.output-width * 9 ? "16:9" : StudioBridge.status.output-width + "×" + StudioBridge.status.output-height);
|
||||
color: #ffffffb0;
|
||||
font-size: Theme.font-xs;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
x: parent.width - self.width - Theme.space-3;
|
||||
y: Theme.space-3;
|
||||
width: fmt.preferred-width + 20px;
|
||||
height: 26px;
|
||||
border-radius: Theme.radius-pill;
|
||||
background: #060a18c8;
|
||||
border-width: 1px;
|
||||
border-color: #ffffff20;
|
||||
fmt := Text {
|
||||
text: StudioBridge.status.output-height + "p • " + StudioBridge.status.fps + " FPS";
|
||||
color: #ffffff;
|
||||
font-size: Theme.font-xs;
|
||||
}
|
||||
}
|
||||
}
|
||||
// What to share.
|
||||
PhoneSection {
|
||||
text: @tr("Source");
|
||||
action: @tr("What do you want to share?");
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
SourceCard {
|
||||
kind: "screen";
|
||||
title: @tr("Screen / Game");
|
||||
subtitle: @tr("Apps or games");
|
||||
icon: Icons.gamepad-2;
|
||||
shown: StudioBridge.status.screen-shown;
|
||||
}
|
||||
SourceCard {
|
||||
kind: "camera";
|
||||
title: @tr("Camera");
|
||||
subtitle: @tr("Front or back");
|
||||
icon: Icons.video;
|
||||
shown: StudioBridge.status.camera-shown;
|
||||
}
|
||||
SourceCard {
|
||||
kind: "window";
|
||||
title: @tr("App Window");
|
||||
subtitle: @tr("A single app");
|
||||
icon: Icons.smartphone;
|
||||
shown: StudioBridge.status.window-shown;
|
||||
}
|
||||
}
|
||||
// Audio.
|
||||
PhoneSection {
|
||||
text: @tr("Audio");
|
||||
icon: Icons.mic;
|
||||
action: @tr("Add a source");
|
||||
action-clicked => { StudioNav.pick-audio(); }
|
||||
}
|
||||
for audio[i] in StudioBridge.audio: PhoneAudioRow {
|
||||
index: i;
|
||||
}
|
||||
// Details.
|
||||
PhoneSection {
|
||||
text: @tr("Stream Details");
|
||||
icon: Icons.file-text;
|
||||
}
|
||||
TextField {
|
||||
text: StudioBridge.form.title;
|
||||
placeholder: @tr("What are you streaming?");
|
||||
label: @tr("Stream title");
|
||||
edited(t) => { StudioBridge.edit-form("title", t); }
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
VerticalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Text {
|
||||
text: @tr("Game");
|
||||
color: Theme.text-secondary;
|
||||
font-size: Theme.font-sm;
|
||||
}
|
||||
TextField {
|
||||
text: StudioBridge.form.game;
|
||||
placeholder: @tr("Category");
|
||||
label: @tr("Game or category");
|
||||
edited(t) => { StudioBridge.edit-form("game", t); }
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Text {
|
||||
text: @tr("Quality");
|
||||
color: Theme.text-secondary;
|
||||
font-size: Theme.font-sm;
|
||||
}
|
||||
Select {
|
||||
model: ["720p • 30 FPS", "720p • 60 FPS", "1080p • 30 FPS", "1080p • 60 FPS"];
|
||||
current-value: StudioBridge.status.output-height + "p • " + StudioBridge.status.fps + " FPS";
|
||||
label: @tr("Output quality");
|
||||
selected(v) => {
|
||||
if v == "720p • 30 FPS" {
|
||||
StudioBridge.set-output("1280", "720", "30");
|
||||
} else if v == "720p • 60 FPS" {
|
||||
StudioBridge.set-output("1280", "720", "60");
|
||||
} else if v == "1080p • 30 FPS" {
|
||||
StudioBridge.set-output("1920", "1080", "30");
|
||||
} else {
|
||||
StudioBridge.set-output("1920", "1080", "60");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-2;
|
||||
Icon {
|
||||
source: Icons.radio;
|
||||
tint: Theme.accent-text;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
Text {
|
||||
text: @tr("Go Live To");
|
||||
color: Theme.accent-text;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
}
|
||||
DestinationSelect {
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
}
|
||||
// Go live (or end) and save a clip.
|
||||
HorizontalLayout {
|
||||
spacing: Theme.space-3;
|
||||
height: 68px;
|
||||
Rectangle {
|
||||
horizontal-stretch: 1;
|
||||
border-radius: Theme.radius-lg;
|
||||
background: StudioBridge.status.live || StudioBridge.status.starting ? Theme.danger-soft : !StudioBridge.status.can-go-live ? Theme.surface-3 : go.pressed ? Theme.accent-pressed : Theme.accent;
|
||||
border-width: 1px;
|
||||
border-color: StudioBridge.status.live ? Theme.danger : Theme.accent-hover;
|
||||
accessible-role: AccessibleRole.button;
|
||||
accessible-label: StudioBridge.status.live ? @tr("End Stream") : @tr("Go Live");
|
||||
accessible-description: StudioBridge.status.hint;
|
||||
go := TouchArea {
|
||||
clicked => {
|
||||
if StudioBridge.status.live || StudioBridge.status.starting {
|
||||
StudioBridge.end-stream();
|
||||
} else if StudioBridge.status.can-go-live {
|
||||
StudioBridge.go-live();
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
spacing: Theme.space-4;
|
||||
Icon {
|
||||
source: StudioBridge.status.live ? Icons.square : Icons.radio;
|
||||
size: 30px;
|
||||
tint: StudioBridge.status.live ? Theme.danger : Theme.on-accent;
|
||||
y: (parent.height - self.height) / 2;
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
Text {
|
||||
text: StudioBridge.status.live ? @tr("End Stream") : StudioBridge.status.starting ? @tr("Starting…") : @tr("Go Live");
|
||||
color: StudioBridge.status.live ? Theme.danger : Theme.on-accent;
|
||||
font-size: Theme.font-xl;
|
||||
font-weight: Theme.weight-semibold;
|
||||
}
|
||||
Text {
|
||||
text: StudioBridge.status.live ? StudioBridge.status.elapsed : StudioBridge.chat-name != "" ? @tr("Start streaming to {}", StudioBridge.chat-name) : StudioBridge.status.hint;
|
||||
color: StudioBridge.status.live ? Theme.danger : #ffffffc0;
|
||||
font-size: Theme.font-xs;
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Rectangle {
|
||||
width: 88px;
|
||||
border-radius: Theme.radius-lg;
|
||||
background: clip.pressed ? Theme.surface-4 : Theme.surface-2;
|
||||
border-width: 1px;
|
||||
border-color: Theme.border;
|
||||
accessible-role: AccessibleRole.button;
|
||||
accessible-label: @tr("Save a clip");
|
||||
clip := TouchArea {
|
||||
clicked => { StudioBridge.save-clip(); }
|
||||
}
|
||||
VerticalLayout {
|
||||
alignment: center;
|
||||
spacing: Theme.space-1;
|
||||
HorizontalLayout {
|
||||
alignment: center;
|
||||
Icon {
|
||||
source: Icons.record;
|
||||
size: 26px;
|
||||
tint: Theme.live;
|
||||
}
|
||||
}
|
||||
Text {
|
||||
text: @tr("Clip");
|
||||
color: Theme.text-secondary;
|
||||
font-size: Theme.font-sm;
|
||||
horizontal-alignment: center;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if StudioBridge.viewers.length > 0: ViewerRequests { }
|
||||
}
|
||||
}
|
||||
StudioDialogs {
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
}
|
||||
}
|
||||
@@ -218,6 +218,13 @@ export component TopBar inherits Rectangle {
|
||||
}
|
||||
}
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.radio;
|
||||
label: @tr("Stream Studio");
|
||||
checked: Nav.page == Page.studio;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Nav.open-studio(); }
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.users;
|
||||
label: @tr("Members");
|
||||
|
||||
@@ -117,6 +117,15 @@ export component MobileShell inherits Rectangle {
|
||||
overflow: elide;
|
||||
}
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.radio;
|
||||
label: @tr("Stream Studio");
|
||||
round: true;
|
||||
filled: true;
|
||||
checked: Nav.page == Page.studio;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { Nav.open-studio(); }
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.bell;
|
||||
label: @tr("Notifications");
|
||||
|
||||
@@ -0,0 +1,321 @@
|
||||
// The Stream Studio's data and callbacks (Rust: src/studio.rs, the view
|
||||
// models in src/vm/studio.rs). The main window and the detached studio
|
||||
// window each have their own instance of these globals: Rust sets the same
|
||||
// models and values on both, and wires both to the same controller.
|
||||
|
||||
import { ChatLine } from "bridge.slint";
|
||||
|
||||
// A scene of the studio.
|
||||
export struct StudioScene {
|
||||
id: int,
|
||||
name: string,
|
||||
// Its sources, front first: "Screen + Camera + Text".
|
||||
detail: string,
|
||||
// Composited now (the live scene).
|
||||
live: bool,
|
||||
// The kind of its front-most source (for the icon).
|
||||
kind: string,
|
||||
}
|
||||
|
||||
// A source of the live scene, front first.
|
||||
export struct StudioSource {
|
||||
id: int,
|
||||
name: string,
|
||||
// screen, window, portal, camera, image, text, colour, pattern
|
||||
kind: string,
|
||||
visible: bool,
|
||||
locked: bool,
|
||||
// keep, blur, image, colour
|
||||
background: string,
|
||||
// Why it shows nothing ("" while it works).
|
||||
error: string,
|
||||
// "1920×1080 · 60 fps"
|
||||
info: string,
|
||||
// At the front or the back (cannot move further).
|
||||
front: bool,
|
||||
back: bool,
|
||||
}
|
||||
|
||||
// An audio source of the stream (`stream.audio_sources`).
|
||||
export struct StudioAudio {
|
||||
name: string,
|
||||
// "Elgato Wave:3", the application...
|
||||
detail: string,
|
||||
// microphone, desktop, app, window, tone
|
||||
kind: string,
|
||||
gain-db: float,
|
||||
muted: bool,
|
||||
// The meter in dBFS, after the gain.
|
||||
level: float,
|
||||
// Why it captures nothing.
|
||||
error: string,
|
||||
}
|
||||
|
||||
// A simulcast layer (`stream.layers`) as typed: any numbers.
|
||||
export struct StudioLayer {
|
||||
// "1280x720"; empty: `scale` of the output.
|
||||
size: string,
|
||||
scale: string,
|
||||
// Frame-rate cap; empty: the output's.
|
||||
fps: string,
|
||||
// kbit/s.
|
||||
bitrate: string,
|
||||
// kbit/s a viewer needs for this layer.
|
||||
min-bitrate: string,
|
||||
}
|
||||
|
||||
// A viewer of the studio's stream.
|
||||
export struct StudioViewer {
|
||||
client: int,
|
||||
name: string,
|
||||
// requested, connecting, connected
|
||||
state: string,
|
||||
}
|
||||
|
||||
// An entry of a picker (screens, windows, cameras, audio sources).
|
||||
export struct StudioPick {
|
||||
name: string,
|
||||
detail: string,
|
||||
// For the icon: monitor, window, portal, camera, microphone, desktop, app, tone
|
||||
kind: string,
|
||||
}
|
||||
|
||||
// The header, the preview's badges and the bottom bar.
|
||||
export struct StudioStatus {
|
||||
// The engine runs (preview, mixer, replay buffer).
|
||||
running: bool,
|
||||
// "Chill Zone • Starfall Community"; empty without a destination.
|
||||
destination: string,
|
||||
// 0: not live, 1: poor, 2: fair, 3: good, 4: excellent.
|
||||
quality: int,
|
||||
quality-text: string,
|
||||
// "1080p • 60 FPS • 8,250 kbps"
|
||||
format: string,
|
||||
// The numbers behind it, for the info button.
|
||||
details: string,
|
||||
live: bool,
|
||||
// Going live: waiting for the server.
|
||||
starting: bool,
|
||||
// "00:12:34"
|
||||
elapsed: string,
|
||||
viewers: int,
|
||||
participants: int,
|
||||
can-go-live: bool,
|
||||
// Why Go Live is off, or what goes wrong.
|
||||
hint: string,
|
||||
recording: bool,
|
||||
recorded: string,
|
||||
// The replay buffer's window (0: off) and what it holds now.
|
||||
replay-seconds: int,
|
||||
replay-held: string,
|
||||
output-width: int,
|
||||
output-height: int,
|
||||
fps: int,
|
||||
detached: bool,
|
||||
// A window of its own is possible (not on Android).
|
||||
can-detach: bool,
|
||||
// The live scene shows a screen, a camera, a window (the phone's cards).
|
||||
screen-shown: bool,
|
||||
camera-shown: bool,
|
||||
window-shown: bool,
|
||||
}
|
||||
|
||||
// The stream settings panel (`studio.stream`, `stream.bitrate_kbps`).
|
||||
export struct StudioForm {
|
||||
destination: int,
|
||||
title: string,
|
||||
game: string,
|
||||
message: string,
|
||||
show-viewers: bool,
|
||||
show-chat: bool,
|
||||
show-now-playing: bool,
|
||||
audio: bool,
|
||||
// kbit/s of the stream without layers, as typed.
|
||||
bitrate: string,
|
||||
}
|
||||
|
||||
// The source properties dialog (also for adding text, colour and image
|
||||
// sources: `id` -1). Numbers as typed.
|
||||
export struct StudioSourceForm {
|
||||
id: int,
|
||||
name: string,
|
||||
kind: string,
|
||||
x: string,
|
||||
y: string,
|
||||
// Empty: the source's own size times `scale`.
|
||||
width: string,
|
||||
height: string,
|
||||
scale: string,
|
||||
// contain, cover, stretch
|
||||
fit: string,
|
||||
crop-left: string,
|
||||
crop-top: string,
|
||||
crop-right: string,
|
||||
crop-bottom: string,
|
||||
// Percent.
|
||||
opacity: float,
|
||||
locked: bool,
|
||||
visible: bool,
|
||||
// keep, blur, image, colour
|
||||
background: string,
|
||||
// Blur radius in percent of the picture's height.
|
||||
blur: string,
|
||||
background-path: string,
|
||||
background-colour: string,
|
||||
// Text, colour ("#rrggbb" or "#rrggbbaa") and image sources.
|
||||
text: string,
|
||||
text-size: string,
|
||||
colour: string,
|
||||
path: string,
|
||||
mirror: bool,
|
||||
}
|
||||
|
||||
// The studio settings dialog (`studio.*` keys and the preview).
|
||||
export struct StudioSettingsForm {
|
||||
replay-seconds: string,
|
||||
replay-memory: string,
|
||||
recording-dir: string,
|
||||
preview-width: string,
|
||||
preview-fps: string,
|
||||
}
|
||||
|
||||
export global StudioBridge {
|
||||
in property <StudioStatus> status;
|
||||
in property <StudioForm> form;
|
||||
// The composite, downscaled (the engine's preview tap).
|
||||
in property <image> preview;
|
||||
in property <bool> has-preview;
|
||||
in property <[StudioScene]> scenes;
|
||||
in property <[StudioSource]> sources;
|
||||
in property <[StudioAudio]> audio;
|
||||
in property <[StudioLayer]> layers;
|
||||
// Where the stream can go: the channel (name) on each server (detail).
|
||||
in property <[StudioPick]> destinations;
|
||||
in property <[StudioViewer]> viewers;
|
||||
// The chat of the channel the stream goes to, and its name.
|
||||
in property <[ChatLine]> chat;
|
||||
in property <string> chat-name;
|
||||
// Filled right before a picker shows.
|
||||
in property <[StudioPick]> picks;
|
||||
|
||||
// The studio page or window appeared: start the engine.
|
||||
callback open();
|
||||
// Into a window of its own, and back.
|
||||
callback detach();
|
||||
callback dock();
|
||||
|
||||
callback select-scene(int);
|
||||
callback add-scene();
|
||||
callback rename-scene(int, string);
|
||||
callback remove-scene(int);
|
||||
|
||||
// Fill `picks` for adding a screen, window or camera source; false:
|
||||
// nothing to pick (it was added directly, e.g. through the portal).
|
||||
callback list-sources(string) -> bool;
|
||||
callback add-picked(string, int);
|
||||
// Text, colour and image sources from the dialog.
|
||||
callback add-source(StudioSourceForm);
|
||||
callback source-form(int) -> StudioSourceForm;
|
||||
callback apply-source(StudioSourceForm);
|
||||
callback toggle-source(int);
|
||||
// up, down, lock, remove, bg-keep, bg-blur
|
||||
callback source-action(int, string);
|
||||
// The phone layout's source cards: screen, camera, window.
|
||||
callback main-source(string);
|
||||
|
||||
// Audio: fill `picks` with what can be added; add, change, remove.
|
||||
callback list-audio();
|
||||
callback add-audio(int);
|
||||
// While dragging (`done` false) and at the end.
|
||||
callback set-gain(int, float, bool);
|
||||
callback toggle-mute(int);
|
||||
callback remove-audio(int);
|
||||
|
||||
// A field of the stream settings: title, game, message, show-viewers,
|
||||
// show-chat, show-now-playing, audio ("true"/"false"), bitrate,
|
||||
// destination (its index).
|
||||
callback edit-form(string, string);
|
||||
callback set-output(string, string, string);
|
||||
callback set-layer(int, StudioLayer);
|
||||
callback add-layer();
|
||||
callback remove-layer(int);
|
||||
callback advanced-settings();
|
||||
|
||||
// Bottom bar.
|
||||
callback save-clip();
|
||||
callback toggle-recording();
|
||||
callback open-recordings();
|
||||
callback go-live();
|
||||
callback end-stream();
|
||||
callback settings-form() -> StudioSettingsForm;
|
||||
callback apply-settings(StudioSettingsForm);
|
||||
|
||||
callback respond-viewer(int, bool);
|
||||
callback send-chat(string);
|
||||
callback open-chat();
|
||||
}
|
||||
|
||||
// What one window shows of the studio: dialogs and pickers (each window has
|
||||
// its own).
|
||||
export global StudioNav {
|
||||
// "", "pick", "source", "scene", "settings"
|
||||
in-out property <string> dialog;
|
||||
// What the picker picks: screen, window, camera, audio
|
||||
in-out property <string> pick-kind;
|
||||
in-out property <StudioSourceForm> source-form;
|
||||
// The scene being renamed.
|
||||
in-out property <int> scene-id: -1;
|
||||
in-out property <string> scene-name;
|
||||
in-out property <StudioSettingsForm> settings-form;
|
||||
|
||||
public function pick(kind: string) {
|
||||
if StudioBridge.list-sources(kind) {
|
||||
pick-kind = kind;
|
||||
dialog = "pick";
|
||||
}
|
||||
}
|
||||
|
||||
public function pick-audio() {
|
||||
StudioBridge.list-audio();
|
||||
pick-kind = "audio";
|
||||
dialog = "pick";
|
||||
}
|
||||
|
||||
public function edit-source(id: int) {
|
||||
source-form = StudioBridge.source-form(id);
|
||||
dialog = "source";
|
||||
}
|
||||
|
||||
// A new text, colour or image source.
|
||||
public function new-source(kind: string) {
|
||||
source-form = {
|
||||
id: -1,
|
||||
kind: kind,
|
||||
name: kind == "text" ? @tr("Text") : kind == "colour" ? @tr("Colour") : @tr("Image"),
|
||||
text: @tr("Your text"),
|
||||
text-size: "64",
|
||||
colour: kind == "text" ? "#ffffff" : "#101a3c",
|
||||
opacity: 100,
|
||||
visible: true,
|
||||
fit: "contain",
|
||||
scale: "1",
|
||||
background: "keep",
|
||||
};
|
||||
dialog = "source";
|
||||
}
|
||||
|
||||
public function rename-scene(id: int, name: string) {
|
||||
scene-id = id;
|
||||
scene-name = name;
|
||||
dialog = "scene";
|
||||
}
|
||||
|
||||
public function open-settings() {
|
||||
settings-form = StudioBridge.settings-form();
|
||||
dialog = "settings";
|
||||
}
|
||||
|
||||
public function close() {
|
||||
dialog = "";
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
// The Stream Studio in a window of its own, while the main window goes on.
|
||||
// Same pieces as the integrated studio (screens/studio-parts.slint), more
|
||||
// compact; it has its own globals, which Rust fills from the same models
|
||||
// (src/studio.rs). Closing it docks the studio back into the main window.
|
||||
|
||||
import { Palette } from "std-widgets.slint";
|
||||
import { Theme } from "theme.slint";
|
||||
import { Icons } from "icons.slint";
|
||||
import { StudioBridge, StudioNav } from "studio-bridge.slint";
|
||||
import { IconButton, ScrollView } from "components/index.slint";
|
||||
import { ScenesCard, SourcesCard, StudioPanel, PanelTitle, StudioPreview, MixerCard, StreamSettings, StudioActions, ViewerRequests, StudioDialogs } from "screens/studio-parts.slint";
|
||||
|
||||
export component StudioWindow inherits Window {
|
||||
title: @tr("Stream Studio");
|
||||
preferred-width: 900px;
|
||||
preferred-height: 720px;
|
||||
min-width: 640px;
|
||||
min-height: 480px;
|
||||
background: Theme.bg-app;
|
||||
default-font-family: "Inter";
|
||||
default-font-size: Theme.font-body;
|
||||
icon: Icons.logo;
|
||||
|
||||
// Scroll bars and menus follow the theme (Rust copies the main
|
||||
// window's Theme here).
|
||||
property <bool> dark: Theme.dark;
|
||||
changed dark => { Palette.color-scheme = Theme.dark ? ColorScheme.dark : ColorScheme.light; }
|
||||
init => { Palette.color-scheme = Theme.dark ? ColorScheme.dark : ColorScheme.light; }
|
||||
|
||||
Rectangle {
|
||||
background: Theme.backdrop;
|
||||
VerticalLayout {
|
||||
padding: Theme.space-3;
|
||||
padding-top: 0;
|
||||
spacing: Theme.space-3;
|
||||
// The app and what this is, and back into the main window.
|
||||
HorizontalLayout {
|
||||
height: 52px;
|
||||
spacing: Theme.space-3;
|
||||
padding-left: Theme.space-2;
|
||||
Image {
|
||||
width: 28px;
|
||||
height: 28px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
source: Icons.logo;
|
||||
}
|
||||
Text {
|
||||
text: "Voelin";
|
||||
color: Theme.text;
|
||||
font-size: Theme.font-xl;
|
||||
font-weight: Theme.weight-semibold;
|
||||
vertical-alignment: center;
|
||||
}
|
||||
Text {
|
||||
text: @tr("Stream Studio");
|
||||
color: Theme.accent-text;
|
||||
font-size: Theme.font-md;
|
||||
vertical-alignment: center;
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.minimize-2;
|
||||
label: @tr("Back into the main window");
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { StudioBridge.dock(); }
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
vertical-stretch: 1;
|
||||
spacing: Theme.space-3;
|
||||
VerticalLayout {
|
||||
width: 216px * max(1.0, Theme.font-scale);
|
||||
spacing: Theme.space-3;
|
||||
ScenesCard {
|
||||
compact: true;
|
||||
vertical-stretch: 1;
|
||||
}
|
||||
SourcesCard {
|
||||
compact: true;
|
||||
vertical-stretch: 1;
|
||||
}
|
||||
}
|
||||
VerticalLayout {
|
||||
horizontal-stretch: 1;
|
||||
spacing: Theme.space-3;
|
||||
StudioPanel {
|
||||
vertical-stretch: 1.2;
|
||||
min-height: 200px;
|
||||
VerticalLayout {
|
||||
padding: Theme.space-3;
|
||||
spacing: Theme.space-2;
|
||||
PanelTitle {
|
||||
text: @tr("Stream Preview");
|
||||
compact: true;
|
||||
}
|
||||
if StudioBridge.viewers.length > 0: ViewerRequests { }
|
||||
StudioPreview {
|
||||
vertical-stretch: 1;
|
||||
large: false;
|
||||
caption: false;
|
||||
controls: true;
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
vertical-stretch: 1;
|
||||
min-height: 200px;
|
||||
spacing: Theme.space-3;
|
||||
MixerCard {
|
||||
compact: true;
|
||||
horizontal-stretch: 1.15;
|
||||
}
|
||||
StudioPanel {
|
||||
horizontal-stretch: 1;
|
||||
ScrollView {
|
||||
StreamSettings {
|
||||
compact: true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
HorizontalLayout {
|
||||
height: 52px;
|
||||
spacing: Theme.space-3;
|
||||
StudioActions {
|
||||
compact: true;
|
||||
horizontal-stretch: 1;
|
||||
}
|
||||
IconButton {
|
||||
icon: Icons.settings;
|
||||
label: @tr("Studio Settings");
|
||||
filled: true;
|
||||
size: 44px;
|
||||
y: (parent.height - self.height) / 2;
|
||||
clicked => { StudioNav.open-settings(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
StudioDialogs {
|
||||
width: parent.width;
|
||||
height: parent.height;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user