Skip to content

Commit

Permalink
Use reaper-common-types instead of defining our own
Browse files Browse the repository at this point in the history
  • Loading branch information
helgoboss committed Feb 20, 2024
1 parent 1cc375d commit b44e02e
Show file tree
Hide file tree
Showing 23 changed files with 137 additions and 247 deletions.
76 changes: 73 additions & 3 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ members = [
base = { path = "base" }
pot = { path = "pot" }
pot-browser = { path = "pot-browser" }
reaper-common-types = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master" }
reaper-rx = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master" }
reaper-fluent = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master" }
reaper-high = { git = "https://github.com/helgoboss/reaper-rs.git", branch = "master", features = ["serde"] }
Expand Down Expand Up @@ -155,6 +156,7 @@ vst = { git = "https://github.com/helgoboss/vst-rs.git", branch = "feature/param

# This is for temporary development with local reaper-rs.
[patch.'https://github.com/helgoboss/reaper-rs.git']
reaper-common-types = { path = "../reaper-rs/main/common-types" }
reaper-fluent = { path = "../reaper-rs/main/fluent" }
reaper-high = { path = "../reaper-rs/main/high" }
reaper-medium = { path = "../reaper-rs/main/medium" }
Expand Down
1 change: 1 addition & 0 deletions main/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ base.workspace = true
reaper-rx.workspace = true
reaper-high.workspace = true
reaper-medium.workspace = true
reaper-common-types = { workspace = true, features = ["color-macros", "palette"] }
reaper-low.workspace = true
reaper-macros.workspace = true
swell-ui.workspace = true
Expand Down
2 changes: 1 addition & 1 deletion main/lib/helgoboss-learn
4 changes: 2 additions & 2 deletions main/src/domain/midi_clock_calculator.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::base::MovingAverageCalculator;
use helgoboss_learn::Bpm;

use crate::domain::SampleOffset;
use reaper_common_types::Bpm;
use reaper_medium::Hz;
use std::convert::TryInto;

Expand All @@ -16,7 +16,7 @@ pub struct MidiClockCalculator {
impl Default for MidiClockCalculator {
fn default() -> Self {
Self {
sample_rate: Hz::new(1.0),
sample_rate: Hz::new_panic(1.0),
sample_counter: 0,
previous_midi_clock_timestamp_in_samples: 0,
bpm_calculator: Default::default(),
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 @@ -96,7 +96,7 @@ impl RealTimeProcessor {
midi_clock_calculator: Default::default(),
control_is_globally_enabled: false,
feedback_is_globally_enabled: false,
sample_rate: Hz::new(1.0),
sample_rate: Hz::new_panic(1.0),
}
}

Expand Down
10 changes: 3 additions & 7 deletions main/src/domain/targets/playtime_slot_volume_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ mod playtime_impl {
rt::{ClipChangeEvent, QualifiedClipChangeEvent},
};
use reaper_high::SliderVolume;
use reaper_medium::Db;
use std::borrow::Cow;

impl RealearnTarget for PlaytimeSlotVolumeTarget {
Expand Down Expand Up @@ -109,12 +108,11 @@ mod playtime_impl {
SliderVolume::try_from_normalized_slider_value(value.to_unit_value()?.get())
.unwrap_or_default();
let db = volume.db();
let api_db = playtime_api::persistence::Db::new(db.get())?;
Backbone::get()
.with_clip_matrix_mut(
context.control_context.instance(),
|matrix| -> anyhow::Result<HitResponse> {
matrix.set_slot_volume(self.slot_coordinates, api_db)?;
matrix.set_slot_volume(self.slot_coordinates, db)?;
Ok(HitResponse::processed_with_effect())
},
)
Expand All @@ -141,9 +139,7 @@ mod playtime_impl {
},
)) if clip_address.slot_address == self.slot_coordinates => (
true,
Some(AbsoluteValue::Continuous(db_unit_value(Db::new(
new_value.get(),
)))),
Some(AbsoluteValue::Continuous(db_unit_value(*new_value))),
),
_ => (false, None),
}
Expand All @@ -167,7 +163,7 @@ mod playtime_impl {
Backbone::get()
.with_clip_matrix(context.instance(), |matrix| {
let db = matrix.find_slot(self.slot_coordinates)?.volume().ok()?;
Some(SliderVolume::from_db(Db::new(db.get())))
Some(SliderVolume::from_db(db))
})
.ok()?
}
Expand Down
14 changes: 5 additions & 9 deletions main/src/domain/targets/seek_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ impl RealearnTarget for SeekTarget {
let value = value.to_unit_value()?;
let info = get_seek_info(self.project, self.options, false);
let desired_pos_within_range = value.get() * info.length();
let desired_pos = info.start_pos.get() + desired_pos_within_range;
let desired_pos = info.start_pos + desired_pos_within_range;
with_seek_behavior(self.behavior, || {
self.project.set_edit_cursor_position(
PositionInSeconds::new(desired_pos),
desired_pos,
SetEditCurPosOptions {
move_view: self.options.move_view,
seek_play: self.options.seek_play,
Expand Down Expand Up @@ -330,17 +330,13 @@ fn get_seek_info(project: Project, options: SeekOptions, ignore_project_length:
if ignore_project_length {
return SeekInfo::new(
SeekContext::Project,
PositionInSeconds::new(0.0),
PositionInSeconds::new(f64::MAX),
PositionInSeconds::ZERO,
PositionInSeconds::new_panic(f64::MAX),
);
} else {
let length = project.length();
if length.get() > 0.0 {
return SeekInfo::new(
SeekContext::Project,
PositionInSeconds::new(0.0),
PositionInSeconds::new(length.get()),
);
return SeekInfo::new(SeekContext::Project, PositionInSeconds::ZERO, length.into());
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion main/src/domain/targets/track_peak_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl TrackPeakTarget {
}
let sum: f64 = peaks.map(|v| v.get()).sum();
let avg = sum / channel_count as f64;
let vol = ReaperVolumeValue::new(avg);
let vol = ReaperVolumeValue::new_panic(avg);
Some(SliderVolume::from_reaper_value(vol))
}
}
Expand Down
2 changes: 1 addition & 1 deletion main/src/infrastructure/plugin/helgobox_plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ impl Plugin for HelgoboxPlugin {
fn set_sample_rate(&mut self, rate: f32) {
firewall(|| {
tracing::debug!("VST set sample rate");
self.sample_rate = Hz::new(rate as _);
self.sample_rate = Hz::new_panic(rate as _);
if let Some(lazy_data) = self.lazy_data.get() {
lazy_data.instance_shell.set_sample_rate(rate);
}
Expand Down
4 changes: 3 additions & 1 deletion main/src/infrastructure/plugin/unit_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,9 @@ impl UnitShell {
// If task queue is full or audio not running, so what. Don't spam the user with error
// messages.
self.normal_real_time_task_sender
.send_if_space(NormalRealTimeTask::UpdateSampleRate(Hz::new(rate as _)));
.send_if_space(NormalRealTimeTask::UpdateSampleRate(Hz::new_panic(
rate as _,
)));
}
}

Expand Down
16 changes: 8 additions & 8 deletions main/src/infrastructure/proto/playtime_request_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ impl PlaytimeProtoRequestHandler {
}

pub fn set_matrix_tempo(&self, req: SetMatrixTempoRequest) -> Result<Response<Empty>, Status> {
let bpm = Bpm::try_from(req.bpm).map_err(|e| Status::invalid_argument(e.as_ref()))?;
let bpm = Bpm::try_from(req.bpm).map_err(|e| Status::invalid_argument(e.to_string()))?;
self.handle_matrix_command(&req.matrix_id, |matrix| {
matrix.set_tempo(bpm);
Ok(())
Expand All @@ -453,11 +453,11 @@ impl PlaytimeProtoRequestHandler {
&self,
req: SetMatrixVolumeRequest,
) -> Result<Response<Empty>, Status> {
let db = Db::try_from(req.db).map_err(|e| Status::invalid_argument(e.as_ref()))?;
let db = Db::try_from(req.db).map_err(|e| Status::invalid_argument(e.to_string()))?;
self.handle_matrix_command(&req.matrix_id, |matrix| {
let project = matrix.permanent_project().or_current_project();
project.master_track()?.set_volume(
db.to_reaper_volume_value(),
db.to_linear_volume_value(),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
);
Expand All @@ -466,8 +466,8 @@ impl PlaytimeProtoRequestHandler {
}

pub fn set_matrix_pan(&self, req: SetMatrixPanRequest) -> Result<Response<Empty>, Status> {
let pan =
ReaperPanValue::try_from(req.pan).map_err(|e| Status::invalid_argument(e.as_ref()))?;
let pan = ReaperPanValue::try_from(req.pan)
.map_err(|e| Status::invalid_argument(e.to_string()))?;
self.handle_matrix_command(&req.matrix_id, |matrix| {
let project = matrix.permanent_project().or_current_project();
project.master_track()?.set_pan(
Expand All @@ -480,10 +480,10 @@ impl PlaytimeProtoRequestHandler {
}

pub fn set_track_volume(&self, req: SetTrackVolumeRequest) -> Result<Response<Empty>, Status> {
let db = Db::try_from(req.db).map_err(|e| Status::invalid_argument(e.as_ref()))?;
let db = Db::try_from(req.db).map_err(|e| Status::invalid_argument(e.to_string()))?;
self.handle_track_command(&req.track_address, |_matrix, track| {
track.set_volume(
db.to_reaper_volume_value(),
db.to_linear_volume_value(),
GangBehavior::DenyGang,
GroupingBehavior::PreventGrouping,
);
Expand All @@ -492,7 +492,7 @@ impl PlaytimeProtoRequestHandler {
}

pub fn set_track_pan(&self, req: SetTrackPanRequest) -> Result<Response<Empty>, Status> {
let pan = ReaperPanValue::new(req.pan.clamp(-1.0, 1.0));
let pan = ReaperPanValue::new_panic(req.pan.clamp(-1.0, 1.0));
self.handle_track_command(&req.track_address, |_matrix, track| {
track.set_pan(
Pan::from_reaper_value(pan),
Expand Down
Loading

0 comments on commit b44e02e

Please sign in to comment.