Skip to content

Commit

Permalink
#330 Introduce "None" source for group interaction "follow-only" mapp…
Browse files Browse the repository at this point in the history
…ings
  • Loading branch information
helgoboss committed May 18, 2021
1 parent 935c3fc commit ef57c90
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
19 changes: 19 additions & 0 deletions main/src/application/source_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ impl SourceModel {
Midi => self.midi_source_type.get().supports_control(),
Osc => true,
Virtual => true,
// Main use case: Group interaction (follow-only).
Never => true,
}
}

Expand All @@ -105,6 +107,7 @@ impl SourceModel {
Midi => self.midi_source_type.get().supports_feedback(),
Osc => true,
Virtual => true,
Never => false,
}
}

Expand Down Expand Up @@ -183,6 +186,9 @@ impl SourceModel {
.unwrap_or_default(),
);
}
Never => {
self.category.set(SourceCategory::Never);
}
};
}

Expand Down Expand Up @@ -215,6 +221,14 @@ impl SourceModel {
DetailedSourceCharacter::PressOnlyButton,
],
},
// Can be anything, depending on the mapping that uses the group interaction.
CompoundMappingSource::Never => vec![
DetailedSourceCharacter::MomentaryVelocitySensitiveButton,
DetailedSourceCharacter::MomentaryOnOffButton,
DetailedSourceCharacter::PressOnlyButton,
DetailedSourceCharacter::RangeControl,
DetailedSourceCharacter::Relative,
],
}
}

Expand Down Expand Up @@ -291,6 +305,7 @@ impl SourceModel {
);
CompoundMappingSource::Osc(osc_source)
}
Never => CompoundMappingSource::Never,
}
}

Expand Down Expand Up @@ -507,6 +522,7 @@ impl Display for SourceModel {
self.create_control_element().to_string().into(),
],
Osc => vec!["OSC".into(), self.osc_address_pattern.get_ref().into()],
Never => vec!["None".into()],
};
let non_empty_lines: Vec<_> = lines.into_iter().filter(|l| !l.is_empty()).collect();
write!(f, "{}", non_empty_lines.join("\n"))
Expand All @@ -528,6 +544,9 @@ impl Display for SourceModel {
)]
#[repr(usize)]
pub enum SourceCategory {
#[serde(rename = "never")]
#[display(fmt = "None")]
Never,
#[serde(rename = "midi")]
#[display(fmt = "MIDI")]
Midi,
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/eventing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl RealSource {
match s {
Midi(s) => Some(Self::Midi(s)),
Osc(s) => Some(Self::Osc(s)),
Virtual(_) => None,
Virtual(_) | Never => None,
}
}

Expand Down
2 changes: 0 additions & 2 deletions main/src/domain/main_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1918,8 +1918,6 @@ impl<EH: DomainEventHandler> Basics<EH> {
);
}
SameTargetValue | InverseTargetValue => {
// TODO-high Add None sources (good for group-interaction-follow-only mappings)
// and None targets (good for group-interaction-lead-only mappings)
if !control_was_successful {
return;
}
Expand Down
16 changes: 12 additions & 4 deletions main/src/domain/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ use derive_more::Display;
use enum_iterator::IntoEnumIterator;
use enum_map::Enum;
use helgoboss_learn::{
ControlType, ControlValue, GroupInteraction, MidiSourceValue, ModeControlOptions,
ModeControlResult, OscSource, RawMidiEvent, SourceCharacter, Target, UnitValue,
format_percentage_without_unit, parse_percentage_without_unit, ControlType, ControlValue,
GroupInteraction, MidiSourceValue, ModeControlOptions, ModeControlResult, OscSource,
RawMidiEvent, SourceCharacter, Target, UnitValue,
};
use helgoboss_midi::{RawShortMessage, ShortMessage};
use num_enum::{IntoPrimitive, TryFromPrimitive};
Expand All @@ -20,6 +21,7 @@ use reaper_high::{ChangeEvent, Fx, Project, Track, TrackRoute};
use rosc::OscMessage;
use serde::{Deserialize, Serialize};
use smallvec::alloc::fmt::Formatter;
use std::convert::TryInto;
use std::fmt;
use std::fmt::Display;
use std::ops::Range;
Expand Down Expand Up @@ -389,7 +391,7 @@ impl MainMapping {
CompoundMappingSource::Osc(self_source) => {
matches!(source, RealSource::Osc(s) if s == self_source)
}
CompoundMappingSource::Virtual(_) => false,
CompoundMappingSource::Virtual(_) | CompoundMappingSource::Never => false,
}
}

Expand Down Expand Up @@ -860,6 +862,7 @@ impl MappingCore {

#[derive(Clone, Eq, PartialEq, Debug, Hash)]
pub enum CompoundMappingSource {
Never,
Midi(MidiSource),
Osc(OscSource),
Virtual(VirtualSource),
Expand Down Expand Up @@ -892,6 +895,7 @@ impl CompoundMappingSource {
Midi(s) => s.format_control_value(value),
Virtual(s) => s.format_control_value(value),
Osc(s) => s.format_control_value(value),
Never => Ok(format_percentage_without_unit(value.as_absolute()?.get())),
}
}

Expand All @@ -901,6 +905,7 @@ impl CompoundMappingSource {
Midi(s) => s.parse_control_value(text),
Virtual(s) => s.parse_control_value(text),
Osc(s) => s.parse_control_value(text),
Never => parse_percentage_without_unit(text)?.try_into(),
}
}

