diff --git a/main/src/application/session.rs b/main/src/application/session.rs index 6622166a9..2fc6dec53 100644 --- a/main/src/application/session.rs +++ b/main/src/application/session.rs @@ -192,6 +192,7 @@ impl Session { party_is_over_subject: Default::default(), ui: WrapDebug(Box::new(ui)), parameters: ZEROED_PLUGIN_PARAMETERS, + // TODO-high This should be probably divided per compartment! parameter_settings: vec![Default::default(); PLUGIN_PARAMETER_COUNT as usize], controller_preset_manager: Box::new(controller_manager), main_preset_manager: Box::new(main_preset_manager), diff --git a/main/src/domain/conditional_activation.rs b/main/src/domain/conditional_activation.rs index a418642c6..4a137be9d 100644 --- a/main/src/domain/conditional_activation.rs +++ b/main/src/domain/conditional_activation.rs @@ -1,5 +1,7 @@ use crate::core::eel; -use crate::domain::{ParameterArray, PLUGIN_PARAMETER_COUNT}; +use crate::domain::{ + ParameterArray, ParameterSlice, COMPARTMENT_PARAMETER_COUNT, PLUGIN_PARAMETER_COUNT, +}; use std::collections::HashSet; #[derive(Debug)] @@ -22,7 +24,7 @@ impl ActivationCondition { /// Returns if this activation condition is fulfilled in presence of the given set of /// parameters. - pub fn is_fulfilled(&self, params: &ParameterArray) -> bool { + pub fn is_fulfilled(&self, params: &ParameterSlice) -> bool { use ActivationCondition::*; match self { Always => true, @@ -51,7 +53,7 @@ impl ActivationCondition { /// TODO-low This is not visible because it's &self. pub fn is_fulfilled_single( &self, - params: &ParameterArray, + params: &ParameterSlice, // Changed index index: u32, // Previous value at changed index @@ -92,7 +94,7 @@ impl ActivationCondition { fn modifier_conditions_are_fulfilled( conditions: &[ModifierCondition], - params: &ParameterArray, + params: &ParameterSlice, ) -> bool { conditions .iter() @@ -102,7 +104,7 @@ fn modifier_conditions_are_fulfilled( fn program_condition_is_fulfilled( param_index: u32, program_index: u32, - params: &ParameterArray, + params: &ParameterSlice, ) -> bool { let param_value = params[param_index as usize]; let current_program_index = (param_value * 99.0).round() as u32; @@ -130,7 +132,7 @@ impl ModifierCondition { /// Returns if this activation condition is fulfilled in presence of the given set of /// parameters. - pub fn is_fulfilled(&self, params: &ParameterArray) -> bool { + pub fn is_fulfilled(&self, params: &ParameterSlice) -> bool { let param_value = match params.get(self.param_index as usize) { // Parameter doesn't exist. Shouldn't happen but handle gracefully. None => return false, @@ -146,7 +148,7 @@ pub struct EelCondition { // Declared above VM in order to be dropped before VM is dropped. program: eel::Program, vm: eel::Vm, - params: [Option; PLUGIN_PARAMETER_COUNT as usize], + params: [Option; COMPARTMENT_PARAMETER_COUNT as usize], y: eel::Variable, } @@ -160,7 +162,7 @@ impl EelCondition { let program = vm.compile(eel_script)?; let y = vm.register_variable("y"); let params = { - let mut array = [None; PLUGIN_PARAMETER_COUNT as usize]; + let mut array = [None; COMPARTMENT_PARAMETER_COUNT as usize]; for i in extract_used_param_indexes(eel_script).into_iter() { let variable_name = format!("p{}", i + 1); let variable = vm.register_variable(&variable_name); @@ -184,7 +186,7 @@ impl EelCondition { }) } - pub fn notify_params_changed(&self, params: &ParameterArray) { + pub fn notify_params_changed(&self, params: &ParameterSlice) { for (i, p) in self.params.iter().enumerate() { if let Some(v) = p { unsafe { @@ -221,7 +223,7 @@ fn extract_used_param_indexes(eel_script: &str) -> HashSet { .captures_iter(eel_script) .map(|m| m[1].parse()) .flatten() - .filter(|i| *i >= 1 && *i <= PLUGIN_PARAMETER_COUNT) + .filter(|i| *i >= 1 && *i <= COMPARTMENT_PARAMETER_COUNT) .map(|i: u32| i - 1) .collect() } diff --git a/main/src/domain/main_processor.rs b/main/src/domain/main_processor.rs index 2a5a6e841..3e2424e96 100644 --- a/main/src/domain/main_processor.rs +++ b/main/src/domain/main_processor.rs @@ -25,9 +25,10 @@ const FEEDBACK_TASK_BULK_SIZE: usize = 64; const CONTROL_TASK_BULK_SIZE: usize = 32; const PARAMETER_TASK_BULK_SIZE: usize = 32; -// TODO-low Making this a usize might save quite some code pub const PLUGIN_PARAMETER_COUNT: u32 = 100; +pub const COMPARTMENT_PARAMETER_COUNT: u32 = 100; pub type ParameterArray = [f32; PLUGIN_PARAMETER_COUNT as usize]; +pub type ParameterSlice = [f32]; pub const ZEROED_PLUGIN_PARAMETERS: ParameterArray = [0.0f32; PLUGIN_PARAMETER_COUNT as usize]; #[derive(Debug)] diff --git a/main/src/domain/mapping.rs b/main/src/domain/mapping.rs index 23fddc00f..5dba3ff2d 100644 --- a/main/src/domain/mapping.rs +++ b/main/src/domain/mapping.rs @@ -1,8 +1,8 @@ use crate::domain::{ ActivationChange, ActivationCondition, ControlOptions, ExtendedProcessorContext, - MappingActivationEffect, Mode, ParameterArray, PlayPosFeedbackResolution, RealearnTarget, - ReaperTarget, TargetCharacter, UnresolvedReaperTarget, VirtualControlElement, VirtualSource, - VirtualSourceValue, VirtualTarget, + MappingActivationEffect, Mode, ParameterArray, ParameterSlice, PlayPosFeedbackResolution, + RealearnTarget, ReaperTarget, TargetCharacter, UnresolvedReaperTarget, VirtualControlElement, + VirtualSource, VirtualSourceValue, VirtualTarget, }; use derive_more::Display; use enum_iterator::IntoEnumIterator; @@ -164,7 +164,7 @@ impl MainMapping { /// Returns `Some` if this affects the mapping's activation state in any way. pub fn check_activation_effect( &self, - params: &ParameterArray, + params: &ParameterSlice, index: u32, previous_value: f32, ) -> Option { @@ -213,7 +213,7 @@ impl MainMapping { Some(update) } - pub fn refresh_all(&mut self, context: ExtendedProcessorContext, params: &ParameterArray) { + pub fn refresh_all(&mut self, context: ExtendedProcessorContext, params: &ParameterSlice) { self.refresh_target(context); self.update_activation(params); } @@ -266,7 +266,7 @@ impl MainMapping { (target_changed, Some(update)) } - pub fn update_activation(&mut self, params: &ParameterArray) -> Option { + pub fn update_activation(&mut self, params: &ParameterSlice) -> Option { let was_active_before = self.is_active(); self.is_active_1 = self.activation_condition_1.is_fulfilled(params); self.is_active_2 = self.activation_condition_2.is_fulfilled(params); diff --git a/main/src/domain/unresolved_reaper_target.rs b/main/src/domain/unresolved_reaper_target.rs index 893f01b23..556c147a1 100644 --- a/main/src/domain/unresolved_reaper_target.rs +++ b/main/src/domain/unresolved_reaper_target.rs @@ -1,9 +1,9 @@ use crate::application::BookmarkAnchorType; use crate::core::hash_util; use crate::domain::{ - ActionInvocationType, DomainGlobal, ExtendedProcessorContext, ParameterArray, + ActionInvocationType, DomainGlobal, ExtendedProcessorContext, ParameterArray, ParameterSlice, PlayPosFeedbackResolution, ReaperTarget, SeekOptions, SoloBehavior, TouchedParameterType, - TrackExclusivity, TransportAction, PLUGIN_PARAMETER_COUNT, + TrackExclusivity, TransportAction, COMPARTMENT_PARAMETER_COUNT, PLUGIN_PARAMETER_COUNT, }; use derive_more::{Display, Error}; use enum_iterator::IntoEnumIterator; @@ -677,18 +677,18 @@ impl ExpressionEvaluator { Ok(evaluator) } - pub fn evaluate(&self, params: &ParameterArray) -> f64 { + pub fn evaluate(&self, params: &ParameterSlice) -> f64 { self.evaluate_internal(params).unwrap_or_default() } - fn evaluate_internal(&self, params: &ParameterArray) -> Result { + fn evaluate_internal(&self, params: &ParameterSlice) -> Result { use fasteval::eval_compiled_ref; let mut cb = |name: &str, _args: Vec| -> Option { if !name.starts_with('p') { return None; } let value: u32 = name[1..].parse().ok()?; - if !(1..=PLUGIN_PARAMETER_COUNT).contains(&value) { + if !(1..=COMPARTMENT_PARAMETER_COUNT).contains(&value) { return None; } let index = (value - 1) as usize; diff --git a/main/src/infrastructure/data/session_data.rs b/main/src/infrastructure/data/session_data.rs index 38aeba130..8cf87e9f7 100644 --- a/main/src/infrastructure/data/session_data.rs +++ b/main/src/infrastructure/data/session_data.rs @@ -172,6 +172,7 @@ impl SessionData { .map(|id| id.to_string()), active_main_preset_id: session.active_main_preset_id().map(|id| id.to_string()), main_preset_auto_load_mode: session.main_preset_auto_load_mode.get(), + // TODO-high This should probably be divided parameters: (0..PLUGIN_PARAMETER_COUNT) .filter_map(|i| { let value = parameters[i as usize]; diff --git a/main/src/infrastructure/ui/mapping_header_panel.rs b/main/src/infrastructure/ui/mapping_header_panel.rs index 74ab27b67..9fa37c6ed 100644 --- a/main/src/infrastructure/ui/mapping_header_panel.rs +++ b/main/src/infrastructure/ui/mapping_header_panel.rs @@ -11,7 +11,7 @@ use crate::application::{ ActivationType, GroupModel, MappingModel, ModifierConditionModel, ProgramConditionModel, SharedSession, WeakSession, }; -use crate::domain::PLUGIN_PARAMETER_COUNT; +use crate::domain::{COMPARTMENT_PARAMETER_COUNT, PLUGIN_PARAMETER_COUNT}; use std::fmt::Debug; use swell_ui::{DialogUnits, Point, SharedView, View, ViewContext, Window}; @@ -491,14 +491,14 @@ impl MappingHeaderPanel { }; let session = self.session(); let session = session.borrow(); - b.fill_combo_box_with_data_small(start.into_iter().chain((0..PLUGIN_PARAMETER_COUNT).map( - |i| { + b.fill_combo_box_with_data_small(start.into_iter().chain( + (0..COMPARTMENT_PARAMETER_COUNT).map(|i| { ( i as isize, format!("{}. {}", i + 1, session.get_parameter_name(i)), ) - }, - ))); + }), + )); } fn session(&self) -> SharedSession {