obws/requests/custom/transitions.rs
1//! Additional structs for use with [`crate::client::Inputs::set_settings`].
2
3use std::path::Path;
4
5use rgb::RGBA8;
6use serde::Serialize;
7use serde_repr::Serialize_repr;
8
9/// Identifier for swipe transitions.
10pub const TYPE_SWIPE: &str = "swipe_transition";
11/// Identifier for slide transitions.
12pub const TYPE_SLIDE: &str = "slide_transition";
13/// Identifier for stinger transitions.
14pub const TYPE_STINGER: &str = "obs_stinger_transition";
15/// Identifier for fade to color transitions.
16pub const TYPE_FADE_TO_COLOR: &str = "fade_to_color_transition";
17/// Identifier for luma wipe transitions.
18pub const TYPE_WIPE: &str = "wipe_transition";
19
20/// Options for a swipe transition. A swipe describes one scene hovering over another and making
21/// the other scene visible by moving in/out of the scene.
22#[derive(Debug, Default, Serialize)]
23#[cfg_attr(feature = "builder", derive(bon::Builder))]
24pub struct Swipe {
25 /// Direction of the swipe.
26 pub direction: Direction,
27 /// Let the new scene swipe into the screen over the current scene. Otherwise the current scene
28 /// swipes out with the new scene behind it becoming visible.
29 pub swipe_in: bool,
30}
31
32/// Options for a slide transition. A slide describes two scene directly next to each other making
33/// one visible by "pushing" the other one away.
34#[derive(Debug, Default, Serialize)]
35#[cfg_attr(feature = "builder", derive(bon::Builder))]
36pub struct Slide {
37 /// Direction of the slide.
38 pub direction: Direction,
39}
40
41/// The direction for a [`Swipe`] or [`Slide].
42#[derive(Clone, Copy, Debug, Default, Serialize)]
43#[serde(rename_all = "lowercase")]
44#[non_exhaustive]
45pub enum Direction {
46 /// From/to the left.
47 #[default]
48 Left,
49 /// From/to the right.
50 Right,
51 /// From/to the top.
52 Up,
53 /// From/to the bottom.
54 Down,
55}
56
57/// Options for a stinger transition. A stinger describes a video being used to hide the old scene
58/// completely, then switch the scene while only the video is visible. Afterwards the video moves
59/// out of the view again to make the new scene visible.
60#[derive(Serialize)]
61#[cfg_attr(feature = "builder", derive(bon::Builder))]
62pub struct Stinger<'a> {
63 /// Location of the video file.
64 pub path: &'a Path,
65 /// The type of value that [`Self::transition_point`] stands for.
66 pub tp_type: TransitionPointType,
67 /// Point at which the scene transition triggers. What unit of this value depends on the set
68 /// [`Self::tp_type`].
69 pub transition_point: u32,
70 /// The kind of audio monitoring to apply. This means whether to send the audio to the output
71 /// stream, only play it locally or do it both.
72 pub audio_monitoring: AudioMonitoring,
73 /// The way audio is gradually swapped between two scenes.
74 pub audio_fade_style: AudioFadeStyle,
75}
76
77/// Different units that are used together with a value to define scene switching point of a video
78/// transition.
79#[derive(Clone, Copy, Debug, Default, Serialize_repr)]
80#[repr(u8)]
81#[non_exhaustive]
82pub enum TransitionPointType {
83 /// Time in milliseconds.
84 #[default]
85 Time = 0,
86 /// Frames (single images) of the video.
87 Frame = 1,
88}
89
90/// Setting for the audio monitoring which defines whether audio is send to the stream, played
91/// locally or both at the same time.
92#[derive(Clone, Copy, Debug, Default, Serialize_repr)]
93#[repr(u8)]
94#[non_exhaustive]
95pub enum AudioMonitoring {
96 /// No monitoring, means to insert the audio into the output stream but not playing it on the
97 /// local machine.
98 #[default]
99 MonitorOff = 0,
100 /// The opposite of [`Self::MonitorOff`], playing the audio locally but not sending it to
101 /// the stream.
102 MonitorOnly = 1,
103 /// A combination of the other options where audio is send to the stream as well as played
104 /// locally.
105 MonitorAndOutput = 2,
106}
107
108/// Describes the way in which the audio is faded between two scenes with a [`Stinger`] transition.
109#[derive(Clone, Copy, Debug, Default, Serialize_repr)]
110#[repr(u8)]
111#[non_exhaustive]
112pub enum AudioFadeStyle {
113 /// Fade out to transition point then fade in.
114 #[default]
115 FadeOutFadeIn = 0,
116 /// Fade out the audio from the old scene and fade in the new scene's audio at the same time,
117 /// creating a slight overlap.
118 Crossfade = 1,
119}
120
121/// Options for a fade to color transition. A color fading describes one scene being blended with
122/// a given color until only the color is visible and then blend from the color to the new scene
123/// until the color is fully gone.
124#[derive(Serialize)]
125#[cfg_attr(feature = "builder", derive(bon::Builder))]
126pub struct FadeToColor {
127 /// Color to blend in/out.
128 #[serde(with = "crate::serde::rgba8_inverse")]
129 pub color: RGBA8,
130 /// The point at which the scenes are swapped. Maximum value is `100`.
131 pub switch_point: u8,
132}
133
134/// Options for a luma wipe transition. A luma wipe describes one scene being gradually displayed
135/// over the other, where the luma image defines a certain animation to do so.
136#[derive(Serialize)]
137#[cfg_attr(feature = "builder", derive(bon::Builder))]
138pub struct Wipe {
139 /// The image to use. This describes the animation that is used.
140 pub luma_image: LumaImage,
141 /// Invert the animation.
142 pub luma_invert: bool,
143 /// Softness of the edges inside the animation where old and new scene "touch".
144 pub luma_softness: f64,
145}
146
147/// A luma image that defines the animation of a [`Wipe`].
148#[derive(Default, Serialize)]
149#[non_exhaustive]
150pub enum LumaImage {
151 /// Barn door animation diagonal from the bottom left.
152 #[serde(rename = "barndoor-botleft.png")]
153 BarndoorBottomLeft,
154 /// Horizontal barn door animation.
155 #[serde(rename = "barndoor-h.png")]
156 BarndoorHorizontal,
157 /// Barn door animation diagonal from the top left.
158 #[serde(rename = "barndoor-topleft.png")]
159 BarndoorTopLeft,
160 /// Vertical barn door animation.
161 #[serde(rename = "barndoor-v.png")]
162 BarndoorVertical,
163 #[serde(rename = "blinds-h.png")]
164 /// Horizontal blinds animation.
165 BlindsHorizontal,
166 /// Box animation from the bottom left.
167 #[serde(rename = "box-botleft.png")]
168 BoxBottomLeft,
169 /// Box animation from the bottom right.
170 #[serde(rename = "box-botright.png")]
171 BoxBottomRight,
172 /// Box animation from the top left.
173 #[serde(rename = "box-topleft.png")]
174 BoxTopLeft,
175 /// Box animation from the top right.
176 #[serde(rename = "box-topright.png")]
177 BoxTopRight,
178 /// Burst animation.
179 #[serde(rename = "burst.png")]
180 Burst,
181 /// Small checkerboard animation.
182 #[serde(rename = "checkerboard-small.png")]
183 CheckerboardSmall,
184 /// Circles animation.
185 #[serde(rename = "circles.png")]
186 Circles,
187 /// Clock sweep animation.
188 #[serde(rename = "clock.png")]
189 Clock,
190 /// Cloud animation.
191 #[serde(rename = "cloud.png")]
192 Cloud,
193 /// Curtain animation.
194 #[serde(rename = "curtain.png")]
195 Curtain,
196 /// Fan animation.
197 #[serde(rename = "fan.png")]
198 Fan,
199 /// Fractal animation.
200 #[serde(rename = "fractal.png")]
201 Fractal,
202 /// Iris animation.
203 #[serde(rename = "iris.png")]
204 Iris,
205 /// Horizontal linear animation.
206 #[default]
207 #[serde(rename = "linear-h.png")]
208 LinearHorizontal,
209 /// Linear animation from the top left.
210 #[serde(rename = "linear-topleft.png")]
211 LinearTopLeft,
212 /// Linear animation from the top right.
213 #[serde(rename = "linear-topright.png")]
214 LinearTopRight,
215 /// Vertical liner animation.
216 #[serde(rename = "linear-v.png")]
217 LinearVertical,
218 /// Horizontal parallel zig-zag animation.
219 #[serde(rename = "parallel-zigzag-h.png")]
220 ParallelZigzagHorizontal,
221 /// Vertical parallel zig-zag animation.
222 #[serde(rename = "parallel-zigzag-v.png")]
223 ParallelZigzagVertical,
224 /// Sinus9 animation.
225 #[serde(rename = "sinus9.png")]
226 Sinus9,
227 /// Spiral animation.
228 #[serde(rename = "spiral.png")]
229 Spiral,
230 /// Square animation.
231 #[serde(rename = "square.png")]
232 Square,
233 /// Squares animation.
234 #[serde(rename = "squares.png")]
235 Squares,
236 /// Stripes animation.
237 #[serde(rename = "stripes.png")]
238 Stripes,
239 /// Horizontal strips animation.
240 #[serde(rename = "strips-h.png")]
241 StripsHorizontal,
242 /// Vertical strips animation.
243 #[serde(rename = "strips-v.png")]
244 StripsVertical,
245 /// Watercolor animation.
246 #[serde(rename = "watercolor.png")]
247 Watercolor,
248 /// Horizontal zig-zag animation.
249 #[serde(rename = "zigzag-h.png")]
250 ZigzagHorizontal,
251 /// Vertical zig-zag animation.
252 #[serde(rename = "zigzag-v.png")]
253 ZigzagVertical,
254}