mirror of
https://github.com/servo/servo.git
synced 2025-08-03 04:30:10 +01:00
Implemented type attribute for OscillatorNode interface
This commit is contained in:
parent
6fb7a8cdc7
commit
969d61a17f
2 changed files with 28 additions and 8 deletions
|
@ -13,23 +13,25 @@ use crate::dom::bindings::codegen::Bindings::OscillatorNodeBinding::OscillatorNo
|
|||
use crate::dom::bindings::codegen::Bindings::OscillatorNodeBinding::{
|
||||
self, OscillatorOptions, OscillatorType,
|
||||
};
|
||||
use crate::dom::bindings::error::Fallible;
|
||||
use crate::dom::bindings::error::{Error, ErrorResult, 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::node::{AudioNodeInit, AudioNodeMessage};
|
||||
use servo_media::audio::oscillator_node::OscillatorNodeMessage;
|
||||
use servo_media::audio::oscillator_node::OscillatorNodeOptions as ServoMediaOscillatorOptions;
|
||||
use servo_media::audio::oscillator_node::OscillatorType as ServoMediaOscillatorType;
|
||||
use servo_media::audio::param::ParamType;
|
||||
use std::cell::Cell;
|
||||
use std::f32;
|
||||
|
||||
#[dom_struct]
|
||||
pub struct OscillatorNode {
|
||||
source_node: AudioScheduledSourceNode,
|
||||
oscillator_type: OscillatorType,
|
||||
frequency: Dom<AudioParam>,
|
||||
detune: Dom<AudioParam>,
|
||||
frequency: Dom<AudioParam>,
|
||||
oscillator_type: Cell<OscillatorType>,
|
||||
}
|
||||
|
||||
impl OscillatorNode {
|
||||
|
@ -71,10 +73,9 @@ impl OscillatorNode {
|
|||
-440. / 2.,
|
||||
440. / 2.,
|
||||
);
|
||||
|
||||
Ok(OscillatorNode {
|
||||
source_node,
|
||||
oscillator_type: options.type_,
|
||||
oscillator_type: Cell::new(options.type_),
|
||||
frequency: Dom::from_ref(&frequency),
|
||||
detune: Dom::from_ref(&detune),
|
||||
})
|
||||
|
@ -113,6 +114,25 @@ impl OscillatorNodeMethods for OscillatorNode {
|
|||
fn Detune(&self) -> DomRoot<AudioParam> {
|
||||
DomRoot::from_ref(&self.detune)
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-oscillatornode-type
|
||||
fn Type(&self) -> OscillatorType {
|
||||
self.oscillator_type.get()
|
||||
}
|
||||
|
||||
// https://webaudio.github.io/web-audio-api/#dom-oscillatornode-type
|
||||
fn SetType(&self, type_: OscillatorType) -> ErrorResult {
|
||||
if type_ == OscillatorType::Custom {
|
||||
return Err(Error::InvalidState);
|
||||
}
|
||||
self.oscillator_type.set(type_);
|
||||
self.source_node
|
||||
.node()
|
||||
.message(AudioNodeMessage::OscillatorNode(
|
||||
OscillatorNodeMessage::SetOscillatorType(type_.into()),
|
||||
));
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
|
||||
impl<'a> From<&'a OscillatorOptions> for ServoMediaOscillatorOptions {
|
||||
|
|
|
@ -24,8 +24,8 @@ dictionary OscillatorOptions : AudioNodeOptions {
|
|||
[Exposed=Window,
|
||||
Constructor (BaseAudioContext context, optional OscillatorOptions options)]
|
||||
interface OscillatorNode : AudioScheduledSourceNode {
|
||||
// [SetterThrows]
|
||||
// attribute OscillatorType type;
|
||||
[SetterThrows]
|
||||
attribute OscillatorType type;
|
||||
|
||||
readonly attribute AudioParam frequency;
|
||||
readonly attribute AudioParam detune;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue