Skip to content

Commit

Permalink
#160 Propagate parameters to session
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Mar 8, 2021
1 parent 9d32e2a commit 83e3009
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions main/src/application/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1717,6 +1717,12 @@ impl DomainEventHandler for WeakSession {
s.ui.target_value_changed(e);
}
}
UpdatedParameter { index, value } => {
session.borrow_mut().parameters[index as usize] = value;
}
UpdatedAllParameters(params) => {
session.borrow_mut().parameters = *params;
}
}
}
}
Expand Down
9 changes: 8 additions & 1 deletion main/src/domain/eventing.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::domain::{CompoundMappingSource, CompoundMappingTarget, MappingCompartment, MappingId};
use crate::domain::{
CompoundMappingSource, CompoundMappingTarget, MappingCompartment, MappingId, ParameterArray,
};
use helgoboss_learn::{MidiSource, OscSource, UnitValue};
use std::collections::HashSet;
use std::fmt::Debug;
Expand All @@ -11,6 +13,11 @@ pub enum DomainEvent<'a> {
allow_virtual_sources: bool,
},
UpdatedOnMappings(HashSet<MappingId>),
UpdatedParameter {
index: u32,
value: f32,
},
UpdatedAllParameters(Box<ParameterArray>),
TargetValueChanged(TargetValueChangedEvent<'a>),
}

Expand Down
4 changes: 4 additions & 0 deletions main/src/domain/main_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,8 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
UpdateAllParameters(parameters) => {
debug!(self.logger, "Updating all parameters...");
self.parameters = *parameters;
self.event_handler
.handle_event(DomainEvent::UpdatedAllParameters(parameters));
// Activation is only supported for main mappings
// Mappings with virtual targets can only exist in the controller compartment
// and the mappings in there don't support conditional activation. However,
Expand Down Expand Up @@ -468,6 +470,8 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
// Update own value (important to do first)
let previous_value = self.parameters[index as usize];
self.parameters[index as usize] = value;
self.event_handler
.handle_event(DomainEvent::UpdatedParameter { index, value });
// Mapping activation is only supported for main mappings but target activation
// might change also in non-virtual controller mappings due to dynamic targets.
for compartment in MappingCompartment::enum_iter() {
Expand Down

0 comments on commit 83e3009

Please sign in to comment.