Skip to content

Commit

Permalink
#231 First step to compartment-private parameters (use slices)
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Mar 22, 2021
1 parent d61fdd2 commit bb70663
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 27 deletions.
1 change: 1 addition & 0 deletions main/src/application/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
22 changes: 12 additions & 10 deletions main/src/domain/conditional_activation.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -92,7 +94,7 @@ impl ActivationCondition {

fn modifier_conditions_are_fulfilled(
conditions: &[ModifierCondition],
params: &ParameterArray,
params: &ParameterSlice,
) -> bool {
conditions
.iter()
Expand All @@ -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;
Expand Down Expand Up @@ -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,
Expand All @@ -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<eel::Variable>; PLUGIN_PARAMETER_COUNT as usize],
params: [Option<eel::Variable>; COMPARTMENT_PARAMETER_COUNT as usize],
y: eel::Variable,
}

Expand All @@ -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);
Expand All @@ -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 {
Expand Down Expand Up @@ -221,7 +223,7 @@ fn extract_used_param_indexes(eel_script: &str) -> HashSet<u32> {
.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()
}
3 changes: 2 additions & 1 deletion main/src/domain/main_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
12 changes: 6 additions & 6 deletions main/src/domain/mapping.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<MappingActivationEffect> {
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -266,7 +266,7 @@ impl MainMapping {
(target_changed, Some(update))
}

pub fn update_activation(&mut self, params: &ParameterArray) -> Option<ActivationChange> {
pub fn update_activation(&mut self, params: &ParameterSlice) -> Option<ActivationChange> {
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);
Expand Down
10 changes: 5 additions & 5 deletions main/src/domain/unresolved_reaper_target.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<f64, fasteval::Error> {
fn evaluate_internal(&self, params: &ParameterSlice) -> Result<f64, fasteval::Error> {
use fasteval::eval_compiled_ref;
let mut cb = |name: &str, _args: Vec<f64>| -> Option<f64> {
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;
Expand Down
1 change: 1 addition & 0 deletions main/src/infrastructure/data/session_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down
10 changes: 5 additions & 5 deletions main/src/infrastructure/ui/mapping_header_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit bb70663

Please sign in to comment.