Skip to content

Commit

Permalink
draw pans in DelayGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
magnetophon committed Nov 1, 2024
1 parent 3d537c7 commit 8da700d
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 11 deletions.
41 changes: 30 additions & 11 deletions src/editor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -417,14 +417,15 @@ impl View for DelayGraph {
time_scaling_factor,
border_width,
);
self.draw_tap_notes_as_diamonds(
self.draw_tap_notes_and_pans(
canvas,
&delay_data,
bounds,
selection_color,
outline_width,
time_scaling_factor,
border_width,
border_color,
true,
);
self.draw_bounding_outline(canvas, bounds, border_color, border_width);
Expand Down Expand Up @@ -575,7 +576,7 @@ impl DelayGraph {
canvas.stroke_path(&path, &vg::Paint::color(color).with_line_width(line_width));
}

fn draw_tap_notes_as_diamonds(
fn draw_tap_notes_and_pans(
&self,
canvas: &mut Canvas,
delay_data: &SharedDelayData,
Expand All @@ -584,11 +585,13 @@ impl DelayGraph {
line_width: f32,
scaling_factor: f32,
border_width: f32,
border_color: vg::Color,
zoomed: bool,
) {
let mut path = vg::Path::new();
let mut diamond_path = vg::Path::new();
let mut pan_path = vg::Path::new();

// Determine the min and max note values if zoomed
// Determine min and max note values if zoomed
let (min_note_value, max_note_value) = if zoomed {
let used_notes = &delay_data.notes[0..delay_data.current_tap];
let min = used_notes.iter().copied().min().unwrap_or(0);
Expand Down Expand Up @@ -622,15 +625,31 @@ impl DelayGraph {

let diamond_half_size = line_width;

// Form a diamond shape, fully scaled
path.move_to(diamond_center_x + diamond_half_size, diamond_center_y);
path.line_to(diamond_center_x, diamond_center_y + diamond_half_size);
path.line_to(diamond_center_x - diamond_half_size, diamond_center_y);
path.line_to(diamond_center_x, diamond_center_y - diamond_half_size);
path.close();
// Create diamond shape
diamond_path.move_to(diamond_center_x + diamond_half_size, diamond_center_y);
diamond_path.line_to(diamond_center_x, diamond_center_y + diamond_half_size);
diamond_path.line_to(diamond_center_x - diamond_half_size, diamond_center_y);
diamond_path.line_to(diamond_center_x, diamond_center_y - diamond_half_size);
diamond_path.close();

// Determine pan line
let pan_value = delay_data.pans[i];
let line_length = 50.0; // Half the total width since +/-100px total width
let pan_offset = pan_value * line_length;

pan_path.move_to(diamond_center_x, diamond_center_y);
pan_path.line_to(diamond_center_x + pan_offset, diamond_center_y);
}

canvas.stroke_path(&path, &vg::Paint::color(color).with_line_width(line_width));
canvas.stroke_path(
&pan_path,
&vg::Paint::color(border_color).with_line_width(line_width),
);

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

Expand Down
4 changes: 4 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ struct Del2 {
pub struct SharedDelayData {
delay_times: [u32; NUM_TAPS],
velocities: [f32; NUM_TAPS],
pans: [f32; NUM_TAPS],
notes: [u8; NUM_TAPS],
current_tap: usize,
current_time: u32,
Expand All @@ -113,6 +114,7 @@ impl Default for SharedDelayData {
Self {
delay_times: [0; NUM_TAPS],
velocities: [0.0; NUM_TAPS],
pans: [0.0; NUM_TAPS],
notes: [0; NUM_TAPS],
current_tap: 0,
current_time: 0,
Expand Down Expand Up @@ -915,6 +917,8 @@ impl Plugin for Del2 {
let pan = ((note as f32 - panning_center) / 12.0 * panning_amount)
.max(-1.0)
.min(1.0);
self.delay_data.pans[tap_index] = pan;

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

let delay_time = self.delay_data.delay_times[tap_index] as isize;
Expand Down

0 comments on commit 8da700d

Please sign in to comment.