feat: Handle program input

This commit is contained in:
Baud 2024-03-11 00:30:16 +00:00
parent 46cca11e00
commit 2325645bb5
5 changed files with 60 additions and 12 deletions

View File

@ -12,16 +12,14 @@ impl DeserializedCommand for InitComplete {
DESERIALIZE_INIT_COMPLETE_RAW_NAME DESERIALIZE_INIT_COMPLETE_RAW_NAME
} }
fn apply_to_state(&self, state: &mut crate::state::AtemState) { fn apply_to_state(&self, _state: &mut crate::state::AtemState) {}
todo!("Apply to state: Init Complete")
}
} }
#[derive(Default)] #[derive(Default)]
pub struct InitCompleteDeserializer {} pub struct InitCompleteDeserializer {}
impl CommandDeserializer for InitCompleteDeserializer { impl CommandDeserializer for InitCompleteDeserializer {
fn deserialize(&self, buffer: &[u8]) -> std::sync::Arc<dyn DeserializedCommand> { fn deserialize(&self, _buffer: &[u8]) -> std::sync::Arc<dyn DeserializedCommand> {
Arc::new(InitComplete {}) Arc::new(InitComplete {})
} }
} }

View File

@ -1,7 +1,10 @@
use std::sync::Arc; use std::sync::Arc;
use crate::commands::command_base::{ use crate::{
BasicWritableCommand, CommandDeserializer, DeserializedCommand, SerializableCommand, commands::command_base::{
BasicWritableCommand, CommandDeserializer, DeserializedCommand, SerializableCommand,
},
state::util::get_mix_effect,
}; };
pub const DESERIALIZE_PROGRAM_INPUT_RAW_NAME: &str = "PrgI"; pub const DESERIALIZE_PROGRAM_INPUT_RAW_NAME: &str = "PrgI";
@ -38,7 +41,16 @@ impl DeserializedCommand for ProgramInput {
} }
fn apply_to_state(&self, state: &mut crate::state::AtemState) { fn apply_to_state(&self, state: &mut crate::state::AtemState) {
todo!("Apply to state: Program Input") let Some(capabilities) = state.info.capabilities() else {
todo!("Return error");
};
if self.mix_effect > *capabilities.mix_effects() {
todo!("Return error");
}
let mix_effect = get_mix_effect(state, self.mix_effect as usize);
mix_effect.program_input = self.source;
} }
} }

View File

@ -2,7 +2,7 @@ use crate::enums::{Model, ProtocolVersion};
#[derive(Clone, PartialEq, Getters, new)] #[derive(Clone, PartialEq, Getters, new)]
pub struct AtemCapabilites { pub struct AtemCapabilites {
mix_effects: u64, mix_effects: u8,
sources: u64, sources: u64,
auxilliaries: u64, auxilliaries: u64,
mix_minus_outputs: u64, mix_minus_outputs: u64,

View File

@ -1,9 +1,41 @@
use super::{settings::MultiViewer, AtemState}; use crate::enums::{TransitionSelection, TransitionStyle};
use super::{
settings::MultiViewer,
video::{MixEffect, TransitionPosition, TransitionProperties, TransitionSettings},
AtemState,
};
pub fn create() -> AtemState { pub fn create() -> AtemState {
AtemState::default() AtemState::default()
} }
pub fn get_mix_effect(state: &mut AtemState, index: usize) -> &mut MixEffect {
// TODO: Use of index here is terrible and dangerous
if state.video.mix_effects().get(index).is_none() {
let mix_effect = MixEffect::new(
index,
0,
0,
false,
None,
TransitionPosition::new(false, 0.0, 0.0),
TransitionProperties::new(
TransitionStyle::MIX,
vec![TransitionSelection::Background],
TransitionStyle::MIX,
vec![TransitionSelection::Background],
),
TransitionSettings::new(None, None, None, None, None),
vec![],
);
state.video.mix_effects_mut()[index] = mix_effect.clone();
};
&mut state.video.mix_effects_mut()[index]
}
pub fn get_multi_viewer(state: &mut AtemState, index: usize) -> Option<&MultiViewer> { pub fn get_multi_viewer(state: &mut AtemState, index: usize) -> Option<&MultiViewer> {
state.settings.multi_viewers().get(index) state.settings.multi_viewers().get(index)
} }

View File

@ -87,9 +87,9 @@ pub struct TransitionPosition {
#[derive(Clone, PartialEq, Getters, new)] #[derive(Clone, PartialEq, Getters, new)]
pub struct MixEffect { pub struct MixEffect {
index: f64, index: usize,
pub program_input: f64, pub program_input: u16,
pub preview_input: f64, pub preview_input: u16,
pub transition_preview: bool, pub transition_preview: bool,
pub fade_to_black: Option<FadeToBlackProperties>, pub fade_to_black: Option<FadeToBlackProperties>,
pub transition_position: TransitionPosition, pub transition_position: TransitionPosition,
@ -113,3 +113,9 @@ pub struct AtemVideoState {
auxiliaries: Vec<f64>, auxiliaries: Vec<f64>,
super_sources: Vec<super_source::SuperSource>, super_sources: Vec<super_source::SuperSource>,
} }
impl AtemVideoState {
pub fn mix_effects_mut(&mut self) -> &mut Vec<MixEffect> {
&mut self.mix_effects
}
}