use jsbind::prelude::*;
use webbind::*;
fn main() {
let context = AudioContext::new();
println!("Got an AudioContext");
let mut oscillator = context.create_oscillator();
println!("Configuring oscillator");
oscillator.set_type_(&OscillatorType::TRIANGLE);
oscillator.frequency().set_value(261.63);
let document = window().document();
let body = document.get_elements_by_tag_name(&"body".into()).item(0);
let mut button = document
.create_element(&"BUTTON".into())
.dyn_into::<HTMLButtonElement>()
.unwrap();
button.set_text_content(&"Click me".into());
button.add_event_listener(
&JsString::from("click"),
&EventListener::from_closure(move |_e: Event| {
println!("Playing");
oscillator.connect_with_destination_param(
context.destination().unchecked_ref::<AudioParam>(),
);
oscillator.start_with_when(0.0);
println!("All done!");
Undefined::VALUE
}),
);
body.append_child(button.dyn_ref::<Node>().unwrap());
}