Skip to content

Commit

Permalink
#11 Allow custom parameter names via JSON export/import
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Aug 26, 2020
1 parent 76aaef1 commit 48be43d
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 6 deletions.
6 changes: 5 additions & 1 deletion main/src/application/parameter_data.rs
Expand Up @@ -4,10 +4,14 @@ use serde::{Deserialize, Serialize};
#[serde(rename_all = "camelCase", default)]
pub struct ParameterData {
pub value: f32,
pub name: Option<String>,
}

impl Default for ParameterData {
fn default() -> Self {
Self { value: 0.0 }
Self {
value: 0.0,
name: None,
}
}
}
17 changes: 14 additions & 3 deletions main/src/application/session_data.rs
@@ -1,5 +1,7 @@
use crate::application::{MappingModelData, ParameterData};
use crate::domain::{MidiControlInput, MidiFeedbackOutput, Session, PLUGIN_PARAMETER_COUNT};
use crate::domain::{
MidiControlInput, MidiFeedbackOutput, ParameterSetting, Session, PLUGIN_PARAMETER_COUNT,
};
use reaper_high::{MidiInputDevice, MidiOutputDevice};
use reaper_medium::{MidiInputDeviceId, MidiOutputDeviceId};
use serde::{Deserialize, Serialize};
Expand Down Expand Up @@ -72,10 +74,14 @@ impl SessionData {
parameters: (0..PLUGIN_PARAMETER_COUNT)
.filter_map(|i| {
let value = session.get_parameter(i);
if value == 0.0 {
let settings = session.get_parameter_settings(i);
if value == 0.0 && settings.custom_name.is_none() {
return None;
}
let data = ParameterData { value };
let data = ParameterData {
value,
name: settings.custom_name.clone(),
};
Some((i, data))
})
.collect(),
Expand Down Expand Up @@ -141,10 +147,15 @@ impl SessionData {
);
// Parameters
let mut parameters = [0.0f32; PLUGIN_PARAMETER_COUNT as usize];
let mut parameter_settings = vec![Default::default(); PLUGIN_PARAMETER_COUNT as usize];
for (i, p) in self.parameters.iter() {
parameters[*i as usize] = p.value;
parameter_settings[*i as usize] = ParameterSetting {
custom_name: p.name.clone(),
};
}
session.set_parameters_without_notification(parameters);
session.set_parameter_settings_without_notification(parameter_settings);
Ok(())
}
}
1 change: 1 addition & 0 deletions main/src/domain/main_processor.rs
Expand Up @@ -19,6 +19,7 @@ const CONTROL_TASK_BULK_SIZE: usize = 32;
type FeedbackSubscriptionGuard = SubscriptionGuard<Box<dyn SubscriptionLike>>;
type FeedbackSubscriptions = HashMap<MappingId, FeedbackSubscriptionGuard>;

// TODO-low Making this a usize might save quite some code
pub const PLUGIN_PARAMETER_COUNT: u32 = 20;

#[derive(Debug)]
Expand Down
24 changes: 23 additions & 1 deletion main/src/domain/session.rs
Expand Up @@ -74,6 +74,7 @@ pub struct Session {
party_is_over_subject: LocalSubject<'static, (), ()>,
ui: WrapDebug<Box<dyn SessionUi>>,
parameters: [f32; PLUGIN_PARAMETER_COUNT as usize],
parameter_settings: Vec<ParameterSetting>,
}

impl Session {
Expand Down Expand Up @@ -111,11 +112,20 @@ impl Session {
party_is_over_subject: Default::default(),
ui: WrapDebug(Box::new(ui)),
parameters: [0.0; PLUGIN_PARAMETER_COUNT as usize],
parameter_settings: vec![Default::default(); PLUGIN_PARAMETER_COUNT as usize],
}
}

pub fn get_parameter_settings(&self, index: u32) -> &ParameterSetting {
&self.parameter_settings[index as usize]
}

pub fn get_parameter_name(&self, index: u32) -> String {
format!("Parameter {}", index + 1)
let setting = &self.parameter_settings[index as usize];
match &setting.custom_name {
None => format!("Parameter {}", index + 1),
Some(n) => n.clone(),
}
}

pub fn get_parameter(&self, index: u32) -> f32 {
Expand All @@ -130,6 +140,13 @@ impl Session {
.unwrap();
}

pub fn set_parameter_settings_without_notification(
&mut self,
parameter_settings: Vec<ParameterSetting>,
) {
self.parameter_settings = parameter_settings;
}

pub fn set_parameters_without_notification(
&mut self,
parameters: [f32; PLUGIN_PARAMETER_COUNT as usize],
Expand Down Expand Up @@ -800,6 +817,11 @@ impl Session {
}
}

#[derive(Clone, Debug, Default)]
pub struct ParameterSetting {
pub custom_name: Option<String>,
}

struct SplinteredProcessorMappings {
real_time: Vec<RealTimeProcessorMapping>,
main: Vec<MainProcessorMapping>,
Expand Down
7 changes: 6 additions & 1 deletion main/src/infrastructure/ui/mapping_panel.rs
Expand Up @@ -2215,7 +2215,12 @@ impl<'a> ImmutableMappingPanel<'a> {
fn fill_mapping_activation_settings_combo_box(&self, control_id: u32) {
let b = self.view.require_control(control_id);
b.fill_combo_box_with_data_small(iter::once((-1isize, "<None>".to_string())).chain(
(0..PLUGIN_PARAMETER_COUNT).map(|i| (i as isize, self.session.get_parameter_name(i))),
(0..PLUGIN_PARAMETER_COUNT).map(|i| {
(
i as isize,
format!("{}. {}", i + 1, self.session.get_parameter_name(i)),
)
}),
));
}

Expand Down

0 comments on commit 48be43d

Please sign in to comment.