Split the Stream Studio: logic into voelin-ui-vm, the windows and the engine in bind.rs

studio.rs (62 Bridge writes) is split like the settings pages. What the
studio decides lives in voelin_ui_vm::studio::logic:

- StudioData, the state apart from the running parts (settings, scenes,
  status, statistics, destination, stream, pickers, overlays), with the
  bitrate and layers a stream starts with, the hidden-tick counter, the
  preview size, the destination choice, the stream settings form and the
  header/bottom-bar status (status_view, with the front end's side passed
  in as a StatusContext), the overlays the switches ask for;
- where the stream goes (destinations, their names and rows, the channel
  tab of the stream chat), the stream settings panel's edits, the output,
  the layer, source, picker and mixer controls (source_action,
  source_change, camera/screen/audio pickers, main_source_changes), the
  studio settings dialog, event and ending texts;
- the studio's own settings type and key (StudioUi, STUDIO_UI), the demo
  studio's sample scenes, viewers, stream and chat message.

voelin-ui keeps studio/mod.rs (StudioState: the models, the running
studio, the windows, the mixer handles, plus StudioData) and studio/bind.rs
(the engine tasks, the preview, the encoder, the two windows' StudioBridge
writes, the camera and screen listing, the chat and stream commands). The
demo settings return their problems instead of logging them. SessionView
and Tab methods that need no Default list type no longer ask for one.
28 new tests cover the logic.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
faumarayandClaude Sonnet 5.5 committed 2026-10-20 16:01:12 +03:00
1 parent 03f4a92161
commit ce0e6e1f62
7 files changed
+3421 -2275

No files matched your search

