Skip to content

Commit

Permalink
#184 Introduce fraction control value WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed May 18, 2021
1 parent 5bd2663 commit 5cb330d
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 20 deletions.
5 changes: 0 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@ generate = []
prometheus = ["serde_prometheus"]

[dependencies]
reaper-rx = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master" }
reaper-high = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master", features = ["serde"] }
reaper-medium = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master", features = ["serde"] }
reaper-low = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master" }
#reaper-rx = { path = "../../reaper-rs/main/rx" }
#reaper-high = { path = "../../reaper-rs/main/high", features = ["serde"] }
#reaper-medium= { path = "../../reaper-rs/main/medium", features = ["serde"] }
#reaper-low = { path = "../../reaper-rs/main/low" }
#reaper-rx = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master" }
#reaper-high = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master", features = ["serde"] }
#reaper-medium = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master", features = ["serde"] }
#reaper-low = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master" }
reaper-rx = { path = "../../reaper-rs/main/rx" }
reaper-high = { path = "../../reaper-rs/main/high", features = ["serde"] }
reaper-medium= { path = "../../reaper-rs/main/medium", features = ["serde"] }
reaper-low = { path = "../../reaper-rs/main/low" }
swell-ui = { path = "../swell-ui" }
rx-util = { path = "../rx-util" }
helgoboss-midi = { version = "0.2", features = ["serde", "serde_repr"] }
Expand Down
2 changes: 1 addition & 1 deletion main/lib/helgoboss-learn
39 changes: 35 additions & 4 deletions main/src/domain/targets/action_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use crate::domain::ui_util::convert_bool_to_unit_value;
use crate::domain::{
ActionInvocationType, AdditionalFeedbackEvent, ControlContext, RealearnTarget, TargetCharacter,
};
use helgoboss_learn::{ControlType, ControlValue, Target, UnitValue};
use helgoboss_learn::{ControlType, ControlValue, Fraction, Target, UnitValue};
use helgoboss_midi::U14;
use reaper_high::{Action, ActionCharacter, Project, Reaper};
use reaper_medium::CommandId;
use reaper_medium::{ActionValueChange, CommandId, WindowContext};
use std::convert::TryFrom;

#[derive(Clone, Debug, PartialEq)]
pub struct ActionTarget {
Expand Down Expand Up @@ -49,11 +51,11 @@ impl RealearnTarget for ActionTarget {
ControlValue::Absolute(v) => match self.invocation_type {
ActionInvocationType::Trigger => {
if !v.is_zero() {
self.action.invoke(v.get(), false, Some(self.project));
self.invoke_with_unit_value(v);
}
}
ActionInvocationType::Absolute => {
self.action.invoke(v.get(), false, Some(self.project))
self.invoke_with_unit_value(v);
}
ActionInvocationType::Relative => {
return Err("relative invocation type can't take absolute values");
Expand All @@ -66,6 +68,17 @@ impl RealearnTarget for ActionTarget {
return Err("relative values need relative invocation type");
}
}
ControlValue::AbsoluteDiscrete(f) => match self.invocation_type {
ActionInvocationType::Trigger => {
if !f.is_zero() {
self.invoke_with_fraction(f)
}
}
ActionInvocationType::Absolute => self.invoke_with_fraction(f),
ActionInvocationType::Relative => {
return Err("relative invocation type can't take absolute values");
}
},
};
Ok(())
}
Expand Down Expand Up @@ -114,3 +127,21 @@ impl<'a> Target<'a> for ActionTarget {
self.control_type_and_character().0
}
}

impl ActionTarget {
fn invoke_with_fraction(&self, f: Fraction) {
if let Ok(u14) = U14::try_from(f.actual()) {
self.action.invoke_directly(
ActionValueChange::AbsoluteHighRes(u14),
WindowContext::Win(Reaper::get().main_window()),
self.project.context(),
);
}
}
}

impl ActionTarget {
fn invoke_with_unit_value(&self, v: UnitValue) {
self.action.invoke(v.get(), false, Some(self.project))
}
}
4 changes: 2 additions & 2 deletions swell-ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ authors = ["Benjamin Klum <[email protected]>"]
edition = "2018"

[dependencies]
reaper-low = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master" }
#reaper-low = { path = "../../reaper-rs/main/low" }
# reaper-low = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master" }
reaper-low = { path = "../../reaper-rs/main/low" }
rxrust = { git = "https://github.com/rxRust/rxRust", branch = "master" }
rx-util = { path = "../rx-util" }
scopeguard = "1.1.0"
Expand Down

0 comments on commit 5cb330d

Please sign in to comment.