diff --git a/crates/components/connections/protocols/dmx/src/module.rs b/crates/components/connections/protocols/dmx/src/module.rs index 119c3f0a7..3f343a832 100644 --- a/crates/components/connections/protocols/dmx/src/module.rs +++ b/crates/components/connections/protocols/dmx/src/module.rs @@ -2,8 +2,8 @@ use crate::dmx_monitor::create_monitor; use mizer_module::*; use crate::processor::DmxProcessor; -use crate::DmxConnectionManager; use crate::project_handler::DmxProjectHandler; +use crate::DmxConnectionManager; pub struct DmxModule; diff --git a/crates/components/connections/protocols/dmx/src/project_handler.rs b/crates/components/connections/protocols/dmx/src/project_handler.rs index de311ad0f..1e37791c7 100644 --- a/crates/components/connections/protocols/dmx/src/project_handler.rs +++ b/crates/components/connections/protocols/dmx/src/project_handler.rs @@ -1,8 +1,11 @@ +use crate::{ + ArtnetInput, ArtnetOutput, DmxConnectionManager, DmxInput, DmxInputConnection, + DmxOutputConnection, SacnOutput, +}; +use mizer_module::*; +use serde::{Deserialize, Serialize}; use std::collections::HashMap; use std::net::Ipv4Addr; -use serde::{Deserialize, Serialize}; -use mizer_module::*; -use crate::{ArtnetInput, ArtnetOutput, DmxConnectionManager, DmxInput, DmxInputConnection, DmxOutputConnection, SacnOutput}; pub struct DmxProjectHandler; @@ -28,7 +31,11 @@ impl ProjectHandler for DmxProjectHandler { "connections" } - fn new_project(&mut self, _context: &mut impl ProjectHandlerContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn new_project( + &mut self, + _context: &mut impl ProjectHandlerContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { let Some(dmx_manager) = injector.try_inject_mut::() else { anyhow::bail!("DMX connection manager not found"); }; @@ -39,7 +46,11 @@ impl ProjectHandler for DmxProjectHandler { Ok(()) } - fn load_project(&mut self, context: &mut impl LoadProjectContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { profiling::scope!("DmxProjectHandler::load_project"); let Some(dmx_manager) = injector.try_inject_mut::() else { anyhow::bail!("DMX connection manager not found"); @@ -51,21 +62,23 @@ impl ProjectHandler for DmxProjectHandler { DmxConfig::Sacn { priority } => { dmx_manager.add_output(id, SacnOutput::new(priority)) } - DmxConfig::ArtnetOutput { port, host } => dmx_manager.add_output( - id, - ArtnetOutput::new(host, port)?, - ), - DmxConfig::ArtnetInput { port, host, name } => dmx_manager.add_input( - id, - ArtnetInput::new(host, port, name)?, - ), + DmxConfig::ArtnetOutput { port, host } => { + dmx_manager.add_output(id, ArtnetOutput::new(host, port)?) + } + DmxConfig::ArtnetInput { port, host, name } => { + dmx_manager.add_input(id, ArtnetInput::new(host, port, name)?) + } } } Ok(()) } - fn save_project(&self, context: &mut impl SaveProjectContext, injector: &dyn InjectDyn) -> anyhow::Result<()> { + fn save_project( + &self, + context: &mut impl SaveProjectContext, + injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { profiling::scope!("DmxProjectHandler::save_project"); let Some(dmx_manager) = injector.try_inject::() else { anyhow::bail!("DMX connection manager not found"); @@ -108,4 +121,3 @@ fn get_input_config(connection: &DmxInputConnection) -> DmxConfig { }, } } - diff --git a/crates/components/connections/protocols/mqtt/src/project_handler.rs b/crates/components/connections/protocols/mqtt/src/project_handler.rs index 66f68efba..86f8a3318 100644 --- a/crates/components/connections/protocols/mqtt/src/project_handler.rs +++ b/crates/components/connections/protocols/mqtt/src/project_handler.rs @@ -1,6 +1,6 @@ -use std::collections::HashMap; -use mizer_module::*; use crate::{MqttAddress, MqttConnectionManager}; +use mizer_module::*; +use std::collections::HashMap; const CONNECTIONS_FILE_NAME: &str = "mqtt"; @@ -11,7 +11,11 @@ impl ProjectHandler for MqttProjectHandler { "connections" } - fn new_project(&mut self, _context: &mut impl ProjectHandlerContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn new_project( + &mut self, + _context: &mut impl ProjectHandlerContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { let Some(mqtt_manager) = injector.try_inject_mut::() else { tracing::warn!("MQTT connection manager not found"); return Ok(()); @@ -22,7 +26,11 @@ impl ProjectHandler for MqttProjectHandler { Ok(()) } - fn load_project(&mut self, context: &mut impl LoadProjectContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { profiling::scope!("MqttProjectHandler::load_project"); let Some(mqtt_manager) = injector.try_inject_mut::() else { tracing::warn!("MQTT connection manager not found"); @@ -37,7 +45,11 @@ impl ProjectHandler for MqttProjectHandler { Ok(()) } - fn save_project(&self, context: &mut impl SaveProjectContext, injector: &dyn InjectDyn) -> anyhow::Result<()> { + fn save_project( + &self, + context: &mut impl SaveProjectContext, + injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { profiling::scope!("MqttProjectHandler::save_project"); let Some(mqtt_manager) = injector.try_inject::() else { tracing::warn!("MQTT connection manager not found"); diff --git a/crates/components/connections/protocols/osc/src/project_handler.rs b/crates/components/connections/protocols/osc/src/project_handler.rs index 0712106a9..4202ad549 100644 --- a/crates/components/connections/protocols/osc/src/project_handler.rs +++ b/crates/components/connections/protocols/osc/src/project_handler.rs @@ -1,6 +1,6 @@ -use std::collections::HashMap; -use mizer_module::*; use crate::{OscAddress, OscConnectionManager}; +use mizer_module::*; +use std::collections::HashMap; const CONNECTIONS_FILE_NAME: &str = "osc"; @@ -11,7 +11,11 @@ impl ProjectHandler for OscProjectHandler { "connections" } - fn new_project(&mut self, _context: &mut impl ProjectHandlerContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn new_project( + &mut self, + _context: &mut impl ProjectHandlerContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { let Some(osc_manager) = injector.try_inject_mut::() else { tracing::warn!("OSC connection manager not found"); return Ok(()); @@ -22,7 +26,11 @@ impl ProjectHandler for OscProjectHandler { Ok(()) } - fn load_project(&mut self, context: &mut impl LoadProjectContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { profiling::scope!("OscProjectHandler::load_project"); let Some(osc_manager) = injector.try_inject_mut::() else { tracing::warn!("OSC connection manager not found"); @@ -37,7 +45,11 @@ impl ProjectHandler for OscProjectHandler { Ok(()) } - fn save_project(&self, context: &mut impl SaveProjectContext, injector: &dyn InjectDyn) -> anyhow::Result<()> { + fn save_project( + &self, + context: &mut impl SaveProjectContext, + injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { profiling::scope!("OscProjectHandler::save_project"); let Some(osc_manager) = injector.try_inject::() else { tracing::warn!("OSC connection manager not found"); diff --git a/crates/components/fixtures/src/config.rs b/crates/components/fixtures/src/config.rs index b1fa37429..2b93fcb5a 100644 --- a/crates/components/fixtures/src/config.rs +++ b/crates/components/fixtures/src/config.rs @@ -1,6 +1,6 @@ -use serde::{Deserialize, Serialize}; use crate::fixture::FixtureConfiguration; use crate::programmer::{Color, Position, Preset, Presets}; +use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct FixtureConfig { diff --git a/crates/components/fixtures/src/manager.rs b/crates/components/fixtures/src/manager.rs index 8a68da8a7..8a4c8434b 100644 --- a/crates/components/fixtures/src/manager.rs +++ b/crates/components/fixtures/src/manager.rs @@ -8,6 +8,7 @@ use mizer_module::*; use mizer_protocol_dmx::DmxConnectionManager; use rayon::prelude::*; +use crate::config::{FixtureConfig, PresetsStore}; use crate::definition::{ FixtureControl, FixtureControlType, FixtureControlValue, FixtureDefinition, FixtureFaderControl, }; @@ -17,7 +18,6 @@ use crate::programmer::{ GenericPreset, Group, Position, Preset, PresetId, PresetType, Presets, Programmer, }; use crate::{FixtureId, FixturePriority, FixtureStates, GroupId}; -use crate::config::{FixtureConfig, PresetsStore}; #[derive(Clone)] pub struct FixtureManager { @@ -437,14 +437,22 @@ impl ProjectHandler for FixtureManager { "fixtures" } - fn new_project(&mut self, _context: &mut impl ProjectHandlerContext, _injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn new_project( + &mut self, + _context: &mut impl ProjectHandlerContext, + _injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { self.clear(); self.presets.load_defaults(); Ok(()) } - fn load_project(&mut self, context: &mut impl LoadProjectContext, _injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + _injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { profiling::scope!("FixtureManager::load_project"); self.clear(); let fixtures = context.read_file::>("patch")?; @@ -468,8 +476,7 @@ impl ProjectHandler for FixtureManager { ); context.report_issue(format!( "No fixture definition for fixture id {}. Missing fixture definition: {}", - fixture.id, - fixture.fixture + fixture.id, fixture.fixture )); } } @@ -483,7 +490,11 @@ impl ProjectHandler for FixtureManager { Ok(()) } - fn save_project(&self, context: &mut impl SaveProjectContext, _injector: &dyn InjectDyn) -> anyhow::Result<()> { + fn save_project( + &self, + context: &mut impl SaveProjectContext, + _injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { profiling::scope!("FixtureManager::save_project"); let mut fixtures = Vec::with_capacity(self.fixtures.len()); for fixture in self.get_fixtures() { diff --git a/crates/components/media/src/lib.rs b/crates/components/media/src/lib.rs index 56c34d119..d42dda6d8 100644 --- a/crates/components/media/src/lib.rs +++ b/crates/components/media/src/lib.rs @@ -22,9 +22,9 @@ mod file_storage; mod import_handler; pub mod media_handlers; mod module; +mod project_loading; pub mod queries; mod thumbnail_generator; -mod project_loading; #[derive(Clone)] #[repr(transparent)] diff --git a/crates/components/media/src/project_loading.rs b/crates/components/media/src/project_loading.rs index 8010a6a07..0ff1e7743 100644 --- a/crates/components/media/src/project_loading.rs +++ b/crates/components/media/src/project_loading.rs @@ -1,18 +1,26 @@ -use mizer_module::*; use crate::MediaServer; +use mizer_module::*; impl ProjectHandler for MediaServer { fn get_name(&self) -> &'static str { "media" } - fn new_project(&mut self, _context: &mut impl ProjectHandlerContext, _injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn new_project( + &mut self, + _context: &mut impl ProjectHandlerContext, + _injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { self.clear(); - + Ok(()) } - fn load_project(&mut self, context: &mut impl LoadProjectContext, _injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + _injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { self.clear(); let files = context.read_file("files")?; self.import_files(files)?; @@ -20,16 +28,19 @@ impl ProjectHandler for MediaServer { self.import_tags(tags)?; let watched_folders = context.read_file("watched_folders")?; self.set_import_paths(watched_folders); - + Ok(()) - } - fn save_project(&self, context: &mut impl SaveProjectContext, _injector: &dyn InjectDyn) -> anyhow::Result<()> { + fn save_project( + &self, + context: &mut impl SaveProjectContext, + _injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { context.write_file("files", self.get_media()?)?; context.write_file("tags", self.get_tags()?)?; context.write_file("watched_folders", self.get_import_paths())?; - + Ok(()) } } diff --git a/crates/components/plan/src/lib.rs b/crates/components/plan/src/lib.rs index e08dcecc5..521c86956 100644 --- a/crates/components/plan/src/lib.rs +++ b/crates/components/plan/src/lib.rs @@ -10,8 +10,8 @@ use uuid::Uuid; pub mod commands; mod debug_ui_pane; mod module; -pub mod queries; mod project_handler; +pub mod queries; pub type PlanStorage = Arc>>; diff --git a/crates/components/plan/src/module.rs b/crates/components/plan/src/module.rs index c0b0df325..d3ccf5915 100644 --- a/crates/components/plan/src/module.rs +++ b/crates/components/plan/src/module.rs @@ -1,6 +1,6 @@ use crate::debug_ui_pane::PlanDebugUiPane; -use mizer_module::{module_name, Module, ModuleContext}; use crate::project_handler::PlanProjectHandler; +use mizer_module::{module_name, Module, ModuleContext}; pub struct PlansModule; diff --git a/crates/components/plan/src/project_handler.rs b/crates/components/plan/src/project_handler.rs index 1ce6a8986..1200d0605 100644 --- a/crates/components/plan/src/project_handler.rs +++ b/crates/components/plan/src/project_handler.rs @@ -1,5 +1,5 @@ -use mizer_module::*; use crate::PlanStorage; +use mizer_module::*; pub struct PlanProjectHandler; @@ -8,23 +8,41 @@ impl ProjectHandler for PlanProjectHandler { "plans" } - fn new_project(&mut self, context: &mut impl ProjectHandlerContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { - let storage = injector.try_inject::().ok_or_else(|| anyhow::anyhow!("Missing plan storage"))?; + fn new_project( + &mut self, + context: &mut impl ProjectHandlerContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { + let storage = injector + .try_inject::() + .ok_or_else(|| anyhow::anyhow!("Missing plan storage"))?; storage.set(Default::default()); Ok(()) } - fn load_project(&mut self, context: &mut impl LoadProjectContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { let plans = context.read_file("plans")?; - let storage = injector.try_inject::().ok_or_else(|| anyhow::anyhow!("Missing plan storage"))?; + let storage = injector + .try_inject::() + .ok_or_else(|| anyhow::anyhow!("Missing plan storage"))?; storage.set(plans); Ok(()) } - fn save_project(&self, context: &mut impl SaveProjectContext, injector: &dyn InjectDyn) -> anyhow::Result<()> { - let storage = injector.try_inject::().ok_or_else(|| anyhow::anyhow!("Missing plan storage"))?; + fn save_project( + &self, + context: &mut impl SaveProjectContext, + injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { + let storage = injector + .try_inject::() + .ok_or_else(|| anyhow::anyhow!("Missing plan storage"))?; let plans = storage.read(); context.write_file("plans", plans)?; diff --git a/crates/components/sequencer/src/effects/project_loading.rs b/crates/components/sequencer/src/effects/project_loading.rs index 0dfecddf6..a81073472 100644 --- a/crates/components/sequencer/src/effects/project_loading.rs +++ b/crates/components/sequencer/src/effects/project_loading.rs @@ -1,19 +1,27 @@ -use mizer_module::*; use crate::{Effect, EffectEngine}; +use mizer_module::*; impl ProjectHandler for EffectEngine { fn get_name(&self) -> &'static str { "effects" } - fn new_project(&mut self, _context: &mut impl ProjectHandlerContext, _injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn new_project( + &mut self, + _context: &mut impl ProjectHandlerContext, + _injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { self.clear(); self.load_defaults(); Ok(()) } - fn load_project(&mut self, context: &mut impl LoadProjectContext, _injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + _injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { self.clear(); let effects = context.read_file::>("effects")?; profiling::scope!("EffectEngine::load_project"); @@ -25,7 +33,11 @@ impl ProjectHandler for EffectEngine { Ok(()) } - fn save_project(&self, context: &mut impl SaveProjectContext, _injector: &dyn InjectDyn) -> anyhow::Result<()> { + fn save_project( + &self, + context: &mut impl SaveProjectContext, + _injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { profiling::scope!("EffectEngine::save_project"); tracing::debug!("save effect engine"); let mut effects = Vec::with_capacity(self.effects.len()); diff --git a/crates/components/sequencer/src/lib.rs b/crates/components/sequencer/src/lib.rs index e580398a3..4867774c3 100644 --- a/crates/components/sequencer/src/lib.rs +++ b/crates/components/sequencer/src/lib.rs @@ -11,11 +11,11 @@ mod cue_preset; pub mod effects; mod module; mod processor; +mod project_loading; mod sequence; mod sequencer; mod state; mod value; -mod project_loading; #[cfg(test)] mod tests { diff --git a/crates/components/sequencer/src/project_loading.rs b/crates/components/sequencer/src/project_loading.rs index 08b3c285f..fae3b8d5c 100644 --- a/crates/components/sequencer/src/project_loading.rs +++ b/crates/components/sequencer/src/project_loading.rs @@ -1,25 +1,37 @@ -use mizer_module::*; use crate::{Sequence, Sequencer}; +use mizer_module::*; impl ProjectHandler for Sequencer { fn get_name(&self) -> &'static str { "sequencer" } - fn new_project(&mut self, context: &mut impl ProjectHandlerContext, _injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn new_project( + &mut self, + context: &mut impl ProjectHandlerContext, + _injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { self.clear(); Ok(()) } - fn load_project(&mut self, context: &mut impl LoadProjectContext, _injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + _injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { let sequences = context.read_file::>("sequences")?; self.load_sequences(sequences); Ok(()) } - fn save_project(&self, context: &mut impl SaveProjectContext, _injector: &dyn InjectDyn) -> anyhow::Result<()> { + fn save_project( + &self, + context: &mut impl SaveProjectContext, + _injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { context.write_file("sequences", self.sequences())?; Ok(()) diff --git a/crates/components/surfaces/src/lib.rs b/crates/components/surfaces/src/lib.rs index ccb85a954..c9f68c6a6 100644 --- a/crates/components/surfaces/src/lib.rs +++ b/crates/components/surfaces/src/lib.rs @@ -6,5 +6,5 @@ pub use registry::SurfaceRegistry; pub mod commands; mod models; mod module; +mod project_loading; mod registry; -mod project_loading; \ No newline at end of file diff --git a/crates/components/surfaces/src/module.rs b/crates/components/surfaces/src/module.rs index 6ea9bd718..2833cedc7 100644 --- a/crates/components/surfaces/src/module.rs +++ b/crates/components/surfaces/src/module.rs @@ -1,8 +1,8 @@ -use mizer_message_bus::MessageBus; -use mizer_module::*; use crate::project_loading::SurfaceProjectHandler; use crate::registry::SurfaceRegistry; use crate::Surface; +use mizer_message_bus::MessageBus; +use mizer_module::*; pub struct SurfaceModule; @@ -23,7 +23,7 @@ impl Module for SurfaceModule { }; context.provide(registry); context.provide(SurfaceProjectHandler); - + context.provide_api(api); Ok(()) diff --git a/crates/components/surfaces/src/project_loading.rs b/crates/components/surfaces/src/project_loading.rs index decc21486..9a2e1a1c6 100644 --- a/crates/components/surfaces/src/project_loading.rs +++ b/crates/components/surfaces/src/project_loading.rs @@ -1,25 +1,33 @@ -use mizer_module::*; use crate::{Surface, SurfaceRegistry}; +use mizer_module::*; -pub struct SurfaceProjectHandler; +pub struct SurfaceProjectHandler; impl ProjectHandler for SurfaceProjectHandler { fn get_name(&self) -> &'static str { "surfaces" } - fn new_project(&mut self, context: &mut impl ProjectHandlerContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn new_project( + &mut self, + context: &mut impl ProjectHandlerContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { let Some(registry) = injector.try_inject::() else { context.report_issue("Unable to load surfaces"); - + return Ok(()); }; registry.clear_surfaces(); - + Ok(()) } - fn load_project(&mut self, context: &mut impl LoadProjectContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { let surfaces = context.read_file::>("surfaces")?; let Some(registry) = injector.try_inject::() else { context.report_issue("Unable to load surfaces"); @@ -32,7 +40,11 @@ impl ProjectHandler for SurfaceProjectHandler { Ok(()) } - fn save_project(&self, context: &mut impl SaveProjectContext, injector: &dyn InjectDyn) -> anyhow::Result<()> { + fn save_project( + &self, + context: &mut impl SaveProjectContext, + injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { let Some(registry) = injector.try_inject::() else { context.report_issue("Unable to load surfaces"); diff --git a/crates/components/timecode/src/lib.rs b/crates/components/timecode/src/lib.rs index debc0f9fe..f2963ab39 100644 --- a/crates/components/timecode/src/lib.rs +++ b/crates/components/timecode/src/lib.rs @@ -7,6 +7,6 @@ mod manager; mod model; mod module; mod processor; +mod project_loading; pub mod queries; mod spline; -mod project_loading; diff --git a/crates/components/timecode/src/project_loading.rs b/crates/components/timecode/src/project_loading.rs index 7602773b5..8b601875b 100644 --- a/crates/components/timecode/src/project_loading.rs +++ b/crates/components/timecode/src/project_loading.rs @@ -1,18 +1,26 @@ -use mizer_module::*; use crate::{TimecodeControl, TimecodeManager, TimecodeTrack}; +use mizer_module::*; impl ProjectHandler for TimecodeManager { fn get_name(&self) -> &'static str { "timecode" } - fn new_project(&mut self, _context: &mut impl ProjectHandlerContext, _injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn new_project( + &mut self, + _context: &mut impl ProjectHandlerContext, + _injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { self.clear(); - + Ok(()) } - fn load_project(&mut self, context: &mut impl LoadProjectContext, _injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + _injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { self.clear(); profiling::scope!("TimecodeManager::load"); let timecodes = context.read_file::>("timecodes")?; @@ -22,7 +30,11 @@ impl ProjectHandler for TimecodeManager { Ok(()) } - fn save_project(&self, context: &mut impl SaveProjectContext, _injector: &dyn InjectDyn) -> anyhow::Result<()> { + fn save_project( + &self, + context: &mut impl SaveProjectContext, + _injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { profiling::scope!("TimecodeManager::save"); context.write_file("timecodes", self.timecodes())?; context.write_file("controls", self.controls())?; diff --git a/crates/mizer/src/lib.rs b/crates/mizer/src/lib.rs index 8b40206d8..45e59b427 100644 --- a/crates/mizer/src/lib.rs +++ b/crates/mizer/src/lib.rs @@ -8,5 +8,5 @@ mod fixture_libraries_loader; mod flags; mod mizer; mod module_context; +mod project_handler; mod runtime_builder; -mod project_handler; \ No newline at end of file diff --git a/crates/mizer/src/mizer.rs b/crates/mizer/src/mizer.rs index ef7a326f8..5f0a29fc8 100644 --- a/crates/mizer/src/mizer.rs +++ b/crates/mizer/src/mizer.rs @@ -8,7 +8,7 @@ use mizer_console::ConsoleCategory; use mizer_media::{MediaDiscovery, MediaServer}; use mizer_message_bus::MessageBus; use mizer_module::{ProjectHandlerContext, Runtime}; -use mizer_project_files::{HandlerContext, history::ProjectHistory, SHOWFILE_EXTENSION}; +use mizer_project_files::{history::ProjectHistory, HandlerContext, SHOWFILE_EXTENSION}; use mizer_runtime::DefaultRuntime; use mizer_session::SessionState; use mizer_status_bus::{ProjectStatus, StatusBus}; diff --git a/crates/mizer/src/module_context.rs b/crates/mizer/src/module_context.rs index b490b1bce..21e8ae914 100644 --- a/crates/mizer/src/module_context.rs +++ b/crates/mizer/src/module_context.rs @@ -1,12 +1,12 @@ use mizer_debug_ui_impl::{DebugUiImpl, DebugUiPane}; use std::future::Future; +use crate::project_handler::ErasedProjectHandler; use mizer_module::{ApiInjector, ModuleContext, ProjectHandler, Runtime}; use mizer_processing::Processor; use mizer_runtime::DefaultRuntime; use mizer_settings::Settings; use mizer_status_bus::StatusHandle; -use crate::project_handler::ErasedProjectHandler; pub struct SetupContext { pub runtime: DefaultRuntime, diff --git a/crates/mizer/src/project_handler.rs b/crates/mizer/src/project_handler.rs index 24977c8b0..b541ac3b3 100644 --- a/crates/mizer/src/project_handler.rs +++ b/crates/mizer/src/project_handler.rs @@ -2,23 +2,47 @@ use mizer_module::*; use mizer_project_files::HandlerContext; pub(crate) trait ErasedProjectHandler { - fn new_project(&mut self, context: &mut crate::mizer::NewProjectContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()>; - fn load_project(&mut self, context: &mut HandlerContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()>; - fn save_project(&self, context: &mut HandlerContext, injector: &dyn InjectDyn) -> anyhow::Result<()>; + fn new_project( + &mut self, + context: &mut crate::mizer::NewProjectContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()>; + fn load_project( + &mut self, + context: &mut HandlerContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()>; + fn save_project( + &self, + context: &mut HandlerContext, + injector: &dyn InjectDyn, + ) -> anyhow::Result<()>; } impl ErasedProjectHandler for T { - fn new_project(&mut self, context: &mut crate::mizer::NewProjectContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn new_project( + &mut self, + context: &mut crate::mizer::NewProjectContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { let mut context = ContextWrapper::new(self, context); T::new_project(self, &mut context, injector) } - fn load_project(&mut self, context: &mut HandlerContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut HandlerContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { let mut context = ContextWrapper::new(self, context); T::load_project(self, &mut context, injector) } - fn save_project(&self, context: &mut HandlerContext, injector: &dyn InjectDyn) -> anyhow::Result<()> { + fn save_project( + &self, + context: &mut HandlerContext, + injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { let mut context = ContextWrapper::new(self, context); T::save_project(self, &mut context, injector) } @@ -46,12 +70,18 @@ impl<'a, TContext: ProjectHandlerContext> ProjectHandlerContext for ContextWrapp impl<'a, TContext: LoadProjectContext> LoadProjectContext for ContextWrapper<'a, TContext> { fn read_file(&self, filename: &str) -> anyhow::Result { - self.context.read_file(&format!("{}/{filename}", self.module)) + self.context + .read_file(&format!("{}/{filename}", self.module)) } } impl<'a, TContext: SaveProjectContext> SaveProjectContext for ContextWrapper<'a, TContext> { - fn write_file(&mut self, filename: &str, content: T) -> anyhow::Result<()> { - self.context.write_file(&format!("{}/{filename}", self.module), content) + fn write_file( + &mut self, + filename: &str, + content: T, + ) -> anyhow::Result<()> { + self.context + .write_file(&format!("{}/{filename}", self.module), content) } } diff --git a/crates/projects/src/handler_context.rs b/crates/projects/src/handler_context.rs index af55f4db4..6fd218b16 100644 --- a/crates/projects/src/handler_context.rs +++ b/crates/projects/src/handler_context.rs @@ -1,13 +1,13 @@ +use crate::project_file::{ProjectArchive, ProjectFile}; +use crate::versioning::{migrate, Migrations}; +use mizer_console::ConsoleCategory; +use mizer_module::{LoadProjectContext, ProjectHandlerContext, SaveProjectContext}; +use serde::de::DeserializeOwned; +use serde::Serialize; use std::fs::File; use std::io::Write; use std::path::Path; -use serde::de::DeserializeOwned; -use serde::Serialize; use zip::unstable::LittleEndianWriteExt; -use mizer_console::ConsoleCategory; -use mizer_module::{LoadProjectContext, ProjectHandlerContext, SaveProjectContext}; -use crate::project_file::{ProjectArchive, ProjectFile}; -use crate::versioning::{migrate, Migrations}; #[derive(Default)] pub struct HandlerContext { @@ -18,7 +18,7 @@ impl HandlerContext { pub fn new() -> Self { Self::default() } - + pub fn open(path: impl AsRef) -> anyhow::Result { let mut file = ProjectFile::open(path.as_ref())?; migrate(&mut file)?; @@ -27,9 +27,7 @@ impl HandlerContext { _ => return Err(anyhow::anyhow!("Invalid project file")), }; - Ok(Self { - archive, - }) + Ok(Self { archive }) } pub fn save(mut self, path: impl AsRef) -> anyhow::Result<()> { diff --git a/crates/projects/src/lib.rs b/crates/projects/src/lib.rs index 1cf7f5f5f..08235e248 100644 --- a/crates/projects/src/lib.rs +++ b/crates/projects/src/lib.rs @@ -7,10 +7,10 @@ use mizer_fixtures::fixture::FixtureConfiguration; use mizer_fixtures::programmer::Group; use mizer_layouts::ControlConfig; use mizer_nodes::NodeConfig; -use mizer_runtime::{Channel, PlaybackSettings}; use mizer_plan::Plan; use mizer_protocol_mqtt::MqttAddress; use mizer_protocol_osc::OscAddress; +use mizer_runtime::{Channel, PlaybackSettings}; use mizer_sequencer::{Effect, Sequence}; use mizer_surfaces::Surface; use mizer_timecode::{TimecodeControl, TimecodeTrack}; @@ -19,11 +19,11 @@ use crate::fixtures::PresetsStore; pub use crate::handler_context::HandlerContext; mod fixtures; -pub mod history; -mod versioning; mod handler_context; -mod project_file; +pub mod history; mod media; +mod project_file; +mod versioning; pub const SHOWFILE_EXTENSION: &str = "mshow"; diff --git a/crates/projects/src/project_file/archive_file.rs b/crates/projects/src/project_file/archive_file.rs index 57916a1e2..3501c1600 100644 --- a/crates/projects/src/project_file/archive_file.rs +++ b/crates/projects/src/project_file/archive_file.rs @@ -1,5 +1,5 @@ -use std::io::{Cursor, Read, Write}; use anyhow::Context; +use std::io::{Cursor, Read, Write}; use zip::{ZipArchive, ZipWriter}; #[derive(Default)] @@ -9,7 +9,7 @@ impl ProjectArchive { pub fn new() -> Self { Self::default() } - + pub fn read(&self) -> anyhow::Result { let archive = ZipArchive::new(Cursor::new(self.0.as_slice()))?; @@ -19,7 +19,7 @@ impl ProjectArchive { pub fn write(&mut self) -> anyhow::Result { let archive = if self.0.is_empty() { ZipWriter::new(Cursor::new(&mut self.0)) - }else { + } else { ZipWriter::new_append(Cursor::new(&mut self.0))? }; @@ -31,8 +31,11 @@ pub(crate) struct ProjectArchiveReader<'a>(ZipArchive>); impl<'a> ProjectArchiveReader<'a> { pub fn read_file(&mut self, file_name: &str) -> anyhow::Result { - let file = self.0.by_name(file_name).context(format!("Reading {file_name}"))?; - + let file = self + .0 + .by_name(file_name) + .context(format!("Reading {file_name}"))?; + Ok(file) } } @@ -41,8 +44,10 @@ pub(crate) struct ProjectArchiveWriter<'a>(ZipWriter>>); impl<'a> ProjectArchiveWriter<'a> { pub fn write_file(&mut self, file_name: &str) -> anyhow::Result<()> { - self.0.start_file::<_, (), _>(file_name, Default::default()).context(format!("Starting {file_name}"))?; - + self.0 + .start_file::<_, (), _>(file_name, Default::default()) + .context(format!("Starting {file_name}"))?; + Ok(()) } } diff --git a/crates/projects/src/project_file/mod.rs b/crates/projects/src/project_file/mod.rs index 8fb63e408..052c44f67 100644 --- a/crates/projects/src/project_file/mod.rs +++ b/crates/projects/src/project_file/mod.rs @@ -1,11 +1,11 @@ +pub(crate) use self::archive_file::ProjectArchive; +use crate::SHOWFILE_EXTENSION; +use indexmap::IndexMap; +use serde::{Deserialize, Serialize}; use std::fs::File; use std::io::Read; use std::path::Path; -use indexmap::IndexMap; -use serde::{Deserialize, Serialize}; use zip::unstable::{LittleEndianReadExt, LittleEndianWriteExt}; -pub(crate) use self::archive_file::ProjectArchive; -use crate::SHOWFILE_EXTENSION; mod archive_file; @@ -39,12 +39,8 @@ impl ProjectFile { let mut file_content = Vec::new(); file.read_to_end(&mut file_content)?; match file_type { - ProjectFileType::Yaml => { - Ok(Self::Yaml(file_content)) - } - ProjectFileType::Zip => { - Ok(Self::Archive(ProjectArchive(file_content))) - } + ProjectFileType::Yaml => Ok(Self::Yaml(file_content)), + ProjectFileType::Zip => Ok(Self::Archive(ProjectArchive(file_content))), } } @@ -60,7 +56,7 @@ impl ProjectFile { let mut reader = archive.read()?; let mut file = reader.read_file("VERSION")?; let version = file.read_u32_le()?; - + Ok(version) } } @@ -83,7 +79,7 @@ impl ProjectFile { Ok(()) } - + pub(crate) fn as_yaml(&mut self) -> Option<&mut Vec> { match self { Self::Yaml(content) => Some(content), @@ -96,7 +92,8 @@ impl ProjectFile { Self::Archive(content) => Some(content), _ => None, } - }} + } +} #[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] struct ProjectVersion { @@ -104,7 +101,6 @@ struct ProjectVersion { pub version: u32, } - #[derive(Default, Debug, Clone, Serialize, Deserialize, PartialEq)] struct ProjectVersionWithContent { #[serde(default)] diff --git a/crates/projects/src/versioning/migration.rs b/crates/projects/src/versioning/migration.rs index 33dfc878b..f7a1c7120 100644 --- a/crates/projects/src/versioning/migration.rs +++ b/crates/projects/src/versioning/migration.rs @@ -61,9 +61,14 @@ macro_rules! yaml_migration { fn migrate(&self, project_file: &mut ProjectFile) -> anyhow::Result<()> { let version = project_file.get_version()?; - tracing::info!("Migrating project file from {} to {}", version, <$variant as ProjectFileMigration>::VERSION); - let file_content = project_file.as_yaml() - .ok_or_else(|| anyhow::anyhow!("Trying to apply yaml migration on new project file"))?; + tracing::info!( + "Migrating project file from {} to {}", + version, + <$variant as ProjectFileMigration>::VERSION + ); + let file_content = project_file.as_yaml().ok_or_else(|| { + anyhow::anyhow!("Trying to apply yaml migration on new project file") + })?; ProjectFileMigration::migrate(self, file_content)?; project_file.write_version(<$variant as ProjectFileMigration>::VERSION)?; @@ -93,9 +98,14 @@ macro_rules! archive_migration { fn migrate(&self, project_file: &mut ProjectFile) -> anyhow::Result<()> { let version = project_file.get_version()?; - tracing::info!("Migrating project file from {} to {}", version, <$variant as ProjectArchiveMigration>::VERSION); - let file_content = project_file.as_archive() - .ok_or_else(|| anyhow::anyhow!("Trying to apply archive migration on old project file"))?; + tracing::info!( + "Migrating project file from {} to {}", + version, + <$variant as ProjectArchiveMigration>::VERSION + ); + let file_content = project_file.as_archive().ok_or_else(|| { + anyhow::anyhow!("Trying to apply archive migration on old project file") + })?; ProjectArchiveMigration::migrate(self, file_content)?; project_file.write_version(<$variant as ProjectArchiveMigration>::VERSION)?; diff --git a/crates/projects/src/versioning/migrations/mod.rs b/crates/projects/src/versioning/migrations/mod.rs index e6de6dcdf..b45f9de16 100644 --- a/crates/projects/src/versioning/migrations/mod.rs +++ b/crates/projects/src/versioning/migrations/mod.rs @@ -1,17 +1,17 @@ +use crate::project_file::ProjectArchive; pub use adapt_fader_config::*; +pub use archive_file::*; pub use migrate_position_presets::*; pub use rename_ports::*; pub use rework_layout_controls_to_not_use_nodes::*; pub use rework_midi_config::*; -pub use archive_file::*; -use crate::project_file::ProjectArchive; mod adapt_fader_config; +mod archive_file; mod migrate_position_presets; mod rename_ports; mod rework_layout_controls_to_not_use_nodes; mod rework_midi_config; -mod archive_file; pub trait ProjectFileMigration: Clone + Copy { const VERSION: u32; diff --git a/crates/projects/src/versioning/mod.rs b/crates/projects/src/versioning/mod.rs index 14dba71c0..965125807 100644 --- a/crates/projects/src/versioning/mod.rs +++ b/crates/projects/src/versioning/mod.rs @@ -1,5 +1,5 @@ -use enum_iterator::all; use crate::project_file::ProjectFile; +use enum_iterator::all; use self::migrations::*; diff --git a/crates/projects/tests/examples.rs b/crates/projects/tests/examples.rs index bc28a64e0..e0c30ed73 100644 --- a/crates/projects/tests/examples.rs +++ b/crates/projects/tests/examples.rs @@ -24,6 +24,6 @@ fn test_load_project(project: &str) { env!("CARGO_MANIFEST_DIR"), project ); - + let _ = HandlerContext::open(path).unwrap(); } diff --git a/crates/runtime/injector/src/lib.rs b/crates/runtime/injector/src/lib.rs index 2ecccbd1a..32336ff5c 100644 --- a/crates/runtime/injector/src/lib.rs +++ b/crates/runtime/injector/src/lib.rs @@ -15,7 +15,10 @@ pub trait InjectDyn { pub trait InjectDynMut: InjectDyn { fn try_inject_dyn_mut(&mut self, type_id: TypeId) -> Option<&mut Box>; - fn try_inject_dyn_mut_with_slice(&mut self, type_id: TypeId) -> Option<(&mut Box, InjectorSlice)>; + fn try_inject_dyn_mut_with_slice( + &mut self, + type_id: TypeId, + ) -> Option<(&mut Box, InjectorSlice)>; } pub trait Inject { @@ -31,25 +34,29 @@ pub trait InjectMut: Inject { fn try_inject_mut(&mut self) -> Option<&mut T>; fn inject_mut(&mut self) -> &mut T { - self.try_inject_mut().unwrap_or_else(|| panic!("Unable to inject {}", type_name::())) + self.try_inject_mut() + .unwrap_or_else(|| panic!("Unable to inject {}", type_name::())) } fn try_inject_mut_with_slice(&mut self) -> Option<(&mut T, InjectorSlice)>; fn inject_mut_with_slice(&mut self) -> (&mut T, InjectorSlice) { - self.try_inject_mut_with_slice().unwrap_or_else(|| panic!("Unable to inject {}", type_name::())) + self.try_inject_mut_with_slice() + .unwrap_or_else(|| panic!("Unable to inject {}", type_name::())) } } impl Inject for I { fn try_inject(&self) -> Option<&T> { - self.try_inject_dyn(TypeId::of::()).and_then(|service| service.downcast_ref()) + self.try_inject_dyn(TypeId::of::()) + .and_then(|service| service.downcast_ref()) } } impl InjectMut for I { fn try_inject_mut(&mut self) -> Option<&mut T> { - self.try_inject_dyn_mut(TypeId::of::()).and_then(|service| service.downcast_mut()) + self.try_inject_dyn_mut(TypeId::of::()) + .and_then(|service| service.downcast_mut()) } fn try_inject_mut_with_slice(&mut self) -> Option<(&mut T, InjectorSlice)> { @@ -112,15 +119,21 @@ impl InjectDynMut for Injector { self.services.get_mut(&type_id) } - fn try_inject_dyn_mut_with_slice(&mut self, type_id: TypeId) -> Option<(&mut Box, InjectorSlice)> { + fn try_inject_dyn_mut_with_slice( + &mut self, + type_id: TypeId, + ) -> Option<(&mut Box, InjectorSlice)> { let injector1: &mut Injector = unsafe { std::mem::transmute_copy(&self) }; let service = injector1.try_inject_dyn_mut(type_id)?; - Some((service, InjectorSlice { - injector: self, - blocked: type_id, - })) + Some(( + service, + InjectorSlice { + injector: self, + blocked: type_id, + }, + )) } } @@ -146,7 +159,10 @@ impl<'a> InjectDynMut for InjectorSlice<'a> { self.injector.try_inject_dyn_mut(type_id) } - fn try_inject_dyn_mut_with_slice(&mut self, type_id: TypeId) -> Option<(&mut Box, InjectorSlice)> { + fn try_inject_dyn_mut_with_slice( + &mut self, + type_id: TypeId, + ) -> Option<(&mut Box, InjectorSlice)> { if type_id == self.blocked { return None; } diff --git a/crates/runtime/layouts/src/module.rs b/crates/runtime/layouts/src/module.rs index 1191f98f3..f66cc8850 100644 --- a/crates/runtime/layouts/src/module.rs +++ b/crates/runtime/layouts/src/module.rs @@ -1,6 +1,6 @@ use crate::debug_ui_pane::LayoutsDebugUiPane; -use mizer_module::{module_name, Module, ModuleContext}; use crate::project_handler::LayoutProjectHandler; +use mizer_module::{module_name, Module, ModuleContext}; pub struct LayoutsModule; diff --git a/crates/runtime/layouts/src/project_handler.rs b/crates/runtime/layouts/src/project_handler.rs index a9e861ae4..93abe4cef 100644 --- a/crates/runtime/layouts/src/project_handler.rs +++ b/crates/runtime/layouts/src/project_handler.rs @@ -1,5 +1,5 @@ -use mizer_module::*; use crate::{Layout, LayoutStorage}; +use mizer_module::*; pub struct LayoutProjectHandler; @@ -8,8 +8,14 @@ impl ProjectHandler for LayoutProjectHandler { "layouts" } - fn new_project(&mut self, context: &mut impl ProjectHandlerContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { - let storage = injector.try_inject_mut::().ok_or_else(|| anyhow::anyhow!("Missing layout storage"))?; + fn new_project( + &mut self, + context: &mut impl ProjectHandlerContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { + let storage = injector + .try_inject_mut::() + .ok_or_else(|| anyhow::anyhow!("Missing layout storage"))?; storage.set(vec![Layout { id: "Default".into(), controls: Vec::new(), @@ -18,16 +24,28 @@ impl ProjectHandler for LayoutProjectHandler { Ok(()) } - fn load_project(&mut self, context: &mut impl LoadProjectContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { let plans = context.read_file("layouts")?; - let storage = injector.try_inject_mut::().ok_or_else(|| anyhow::anyhow!("Missing layout storage"))?; + let storage = injector + .try_inject_mut::() + .ok_or_else(|| anyhow::anyhow!("Missing layout storage"))?; storage.set(plans); Ok(()) } - fn save_project(&self, context: &mut impl SaveProjectContext, injector: &dyn InjectDyn) -> anyhow::Result<()> { - let storage = injector.try_inject::().ok_or_else(|| anyhow::anyhow!("Missing layout storage"))?; + fn save_project( + &self, + context: &mut impl SaveProjectContext, + injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { + let storage = injector + .try_inject::() + .ok_or_else(|| anyhow::anyhow!("Missing layout storage"))?; let plans = storage.read(); context.write_file("layouts", plans)?; diff --git a/crates/runtime/module/src/lib.rs b/crates/runtime/module/src/lib.rs index b34e5dd6a..c6ae95bac 100644 --- a/crates/runtime/module/src/lib.rs +++ b/crates/runtime/module/src/lib.rs @@ -1,8 +1,8 @@ +use serde::de::DeserializeOwned; +use serde::Serialize; use std::fmt::Display; use std::future::Future; use std::time::Duration; -use serde::de::DeserializeOwned; -use serde::Serialize; pub use mizer_processing::*; pub use mizer_settings::*; @@ -15,9 +15,21 @@ mod api_injector; pub trait ProjectHandler { fn get_name(&self) -> &'static str; - fn new_project(&mut self, context: &mut impl ProjectHandlerContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()>; - fn load_project(&mut self, context: &mut impl LoadProjectContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()>; - fn save_project(&self, context: &mut impl SaveProjectContext, injector: &dyn InjectDyn) -> anyhow::Result<()>; + fn new_project( + &mut self, + context: &mut impl ProjectHandlerContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()>; + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()>; + fn save_project( + &self, + context: &mut impl SaveProjectContext, + injector: &dyn InjectDyn, + ) -> anyhow::Result<()>; } pub trait ProjectHandlerContext { diff --git a/crates/runtime/pipeline/node/src/lib.rs b/crates/runtime/pipeline/node/src/lib.rs index fb09f5669..97eac5805 100644 --- a/crates/runtime/pipeline/node/src/lib.rs +++ b/crates/runtime/pipeline/node/src/lib.rs @@ -4,7 +4,7 @@ use std::fmt::Debug; use downcast::*; pub use mizer_debug_ui::DebugUiDrawHandle; -pub use mizer_injector::{Injector, InjectDynMut, InjectMut, Inject, InjectDyn}; +pub use mizer_injector::{Inject, InjectDyn, InjectDynMut, InjectMut, Injector}; pub use mizer_ports::{port_types, Color, PortId, PortType}; pub use self::context::*; diff --git a/crates/runtime/pipeline/nodes/connections/protocols/midi/src/lib.rs b/crates/runtime/pipeline/nodes/connections/protocols/midi/src/lib.rs index c17a357e0..5b0404f00 100644 --- a/crates/runtime/pipeline/nodes/connections/protocols/midi/src/lib.rs +++ b/crates/runtime/pipeline/nodes/connections/protocols/midi/src/lib.rs @@ -4,7 +4,7 @@ use enum_iterator::Sequence; use num_enum::{IntoPrimitive, TryFromPrimitive}; use serde::{Deserialize, Serialize}; -use mizer_node::{InjectDyn, Inject, SelectVariant, Injector}; +use mizer_node::{Inject, InjectDyn, Injector, SelectVariant}; use mizer_protocol_midi::{ControlStep, MidiConnectionManager}; pub use self::input::{MidiInputConfig, MidiInputNode}; diff --git a/crates/runtime/pipeline/nodes/connections/protocols/mqtt/src/lib.rs b/crates/runtime/pipeline/nodes/connections/protocols/mqtt/src/lib.rs index e85038514..708b4001a 100644 --- a/crates/runtime/pipeline/nodes/connections/protocols/mqtt/src/lib.rs +++ b/crates/runtime/pipeline/nodes/connections/protocols/mqtt/src/lib.rs @@ -1,4 +1,4 @@ -use mizer_node::{InjectDyn, Inject, SelectVariant}; +use mizer_node::{Inject, InjectDyn, SelectVariant}; use mizer_protocol_mqtt::MqttConnectionManager; pub use self::input::*; diff --git a/crates/runtime/pipeline/nodes/connections/protocols/osc/src/lib.rs b/crates/runtime/pipeline/nodes/connections/protocols/osc/src/lib.rs index ae4b665ec..487a434cc 100644 --- a/crates/runtime/pipeline/nodes/connections/protocols/osc/src/lib.rs +++ b/crates/runtime/pipeline/nodes/connections/protocols/osc/src/lib.rs @@ -1,6 +1,6 @@ pub use argument_type::OscArgumentType; pub use input::*; -use mizer_node::{InjectDyn, Inject, SelectVariant}; +use mizer_node::{Inject, InjectDyn, SelectVariant}; use mizer_protocol_osc::OscConnectionManager; pub use output::*; diff --git a/crates/runtime/pipeline/nodes/pixels/src/texture_to_pixels.rs b/crates/runtime/pipeline/nodes/pixels/src/texture_to_pixels.rs index 9bd39167a..410915723 100644 --- a/crates/runtime/pipeline/nodes/pixels/src/texture_to_pixels.rs +++ b/crates/runtime/pipeline/nodes/pixels/src/texture_to_pixels.rs @@ -2,7 +2,7 @@ use std::sync::Arc; use image::{DynamicImage, GenericImageView, ImageBuffer, Rgba}; -use mizer_node::{NodeContext, PortId, Inject}; +use mizer_node::{Inject, NodeContext, PortId}; use mizer_wgpu::{BufferHandle, TextureHandle, TextureRegistry, WgpuContext, WgpuPipeline}; pub struct TextureToPixelsConverter { diff --git a/crates/runtime/pipeline/nodes/plan/src/texture_to_pixels.rs b/crates/runtime/pipeline/nodes/plan/src/texture_to_pixels.rs index c81b05db5..9a63b4c3c 100644 --- a/crates/runtime/pipeline/nodes/plan/src/texture_to_pixels.rs +++ b/crates/runtime/pipeline/nodes/plan/src/texture_to_pixels.rs @@ -1,6 +1,6 @@ use std::sync::Arc; -use mizer_node::{NodeContext, PortId, Inject}; +use mizer_node::{Inject, NodeContext, PortId}; use mizer_wgpu::{BufferHandle, TextureHandle, TextureRegistry, WgpuContext, WgpuPipeline}; pub struct TextureToPixelsConverter { diff --git a/crates/runtime/pipeline/nodes/src/config.rs b/crates/runtime/pipeline/nodes/src/config.rs index a75d4cbf7..56a8de427 100644 --- a/crates/runtime/pipeline/nodes/src/config.rs +++ b/crates/runtime/pipeline/nodes/src/config.rs @@ -1,5 +1,5 @@ -use serde::{Deserialize, Serialize}; use mizer_node::{NodeDesigner, NodePath}; +use serde::{Deserialize, Serialize}; #[derive(Debug, Clone, Serialize, Deserialize, PartialEq)] pub struct NodeConfig { diff --git a/crates/runtime/pipeline/nodes/src/lib.rs b/crates/runtime/pipeline/nodes/src/lib.rs index 892d5c5e0..4e2fa21ee 100644 --- a/crates/runtime/pipeline/nodes/src/lib.rs +++ b/crates/runtime/pipeline/nodes/src/lib.rs @@ -35,8 +35,8 @@ pub use mizer_midi_nodes::{ pub use mizer_mqtt_nodes::{MqttInputNode, MqttOutputNode}; pub use mizer_ndi_nodes::{NdiInputNode, NdiOutputNode}; use mizer_node::{ - ConfigurableNode, DebugUiDrawHandle, NodeDetails, NodeSetting, NodeTemplate, - NodeType, PipelineNode, PortId, PortMetadata, InjectDyn, + ConfigurableNode, DebugUiDrawHandle, InjectDyn, NodeDetails, NodeSetting, NodeTemplate, + NodeType, PipelineNode, PortId, PortMetadata, }; pub use mizer_opc_nodes::OpcOutputNode; pub use mizer_osc_nodes::{OscArgumentType, OscInputNode, OscOutputNode}; @@ -69,14 +69,14 @@ pub use mizer_webcam_nodes::WebcamNode; use crate::test_sink::TestSink; -pub use self::container_node::ContainerNode; pub use self::config::NodeConfig; +pub use self::container_node::ContainerNode; +mod config; mod container_node; mod downcast; #[doc(hidden)] pub mod test_sink; -mod config; macro_rules! node_impl { ($($node_type:ident($node:ty),)*) => { diff --git a/crates/runtime/pipeline/nodes/timecode/src/control.rs b/crates/runtime/pipeline/nodes/timecode/src/control.rs index 31a9b2604..9536c5940 100644 --- a/crates/runtime/pipeline/nodes/timecode/src/control.rs +++ b/crates/runtime/pipeline/nodes/timecode/src/control.rs @@ -47,14 +47,15 @@ impl PipelineNode for TimecodeControlNode { } fn display_name(&self, injector: &dyn InjectDyn) -> String { - if let Some(timecode) = injector - .try_inject::() - .and_then(|timecode_manager| { - timecode_manager - .timecodes() - .into_iter() - .find(|timecode| timecode.id == self.timecode_id) - }) + if let Some(timecode) = + injector + .try_inject::() + .and_then(|timecode_manager| { + timecode_manager + .timecodes() + .into_iter() + .find(|timecode| timecode.id == self.timecode_id) + }) { format!("Timecode Control ({})", timecode.name) } else { diff --git a/crates/runtime/pipeline/nodes/timecode/src/output.rs b/crates/runtime/pipeline/nodes/timecode/src/output.rs index 56d16217a..2b6a6f372 100644 --- a/crates/runtime/pipeline/nodes/timecode/src/output.rs +++ b/crates/runtime/pipeline/nodes/timecode/src/output.rs @@ -44,14 +44,15 @@ impl PipelineNode for TimecodeOutputNode { } fn display_name(&self, injector: &dyn InjectDyn) -> String { - if let Some(control) = injector - .try_inject::() - .and_then(|timecode_manager| { - timecode_manager - .controls() - .into_iter() - .find(|control| control.id == self.control_id) - }) + if let Some(control) = + injector + .try_inject::() + .and_then(|timecode_manager| { + timecode_manager + .controls() + .into_iter() + .find(|control| control.id == self.control_id) + }) { format!("Timecode Output ({})", control.name) } else { diff --git a/crates/runtime/pipeline/nodes/timecode/src/recorder.rs b/crates/runtime/pipeline/nodes/timecode/src/recorder.rs index 14bb70bc8..86a9cf4af 100644 --- a/crates/runtime/pipeline/nodes/timecode/src/recorder.rs +++ b/crates/runtime/pipeline/nodes/timecode/src/recorder.rs @@ -44,14 +44,15 @@ impl PipelineNode for TimecodeRecorderNode { } fn display_name(&self, injector: &dyn InjectDyn) -> String { - if let Some(control) = injector - .try_inject::() - .and_then(|timecode_manager| { - timecode_manager - .controls() - .into_iter() - .find(|control| control.id == self.control_id) - }) + if let Some(control) = + injector + .try_inject::() + .and_then(|timecode_manager| { + timecode_manager + .controls() + .into_iter() + .find(|control| control.id == self.control_id) + }) { format!("Timecode Recorder ({})", control.name) } else { diff --git a/crates/runtime/pipeline/src/context.rs b/crates/runtime/pipeline/src/context.rs index a2f85f5d9..101f36e62 100644 --- a/crates/runtime/pipeline/src/context.rs +++ b/crates/runtime/pipeline/src/context.rs @@ -96,7 +96,10 @@ impl NodePreviewState { impl<'a> InjectDyn for PipelineContext<'a> { fn try_inject_dyn(&self, type_id: TypeId) -> Option<&Box> { - self.processing_context.borrow().injector().try_inject_dyn(type_id) + self.processing_context + .borrow() + .injector() + .try_inject_dyn(type_id) } } diff --git a/crates/runtime/processing/src/lib.rs b/crates/runtime/processing/src/lib.rs index f9ca7302f..3d3dd58e8 100644 --- a/crates/runtime/processing/src/lib.rs +++ b/crates/runtime/processing/src/lib.rs @@ -2,7 +2,7 @@ use std::fmt::Debug; pub use mizer_clock::ClockFrame; pub use mizer_debug_ui::{DebugUi, DebugUiDrawHandle, DebugUiPane, NodeStateAccess}; -pub use mizer_injector::{Inject, InjectMut, InjectDyn, InjectDynMut, Injector}; +pub use mizer_injector::{Inject, InjectDyn, InjectDynMut, InjectMut, Injector}; #[derive(Default, Debug, Clone, Copy)] pub struct ProcessorPriorities { diff --git a/crates/runtime/src/lib.rs b/crates/runtime/src/lib.rs index 6a78923a6..110fae66b 100644 --- a/crates/runtime/src/lib.rs +++ b/crates/runtime/src/lib.rs @@ -5,8 +5,8 @@ pub use node_metadata::NodeMetadataRef; pub use self::api::*; pub use self::coordinator::CoordinatorRuntime; pub use self::pipeline::*; -pub use self::views::LayoutsView; pub use self::project_handler::{Channel, PlaybackSettings}; +pub use self::views::LayoutsView; pub type DefaultRuntime = CoordinatorRuntime; @@ -18,6 +18,6 @@ mod debug_ui_pane; mod module; mod node_metadata; mod pipeline; -pub mod queries; mod project_handler; +pub mod queries; mod views; diff --git a/crates/runtime/src/module.rs b/crates/runtime/src/module.rs index 976a08fcc..393d0681c 100644 --- a/crates/runtime/src/module.rs +++ b/crates/runtime/src/module.rs @@ -1,8 +1,8 @@ use crate::debug_ui_pane::NodesDebugUiPane; use crate::pipeline::RuntimeProcessor; +use crate::project_handler::PipelineProjectHandler; use crate::Pipeline; use mizer_module::*; -use crate::project_handler::PipelineProjectHandler; pub struct RuntimeModule; diff --git a/crates/runtime/src/pipeline.rs b/crates/runtime/src/pipeline.rs index 2cea61e98..de418b5e1 100644 --- a/crates/runtime/src/pipeline.rs +++ b/crates/runtime/src/pipeline.rs @@ -3,13 +3,15 @@ use crate::context::CoordinatorRuntimeContext; use anyhow::Context; use indexmap::IndexMap; use mizer_clock::{BoxedClock, ClockFrame}; -use mizer_debug_ui_impl::{NodeStateAccess}; -use mizer_node::{InjectDyn, NodeDesigner, NodeLink, NodeMetadata, NodePath, NodeSetting, NodeType, PipelineNode, PortDirection, PortMetadata, ProcessingNode, +use mizer_debug_ui_impl::NodeStateAccess; +use mizer_node::{ + InjectDyn, NodeDesigner, NodeLink, NodeMetadata, NodePath, NodeSetting, NodeType, PipelineNode, + PortDirection, PortMetadata, ProcessingNode, }; use mizer_nodes::{ContainerNode, Node, NodeDowncast, NodeExt}; use mizer_pipeline::{NodePortReader, NodePreviewRef, PipelineWorker, ProcessingNodeExt}; use mizer_ports::PortId; -use mizer_processing::{Processor, Injector, ProcessorPriorities}; +use mizer_processing::{Injector, Processor, ProcessorPriorities}; use pinboard::NonEmptyPinboard; use std::cmp::Ordering; use std::collections::HashMap; diff --git a/crates/runtime/src/project_handler.rs b/crates/runtime/src/project_handler.rs index 51b0999f3..969355e53 100644 --- a/crates/runtime/src/project_handler.rs +++ b/crates/runtime/src/project_handler.rs @@ -1,11 +1,11 @@ -use serde::{Deserialize, Serialize}; +use crate::Pipeline; use lazy_static::lazy_static; use mizer_module::*; use mizer_node::{NodeLink, NodePath, NodeType}; use mizer_nodes::{NodeConfig, NodeDowncast}; use mizer_ports::PortId; use regex::{Regex, RegexBuilder}; -use crate::{Pipeline}; +use serde::{Deserialize, Serialize}; lazy_static! { static ref CHANNEL_REGEX: Regex = RegexBuilder::new( @@ -23,16 +23,40 @@ impl ProjectHandler for PipelineProjectHandler { "pipeline" } - fn new_project(&mut self, _context: &mut impl ProjectHandlerContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn new_project( + &mut self, + _context: &mut impl ProjectHandlerContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { let (pipeline, injector) = injector.inject_mut_with_slice::(); pipeline.clear(); - pipeline.add_node(&injector, NodeType::Programmer, Default::default(), None, None).unwrap(); - pipeline.add_node(&injector, NodeType::Transport, Default::default(), None, None).unwrap(); + pipeline + .add_node( + &injector, + NodeType::Programmer, + Default::default(), + None, + None, + ) + .unwrap(); + pipeline + .add_node( + &injector, + NodeType::Transport, + Default::default(), + None, + None, + ) + .unwrap(); Ok(()) } - fn load_project(&mut self, context: &mut impl LoadProjectContext, injector: &mut dyn InjectDynMut) -> anyhow::Result<()> { + fn load_project( + &mut self, + context: &mut impl LoadProjectContext, + injector: &mut dyn InjectDynMut, + ) -> anyhow::Result<()> { profiling::scope!("CoordinatorRuntime::load_project"); let (pipeline, injector) = injector.inject_mut_with_slice::(); pipeline.clear(); @@ -44,8 +68,7 @@ impl ProjectHandler for PipelineProjectHandler { for link in channels { let source_port = pipeline.get_output_port_metadata(&link.from_path, &link.from_channel); - let target_port = - pipeline.get_input_port_metadata(&link.to_path, &link.to_channel); + let target_port = pipeline.get_input_port_metadata(&link.to_path, &link.to_channel); anyhow::ensure!( source_port.port_type == target_port.port_type, "Missmatched port types\nsource: {:?}\ntarget: {:?}\nlink: {:?}", @@ -67,7 +90,11 @@ impl ProjectHandler for PipelineProjectHandler { Ok(()) } - fn save_project(&self, context: &mut impl SaveProjectContext, injector: &dyn InjectDyn) -> anyhow::Result<()> { + fn save_project( + &self, + context: &mut impl SaveProjectContext, + injector: &dyn InjectDyn, + ) -> anyhow::Result<()> { // let playback_settings = PlaybackSettings { // fps: self. // }