Skip to content

Commit

Permalink
#160 Make evaluation partially work WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Mar 8, 2021
1 parent 28e8238 commit 9d32e2a
Show file tree
Hide file tree
Showing 17 changed files with 352 additions and 197 deletions.
16 changes: 8 additions & 8 deletions main/src/application/mapping_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ use crate::application::{
};
use crate::core::{prop, Prop};
use crate::domain::{
ActivationCondition, CompoundMappingTarget, ExtendedSourceCharacter, MainMapping,
MappingCompartment, MappingId, ProcessorContext, ProcessorMappingOptions, RealearnTarget,
ReaperTarget, TargetCharacter,
ActivationCondition, CompoundMappingTarget, ExtendedProcessorContext, ExtendedSourceCharacter,
MainMapping, MappingCompartment, MappingId, ProcessorContext, ProcessorMappingOptions,
RealearnTarget, ReaperTarget, TargetCharacter,
};

use std::cell::RefCell;
Expand Down Expand Up @@ -147,15 +147,15 @@ impl MappingModel {

pub fn with_context<'a>(
&'a self,
context: &'a ProcessorContext,
context: ExtendedProcessorContext<'a>,
) -> MappingModelWithContext<'a> {
MappingModelWithContext {
mapping: self,
context,
}
}

pub fn adjust_mode_if_necessary(&mut self, context: &ProcessorContext) {
pub fn adjust_mode_if_necessary(&mut self, context: ExtendedProcessorContext) {
let with_context = self.with_context(context);
if with_context.mode_makes_sense().contains(&false) {
if let Ok(preferred_mode_type) = with_context.preferred_mode_type() {
Expand All @@ -165,13 +165,13 @@ impl MappingModel {
}
}

pub fn reset_mode(&mut self, context: &ProcessorContext) {
pub fn reset_mode(&mut self, context: ExtendedProcessorContext) {
self.mode_model.reset_within_type();
self.set_preferred_mode_values(context);
}

// Changes mode settings if there are some preferred ones for a certain source or target.
pub fn set_preferred_mode_values(&mut self, context: &ProcessorContext) {
pub fn set_preferred_mode_values(&mut self, context: ExtendedProcessorContext) {
self.mode_model
.step_interval
.set(self.with_context(context).preferred_step_interval())
Expand Down Expand Up @@ -257,7 +257,7 @@ impl Default for GroupData {

pub struct MappingModelWithContext<'a> {
mapping: &'a MappingModel,
context: &'a ProcessorContext,
context: ExtendedProcessorContext<'a>,
}

impl<'a> MappingModelWithContext<'a> {
Expand Down
6 changes: 3 additions & 3 deletions main/src/application/preset.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::application::{GroupModel, MappingModel, SharedGroup, SharedMapping, TargetCategory};
use crate::domain::{ProcessorContext, VirtualFx, VirtualTrack};
use crate::domain::{ExtendedProcessorContext, ProcessorContext, VirtualFx, VirtualTrack};
use std::fmt;
use std::fmt::Debug;

Expand Down Expand Up @@ -31,7 +31,7 @@ pub fn mappings_have_project_references(mappings: &[MappingModel]) -> bool {

pub fn make_mappings_project_independent(
mappings: &mut [MappingModel],
context: &ProcessorContext,
context: ExtendedProcessorContext,
) {
mappings
.iter_mut()
Expand Down Expand Up @@ -59,7 +59,7 @@ fn mapping_has_project_references(mapping: &MappingModel) -> bool {
}
}

fn make_mapping_project_independent(mapping: &mut MappingModel, context: &ProcessorContext) {
fn make_mapping_project_independent(mapping: &mut MappingModel, context: ExtendedProcessorContext) {
let target = &mut mapping.target_model;
match target.category.get() {
TargetCategory::Reaper => {
Expand Down
39 changes: 25 additions & 14 deletions main/src/application/session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ use crate::application::{
};
use crate::core::{prop, when, AsyncNotifier, Global, Prop};
use crate::domain::{
CompoundMappingSource, DomainEvent, DomainEventHandler, MainMapping, MappingCompartment,
MappingId, MidiControlInput, MidiFeedbackOutput, NormalMainTask, NormalRealTimeTask,
OscDeviceId, ProcessorContext, RealSource, ReaperTarget, TargetValueChangedEvent,
VirtualSource, PLUGIN_PARAMETER_COUNT,
CompoundMappingSource, DomainEvent, DomainEventHandler, ExtendedProcessorContext, MainMapping,
MappingCompartment, MappingId, MidiControlInput, MidiFeedbackOutput, NormalMainTask,
NormalRealTimeTask, OscDeviceId, ParameterArray, ProcessorContext, RealSource, ReaperTarget,
TargetValueChangedEvent, VirtualSource, PLUGIN_PARAMETER_COUNT, ZEROED_PLUGIN_PARAMETERS,
};
use enum_iterator::IntoEnumIterator;
use enum_map::EnumMap;
Expand Down Expand Up @@ -76,6 +76,7 @@ pub struct Session {
normal_real_time_task_sender: crossbeam_channel::Sender<NormalRealTimeTask>,
party_is_over_subject: LocalSubject<'static, (), ()>,
ui: WrapDebug<Box<dyn SessionUi>>,
parameters: ParameterArray,
parameter_settings: Vec<ParameterSetting>,
controller_preset_manager: Box<dyn PresetManager<PresetType = ControllerPreset>>,
main_preset_manager: Box<dyn PresetManager<PresetType = MainPreset>>,
Expand Down Expand Up @@ -186,6 +187,7 @@ impl Session {
normal_real_time_task_sender,
party_is_over_subject: Default::default(),
ui: WrapDebug(Box::new(ui)),
parameters: ZEROED_PLUGIN_PARAMETERS,
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 Expand Up @@ -273,7 +275,7 @@ impl Session {
self.sync_control_is_globally_enabled();
self.sync_feedback_is_globally_enabled();
// Now sync mappings - which includes initial feedback.
for compartment in MappingCompartment::into_enum_iter() {
for compartment in MappingCompartment::enum_iter() {
self.resubscribe_to_mappings(compartment, weak_session.clone());
self.sync_all_mappings_full(compartment);
}
Expand All @@ -289,7 +291,7 @@ impl Session {
when(self.auto_correct_settings.changed())
.with(weak_session.clone())
.do_async(|shared_session, _| {
for compartment in MappingCompartment::into_enum_iter() {
for compartment in MappingCompartment::enum_iter() {
shared_session
.borrow_mut()
.resubscribe_to_mappings(compartment, Rc::downgrade(&shared_session));
Expand Down Expand Up @@ -424,7 +426,7 @@ impl Session {
for m in self.all_mappings() {
m.borrow_mut()
.target_model
.invalidate_fx_index(&self.context);
.invalidate_fx_index(self.extended_context());
}
}

Expand Down Expand Up @@ -568,9 +570,11 @@ impl Session {
)
.with(Rc::downgrade(&shared_mapping))
.do_sync(move |mapping, _| {
mapping
.borrow_mut()
.adjust_mode_if_necessary(&processor_context);
// TODO-high We need access to the parameters when adjusting the mode but
// we can't just copy them! Find a solution.
// mapping
// .borrow_mut()
// .adjust_mode_if_necessary(&processor_context);
});
all_subscriptions.add(subscription);
}
Expand Down Expand Up @@ -636,6 +640,10 @@ impl Session {
&self.context
}

pub fn extended_context(&self) -> ExtendedProcessorContext {
ExtendedProcessorContext::new(&self.context, &self.parameters)
}

pub fn add_default_group(&mut self, name: String) -> GroupId {
let group = GroupModel::new_from_ui(name);
self.add_group(group)
Expand Down Expand Up @@ -921,7 +929,7 @@ impl Session {
}

fn all_mappings(&self) -> impl Iterator<Item = &SharedMapping> {
MappingCompartment::into_enum_iter()
MappingCompartment::enum_iter()
.map(move |compartment| self.mappings(compartment))
.flatten()
}
Expand Down Expand Up @@ -1170,7 +1178,7 @@ impl Session {
&self,
mapping_id: MappingId,
) -> Option<(MappingCompartment, usize)> {
MappingCompartment::into_enum_iter().find_map(|compartment| {
MappingCompartment::enum_iter().find_map(|compartment| {
let index = self.index_of_mapping(compartment, mapping_id)?;
Some((compartment, index))
})
Expand Down Expand Up @@ -1451,8 +1459,11 @@ impl Session {
compartment: MappingCompartment,
target: &ReaperTarget,
) -> Option<&SharedMapping> {
self.mappings(compartment)
.find(|m| m.borrow().with_context(&self.context).has_target(target))
self.mappings(compartment).find(|m| {
m.borrow()
.with_context(self.extended_context())
.has_target(target)
})
}

pub fn toggle_learn_source_for_target(
Expand Down
34 changes: 20 additions & 14 deletions main/src/application/target_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ use serde::{Deserialize, Serialize};
use crate::application::VirtualControlElementType;
use crate::domain::{
find_bookmark, get_fx, get_fx_chain, get_fx_param, get_track_send, ActionInvocationType,
CompoundMappingTarget, ExpressionEvaluator, FxAnchor, FxDescriptor, ProcessorContext,
ReaperTarget, SoloBehavior, TouchedParameterType, TrackDescriptor, TrackExclusivity,
TransportAction, UnresolvedCompoundMappingTarget, UnresolvedReaperTarget,
CompoundMappingTarget, ExpressionEvaluator, ExtendedProcessorContext, FxAnchor, FxDescriptor,
ProcessorContext, ReaperTarget, SoloBehavior, TouchedParameterType, TrackDescriptor,
TrackExclusivity, TransportAction, UnresolvedCompoundMappingTarget, UnresolvedReaperTarget,
VirtualControlElement, VirtualFx, VirtualTarget, VirtualTrack,
};
use serde_repr::*;
Expand Down Expand Up @@ -103,7 +103,10 @@ impl Default for TargetModel {
}

impl TargetModel {
pub fn take_fx_snapshot(&self, context: &ProcessorContext) -> Result<FxSnapshot, &'static str> {
pub fn take_fx_snapshot(
&self,
context: ExtendedProcessorContext,
) -> Result<FxSnapshot, &'static str> {
let fx = self.with_context(context).fx()?;
let fx_info = fx.info();
let fx_snapshot = FxSnapshot {
Expand All @@ -119,7 +122,7 @@ impl TargetModel {
Ok(fx_snapshot)
}

pub fn invalidate_fx_index(&mut self, context: &ProcessorContext) {
pub fn invalidate_fx_index(&mut self, context: ExtendedProcessorContext) {
if !self.supports_fx() {
return;
}
Expand Down Expand Up @@ -412,7 +415,10 @@ impl TargetModel {
}
}

pub fn with_context<'a>(&'a self, context: &'a ProcessorContext) -> TargetModelWithContext<'a> {
pub fn with_context<'a>(
&'a self,
context: ExtendedProcessorContext<'a>,
) -> TargetModelWithContext<'a> {
TargetModelWithContext {
target: self,
context,
Expand Down Expand Up @@ -526,7 +532,7 @@ pub fn get_fx_label(index: u32, fx: &Fx) -> String {

pub struct TargetModelWithContext<'a> {
target: &'a TargetModel,
context: &'a ProcessorContext,
context: ExtendedProcessorContext<'a>,
}

impl<'a> TargetModelWithContext<'a> {
Expand All @@ -542,7 +548,7 @@ impl<'a> TargetModelWithContext<'a> {
/// track/FX/parameter) is not available.
pub fn create_target(&self) -> Result<CompoundMappingTarget, &'static str> {
let unresolved = self.target.create_target()?;
unresolved.resolve(&self.context)
unresolved.resolve(self.context)
}

pub fn is_known_to_be_roundable(&self) -> bool {
Expand All @@ -558,26 +564,26 @@ impl<'a> TargetModelWithContext<'a> {
}
// Returns an error if the FX doesn't exist.
pub fn fx(&self) -> Result<Fx, &'static str> {
get_fx(&self.context, &self.target.fx_descriptor()?)
get_fx(self.context, &self.target.fx_descriptor()?)
}

pub fn project(&self) -> Project {
self.context.project_or_current_project()
self.context.context.project_or_current_project()
}

// TODO-low Consider returning a Cow
pub fn effective_track(&self) -> Result<Track, &'static str> {
self.target
.virtual_track()
.ok_or("virtual track not complete")?
.resolve(&self.context)
.resolve(self.context)
.map_err(|_| "particular track couldn't be resolved")
}

// Returns an error if that send (or track) doesn't exist.
fn track_send(&self) -> Result<TrackSend, &'static str> {
get_track_send(
&self.context,
self.context,
&self
.target
.virtual_track()
Expand All @@ -589,7 +595,7 @@ impl<'a> TargetModelWithContext<'a> {
// Returns an error if that param (or FX) doesn't exist.
fn fx_param(&self) -> Result<FxParameter, &'static str> {
get_fx_param(
&self.context,
self.context,
&self.target.fx_descriptor()?,
self.target.param_index.get(),
)
Expand Down Expand Up @@ -620,7 +626,7 @@ impl<'a> TargetModelWithContext<'a> {
}

pub fn get_guid_based_fx_at_index(
context: &ProcessorContext,
context: ExtendedProcessorContext,
track: &VirtualTrack,
is_input_fx: bool,
fx_index: u32,
Expand Down
Loading

0 comments on commit 9d32e2a

Please sign in to comment.