Expand All @@ -910,6 +915,7 @@ impl CompoundMappingSource {
Midi(s) => ExtendedSourceCharacter::Normal(s.character()),
Virtual(s) => s.character(),
Osc(s) => ExtendedSourceCharacter::Normal(s.character()),
Never => ExtendedSourceCharacter::VirtualContinuous,
}
}

Expand All @@ -920,14 +926,16 @@ impl CompoundMappingSource {
Osc(s) => s.feedback(feedback_value).map(SourceFeedbackValue::Osc),
// This is handled in a special way by consumers.
Virtual(_) => None,
// No feedback for never source.
Never => None,
}
}

pub fn consumes(&self, msg: &impl ShortMessage) -> bool {
use CompoundMappingSource::*;
match self {
Midi(s) => s.consumes(msg),
Virtual(_) | Osc(_) => false,
Virtual(_) | Osc(_) | Never => false,
}
}
}
Expand Down
19 changes: 11 additions & 8 deletions main/src/infrastructure/ui/mapping_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ impl<'a> MutableMappingPanel<'a> {
Osc => {
self.mapping.source_model.osc_arg_is_relative.set(checked);
}
Virtual => {}
Virtual | Never => {}
};
}

Expand Down Expand Up @@ -891,7 +891,7 @@ impl<'a> MutableMappingPanel<'a> {
.osc_arg_type_tag
.set(i.try_into().expect("invalid OSC type tag"));
}
Virtual => {}
Virtual | Never => {}
}
}

Expand Down Expand Up @@ -962,6 +962,7 @@ impl<'a> MutableMappingPanel<'a> {
.control_element_id
.set_with_initiator(text.parse().unwrap_or_default(), Some(edit_control_id));
}
Never => {}
};
}

Expand Down Expand Up @@ -992,7 +993,7 @@ impl<'a> MutableMappingPanel<'a> {
.osc_address_pattern
.set_with_initiator(value, Some(edit_control_id));
}
Virtual => {}
Virtual | Never => {}
}
}
}
Expand Down Expand Up @@ -2326,6 +2327,7 @@ impl<'a> ImmutableMappingPanel<'a> {
),
Virtual => ("", "ID", "", ""),
Osc => ("", "Argument", "Type", "Address"),
Never => ("", "", "", ""),
};
self.view
.require_control(root::ID_SOURCE_CHANNEL_LABEL)
Expand Down Expand Up @@ -2510,7 +2512,7 @@ impl<'a> ImmutableMappingPanel<'a> {
"14-bit values",
),
Osc => (self.source.osc_arg_is_relative.get(), "Is relative"),
Virtual => return,
Virtual | Never => return,
};
let c = self.view.require_control(root::ID_SOURCE_14_BIT_CHECK_BOX);
c.set_text(label);
Expand Down Expand Up @@ -2553,6 +2555,7 @@ impl<'a> ImmutableMappingPanel<'a> {
},
Osc => format_osc_arg_index(self.source.osc_arg_index.get()),
Virtual => self.source.control_element_id.get().to_string(),
Never => return,
};
c.set_text(text)
}
Expand All @@ -2578,7 +2581,7 @@ impl<'a> ImmutableMappingPanel<'a> {
_ => return,
},
Osc => (self.source.osc_address_pattern.get_ref().as_str(), false),
Virtual => return,
Virtual | Never => return,
};
c.set_text(value_text);
c.set_enabled(!read_only);
Expand All @@ -2594,7 +2597,7 @@ impl<'a> ImmutableMappingPanel<'a> {
let (label_text, item_index) = match self.source.category.get() {
Midi => ("Character", self.source.custom_character.get().into()),
Osc => ("Type", self.source.osc_arg_type_tag.get().into()),
Virtual => return,
Virtual | Never => return,
};
self.view
.require_control(root::ID_SOURCE_CHARACTER_LABEL_TEXT)
Expand Down Expand Up @@ -4924,7 +4927,7 @@ impl<'a> ImmutableMappingPanel<'a> {
match self.source.category.get() {
Midi => b.fill_combo_box_indexed(MidiSourceType::into_enum_iter()),
Virtual => b.fill_combo_box_indexed(VirtualControlElementType::into_enum_iter()),
Osc => {}
Osc | Never => {}
};
}

Expand Down Expand Up @@ -4963,7 +4966,7 @@ impl<'a> ImmutableMappingPanel<'a> {
Osc => {
combo.fill_combo_box_indexed(OscTypeTag::into_enum_iter());
}
Virtual => {}
Virtual | Never => {}
}
}

Expand Down

0 comments on commit ef57c90

Please sign in to comment.