Skip to content

Commit

Permalink
#184 Fix wrong Eq and Ord implementation for AbsoluteValue
Browse files Browse the repository at this point in the history
it made tests return false positives because just unit values were compared
  • Loading branch information
helgoboss committed May 23, 2021
1 parent 8a74240 commit 3bf63a5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
17 changes: 14 additions & 3 deletions main/src/domain/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use enum_map::Enum;
use helgoboss_learn::{
format_percentage_without_unit, parse_percentage_without_unit, AbsoluteValue, ControlType,
ControlValue, GroupInteraction, MidiSourceValue, ModeControlOptions, ModeControlResult,
OscSource, RawMidiEvent, SourceCharacter, Target, UnitValue,
ModeFeedbackOptions, OscSource, RawMidiEvent, SourceCharacter, Target, UnitValue,
};
use helgoboss_midi::{RawShortMessage, ShortMessage};
use num_enum::{IntoPrimitive, TryFromPrimitive};
Expand Down Expand Up @@ -676,11 +676,14 @@ impl MainMapping {
with_projection_feedback: bool,
with_source_feedback: bool,
) -> Option<FeedbackValue> {
let options = ModeFeedbackOptions {
source_is_virtual: self.core.source.is_virtual(),
};
// TODO-high discrete
let mode_value = self
.core
.mode
.feedback(AbsoluteValue::Continuous(target_value))?;
.feedback_with_options(AbsoluteValue::Continuous(target_value), options)?;
// TODO-high discrete
self.feedback_given_mode_value(
mode_value.to_unit_value(),
Expand Down Expand Up @@ -986,6 +989,10 @@ impl CompoundMappingSource {
Virtual(_) | Osc(_) | Never => false,
}
}

pub fn is_virtual(&self) -> bool {
matches!(self, CompoundMappingSource::Virtual(_))
}
}

#[derive(Clone, PartialEq, Debug)]
Expand Down Expand Up @@ -1481,7 +1488,11 @@ fn match_partially(
// TODO-medium If we want to support fire after timeout and turbo for mappings with
// virtual targets one day, we need to poll this in real-time processor and OSC
// processing, too!
let transformed_control_value = core.mode.control(control_value, target, ())?;
let res =
core.mode
.control_with_options(control_value, target, (), ModeControlOptions::default())?;
let transformed_control_value: Option<ControlValue> = res.into();
let transformed_control_value = transformed_control_value?;
if core.options.feedback_send_behavior == FeedbackSendBehavior::PreventEchoFeedback {
core.time_of_last_control = Some(Instant::now());
}
Expand Down
7 changes: 5 additions & 2 deletions main/src/domain/real_time_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,11 +1235,14 @@ fn process_real_mapping(
mapping.resolved_target.as_ref()
{
// Must be processed here in real-time processor.
let v = mapping
let control_value: Option<ControlValue> = mapping
.core
.mode
.control(value, reaper_target, ())
.control_with_options(value, reaper_target, (), options.mode_control_options)
.ok_or("mode didn't return control value")?
.into();
let v = control_value
.ok_or("target already has desired value")?
.as_unit_value()?;
match reaper_target {
RealTimeReaperTarget::SendMidi(t) => {
Expand Down

0 comments on commit 3bf63a5

Please sign in to comment.