+12 -8
View File
@@ -192,7 +192,9 @@ impl<L: Default> Tab<L> {
cache: Default::default(),
}
}
}
impl<L> Tab<L> {
/// A private chat (on the Direct Messages page, not in the chat strip).
pub fn is_private(&self) -> bool {
matches!(self.target, ChatTarget::Private(_))
@@ -356,7 +358,7 @@ impl<L: Default> Default for SessionView<L> {
}
}
impl<L: Default> SessionView<L> {
impl<L> SessionView<L> {
/// Streams can be watched and shared: TeamSpeak 6, connected with voice.
pub fn streams_available(&self) -> bool {
self.capabilities.streams && self.state.voice == VoiceState::Connected
@@ -441,13 +443,6 @@ impl<L: Default> SessionView<L> {
true
}
/// A new tab for `target`, read as far as the store says.
pub fn new_tab(&self, target: ChatTarget, title: String) -> Tab<L> {
let mut tab = Tab::new(target, title);
tab.read_from(&self.reads);
tab
}
/// The session's gateway offers this feature
/// (`voelin_gateway_proto::feature`).
pub fn gateway_has(&self, feature: &str) -> bool {
@@ -482,6 +477,15 @@ impl<L: Default> SessionView<L> {
}
}
impl<L: Default> SessionView<L> {
/// A new tab for `target`, read as far as the store says.
pub fn new_tab(&self, target: ChatTarget, title: String) -> Tab<L> {
let mut tab = Tab::new(target, title);
tab.read_from(&self.reads);
tab
}
}
/// The data the screens share, apart from the engine and the toolkit: the
/// servers and what is known of their sessions, the settings the screens
/// show and the dialogs' targets.
File diff suppressed because it is too large. Load diff
@@ -1,6 +1,9 @@
//! 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.
//! Decisions of the studio (what it does when) are in [`logic`].
pub mod logic;
use std::time::Duration;
+1 -1
View File
@@ -54,7 +54,7 @@ fn open_settings(dir: &Path, overrides: &[String]) -> Settings {
for key in crate::settings::page_keys() {
prefs.register(key);
}
prefs.register(&crate::studio::STUDIO_UI);
prefs.register(&crate::vm::studio::logic::STUDIO_UI);
let config = std::env::var_os("VOELIN_CONFIG")
.map(PathBuf::from)
.or_else(|| Some(dir.join("config.toml")).filter(|p| p.exists()));
File diff suppressed because it is too large. Load diff
File diff suppressed because it is too large. Load diff
+103
View File
@@ -0,0 +1,103 @@
//! The Stream Studio: the controller behind its page in the main window, its
//! window of its own and the phone layout (ui/screens/studio*.slint,
//! ui/studio-window.slint).
//!
//! The engine's studio (`voelin_core::studio`) composites the scenes; a
//! `Streamer` started for it encodes the composite from the start, so the
//! recording and the replay buffer need no live stream, and going live
//! attaches it to a TeamSpeak stream of our voice channel like any share.
//! The studio runs while it is shown, live or recording.
//!
//! Both windows' StudioBridge globals show the same models (shared
//! rows) and get the same values; their callbacks come here
//! (bind/studio.rs). Commands go to the studio through one task, in order.
//!
//! What the studio decides (where the stream goes, what the header says,
//! what the controls change) is `voelin_ui_vm::studio::logic`; `bind.rs` runs
//! the studio and puts the rows and values on the two windows.
mod bind;
use std::sync::Arc;
use std::sync::atomic::{AtomicBool, Ordering};
use slint::{Rgba8Pixel, SharedPixelBuffer};
use tokio::sync::mpsc;
use voelin_core::media::voelin_media::mix::SourceHandle;
use voelin_core::media::{AudioApps, Latest, Streamer};
use voelin_core::studio::scene::Source;
use voelin_core::studio::{self, Studio};
use crate::app::StudioWindow;
use crate::bind::rows::Rows;
use crate::vm;
use crate::vm::studio::Overlay;
use crate::vm::studio::logic::StudioData;
type Picture = SharedPixelBuffer<Rgba8Pixel>;
/// The models both windows show.
#[derive(Default)]
struct Models {
scenes: Rows<vm::studio_bridge::StudioScene>,
sources: Rows<vm::studio_bridge::StudioSource>,
audio: Rows<vm::studio_bridge::StudioAudio>,
layers: Rows<vm::studio_bridge::StudioLayer>,
viewers: Rows<vm::studio_bridge::StudioViewer>,
destinations: Rows<vm::studio_bridge::StudioPick>,
picks: Rows<vm::studio_bridge::StudioPick>,
/// The destination channel's chat (`studio_sync_chat`).
chat: Rows<vm::bridge::ChatLine>,
}
/// A change of the scene graph, applied in order by one task.
enum Op {
Apply(studio::Command),
/// A source for the live scene (a new scene if there is none).
Add(Source),
/// Keep the overlay sources as asked.
Overlays(Vec<Overlay>),
}
/// A running studio.
struct Running {
studio: Arc<Studio>,
/// Encodes the composite; `None` until it started (or if it failed).
streamer: Option<Streamer>,
ops: mpsc::UnboundedSender<Op>,
/// The newest preview picture, for the UI thread.
pictures: Arc<Latest<Picture>>,
/// Stops the preview thread.
stop: Arc<AtomicBool>,
tasks: Vec<tokio::task::JoinHandle<()>>,
/// The mixer's meters, about 15 times a second.
_meters: slint::Timer,
}
impl Drop for Running {
fn drop(&mut self) {
self.stop.store(true, Ordering::Relaxed);
for task in &self.tasks {
task.abort();
}
}
}
/// The studio's state on the UI thread (`App::studio`).
#[derive(Default)]
pub(crate) struct StudioState {
models: Models,
/// The main window's globals have the models.
attached: bool,
/// The studio in a window of its own.
pub(crate) window: Option<StudioWindow>,
run: Option<Running>,
starting: bool,
/// What the studio knows apart from its running parts.
data: StudioData,
/// Applications that play audio, for the audio picker.
apps: Option<AudioApps>,
/// The mixer source of each audio row.
meters: Vec<Option<SourceHandle>>,
has_preview: bool,
}