Skip to content

Commit

Permalink
#184 Make it compile with helgoboss-learn discrete adjustments
Browse files Browse the repository at this point in the history
doesn't use the new features yet
  • Loading branch information
helgoboss committed May 23, 2021
1 parent aba59f5 commit 68d62c3
Show file tree
Hide file tree
Showing 42 changed files with 198 additions and 135 deletions.
28 changes: 24 additions & 4 deletions main/src/application/mode_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use crate::base::{prop, Prop};
use crate::domain::{EelTransformation, Mode, OutputVariable};

use helgoboss_learn::{
check_mode_applicability, full_unit_interval, AbsoluteMode, ButtonUsage,
DetailedSourceCharacter, DiscreteIncrement, EncoderUsage, FireMode, GroupInteraction, Interval,
ModeApplicabilityCheckInput, ModeParameter, OutOfRangeBehavior, PressDurationProcessor,
SoftSymmetricUnitValue, TakeoverMode, UnitValue,
check_mode_applicability, full_discrete_interval, full_unit_interval, AbsoluteMode,
ButtonUsage, DetailedSourceCharacter, DiscreteIncrement, EncoderUsage, FireMode,
GroupInteraction, Interval, ModeApplicabilityCheckInput, ModeParameter, OutOfRangeBehavior,
PressDurationProcessor, SoftSymmetricUnitValue, TakeoverMode, UnitValue,
};

