Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Oct 19, 2024
1 parent 6596977 commit e7f7e0a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
11 changes: 10 additions & 1 deletion src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,9 @@ impl DelayGraph {
Self {
delay_data: delay_data.get(cx),
}
.build(cx, |_cx| ())
.build(cx, |_cx| {
// put other widgets here
})
}
}

Expand Down Expand Up @@ -434,6 +436,13 @@ impl DelayGraph {

canvas.stroke_path(&path, &vg::Paint::color(color).with_line_width(line_width));
}
// TODO: .overflow(Overflow::Visible);

fn u8_note_to_name(note_nr: u8) -> String {
let note_name = util::NOTES[(note_nr % 12) as usize];
let octave = (note_nr / 12) - 1;
format!("{note_name}{octave}")
}

fn draw_bounding_outline(
&self,
Expand Down
47 changes: 20 additions & 27 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,18 +539,17 @@ impl Plugin for Del2 {
}

impl Del2 {
// #[inline]
fn update_timing_params(&mut self) {
self.delay_data.max_tap_samples = (self.sample_rate as f32
* self.params.global.timing_params.max_tap_seconds.value() as f32)
as u32;
self.min_tap_samples = (self.sample_rate as f32
let sample_rate = self.sample_rate as f32;
self.delay_data.max_tap_samples =
(sample_rate * self.params.global.timing_params.max_tap_seconds.value()) as u32;
self.min_tap_samples = (sample_rate
* self
.params
.global
.timing_params
.min_tap_milliseconds
.value() as f32
.value()
* 0.001) as u32;
}

Expand Down Expand Up @@ -689,27 +688,24 @@ impl Del2 {
let filter_params = Arc::get_mut_unchecked(&mut self.filter_params[tap]);

// Cache repeated calculations
let low_velocity = &velocity_params.velocity_low;
let high_velocity = &velocity_params.velocity_high;
let low_params = &velocity_params.velocity_low;
let high_params = &velocity_params.velocity_high;

let low_res = low_velocity.res.value();
let high_res = high_velocity.res.value();
let res = Del2::lerp(low_res, high_res, velocity);

let low_cutoff = low_velocity.cutoff.value();
let high_cutoff = high_velocity.cutoff.value();
let cutoff = Del2::log_interpolate(low_cutoff, high_cutoff, velocity);

let low_drive_db = util::gain_to_db(low_velocity.drive.value());
let high_drive_db = util::gain_to_db(high_velocity.drive.value());
let drive_db = Del2::lerp(low_drive_db, high_drive_db, velocity);
let res = Del2::lerp(low_params.res.value(), high_params.res.value(), velocity);
let cutoff = Del2::log_interpolate(
low_params.cutoff.value(),
high_params.cutoff.value(),
velocity,
);
let drive_db = Del2::lerp(
util::gain_to_db(low_params.drive.value()),
util::gain_to_db(high_params.drive.value()),
velocity,
);
let drive = util::db_to_gain(drive_db);
let mode =
MyLadderMode::lerp(low_params.mode.value(), high_params.mode.value(), velocity);

let low_mode = low_velocity.mode.value();
let high_mode = high_velocity.mode.value();
let mode = MyLadderMode::lerp(low_mode, high_mode, velocity);
// println!("mode {}: {}", tap, mode);
// Updating filter parameters
filter_params.set_resonance(res);
filter_params.set_frequency(cutoff);
filter_params.drive = drive;
Expand Down Expand Up @@ -751,7 +747,6 @@ impl Del2 {
}
}

// #[inline]
fn process_tap(&mut self, block_len: usize, tap: usize, out_l: &mut [f32], out_r: &mut [f32]) {
let delay_time = self.delay_data.delay_times[tap] as isize;
// delay_time - 1 because we are processing 2 samples at once in process_audio
Expand Down Expand Up @@ -843,7 +838,6 @@ impl Del2 {
}
}

// #[inline]
fn make_stereo_frame(&self, index: usize) -> f32x4 {
f32x4::from_array([
self.temp_l[index],
Expand All @@ -853,7 +847,6 @@ impl Del2 {
])
}

// #[inline]
fn accumulate_processed_results(
i: usize,
block_len: usize,
Expand Down

0 comments on commit e7f7e0a

Please sign in to comment.