mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Initial AudioParam bindings
This commit is contained in:
parent
885addfaae
commit
7380f69f77
8 changed files with 187 additions and 55 deletions
|
@ -3,30 +3,44 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use dom::bindings::codegen::Bindings::AudioParamBinding;
|
||||
use dom::bindings::codegen::Bindings::AudioParamBinding::AudioParamMethods;
|
||||
use dom::bindings::codegen::Bindings::AudioParamBinding::{AudioParamMethods, AutomationRate};
|
||||
use dom::bindings::num::Finite;
|
||||
use dom::bindings::reflector::{Reflector, reflect_dom_object};
|
||||
use dom::bindings::root::DomRoot;
|
||||
use dom::globalscope::GlobalScope;
|
||||
use dom::bindings::trace::JSTraceable;
|
||||
use dom::window::Window;
|
||||
use dom_struct::dom_struct;
|
||||
use malloc_size_of::MallocSizeOf;
|
||||
use servo_media::audio::param::RampKind;
|
||||
use std::cell::Cell;
|
||||
|
||||
pub trait AudioParamImpl: JSTraceable + MallocSizeOf {
|
||||
fn set_value(&self, value: f32);
|
||||
fn set_value_at_time(&self, value: f32, start_time: f64);
|
||||
fn ramp_to_value_at_time(&self, ramp_kind: RampKind, value: f32, end_time: f64);
|
||||
fn set_target_at_time(&self, value: f32, start_time: f64, time_constant: f32);
|
||||
}
|
||||
|
||||
#[dom_struct]
|
||||
pub struct AudioParam {
|
||||
reflector_: Reflector,
|
||||
value: Cell<f32>,
|
||||
param_impl: Box<AudioParamImpl>,
|
||||
automation_rate: Cell<AutomationRate>,
|
||||
default_value: f32,
|
||||
min_value: f32,
|
||||
max_value: f32,
|
||||
}
|
||||
|
||||
impl AudioParam {
|
||||
pub fn new_inherited(default_value: f32,
|
||||
pub fn new_inherited(param_impl: Box<AudioParamImpl>,
|
||||
automation_rate: AutomationRate,
|
||||
default_value: f32,
|
||||
min_value: f32,
|
||||
max_value: f32) -> AudioParam {
|
||||
AudioParam {
|
||||
reflector_: Reflector::new(),
|
||||
value: Cell::new(default_value),
|
||||
param_impl,
|
||||
automation_rate: Cell::new(automation_rate),
|
||||
default_value,
|
||||
min_value,
|
||||
max_value,
|
||||
|
@ -34,22 +48,35 @@ impl AudioParam {
|
|||
}
|
||||
|
||||
#[allow(unrooted_must_root)]
|
||||
pub fn new(global: &GlobalScope,
|
||||
pub fn new(window: &Window,
|
||||
param_impl: Box<AudioParamImpl>,
|
||||
automation_rate: AutomationRate,
|
||||
default_value: f32,
|
||||
min_value: f32,
|
||||
max_value: f32) -> DomRoot<AudioParam> {
|
||||
let audio_param = AudioParam::new_inherited(default_value, min_value, max_value);
|
||||
reflect_dom_object(Box::new(audio_param), global, AudioParamBinding::Wrap)
|
||||
let audio_param = AudioParam::new_inherited(param_impl, automation_rate,
|
||||
default_value, min_value, max_value);
|
||||
reflect_dom_object(Box::new(audio_param), window, AudioParamBinding::Wrap)
|
||||
}
|
||||
}
|
||||
|
||||
impl AudioParamMethods for AudioParam {
|
||||
fn AutomationRate(&self) -> AutomationRate {
|
||||
self.automation_rate.get()
|
||||
}
|
||||
|
||||
fn SetAutomationRate(&self, automation_rate: AutomationRate) {
|
||||
self.automation_rate.set(automation_rate);
|
||||
// XXX set servo-media param automation rate
|
||||
}
|
||||
|
||||
fn Value(&self) -> Finite<f32> {
|
||||
Finite::wrap(self.value.get())
|
||||
// XXX
|
||||
Finite::wrap(0.)
|
||||
}
|
||||
|
||||
fn SetValue(&self, value: Finite<f32>) {
|
||||
self.value.set(*value);
|
||||
self.param_impl.set_value(*value);
|
||||
}
|
||||
|
||||
fn DefaultValue(&self) -> Finite<f32> {
|
||||
|
@ -63,4 +90,32 @@ impl AudioParamMethods for AudioParam {
|
|||
fn MaxValue(&self) -> Finite<f32> {
|
||||
Finite::wrap(self.max_value)
|
||||
}
|
||||
|
||||
fn SetValueAtTime(&self, value: Finite<f32>, start_time: Finite<f64>)
|
||||
-> DomRoot<AudioParam>
|
||||
{
|
||||
self.param_impl.set_value_at_time(*value, *start_time);
|
||||
DomRoot::from_ref(self)
|
||||
}
|
||||
|
||||
fn LinearRampToValueAtTime(&self, value: Finite<f32>, end_time: Finite<f64>)
|
||||
-> DomRoot<AudioParam>
|
||||
{
|
||||
self.param_impl.ramp_to_value_at_time(RampKind::Linear, *value, *end_time);
|
||||
DomRoot::from_ref(self)
|
||||
}
|
||||
|
||||
fn ExponentialRampToValueAtTime(&self, value: Finite<f32>, end_time: Finite<f64>)
|
||||
-> DomRoot<AudioParam>
|
||||
{
|
||||
self.param_impl.ramp_to_value_at_time(RampKind::Exponential, *value, *end_time);
|
||||
DomRoot::from_ref(self)
|
||||
}
|
||||
|
||||
fn SetTargetAtTime(&self, target: Finite<f32>, start_time: Finite<f64>, time_constant: Finite<f32>)
|
||||
-> DomRoot<AudioParam>
|
||||
{
|
||||
self.param_impl.set_target_at_time(*target, *start_time, *time_constant);
|
||||
DomRoot::from_ref(self)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue