Skip to content

Commit

Permalink
#184 Add Discrete mode
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed May 20, 2021
1 parent 19a27d0 commit e400d90
Show file tree
Hide file tree
Showing 40 changed files with 47 additions and 44 deletions.
2 changes: 1 addition & 1 deletion main/src/application/mapping_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ impl<'a> MappingModelWithContext<'a> {
Normal(MomentaryButton) | Normal(ToggleButton) => {
let target = self.target_with_context().resolve_first()?;
match mode_type {
AbsoluteMode::Normal | AbsoluteMode::ToggleButtons => {
AbsoluteMode::Normal | AbsoluteMode::Discrete | AbsoluteMode::ToggleButtons => {
!target.control_type().is_relative()
}
AbsoluteMode::IncrementalButtons => {
Expand Down
6 changes: 3 additions & 3 deletions main/src/domain/main_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ impl<EH: DomainEventHandler> MainProcessor<EH> {
// Control value is not important because we only do target-value
// based group interaction after polling (makes sense because control-value
// based one has been done at control time already.
ControlValue::Absolute(Default::default()),
ControlValue::AbsoluteContinuous(Default::default()),
// We already know that control was successful (checked above).
true,
);
Expand Down Expand Up @@ -1946,7 +1946,7 @@ impl<EH: DomainEventHandler> Basics<EH> {
&other_mapping.mode().target_value_interval,
);
other_mapping.control_from_target(
ControlValue::Absolute(scaled_interaction_value),
ControlValue::AbsoluteContinuous(scaled_interaction_value),
ControlOptions::default(),
basics.control_context(),
&basics.logger,
Expand Down Expand Up @@ -2113,7 +2113,7 @@ impl<EH: DomainEventHandler> Basics<EH> {
with_source_feedback,
value,
} => {
if let ControlValue::Absolute(v) = value.control_value() {
if let ControlValue::AbsoluteContinuous(v) = value.control_value() {
for m in mappings_with_virtual_targets
.values()
.filter(|m| m.feedback_is_effectively_on())
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/mapping.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,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())),
Never => Ok(format_percentage_without_unit(value.as_unit_value()?.get())),
}
}

Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/real_time_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1240,7 +1240,7 @@ fn process_real_mapping(
.mode
.control(value, reaper_target, ())
.ok_or("mode didn't return control value")?
.as_absolute()?;
.as_unit_value()?;
match reaper_target {
RealTimeReaperTarget::SendMidi(t) => {
// This is a type of mapping that we should process right here because we want to
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/action_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ impl RealearnTarget for ActionTarget {

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
match value {
ControlValue::Absolute(v) => match self.invocation_type {
ControlValue::AbsoluteContinuous(v) => match self.invocation_type {
ActionInvocationType::Trigger => {
if !v.is_zero() {
self.invoke_with_unit_value(v);
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/all_track_fx_enable_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl RealearnTarget for AllTrackFxEnableTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
if value.as_absolute()?.is_zero() {
if value.as_unit_value()?.is_zero() {
handle_track_exclusivity(&self.track, self.exclusivity, |t| t.enable_fx());
self.track.disable_fx();
} else {
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/automation_mode_override_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl RealearnTarget for AutomationModeOverrideTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
if value.as_absolute()?.is_zero() {
if value.as_unit_value()?.is_zero() {
Reaper::get().set_global_automation_override(None);
} else {
Reaper::get().set_global_automation_override(self.mode_override);
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/automation_touch_state_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ impl RealearnTarget for AutomationTouchStateTarget {

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
let mut ctx = BackboneState::target_context().borrow_mut();
if value.as_absolute()?.is_zero() {
if value.as_unit_value()?.is_zero() {
handle_track_exclusivity(&self.track, self.exclusivity, |t| {
ctx.touch_automation_parameter(t.raw(), self.parameter_type)
});
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/clip_seek_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ impl RealearnTarget for ClipSeekTarget {
}

fn control(&self, value: ControlValue, context: ControlContext) -> Result<(), &'static str> {
let value = value.as_absolute()?;
let value = value.as_unit_value()?;
let mut instance_state = context.instance_state.borrow_mut();
instance_state.seek_slot(self.slot_index, value)?;
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/clip_transport_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ impl RealearnTarget for ClipTransportTarget {

fn control(&self, value: ControlValue, context: ControlContext) -> Result<(), &'static str> {
use TransportAction::*;
let on = !value.as_absolute()?.is_zero();
let on = !value.as_unit_value()?.is_zero();
let mut instance_state = context.instance_state.borrow_mut();
match self.action {
PlayStop => {
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/clip_volume_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ impl RealearnTarget for ClipVolumeTarget {
}

fn control(&self, value: ControlValue, context: ControlContext) -> Result<(), &'static str> {
let volume = Volume::try_from_soft_normalized_value(value.as_absolute()?.get());
let volume = Volume::try_from_soft_normalized_value(value.as_unit_value()?.get());
let mut instance_state = context.instance_state.borrow_mut();
instance_state.set_volume(
self.slot_index,
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/fx_enable_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl RealearnTarget for FxEnableTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
if value.as_absolute()?.is_zero() {
if value.as_unit_value()?.is_zero() {
self.fx.disable();
} else {
self.fx.enable();
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/fx_navigate_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl RealearnTarget for FxNavigateTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
let fx_index = convert_unit_value_to_fx_index(&self.fx_chain, value.as_absolute()?);
let fx_index = convert_unit_value_to_fx_index(&self.fx_chain, value.as_unit_value()?);
use FxDisplayType::*;
match fx_index {
None => match self.display_type {
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/fx_open_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ impl RealearnTarget for FxOpenTarget {

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
use FxDisplayType::*;
if value.as_absolute()?.is_zero() {
if value.as_unit_value()?.is_zero() {
match self.display_type {
FloatingWindow => {
self.fx.hide_floating_window();
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/fx_parameter_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ impl RealearnTarget for FxParameterTarget {
fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
// It's okay to just convert this to a REAPER-normalized value. We don't support
// values above the maximum (or buggy plug-ins).
let v = ReaperNormalizedFxParamValue::new(value.as_absolute()?.get());
let v = ReaperNormalizedFxParamValue::new(value.as_unit_value()?.get());
self.param
.set_reaper_normalized_value(v)
.map_err(|_| "couldn't set FX parameter value")?;
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/fx_preset_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl RealearnTarget for FxPresetTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
let preset_index = convert_unit_value_to_preset_index(&self.fx, value.as_absolute()?);
let preset_index = convert_unit_value_to_preset_index(&self.fx, value.as_unit_value()?);
let preset_ref = match preset_index {
None => FxPresetRef::FactoryPreset,
Some(i) => FxPresetRef::Preset(i),
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/go_to_bookmark_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl RealearnTarget for GoToBookmarkTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
if !value.as_absolute()?.is_zero() {
if !value.as_unit_value()?.is_zero() {
match self.bookmark_type {
BookmarkType::Marker => self
.project
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/load_fx_snapshot_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl RealearnTarget for LoadFxSnapshotTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
if !value.as_absolute()?.is_zero() {
if !value.as_unit_value()?.is_zero() {
BackboneState::target_context()
.borrow_mut()
.load_fx_snapshot(self.fx.clone(), &self.chunk, self.chunk_hash)?
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/midi_send_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ impl RealearnTarget for MidiSendTarget {
fn control(&self, value: ControlValue, context: ControlContext) -> Result<(), &'static str> {
// We arrive here only if controlled via OSC. Sending MIDI in response to incoming
// MIDI messages is handled directly in the real-time processor.
let raw_midi_event = self.pattern.to_concrete_midi_event(value.as_absolute()?);
let raw_midi_event = self.pattern.to_concrete_midi_event(value.as_unit_value()?);
match self.destination {
SendMidiDestination::FxOutput => Err("OSC => MIDI FX output not supported"),
SendMidiDestination::FeedbackOutput => {
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/osc_send_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl RealearnTarget for OscSendTarget {
let msg = OscMessage {
addr: self.address_pattern.clone(),
args: if let Some(desc) = self.arg_descriptor {
desc.to_concrete_args(value.as_absolute()?)
desc.to_concrete_args(value.as_unit_value()?)
.ok_or("sending of this OSC type not supported")?
} else {
vec![]
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/playrate_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl RealearnTarget for PlayrateTarget {

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
let play_rate =
PlayRate::from_normalized_value(NormalizedPlayRate::new(value.as_absolute()?.get()));
PlayRate::from_normalized_value(NormalizedPlayRate::new(value.as_unit_value()?.get()));
self.project.set_play_rate(play_rate);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/route_mute_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ impl RealearnTarget for RouteMuteTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
if value.as_absolute()?.is_zero() {
if value.as_unit_value()?.is_zero() {
self.route.unmute();
} else {
self.route.mute();
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/route_pan_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ impl RealearnTarget for RoutePanTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
let pan = Pan::from_normalized_value(value.as_absolute()?.get());
let pan = Pan::from_normalized_value(value.as_unit_value()?.get());
self.route
.set_pan(pan)
.map_err(|_| "couldn't set route pan")?;
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/route_volume_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl RealearnTarget for RouteVolumeTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
let volume = Volume::try_from_soft_normalized_value(value.as_absolute()?.get());
let volume = Volume::try_from_soft_normalized_value(value.as_unit_value()?.get());
self.route
.set_volume(volume.unwrap_or(Volume::MIN))
.map_err(|_| "couldn't set route volume")?;
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/seek_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ impl RealearnTarget for SeekTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
let value = value.as_absolute()?;
let value = value.as_unit_value()?;
let info = get_seek_info(self.project, self.options);
let desired_pos_within_range = value.get() * info.length();
let desired_pos = info.start_pos.get() + desired_pos_within_range;
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/selected_track_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ impl RealearnTarget for SelectedTrackTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
let track_index = convert_unit_value_to_track_index(self.project, value.as_absolute()?);
let track_index = convert_unit_value_to_track_index(self.project, value.as_unit_value()?);
let track = match track_index {
None => self.project.master_track(),
Some(i) => self
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/tempo_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ impl RealearnTarget for TempoTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
let tempo = reaper_high::Tempo::from_normalized_value(value.as_absolute()?.get());
let tempo = reaper_high::Tempo::from_normalized_value(value.as_unit_value()?.get());
self.project.set_tempo(tempo, UndoBehavior::OmitUndoPoint);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/track_arm_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl RealearnTarget for TrackArmTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
if value.as_absolute()?.is_zero() {
if value.as_unit_value()?.is_zero() {
handle_track_exclusivity(&self.track, self.exclusivity, |t| t.arm(false));
self.track.disarm(false);
} else {
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/track_automation_mode_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ impl RealearnTarget for TrackAutomationModeTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
if value.as_absolute()?.is_zero() {
if value.as_unit_value()?.is_zero() {
handle_track_exclusivity(&self.track, self.exclusivity, |t| {
t.set_automation_mode(self.mode)
});
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/track_mute_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ impl RealearnTarget for TrackMuteTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
if value.as_absolute()?.is_zero() {
if value.as_unit_value()?.is_zero() {
handle_track_exclusivity(&self.track, self.exclusivity, |t| t.mute());
self.track.unmute();
} else {
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/track_pan_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ impl RealearnTarget for TrackPanTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
let pan = Pan::from_normalized_value(value.as_absolute()?.get());
let pan = Pan::from_normalized_value(value.as_unit_value()?.get());
self.track.set_pan(pan);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/track_selection_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl RealearnTarget for TrackSelectionTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
if value.as_absolute()?.is_zero() {
if value.as_unit_value()?.is_zero() {
handle_track_exclusivity(&self.track, self.exclusivity, |t| t.select());
self.track.unselect();
} else if self.exclusivity == TrackExclusivity::ExclusiveAll {
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/track_show_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ impl RealearnTarget for TrackShowTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
if value.as_absolute()?.is_zero() {
if value.as_unit_value()?.is_zero() {
handle_track_exclusivity(&self.track, self.exclusivity, |t| {
t.set_shown(self.area, true)
});
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/track_solo_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl RealearnTarget for TrackSoloTarget {
ReaperPreference => t.solo(),
}
};
if value.as_absolute()?.is_zero() {
if value.as_unit_value()?.is_zero() {
handle_track_exclusivity(&self.track, self.exclusivity, solo_track);
self.track.unsolo();
} else {
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/track_volume_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ impl RealearnTarget for TrackVolumeTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
let volume = Volume::try_from_soft_normalized_value(value.as_absolute()?.get());
let volume = Volume::try_from_soft_normalized_value(value.as_unit_value()?.get());
self.track.set_volume(volume.unwrap_or(Volume::MIN));
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/track_width_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl RealearnTarget for TrackWidthTarget {
}

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
let width = Width::from_normalized_value(value.as_absolute()?.get());
let width = Width::from_normalized_value(value.as_unit_value()?.get());
self.track.set_width(width);
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/transport_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ impl RealearnTarget for TransportTarget {

fn control(&self, value: ControlValue, _: ControlContext) -> Result<(), &'static str> {
use TransportAction::*;
let on = !value.as_absolute()?.is_zero();
let on = !value.as_unit_value()?.is_zero();
match self.action {
PlayStop => {
if on {
Expand Down
7 changes: 5 additions & 2 deletions main/src/domain/virtual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,14 @@ impl VirtualSource {
}

pub fn feedback(&self, feedback_value: UnitValue) -> VirtualSourceValue {
VirtualSourceValue::new(self.control_element, ControlValue::Absolute(feedback_value))
VirtualSourceValue::new(
self.control_element,
ControlValue::AbsoluteContinuous(feedback_value),
)
}

pub fn format_control_value(&self, value: ControlValue) -> Result<String, &'static str> {
let absolute_value = value.as_absolute()?;
let absolute_value = value.as_unit_value()?;
Ok(format_as_percentage_without_unit(absolute_value))
}

Expand Down
4 changes: 2 additions & 2 deletions main/src/infrastructure/ui/mapping_panel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4253,7 +4253,7 @@ impl<'a> ImmutableMappingPanel<'a> {
) {
let formatted_value = self
.source
.format_control_value(ControlValue::Absolute(value))
.format_control_value(ControlValue::AbsoluteContinuous(value))
.unwrap_or_else(|_| "".to_string());
if initiator != Some(edit_control_id) {
self.view
Expand Down Expand Up @@ -5430,7 +5430,7 @@ fn update_target_value(
for target in targets {
// If it doesn't work in some cases, so what.
let res = target.control(
ControlValue::Absolute(value),
ControlValue::AbsoluteContinuous(value),
create_control_context(
feedback_output,
instance_state,
Expand Down

0 comments on commit e400d90

Please sign in to comment.