Skip to content

Commit

Permalink
style(fmt): apply cargo fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
maxjoehnk committed Dec 28, 2024
1 parent cf251e0 commit 507521a
Show file tree
Hide file tree
Showing 52 changed files with 455 additions and 211 deletions.
2 changes: 1 addition & 1 deletion crates/components/connections/protocols/dmx/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
42 changes: 27 additions & 15 deletions crates/components/connections/protocols/dmx/src/project_handler.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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::<DmxConnectionManager>() else {
anyhow::bail!("DMX connection manager not found");
};
Expand All @@ -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::<DmxConnectionManager>() else {
anyhow::bail!("DMX connection manager not found");
Expand All @@ -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::<DmxConnectionManager>() else {
anyhow::bail!("DMX connection manager not found");
Expand Down Expand Up @@ -108,4 +121,3 @@ fn get_input_config(connection: &DmxInputConnection) -> DmxConfig {
},
}
}

Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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::<MqttConnectionManager>() else {
tracing::warn!("MQTT connection manager not found");
return Ok(());
Expand All @@ -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::<MqttConnectionManager>() else {
tracing::warn!("MQTT connection manager not found");
Expand All @@ -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::<MqttConnectionManager>() else {
tracing::warn!("MQTT connection manager not found");
Expand Down
22 changes: 17 additions & 5 deletions crates/components/connections/protocols/osc/src/project_handler.rs
Original file line number Diff line number Diff line change
@@ -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";

Expand All @@ -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::<OscConnectionManager>() else {
tracing::warn!("OSC connection manager not found");
return Ok(());
Expand All @@ -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::<OscConnectionManager>() else {
tracing::warn!("OSC connection manager not found");
Expand All @@ -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::<OscConnectionManager>() else {
tracing::warn!("OSC connection manager not found");
Expand Down
2 changes: 1 addition & 1 deletion crates/components/fixtures/src/config.rs
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
23 changes: 17 additions & 6 deletions crates/components/fixtures/src/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand All @@ -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 {
Expand Down Expand Up @@ -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::<Vec<FixtureConfig>>("patch")?;
Expand All @@ -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
));
}
}
Expand All @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion crates/components/media/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
27 changes: 19 additions & 8 deletions crates/components/media/src/project_loading.rs
Original file line number Diff line number Diff line change
@@ -1,35 +1,46 @@
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)?;
let tags = context.read_file("tags")?;
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(())
}
}
2 changes: 1 addition & 1 deletion crates/components/plan/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<NonEmptyPinboard<Vec<Plan>>>;

Expand Down
2 changes: 1 addition & 1 deletion crates/components/plan/src/module.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
32 changes: 25 additions & 7 deletions crates/components/plan/src/project_handler.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use mizer_module::*;
use crate::PlanStorage;
use mizer_module::*;

pub struct PlanProjectHandler;

Expand All @@ -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::<PlanStorage>().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::<PlanStorage>()
.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::<PlanStorage>().ok_or_else(|| anyhow::anyhow!("Missing plan storage"))?;
let storage = injector
.try_inject::<PlanStorage>()
.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::<PlanStorage>().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::<PlanStorage>()
.ok_or_else(|| anyhow::anyhow!("Missing plan storage"))?;
let plans = storage.read();
context.write_file("plans", plans)?;

Expand Down
Loading

0 comments on commit 507521a

Please sign in to comment.