1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 06:27:45 +00:00

Piano: Draw stereo waves

Draw two waves in different colors.
This commit is contained in:
William McPherson 2020-02-10 00:53:47 +11:00 committed by Andreas Kling
parent 93903c8064
commit 4ad96df0d4
3 changed files with 72 additions and 16 deletions

View file

@ -69,18 +69,26 @@ void WaveEditor::paint_event(GUI::PaintEvent& event)
painter.translate(frame_thickness(), frame_thickness());
int prev_x = 0;
int prev_y = sample_to_y(recorded_sample[0].left);
painter.set_pixel({ prev_x, prev_y }, wave_colors[RecordedSample]);
int left_prev_y = sample_to_y(recorded_sample[0].left);
int right_prev_y = sample_to_y(recorded_sample[0].right);
painter.set_pixel({ prev_x, left_prev_y }, left_wave_colors[RecordedSample]);
painter.set_pixel({ prev_x, right_prev_y }, right_wave_colors[RecordedSample]);
for (int x = 1; x < recorded_sample.size(); ++x) {
int y = sample_to_y(recorded_sample[x].left);
int left_y = sample_to_y(recorded_sample[x].left);
int right_y = sample_to_y(recorded_sample[x].right);
Gfx::Point point1(prev_x * width_scale, prev_y);
Gfx::Point point2(x * width_scale, y);
painter.draw_line(point1, point2, wave_colors[RecordedSample]);
Gfx::Point left_point1(prev_x * width_scale, left_prev_y);
Gfx::Point left_point2(x * width_scale, left_y);
painter.draw_line(left_point1, left_point2, left_wave_colors[RecordedSample]);
Gfx::Point right_point1(prev_x * width_scale, right_prev_y);
Gfx::Point right_point2(x * width_scale, right_y);
painter.draw_line(right_point1, right_point2, right_wave_colors[RecordedSample]);
prev_x = x;
prev_y = y;
left_prev_y = left_y;
right_prev_y = right_y;
}
}