diff --git a/crates/midra-layout/src/device_ui.rs b/crates/midra-layout/src/device_ui.rs index fa5de01..2b2e5ae 100644 --- a/crates/midra-layout/src/device_ui.rs +++ b/crates/midra-layout/src/device_ui.rs @@ -23,7 +23,6 @@ pub(super) struct DeviceUi { sizing: Sizing, pub(super) sending: bool, message: String, - send_targets: std::collections::BTreeMap, pub(super) host: String, pending: Option>>, snapshot: Option, @@ -33,7 +32,6 @@ pub(super) struct DeviceUi { } impl DeviceUi { pub(super) fn reset_mappings(&mut self) { - self.send_targets.clear(); self.destinations.fill(Destination::Skip); } pub(super) fn with_connection_preferences(host: String, allow_program: bool) -> Self { @@ -43,33 +41,57 @@ impl DeviceUi { ..Self::default() } } - fn selected_plan(&self, layout: &midra_layout::Layout) -> Result { + fn linked_plans(&self, layout: &midra_layout::Layout, all: bool) -> Result, String> { let snapshot = self.snapshot.as_ref().ok_or("Connect to Midra first.")?; - let mappings: Vec<_> = layout - .selected_indices() - .iter() - .map(|&i| { - let id = layout.layer_info(i).id; - (id, self.send_targets.get(&id).cloned().unwrap_or_default()) + let indices = if all { + (0..layout.layers().len()) + .filter(|&i| layout.layer_info(i).midra_link.is_some()) + .collect() + } else { + layout.selected_indices() + }; + if indices.is_empty() { + return Err("Choose layers and link their Midra destinations first.".into()); + } + let mut groups = std::collections::BTreeMap::>::new(); + for i in indices { + let info = layout.layer_info(i); + let link = info + .midra_link + .as_ref() + .ok_or_else(|| format!("{} has no Midra link.", info.name))?; + groups + .entry(link.screen.clone()) + .or_default() + .push((info.id, link.layer.clone())); + } + groups + .into_iter() + .map(|(screen, mappings)| { + let index = snapshot + .screens + .iter() + .position(|s| s.id == screen) + .ok_or_else(|| format!("Linked screen {screen} is unavailable."))?; + Plan::prepare( + snapshot, + layout, + index, + &mappings, + if self.allow_program { + self.target + } else { + Target::Preview + }, + self.sizing, + ) }) - .collect(); - Plan::prepare( - snapshot, - layout, - self.screen, - &mappings, - if self.allow_program { - self.target - } else { - Target::Preview - }, - self.sizing, - ) + .collect() } pub(super) fn online(&self) -> bool { self.snapshot.is_some() } - fn send(&mut self, ctx: &egui::Context, plan: Plan) { + fn send(&mut self, ctx: &egui::Context, plans: Vec) { let (tx, rx) = mpsc::channel(); self.pending = Some(rx); self.sending = true; @@ -78,7 +100,18 @@ impl DeviceUi { let host = self.host.clone(); let ctx = ctx.clone(); std::thread::spawn(move || { - let result = device_send::send(&host, &plan); + let result = (|| { + let mut last = None; + for (i, plan) in plans.iter().enumerate() { + last = Some(device_send::send(&host, plan).map_err(|e| { + format!( + "Screen {} failed after {i} completed screen sends: {e}", + plan.screen + ) + })?); + } + last.ok_or_else(|| "No linked layers to send.".into()) + })(); let _ = tx.send(result); ctx.request_repaint(); }); @@ -88,7 +121,6 @@ impl DeviceUi { self.pending = Some(rx); self.snapshot = None; self.destinations.clear(); - self.send_targets.clear(); self.error.clear(); self.message.clear(); let host = self.host.clone(); @@ -130,23 +162,28 @@ impl DeviceUi { } impl Editor { pub(super) fn midra_apply_button(&mut self, ui: &mut egui::Ui) { - let plan = self.device.selected_plan(&self.layout); + self.midra_send_button(ui, false); + } + pub(super) fn midra_send_button(&mut self, ui: &mut egui::Ui, all: bool) { + let plans = self.device.linked_plans(&self.layout, all); let enabled = self.device.online() && self.device.pending.is_none() - && plan.as_ref().map_or(true, |p| !p.changes.is_empty()); - let tooltip = match &plan { - Ok(p) if p.changes.is_empty() => { - "Selected layers already match the device snapshot.".into() - } - Ok(p) => format!( - "Send selected layers to {:?}, screen {}, bank {} using the configured destinations.", - p.target, p.screen, p.bank + && plans + .as_ref() + .map_or(true, |plans| plans.iter().any(|p| !p.changes.is_empty())); + let tooltip = match &plans { + Ok(plans) => format!( + "Send {} linked screen(s) to {:?} using saved layer destinations.", + plans.len(), + plans[0].target ), - Err(e) => format!("Configure layer destinations before sending. {e}"), + Err(e) => e.clone(), }; if apply_button( ui, - if self.device.sending { + if all { + "Send all linked layers" + } else if self.device.sending { "Applying…" } else { "Apply to Midra" @@ -157,17 +194,12 @@ impl Editor { .on_disabled_hover_text(&tooltip) .clicked() { - match plan { - Ok(plan) => { - self.device.send(ui.ctx(), plan); - self.device.prepare_send = true; - self.device.open = true; - } - Err(_) => { - self.device.prepare_send = true; - self.device.open = true; - } + match plans { + Ok(plans) => self.device.send(ui.ctx(), plans), + Err(error) => self.device.error = error, } + self.device.prepare_send = true; + self.device.open = true; ui.close_menu(); } } @@ -251,13 +283,27 @@ impl Editor { for (i, screen) in snapshot.screens.iter().enumerate() { ui.selectable_value(&mut self.device.screen, i, format!("Screen {} · {} × {}", screen.id, screen.resolution[0], screen.resolution[1])); } }); let screen = &snapshot.screens[self.device.screen]; - if previous != self.device.screen { self.device.destinations = vec![Destination::Skip; screen.layers.len()]; self.device.send_targets.clear(); } + if previous != self.device.screen { self.device.destinations = vec![Destination::Skip; screen.layers.len()]; } ui.label(format!("Captured Preview bank: {}. Refresh to read subsequent changes.", screen.preview_bank)); let matches = screen.resolution == self.layout.formats().output; if !matches { ui.colored_label(ui.visuals().warn_fg_color, format!("Device canvas {} × {}; editor {} × {}. Match output resolution before importing.", screen.resolution[0], screen.resolution[1], self.layout.formats().output[0], self.layout.formats().output[1])); } if self.device.prepare_send { - send_plan = send_review(ui, &self.layout, snapshot, self.device.screen, &mut self.device.send_targets, + let screen_id = screen.id.clone(); + let mut targets: std::collections::BTreeMap<_, _> = self.layout.selected_indices().into_iter().map(|i| { + let info = self.layout.layer_info(i); + (info.id, info.midra_link.as_ref().filter(|link| link.screen == screen_id).map(|link| link.layer.clone()).unwrap_or_default()) + }).collect(); + let previous = targets.clone(); + send_plan = send_review(ui, &self.layout, snapshot, self.device.screen, &mut targets, &mut self.device.target, &mut self.device.sizing, self.device.pending.is_some(), self.device.allow_program); + 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(); + let link = (!destination.is_empty()).then_some(midra_layout::MidraLink { screen: screen_id.clone(), layer: destination }); + if let Err(e) = self.layout.set_midra_link(i, link) { self.device.error = e; } + } + } + self.midra_send_button(ui, true); return; } egui::ScrollArea::vertical().max_height(300.0).show(ui, |ui| { @@ -311,7 +357,7 @@ impl Editor { }); self.device.open = open; if let Some(plan) = send_plan { - self.device.send(ctx, plan); + self.device.send(ctx, vec![plan]); } if imported { self.sync(); @@ -361,7 +407,14 @@ fn send_review( } let mut used = std::collections::BTreeSet::new(); for i in selected { - let id = layout.layer_info(i).id; + let info = layout.layer_info(i); + let id = info.id; + if let Some(link) = &info.midra_link { + ui.weak(format!( + "Saved link: screen {} · layer {}", + link.screen, link.layer + )); + } let target = targets.entry(id).or_default(); ui.separator(); ui.horizontal(|ui| { @@ -467,6 +520,65 @@ fn container_label(geometry: midra_layout::Geometry) -> String { #[cfg(test)] mod tests { use super::*; + fn linked_test_snapshot() -> device::Snapshot { + let layer = serde_json::json!({"position":{"pp":{"posH":500,"posV":300}},"size":{"pp":{"sizeH":640,"sizeV":360}},"source":{"pp":{"input":"INPUT_4"}},"status":{"pp":{"contentWidth":1920,"contentHeight":1080}},"crop":{"pp":{"left":0,"right":0,"top":0,"bottom":0,"aspectOverride":"GLOBAL_SETTING"}},"mask":{"pp":{"left":0,"right":0,"top":0,"bottom":0}}}); + let raw = serde_json::json!({"device": {"transition":{"screenList":{"items":{"1":{"status":{"pp":{"transition":"AT_DOWN"}}}}}},"screenList":{"items":{"1":{"canvas":{"status":{"size":{"pp":{"sizeH":1920,"sizeV":1080}}}},"presetList":{"items":{"UP":{"liveLayerList":{"items":{"1":layer,"2":layer}}},"DOWN":{"liveLayerList":{"items":{"1":layer,"2":layer}}}}}}}}}}); + device::Snapshot::parse( + &serde_json::json!({"type":"Eikos 4K","version":{"major":3,"minor":3,"patch":10}}), + &raw, + ) + .unwrap() + } + #[test] + fn all_linked_plans_include_hidden_locked_unselected_layers_across_screens() { + let mut snapshot = linked_test_snapshot(); + let second = snapshot.raw["device"]["screenList"]["items"]["1"].clone(); + snapshot.raw["device"]["screenList"]["items"]["2"] = second; + let transition = snapshot.raw["device"]["transition"]["screenList"]["items"]["1"].clone(); + snapshot.raw["device"]["transition"]["screenList"]["items"]["2"] = transition; + let mut screen = snapshot.screens[0].clone(); + screen.id = "2".into(); + snapshot.screens.push(screen); + let mut state = DeviceUi { + snapshot: Some(snapshot), + ..Default::default() + }; + let mut layout = midra_layout::Layout::default(); + for i in 0..2 { + layout + .set_midra_link( + i, + Some(midra_layout::MidraLink { + screen: (i + 1).to_string(), + layer: "1".into(), + }), + ) + .unwrap(); + } + layout.set_visible(0, false); + layout.set_locked(1, true); + layout.select(None); + assert!(state.linked_plans(&layout, false).is_err()); + let plans = state.linked_plans(&layout, true).unwrap(); + assert_eq!(plans.len(), 2); + assert_eq!(plans[0].screen, "1"); + assert_eq!(plans[1].screen, "2"); + assert!(plans.iter().all(|p| !p.changes.is_empty())); + state.reset_mappings(); + assert_eq!(state.linked_plans(&layout, true).unwrap().len(), 2); + layout + .set_midra_link( + 1, + Some(midra_layout::MidraLink { + screen: "1".into(), + layer: "1".into(), + }), + ) + .unwrap(); + assert!(state.linked_plans(&layout, true).is_err()); + layout.set_midra_link(1, None).unwrap(); + assert_eq!(state.linked_plans(&layout, true).unwrap().len(), 1); + } #[test] fn program_destination_is_hidden_and_reset_until_enabled() { for allow in [false, true] { diff --git a/crates/midra-layout/src/gui.rs b/crates/midra-layout/src/gui.rs index 0932806..94c3dd5 100644 --- a/crates/midra-layout/src/gui.rs +++ b/crates/midra-layout/src/gui.rs @@ -2415,8 +2415,17 @@ impl Editor { self.midra_apply_button(ui); }, ); + ui.scope_builder( + egui::UiBuilder::new().max_rect(Rect::from_min_size( + r.min + Vec2::new(212.0, 5.0), + Vec2::new(160.0, 25.0), + )), + |ui| { + self.midra_send_button(ui, true); + }, + ); ink.text( - 248.0, + 382.0, 10.0, if !self.layout.selected_indices().is_empty() { "Shift-click or drag a box to select layers" diff --git a/crates/midra-layout/src/lib.rs b/crates/midra-layout/src/lib.rs index f75e3ff..6f9be51 100644 --- a/crates/midra-layout/src/lib.rs +++ b/crates/midra-layout/src/lib.rs @@ -301,7 +301,27 @@ pub enum AlignTarget { /// Persistent identity independent of list order or device layer numbering. #[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)] #[serde(deny_unknown_fields)] +pub struct MidraLink { + pub screen: String, + pub layer: String, +} +impl MidraLink { + pub fn validate(&self) -> Result<(), String> { + if [&self.screen, &self.layer].iter().any(|id| { + id.is_empty() + || id.len() > 16 + || !id.bytes().all(|b| b.is_ascii_digit()) + || id.parse::().unwrap_or(0) == 0 + }) { + return Err("Midra screen and layer IDs must be positive decimal identifiers.".into()); + } + Ok(()) + } +} +#[derive(Clone, Debug, PartialEq, serde::Serialize, serde::Deserialize)] +#[serde(deny_unknown_fields)] pub struct LayerInfo { + pub midra_link: Option, pub id: usize, pub name: String, pub folder: String, @@ -348,11 +368,13 @@ impl Default for Layout { Self { info: vec![ LayerInfo { + midra_link: None, id: 1, name: "Presenter".into(), folder: String::new(), }, LayerInfo { + midra_link: None, id: 2, name: "Slides".into(), folder: String::new(), @@ -417,6 +439,22 @@ impl Layout { self.layers = s.layers; self.formats = s.formats; } + pub fn set_midra_link(&mut self, i: usize, link: Option) -> Result<(), String> { + if i >= self.info.len() { + return Err("Layer no longer exists.".into()); + } + if let Some(link) = &link { + link.validate()?; + } + if self.info[i].midra_link == link { + return Ok(()); + } + self.finish_drag(); + let before = self.snapshot(); + self.info[i].midra_link = link; + self.remember(before); + Ok(()) + } pub fn layer_info(&self, i: usize) -> &LayerInfo { &self.info[i] } @@ -479,6 +517,7 @@ impl Layout { }; self.layers.push(g); self.info.push(LayerInfo { + midra_link: None, id: self.next_id, name: format!("Layer {}", self.next_id), folder: String::new(), diff --git a/crates/midra-layout/src/project.rs b/crates/midra-layout/src/project.rs index 80b283a..1c9d545 100644 --- a/crates/midra-layout/src/project.rs +++ b/crates/midra-layout/src/project.rs @@ -34,6 +34,8 @@ pub struct Input { #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(deny_unknown_fields)] pub struct Layer { + #[serde(deserialize_with = "deserialize_link")] + pub midra_link: Option, pub name: String, pub folder: String, pub id: usize, @@ -43,6 +45,11 @@ pub struct Layer { pub visible: bool, pub locked: bool, } +fn deserialize_link<'de, D: serde::Deserializer<'de>>( + deserializer: D, +) -> Result, D::Error> { + Option::::deserialize(deserializer) +} #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(deny_unknown_fields)] pub struct Reference { @@ -106,7 +113,7 @@ impl Project { pub fn from_layout(layout: &Layout) -> Self { Self { format: FORMAT.into(), - version: 4, + version: 5, next_layer_id: layout.next_id, output_resolution: layout.formats.output.into(), inputs: (0..layout.formats.sources.len()) @@ -122,6 +129,7 @@ impl Project { .collect(), layers: (0..layout.layers.len()) .map(|i| Layer { + midra_link: layout.info[i].midra_link.clone(), name: layout.info[i].name.clone(), folder: layout.info[i].folder.clone(), id: layout.info[i].id, @@ -151,9 +159,9 @@ impl Project { } /// Build a fresh document only after validating the entire file. No history is restored. pub fn layout(&self) -> Result { - if self.format != FORMAT || self.version != 4 { + if self.format != FORMAT || self.version != 5 { return Err( - "Unsupported project format/version; expected beffroi.midra-layout version 4." + "Unsupported project format/version; expected beffroi.midra-layout version 5." .into(), ); } @@ -212,7 +220,11 @@ impl Project { { return Err("Invalid layer identity, name, folder or source ID.".into()); } + if let Some(link) = &layer.midra_link { + link.validate()?; + } layout.info.push(crate::LayerInfo { + midra_link: layer.midra_link.clone(), id: layer.id, name: layer.name.clone(), folder: layer.folder.clone(), @@ -337,6 +349,16 @@ impl Project { } migrated["version"] = 4.into(); } + if (1..=4).contains(&header.version) { + for layer in migrated["layers"].as_array_mut().ok_or("Missing layers")? { + let layer = layer.as_object_mut().ok_or("Invalid layer")?; + if layer.contains_key("midra_link") { + return Err("Unexpected Midra link in old project".into()); + } + layer.insert("midra_link".into(), serde_json::Value::Null); + } + migrated["version"] = 5.into(); + } let p: Self = serde_json::from_value(migrated).map_err(|e| format!("Invalid project JSON: {e}"))?; p.layout()?; diff --git a/crates/midra-layout/src/project_ui.rs b/crates/midra-layout/src/project_ui.rs index 515174c..85ef9d7 100644 --- a/crates/midra-layout/src/project_ui.rs +++ b/crates/midra-layout/src/project_ui.rs @@ -142,6 +142,7 @@ impl Editor { } pub(super) fn export_menu(&mut self, ui: &mut egui::Ui) { self.midra_apply_button(ui); + self.midra_send_button(ui, true); if ui.button("Configure Midra export…").clicked() { self.device.prepare_send = true; self.device.open = true; diff --git a/crates/midra-layout/tests/project.rs b/crates/midra-layout/tests/project.rs index f14a882..4b4a085 100644 --- a/crates/midra-layout/tests/project.rs +++ b/crates/midra-layout/tests/project.rs @@ -191,3 +191,44 @@ fn v4_example_and_old_version_migrations_preserve_defaults() { .remove("outline_layers"); assert!(Project::from_json(&value.to_string()).is_err()); } + +#[test] +fn persistent_midra_links_roundtrip_migrate_and_undo() { + use midra_layout::MidraLink; + let mut layout = Layout::default(); + let link = MidraLink { + screen: "2".into(), + layer: "1".into(), + }; + layout.set_midra_link(1, Some(link.clone())).unwrap(); + layout.select(None); + let project = Project::from_layout(&layout); + let restored = Project::from_json(&project.to_json().unwrap()) + .unwrap() + .layout() + .unwrap(); + assert_eq!(restored.layer_info(1).midra_link, Some(link.clone())); + layout.undo(); + assert!(layout.layer_info(1).midra_link.is_none()); + layout.redo(); + assert_eq!(layout.layer_info(1).midra_link, Some(link)); + layout.set_midra_link(1, None).unwrap(); + assert!(layout.layer_info(1).midra_link.is_none()); + for text in [ + include_str!("../../../docs/interfaces/midra-layout-v4.example.json"), + include_str!("../../../docs/interfaces/midra-layout-v5.example.json"), + ] { + let p = Project::from_json(text).unwrap(); + assert_eq!(p.version, 5); + assert!(p.layers.iter().all(|l| l.midra_link.is_none())); + } + let mut value = serde_json::to_value(&project).unwrap(); + value["layers"][1]["midra_link"]["screen"] = "../2".into(); + assert!(Project::from_json(&value.to_string()).is_err()); + value["layers"][1]["midra_link"] = serde_json::Value::Null; + value["layers"][1] + .as_object_mut() + .unwrap() + .remove("midra_link"); + assert!(Project::from_json(&value.to_string()).is_err()); +} diff --git a/docs/interfaces/midra-device-send.md b/docs/interfaces/midra-device-send.md index 69e573f..326173d 100644 --- a/docs/interfaces/midra-device-send.md +++ b/docs/interfaces/midra-device-send.md @@ -70,10 +70,11 @@ to avoid temporarily exhausting the retained area while moving a crop. Readback checks every changed field. No-op plans are disabled. Failure reports partial/uncertain outcomes without blind retries or automatic rollback. -Program selection is explicit. The application defaults to Preview and hides Program unless the persisted `allow_sending_to_program` preference is enabled. Turning it off resets the exporter to Preview, including quick Apply. Mappings, -plans and raw snapshots are not saved in projects or preferences. The device address is saved in [application settings](midra-layout-settings.md), never in projects. Refresh and screen changes reset destination review. Physical display +Program selection is explicit. The application defaults to Preview and hides Program unless the persisted `allow_sending_to_program` preference is enabled. Turning it off resets the exporter to Preview, including quick Apply. Layer screen/destination links are saved in project version 5. Plans and raw snapshots are not saved in projects or preferences. The device address is saved in [application settings](midra-layout-settings.md), never in projects. Refresh and screen changes preserve saved links. Physical display validation remains separate from the successful device-field and import round trips. -The status-bar and Export-menu **Apply to Midra** actions prepare a fresh plan for the current editor selection using the session mappings, target and sizing mode. Valid changed plans send immediately with readback verification, without a preflight refusal. Missing or invalid mappings open the configuration window without writing; no-op plans and busy/offline actions are disabled. No persistent schema changes are involved. +The status-bar and Export-menu **Apply to Midra** actions prepare a fresh plan for the current editor selection using saved layer links and the session target and sizing mode. Valid changed plans send immediately with readback verification, without a preflight refusal. Missing or invalid mappings open the configuration window without writing; no-op plans and busy/offline actions are disabled. No persistent schema changes are involved. Snapshot layer lists omit unassigned source slots (`NONE` or empty), before geometry validation. Assigned layers remain available even when OFF. + +**Send all linked layers** includes all linked document layers, even unselected, hidden or locked ones. Plans are grouped by saved screen ID and all groups are validated before starting. Screen groups send sequentially with readback; on failure later groups are not sent, and the result reports the failed screen and completed-group count. Links never auto-send and are not tied to an IP address. diff --git a/docs/interfaces/midra-layout-settings.md b/docs/interfaces/midra-layout-settings.md index b230978..c48429f 100644 --- a/docs/interfaces/midra-layout-settings.md +++ b/docs/interfaces/midra-layout-settings.md @@ -56,7 +56,7 @@ the previous destination where atomic publication failed; Options offers a retry Failure to locate a configuration directory also disables persistence with an Options error. Tests use temporary directories and never touch user settings. -The device address is saved immediately when edited in **Midra connection…**. Loading settings never connects or sends. Opening a project preserves the current connection and address, and clears transfer mappings. Connection status, snapshots and mappings are not persisted. Restore default preferences leaves the connection address unchanged; edit it in the connection window. +The device address is saved immediately when edited in **Midra connection…**. Loading settings never connects or sends. Opening a project preserves the current connection and address, clears import choices, and loads the project’s saved layer destination links. Connection status and snapshots are not persisted. Layer destination links are saved in project JSON, not application settings. Restore default preferences leaves the connection address unchanged; edit it in the connection window. No layer geometry, source crops, camera state, project paths, image bytes or clipboard contents are stored. No settings are exported to SVG. Breaking or additive schema changes under this strict contract require a version diff --git a/docs/interfaces/midra-layout-v5.example.json b/docs/interfaces/midra-layout-v5.example.json new file mode 100644 index 0000000..3e66e33 --- /dev/null +++ b/docs/interfaces/midra-layout-v5.example.json @@ -0,0 +1,99 @@ +{ + "format": "beffroi.midra-layout", + "version": 5, + "output_resolution": { + "width": 1920, + "height": 1080 + }, + "inputs": [ + { + "id": 1, + "source_format": "sixteen_nine", + "native_resolution": { + "width": 1920, + "height": 1080 + }, + "input_crop": { + "left": 0.0, + "right": 0.0, + "top": 0.0, + "bottom": 0.0 + } + }, + { + "id": 2, + "source_format": "sixteen_nine", + "native_resolution": { + "width": 1920, + "height": 1080 + }, + "input_crop": { + "left": 0.0, + "right": 0.0, + "top": 0.0, + "bottom": 0.0 + } + } + ], + "layers": [ + { + "id": 1, + "source_id": 1, + "bounds": { + "x": 120.0, + "y": 180.0, + "width": 640.0, + "height": 360.0 + }, + "advanced_crop": { + "left": 0.0, + "right": 0.0, + "top": 0.0, + "bottom": 0.0 + }, + "visible": true, + "locked": false, + "name": "Presenter", + "folder": "", + "midra_link": null + }, + { + "id": 2, + "source_id": 2, + "bounds": { + "x": 1160.0, + "y": 180.0, + "width": 640.0, + "height": 360.0 + }, + "advanced_crop": { + "left": 0.0, + "right": 0.0, + "top": 0.0, + "bottom": 0.0 + }, + "visible": true, + "locked": false, + "name": "Slides", + "folder": "", + "midra_link": null + } + ], + "reference": null, + "editor": { + "selected_layer_ids": [ + 2 + ], + "position_corner": "top_left", + "keep_aspect_ratio": true, + "viewport_zoom": 1.0, + "viewport_pan": [ + 0.0, + 0.0 + ], + "show_source_pattern": false, + "show_toolbar_icon_names": false, + "outline_layers": false + }, + "next_layer_id": 3 +} diff --git a/docs/interfaces/midra-layout.md b/docs/interfaces/midra-layout.md index 935a25e..fe2feb1 100644 --- a/docs/interfaces/midra-layout.md +++ b/docs/interfaces/midra-layout.md @@ -5,7 +5,7 @@ These are offline editor formats, not Analog Way REST payloads. Implementation: [`project.rs`](../../crates/midra-layout/tests/project.rs). Update this contract, examples and tests in the same change as any save/export schema change. -## Project JSON, version 4 +## Project JSON, version 5 Suggested filename: `layout.midra.json`. Encoding: UTF-8, pretty-printed JSON, with a trailing newline. A project preserves applied document values at their @@ -18,16 +18,16 @@ and `next_layer_id: 3`; other values are preserved. The [version 1 example](midra-layout-v1.example.json) remains a migration fixture. Version 4 adds `editor.outline_layers: false`, and reference `native_size: false` and `offset: [0, 0]` when migrating versions 1–3. Old fitting behavior is preserved. -Saving always writes version 4. Older applications reject version 4 files. +Version 5 adds required `midra_link` to every layer. Versions 1–4 migrate with null links; links cannot be supplied under an older version. Saving always writes version 5. Older applications reject version 5 files. Incompatible files are never partially applied. -[Complete example](midra-layout-v4.example.json) is a valid default project, +[Complete example](midra-layout-v5.example.json) is a valid default project, without a reference image. It is loaded by the regression tests. | Root field | Representation / meaning | | --- | --- | | `format` | Exactly `"beffroi.midra-layout"` | -| `version` | Integer `4` | +| `version` | Integer `5` | | `next_layer_id` | Positive integer strictly greater than every layer ID; not rewound by undo | | `output_resolution` | `{ "width": integer, "height": integer }`, screen pixels | | `inputs` | 1–1024 input objects, consecutive IDs starting at 1 | @@ -55,6 +55,7 @@ Layer objects: | --- | --- | | `id` | Unique positive stable editor layer ID; independent of list position and Midra mapping | | `name` | Nonblank display name, at most 128 characters | +| `midra_link` | Required: null (unlinked) or `{ "screen": "2", "layer": "1" }`. Positive decimal device IDs as strings, at most 16 ASCII digits; unknown fields rejected. No host, bank or credentials. | | `folder` | Local folder name, at most 128 characters; empty means ungrouped | | `source_id` | Existing input slot ID; multiple layers may share an input | | `bounds` | `{ "x": number, "y": number, "width": number, "height": number }`, final visible box in screen pixels; x/y are its top-left position | @@ -164,9 +165,11 @@ and `viewBox="0 0 W H"` equal to the output screen. The root carries ## Compatibility changes -Project version 4 and SVG version 1 are strict contracts. A breaking project field/meaning change must bump +Project version 5 and SVG version 1 are strict contracts. A breaking project field/meaning change must bump `version` and either implement a tested migration or clearly reject older/newer files. Changing rectangle/marker semantics requires a corresponding documented SVG interface revision and importer tests. Update this document and its example with every schema or semantic change, including additive fields under the strict unknown-field policy. Never silently interpret a future version as a supported version. + +Midra links belong to layer identity and survive selection changes, refresh, rename, reorder and project round trips. Link edits support Undo/Redo. New layers and older projects start unlinked. Links refer to the currently connected device; Preview/Program and sizing remain session choices, and Program permission remains an application preference. Duplicate destinations can be stored, but a send containing duplicates is rejected before any writes. Unavailable screens/layers are reported without deleting the saved links. SVG exports geometry only and omits links. diff --git a/docs/midra-layout.md b/docs/midra-layout.md index ff11383..71e4e5a 100644 --- a/docs/midra-layout.md +++ b/docs/midra-layout.md @@ -625,3 +625,5 @@ Layer rows use padlock and eye icon buttons for locking and visibility, with too Snapping also applies to side and corner resizing, including with aspect ratio locked. Hold **Shift** during a resize to temporarily invert snapping (on when disabled, off when enabled); release uses the current modifier state. **Alt** still disables snapping. Shift-drag on a resize handle resizes; Shift-click and Shift-drag elsewhere retain selection behavior. Midra layer lists omit unassigned source slots (`NONE` or empty). Assigned inputs remain listed even if the layer is off. The exporter defaults to Preview and hides Program until **Preferences → Midra integration → Allow sending to Program** is checked. This preference is saved automatically; turning it off returns the exporter and quick Apply action to Preview. + +Destination choices in **Configure Midra export…** now save immediately on the editor layer and support Undo. Save the project JSON to keep links across sessions. Links include screen and layer IDs and survive refreshes and selection changes. Choose the empty destination on the linked screen to unlink. **Send all linked layers** is available beside Apply, in Export and in the send window; it includes unselected, hidden and locked linked layers, grouped by screen. The usual Apply action sends selected linked layers. Preview/Program and sizing still use the current export options.