Small clean up

This commit is contained in:
Rob Watson 2020-09-09 11:12:49 +02:00
parent 89866f944b
commit 4a951c6035
1 changed files with 29 additions and 33 deletions

View File

@ -69,12 +69,9 @@ impl Canvas {
fn redraw_canvas(&mut self) {
let canvas_element = self.canvas_node.cast::<HtmlCanvasElement>().unwrap();
// canvas_element.clear(); TODO
let width = canvas_element.width();
let height = canvas_element.height();
// TODO: error handling
let context = canvas_element
.get_context("2d")
.unwrap()
@ -84,19 +81,16 @@ impl Canvas {
context.set_fill_style(&"black".into());
context.set_stroke_style(&"green".into());
context.fill_rect(0.0, 0.0, width as f64, height as f64);
context.fill_rect(0.0, 0.0, canvas_element.width() as f64, height as f64);
// TODO: improve
if self.audio_data.is_none() {
return;
}
if self.audio_data.is_some() {
let audio_data = self.audio_data.as_ref().unwrap();
// TODO: multi-channel
let _num_channels = audio_data.number_of_channels(); // 1
let channel_data = audio_data.get_channel_data(0).unwrap();
let chunks = utils::chunks_fixed(&channel_data, width as usize);
let chunks = utils::chunks_fixed(&channel_data, canvas_element.width() as usize);
chunks.enumerate().for_each(|(i, chunk)| {
let max = chunk
@ -114,7 +108,9 @@ impl Canvas {
context.move_to(i as f64, mid - (len / 2f64));
context.line_to(i as f64, mid + (len / 2f64));
context.stroke();
// ConsoleService::log(&format!("index {}: max {}, pc {}, len {}", i, max, pc, len));
});
}
}
}