From 7ee42e4223dc970aeffc56ecddec2738c8340f8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Jim=C3=A9nez=20Moreno?= Date: Tue, 7 Nov 2017 20:57:30 +0100 Subject: Initial WebAudio API stubs --- components/script/dom/oscillatornode.rs | 81 +++++++++++++++++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 components/script/dom/oscillatornode.rs (limited to 'components/script/dom/oscillatornode.rs') diff --git a/components/script/dom/oscillatornode.rs b/components/script/dom/oscillatornode.rs new file mode 100644 index 00000000000..558e44357a7 --- /dev/null +++ b/components/script/dom/oscillatornode.rs @@ -0,0 +1,81 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v.2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +use dom::audioscheduledsourcenode::AudioScheduledSourceNode; +use dom::baseaudiocontext::BaseAudioContext; +use dom::bindings::codegen::Bindings::AudioNodeBinding::AudioNodeOptions; +use dom::bindings::codegen::Bindings::AudioNodeBinding::{ChannelCountMode, ChannelInterpretation}; +use dom::bindings::codegen::Bindings::OscillatorNodeBinding; +use dom::bindings::codegen::Bindings::OscillatorNodeBinding::OscillatorOptions; +use dom::bindings::error::Fallible; +use dom::bindings::reflector::reflect_dom_object; +use dom::bindings::root::DomRoot; +use dom::window::Window; +use dom_struct::dom_struct; + +#[dom_struct] +pub struct OscillatorNode { + node: AudioScheduledSourceNode, + // oscillator_type: OscillatorType, + // frequency: AudioParam, + // detune: AudioParam, +} + +impl OscillatorNode { + #[allow(unrooted_must_root)] + #[allow(unsafe_code)] + pub fn new_inherited( + window: &Window, + context: &BaseAudioContext, + ) -> OscillatorNode { + let mut options = unsafe { AudioNodeOptions::empty(window.get_cx()) }; + options.channelCount = Some(2); + options.channelCountMode = Some(ChannelCountMode::Max); + options.channelInterpretation = Some(ChannelInterpretation::Speakers); + OscillatorNode { + node: AudioScheduledSourceNode::new_inherited( + context, + &options, + 0, /* inputs */ + 1, /* outputs */ + ), + } + } + + #[allow(unrooted_must_root)] + pub fn new( + window: &Window, + context: &BaseAudioContext, + _options: &OscillatorOptions, + ) -> DomRoot { + let node = OscillatorNode::new_inherited(window, context); + reflect_dom_object(Box::new(node), window, OscillatorNodeBinding::Wrap) + } + + pub fn Constructor( + window: &Window, + context: &BaseAudioContext, + options: &OscillatorOptions, + ) -> Fallible> { + Ok(OscillatorNode::new(window, context, options)) + } +} + +/*impl OscillatorNodeMethods for OscillatorNode { + fn SetPeriodicWave(&self, periodic_wave: PeriodicWave) { + // XXX + } + + fn Type(&self) -> OscillatorType { + self.oscillator_type + } + + fn Frequency(&self) -> DomRoot { + DomRoot::from_ref(&self.frequency) + } + + fn Detune(&self) -> DomRoot { + DomRoot::from_ref(&self.detune) + } +}*/ -- cgit v1.2.3