Skip to content

Commit

Permalink
fix pan drawing, simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Nov 18, 2024
1 parent bd2d73b commit 22828f1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
5 changes: 3 additions & 2 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ impl DelayGraph {
let available_height = (-(margin + note_size + border_width)).mul_add(2.0, bounds.h);

let get_normalized_value = |value: u8, min: f32, max: f32| -> f32 {
if max == min {
if (max - min).abs() < 0.5 {
value as f32 / 127.0
} else {
(value as f32 - min) / (max - min)
Expand Down Expand Up @@ -832,7 +832,8 @@ impl DelayGraph {
note_path.close();

let pan_value =
(f32::from(note_value - panning_center) * panning_amount).clamp(-1.0, 1.0);
((note_value as f32 - panning_center as f32) * panning_amount).clamp(-1.0, 1.0);

let line_length = if pan_value.abs() > 1.0 / 50.0 {
50.0
} else {
Expand Down
13 changes: 4 additions & 9 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -733,10 +733,8 @@ impl Plugin for Del2 {

for (tap_index, delay_tap) in self.delay_taps.iter_mut().enumerate() {
if let Some(v) = delay_tap.as_mut() {
let note = v.note;

let pan =
((f32::from(note) - panning_center) * panning_amount).clamp(-1.0, 1.0);
((f32::from(v.note) - panning_center) * panning_amount).clamp(-1.0, 1.0);

let (offset_l, offset_r) = Self::pan_to_haas_samples(pan, sample_rate);

Expand Down Expand Up @@ -771,8 +769,7 @@ impl Plugin for Del2 {
v.delayed_audio_l.get(i + 1).copied().unwrap_or(0.0),
v.delayed_audio_r.get(i + 1).copied().unwrap_or(0.0),
]);
let processed = v.ladders.tick_pivotal(frame);
let frame_out = *processed.as_array();
let frame_out = *v.ladders.tick_pivotal(frame).as_array();
v.delayed_audio_l[i] = frame_out[0];
v.delayed_audio_r[i] = frame_out[1];
if i + 1 < block_end {
Expand Down Expand Up @@ -1317,11 +1314,9 @@ impl Del2 {

// Recycle an old tap if `delay_time` and `note` match
if let Some(existing_tap) = self.delay_taps.iter_mut().find(|tap_option| {
if let Some(tap) = tap_option {
tap_option.as_ref().map_or(false, |tap| {
tap.delay_time == delay_time && tap.note == note
} else {
false
}
})
}) {
let tap = existing_tap.as_mut().unwrap();
tap.velocity = velocity;
Expand Down

0 comments on commit 22828f1

Please sign in to comment.