mirror of
https://github.com/servo/servo.git
synced 2025-08-03 20:50:07 +01:00
Auto merge of #23282 - josephhutch:OscillatorNodeType, r=ferjm
Implemented type attribute for OscillatorNode interface <!-- Please describe your changes on the following line: --> Please see https://github.com/servo/media/pull/242 for implementation of the new oscillator node message. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `___` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #___ (GitHub issue number if applicable) <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because ___ <!-- Also, please make sure that "Allow edits from maintainers" checkbox is checked, so that we can help you if you get stuck somewhere along the way.--> <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/23282) <!-- Reviewable:end -->
This commit is contained in:
commit
1cbb04c647
3 changed files with 28 additions and 14 deletions
|
@ -13,23 +13,25 @@ use crate::dom::bindings::codegen::Bindings::OscillatorNodeBinding::OscillatorNo
|
||||||
use crate::dom::bindings::codegen::Bindings::OscillatorNodeBinding::{
|
use crate::dom::bindings::codegen::Bindings::OscillatorNodeBinding::{
|
||||||
self, OscillatorOptions, OscillatorType,
|
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::reflector::reflect_dom_object;
|
||||||
use crate::dom::bindings::root::{Dom, DomRoot};
|
use crate::dom::bindings::root::{Dom, DomRoot};
|
||||||
use crate::dom::window::Window;
|
use crate::dom::window::Window;
|
||||||
use dom_struct::dom_struct;
|
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::OscillatorNodeOptions as ServoMediaOscillatorOptions;
|
||||||
use servo_media::audio::oscillator_node::OscillatorType as ServoMediaOscillatorType;
|
use servo_media::audio::oscillator_node::OscillatorType as ServoMediaOscillatorType;
|
||||||
use servo_media::audio::param::ParamType;
|
use servo_media::audio::param::ParamType;
|
||||||
|
use std::cell::Cell;
|
||||||
use std::f32;
|
use std::f32;
|
||||||
|
|
||||||
#[dom_struct]
|
#[dom_struct]
|
||||||
pub struct OscillatorNode {
|
pub struct OscillatorNode {
|
||||||
source_node: AudioScheduledSourceNode,
|
source_node: AudioScheduledSourceNode,
|
||||||
oscillator_type: OscillatorType,
|
|
||||||
frequency: Dom<AudioParam>,
|
|
||||||
detune: Dom<AudioParam>,
|
detune: Dom<AudioParam>,
|
||||||
|
frequency: Dom<AudioParam>,
|
||||||
|
oscillator_type: Cell<OscillatorType>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl OscillatorNode {
|
impl OscillatorNode {
|
||||||
|
@ -71,10 +73,9 @@ impl OscillatorNode {
|
||||||
-440. / 2.,
|
-440. / 2.,
|
||||||
440. / 2.,
|
440. / 2.,
|
||||||
);
|
);
|
||||||
|
|
||||||
Ok(OscillatorNode {
|
Ok(OscillatorNode {
|
||||||
source_node,
|
source_node,
|
||||||
oscillator_type: options.type_,
|
oscillator_type: Cell::new(options.type_),
|
||||||
frequency: Dom::from_ref(&frequency),
|
frequency: Dom::from_ref(&frequency),
|
||||||
detune: Dom::from_ref(&detune),
|
detune: Dom::from_ref(&detune),
|
||||||
})
|
})
|
||||||
|
@ -113,6 +114,25 @@ impl OscillatorNodeMethods for OscillatorNode {
|
||||||
fn Detune(&self) -> DomRoot<AudioParam> {
|
fn Detune(&self) -> DomRoot<AudioParam> {
|
||||||
DomRoot::from_ref(&self.detune)
|
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 {
|
impl<'a> From<&'a OscillatorOptions> for ServoMediaOscillatorOptions {
|
||||||
|
|
|
@ -24,8 +24,8 @@ dictionary OscillatorOptions : AudioNodeOptions {
|
||||||
[Exposed=Window,
|
[Exposed=Window,
|
||||||
Constructor (BaseAudioContext context, optional OscillatorOptions options)]
|
Constructor (BaseAudioContext context, optional OscillatorOptions options)]
|
||||||
interface OscillatorNode : AudioScheduledSourceNode {
|
interface OscillatorNode : AudioScheduledSourceNode {
|
||||||
// [SetterThrows]
|
[SetterThrows]
|
||||||
// attribute OscillatorType type;
|
attribute OscillatorType type;
|
||||||
|
|
||||||
readonly attribute AudioParam frequency;
|
readonly attribute AudioParam frequency;
|
||||||
readonly attribute AudioParam detune;
|
readonly attribute AudioParam detune;
|
||||||
|
|
|
@ -41,9 +41,6 @@
|
||||||
[AudioWorkletNode interface: worklet_node must inherit property "port" with the proper type]
|
[AudioWorkletNode interface: worklet_node must inherit property "port" with the proper type]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[OscillatorNode interface: attribute type]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[AudioContext interface: operation suspend()]
|
[AudioContext interface: operation suspend()]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
@ -140,9 +137,6 @@
|
||||||
[AudioNode interface: calling connect(AudioParam, unsigned long) on new DynamicsCompressorNode(context) with too few arguments must throw TypeError]
|
[AudioNode interface: calling connect(AudioParam, unsigned long) on new DynamicsCompressorNode(context) with too few arguments must throw TypeError]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
[OscillatorNode interface: new OscillatorNode(context) must inherit property "type" with the proper type]
|
|
||||||
expected: FAIL
|
|
||||||
|
|
||||||
[MediaStreamAudioDestinationNode interface: attribute stream]
|
[MediaStreamAudioDestinationNode interface: attribute stream]
|
||||||
expected: FAIL
|
expected: FAIL
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue