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:
bors-servo 2019-05-22 05:09:43 -04:00 committed by GitHub
commit 1cbb04c647
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 14 deletions

View file

@ -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 {

View file

@ -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;