Skip to content

Commit

Permalink
opt waveform multiband
Browse files Browse the repository at this point in the history
  • Loading branch information
aizcutei committed Jun 12, 2024
1 parent d4aefd6 commit a01e95e
Show file tree
Hide file tree
Showing 8 changed files with 323 additions and 322 deletions.
294 changes: 136 additions & 158 deletions src/audio/callback.rs

Large diffs are not rendered by default.

113 changes: 62 additions & 51 deletions src/frame/spectrogram_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,57 +22,68 @@ impl NanometersApp {
let speed = 1;
ui.painter().rect_filled(rect, 0.0, self.setting.theme.bg);
// Calculate image

match self.setting.spectrogram.orientation {
SpectrogramOrientation::H => {
if !image.is_empty() {
let colorimage = ColorImage {
size: [resolution, (width / speed) as usize],
pixels: image
[(1920 - (width / speed) as usize) * resolution..1920 * resolution]
.to_owned(),
};
let texture =
ui.ctx()
.load_texture("spectrogram", colorimage, Default::default());
self.spectrogram.texture = Some(texture);
}
if self.spectrogram.texture.is_some() {
Image::from_texture(self.spectrogram.texture.as_ref().unwrap())
.maintain_aspect_ratio(false)
.fit_to_exact_size(vec2(rect.height(), rect.width()))
.rotate(-90.0_f32.to_radians(), vec2(1.0, 0.0))
.paint_at(
ui,
Rect::from_min_size(
pos2(rect.min.x - rect.height(), rect.min.y),
vec2(rect.height(), rect.width()),
),
);
}
}
SpectrogramOrientation::V => {
if !image.is_empty() {
let colorimage = ColorImage {
size: [resolution, (height / speed) as usize],
pixels: image
[(1920 - (height / speed) as usize) * resolution..1920 * resolution]
.to_owned(),
};
let texture =
ui.ctx()
.load_texture("spectrogram", colorimage, Default::default());
self.spectrogram.texture = Some(texture);
}
if self.spectrogram.texture.is_some() {
ui.painter().image(
self.spectrogram.texture.as_ref().unwrap().id(),
rect,
Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)),
Color32::WHITE,
);
}
match self.setting.spectrogram.mode {
SpectrogramMode::Classic => match self.setting.spectrogram.orientation {
SpectrogramOrientation::H => {}
SpectrogramOrientation::V => {}
},
SpectrogramMode::Sharp => {
match self.setting.spectrogram.orientation {
SpectrogramOrientation::H => {
if !image.is_empty() {
let colorimage = ColorImage {
size: [resolution, (width / speed) as usize],
pixels: image[(1920 - (width / speed) as usize) * resolution
..1920 * resolution]
.to_owned(),
};
let texture = ui.ctx().load_texture(
"spectrogram",
colorimage,
Default::default(),
);
self.spectrogram.texture = Some(texture);
}
if self.spectrogram.texture.is_some() {
Image::from_texture(self.spectrogram.texture.as_ref().unwrap())
.maintain_aspect_ratio(false)
.fit_to_exact_size(vec2(rect.height(), rect.width()))
.rotate(-90.0_f32.to_radians(), vec2(1.0, 0.0))
.paint_at(
ui,
Rect::from_min_size(
pos2(rect.min.x - rect.height(), rect.min.y),
vec2(rect.height(), rect.width()),
),
);
}
}
SpectrogramOrientation::V => {
if !image.is_empty() {
let colorimage = ColorImage {
size: [resolution, (height / speed) as usize],
pixels: image[(1920 - (height / speed) as usize) * resolution
..1920 * resolution]
.to_owned(),
};
let texture = ui.ctx().load_texture(
"spectrogram",
colorimage,
Default::default(),
);
self.spectrogram.texture = Some(texture);
}
if self.spectrogram.texture.is_some() {
ui.painter().image(
self.spectrogram.texture.as_ref().unwrap().id(),
rect,
Rect::from_min_max(pos2(0.0, 0.0), pos2(1.0, 1.0)),
Color32::WHITE,
);
}
}
};
}
};
}
}
}
60 changes: 16 additions & 44 deletions src/frame/vectorscope_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,11 +296,12 @@ impl NanometersApp {
if data.r.is_empty() {
ui.painter().extend(self.vectorscope.plot.clone());
} else {
let max = data.r_max.max(data.g_max).max(data.b_max);
let transform = emath::TSTransform::new(
[rect.center().x, rect.center().y].into(),
if self.setting.vectorscope.normalize {
if data.max > 0.001 {
rect.center().y / (1.0 + data.max.log10() / 3.0)
rect.center().y / (1.0 + max.log10() / 3.0)
} else {
rect.center().y
}
Expand Down Expand Up @@ -463,10 +464,11 @@ impl NanometersApp {
if data.r.is_empty() {
ui.painter().extend(self.vectorscope.plot.clone());
} else {
let max = data.r_max.max(data.g_max).max(data.b_max);
let transform = emath::TSTransform::new(
[rect.center().x, rect.max.y].into(),
if self.setting.vectorscope.normalize {
0.717067812 * rect.max.y / data.max
0.717067812 * rect.max.y / max
} else {
0.717067812 * rect.center().y
},
Expand Down Expand Up @@ -660,26 +662,11 @@ impl NanometersApp {
if data.r.is_empty() {
ui.painter().extend(self.vectorscope.plot.clone());
} else {
let transform_r = emath::TSTransform::new(
[rect.center().x, rect.center().y].into(),
if self.setting.vectorscope.normalize {
0.3535533906 * rect.max.y / data.r_max
} else {
0.3535533906 * rect.center().y
},
);
let transform_g = emath::TSTransform::new(
[rect.center().x, rect.center().y].into(),
if self.setting.vectorscope.normalize {
0.3535533906 * rect.max.y / data.g_max
} else {
0.3535533906 * rect.center().y
},
);
let transform_b = emath::TSTransform::new(
let max = data.r_max.max(data.g_max).max(data.b_max);
let transform = emath::TSTransform::new(
[rect.center().x, rect.center().y].into(),
if self.setting.vectorscope.normalize {
0.3535533906 * rect.max.y / data.b_max
0.3535533906 * rect.max.y / max
} else {
0.3535533906 * rect.center().y
},
Expand All @@ -689,7 +676,7 @@ impl NanometersApp {
.iter()
.map(|p| {
Shape::circle_filled(
transform_r.mul_pos(p.clone()),
transform.mul_pos(p.clone()),
self.setting.vectorscope.point_size * 0.5,
Color32::from_rgb_additive(255, 0, 0),
)
Expand All @@ -700,7 +687,7 @@ impl NanometersApp {
.iter()
.map(|p| {
Shape::circle_filled(
transform_g.mul_pos(p.clone()),
transform.mul_pos(p.clone()),
self.setting.vectorscope.point_size * 0.5,
Color32::from_rgb_additive(0, 255, 0),
)
Expand All @@ -711,7 +698,7 @@ impl NanometersApp {
.iter()
.map(|p| {
Shape::circle_filled(
transform_b.mul_pos(p.clone()),
transform.mul_pos(p.clone()),
self.setting.vectorscope.point_size * 0.5,
Color32::from_rgb_additive(0, 0, 255),
)
Expand Down Expand Up @@ -818,26 +805,11 @@ impl NanometersApp {
if data.r.is_empty() {
ui.painter().extend(self.vectorscope.plot.clone());
} else {
let transform_r = emath::TSTransform::new(
[rect.center().x, rect.center().y].into(),
if self.setting.vectorscope.normalize {
rect.center().y / data.r_max
} else {
rect.center().y
},
);
let transform_g = emath::TSTransform::new(
[rect.center().x, rect.center().y].into(),
if self.setting.vectorscope.normalize {
rect.center().y / data.g_max
} else {
rect.center().y
},
);
let transform_b = emath::TSTransform::new(
let max = data.r_max.max(data.g_max).max(data.b_max);
let transform = emath::TSTransform::new(
[rect.center().x, rect.center().y].into(),
if self.setting.vectorscope.normalize {
rect.center().y / data.b_max
rect.center().y / max
} else {
rect.center().y
},
Expand All @@ -847,7 +819,7 @@ impl NanometersApp {
.iter()
.map(|p| {
Shape::circle_filled(
transform_r.mul_pos(p.to_owned()).to_owned(),
transform.mul_pos(p.to_owned()).to_owned(),
self.setting.vectorscope.point_size * 0.5,
Color32::from_rgb_additive(255, 0, 0),
)
Expand All @@ -858,7 +830,7 @@ impl NanometersApp {
.iter()
.map(|p| {
Shape::circle_filled(
transform_g.mul_pos(p.to_owned()).to_owned(),
transform.mul_pos(p.to_owned()).to_owned(),
self.setting.vectorscope.point_size * 0.5,
Color32::from_rgb_additive(0, 255, 0),
)
Expand All @@ -869,7 +841,7 @@ impl NanometersApp {
.iter()
.map(|p| {
Shape::circle_filled(
transform_b.mul_pos(p.to_owned()).to_owned(),
transform.mul_pos(p.to_owned()).to_owned(),
self.setting.vectorscope.point_size * 0.5,
Color32::from_rgb_additive(0, 0, 255),
)
Expand Down
16 changes: 5 additions & 11 deletions src/frame/waveform_meter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,7 @@ impl NanometersApp {
.plot_point
.ud
.push_back(rect.center().y - rect.height() * v.value.min / 2.0);
self.waveform
.plot_point
.ucolor
.push_back(full_brightness_color(&v.color));
self.waveform.plot_point.ucolor.push_back(v.color);
});
}
let len = self.waveform.plot_point.uu.len();
Expand Down Expand Up @@ -138,10 +135,7 @@ impl NanometersApp {
.plot_point
.dd
.push_back(rect.center().y - rect.height() * v.value.min / 2.0);
self.waveform
.plot_point
.dcolor
.push_back(full_brightness_color(&v.color));
self.waveform.plot_point.dcolor.push_back(v.color);
});
}
let len = self.waveform.plot_point.du.len();
Expand Down Expand Up @@ -193,15 +187,15 @@ impl NanometersApp {
self.waveform
.plot_point
.r
.push_back(rect.height() * (1.0 - v.color[0]));
.push_back(rect.height() * (1.0 - (v.color.r() / 255) as f32));
self.waveform
.plot_point
.g
.push_back(rect.height() * (1.0 - v.color[1]));
.push_back(rect.height() * (1.0 - (v.color.g() / 255) as f32));
self.waveform
.plot_point
.b
.push_back(rect.height() * (1.0 - v.color[2]));
.push_back(rect.height() * (1.0 - (v.color.b() / 255) as f32));
});
}
let len = self.waveform.plot_point.r.len();
Expand Down
Loading

0 comments on commit a01e95e

Please sign in to comment.