From 305ecb7910d7030d7e25594c8c8b2b0ef3eaf2f9 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Sun, 19 Aug 2018 14:42:25 -0700 Subject: [PATCH] Remove `nll` feature from `webaudio` example --- examples/webaudio/src/lib.rs | 56 ++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/examples/webaudio/src/lib.rs b/examples/webaudio/src/lib.rs index b048c27e..704f71e9 100644 --- a/examples/webaudio/src/lib.rs +++ b/examples/webaudio/src/lib.rs @@ -1,5 +1,3 @@ -#![feature(nll)] - extern crate wasm_bindgen; extern crate web_sys; @@ -45,13 +43,20 @@ impl FmOsc { // TODO, how to throw from a constructor? let ctx = web_sys::AudioContext::new().unwrap(); - let base: &BaseAudioContext = ctx.as_ref(); + let primary; + let fm_osc; + let gain; + let fm_gain; - // create our web audio objects - let primary = base.create_oscillator().unwrap(); - let fm_osc = base.create_oscillator().unwrap(); - let gain = base.create_gain().unwrap(); - let fm_gain = base.create_gain().unwrap(); + { + let base: &BaseAudioContext = ctx.as_ref(); + + // create our web audio objects + primary = base.create_oscillator().unwrap(); + fm_osc = base.create_oscillator().unwrap(); + gain = base.create_gain().unwrap(); + fm_gain = base.create_gain().unwrap(); + } // some initial settings: primary.set_type(OscillatorType::Sine); @@ -63,27 +68,30 @@ impl FmOsc { // Create base class references: - let primary_node: &AudioNode = primary.as_ref(); - let gain_node: &AudioNode = gain.as_ref(); - let fm_osc_node: &AudioNode = fm_osc.as_ref(); - let fm_gain_node: &AudioNode = fm_gain.as_ref(); - let destination = base.destination(); - let destination_node: &AudioNode = destination.as_ref(); + { + let primary_node: &AudioNode = primary.as_ref(); + let gain_node: &AudioNode = gain.as_ref(); + let fm_osc_node: &AudioNode = fm_osc.as_ref(); + let fm_gain_node: &AudioNode = fm_gain.as_ref(); + let base: &BaseAudioContext = ctx.as_ref(); + let destination = base.destination(); + let destination_node: &AudioNode = destination.as_ref(); - // connect them up: + // connect them up: - // The primary oscillator is routed through the gain node, so that it can control the overall output volume - primary_node.connect_with_destination_and_output_and_input_using_destination(gain.as_ref()); - // Then connect the gain node to the AudioContext destination (aka your speakers) - gain_node.connect_with_destination_and_output_and_input_using_destination(destination_node); + // The primary oscillator is routed through the gain node, so that it can control the overall output volume + primary_node.connect_with_destination_and_output_and_input_using_destination(gain.as_ref()); + // Then connect the gain node to the AudioContext destination (aka your speakers) + gain_node.connect_with_destination_and_output_and_input_using_destination(destination_node); - // the FM oscillator is connected to its own gain node, so it can control the amount of modulation - fm_osc_node.connect_with_destination_and_output_and_input_using_destination(fm_gain.as_ref()); + // the FM oscillator is connected to its own gain node, so it can control the amount of modulation + fm_osc_node.connect_with_destination_and_output_and_input_using_destination(fm_gain.as_ref()); - // Connect the FM oscillator to the frequency parameter of the main oscillator, so that the - // FM node can modulate its frequency - fm_gain_node.connect_with_destination_and_output_using_destination(&primary.frequency()); + // Connect the FM oscillator to the frequency parameter of the main oscillator, so that the + // FM node can modulate its frequency + fm_gain_node.connect_with_destination_and_output_using_destination(&primary.frequency()); + } // start the oscillators!