Small clean up
This commit is contained in:
parent
89866f944b
commit
4a951c6035
|
@ -69,12 +69,9 @@ impl Canvas {
|
||||||
|
|
||||||
fn redraw_canvas(&mut self) {
|
fn redraw_canvas(&mut self) {
|
||||||
let canvas_element = self.canvas_node.cast::<HtmlCanvasElement>().unwrap();
|
let canvas_element = self.canvas_node.cast::<HtmlCanvasElement>().unwrap();
|
||||||
// canvas_element.clear(); TODO
|
|
||||||
|
|
||||||
let width = canvas_element.width();
|
let width = canvas_element.width();
|
||||||
let height = canvas_element.height();
|
let height = canvas_element.height();
|
||||||
|
|
||||||
// TODO: error handling
|
|
||||||
let context = canvas_element
|
let context = canvas_element
|
||||||
.get_context("2d")
|
.get_context("2d")
|
||||||
.unwrap()
|
.unwrap()
|
||||||
|
@ -84,19 +81,16 @@ impl Canvas {
|
||||||
|
|
||||||
context.set_fill_style(&"black".into());
|
context.set_fill_style(&"black".into());
|
||||||
context.set_stroke_style(&"green".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_some() {
|
||||||
if self.audio_data.is_none() {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
let audio_data = self.audio_data.as_ref().unwrap();
|
let audio_data = self.audio_data.as_ref().unwrap();
|
||||||
|
|
||||||
// TODO: multi-channel
|
// TODO: multi-channel
|
||||||
let _num_channels = audio_data.number_of_channels(); // 1
|
let _num_channels = audio_data.number_of_channels(); // 1
|
||||||
|
|
||||||
let channel_data = audio_data.get_channel_data(0).unwrap();
|
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)| {
|
chunks.enumerate().for_each(|(i, chunk)| {
|
||||||
let max = chunk
|
let max = chunk
|
||||||
|
@ -114,7 +108,9 @@ impl Canvas {
|
||||||
context.move_to(i as f64, mid - (len / 2f64));
|
context.move_to(i as f64, mid - (len / 2f64));
|
||||||
context.line_to(i as f64, mid + (len / 2f64));
|
context.line_to(i as f64, mid + (len / 2f64));
|
||||||
context.stroke();
|
context.stroke();
|
||||||
|
|
||||||
// ConsoleService::log(&format!("index {}: max {}, pc {}, len {}", i, max, pc, len));
|
// ConsoleService::log(&format!("index {}: max {}, pc {}, len {}", i, max, pc, len));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue