StereoPannerNode DOM

This commit is contained in:
Maria Sable 2019-04-27 10:02:14 -04:00 committed by Manish Goregaokar
parent 549d320167
commit 58f027468c
12 changed files with 173 additions and 109 deletions

View file

@ -10,7 +10,9 @@ use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
ChannelCountMode, ChannelInterpretation,
};
use crate::dom::bindings::codegen::InheritTypes::{AudioNodeTypeId, EventTargetTypeId};
use crate::dom::bindings::codegen::InheritTypes::{
AudioNodeTypeId, AudioScheduledSourceNodeTypeId, EventTargetTypeId,
};
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::root::{Dom, DomRoot};
@ -236,6 +238,13 @@ impl AudioNodeMethods for AudioNode {
return Err(Error::NotSupported);
}
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::AudioScheduledSourceNode(
AudioScheduledSourceNodeTypeId::StereoPannerNode,
)) => {
if value > 2 {
return Err(Error::NotSupported);
}
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelMergerNode) => {
return Err(Error::InvalidState);
},
@ -280,6 +289,13 @@ impl AudioNodeMethods for AudioNode {
return Err(Error::NotSupported);
}
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::AudioScheduledSourceNode(
AudioScheduledSourceNodeTypeId::StereoPannerNode,
)) => {
if value == ChannelCountMode::Max {
return Err(Error::NotSupported);
}
},
EventTargetTypeId::AudioNode(AudioNodeTypeId::ChannelMergerNode) => {
return Err(Error::InvalidState);
},

View file

@ -27,6 +27,7 @@ use crate::dom::bindings::codegen::Bindings::ChannelSplitterNodeBinding::Channel
use crate::dom::bindings::codegen::Bindings::GainNodeBinding::GainOptions;
use crate::dom::bindings::codegen::Bindings::OscillatorNodeBinding::OscillatorOptions;
use crate::dom::bindings::codegen::Bindings::PannerNodeBinding::PannerOptions;
use crate::dom::bindings::codegen::Bindings::StereoPannerNodeBinding::StereoPannerOptions;
use crate::dom::bindings::error::{Error, ErrorResult, Fallible};
use crate::dom::bindings::inheritance::Castable;
use crate::dom::bindings::num::Finite;
@ -42,6 +43,7 @@ use crate::dom::gainnode::GainNode;
use crate::dom::oscillatornode::OscillatorNode;
use crate::dom::pannernode::PannerNode;
use crate::dom::promise::Promise;
use crate::dom::stereopannernode::StereoPannerNode;
use crate::dom::window::Window;
use crate::task_source::TaskSource;
use dom_struct::dom_struct;
@ -361,6 +363,15 @@ impl BaseAudioContextMethods for BaseAudioContext {
)
}
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createstereopanner
fn CreateStereoPanner(&self) -> Fallible<DomRoot<StereoPannerNode>> {
StereoPannerNode::new(
&self.global().as_window(),
&self,
&StereoPannerOptions::empty(),
)
}
/// https://webaudio.github.io/web-audio-api/#dom-baseaudiocontext-createchannelmerger
fn CreateChannelMerger(&self, count: u32) -> Fallible<DomRoot<ChannelMergerNode>> {
let mut opts = ChannelMergerOptions::empty();

View file

@ -457,6 +457,7 @@ pub mod serviceworkerglobalscope;
pub mod serviceworkerregistration;
pub mod servoparser;
pub mod shadowroot;
pub mod stereopannernode;
pub mod storage;
pub mod storageevent;
pub mod stylepropertymapreadonly;

View file

@ -0,0 +1,106 @@
/* 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 https://mozilla.org/MPL/2.0/. */
use crate::dom::audioparam::AudioParam;
use crate::dom::audioscheduledsourcenode::AudioScheduledSourceNode;
use crate::dom::baseaudiocontext::BaseAudioContext;
use crate::dom::bindings::codegen::Bindings::AudioNodeBinding::{
ChannelCountMode, ChannelInterpretation,
};
use crate::dom::bindings::codegen::Bindings::AudioParamBinding::AutomationRate;
use crate::dom::bindings::codegen::Bindings::StereoPannerNodeBinding::StereoPannerNodeMethods;
use crate::dom::bindings::codegen::Bindings::StereoPannerNodeBinding::{self, StereoPannerOptions};
use crate::dom::bindings::error::{Error, Fallible};
use crate::dom::bindings::reflector::reflect_dom_object;
use crate::dom::bindings::root::{Dom, DomRoot};
use crate::dom::window::Window;
use dom_struct::dom_struct;
use servo_media::audio::node::AudioNodeInit;
use servo_media::audio::param::ParamType;
use servo_media::audio::stereo_panner::StereoPannerOptions as ServoMediaStereoPannerOptions;
#[dom_struct]
pub struct StereoPannerNode {
source_node: AudioScheduledSourceNode,
pan: Dom<AudioParam>,
}
impl StereoPannerNode {
#[allow(unrooted_must_root)]
pub fn new_inherited(
window: &Window,
context: &BaseAudioContext,
options: &StereoPannerOptions,
) -> Fallible<StereoPannerNode> {
let node_options = options.parent.unwrap_or(
2,
ChannelCountMode::Clamped_max,
ChannelInterpretation::Speakers,
);
if node_options.mode == ChannelCountMode::Max {
return Err(Error::NotSupported);
}
if node_options.count > 2 || node_options.count == 0 {
return Err(Error::NotSupported);
}
let source_node = AudioScheduledSourceNode::new_inherited(
AudioNodeInit::StereoPannerNode(options.into()),
context,
node_options,
1, /* inputs */
1, /* outputs */
)?;
let node_id = source_node.node().node_id();
let pan = AudioParam::new(
window,
context,
node_id,
ParamType::Pan,
AutomationRate::A_rate,
*options.pan,
-1.,
1.,
);
Ok(StereoPannerNode {
source_node,
pan: Dom::from_ref(&pan),
})
}
#[allow(unrooted_must_root)]
pub fn new(
window: &Window,
context: &BaseAudioContext,
options: &StereoPannerOptions,
) -> Fallible<DomRoot<StereoPannerNode>> {
let node = StereoPannerNode::new_inherited(window, context, options)?;
Ok(reflect_dom_object(
Box::new(node),
window,
StereoPannerNodeBinding::Wrap,
))
}
pub fn Constructor(
window: &Window,
context: &BaseAudioContext,
options: &StereoPannerOptions,
) -> Fallible<DomRoot<StereoPannerNode>> {
StereoPannerNode::new(window, context, options)
}
}
impl StereoPannerNodeMethods for StereoPannerNode {
// https://webaudio.github.io/web-audio-api/#dom-stereopannernode-pan
fn Pan(&self) -> DomRoot<AudioParam> {
DomRoot::from_ref(&self.pan)
}
}
impl<'a> From<&'a StereoPannerOptions> for ServoMediaStereoPannerOptions {
fn from(options: &'a StereoPannerOptions) -> Self {
Self { pan: *options.pan }
}
}

View file

@ -43,7 +43,7 @@ interface BaseAudioContext : EventTarget {
// sequence<double> feedback);
// WaveShaperNode createWaveShaper();
[Throws] PannerNode createPanner();
// StereoPannerNode createStereoPanner();
[Throws] StereoPannerNode createStereoPanner();
// ConvolverNode createConvolver();
[Throws] ChannelSplitterNode createChannelSplitter(optional unsigned long numberOfOutputs = 6);
[Throws] ChannelMergerNode createChannelMerger(optional unsigned long numberOfInputs = 6);

View file

@ -0,0 +1,17 @@
/* 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 https://mozilla.org/MPL/2.0/. */
/*
* The origin of this IDL file is
* https://webaudio.github.io/web-audio-api/#StereoPannerNode
*/
dictionary StereoPannerOptions: AudioNodeOptions {
float pan = 0;
};
[Exposed=Window,
Constructor (BaseAudioContext context, optional StereoPannerOptions options)]
interface StereoPannerNode : AudioScheduledSourceNode {
readonly attribute AudioParam pan;
};