From 6887cebb90302ab0ea3ab6bf6ac3af48337fba01 Mon Sep 17 00:00:00 2001 From: selikhov Date: Sat, 3 Oct 2026 06:39:18 +0300 Subject: [PATCH 01/15] voelin-ui: lay out the Stream Studio screens The studio gets its screens before its controller: scenes, sources, the preview with LIVE, timer and viewers, the audio mixer, the stream chat, the stream settings with the simulcast layers, the bottom bar and the dialogs, arranged three ways (a page of the main window, a window of its own, the phone layout). They read only the StudioBridge and StudioNav globals, so the second window, which has globals of its own, shows the same pieces once Rust fills both. A button in each top bar opens it. Work in progress: nothing in Rust drives these globals yet. Co-Authored-By: Claude Opus 5.5 --- crates/voelin-ui/ui/app.slint | 13 +- .../voelin-ui/ui/assets/icons/app-window.svg | 18 + crates/voelin-ui/ui/assets/icons/crop.svg | 16 + crates/voelin-ui/ui/assets/icons/layers.svg | 17 + crates/voelin-ui/ui/icons.slint | 3 + crates/voelin-ui/ui/nav.slint | 12 + .../voelin-ui/ui/screens/studio-parts.slint | 2084 +++++++++++++++++ crates/voelin-ui/ui/screens/studio.slint | 616 +++++ crates/voelin-ui/ui/shells/desktop.slint | 7 + crates/voelin-ui/ui/shells/mobile.slint | 9 + crates/voelin-ui/ui/studio-bridge.slint | 322 +++ crates/voelin-ui/ui/studio-window.slint | 136 ++ 12 files changed, 3251 insertions(+), 2 deletions(-) create mode 100644 crates/voelin-ui/ui/assets/icons/app-window.svg create mode 100644 crates/voelin-ui/ui/assets/icons/crop.svg create mode 100644 crates/voelin-ui/ui/assets/icons/layers.svg create mode 100644 crates/voelin-ui/ui/screens/studio-parts.slint create mode 100644 crates/voelin-ui/ui/screens/studio.slint create mode 100644 crates/voelin-ui/ui/studio-bridge.slint create mode 100644 crates/voelin-ui/ui/studio-window.slint diff --git a/crates/voelin-ui/ui/app.slint b/crates/voelin-ui/ui/app.slint index 60c278d..193d199 100644 --- a/crates/voelin-ui/ui/app.slint +++ b/crates/voelin-ui/ui/app.slint @@ -24,11 +24,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; @@ -104,7 +109,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; } @@ -144,6 +149,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 { @@ -159,7 +167,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 { @@ -167,6 +175,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 { } } } } diff --git a/crates/voelin-ui/ui/assets/icons/app-window.svg b/crates/voelin-ui/ui/assets/icons/app-window.svg new file mode 100644 index 0000000..b28c600 --- /dev/null +++ b/crates/voelin-ui/ui/assets/icons/app-window.svg @@ -0,0 +1,18 @@ + + + + + + + diff --git a/crates/voelin-ui/ui/assets/icons/crop.svg b/crates/voelin-ui/ui/assets/icons/crop.svg new file mode 100644 index 0000000..39e18e5 --- /dev/null +++ b/crates/voelin-ui/ui/assets/icons/crop.svg @@ -0,0 +1,16 @@ + + + + + diff --git a/crates/voelin-ui/ui/assets/icons/layers.svg b/crates/voelin-ui/ui/assets/icons/layers.svg new file mode 100644 index 0000000..667affe --- /dev/null +++ b/crates/voelin-ui/ui/assets/icons/layers.svg @@ -0,0 +1,17 @@ + + + + + + diff --git a/crates/voelin-ui/ui/icons.slint b/crates/voelin-ui/ui/icons.slint index 8bc4ac5..30607a4 100644 --- a/crates/voelin-ui/ui/icons.slint +++ b/crates/voelin-ui/ui/icons.slint @@ -5,6 +5,7 @@ export global Icons { out property activity: @image-url("assets/icons/activity.svg"); + out property app-window: @image-url("assets/icons/app-window.svg"); out property arrow-left: @image-url("assets/icons/arrow-left.svg"); out property arrow-right: @image-url("assets/icons/arrow-right.svg"); out property at-sign: @image-url("assets/icons/at-sign.svg"); @@ -27,6 +28,7 @@ export global Icons { out property coffee: @image-url("assets/icons/coffee.svg"); out property compass: @image-url("assets/icons/compass.svg"); out property copy: @image-url("assets/icons/copy.svg"); + out property crop: @image-url("assets/icons/crop.svg"); out property crown: @image-url("assets/icons/crown.svg"); out property download: @image-url("assets/icons/download.svg"); out property more-vertical: @image-url("assets/icons/ellipsis-vertical.svg"); @@ -53,6 +55,7 @@ export global Icons { out property image: @image-url("assets/icons/image.svg"); out property info: @image-url("assets/icons/info.svg"); out property keyboard: @image-url("assets/icons/keyboard.svg"); + out property layers: @image-url("assets/icons/layers.svg"); out property layout-grid: @image-url("assets/icons/layout-grid.svg"); out property leaf: @image-url("assets/icons/leaf.svg"); out property library: @image-url("assets/icons/library.svg"); diff --git a/crates/voelin-ui/ui/nav.slint b/crates/voelin-ui/ui/nav.slint index 20d2bc9..8674314 100644 --- a/crates/voelin-ui/ui/nav.slint +++ b/crates/voelin-ui/ui/nav.slint @@ -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. @@ -104,6 +107,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); + } + } + public function select-server(id: int) { show(Page.server); Bridge.select-server(id); diff --git a/crates/voelin-ui/ui/screens/studio-parts.slint b/crates/voelin-ui/ui/screens/studio-parts.slint new file mode 100644 index 0000000..1113dc3 --- /dev/null +++ b/crates/voelin-ui/ui/screens/studio-parts.slint @@ -0,0 +1,2084 @@ +// The Stream Studio's pieces: scenes, sources, the preview, the audio +// mixer, the stream chat, the stream settings, the bottom bar and the +// dialogs. studio.slint arranges them for the main window, the detached +// window and the phone. They read only StudioBridge / StudioNav (and the +// theme), so they work in the second window too. + +import { Theme } from "../theme.slint"; +import { Icons } from "../icons.slint"; +import { ChatLine } from "../bridge.slint"; +import { StudioBridge, StudioNav, StudioScene, StudioSource, StudioAudio, StudioLayer, StudioPick, StudioSourceForm, StudioSettingsForm } from "../studio-bridge.slint"; +import { Icon, Button, ButtonKind, IconButton, Avatar, LiveBadge, Chip, Toggle, ToggleRow, TextField, Field, Select, Slider, Meter, SegmentedTabs, Divider, Spinner, PopupMenu, MenuEntry, Modal, Tooltip, RichText, ListView, ScrollView } from "../components/index.slint"; + +// Icons of source and audio kinds. +export global StudioKinds { + public pure function icon(kind: string) -> image { + kind == "screen" || kind == "portal" || kind == "monitor" ? Icons.monitor + : kind == "window" ? Icons.app-window + : kind == "camera" ? Icons.video + : kind == "image" ? Icons.image + : kind == "text" ? Icons.type + : kind == "colour" ? Icons.palette + : kind == "pattern" ? Icons.layout-grid + : kind == "microphone" ? Icons.mic + : kind == "desktop" ? Icons.volume-2 + : kind == "app" ? Icons.gamepad-2 + : kind == "window-audio" ? Icons.app-window + : kind == "tone" ? Icons.audio-lines + : Icons.layers + } +} + +// A rounded panel of the studio (surface, border). +export component StudioPanel inherits Rectangle { + background: Theme.surface.transparentize(0.08); + border-radius: Theme.radius-xl; + border-width: 1px; + border-color: Theme.border; + clip: true; +} + +// A panel's title row with actions (@children) at the right. +export component PanelTitle inherits HorizontalLayout { + in property text; + in property note; + in property icon; + in property compact; + spacing: Theme.space-3; + min-height: compact ? 28px : 34px; + if root.icon.width > 0: Icon { + source: root.icon; + size: Theme.icon-md; + tint: Theme.text-secondary; + y: (parent.height - self.height) / 2; + } + HorizontalLayout { + horizontal-stretch: 1; + spacing: Theme.space-2; + Text { + text: root.text; + color: Theme.text; + font-size: root.compact ? Theme.font-md : Theme.font-lg; + font-weight: Theme.weight-semibold; + vertical-alignment: center; + overflow: elide; + accessible-role: AccessibleRole.text; + } + if root.note != "": Text { + text: root.note; + color: Theme.text-muted; + font-size: root.compact ? Theme.font-sm : Theme.font-body; + vertical-alignment: center; + overflow: elide; + } + } + @children +} + +// One scene: click to make it live, double-click (or the menu) to rename. +component SceneRow inherits Rectangle { + in property scene; + in property compact; + height: compact ? 46px : 58px; + border-radius: Theme.radius-md; + background: scene.live ? @linear-gradient(90deg, Theme.accent-pressed 0%, Theme.accent 100%) + : touch.has-hover ? Theme.surface-3 : Theme.surface-2.transparentize(0.45); + border-width: 1px; + border-color: scene.live ? Theme.accent-hover : Theme.border; + accessible-role: AccessibleRole.list-item; + accessible-label: scene.name; + accessible-description: scene.detail; + accessible-item-selectable: true; + accessible-item-selected: scene.live; + accessible-action-default => { StudioBridge.select-scene(scene.id); } + if scene.live: Rectangle { + x: -Theme.glow-width; + y: -Theme.glow-width; + width: parent.width + 2 * Theme.glow-width; + height: parent.height + 2 * Theme.glow-width; + border-radius: Theme.radius-md + Theme.glow-width; + border-width: Theme.glow-width; + border-color: Theme.glow; + } + touch := TouchArea { + mouse-cursor: MouseCursor.pointer; + clicked => { StudioBridge.select-scene(scene.id); } + double-clicked => { StudioNav.rename-scene(scene.id, scene.name); } + pointer-event(e) => { + if e.button == PointerEventButton.right && e.kind == PointerEventKind.up { + menu.show(self.mouse-x, self.mouse-y); + } + } + HorizontalLayout { + padding-left: Theme.space-4; + padding-right: Theme.space-2; + spacing: Theme.space-4; + Icon { + source: StudioKinds.icon(scene.kind); + size: root.compact ? 20px : 24px; + tint: scene.live ? Theme.on-accent : Theme.icon; + y: (parent.height - self.height) / 2; + } + VerticalLayout { + alignment: center; + horizontal-stretch: 1; + Text { + text: scene.name; + color: scene.live ? Theme.on-accent : Theme.text; + font-size: root.compact ? Theme.font-body : Theme.font-md; + font-weight: Theme.weight-semibold; + overflow: elide; + } + if scene.detail != "": Text { + text: scene.detail; + color: scene.live ? #ffffffc0 : Theme.text-muted; + font-size: root.compact ? Theme.font-xs : Theme.font-sm; + overflow: elide; + } + } + if touch.has-hover: IconButton { + icon: Icons.more-vertical; + label: @tr("Scene menu"); + size: 28px; + icon-size: Theme.icon-sm; + tint: scene.live ? Theme.on-accent : Theme.icon; + y: (parent.height - self.height) / 2; + clicked => { menu.show(root.width - 200px, root.height); } + } + } + } + menu := PopupMenu { + menu-width: 200px; + entries: [ + { text: @tr("Go live with this scene"), icon: Icons.radio, enabled: !scene.live }, + { text: @tr("Rename"), icon: Icons.pencil, enabled: true }, + { text: @tr("Remove"), icon: Icons.trash-2, enabled: true, danger: true, separator: true }, + ]; + activated(i) => { + if i == 0 { + StudioBridge.select-scene(scene.id); + } else if i == 1 { + StudioNav.rename-scene(scene.id, scene.name); + } else { + StudioBridge.remove-scene(scene.id); + } + } + } +} + +// The scenes: the live one highlighted; "Add Scene" at the end. +export component ScenesCard inherits StudioPanel { + in property compact; + VerticalLayout { + padding: root.compact ? Theme.space-3 : Theme.space-4; + spacing: Theme.space-3; + PanelTitle { + text: @tr("Scenes"); + compact: root.compact; + IconButton { + icon: Icons.plus; + label: @tr("Add scene"); + size: 30px; + y: (parent.height - self.height) / 2; + clicked => { StudioBridge.add-scene(); } + } + } + ListView { + vertical-stretch: 1; + accessible-label: @tr("Scenes"); + for scene in StudioBridge.scenes: VerticalLayout { + padding-top: 3px; + padding-bottom: 3px; + padding-left: 3px; + padding-right: 3px; + SceneRow { + scene: scene; + compact: root.compact; + } + } + } + if !root.compact: Rectangle { + height: 46px; + border-radius: Theme.radius-md; + background: add-touch.has-hover ? Theme.surface-3 : Theme.surface-2.transparentize(0.45); + border-width: 1px; + border-color: Theme.border; + accessible-role: AccessibleRole.button; + accessible-label: @tr("Add Scene"); + accessible-action-default => { StudioBridge.add-scene(); } + add-touch := TouchArea { + mouse-cursor: MouseCursor.pointer; + clicked => { StudioBridge.add-scene(); } + } + HorizontalLayout { + padding-left: Theme.space-4; + spacing: Theme.space-4; + Icon { + source: Icons.plus; + size: Theme.icon-md; + tint: Theme.text-secondary; + y: (parent.height - self.height) / 2; + } + Text { + text: @tr("Add Scene"); + color: Theme.text-secondary; + font-size: Theme.font-md; + vertical-alignment: center; + horizontal-stretch: 1; + } + } + } + } +} + +// One source of the live scene: visibility and a menu. +component SourceRow inherits Rectangle { + in property source; + in property compact; + height: compact ? 36px : 42px; + border-radius: Theme.radius-md; + background: touch.has-hover ? Theme.surface-3 : Theme.surface-2.transparentize(0.45); + border-width: 1px; + border-color: Theme.border; + accessible-role: AccessibleRole.list-item; + accessible-label: source.name; + accessible-description: source.error != "" ? source.error : source.info; + touch := TouchArea { + double-clicked => { StudioNav.edit-source(source.id); } + pointer-event(e) => { + if e.button == PointerEventButton.right && e.kind == PointerEventKind.up { + menu.show(self.mouse-x, self.mouse-y); + } + } + HorizontalLayout { + padding-left: Theme.space-3; + padding-right: Theme.space-1; + spacing: Theme.space-3; + Icon { + source: StudioKinds.icon(source.kind); + size: root.compact ? Theme.icon-sm : Theme.icon-md; + tint: source.visible ? Theme.icon : Theme.text-disabled; + y: (parent.height - self.height) / 2; + } + Text { + text: source.name; + color: source.visible ? Theme.text : Theme.text-muted; + font-size: root.compact ? Theme.font-sm : Theme.font-body; + vertical-alignment: center; + horizontal-stretch: 1; + overflow: elide; + } + if source.locked: Icon { + source: Icons.lock; + size: 14px; + tint: Theme.text-muted; + y: (parent.height - self.height) / 2; + } + if source.error != "": Tooltip { + text: source.error; + width: 20px; + height: 20px; + y: (parent.height - self.height) / 2; + Icon { + source: Icons.triangle-alert; + size: 16px; + tint: Theme.warning; + } + } + IconButton { + icon: source.visible ? Icons.eye : Icons.eye-off; + label: source.visible ? @tr("Hide {}", source.name) : @tr("Show {}", source.name); + size: root.compact ? 26px : 30px; + icon-size: Theme.icon-sm; + tint: source.visible ? Theme.accent-text : Theme.text-muted; + y: (parent.height - self.height) / 2; + clicked => { StudioBridge.toggle-source(source.id); } + } + IconButton { + icon: Icons.more-vertical; + label: @tr("Source menu"); + size: root.compact ? 26px : 30px; + icon-size: Theme.icon-sm; + y: (parent.height - self.height) / 2; + clicked => { menu.show(root.width - 220px, root.height); } + } + } + } + menu := PopupMenu { + entries: [ + { text: @tr("Transform…"), icon: Icons.maximize, enabled: !source.locked }, + { text: @tr("Crop…"), icon: Icons.crop, enabled: !source.locked }, + { text: @tr("Opacity…"), icon: Icons.circle, enabled: true }, + { text: source.locked ? @tr("Unlock") : @tr("Lock"), icon: Icons.lock, enabled: true }, + { text: source.background == "keep" ? @tr("Blur background") : @tr("Background effect off"), icon: Icons.sparkles, enabled: source.kind == "camera", separator: true }, + { text: @tr("Background effect…"), icon: Icons.sliders-horizontal, enabled: source.kind == "camera" }, + { text: @tr("Bring forward"), icon: Icons.chevron-up, enabled: !source.front, separator: true }, + { text: @tr("Send backward"), icon: Icons.chevron-down, enabled: !source.back }, + { text: @tr("Rename…"), icon: Icons.pencil, enabled: true, separator: true }, + { text: @tr("Remove"), icon: Icons.trash-2, enabled: true, danger: true }, + ]; + activated(i) => { + if i == 0 || i == 1 || i == 2 || i == 5 || i == 8 { + StudioNav.edit-source(source.id); + } else if i == 3 { + StudioBridge.source-action(source.id, "lock"); + } else if i == 4 { + StudioBridge.source-action(source.id, source.background == "keep" ? "bg-blur" : "bg-keep"); + } else if i == 6 { + StudioBridge.source-action(source.id, "up"); + } else if i == 7 { + StudioBridge.source-action(source.id, "down"); + } else { + StudioBridge.source-action(source.id, "remove"); + } + } + } +} + +// Adds a source of the kind picked from its menu. +export component AddSourceButton inherits Rectangle { + in property size: 30px; + width: size; + height: size; + IconButton { + icon: Icons.plus; + label: @tr("Add source"); + size: root.size; + clicked => { menu.show(root.width - 200px, root.height + 4px); } + } + menu := PopupMenu { + menu-width: 200px; + entries: [ + { text: @tr("Screen"), icon: Icons.monitor, enabled: true }, + { text: @tr("Window"), icon: Icons.app-window, enabled: true }, + { text: @tr("Camera"), icon: Icons.video, enabled: true }, + { text: @tr("Image"), icon: Icons.image, enabled: true, separator: true }, + { text: @tr("Text"), icon: Icons.type, enabled: true }, + { text: @tr("Colour"), icon: Icons.palette, enabled: true }, + ]; + activated(i) => { + if i == 0 { + StudioNav.pick("screen"); + } else if i == 1 { + StudioNav.pick("window"); + } else if i == 2 { + StudioNav.pick("camera"); + } else if i == 3 { + StudioNav.new-source("image"); + } else if i == 4 { + StudioNav.new-source("text"); + } else { + StudioNav.new-source("colour"); + } + } + } +} + +// The sources of the live scene, front first. +export component SourcesCard inherits StudioPanel { + in property compact; + VerticalLayout { + padding: root.compact ? Theme.space-3 : Theme.space-4; + spacing: Theme.space-3; + PanelTitle { + text: @tr("Sources"); + compact: root.compact; + AddSourceButton { + y: (parent.height - self.height) / 2; + } + } + if StudioBridge.sources.length == 0: Text { + text: StudioBridge.scenes.length == 0 ? @tr("Add a scene first.") : @tr("Nothing in this scene yet: add a screen, a window, a camera, an image, text or a colour."); + color: Theme.text-muted; + font-size: Theme.font-sm; + wrap: word-wrap; + } + ListView { + vertical-stretch: 1; + accessible-label: @tr("Sources"); + for source in StudioBridge.sources: VerticalLayout { + padding-top: 3px; + padding-bottom: 3px; + padding-left: 1px; + padding-right: 1px; + SourceRow { + source: source; + compact: root.compact; + } + } + } + } +} + +// A dark chip over the preview (timer, viewers). +component PreviewChip inherits Rectangle { + in property text; + in property icon; + in property large: true; + height: large ? 30px : 24px; + width: row.preferred-width; + border-radius: Theme.radius-sm; + background: #060a18c0; + border-width: 1px; + border-color: #ffffff1c; + accessible-role: AccessibleRole.text; + accessible-label: text; + row := HorizontalLayout { + padding-left: root.large ? Theme.space-3 : Theme.space-2; + padding-right: self.padding-left; + spacing: Theme.space-2; + if root.icon.width > 0: Icon { + source: root.icon; + size: root.large ? 16px : 13px; + tint: #ffffff; + y: (parent.height - self.height) / 2; + } + Text { + text: root.text; + color: #ffffff; + font-size: root.large ? Theme.font-body : Theme.font-xs; + font-weight: Theme.weight-medium; + vertical-alignment: center; + } + } +} + +// The live composite with its badges: LIVE and the time, viewers and +// participants, the title. +export component StudioPreview inherits Rectangle { + in property large: true; + // The title and destination at the bottom. + in property caption: true; + // Output size and rate on the picture (the detached window). + in property controls; + property ratio: StudioBridge.status.output-height > 0 ? StudioBridge.status.output-width / StudioBridge.status.output-height : 16 / 9; + accessible-role: AccessibleRole.image; + accessible-label: @tr("Stream preview"); + screen := Rectangle { + width: min(parent.width, parent.height * root.ratio); + height: self.width / root.ratio; + x: (parent.width - self.width) / 2; + y: 0; + border-radius: Theme.radius-md; + background: #03060f; + border-width: 1px; + border-color: Theme.border; + clip: true; + Image { + width: parent.width; + height: parent.height; + source: StudioBridge.preview; + image-fit: contain; + visible: StudioBridge.has-preview; + } + if !StudioBridge.has-preview: VerticalLayout { + alignment: center; + spacing: Theme.space-3; + HorizontalLayout { + alignment: center; + Spinner { + size: 22px; + running: StudioBridge.status.running; + } + } + Text { + text: StudioBridge.status.running ? @tr("Waiting for the first picture…") : @tr("Starting the studio…"); + color: Theme.text-secondary; + horizontal-alignment: center; + } + } + // The caption: title • destination. + if root.caption && (StudioBridge.form.title != "" || StudioBridge.status.destination != ""): Rectangle { + y: parent.height - self.height; + height: root.large ? 64px : 44px; + background: @linear-gradient(180deg, #00000000 0%, #000000a0 100%); + HorizontalLayout { + padding-left: root.large ? Theme.space-5 : Theme.space-3; + padding-right: Theme.space-5; + padding-bottom: root.large ? Theme.space-4 : Theme.space-2; + alignment: start; + Text { + vertical-alignment: bottom; + text: StudioBridge.form.title != "" && StudioBridge.status.destination != "" ? StudioBridge.form.title + " • " + StudioBridge.status.destination + : StudioBridge.form.title != "" ? StudioBridge.form.title : StudioBridge.status.destination; + color: #ffffffe0; + font-size: root.large ? Theme.font-sm : Theme.font-xs; + overflow: elide; + } + } + } + // LIVE and the time, or REC. + HorizontalLayout { + x: root.large ? Theme.space-4 : Theme.space-3; + y: root.large ? Theme.space-4 : Theme.space-3; + height: root.large ? 30px : 24px; + spacing: Theme.space-3; + if StudioBridge.status.live: LiveBadge { + large: true; + height: parent.height; + } + if StudioBridge.status.starting: LiveBadge { + text: @tr("STARTING"); + large: true; + height: parent.height; + background: Theme.warning; + } + if StudioBridge.status.live: PreviewChip { + text: StudioBridge.status.elapsed; + large: root.large; + } + if StudioBridge.status.recording: PreviewChip { + icon: Icons.record; + text: @tr("REC {}", StudioBridge.status.recorded); + large: root.large; + } + if !StudioBridge.status.live && !StudioBridge.status.starting && !StudioBridge.status.recording: PreviewChip { + text: @tr("PREVIEW"); + large: root.large; + } + } + // Viewers and participants. + if StudioBridge.status.live && !root.controls: HorizontalLayout { + x: parent.width - self.width - (root.large ? Theme.space-4 : Theme.space-3); + y: root.large ? Theme.space-4 : Theme.space-3; + height: root.large ? 30px : 24px; + spacing: Theme.space-2; + PreviewChip { + icon: Icons.eye; + text: StudioBridge.status.viewers; + large: root.large; + accessible-label: @tr("{} watching", StudioBridge.status.viewers); + } + PreviewChip { + icon: Icons.user; + text: StudioBridge.status.participants; + large: root.large; + accessible-label: @tr("{} joined the stream", StudioBridge.status.participants); + } + } + // Output size and rate. + if root.controls: HorizontalLayout { + x: parent.width - self.width - Theme.space-3; + y: Theme.space-3; + height: 30px; + spacing: 0px; + Rectangle { + width: res.preferred-width; + border-radius: Theme.radius-sm; + background: #060a18c8; + border-width: 1px; + border-color: #ffffff1c; + res := HorizontalLayout { + padding-left: Theme.space-3; + padding-right: Theme.space-3; + spacing: Theme.space-3; + Text { + text: StudioBridge.status.output-height + "p"; + color: #ffffff; + font-size: Theme.font-sm; + vertical-alignment: center; + } + Rectangle { + width: 1px; + background: #ffffff30; + } + Text { + text: @tr("{} FPS", StudioBridge.status.fps); + color: #ffffff; + font-size: Theme.font-sm; + vertical-alignment: center; + } + Icon { + source: Icons.chevron-down; + size: 14px; + tint: #ffffff; + y: (parent.height - self.height) / 2; + } + } + TouchArea { + mouse-cursor: MouseCursor.pointer; + clicked => { output-menu.show(0, parent.height + 4px); } + } + output-menu := PopupMenu { + menu-width: 180px; + entries: [ + { text: "720p · 30 FPS", enabled: true }, + { text: "720p · 60 FPS", enabled: true }, + { text: "1080p · 30 FPS", enabled: true }, + { text: "1080p · 60 FPS", enabled: true }, + { text: "1440p · 60 FPS", enabled: true }, + { text: "2160p · 30 FPS", enabled: true }, + ]; + activated(i) => { + if i == 0 { + StudioBridge.set-output("1280", "720", "30"); + } else if i == 1 { + StudioBridge.set-output("1280", "720", "60"); + } else if i == 2 { + StudioBridge.set-output("1920", "1080", "30"); + } else if i == 3 { + StudioBridge.set-output("1920", "1080", "60"); + } else if i == 4 { + StudioBridge.set-output("2560", "1440", "60"); + } else { + StudioBridge.set-output("3840", "2160", "30"); + } + } + } + } + } + } +} + +// The broadcast mark of the studio's header. +export component StudioMark inherits Rectangle { + in property size: 44px; + width: size; + height: size; + Icon { + source: Icons.radio; + size: root.size * 0.8; + tint: Theme.accent-text; + } +} + +// "Stream Studio — streaming to …", connection, format, pop out. +export component StudioHeader inherits HorizontalLayout { + spacing: Theme.space-4; + min-height: 56px; + StudioMark { + y: (parent.height - self.height) / 2; + } + VerticalLayout { + alignment: center; + horizontal-stretch: 1; + spacing: 2px; + Text { + text: @tr("Stream Studio"); + color: Theme.text; + font-size: Theme.font-xl; + font-weight: Theme.weight-semibold; + overflow: elide; + } + Text { + text: StudioBridge.status.destination != "" ? (StudioBridge.status.live ? @tr("Streaming to {}", StudioBridge.status.destination) : @tr("Goes live to {}", StudioBridge.status.destination)) : StudioBridge.status.hint; + color: StudioBridge.status.destination != "" ? Theme.accent-text : Theme.text-muted; + font-size: Theme.font-body; + overflow: elide; + } + } + VerticalLayout { + alignment: center; + spacing: Theme.space-2; + HorizontalLayout { + alignment: end; + spacing: Theme.space-2; + Rectangle { + width: 9px; + height: 9px; + y: (parent.height - self.height) / 2; + border-radius: 4.5px; + background: StudioBridge.status.quality >= 4 ? Theme.success : StudioBridge.status.quality == 3 ? Theme.success : StudioBridge.status.quality == 2 ? Theme.warning : StudioBridge.status.quality == 1 ? Theme.danger : Theme.offline; + } + Text { + text: StudioBridge.status.quality-text; + color: StudioBridge.status.quality >= 3 ? Theme.success : StudioBridge.status.quality == 2 ? Theme.warning : StudioBridge.status.quality == 1 ? Theme.danger : Theme.text-muted; + font-size: Theme.font-sm; + vertical-alignment: center; + } + } + HorizontalLayout { + alignment: end; + spacing: Theme.space-3; + Text { + text: StudioBridge.status.format; + color: Theme.text-secondary; + font-size: Theme.font-sm; + vertical-alignment: center; + } + Tooltip { + text: StudioBridge.status.details; + below: true; + width: 20px; + height: 20px; + Icon { + source: Icons.info; + size: 18px; + tint: Theme.text-secondary; + } + } + } + } + IconButton { + icon: StudioBridge.status.detached ? Icons.minimize-2 : Icons.external-link; + label: StudioBridge.status.detached ? @tr("Back into the main window") : @tr("Open in its own window"); + y: (parent.height - self.height) / 2; + clicked => { + if StudioBridge.status.detached { + StudioBridge.dock(); + } else { + StudioBridge.detach(); + } + } + } +} + +// One audio source: meter, gain, mute, a menu. +component MixerRow inherits Rectangle { + in property audio; + in property index; + in property compact; + // The phone: a chevron opens the menu. + in property phone; + height: compact ? 56px : 68px; + accessible-role: AccessibleRole.groupbox; + accessible-label: audio.name; + HorizontalLayout { + spacing: root.compact ? Theme.space-3 : Theme.space-4; + Rectangle { + width: root.compact ? 36px : 44px; + height: self.width; + y: (parent.height - self.height) / 2; + border-radius: Theme.radius-md; + background: Theme.surface-3; + Icon { + source: StudioKinds.icon(audio.kind); + size: root.compact ? 18px : 22px; + tint: audio.muted ? Theme.text-disabled : Theme.icon; + } + } + VerticalLayout { + alignment: center; + horizontal-stretch: 1; + spacing: Theme.space-2; + HorizontalLayout { + spacing: Theme.space-2; + Text { + text: audio.name; + color: audio.muted ? Theme.text-muted : Theme.text; + font-size: root.compact ? Theme.font-sm : Theme.font-body; + font-weight: Theme.weight-medium; + overflow: elide; + max-width: self.preferred-width; + } + if audio.detail != "": Text { + text: "(" + audio.detail + ")"; + color: Theme.text-muted; + font-size: root.compact ? Theme.font-sm : Theme.font-body; + overflow: elide; + horizontal-stretch: 1; + } + if audio.detail == "": Rectangle { + horizontal-stretch: 1; + } + if audio.error != "": Tooltip { + text: audio.error; + width: 18px; + height: 18px; + Icon { + source: Icons.triangle-alert; + size: 15px; + tint: Theme.warning; + } + } + Text { + text: audio.muted ? @tr("muted") : @tr("{} dB", round(audio.gain-db * 10) / 10); + color: Theme.text-secondary; + font-size: root.compact ? Theme.font-xs : Theme.font-sm; + horizontal-alignment: right; + min-width: 52px; + } + } + HorizontalLayout { + spacing: Theme.space-4; + Meter { + y: (parent.height - self.height) / 2; + height: root.compact ? 8px : 9px; + segments: 16; + floor: -60; + level: audio.level; + active: !audio.muted; + min-width: 60px; + horizontal-stretch: 1; + accessible-label: @tr("{} level", audio.name); + } + Slider { + width: root.phone ? 46% : 44%; + horizontal-stretch: 0; + y: (parent.height - self.height) / 2; + minimum: -60; + maximum: 20; + step: 0.5; + value: audio.gain-db; + label: @tr("{} gain", audio.name); + changed(v) => { StudioBridge.set-gain(root.index, v, false); } + released(v) => { StudioBridge.set-gain(root.index, v, true); } + } + } + } + if !root.phone: IconButton { + icon: audio.muted ? Icons.volume-x : Icons.volume-2; + label: audio.muted ? @tr("Unmute {}", audio.name) : @tr("Mute {}", audio.name); + checked: audio.muted; + danger: true; + size: 32px; + icon-size: Theme.icon-md; + y: (parent.height - self.height) / 2; + clicked => { StudioBridge.toggle-mute(root.index); } + } + IconButton { + icon: root.phone ? Icons.chevron-right : Icons.more-vertical; + label: @tr("{} menu", audio.name); + size: 30px; + icon-size: Theme.icon-sm; + y: (parent.height - self.height) / 2; + clicked => { menu.show(root.width - 200px, root.height - 8px); } + } + } + menu := PopupMenu { + menu-width: 200px; + entries: [ + { text: audio.muted ? @tr("Unmute") : @tr("Mute"), icon: audio.muted ? Icons.volume-2 : Icons.volume-x, enabled: true }, + { text: @tr("Reset to 0 dB"), icon: Icons.refresh-cw, enabled: audio.gain-db != 0 }, + { text: @tr("Remove"), icon: Icons.trash-2, enabled: true, danger: true, separator: true }, + ]; + activated(i) => { + if i == 0 { + StudioBridge.toggle-mute(root.index); + } else if i == 1 { + StudioBridge.set-gain(root.index, 0, true); + } else { + StudioBridge.remove-audio(root.index); + } + } + } +} + +// The audio of the stream (the streamer's mixer). +export component MixerCard inherits StudioPanel { + in property compact; + VerticalLayout { + padding: root.compact ? Theme.space-3 : Theme.space-4; + padding-top: root.compact ? Theme.space-3 : Theme.space-3; + spacing: Theme.space-1; + PanelTitle { + text: @tr("Audio Mixer"); + compact: root.compact; + IconButton { + icon: Icons.plus; + label: @tr("Add an audio source"); + size: 30px; + y: (parent.height - self.height) / 2; + clicked => { StudioNav.pick-audio(); } + } + IconButton { + icon: Icons.settings; + label: @tr("Stream audio settings"); + size: 30px; + y: (parent.height - self.height) / 2; + clicked => { StudioBridge.advanced-settings(); } + } + } + Divider { } + if StudioBridge.audio.length == 0: Text { + text: @tr("No audio: add your microphone, the desktop or an application."); + color: Theme.text-muted; + font-size: Theme.font-sm; + wrap: word-wrap; + } + ListView { + vertical-stretch: 1; + accessible-label: @tr("Audio sources"); + for audio[i] in StudioBridge.audio: VerticalLayout { + MixerRow { + audio: audio; + index: i; + compact: root.compact; + } + if i < StudioBridge.audio.length - 1: Divider { } + } + } + } +} + +// A chat line, compact. +component ChatRow inherits Rectangle { + in property line; + min-height: body.preferred-height; + accessible-role: AccessibleRole.list-item; + accessible-label: line.author + ": " + line.text; + body := HorizontalLayout { + padding-top: line.continued ? 1px : Theme.space-3; + padding-left: Theme.space-2; + padding-right: Theme.space-3; + spacing: Theme.space-3; + VerticalLayout { + width: 34px; + alignment: start; + if !line.continued: Avatar { + size: 34px; + initials: line.initials; + tint: line.tint; + label: line.author; + } + } + VerticalLayout { + horizontal-stretch: 1; + spacing: 1px; + if !line.continued: HorizontalLayout { + spacing: Theme.space-3; + alignment: start; + Text { + text: line.author; + color: line.relayed ? Theme.accent-text : Theme.name-text; + font-size: Theme.font-body; + font-weight: Theme.weight-medium; + } + Text { + text: line.time; + color: Theme.text-muted; + font-size: Theme.font-xs; + vertical-alignment: center; + } + } + if !line.rich: Text { + text: line.text; + color: Theme.text; + font-size: Theme.font-body; + wrap: word-wrap; + } + if line.rich: RichText { + runs: line.runs; + emoji-size: line.jumbo ? 32px : Theme.font-body * 1.35; + } + } + } +} + +// The chat of the channel the stream goes to. +export component StudioChat inherits StudioPanel { + VerticalLayout { + padding-top: Theme.space-3; + padding-bottom: Theme.space-3; + spacing: Theme.space-1; + HorizontalLayout { + padding-left: Theme.space-4; + padding-right: Theme.space-3; + PanelTitle { + icon: Icons.users; + text: @tr("Stream Chat"); + note: StudioBridge.chat-name != "" ? "(" + StudioBridge.chat-name + ")" : ""; + IconButton { + icon: Icons.external-link; + label: @tr("Open the channel chat"); + size: 30px; + icon-size: Theme.icon-sm; + enabled: StudioBridge.chat-name != ""; + y: (parent.height - self.height) / 2; + clicked => { StudioBridge.open-chat(); } + } + } + } + Divider { } + if StudioBridge.chat-name == "": Text { + vertical-stretch: 1; + text: @tr("Join a voice channel on a TeamSpeak 6 server: its chat shows here."); + color: Theme.text-muted; + font-size: Theme.font-sm; + horizontal-alignment: center; + vertical-alignment: center; + wrap: word-wrap; + } + if StudioBridge.chat-name != "": ListView { + vertical-stretch: 1; + accessible-label: @tr("Stream chat"); + for line in StudioBridge.chat: ChatRow { + line: line; + } + } + HorizontalLayout { + padding-left: Theme.space-3; + padding-right: Theme.space-3; + padding-top: Theme.space-2; + Rectangle { + height: 44px; + border-radius: Theme.radius-md; + background: Theme.surface-2; + border-width: 1px; + border-color: input.has-focus ? Theme.accent : Theme.border; + HorizontalLayout { + padding-left: Theme.space-4; + padding-right: Theme.space-1; + spacing: Theme.space-1; + input := TextField { + bare: true; + enabled: StudioBridge.chat-name != ""; + placeholder: StudioBridge.chat-name != "" ? @tr("Message goes to {}…", StudioBridge.chat-name) : @tr("No chat yet"); + label: @tr("Message to the stream chat"); + accepted(text) => { + if text != "" { + StudioBridge.send-chat(text); + self.clear(); + } + } + } + IconButton { + icon: Icons.send; + label: @tr("Send"); + enabled: input.text != ""; + tint: input.text != "" ? Theme.accent-text : Theme.text-muted; + size: 36px; + y: (parent.height - self.height) / 2; + clicked => { + if input.text != "" { + StudioBridge.send-chat(input.text); + input.clear(); + } + } + } + } + } + } + } +} + +// The destination drop-down: channel and server of each choice. +export component DestinationSelect inherits Rectangle { + in property compact; + property current: StudioBridge.form.destination >= 0 && StudioBridge.form.destination < StudioBridge.destinations.length ? StudioBridge.destinations[StudioBridge.form.destination] : ""; + height: compact ? 40px : 52px; + border-radius: Theme.radius-md; + background: touch.has-hover ? Theme.surface-3 : Theme.surface-2; + border-width: 1px; + border-color: Theme.border; + accessible-role: AccessibleRole.combobox; + accessible-label: @tr("Destination"); + accessible-value: current; + accessible-action-default => { popup.show(); } + touch := TouchArea { + enabled: StudioBridge.destinations.length > 0; + mouse-cursor: MouseCursor.pointer; + clicked => { popup.show(); } + } + HorizontalLayout { + padding-left: Theme.space-3; + padding-right: Theme.space-3; + spacing: Theme.space-3; + Image { + width: root.compact ? 22px : 30px; + height: self.width; + y: (parent.height - self.height) / 2; + source: Icons.logo; + } + VerticalLayout { + alignment: center; + horizontal-stretch: 1; + Text { + text: root.current == "" ? @tr("No TeamSpeak 6 voice connection") : root.current; + color: root.current == "" ? Theme.text-muted : Theme.text; + font-size: root.compact ? Theme.font-sm : Theme.font-md; + overflow: elide; + } + } + Icon { + source: Icons.chevron-down; + size: Theme.icon-sm; + tint: Theme.text-secondary; + y: (parent.height - self.height) / 2; + } + } + popup := PopupWindow { + x: 0; + y: root.height + 4px; + width: root.width; + close-policy: PopupClosePolicy.close-on-click-outside; + Rectangle { + border-radius: Theme.radius-md; + background: Theme.surface-3; + border-width: 1px; + border-color: Theme.border-strong; + VerticalLayout { + padding: Theme.space-2; + for item[i] in StudioBridge.destinations: Rectangle { + height: Theme.control-height; + border-radius: Theme.radius-sm; + background: i == StudioBridge.form.destination ? Theme.accent-soft : item-touch.has-hover ? Theme.surface-4 : transparent; + item-touch := TouchArea { + mouse-cursor: MouseCursor.pointer; + clicked => { + StudioBridge.edit-form("destination", "" + i); + popup.close(); + } + } + HorizontalLayout { + padding-left: Theme.space-3; + Text { + text: item; + color: Theme.text; + vertical-alignment: center; + overflow: elide; + } + } + } + } + } + } +} + +// A label above a field. +component FormLabel inherits Text { + color: Theme.text-secondary; + font-size: Theme.font-sm; + font-weight: Theme.weight-medium; +} + +// A multi-line text box (the go-live message). +component TextBox inherits Rectangle { + in-out property text <=> input.text; + in property placeholder; + callback edited(string); + min-height: 64px; + border-radius: Theme.radius-md; + background: Theme.surface-2; + border-width: 1px; + border-color: input.has-focus ? Theme.accent : Theme.border; + forward-focus: input; + TouchArea { + mouse-cursor: MouseCursor.text; + clicked => { input.focus(); } + } + HorizontalLayout { + padding: Theme.space-3; + padding-left: Theme.space-4; + Rectangle { + Text { + width: 100%; + height: 100%; + vertical-alignment: top; + text: input.text == "" ? root.placeholder : ""; + color: Theme.text-muted; + wrap: word-wrap; + } + input := TextInput { + width: 100%; + height: 100%; + single-line: false; + wrap: word-wrap; + color: Theme.text; + selection-background-color: Theme.accent-soft; + selection-foreground-color: Theme.text; + accessible-label: root.placeholder; + edited => { root.edited(self.text); } + } + } + } +} + +// A switch row of the settings panel. +component SwitchRow inherits HorizontalLayout { + in property text; + in property checked; + in property key; + min-height: 36px; + spacing: Theme.space-3; + Text { + text: root.text; + color: Theme.text; + vertical-alignment: center; + horizontal-stretch: 1; + overflow: elide; + } + Toggle { + y: (parent.height - self.height) / 2; + checked: root.checked; + label: root.text; + toggled(on) => { StudioBridge.edit-form(root.key, on ? "true" : "false"); } + } +} + +// One simulcast layer as fields. +component LayerRow inherits HorizontalLayout { + in property layer; + in property index; + spacing: Theme.space-2; + function apply() { + StudioBridge.set-layer(root.index, { + size: size.text, + scale: layer.scale, + fps: fps.text, + bitrate: bitrate.text, + min-bitrate: layer.min-bitrate, + }); + } + size := TextField { + text: layer.size != "" ? layer.size : layer.scale + "×"; + label: @tr("Layer size, or a scale like 0.5×"); + placeholder: "1280x720"; + font-size: Theme.font-sm; + accepted => { root.apply(); } + } + fps := TextField { + text: layer.fps; + label: @tr("Layer frame rate"); + placeholder: @tr("fps"); + font-size: Theme.font-sm; + max-width: 64px; + horizontal-stretch: 0; + accepted => { root.apply(); } + } + bitrate := TextField { + text: layer.bitrate; + label: @tr("Layer bitrate in kbit/s"); + placeholder: "kbit/s"; + font-size: Theme.font-sm; + accepted => { root.apply(); } + } + IconButton { + icon: Icons.x; + label: @tr("Remove the layer"); + size: 28px; + icon-size: Theme.icon-sm; + y: (parent.height - self.height) / 2; + clicked => { StudioBridge.remove-layer(root.index); } + } +} + +// Destination, title, game, go-live message, overlays, quality. +export component StreamSettings inherits VerticalLayout { + // The detached window: destination, quality and title only. + in property compact; + padding: root.compact ? Theme.space-3 : Theme.space-5; + spacing: root.compact ? Theme.space-2 : Theme.space-4; + PanelTitle { + text: @tr("Stream Settings"); + compact: root.compact; + } + if root.compact: Divider { } + VerticalLayout { + spacing: Theme.space-2; + FormLabel { text: @tr("Destination"); } + DestinationSelect { + compact: root.compact; + } + } + if root.compact: VerticalLayout { + spacing: Theme.space-2; + FormLabel { text: @tr("Quality"); } + Select { + model: ["720p 30 FPS", "720p 60 FPS", "1080p 30 FPS", "1080p 60 FPS", "1440p 60 FPS", "2160p 30 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 if v == "1080p 60 FPS" { + StudioBridge.set-output("1920", "1080", "60"); + } else if v == "1440p 60 FPS" { + StudioBridge.set-output("2560", "1440", "60"); + } else { + StudioBridge.set-output("3840", "2160", "30"); + } + } + } + } + VerticalLayout { + spacing: Theme.space-2; + FormLabel { text: @tr("Stream Title"); } + TextField { + text: StudioBridge.form.title; + placeholder: @tr("What are you streaming?"); + label: @tr("Stream title"); + edited(t) => { StudioBridge.edit-form("title", t); } + } + } + if !root.compact: VerticalLayout { + spacing: Theme.space-2; + FormLabel { text: @tr("Game"); } + TextField { + text: StudioBridge.form.game; + placeholder: @tr("Game or category"); + label: @tr("Game or category"); + edited(t) => { StudioBridge.edit-form("game", t); } + } + } + if !root.compact: VerticalLayout { + spacing: Theme.space-2; + FormLabel { text: @tr("Go Live Message (optional)"); } + TextBox { + text: StudioBridge.form.message; + placeholder: @tr("Sent to the channel chat when you go live"); + edited(t) => { StudioBridge.edit-form("message", t); } + } + } + if !root.compact: VerticalLayout { + spacing: Theme.space-1; + SwitchRow { + text: @tr("Show Viewer Count"); + key: "show-viewers"; + checked: StudioBridge.form.show-viewers; + } + SwitchRow { + text: @tr("Show Chat Overlay"); + key: "show-chat"; + checked: StudioBridge.form.show-chat; + } + SwitchRow { + text: @tr("Show Now Playing"); + key: "show-now-playing"; + checked: StudioBridge.form.show-now-playing; + } + SwitchRow { + text: @tr("Enable Stream Audio"); + key: "audio"; + checked: StudioBridge.form.audio; + } + } + if !root.compact: Divider { } + if !root.compact: Rectangle { + height: 44px; + border-radius: Theme.radius-md; + background: adv.has-hover ? Theme.surface-3 : transparent; + accessible-role: AccessibleRole.button; + accessible-label: @tr("Advanced Settings"); + accessible-action-default => { StudioBridge.advanced-settings(); } + adv := TouchArea { + mouse-cursor: MouseCursor.pointer; + clicked => { StudioBridge.advanced-settings(); } + } + HorizontalLayout { + spacing: Theme.space-4; + Icon { + source: Icons.settings; + size: Theme.icon-md; + tint: Theme.text-secondary; + y: (parent.height - self.height) / 2; + } + Text { + text: @tr("Advanced Settings"); + color: Theme.text; + font-size: Theme.font-md; + vertical-alignment: center; + horizontal-stretch: 1; + } + Icon { + source: Icons.chevron-right; + size: Theme.icon-md; + tint: Theme.text-secondary; + y: (parent.height - self.height) / 2; + } + } + } + if !root.compact: Divider { } + // Output size and rate: presets, or any numbers. + if !root.compact: VerticalLayout { + spacing: Theme.space-2; + FormLabel { text: @tr("Output (width × height, FPS)"); } + HorizontalLayout { + spacing: Theme.space-2; + out-w := TextField { + text: StudioBridge.status.output-width; + input-type: number; + label: @tr("Output width"); + accepted => { StudioBridge.set-output(out-w.text, out-h.text, out-fps.text); } + } + Text { + text: "×"; + color: Theme.text-muted; + vertical-alignment: center; + } + out-h := TextField { + text: StudioBridge.status.output-height; + input-type: number; + label: @tr("Output height"); + accepted => { StudioBridge.set-output(out-w.text, out-h.text, out-fps.text); } + } + out-fps := TextField { + text: StudioBridge.status.fps; + input-type: number; + label: @tr("Output frame rate"); + max-width: 64px; + horizontal-stretch: 0; + accepted => { StudioBridge.set-output(out-w.text, out-h.text, out-fps.text); } + } + } + HorizontalLayout { + spacing: Theme.space-2; + Button { + small: true; + text: "720p"; + horizontal-stretch: 1; + checked: StudioBridge.status.output-height == 720; + clicked => { StudioBridge.set-output("1280", "720", out-fps.text); } + } + Button { + small: true; + text: "1080p"; + horizontal-stretch: 1; + checked: StudioBridge.status.output-height == 1080; + clicked => { StudioBridge.set-output("1920", "1080", out-fps.text); } + } + Button { + small: true; + text: "1440p"; + horizontal-stretch: 1; + checked: StudioBridge.status.output-height == 1440; + clicked => { StudioBridge.set-output("2560", "1440", out-fps.text); } + } + Button { + small: true; + text: "30"; + horizontal-stretch: 1; + checked: StudioBridge.status.fps == 30; + clicked => { StudioBridge.set-output(out-w.text, out-h.text, "30"); } + } + Button { + small: true; + text: "60"; + horizontal-stretch: 1; + checked: StudioBridge.status.fps == 60; + clicked => { StudioBridge.set-output(out-w.text, out-h.text, "60"); } + } + } + } + if !root.compact: VerticalLayout { + spacing: Theme.space-2; + FormLabel { text: StudioBridge.layers.length == 0 ? @tr("Bitrate (kbit/s)") : @tr("Simulcast layers (size or scale, FPS, kbit/s)"); } + if StudioBridge.layers.length == 0: TextField { + text: StudioBridge.form.bitrate; + input-type: number; + label: @tr("Bitrate in kbit/s"); + accepted(t) => { StudioBridge.edit-form("bitrate", t); } + } + for layer[i] in StudioBridge.layers: LayerRow { + layer: layer; + index: i; + } + Button { + small: true; + icon: Icons.layers; + text: StudioBridge.layers.length == 0 ? @tr("Add simulcast layers") : @tr("Add a layer"); + clicked => { StudioBridge.add-layer(); } + } + } +} + +// The Record Clip button and its menu: recording, replay length, folder. +component RecordButton inherits Rectangle { + in property compact; + height: compact ? 44px : 52px; + width: row.preferred-width; + border-radius: Theme.radius-md; + background: main.has-hover ? Theme.surface-3 : Theme.surface-2; + border-width: 1px; + border-color: StudioBridge.status.recording ? Theme.live : Theme.border-strong; + accessible-role: AccessibleRole.button; + accessible-label: @tr("Record Clip"); + accessible-description: StudioBridge.status.replay-seconds > 0 ? @tr("Saves the last {} seconds", StudioBridge.status.replay-seconds) : @tr("The replay buffer is off"); + accessible-action-default => { StudioBridge.save-clip(); } + row := HorizontalLayout { + Rectangle { + width: inner.preferred-width; + main := TouchArea { + mouse-cursor: MouseCursor.pointer; + clicked => { StudioBridge.save-clip(); } + } + inner := HorizontalLayout { + padding-left: root.compact ? Theme.space-4 : Theme.space-5; + padding-right: Theme.space-4; + spacing: Theme.space-3; + Rectangle { + width: 20px; + height: 20px; + y: (parent.height - self.height) / 2; + border-radius: 10px; + border-width: 2px; + border-color: Theme.live; + Rectangle { + width: 10px; + height: 10px; + border-radius: 5px; + background: Theme.live; + } + } + Text { + text: StudioBridge.status.recording ? @tr("Recording {}", StudioBridge.status.recorded) : @tr("Record Clip"); + color: Theme.text; + font-size: root.compact ? Theme.font-body : Theme.font-md; + font-weight: Theme.weight-medium; + vertical-alignment: center; + } + } + } + Rectangle { + width: 1px; + background: Theme.border-strong; + } + Rectangle { + width: 40px; + background: more.has-hover ? Theme.surface-4 : transparent; + border-top-right-radius: Theme.radius-md; + border-bottom-right-radius: Theme.radius-md; + accessible-role: AccessibleRole.button; + accessible-label: @tr("Recording options"); + accessible-action-default => { menu.show(0, root.height + 4px); } + more := TouchArea { + mouse-cursor: MouseCursor.pointer; + clicked => { menu.show(root.width - 260px, root.height + 4px); } + } + Icon { + source: Icons.chevron-down; + size: Theme.icon-sm; + tint: Theme.text-secondary; + } + } + } + menu := PopupMenu { + menu-width: 260px; + entries: [ + { text: StudioBridge.status.replay-seconds > 0 ? @tr("Save the last {} seconds", StudioBridge.status.replay-seconds) : @tr("Save clip (replay buffer off)"), icon: Icons.download, enabled: StudioBridge.status.replay-seconds > 0 }, + { text: StudioBridge.status.recording ? @tr("Stop recording") : @tr("Start recording"), icon: StudioBridge.status.recording ? Icons.square : Icons.record, enabled: StudioBridge.status.running, separator: true }, + { text: @tr("Replay length…"), icon: Icons.clock, enabled: true }, + { text: @tr("Open the recordings folder"), icon: Icons.folder-open, enabled: true }, + ]; + activated(i) => { + if i == 0 { + StudioBridge.save-clip(); + } else if i == 1 { + StudioBridge.toggle-recording(); + } else if i == 2 { + StudioNav.open-settings(); + } else { + StudioBridge.open-recordings(); + } + } + } +} + +// The bottom bar: share a window or the screen, record, go live, end. +export component StudioActions inherits HorizontalLayout { + in property compact; + property h: compact ? 44px : 52px; + spacing: compact ? Theme.space-3 : Theme.space-4; + alignment: center; + if !root.compact: Button { + min-height: root.h; + icon: Icons.app-window; + text: @tr("Share Window"); + y: (parent.height - self.height) / 2; + clicked => { StudioBridge.share("window"); } + } + Button { + min-height: root.h; + icon: Icons.monitor; + text: @tr("Share Screen"); + y: (parent.height - self.height) / 2; + clicked => { StudioBridge.share("screen"); } + } + RecordButton { + compact: root.compact; + y: (parent.height - self.height) / 2; + } + Rectangle { + min-width: root.compact ? 170px : 210px; + height: root.h; + y: (parent.height - self.height) / 2; + Rectangle { + x: -Theme.glow-width; + y: -Theme.glow-width; + width: parent.width + 2 * Theme.glow-width; + height: parent.height + 2 * Theme.glow-width; + border-radius: Theme.radius-md + Theme.glow-width; + border-width: StudioBridge.status.can-go-live ? Theme.glow-width : 0px; + border-color: Theme.glow; + } + Button { + width: parent.width; + min-height: root.h; + kind: ButtonKind.primary; + icon: Icons.radio; + text: StudioBridge.status.live ? @tr("Live") : StudioBridge.status.starting ? @tr("Starting…") : @tr("Go Live"); + enabled: StudioBridge.status.can-go-live; + accessible-description: StudioBridge.status.hint; + clicked => { StudioBridge.go-live(); } + } + } + Button { + min-width: root.compact ? 170px : 210px; + min-height: root.h; + kind: ButtonKind.danger; + icon: Icons.square; + text: @tr("End Stream"); + enabled: StudioBridge.status.live || StudioBridge.status.starting; + y: (parent.height - self.height) / 2; + clicked => { StudioBridge.end-stream(); } + } +} + +// Requests to watch the stream (when not everyone is let in). +export component ViewerRequests inherits VerticalLayout { + spacing: Theme.space-2; + for viewer in StudioBridge.viewers: HorizontalLayout { + spacing: Theme.space-2; + if viewer.state == "requested": Text { + text: @tr("{} wants to watch", viewer.name); + color: Theme.warning; + vertical-alignment: center; + horizontal-stretch: 1; + overflow: elide; + } + if viewer.state == "requested": Button { + small: true; + kind: ButtonKind.primary; + text: @tr("Accept"); + clicked => { StudioBridge.respond-viewer(viewer.client, true); } + } + if viewer.state == "requested": Button { + small: true; + text: @tr("Deny"); + clicked => { StudioBridge.respond-viewer(viewer.client, false); } + } + } +} + +// A labelled numeric field of the source dialog. +component NumberField inherits VerticalLayout { + in property label; + in-out property value <=> field.text; + in property placeholder; + spacing: Theme.space-1; + Text { + text: root.label; + color: Theme.text-muted; + font-size: Theme.font-xs; + } + field := TextField { + placeholder: root.placeholder; + label: root.label; + font-size: Theme.font-sm; + } +} + +// Add or edit a source: name, what it shows, where, crop, opacity, +// background effect. +component SourceDialog inherits Modal { + in-out property form; + callback done(); + property adding: form.id < 0; + title: adding ? (form.kind == "text" ? @tr("Add text") : form.kind == "colour" ? @tr("Add a colour") : @tr("Add an image")) : form.name; + subtitle: adding ? @tr("Added to the live scene.") : @tr("Position, size and crop are in output pixels."); + icon: StudioKinds.icon(form.kind); + card-width: 560px; + card-height: 680px; + dismissed => { done(); } + ScrollView { + vertical-stretch: 1; + VerticalLayout { + spacing: Theme.space-4; + padding-right: Theme.space-3; + Field { + label: @tr("Name"); + TextField { + text <=> form.name; + label: @tr("Name"); + } + } + if form.kind == "text": Field { + label: @tr("Text (a new line with \\n)"); + TextField { + text <=> form.text; + label: @tr("Text"); + } + } + if form.kind == "text" || form.kind == "colour": HorizontalLayout { + spacing: Theme.space-3; + if form.kind == "text": NumberField { + label: @tr("Size (px)"); + value <=> form.text-size; + } + NumberField { + label: @tr("Colour (#rrggbb or #rrggbbaa)"); + value <=> form.colour; + } + } + if form.kind == "image": Field { + label: @tr("Image file (PNG or JPEG)"); + TextField { + text <=> form.path; + placeholder: "/home/you/Pictures/overlay.png"; + label: @tr("Image file"); + icon: Icons.image; + } + } + if form.kind == "camera": ToggleRow { + text: @tr("Mirror"); + description: @tr("As in a mirror (front cameras)"); + checked <=> form.mirror; + } + Text { + text: @tr("Transform"); + color: Theme.text; + font-weight: Theme.weight-semibold; + } + HorizontalLayout { + spacing: Theme.space-3; + NumberField { + label: "X"; + value <=> form.x; + } + NumberField { + label: "Y"; + value <=> form.y; + } + NumberField { + label: @tr("Width"); + value <=> form.width; + placeholder: @tr("own"); + } + NumberField { + label: @tr("Height"); + value <=> form.height; + placeholder: @tr("own"); + } + NumberField { + label: @tr("Scale"); + value <=> form.scale; + } + } + SegmentedTabs { + model: [@tr("Fit inside"), @tr("Fill (crop)"), @tr("Stretch")]; + current-index: form.fit == "cover" ? 1 : form.fit == "stretch" ? 2 : 0; + label: @tr("How it fills its box"); + selected(i) => { form.fit = i == 1 ? "cover" : i == 2 ? "stretch" : "contain"; } + } + Text { + text: @tr("Crop (source pixels)"); + color: Theme.text; + font-weight: Theme.weight-semibold; + } + HorizontalLayout { + spacing: Theme.space-3; + NumberField { + label: @tr("Left"); + value <=> form.crop-left; + } + NumberField { + label: @tr("Top"); + value <=> form.crop-top; + } + NumberField { + label: @tr("Right"); + value <=> form.crop-right; + } + NumberField { + label: @tr("Bottom"); + value <=> form.crop-bottom; + } + } + HorizontalLayout { + spacing: Theme.space-4; + Text { + text: @tr("Opacity"); + color: Theme.text; + font-weight: Theme.weight-semibold; + vertical-alignment: center; + } + Slider { + y: (parent.height - self.height) / 2; + minimum: 0; + maximum: 100; + value <=> form.opacity; + label: @tr("Opacity"); + } + Text { + text: @tr("{}%", round(form.opacity)); + color: Theme.text-secondary; + vertical-alignment: center; + width: 44px; + } + } + HorizontalLayout { + spacing: Theme.space-6; + ToggleRow { + text: @tr("Visible"); + checked <=> form.visible; + } + ToggleRow { + text: @tr("Locked"); + checked <=> form.locked; + } + } + if form.kind == "camera": VerticalLayout { + spacing: Theme.space-3; + Text { + text: @tr("Background effect"); + color: Theme.text; + font-weight: Theme.weight-semibold; + } + SegmentedTabs { + model: [@tr("Off"), @tr("Blur"), @tr("Image"), @tr("Colour")]; + current-index: form.background == "blur" ? 1 : form.background == "image" ? 2 : form.background == "colour" ? 3 : 0; + label: @tr("Background effect"); + selected(i) => { form.background = i == 1 ? "blur" : i == 2 ? "image" : i == 3 ? "colour" : "keep"; } + } + if form.background == "blur": NumberField { + label: @tr("Blur strength (% of the picture's height)"); + value <=> form.blur; + } + if form.background == "image": NumberField { + label: @tr("Background image file"); + value <=> form.background-path; + } + if form.background == "colour": NumberField { + label: @tr("Background colour (#rrggbb)"); + value <=> form.background-colour; + } + Text { + text: @tr("The subject is found by a simple oval for now: what is outside it is replaced."); + color: Theme.text-muted; + font-size: Theme.font-xs; + wrap: word-wrap; + } + } + } + } + HorizontalLayout { + alignment: end; + spacing: Theme.space-3; + Button { + text: @tr("Cancel"); + clicked => { root.done(); } + } + Button { + kind: ButtonKind.primary; + text: root.adding ? @tr("Add") : @tr("Apply"); + clicked => { + if root.adding { + StudioBridge.add-source(root.form); + } else { + StudioBridge.apply-source(root.form); + } + root.done(); + } + } + } +} + +// Pick a screen, window, camera or audio source. +component PickDialog inherits Modal { + in property kind; + callback done(); + title: kind == "screen" ? @tr("Share a screen") : kind == "window" ? @tr("Share a window") : kind == "camera" ? @tr("Add a camera") : @tr("Add an audio source"); + subtitle: kind == "audio" ? @tr("Mixed into the stream's audio.") : @tr("Added to the live scene."); + icon: StudioKinds.icon(kind == "audio" ? "microphone" : kind); + card-width: 520px; + card-height: 540px; + dismissed => { done(); } + if StudioBridge.picks.length == 0: Text { + vertical-stretch: 1; + text: @tr("Nothing found."); + color: Theme.text-muted; + horizontal-alignment: center; + vertical-alignment: center; + } + if StudioBridge.picks.length > 0: ListView { + vertical-stretch: 1; + for pick[i] in StudioBridge.picks: Rectangle { + height: 52px; + border-radius: Theme.radius-md; + background: pick-touch.has-hover ? Theme.surface-3 : transparent; + accessible-role: AccessibleRole.button; + accessible-label: pick.name; + accessible-description: pick.detail; + accessible-action-default => { + if root.kind == "audio" { + StudioBridge.add-audio(i); + } else { + StudioBridge.add-picked(root.kind, i); + } + root.done(); + } + pick-touch := TouchArea { + mouse-cursor: MouseCursor.pointer; + clicked => { + if root.kind == "audio" { + StudioBridge.add-audio(i); + } else { + StudioBridge.add-picked(root.kind, i); + } + root.done(); + } + } + HorizontalLayout { + padding-left: Theme.space-3; + padding-right: Theme.space-3; + spacing: Theme.space-4; + Rectangle { + width: 36px; + height: 36px; + y: (parent.height - self.height) / 2; + border-radius: Theme.radius-md; + background: Theme.surface-3; + Icon { + source: StudioKinds.icon(pick.kind); + size: 18px; + } + } + VerticalLayout { + alignment: center; + horizontal-stretch: 1; + Text { + text: pick.name; + color: Theme.text; + overflow: elide; + } + if pick.detail != "": Text { + text: pick.detail; + color: Theme.text-muted; + font-size: Theme.font-sm; + overflow: elide; + } + } + } + } + } +} + +// Rename a scene. +component SceneDialog inherits Modal { + callback done(); + title: @tr("Rename scene"); + icon: Icons.pencil; + card-width: 420px; + card-height: 220px; + dismissed => { done(); } + name := TextField { + text: StudioNav.scene-name; + label: @tr("Scene name"); + accepted(t) => { + StudioBridge.rename-scene(StudioNav.scene-id, t); + root.done(); + } + } + HorizontalLayout { + alignment: end; + spacing: Theme.space-3; + Button { + text: @tr("Cancel"); + clicked => { root.done(); } + } + Button { + kind: ButtonKind.primary; + text: @tr("Rename"); + clicked => { + StudioBridge.rename-scene(StudioNav.scene-id, name.text); + root.done(); + } + } + } +} + +// The studio's own settings: replay buffer, recordings, preview. +component StudioSettingsDialog inherits Modal { + in-out property form; + callback done(); + title: @tr("Studio Settings"); + subtitle: @tr("Clips, recordings and the preview. Stream quality is in the stream settings."); + icon: Icons.settings; + card-width: 520px; + card-height: 560px; + dismissed => { done(); } + ScrollView { + vertical-stretch: 1; + VerticalLayout { + spacing: Theme.space-4; + padding-right: Theme.space-3; + Field { + label: @tr("Replay buffer (seconds, 0: off)"); + hint: @tr("Record Clip saves this much of what was streamed or composed."); + TextField { + text <=> form.replay-seconds; + input-type: number; + icon: Icons.clock; + label: @tr("Replay buffer in seconds"); + } + } + Field { + label: @tr("Replay memory (MB)"); + hint: @tr("Beyond this the oldest part goes to a temporary file."); + TextField { + text <=> form.replay-memory; + input-type: number; + icon: Icons.hard-drive; + label: @tr("Replay memory in megabytes"); + } + } + Field { + label: @tr("Recordings and clips folder"); + hint: @tr("Empty: a Voelin folder in your videos folder."); + TextField { + text <=> form.recording-dir; + icon: Icons.folder-open; + label: @tr("Recordings folder"); + } + } + HorizontalLayout { + spacing: Theme.space-3; + Field { + label: @tr("Preview width (pixels)"); + TextField { + text <=> form.preview-width; + input-type: number; + label: @tr("Preview width"); + } + } + Field { + label: @tr("Preview FPS"); + TextField { + text <=> form.preview-fps; + input-type: number; + label: @tr("Preview frame rate"); + } + } + } + } + } + HorizontalLayout { + alignment: end; + spacing: Theme.space-3; + Button { + text: @tr("Cancel"); + clicked => { root.done(); } + } + Button { + kind: ButtonKind.primary; + text: @tr("Save"); + clicked => { + StudioBridge.apply-settings(root.form); + root.done(); + } + } + } +} + +// The dialog StudioNav asks for, over the whole studio. +export component StudioDialogs inherits Rectangle { + if StudioNav.dialog == "pick": PickDialog { + kind: StudioNav.pick-kind; + done => { StudioNav.close(); } + } + if StudioNav.dialog == "source": SourceDialog { + form <=> StudioNav.source-form; + done => { StudioNav.close(); } + } + if StudioNav.dialog == "scene": SceneDialog { + done => { StudioNav.close(); } + } + if StudioNav.dialog == "settings": StudioSettingsDialog { + form <=> StudioNav.settings-form; + done => { StudioNav.close(); } + } +} diff --git a/crates/voelin-ui/ui/screens/studio.slint b/crates/voelin-ui/ui/screens/studio.slint new file mode 100644 index 0000000..d79b33b --- /dev/null +++ b/crates/voelin-ui/ui/screens/studio.slint @@ -0,0 +1,616 @@ +// 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; + StudioPanel { + vertical-stretch: 1.7; + 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: 250px; + 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 { + width: 250px * max(1.0, Theme.font-scale); + padding-left: Theme.space-3; + } + 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 text; + in property icon; + in property 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 kind; + in property title; + in property subtitle; + in property icon; + // A visible source of this kind is in the live scene. + in property 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 index; + property 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; + 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; + } + } + 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; + } +} diff --git a/crates/voelin-ui/ui/shells/desktop.slint b/crates/voelin-ui/ui/shells/desktop.slint index 32d1ef3..542f125 100644 --- a/crates/voelin-ui/ui/shells/desktop.slint +++ b/crates/voelin-ui/ui/shells/desktop.slint @@ -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 and streams"); diff --git a/crates/voelin-ui/ui/shells/mobile.slint b/crates/voelin-ui/ui/shells/mobile.slint index c75a72d..25bd331 100644 --- a/crates/voelin-ui/ui/shells/mobile.slint +++ b/crates/voelin-ui/ui/shells/mobile.slint @@ -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"); diff --git a/crates/voelin-ui/ui/studio-bridge.slint b/crates/voelin-ui/ui/studio-bridge.slint new file mode 100644 index 0000000..2e1556b --- /dev/null +++ b/crates/voelin-ui/ui/studio-bridge.slint @@ -0,0 +1,322 @@ +// 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, + // 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 status; + in property form; + // The composite, downscaled (the engine's preview tap). + in property preview; + in property has-preview; + in property <[StudioScene]> scenes; + in property <[StudioSource]> sources; + in property <[StudioAudio]> audio; + in property <[StudioLayer]> layers; + // "Chill Zone • Starfall Community", one per server the stream can go to. + in property <[string]> destinations; + in property <[StudioViewer]> viewers; + // The chat of the channel the stream goes to, and its name. + in property <[ChatLine]> chat; + in property chat-name; + // Filled right before a picker shows. + in property <[StudioPick]> picks; + // Where recordings and clips go. + in property recordings-dir; + + // 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 share(string); + 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 dialog; + // What the picker picks: screen, window, camera, audio + in-out property pick-kind; + in-out property source-form; + // The scene being renamed. + in-out property scene-id: -1; + in-out property scene-name; + in-out property 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 = ""; + } +} diff --git a/crates/voelin-ui/ui/studio-window.slint b/crates/voelin-ui/ui/studio-window.slint new file mode 100644 index 0000000..658837b --- /dev/null +++ b/crates/voelin-ui/ui/studio-window.slint @@ -0,0 +1,136 @@ +// 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 { Theme } from "theme.slint"; +import { Icons } from "icons.slint"; +import { StudioBridge, StudioNav } from "studio-bridge.slint"; +import { IconButton } 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; + + 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.25; + 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: 220px; + spacing: Theme.space-3; + MixerCard { + compact: true; + horizontal-stretch: 1.15; + } + StudioPanel { + horizontal-stretch: 1; + 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; + } +} From eaf91927cc7721e0371088e318e025b56d1cba37 Mon Sep 17 00:00:00 2001 From: selikhov Date: Sat, 3 Oct 2026 06:44:55 +0300 Subject: [PATCH 02/15] voelin-media: apply a camera's new background effect A source's input was kept when its background changed as long as both the old and the new effect needed a mask, but the background filter is set up with its effect when the input starts. So switching a camera from blur to a colour or an image, or changing the blur strength, changed the scene and nothing on screen. The input now restarts whenever the effect differs, as it already did when the effect went on or off. Co-Authored-By: Claude Opus 5.5 --- crates/voelin-media/src/studio/mod.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/voelin-media/src/studio/mod.rs b/crates/voelin-media/src/studio/mod.rs index 3ed24fb..b444c58 100644 --- a/crates/voelin-media/src/studio/mod.rs +++ b/crates/voelin-media/src/studio/mod.rs @@ -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(); From 0acc5349544ce833a7fa13d454776f09039f0b22 Mon Sep 17 00:00:00 2001 From: selikhov Date: Sat, 3 Oct 2026 07:07:12 +0300 Subject: [PATCH 03/15] voelin-ui: drive the Stream Studio from the engine The studio screens now run on the engine's studio: scenes and sources are its scene graph (switch, add, rename, remove, reorder, show, lock, transform, crop, opacity, background effect), the preview is its preview tap turned into pictures on a thread of its own (latest wins, so a busy UI skips frames instead of holding up the composite), and a Streamer started for it encodes the composite from the start, so Record Clip and recordings work before going live. Going live starts a TeamSpeak stream in our voice channel and attaches that streamer to it, then tells the studio; viewers, requests and the connection quality (the viewers' bandwidth estimates and the composed frame rate) show in the header. The audio mixer is stream.audio_sources with the mixer's meters, read lock-free about 15 times a second; a gain drag goes to the mixer at once and is stored at the end. The stream settings are a new studio.ui key; title, game and go-live message, and three switches that keep overlay text sources (viewer count, chat, now playing) in the live scene. The game goes into the stream's name, which is all a TeamSpeak stream has and what the gateway's directory shows. Layers, bitrate and output size are the stream.* and studio.* keys, followed while streaming. The detached window has its own globals; the same models are set on both and both are wired to this controller. With VOELIN_DEMO_UI the studio runs from synthetic sources and tones on settings in memory, and VOELIN_OPEN=studio[:window|live|record|] opens each state for screenshots, which now also capture the studio's window. Co-Authored-By: Claude Opus 5.5 --- crates/voelin-ui/src/app.rs | 11 + crates/voelin-ui/src/appearance.rs | 1 + crates/voelin-ui/src/bind/mod.rs | 6 +- crates/voelin-ui/src/bind/studio.rs | 137 ++ crates/voelin-ui/src/dev.rs | 44 +- crates/voelin-ui/src/lib.rs | 1 + crates/voelin-ui/src/studio.rs | 2044 +++++++++++++++++ crates/voelin-ui/src/video.rs | 42 +- crates/voelin-ui/src/vm/mod.rs | 1 + crates/voelin-ui/src/vm/studio.rs | 727 ++++++ .../voelin-ui/ui/screens/studio-parts.slint | 4 +- crates/voelin-ui/ui/studio-bridge.slint | 3 - 12 files changed, 3011 insertions(+), 10 deletions(-) create mode 100644 crates/voelin-ui/src/bind/studio.rs create mode 100644 crates/voelin-ui/src/studio.rs create mode 100644 crates/voelin-ui/src/vm/studio.rs diff --git a/crates/voelin-ui/src/app.rs b/crates/voelin-ui/src/app.rs index 578b06d..6e52435 100644 --- a/crates/voelin-ui/src/app.rs +++ b/crates/voelin-ui/src/app.rs @@ -48,6 +48,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())); @@ -260,6 +261,8 @@ pub(crate) struct App { pub open_client_pending: bool, /// The notices are in the About page's model. pub notices_loaded: bool, + /// The Stream Studio (studio.rs). + pub studio: crate::studio::StudioState, } thread_local! { @@ -443,6 +446,7 @@ pub fn run(options: RunOptions) -> Result<()> { autoshare: switches.autoshare, open_client_pending: switches.open_client, notices_loaded: false, + studio: Default::default(), }; APP.with(|a| *a.borrow_mut() = Some(app)); crate::bind::wire(&ui); @@ -670,6 +674,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), } } diff --git a/crates/voelin-ui/src/appearance.rs b/crates/voelin-ui/src/appearance.rs index 8f82162..ac4cc5f 100644 --- a/crates/voelin-ui/src/appearance.rs +++ b/crates/voelin-ui/src/appearance.rs @@ -32,6 +32,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 diff --git a/crates/voelin-ui/src/bind/mod.rs b/crates/voelin-ui/src/bind/mod.rs index 8537548..92ff348 100644 --- a/crates/voelin-ui/src/bind/mod.rs +++ b/crates/voelin-ui/src/bind/mod.rs @@ -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::()); } diff --git a/crates/voelin-ui/src/bind/studio.rs b/crates/voelin-ui/src/bind/studio.rs new file mode 100644 index 0000000..1d3a0c1 --- /dev/null +++ b/crates/voelin-ui/src/bind/studio.rs @@ -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()); + }); +} diff --git a/crates/voelin-ui/src/dev.rs b/crates/voelin-ui/src/dev.rs index af1832e..f532bfe 100644 --- a/crates/voelin-ui/src/dev.rs +++ b/crates/voelin-ui/src/dev.rs @@ -15,7 +15,13 @@ //! appearance, or 0-4), `about`, `share`, `bookmark` (add a server), //! `emoji` (the picker), `client` (the volume dialog of the first other //! client once connected), `panel` / `no-panel` (the right panel), -//! `tab:` (phone layout). +//! `tab:` (phone layout), +//! `studio[:]`: 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 (`-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. @@ -24,7 +30,7 @@ use std::sync::Arc; use std::time::Duration; use anyhow::Result; -use slint::ComponentHandle; +use slint::{ComponentHandle, Rgba8Pixel, SharedPixelBuffer}; use voelin_core::stream::{StreamInfo, StreamKind}; use voelin_core::{Event, ObserveState, SessionState, Source, VoiceState}; use voelin_model::{ChannelInfo, ChatMessage, ChatTarget, ClientInfo, Presence, ServerFlavor}; @@ -137,6 +143,12 @@ pub(crate) fn start(ui: &MainWindow, switches: &Switches) -> Running { "panel" => nav.set_right_panel_open(true), "no-panel" => nav.set_right_panel_open(false), "tab" => nav.set_mobile_tab(mobile_tab(arg)), + "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:?}"), @@ -163,7 +175,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, top: &SharedPixelBuffer) { + 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, 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); diff --git a/crates/voelin-ui/src/lib.rs b/crates/voelin-ui/src/lib.rs index d6e2eab..0a72f7b 100644 --- a/crates/voelin-ui/src/lib.rs +++ b/crates/voelin-ui/src/lib.rs @@ -12,6 +12,7 @@ mod servers; mod settings; mod settings_page; mod streams; +mod studio; mod video; mod vm; diff --git a/crates/voelin-ui/src/studio.rs b/crates/voelin-ui/src/studio.rs new file mode 100644 index 0000000..b80a82b --- /dev/null +++ b/crates/voelin-ui/src/studio.rs @@ -0,0 +1,2044 @@ +//! 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 +//! VecModels) and get the same values; their callbacks come here +//! (bind/studio.rs). Commands go to the studio through one task, in order. + +use std::path::PathBuf; +use std::rc::Rc; +use std::sync::atomic::{AtomicBool, Ordering}; +use std::sync::{Arc, Weak}; +use std::time::Duration; + +use serde::{Deserialize, Serialize}; +use slint::{ + ComponentHandle, Model, ModelRc, Rgba8Pixel, SharedPixelBuffer, SharedString, VecModel, +}; +use tokio::sync::broadcast::error::RecvError; +use tokio::sync::{broadcast, mpsc}; +use tracing::warn; +use voelin_core::media::voelin_media::capture::SourceId; +use voelin_core::media::voelin_media::handoff::Handoff; +use voelin_core::media::voelin_media::mix::SourceHandle; +use voelin_core::media::voelin_media::{VideoFrame, convert}; +use voelin_core::media::{ + AudioApps, AudioSourceSpec, Latest, Streamer, StreamerConfigUpdate, StreamerStats, audio_apps, + audio_source_specs, screen_sources, +}; +use voelin_core::settings::{ + AudioSourceKindSetting, AudioSourceSetting, Key, Kind, STREAM_AUDIO_SOURCES, + STREAM_BITRATE_KBPS, STREAM_LAYERS, STUDIO_RECORDING_DIR, STUDIO_REPLAY_MEMORY_MB, + STUDIO_REPLAY_SECONDS, STUDIO_SCENES, Settings, layer_specs, +}; +use voelin_core::stream::{EndReason, StreamSetup, ViewerInfo, ViewerState}; +use voelin_core::studio::scene::{ + Align, Background, Colour, Fit, Scene, Scenes, Source, SourceKind, Transform, +}; +use voelin_core::studio::{self, SourceChange, Stats, Status, Studio, camera}; +use voelin_core::{Command, StreamState}; +use voelin_model::{ChatMessage, ChatTarget}; + +use crate::app::{ + App, ChatLine, Nav, Page, StudioAudio, StudioBridge, StudioForm, StudioLayer, StudioNav, + StudioPick, StudioScene, StudioSettingsForm, StudioSource, StudioSourceForm, StudioStatus, + StudioViewer, StudioWindow, Tab, Theme, later, with_app, +}; +use crate::settings::parse_positive; +use crate::video::CaptureRequest; +use crate::vm; +use crate::vm::studio::{OVERLAY_CHAT, OVERLAY_NOW_PLAYING, OVERLAY_VIEWERS, Overlay}; + +type Picture = SharedPixelBuffer; + +/// The stream settings panel and the studio's own choices. +pub static STUDIO_UI: Key = Key::new( + "studio.ui", + Kind::Json, + "Stream Studio: title, game, go-live message, overlays, stream audio, preview size.", + StudioUi::default, +); + +#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[serde(default)] +pub struct StudioUi { + pub title: String, + /// Game or category: goes into the stream's name after the title. + pub game: String, + /// Sent to the channel's chat when the stream goes live. + pub message: String, + /// Overlay sources kept in the live scene (`vm::studio::apply_overlays`). + pub show_viewers: bool, + pub show_chat: bool, + pub show_now_playing: bool, + /// The stream's audio (the mixer's sources); off: none. + pub audio: bool, + /// The preview's width in pixels (its height follows the output) and + /// frame rate. + pub preview_width: u32, + pub preview_fps: u32, +} + +impl Default for StudioUi { + fn default() -> Self { + Self { + title: String::new(), + game: String::new(), + message: String::new(), + show_viewers: false, + show_chat: false, + show_now_playing: false, + audio: true, + preview_width: 960, + preview_fps: 15, + } + } +} + +/// The models both windows show. +#[derive(Default)] +struct Models { + scenes: Rc>, + sources: Rc>, + audio: Rc>, + layers: Rc>, + viewers: Rc>, + destinations: Rc>, + picks: Rc>, + /// The chat while there is no destination. + no_chat: Rc>, +} + +/// What a picker row adds. +enum Pick { + Source { name: String, kind: SourceKind }, + Audio(AudioSourceSetting), +} + +/// Our stream from the studio. +struct Outgoing { + session: i64, + live: bool, + viewers: Vec, +} + +/// 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), +} + +/// A running studio. +struct Running { + studio: Arc, + /// Encodes the composite; `None` until it started (or if it failed). + streamer: Option, + ops: mpsc::UnboundedSender, + /// The newest preview picture, for the UI thread. + pictures: Arc>, + /// Stops the preview thread. + stop: Arc, + tasks: Vec>, + /// 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. + window: Option, + run: Option, + starting: bool, + /// Why it does not run or cannot stream. + error: String, + /// Where it keeps its keys: the app's settings, or with VOELIN_DEMO_UI + /// its own in memory (nothing stored). + settings: Option, + scenes: Arc, + status: Status, + stats: Option>, + encoder: Option, + ui: StudioUi, + destination: Option, + stream: Option, + picks: Vec, + /// Applications that play audio, for the audio picker. + apps: Option, + /// The mixer source of each audio row. + meters: Vec>, + /// The overlays last asked for. + overlays: Vec, + has_preview: bool, + /// Stats ticks it was not shown; it stops after a few. + hidden: u32, + /// Development switches waiting for the studio (dev.rs). + dev: Vec, +} + +/// Forward the studio's events to the UI thread. +async fn forward_events(mut events: broadcast::Receiver) { + loop { + match events.recv().await { + Ok(event) => later(move |app| app.studio_event(event)), + Err(RecvError::Lagged(_)) => {} + Err(RecvError::Closed) => break, + } + } +} + +/// Apply the ops one after the other. +async fn run_ops(studio: Weak, mut ops: mpsc::UnboundedReceiver) { + while let Some(op) = ops.recv().await { + let Some(studio) = studio.upgrade() else { break }; + let result = match op { + Op::Apply(command) => studio.apply(command).await, + Op::Add(mut source) => { + let mut scenes = studio.scenes(); + if scenes.active().is_none() { + let id = scenes.next_scene_id(); + scenes.scenes.push(Scene::new(id, "Scene 1")); + scenes.active = id; + } + if let Some(scene) = scenes.active_mut() { + source.id = scene.next_source_id(); + scene.sources.push(source); + } + studio.apply(studio::Command::SetScenes(Box::new(scenes))).await + } + Op::Overlays(wanted) => { + let mut scenes = studio.scenes(); + if vm::studio::apply_overlays(&mut scenes, &wanted) { + studio.apply(studio::Command::SetScenes(Box::new(scenes))).await + } else { + Ok(()) + } + } + }; + if let Err(e) = result { + later(move |app| app.set_status(format!("Stream Studio: {e}"))); + } + } +} + +/// Tell the UI thread when a key the studio follows changes elsewhere. +async fn watch_settings(settings: Settings) { + let mut audio = settings.watch(&STREAM_AUDIO_SOURCES); + let mut layers = settings.watch(&STREAM_LAYERS); + let mut bitrate = settings.watch(&STREAM_BITRATE_KBPS); + let mut ui = settings.watch(&STUDIO_UI); + loop { + tokio::select! { + Some(_) = audio.changed() => later(|app| app.studio_audio_changed()), + Some(_) = layers.changed() => later(|app| app.studio_encoding_changed()), + Some(_) = bitrate.changed() => later(|app| app.studio_encoding_changed()), + Some(_) = ui.changed() => later(|app| app.studio_ui_changed()), + else => break, + } + } +} + +/// Turn preview frames into pictures on a thread of its own; the UI thread +/// takes the newest when it gets to it. +fn spawn_preview( + handoff: Arc>, + pictures: Arc>, + stop: Arc, +) { + let spawned = + std::thread::Builder::new().name("voelin-studio-preview".into()).spawn(move || { + while !stop.load(Ordering::Relaxed) && !handoff.is_closed() { + let Some(frame) = handoff.wait_timeout(Duration::from_millis(250)) else { + continue; + }; + let mut picture = Picture::new(frame.width, frame.height); + let stride = frame.width as usize * 4; + if let Err(e) = convert::to_rgba(&frame, picture.make_mut_bytes(), stride) { + warn!("studio preview: {e}"); + continue; + } + if pictures.put(picture) { + later(|app| app.studio_picture()); + } + } + }); + if let Err(e) = spawned { + warn!("cannot show the studio's preview: {e}"); + } +} + +/// The demo studio of VOELIN_DEMO_UI: sample scenes from synthetic sources, +/// test tones, recordings in a temporary folder; in memory only. +fn demo_settings() -> Settings { + let settings = Settings::in_memory(); + let text = |text: &str, size_px: f32| SourceKind::Text { + text: text.into(), + font: None, + size_px, + colour: Colour::WHITE, + backdrop: Colour::CLEAR, + align: Align::Center, + padding: 0, + }; + let source = |id: u64, name: &str, kind: SourceKind, transform: Transform| Source { + name: name.into(), + transform, + ..Source::new(id, kind) + }; + let slate = |id: u64, name: &str, words: &str| { + let mut scene = Scene::new(id, name); + scene.sources = vec![ + source( + 1, + "Backdrop", + SourceKind::Colour { colour: Colour::rgb(16, 26, 60), size: (1920, 1080) }, + Transform::full(1920, 1080), + ), + source(2, "Title", text(words, 120.0), Transform::box_at(160.0, 440.0, 1600.0, 200.0)), + ]; + scene + }; + let camera = SourceKind::Camera { + device: camera::SYNTHETIC.into(), + size: None, + fps: None, + mirror: false, + }; + let mut main = Scene::new(1, "Main Stream"); + let mut cam = source(2, "Camera", camera.clone(), Transform::default()); + cam.transform = vm::studio::placement(&camera, (1920, 1080)); + cam.background = Background::Blur { strength: 0.04 }; + main.sources = vec![ + source( + 1, + "Game Capture", + SourceKind::Pattern { size: (1280, 720) }, + Transform { fit: Fit::Cover, ..Transform::full(1920, 1080) }, + ), + cam, + ]; + let mut chatting = Scene::new(2, "Just Chatting"); + chatting.sources = vec![source( + 1, + "Camera", + camera, + Transform { fit: Fit::Cover, ..Transform::full(1920, 1080) }, + )]; + let scenes = Scenes { + scenes: vec![ + main, + chatting, + slate(3, "Be Right Back", "Be right back"), + slate(4, "Starting Soon", "Starting soon"), + slate(5, "Ending", "Thanks for watching"), + ], + active: 1, + width: 1920, + height: 1080, + fps: 60, + }; + let tone = |frequency, gain| AudioSourceSetting { + gain, + ..AudioSourceSetting::new(AudioSourceKindSetting::Synthetic { frequency }) + }; + let recordings = std::env::temp_dir().join("voelin-demo-recordings"); + let results = [ + settings.set(&STUDIO_SCENES, scenes), + settings.set( + &STREAM_AUDIO_SOURCES, + vec![ + AudioSourceSetting { + gain: 0.49, + ..AudioSourceSetting::new(AudioSourceKindSetting::Microphone) + }, + tone(440, 0.25), + tone(660, 0.39), + ], + ), + settings.set(&STUDIO_RECORDING_DIR, recordings.display().to_string()), + settings.set( + &STUDIO_UI, + StudioUi { + title: "Exploring the Lands Between".into(), + game: "Adventure".into(), + message: "Going live in Chill Zone — exploring the Lands Between. Come hang!" + .into(), + show_viewers: true, + show_now_playing: true, + ..StudioUi::default() + }, + ), + ]; + for result in results { + if let Err(e) = result { + warn!("demo studio: {e}"); + } + } + settings +} + +/// The overlay text of what is on: the title and the game. +fn now_playing(ui: &StudioUi) -> Option { + let lines: Vec<&str> = + [ui.title.trim(), ui.game.trim()].into_iter().filter(|s| !s.is_empty()).collect(); + (!lines.is_empty()).then(|| lines.join("\n")) +} + +/// The stream's name: the title, and the game after it. TeamSpeak streams +/// have a name only, and the gateway's directory takes it from there. +pub fn stream_name(ui: &StudioUi) -> String { + match (ui.title.trim(), ui.game.trim()) { + (title, "") => title.to_owned(), + ("", game) => game.to_owned(), + (title, game) => format!("{title} — {game}"), + } +} + +fn file_name(what: &str) -> String { + format!("{what} {}.mkv", chrono::Local::now().format("%Y-%m-%d %H-%M-%S")) +} + +impl App { + /// The studio's settings (made once). + fn studio_settings(&mut self) -> Settings { + let demo = self.demo_ui; + let prefs = &self.prefs; + self.studio + .settings + .get_or_insert_with(|| if demo { demo_settings() } else { prefs.clone() }) + .clone() + } + + fn studio_streamer(&self) -> Option<&Streamer> { + self.studio.run.as_ref()?.streamer.as_ref() + } + + fn studio_op(&self, op: Op) { + if let Some(run) = &self.studio.run { + let _ = run.ops.send(op); + } + } + + /// `f` on the StudioBridge of the main window and of the studio window. + fn studio_each(&self, f: impl Fn(&StudioBridge)) { + if let Some(ui) = self.ui.upgrade() { + f(&ui.global::()); + } + if let Some(window) = &self.studio.window { + f(&window.global::()); + } + } + + /// The StudioNav of the window the studio is in. + fn studio_nav(&self, f: impl FnOnce(&StudioNav)) { + match (&self.studio.window, self.ui.upgrade()) { + (Some(window), _) => f(&window.global::()), + (None, Some(ui)) => f(&ui.global::()), + _ => {} + } + } + + fn studio_attach(&self, bridge: &StudioBridge) { + let m = &self.studio.models; + bridge.set_scenes(ModelRc::from(m.scenes.clone())); + bridge.set_sources(ModelRc::from(m.sources.clone())); + bridge.set_audio(ModelRc::from(m.audio.clone())); + bridge.set_layers(ModelRc::from(m.layers.clone())); + bridge.set_viewers(ModelRc::from(m.viewers.clone())); + bridge.set_destinations(ModelRc::from(m.destinations.clone())); + bridge.set_picks(ModelRc::from(m.picks.clone())); + bridge.set_chat(ModelRc::from(m.no_chat.clone())); + } + + /// Whether a studio page or window is on screen. + fn studio_shown(&self) -> bool { + self.studio.window.is_some() + || self.ui.upgrade().is_some_and(|ui| ui.global::