use rxrust::prelude::*;
Expand Down Expand Up @@ -207,11 +207,23 @@ impl ModeModel {
} else {
full_unit_interval()
},
discrete_source_value_interval: if is_relevant(ModeParameter::SourceMinMax) {
// TODO-high
full_discrete_interval()
} else {
full_discrete_interval()
},
target_value_interval: if is_relevant(ModeParameter::TargetMinMax) {
self.target_value_interval.get()
} else {
full_unit_interval()
},
discrete_target_value_interval: if is_relevant(ModeParameter::TargetMinMax) {
// TODO-high
full_discrete_interval()
} else {
full_discrete_interval()
},
step_count_interval: Interval::new(
min_step_count,
if step_max_is_relevant {
Expand All @@ -233,6 +245,12 @@ impl ModeModel {
} else {
full_unit_interval()
},
discrete_jump_interval: if is_relevant(ModeParameter::JumpMinMax) {
// TODO-high
full_discrete_interval()
} else {
full_discrete_interval()
},
press_duration_processor: PressDurationProcessor::new(
if is_relevant(ModeParameter::FireMode) {
self.fire_mode.get()
Expand Down Expand Up @@ -302,7 +320,9 @@ impl ModeModel {
false
},
current_absolute_value: UnitValue::MIN,
discrete_current_absolute_value: 0,
previous_absolute_control_value: None,
discrete_previous_absolute_control_value: None,
}
}
}
Expand Down
12 changes: 4 additions & 8 deletions main/src/domain/eel_transformation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,18 @@ impl EelTransformation {
}

impl Transformation for EelTransformation {
fn transform(
&self,
input_value: UnitValue,
output_value: UnitValue,
) -> Result<UnitValue, &'static str> {
fn transform(&self, input_value: f64, output_value: f64) -> Result<f64, &'static str> {
let result = unsafe {
use OutputVariable::*;
let (input_var, output_var) = match self.output_var {
X => (&self.eel_unit.y, &self.eel_unit.x),
Y => (&self.eel_unit.x, &self.eel_unit.y),
};
input_var.set(input_value.get());
output_var.set(output_value.get());
input_var.set(input_value);
output_var.set(output_value);
self.eel_unit.program.execute();
output_var.get()
};
result.try_into().map_err(|_| "result is not a unit value")
Ok(result)
}
}
3 changes: 3 additions & 0 deletions main/src/domain/main_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
&self.collections.mappings_with_virtual_targets,
&mut |t| {
if let Some(value) = t.current_value(control_context) {
let value = value.to_unit_value();
match previous_target_values[compartment].entry(*mapping_id) {
Entry::Occupied(mut e) => {
if (e.get().get() - value.get()).abs()
Expand All @@ -415,6 +416,8 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
} else {
// Value has changed.
e.insert(value);
// TODO-high Here and in similar places we should
// return AbsoluteValue.
(true, Some(value))
}
}
Expand Down
33 changes: 24 additions & 9 deletions main/src/domain/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ use derive_more::Display;
use enum_iterator::IntoEnumIterator;
use enum_map::Enum;
use helgoboss_learn::{
format_percentage_without_unit, parse_percentage_without_unit, ControlType, ControlValue,
GroupInteraction, MidiSourceValue, ModeControlOptions, ModeControlResult, OscSource,
RawMidiEvent, SourceCharacter, Target, UnitValue,
format_percentage_without_unit, parse_percentage_without_unit, AbsoluteValue, ControlType,
ControlValue, GroupInteraction, MidiSourceValue, ModeControlOptions, ModeControlResult,
OscSource, RawMidiEvent, SourceCharacter, Target, UnitValue,
};
use helgoboss_midi::{RawShortMessage, ShortMessage};
use num_enum::{IntoPrimitive, TryFromPrimitive};
Expand Down Expand Up @@ -632,7 +632,8 @@ impl MainMapping {
})
.max()?;
self.feedback_given_target_value(
combined_target_value,
// TODO-high Discrete
combined_target_value.to_unit_value(),
with_projection_feedback,
!self.core.is_echo(),
)
Expand All @@ -648,11 +649,16 @@ impl MainMapping {
target: &ReaperTarget,
context: ControlContext,
) -> Option<UnitValue> {
target_value.or_else(|| target.current_value(context))
// TODO-high discrete
target_value.or_else(|| target.current_value(context).map(|v| v.to_unit_value()))
}

pub fn current_aggregated_target_value(&self, context: ControlContext) -> Option<UnitValue> {
let values = self.targets.iter().map(|t| t.current_value(context));
// TODO-high discrete
let values = self
.targets
.iter()
.map(|t| t.current_value(context).map(|v| v.to_unit_value()));
aggregate_target_values(values)
}

Expand All @@ -670,8 +676,17 @@ impl MainMapping {
with_projection_feedback: bool,
with_source_feedback: bool,
) -> Option<FeedbackValue> {
let mode_value = self.core.mode.feedback(target_value)?;
self.feedback_given_mode_value(mode_value, with_projection_feedback, with_source_feedback)
// TODO-high discrete
let mode_value = self
.core
.mode
.feedback(AbsoluteValue::Continuous(target_value))?;
// TODO-high discrete
self.feedback_given_mode_value(
mode_value.to_unit_value(),
with_projection_feedback,
with_source_feedback,
)
}

pub fn feedback_given_mode_value(
Expand Down Expand Up @@ -1364,7 +1379,7 @@ impl RealearnTarget for CompoundMappingTarget {
impl<'a> Target<'a> for CompoundMappingTarget {
type Context = ControlContext<'a>;

fn current_value(&self, context: ControlContext) -> Option<UnitValue> {
fn current_value(&self, context: ControlContext) -> Option<AbsoluteValue> {
use CompoundMappingTarget::*;
match self {
Reaper(t) => t.current_value(context),
Expand Down
6 changes: 3 additions & 3 deletions main/src/domain/reaper_target.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::base::default_util::is_default;
use derive_more::Display;
use enum_iterator::IntoEnumIterator;
use helgoboss_learn::{ControlType, ControlValue, Target, UnitValue};
use helgoboss_learn::{AbsoluteValue, ControlType, ControlValue, Target, UnitValue};
use num_enum::{IntoPrimitive, TryFromPrimitive};
use reaper_high::{
Action, AvailablePanValue, BookmarkType, ChangeEvent, Fx, FxChain, Pan, PlayRate, Project,
Expand Down Expand Up @@ -566,7 +566,7 @@ impl<'a> Target<'a> for ReaperTarget {
// controlled from real-time processor.
type Context = ControlContext<'a>;

fn current_value(&self, context: ControlContext) -> Option<UnitValue> {
fn current_value(&self, context: ControlContext) -> Option<AbsoluteValue> {
use ReaperTarget::*;
match self {
SendOsc { .. } => None,
Expand Down Expand Up @@ -613,7 +613,7 @@ impl<'a> Target<'a> for ReaperTarget {
impl<'a> Target<'a> for RealTimeReaperTarget {
type Context = ();

fn current_value(&self, _: ()) -> Option<UnitValue> {
fn current_value(&self, _: ()) -> Option<AbsoluteValue> {
use RealTimeReaperTarget::*;
match self {
SendMidi(t) => t.current_value(()),
Expand Down
7 changes: 4 additions & 3 deletions main/src/domain/targets/action_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ use crate::domain::ui_util::convert_bool_to_unit_value;
use crate::domain::{
ActionInvocationType, AdditionalFeedbackEvent, ControlContext, RealearnTarget, TargetCharacter,
};
use helgoboss_learn::{ControlType, ControlValue, Fraction, Target, UnitValue};
use helgoboss_learn::ControlType::AbsoluteContinuous;
use helgoboss_learn::{AbsoluteValue, ControlType, ControlValue, Fraction, Target, UnitValue};
use helgoboss_midi::U14;
use reaper_high::{Action, ActionCharacter, Project, Reaper};
use reaper_medium::{ActionValueChange, CommandId, WindowContext};
Expand Down Expand Up @@ -107,7 +108,7 @@ impl RealearnTarget for ActionTarget {
impl<'a> Target<'a> for ActionTarget {
type Context = ();

fn current_value(&self, _: ()) -> Option<UnitValue> {
fn current_value(&self, _: ()) -> Option<AbsoluteValue> {
let val = if let Some(state) = self.action.is_on() {
// Toggle action: Return toggle state as 0 or 1.
convert_bool_to_unit_value(state)
Expand All @@ -120,7 +121,7 @@ impl<'a> Target<'a> for ActionTarget {
UnitValue::MIN
}
};
Some(val)
Some(AbsoluteValue::Continuous(val))
}

fn control_type(&self) -> ControlType {
Expand Down
7 changes: 4 additions & 3 deletions main/src/domain/targets/all_track_fx_enable_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::domain::{
get_control_type_and_character_for_track_exclusivity, handle_track_exclusivity, ControlContext,
RealearnTarget, TargetCharacter, TrackExclusivity,
};
use helgoboss_learn::{ControlType, ControlValue, Target, UnitValue};
use helgoboss_learn::{AbsoluteValue, ControlType, ControlValue, Target, UnitValue};
use reaper_high::{Project, Track};

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -57,8 +57,9 @@ impl RealearnTarget for AllTrackFxEnableTarget {
impl<'a> Target<'a> for AllTrackFxEnableTarget {
type Context = ();

fn current_value(&self, _: ()) -> Option<UnitValue> {
Some(all_track_fx_enable_unit_value(self.track.fx_is_enabled()))
fn current_value(&self, _: ()) -> Option<AbsoluteValue> {
let val = all_track_fx_enable_unit_value(self.track.fx_is_enabled());
Some(AbsoluteValue::Continuous(val))
}

fn control_type(&self) -> ControlType {
Expand Down
6 changes: 3 additions & 3 deletions main/src/domain/targets/automation_mode_override_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::domain::{
format_value_as_on_off, global_automation_mode_override_unit_value, ControlContext,
RealearnTarget, TargetCharacter,
};
use helgoboss_learn::{ControlType, ControlValue, Target, UnitValue};
use helgoboss_learn::{AbsoluteValue, ControlType, ControlValue, Target, UnitValue};
use reaper_high::{ChangeEvent, Reaper};
use reaper_medium::GlobalAutomationModeOverride;

Expand Down Expand Up @@ -58,12 +58,12 @@ impl RealearnTarget for AutomationModeOverrideTarget {
impl<'a> Target<'a> for AutomationModeOverrideTarget {
type Context = ();

fn current_value(&self, _: ()) -> Option<UnitValue> {
fn current_value(&self, _: ()) -> Option<AbsoluteValue> {
let value = global_automation_mode_override_unit_value(
self.mode_override,
Reaper::get().global_automation_override(),
);
Some(value)
Some(AbsoluteValue::Continuous(value))
}

fn control_type(&self) -> ControlType {
Expand Down
6 changes: 3 additions & 3 deletions main/src/domain/targets/automation_touch_state_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::domain::{
handle_track_exclusivity, touched_unit_value, AdditionalFeedbackEvent, BackboneState,
ControlContext, RealearnTarget, TargetCharacter, TouchedParameterType, TrackExclusivity,
};
use helgoboss_learn::{ControlType, ControlValue, Target, UnitValue};
use helgoboss_learn::{AbsoluteValue, ControlType, ControlValue, Target, UnitValue};
use reaper_high::{Project, Track};

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -72,11 +72,11 @@ impl RealearnTarget for AutomationTouchStateTarget {
impl<'a> Target<'a> for AutomationTouchStateTarget {
type Context = ();

fn current_value(&self, _: ()) -> Option<UnitValue> {
fn current_value(&self, _: ()) -> Option<AbsoluteValue> {
let is_touched = BackboneState::target_context()
.borrow()
.automation_parameter_is_touched(self.track.raw(), self.parameter_type);
Some(touched_unit_value(is_touched))
Some(AbsoluteValue::Continuous(touched_unit_value(is_touched)))
}

fn control_type(&self) -> ControlType {
Expand Down
6 changes: 3 additions & 3 deletions main/src/domain/targets/clip_seek_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::domain::{
AdditionalFeedbackEvent, ClipChangedEvent, ClipPlayState, ControlContext, FeedbackResolution,
InstanceFeedbackEvent, RealearnTarget, TargetCharacter,
};
use helgoboss_learn::{ControlType, ControlValue, Target, UnitValue};
use helgoboss_learn::{AbsoluteValue, ControlType, ControlValue, Target, UnitValue};

#[derive(Clone, Debug, PartialEq)]
pub struct ClipSeekTarget {
Expand Down Expand Up @@ -69,14 +69,14 @@ impl RealearnTarget for ClipSeekTarget {
impl<'a> Target<'a> for ClipSeekTarget {
type Context = ControlContext<'a>;

fn current_value(&self, context: ControlContext<'a>) -> Option<UnitValue> {
fn current_value(&self, context: ControlContext<'a>) -> Option<AbsoluteValue> {
let instance_state = context.instance_state.borrow();
let val = instance_state
.get_slot(self.slot_index)
.ok()?
.position()
.ok()?;
Some(val)
Some(AbsoluteValue::Continuous(val))
}

fn control_type(&self) -> ControlType {
Expand Down
6 changes: 3 additions & 3 deletions main/src/domain/targets/clip_transport_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::domain::{
ClipChangedEvent, ControlContext, InstanceFeedbackEvent, RealearnTarget, SlotPlayOptions,
TargetCharacter, TransportAction,
};
use helgoboss_learn::{ControlType, ControlValue, Target, UnitValue};
use helgoboss_learn::{AbsoluteValue, ControlType, ControlValue, Target, UnitValue};
use reaper_high::{ChangeEvent, Project, Track};

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -133,7 +133,7 @@ impl RealearnTarget for ClipTransportTarget {
impl<'a> Target<'a> for ClipTransportTarget {
type Context = ControlContext<'a>;

fn current_value(&self, context: ControlContext<'a>) -> Option<UnitValue> {
fn current_value(&self, context: ControlContext<'a>) -> Option<AbsoluteValue> {
let instance_state = context.instance_state.borrow();
use TransportAction::*;
let val = match self.action {
Expand All @@ -150,7 +150,7 @@ impl<'a> Target<'a> for ClipTransportTarget {
}
Record => return None,
};
Some(val)
Some(AbsoluteValue::Continuous(val))
}

fn control_type(&self) -> ControlType {
Expand Down
6 changes: 3 additions & 3 deletions main/src/domain/targets/clip_volume_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::domain::ui_util::{
use crate::domain::{
ClipChangedEvent, ControlContext, InstanceFeedbackEvent, RealearnTarget, TargetCharacter,
};
use helgoboss_learn::{ControlType, ControlValue, Target, UnitValue};
use helgoboss_learn::{AbsoluteValue, ControlType, ControlValue, Target, UnitValue};
use reaper_high::Volume;

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -67,10 +67,10 @@ impl RealearnTarget for ClipVolumeTarget {
impl<'a> Target<'a> for ClipVolumeTarget {
type Context = ControlContext<'a>;

fn current_value(&self, context: ControlContext<'a>) -> Option<UnitValue> {
fn current_value(&self, context: ControlContext<'a>) -> Option<AbsoluteValue> {
let instance_state = context.instance_state.borrow();
let volume = instance_state.get_slot(self.slot_index).ok()?.volume();
Some(reaper_volume_unit_value(volume))
Some(AbsoluteValue::Continuous(reaper_volume_unit_value(volume)))
}

fn control_type(&self) -> ControlType {
Expand Down
8 changes: 5 additions & 3 deletions main/src/domain/targets/fx_enable_target.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::domain::{
format_value_as_on_off, fx_enable_unit_value, ControlContext, RealearnTarget, TargetCharacter,
};
use helgoboss_learn::{ControlType, ControlValue, Target, UnitValue};
use helgoboss_learn::{AbsoluteValue, ControlType, ControlValue, Target, UnitValue};
use reaper_high::{ChangeEvent, Fx, Project, Track};

#[derive(Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -60,8 +60,10 @@ impl RealearnTarget for FxEnableTarget {
impl<'a> Target<'a> for FxEnableTarget {
type Context = ();

fn current_value(&self, _: ()) -> Option<UnitValue> {
Some(fx_enable_unit_value(self.fx.is_enabled()))
fn current_value(&self, _: ()) -> Option<AbsoluteValue> {
Some(AbsoluteValue::Continuous(fx_enable_unit_value(
self.fx.is_enabled(),
)))
}

fn control_type(&self) -> ControlType {
Expand Down
Loading

0 comments on commit 68d62c3

Please sign in to comment.