Skip to content

Commit 06c43fb

Browse files
Misei.Misei.
authored andcommitted
Refactor ATEM source handling and tighten switcher layout fidelity.
Move frontend source selection to backend-provided source IDs, split Tauri invoke/state sync into dedicated modules, and update switcher panel layout/controls to better match expected ATEM behavior and visuals.
1 parent b16055f commit 06c43fb

File tree

6 files changed

+957
-220
lines changed

6 files changed

+957
-220
lines changed

src-tauri/src/lib.rs

Lines changed: 110 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ struct DskRuntimeDto {
3434
remaining_frames: u8,
3535
}
3636

37+
#[derive(Debug, Clone, Serialize)]
38+
struct SourceItemDto {
39+
source_index: usize,
40+
source_id: u16,
41+
source_name: String,
42+
}
43+
3744
#[derive(Debug, Clone, Serialize)]
3845
struct AtemSnapshotDto {
3946
initialisation_complete: bool,
@@ -42,6 +49,9 @@ struct AtemSnapshotDto {
4249
program_sources: Vec<String>,
4350
preview_sources: Vec<String>,
4451
available_sources: Vec<String>,
52+
program_source_ids: Vec<u16>,
53+
preview_source_ids: Vec<u16>,
54+
available_source_items: Vec<SourceItemDto>,
4555
tally_by_source: HashMap<String, Vec<String>>,
4656
dsk_keys: Vec<u8>,
4757
dsk_sources: HashMap<String, (String, String)>,
@@ -72,6 +82,10 @@ fn stringify_source(source: &VideoSource) -> String {
7282
format!("{source:?}")
7383
}
7484

85+
fn source_id(source: &VideoSource) -> u16 {
86+
*source as u16
87+
}
88+
7589
fn snapshot_to_dto(snapshot: &AtemSnapshot) -> AtemSnapshotDto {
7690
let tally_by_source = snapshot
7791
.tally_by_source
@@ -134,6 +148,18 @@ fn snapshot_to_dto(snapshot: &AtemSnapshot) -> AtemSnapshotDto {
134148
.iter()
135149
.map(stringify_source)
136150
.collect(),
151+
program_source_ids: snapshot.program_sources.iter().map(source_id).collect(),
152+
preview_source_ids: snapshot.preview_sources.iter().map(source_id).collect(),
153+
available_source_items: snapshot
154+
.available_sources
155+
.iter()
156+
.enumerate()
157+
.map(|(source_index, source)| SourceItemDto {
158+
source_index,
159+
source_id: source_id(source),
160+
source_name: stringify_source(source),
161+
})
162+
.collect(),
137163
tally_by_source,
138164
dsk_keys: snapshot.dsk_keys.clone(),
139165
dsk_sources,
@@ -164,6 +190,9 @@ fn empty_snapshot_dto() -> AtemSnapshotDto {
164190
program_sources: Vec::new(),
165191
preview_sources: Vec::new(),
166192
available_sources: Vec::new(),
193+
program_source_ids: Vec::new(),
194+
preview_source_ids: Vec::new(),
195+
available_source_items: Vec::new(),
167196
tally_by_source: HashMap::new(),
168197
dsk_keys: Vec::new(),
169198
dsk_sources: HashMap::new(),
@@ -379,6 +408,81 @@ async fn set_next_transition(
379408
.map_err(|e| e.to_string())
380409
}
381410

411+
#[tauri::command]
412+
async fn dsk_auto(state: State<'_, AppState>, key: u8) -> Result<(), String> {
413+
let inner = state.inner.lock().await;
414+
let managed = inner
415+
.connection
416+
.as_ref()
417+
.ok_or_else(|| "not connected".to_string())?;
418+
managed
419+
.connection
420+
.client
421+
.dsk_auto(key)
422+
.await
423+
.map_err(|e| e.to_string())
424+
}
425+
426+
#[tauri::command]
427+
async fn set_dsk_on_air(state: State<'_, AppState>, key: u8, on_air: bool) -> Result<(), String> {
428+
let inner = state.inner.lock().await;
429+
let managed = inner
430+
.connection
431+
.as_ref()
432+
.ok_or_else(|| "not connected".to_string())?;
433+
managed
434+
.connection
435+
.client
436+
.set_dsk_on_air(key, on_air)
437+
.await
438+
.map_err(|e| e.to_string())
439+
}
440+
441+
#[tauri::command]
442+
async fn set_dsk_tie(state: State<'_, AppState>, key: u8, tie: bool) -> Result<(), String> {
443+
let inner = state.inner.lock().await;
444+
let managed = inner
445+
.connection
446+
.as_ref()
447+
.ok_or_else(|| "not connected".to_string())?;
448+
managed
449+
.connection
450+
.client
451+
.set_dsk_tie(key, tie)
452+
.await
453+
.map_err(|e| e.to_string())
454+
}
455+
456+
#[tauri::command]
457+
async fn set_dsk_rate(state: State<'_, AppState>, key: u8, rate: u8) -> Result<(), String> {
458+
let inner = state.inner.lock().await;
459+
let managed = inner
460+
.connection
461+
.as_ref()
462+
.ok_or_else(|| "not connected".to_string())?;
463+
managed
464+
.connection
465+
.client
466+
.set_dsk_rate(key, rate)
467+
.await
468+
.map_err(|e| e.to_string())
469+
}
470+
471+
#[tauri::command]
472+
async fn toggle_auto_black(state: State<'_, AppState>, me: u8) -> Result<(), String> {
473+
let inner = state.inner.lock().await;
474+
let managed = inner
475+
.connection
476+
.as_ref()
477+
.ok_or_else(|| "not connected".to_string())?;
478+
managed
479+
.connection
480+
.client
481+
.toggle_auto_black(me)
482+
.await
483+
.map_err(|e| e.to_string())
484+
}
485+
382486
#[cfg_attr(mobile, tauri::mobile_entry_point)]
383487
pub fn run() {
384488
tauri::Builder::default()
@@ -394,7 +498,12 @@ pub fn run() {
394498
set_preview_input_by_index,
395499
cut,
396500
auto_transition,
397-
set_next_transition
501+
set_next_transition,
502+
dsk_auto,
503+
set_dsk_on_air,
504+
set_dsk_tie,
505+
set_dsk_rate,
506+
toggle_auto_black
398507
])
399508
.run(tauri::generate_context!())
400509
.expect("error while running tauri application");

0 commit comments

Comments
 (0)