From 8de8a374aef214b334b60065b857adbbd363e3b2 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 14 Nov 2026 16:31:26 +0100 Subject: [PATCH] Make advanced Midra input settings explicitly opt-in --- crates/midra-layout/src/device_send.rs | 64 +++- crates/midra-layout/src/device_ui.rs | 33 +- crates/midra-layout/src/format_ui.rs | 49 ++- crates/midra-layout/src/gui.rs | 2 + crates/midra-layout/src/input_ui.rs | 413 +++++++++++++++++++++++++ crates/midra-layout/src/project_ui.rs | 1 + docs/interfaces/midra-device-send.md | 56 +++- docs/midra-layout.md | 24 ++ docs/midralayout/changelog.md | 2 + 9 files changed, 630 insertions(+), 14 deletions(-) create mode 100644 crates/midra-layout/src/input_ui.rs diff --git a/crates/midra-layout/src/device_send.rs b/crates/midra-layout/src/device_send.rs index 4b628cb..6673d85 100644 --- a/crates/midra-layout/src/device_send.rs +++ b/crates/midra-layout/src/device_send.rs @@ -1,4 +1,4 @@ -//! Reviewed, explicit WebRCS layer writes. No routing, TAKE or shared input writes. +//! Explicit WebRCS layer writes, plus separately opted-in advanced input edits. No routing or TAKE. use crate::{ Layout, device::{self, Snapshot}, @@ -226,6 +226,30 @@ fn execute(plan: &Plan, transport: &mut impl Transport) -> Result = plan + .changes + .iter() + .filter_map(|change| { + let p = &change.path; + (p.get(1).is_some_and(|v| v == "inputList") + && p.get(8).is_some_and(|v| v == "cropping") + && p.len() == 12) + .then(|| p[..11].to_vec()) + }) + .collect(); + for mut path in input_crops { + path.push("xUpdate".into()); + for value in [false, true] { + transport + .write(&Change { + path: path.clone(), + before: json!(!value), + after: json!(value), + }) + .map_err(|e| format!("Input values sent, but applying input crop failed: {e}"))?; + } + } // WebRCS commits staged preset edits with a false -> true edge. // Always pulse, even if values already match the server's staging store. for value in [false, true] { @@ -402,6 +426,44 @@ mod tests { Ok(()) } } + #[test] + fn explicit_input_crop_changes_pulse_only_that_input_before_preset_apply() { + let mut state = snapshot(); + state.raw["device"]["inputList"] = json!({"items":{"INPUT_4":{"plugList":{"items":{"2":{"settings":{"cropping":{"control":{"pp":{"left":0,"xUpdate":true}}}}}}}}}}); + let path = + "device/inputList/items/INPUT_4/plugList/items/2/settings/cropping/control/pp/left"; + let plan = Plan { + screen: "1".into(), + bank: "UP".into(), + target: Target::Preview, + changes: vec![Change { + path: path.split('/').map(str::to_owned).collect(), + before: json!(0), + after: json!(40), + }], + }; + let mut transport = Mock { + state, + writes: 0, + fail_at: None, + ignore: false, + writes_log: vec![], + }; + execute(&plan, &mut transport).unwrap(); + assert_eq!(transport.writes_log.len(), 5); + for (i, value) in [(1, false), (2, true)] { + assert_eq!( + transport.writes_log[i].0.join("/"), + path.replace("/left", "/xUpdate") + ); + assert_eq!(transport.writes_log[i].1, json!(value)); + } + assert_eq!( + transport.writes_log[3].0.join("/"), + "device/preset/control/pp/xUpdate" + ); + } + #[test] fn crop_decreases_precede_increases_when_reframing() { let mut state = snapshot(); diff --git a/crates/midra-layout/src/device_ui.rs b/crates/midra-layout/src/device_ui.rs index 4d610a7..1eb3862 100644 --- a/crates/midra-layout/src/device_ui.rs +++ b/crates/midra-layout/src/device_ui.rs @@ -39,6 +39,7 @@ enum Destination { #[derive(Default)] pub(super) struct DeviceUi { + pub(super) input_edits: input_ui::InputEdits, pub open: bool, pub(super) scope: TransferScope, import_closing: bool, @@ -129,7 +130,7 @@ impl DeviceUi { .iter() .position(|s| s.id == screen) .ok_or_else(|| format!("Linked screen {screen} is unavailable."))?; - Plan::prepare( + let mut plan = Plan::prepare( snapshot, layout, index, @@ -140,7 +141,10 @@ impl DeviceUi { Target::Preview }, self.sizing, - ) + )?; + self.input_edits + .extend_plan(snapshot, &mappings, &mut plan)?; + Ok(plan) }) .collect() } @@ -266,6 +270,14 @@ impl DeviceUi { } } impl Editor { + pub(super) fn advanced_input_controls(&mut self, ui: &mut egui::Ui, i: usize) { + self.device.input_edits.show( + ui, + self.device.snapshot.as_ref(), + self.layout.layer_info(i).midra_link.as_ref(), + ); + } + pub(super) fn layer_mapping_controls(&mut self, ui: &mut egui::Ui, i: usize) { let original = self.layout.layer_info(i).midra_link.clone(); let mut link = original.clone(); @@ -540,6 +552,7 @@ impl Editor { ui.label("Device IP"); if ui.add_enabled(self.device.pending.is_none(), egui::TextEdit::singleline(&mut self.device.host).hint_text("192.168.…")).changed() { self.device.snapshot = None; + self.device.input_edits.clear(); self.device.reset_mappings(); self.device.error.clear(); self.device.message.clear(); @@ -549,6 +562,7 @@ impl Editor { if ui.add_enabled(self.device.pending.is_none(), egui::Button::new(if self.device.online() { "Refresh connection" } else { "Connect" })).clicked() { self.device.fetch(ctx); } if ui.add_enabled(self.device.online() && self.device.pending.is_none(), egui::Button::new("Disconnect")).clicked() { self.device.snapshot = None; + self.device.input_edits.clear(); self.device.reset_mappings(); self.device.message.clear(); } @@ -632,7 +646,7 @@ impl Editor { }).collect(); let previous = targets.clone(); send_plan = send_review(ui, &self.layout, &scope_indices, snapshot, self.device.screen, &mut targets, - &mut self.device.target, &mut self.device.sizing, self.device.pending.is_some(), self.device.allow_program); + &mut self.device.target, &mut self.device.sizing, self.device.pending.is_some(), self.device.allow_program, &self.device.input_edits); for (id, destination) in targets { if previous.get(&id) != Some(&destination) { let i = (0..self.layout.layers().len()).find(|&i| self.layout.layer_info(i).id == id).unwrap(); @@ -804,6 +818,7 @@ fn send_review( sizing: &mut Sizing, busy: bool, allow_program: bool, + input_edits: &input_ui::InputEdits, ) -> Option { let screen = &snapshot.screens[screen_index]; if !allow_program { @@ -903,7 +918,11 @@ fn send_review( &mappings, *target_mode, *sizing, - ) { + ) + .and_then(|mut plan| { + input_edits.extend_plan(snapshot, &mappings, &mut plan)?; + Ok(plan) + }) { Ok(plan) => { ui.label(format!( "{:?} · screen {} · physical bank {} · {} changed fields", @@ -916,7 +935,7 @@ fn send_review( for change in &plan.changes { ui.label(format!( "{}: {} → {}", - change.path[8..].join("/"), + change.path.join("/"), change.before, change.after )); @@ -1239,6 +1258,7 @@ mod tests { &mut Sizing::OutputBox, false, allow, + &input_ui::InputEdits::default(), ); }); }); @@ -1387,6 +1407,7 @@ mod tests { &mut Sizing::OutputBox, false, false, + &input_ui::InputEdits::default(), ) }); }); @@ -1409,6 +1430,7 @@ mod tests { &mut Sizing::OutputBox, false, false, + &input_ui::InputEdits::default(), ) }); }); @@ -1658,6 +1680,7 @@ mod tests { &mut Sizing::OutputBox, false, false, + &input_ui::InputEdits::default(), ); }); }); diff --git a/crates/midra-layout/src/format_ui.rs b/crates/midra-layout/src/format_ui.rs index 0ca2d0a..511e891 100644 --- a/crates/midra-layout/src/format_ui.rs +++ b/crates/midra-layout/src/format_ui.rs @@ -332,7 +332,7 @@ impl Editor { } let i = d.layer; let mut open = true; - egui::Window::new(format!("Layer properties · {}",self.layout.layer_label(i))).open(&mut open).default_width(540.0).default_height(520.0).min_height(380.0).vscroll(true).show(ctx,|ui| { + egui::Window::new(format!("Layer properties · {}",self.layout.layer_label(i))).open(&mut open).default_width(540.0).default_height(720.0).min_height(380.0).vscroll(true).show(ctx,|ui| { ui.horizontal(|ui| { ui.selectable_value(&mut self.property_tab,PropertyTab::Source,"Source"); ui.selectable_value(&mut self.property_tab,PropertyTab::Layer,"Layer"); @@ -353,7 +353,13 @@ impl Editor { ui.small("Editor input shares source format and input crop between editor layers; it is separate from the Midra link."); } if self.property_tab == PropertyTab::Source { - ui.heading("Source / input resolution"); + ui.heading("Advanced source / input settings"); + self.advanced_input_controls(ui, i); + ui.separator(); + ui.label("Editor source model (local geometry)"); + ui.small("These dimensions describe the editor source, not a device timing command. Local input correction is currently folded into exported layer crop; use the device controls above for the actual shared Midra input settings."); + ui.add_enabled_ui(self.device.input_edits.enabled, |ui| { + let affected:Vec<_>=(0..self.layout.layers().len()).filter(|j| *j==i || self.layout.formats().source_for[*j]==d.source_id).map(|j|self.layout.layer_label(j)).collect(); ui.label(format!("Input edits affect: {}",affected.join(", "))); let old_native=d.source.native; @@ -384,6 +390,7 @@ impl Editor { }); if old_crop!=d.source.input_crop && let Ok(size)=d.source.input() { d.input_size=size; } ui.label("Input crop edges: native source pixels. Native-size changes reset the draft input crop before review."); + }); } if self.property_tab == PropertyTab::Layer { let before_size = d.size; @@ -432,7 +439,7 @@ impl Editor { _=>{} } let pending = d.pending(&self.layout); - if apply_button(ui,"Apply source changes", pending).clicked() { + if apply_button(ui,"Apply source changes", pending && (self.device.input_edits.enabled || self.property_tab == PropertyTab::Mapping)).clicked() { match d.apply(&mut self.layout, position_reference, self.keep_aspect_ratio) { Ok(())=>{self.sync();d=FormatDraft::new(&self.layout,i);},Err(e)=>d.error=e } } ui.small("Source changes require Apply. Switching tabs keeps pending source edits."); @@ -733,6 +740,7 @@ mod tests { property_tab: PropertyTab::Source, ..Default::default() }; + app.device.input_edits.enabled = true; let crop = Crop { left: 20.0, right: 20.0, @@ -1062,7 +1070,11 @@ mod tests { d.framing.zoom = 2.0; app.format_draft = Some(d); for (title, tab, heading) in [ - ("Source", PropertyTab::Source, "Source / input resolution"), + ( + "Source", + PropertyTab::Source, + "Advanced source / input settings", + ), ("Mapping", PropertyTab::Mapping, "Layer mapping"), ("Crop", PropertyTab::Crop, "Layer crop / zoom & position"), ( @@ -1081,7 +1093,7 @@ mod tests { .filter_map(|s| match &s.shape { egui::Shape::Text(t) if [ - "Source / input resolution", + "Advanced source / input settings", "Layer mapping", "Layer crop / zoom & position", "Layer resolution / final visible box", @@ -1147,6 +1159,32 @@ mod tests { app.layout.undo(); assert_eq!(app.layout.formats().output, [1920, 1080]); } + #[test] + fn advanced_source_edits_require_explicit_checkbox() { + let mut app = Editor { + property_tab: PropertyTab::Source, + ..Default::default() + }; + let ctx = egui::Context::default(); + let before = app.layout.formats().clone(); + let mut draft = FormatDraft::new(&app.layout, 1); + draft.input_size = [1920.0, 1000.0]; + draft.source.input_crop = Crop::centered([1920.0, 1080.0], draft.input_size).unwrap(); + app.format_draft = Some(draft); + click_text(&mut app, &ctx, "Apply source changes"); + assert_eq!(app.layout.formats(), &before); + assert!(!app.device.input_edits.enabled); + click_text( + &mut app, + &ctx, + "Edit advanced input settings and include my edits when sending", + ); + assert!(app.device.input_edits.enabled); + click_text(&mut app, &ctx, "Apply source changes"); + assert_eq!(app.layout.formats().input(1).unwrap(), [1920.0, 1000.0]); + assert!(!app.device.sending); + } + #[test] fn source_and_layer_dialog_applies_worked_example_with_one_undo() { let mut app = Editor { @@ -1154,6 +1192,7 @@ mod tests { keep_aspect_ratio: false, ..Default::default() }; + app.device.input_edits.enabled = true; let ctx = egui::Context::default(); let before = app.layout.layers().clone(); let formats = app.layout.formats().clone(); diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index e4dd303..c6ce581 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -3,6 +3,8 @@ use super::*; mod device_ui; #[path = "format_ui.rs"] mod format_ui; +#[path = "input_ui.rs"] +mod input_ui; #[path = "layers_ui.rs"] mod layers_ui; #[path = "menu_ui.rs"] diff --git a/crates/midra-layout/src/input_ui.rs b/crates/midra-layout/src/input_ui.rs new file mode 100644 index 0000000..c44da0c --- /dev/null +++ b/crates/midra-layout/src/input_ui.rs @@ -0,0 +1,413 @@ +//! Session-only, explicitly enabled edits to the device's shared input settings. +use super::*; +use midra_layout::{ + device::Snapshot, + device_send::{Change, Plan}, +}; +use serde_json::{Value, json}; +use std::collections::{BTreeMap, BTreeSet}; + +#[derive(Default)] +pub(super) struct InputEdits { + pub enabled: bool, + // Only fields actually edited are staged; opening the tab never stages defaults. + values: BTreeMap, +} + +fn input_path(snapshot: &Snapshot, screen: &str, bank: &str, layer: &str) -> Option { + let input = snapshot.raw.pointer(&format!("/device/screenList/items/{screen}/presetList/items/{bank}/liveLayerList/items/{layer}/source/pp/input"))?.as_str()?; + let base = format!("/device/inputList/items/{input}"); + let plug = snapshot + .raw + .pointer(&format!("{base}/status/pp/plug"))? + .as_str()?; + Some(format!("{base}/plugList/items/{plug}/settings")) +} + +fn setting_label(value: &str) -> String { + match value { + "NATIVE" => "Native".into(), + "SIGNAL" => "Signal".into(), + "CUSTOM" => "Custom".into(), + "LAYER_SETTING" => "Layer setting".into(), + "CENTERED" => "Centered".into(), + "FULLSCREEN" => "Full screen".into(), + "CROPPED" => "Cropped".into(), + "NONE" => "None".into(), + "LETTERBOX_1_78" => "Letterbox 1.78:1".into(), + "LETTERBOX_1_85" => "Letterbox 1.85:1".into(), + "LETTERBOX_2_35" => "Letterbox 2.35:1".into(), + "PILLARBOX_1_33" => "Pillarbox 1.33:1".into(), + _ => value.replace('_', ":"), + } +} + +impl InputEdits { + pub fn clear(&mut self) { + *self = Self::default(); + } + + pub fn show( + &mut self, + ui: &mut egui::Ui, + snapshot: Option<&Snapshot>, + link: Option<&midra_layout::MidraLink>, + ) { + ui.label( + "Advanced — use only when you need to correct an input and understand the effect.", + ); + ui.label("These device controls map one-for-one to WebRCS Advanced Input settings. Content ratio / Transform to change the input's aspect before layer framing. Usually leave them set on the Midra."); + ui.label("Input crop removes source edges before dynamic layer crop / zoom. It does not resize the layer's bounding box. This processing is a Midra feature, not an editor-only effect."); + if ui + .checkbox( + &mut self.enabled, + "Edit advanced input settings and include my edits when sending", + ) + .changed() + && !self.enabled + { + self.values.clear(); + } + ui.small("Off by default. Only edited device fields are sent, and only with layers using that input. Inputs are shared: edits can affect other layers and Program too. Uncheck to discard staged edits. This opt-in lasts for this session only."); + let Some((snapshot, base)) = snapshot.and_then(|snapshot| { + let link = link?; + let screen = snapshot.screens.iter().find(|s| s.id == link.screen)?; + input_path(snapshot, &link.screen, &screen.preview_bank, &link.layer) + .map(|base| (snapshot, base)) + }) else { + ui.small("Connect and map this layer to a Midra input source to inspect its advanced settings. No device input edits are staged offline."); + return; + }; + ui.small(format!( + "Shared input: {} · plug {} (from linked Preview layer)", + base.split('/').nth(4).unwrap_or("?"), + base.split('/').nth(7).unwrap_or("?") + )); + ui.add_enabled_ui(self.enabled, |ui| { + for (suffix, label, options) in [ + ( + "aspect/pp/signal", + "Content ratio", + &[ + "NATIVE", "5_4", "4_3", "16_10", "15_9", "16_9", "21_9", "256_135", "64_27", + ][..], + ), + ( + "aspect/pp/transformTo", + "Transform to", + &[ + "SIGNAL", "5_4", "4_3", "16_10", "15_9", "16_9", "21_9", "CUSTOM", + ][..], + ), + ( + "aspect/pp/layerFill", + "Layer fill option", + &["LAYER_SETTING", "1_1", "CENTERED", "FULLSCREEN", "CROPPED"][..], + ), + ( + "cropping/control/pp/predefined", + "Input crop preset", + &[ + "NONE", + "LETTERBOX_1_78", + "LETTERBOX_1_85", + "LETTERBOX_2_35", + "PILLARBOX_1_33", + ][..], + ), + ] { + let path = format!("{base}/{suffix}"); + let Some(original) = snapshot.raw.pointer(&path) else { + continue; + }; + let mut value = self + .values + .get(&path) + .unwrap_or(original) + .as_str() + .unwrap_or_default() + .to_owned(); + let before = value.clone(); + ui.horizontal(|ui| { + ui.label(label); + egui::ComboBox::from_id_salt(&path) + .selected_text(setting_label(&value)) + .show_ui(ui, |ui| { + for option in options { + ui.selectable_value( + &mut value, + (*option).into(), + setting_label(option), + ); + } + }); + }); + if value != before { + self.stage(path, json!(value), original); + } + } + for (suffix, label, min, max, scale) in [ + ( + "aspect/pp/customRatio", + "Custom aspect ratio ", + 250., + 10000., + 0.001, + ), + ( + "cropping/control/pp/left", + "Input crop left ", + 0., + 8191., + 1., + ), + ( + "cropping/control/pp/right", + "Input crop right ", + 0., + 8191., + 1., + ), + ("cropping/control/pp/top", "Input crop top ", 0., 8191., 1.), + ( + "cropping/control/pp/bottom", + "Input crop bottom ", + 0., + 8191., + 1., + ), + ] { + let path = format!("{base}/{suffix}"); + let Some(original) = snapshot.raw.pointer(&path) else { + continue; + }; + let mut value = self + .values + .get(&path) + .unwrap_or(original) + .as_f64() + .unwrap_or_default() + * scale; + if ui + .add( + egui::DragValue::new(&mut value) + .range(min * scale..=max * scale) + .speed(scale) + .prefix(label) + .max_decimals(if scale == 1. { 0 } else { 3 }), + ) + .changed() + { + self.stage(path, json!((value / scale).round() as i64), original); + } + } + }); + ui.small("Edits wait for Send; opening this tab or enabling the checkbox sends nothing. Refresh/load after sending to inspect the device's resulting content dimensions."); + } + fn stage(&mut self, path: String, value: Value, original: &Value) { + if &value == original { + self.values.remove(&path); + } else { + self.values.insert(path, value); + } + } + pub fn extend_plan( + &self, + snapshot: &Snapshot, + mappings: &[(usize, String)], + plan: &mut Plan, + ) -> Result<(), String> { + if !self.enabled { + return Ok(()); + } + let inputs: BTreeSet<_> = mappings + .iter() + .filter_map(|(_, layer)| input_path(snapshot, &plan.screen, &plan.bank, layer)) + .collect(); + let mut changes = Vec::new(); + for (path, after) in &self.values { + if !inputs + .iter() + .any(|base| path.starts_with(&format!("{base}/"))) + { + continue; + } + let before = snapshot + .raw + .pointer(path) + .ok_or("Refresh the device: a staged input setting is unavailable.")?; + if before != after { + changes.push(Change { + path: path + .trim_start_matches('/') + .split('/') + .map(str::to_owned) + .collect(), + before: before.clone(), + after: after.clone(), + }); + } + } + changes.append(&mut plan.changes); + plan.changes = changes; + Ok(()) + } +} + +#[cfg(test)] +mod tests { + use super::*; + use midra_layout::device_send::Target; + + fn fixture() -> Snapshot { + Snapshot { + identity: "Test".into(), + screens: vec![], + raw: json!({"device": {"inputList": {"items": {"INPUT_4": {"status": {"pp": {"plug": "2"}}, "plugList": {"items": {"2": {"settings": {"aspect": {"pp": {"signal": "NATIVE", "transformTo": "SIGNAL", "customRatio": 1333, "layerFill": "LAYER_SETTING"}}, "cropping": {"control": {"pp": {"left": 0, "right": 0, "top": 0, "bottom": 0, "predefined": "NONE", "xUpdate": true}}}}}}}}}}, "screenList": {"items": {"1": {"presetList": {"items": {"UP": {"liveLayerList": {"items": {"1": {"source": {"pp": {"input": "INPUT_4"}}}, "2": {"source": {"pp": {"input": "INPUT_NONE"}}}}}}, "DOWN": {"liveLayerList": {"items": {"1": {"source": {"pp": {"input": "INPUT_NONE"}}}}}}}}}}}}}), + } + } + fn empty_plan() -> Plan { + Plan { + screen: "1".into(), + bank: "UP".into(), + target: Target::Preview, + changes: vec![], + } + } + + #[test] + fn connected_source_controls_open_read_only_and_unchecking_discards_edits() { + let mut snapshot = fixture(); + snapshot.screens.push(midra_layout::device::Screen { + id: "1".into(), + resolution: [1920, 1080], + preview_bank: "UP".into(), + layers: vec![], + }); + let link = midra_layout::MidraLink { + screen: "1".into(), + layer: "1".into(), + }; + let ctx = egui::Context::default(); + let mut edits = InputEdits::default(); + let mut draw = |edits: &mut InputEdits, events| { + ctx.run( + egui::RawInput { + screen_rect: Some(egui::Rect::from_min_size( + egui::Pos2::ZERO, + egui::vec2(900., 1000.), + )), + events, + ..Default::default() + }, + |ctx| { + egui::CentralPanel::default() + .show(ctx, |ui| edits.show(ui, Some(&snapshot), Some(&link))); + }, + ) + }; + draw(&mut edits, vec![]); + let output = draw(&mut edits, vec![]); + assert!(!edits.enabled); + assert!(edits.values.is_empty()); + assert!(output.shapes.iter().any(|shape| matches!(&shape.shape, egui::Shape::Text(t) if t.galley.text() == "Content ratio"))); + let pos = output + .shapes + .iter() + .find_map(|shape| match &shape.shape { + egui::Shape::Text(t) + if t.galley.text() + == "Edit advanced input settings and include my edits when sending" => + { + Some(t.pos + egui::vec2(10., 5.)) + } + _ => None, + }) + .unwrap(); + let click = |edits: &mut InputEdits, + draw: &mut dyn FnMut( + &mut InputEdits, + Vec, + ) -> egui::FullOutput| { + draw( + edits, + vec![ + egui::Event::PointerMoved(pos), + super::super::tests::mouse(pos, true), + ], + ); + draw(edits, vec![super::super::tests::mouse(pos, false)]); + }; + click(&mut edits, &mut draw); + assert!(edits.enabled); + assert!(edits.values.is_empty()); + edits.stage("test".into(), json!(40), &json!(0)); + click(&mut edits, &mut draw); + assert!(!edits.enabled); + assert!(edits.values.is_empty()); + } + + #[test] + fn default_enable_only_and_unrelated_layers_never_write_inputs() { + let snapshot = fixture(); + let mappings = [(1, "1".into())]; + let mut edits = InputEdits::default(); + let mut plan = empty_plan(); + edits.extend_plan(&snapshot, &mappings, &mut plan).unwrap(); + assert!(plan.changes.is_empty()); + edits.enabled = true; + edits.extend_plan(&snapshot, &mappings, &mut plan).unwrap(); + assert!(plan.changes.is_empty()); + let path = format!( + "{}/cropping/control/pp/left", + input_path(&snapshot, "1", "UP", "1").unwrap() + ); + edits.stage(path.clone(), json!(40), &json!(0)); + edits + .extend_plan(&snapshot, &[(2, "2".into())], &mut plan) + .unwrap(); + assert!(plan.changes.is_empty()); + edits.extend_plan(&snapshot, &mappings, &mut plan).unwrap(); + assert_eq!(plan.changes.len(), 1); + assert_eq!(plan.changes[0].path.join("/"), path.trim_start_matches('/')); + assert_eq!(plan.changes[0].after, json!(40)); + // Program has a different routed source and must not receive Preview input edits. + let mut program = empty_plan(); + program.bank = "DOWN".into(); + program.target = Target::Program; + edits + .extend_plan(&snapshot, &mappings, &mut program) + .unwrap(); + assert!(program.changes.is_empty()); + edits.enabled = false; + let mut disabled = empty_plan(); + edits + .extend_plan(&snapshot, &mappings, &mut disabled) + .unwrap(); + assert!(disabled.changes.is_empty()); + edits.clear(); + assert!(edits.values.is_empty()); + assert!(!edits.enabled); + } + + #[test] + fn reverted_values_are_not_staged_and_duplicate_routes_are_written_once() { + let snapshot = fixture(); + let path = format!( + "{}/aspect/pp/transformTo", + input_path(&snapshot, "1", "UP", "1").unwrap() + ); + let mut edits = InputEdits { + enabled: true, + ..Default::default() + }; + edits.stage(path.clone(), json!("16_9"), &json!("SIGNAL")); + let mut plan = empty_plan(); + edits + .extend_plan(&snapshot, &[(1, "1".into()), (2, "1".into())], &mut plan) + .unwrap(); + assert_eq!(plan.changes.len(), 1); + edits.stage(path, json!("SIGNAL"), &json!("SIGNAL")); + assert!(edits.values.is_empty()); + } +} diff --git a/crates/midra-layout/src/project_ui.rs b/crates/midra-layout/src/project_ui.rs index f7bab4d..c8e7c5a 100644 --- a/crates/midra-layout/src/project_ui.rs +++ b/crates/midra-layout/src/project_ui.rs @@ -73,6 +73,7 @@ impl Editor { .transpose()?; let e = project.editor; self.device.reset_mappings(); + self.device.input_edits.clear(); // Replace only after both the document and embedded image are ready. *self = Self { device: std::mem::take(&mut self.device), diff --git a/docs/interfaces/midra-device-send.md b/docs/interfaces/midra-device-send.md index b915f84..adad26d 100644 --- a/docs/interfaces/midra-device-send.md +++ b/docs/interfaces/midra-device-send.md @@ -1,6 +1,6 @@ # Midra reviewed layer exchange -This is a transient device protocol, not a project/save schema. Project v4 remains +This is a transient device protocol, not a project/save schema. Project v9 remains unchanged. Compatibility exercised: Eikos 4K firmware 3.3.10, installed WebRCS `app.e42fce4879f318b28cde.js`. Other firmware needs verification. @@ -13,7 +13,7 @@ A WebSocket at `ws://DEVICE_IP/` accepts JSON text: {"channel":"DEVICE","data":{"path":["device","screenList","items","2","presetList","items","UP","liveLayerList","items","1","position","pp","posH"],"value":162}} ``` -Reviewed fields under the mapped live layer are only: +Normal geometry fields under the mapped live layer are: - `size.pp.sizeH`, `size.pp.sizeV`: integer container pixels, 1–65535. - `position.pp.posH`, `position.pp.posV`: integer center coordinates, −67268–67268. @@ -22,7 +22,8 @@ Reviewed fields under the mapped live layer are only: At `AT_DOWN`, Preview is UP and Program DOWN; `AT_UP` reverses those roles. The selected configuration captures one physical bank. Send writes directly without a preflight read or stale-snapshot refusal. Commands do not retarget halfway through. No TAKE or source routing, -mask, effect, opacity, shared input crop or output setting is sent. +mask, effect, opacity or output setting is sent. Shared input aspect/crop fields +are omitted unless explicitly opted into and edited as described below. ## Conversion @@ -148,3 +149,52 @@ and `midra_link.layer` fields locally. **Unmap** saves `midra_link: null`, so linked sends and loads skip the layer. These edits are undoable and never issue device commands. Connected selectors use discovered screens/layers; offline editing accepts positive numeric IDs. Project schema and version are unchanged. + +## Opt-in advanced input edits (transient) + +The Source tab's device controls map one-for-one to the installed WebRCS +Advanced Input settings. They are separate from the editor's local source model +and its existing combined layer-crop conversion above. Field names, enum values, +ranges and input-crop update pulse were checked against the connected Eikos +snapshot and `app.e42fce4879f318b28cde.js`; this change did not write to hardware. + +Read the linked Preview layer's `source.pp.input`, then the input's +`status.pp.plug`. The write root is +`device/inputList/items/INPUT_N/plugList/items/P/settings/`: + +| Suffix | Encoding / units | +| --- | --- | +| `aspect/pp/signal` | `NATIVE`, `5_4`, `4_3`, `16_10`, `15_9`, `16_9`, `21_9`, `256_135`, `64_27` | +| `aspect/pp/transformTo` | `SIGNAL`, `5_4`, `4_3`, `16_10`, `15_9`, `16_9`, `21_9`, `CUSTOM` | +| `aspect/pp/customRatio` | Integer ratio × 1000, 250–10000; UI displays 0.250–10.000 | +| `aspect/pp/layerFill` | `LAYER_SETTING`, `1_1`, `CENTERED`, `FULLSCREEN`, `CROPPED` | +| `cropping/control/pp/predefined` | `NONE`, `LETTERBOX_1_78`, `LETTERBOX_1_85`, `LETTERBOX_2_35`, `PILLARBOX_1_33` | +| `cropping/control/pp/left`, `right`, `top`, `bottom` | Whole input pixels, 0–8191 | + +Input crop is processed before layer crop/zoom and does not set layer-container +resolution. These settings are shared across consumers of the physical input; +they are not bank-local. A Preview geometry send with opted-in input edits can +therefore affect a Program layer using the same input. Layer exports continue +to use their own Centered aspect override; input layer-fill edits may affect +other layers configured to inherit input settings. + +The checkbox defaults off; merely enabling it or opening the tab stages nothing. +Only edited fields are retained; reverting to the captured value removes the +edit. Plans include a staged field only when an explicitly mapped destination +in the chosen physical bank currently uses that input and plug. A Program +layer with different routing does not receive the Preview input's edits. +Duplicate mappings to one input add each field once per screen plan. Raw input +edits are listed in Exact device changes and apply to both reviewed and direct +linked sends. They never route sources or write unrelated input defaults. + +Input field writes precede layer writes. After writes, each changed input crop +gets its own `cropping/control/pp/xUpdate` false→true pulse, then the normal +preset update pulse runs. Readback checks edited values, excluding intermediate +pulse values. Existing partial-failure reporting applies; no automatic rollback +or resend. Refresh/load reads resulting device content geometry; the input +controls do not predict device resampling or update the local source model. + +This is session-only state, not part of project JSON, SVG, preferences or +recovery. Uncheck, disconnect, address change and project load discard staged +input edits and reset opt-in. Existing files migrate without changes and never +opt into shared input writes. No persistent format/version change is introduced. diff --git a/docs/midra-layout.md b/docs/midra-layout.md index 80d65db..981135f 100644 --- a/docs/midra-layout.md +++ b/docs/midra-layout.md @@ -558,6 +558,30 @@ Pending changes make Apply solid purple. This applies to position/size, output resolution drafts, source/input formats, names/folders, and mapped imports. Each section tracks its own values; reverting an edit clears its pending state. +**Source is an advanced section**, disabled until **Edit advanced input settings +and include my edits when sending** is checked. Its device controls mirror the +linked Preview layer's current input and active plug in WebRCS Advanced Input: +content ratio, transform ratio, custom ratio, layer fill, input crop preset and +four pixel crop edges. Usually keep these settings on the Midra. Input crop +runs before dynamic layer crop/zoom without resizing the layer bounding box; +this is device processing, not an editor-only effect. Inputs are shared, so an +input edit can also affect other layers and Program. + +Opening Source, checking the box, or changing a value does not send. Only fields +actually edited are staged for the next explicit Send, and only when that send +includes a destination routed to the same input/plug. Untouched aspect/crop +settings stay as they are on the machine. Unchecking discards staged edits. +The opt-in and device edits are session-only: disconnecting, changing the device +address or loading a project clears them. Source routing is never changed. +Refresh/load after sending to inspect the resulting device content dimensions. + +The separately labeled **Editor source model (local geometry)** retains the +existing offline format/input-resolution calculations, also gated by the checkbox. +Its native dimensions are metadata, not device timing commands. Its local input +correction still folds into exported *layer* crop; it does not configure the +shared hardware input. Apply source changes commits this local model, whereas +the device controls above wait for Send. + Layer properties has four tabs: **Source** for native/input resolution and input crop, **Layer** for the final visible box, **Crop** for content zoom and offset, and **Mapping** for editor input identity and the saved Midra screen/layer link. diff --git a/docs/midralayout/changelog.md b/docs/midralayout/changelog.md index fe15372..daa695d 100644 --- a/docs/midralayout/changelog.md +++ b/docs/midralayout/changelog.md @@ -4,6 +4,8 @@ ## Unreleased +- Make Source an advanced, opt-in section with explanations of input aspect correction and pre-layer input crop. Show the linked device input's actual WebRCS aspect/crop controls separately from the local geometry model. Stage only edited fields, include them in scoped sends only while enabled, and pulse input crop updates. The opt-in and staged device edits are session-only and clear on disconnect, address/project change or uncheck. Verified field names/ranges against the connected Eikos WebRCS; regression tests use mock devices, without hardware writes. + - Add a Mapping properties tab and right-click entry with selectable Midra screen/layer links and Unmap. Unmapped layers are excluded from linked sends/loads; link edits are local, saved with projects and undoable. Move the separate editor input identity selector into Mapping. - Draw the snapping dropdown chevron and layer order arrows as vector icons, avoiding missing font glyphs while preserving tooltips, disabled states and button accessibility.