2012-10-16 18:19:06 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et cindent: */
|
|
|
|
/* 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 http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2012-10-30 14:39:38 -07:00
|
|
|
#ifndef AudioParam_h_
|
|
|
|
#define AudioParam_h_
|
2012-10-16 18:19:06 -07:00
|
|
|
|
|
|
|
#include "AudioEventTimeline.h"
|
|
|
|
#include "nsWrapperCache.h"
|
|
|
|
#include "nsCycleCollectionParticipant.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "EnableWebAudioCheck.h"
|
|
|
|
#include "nsAutoPtr.h"
|
2013-01-28 15:59:29 -08:00
|
|
|
#include "AudioNode.h"
|
2012-10-16 18:19:06 -07:00
|
|
|
#include "mozilla/dom/TypedArray.h"
|
|
|
|
#include "mozilla/Util.h"
|
2013-01-28 14:42:27 -08:00
|
|
|
#include "mozilla/ErrorResult.h"
|
2012-10-16 18:19:06 -07:00
|
|
|
|
2012-11-14 18:38:26 -08:00
|
|
|
struct JSContext;
|
2012-10-16 18:19:06 -07:00
|
|
|
class nsIDOMWindow;
|
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
|
|
|
|
namespace dom {
|
|
|
|
|
2013-01-25 13:46:44 -08:00
|
|
|
typedef AudioEventTimeline<ErrorResult> AudioParamTimeline;
|
2012-10-16 18:19:06 -07:00
|
|
|
|
|
|
|
class AudioParam MOZ_FINAL : public nsWrapperCache,
|
|
|
|
public EnableWebAudioCheck,
|
|
|
|
public AudioParamTimeline
|
|
|
|
{
|
|
|
|
public:
|
2013-01-28 15:59:29 -08:00
|
|
|
typedef void (*CallbackType)(AudioNode*);
|
|
|
|
|
|
|
|
AudioParam(AudioNode* aNode,
|
|
|
|
CallbackType aCallback,
|
2012-10-16 18:19:06 -07:00
|
|
|
float aDefaultValue,
|
|
|
|
float aMinValue,
|
|
|
|
float aMaxValue);
|
|
|
|
virtual ~AudioParam();
|
|
|
|
|
|
|
|
NS_INLINE_DECL_CYCLE_COLLECTING_NATIVE_REFCOUNTING(AudioParam)
|
|
|
|
NS_DECL_CYCLE_COLLECTION_SCRIPT_HOLDER_NATIVE_CLASS(AudioParam)
|
|
|
|
|
|
|
|
AudioContext* GetParentObject() const
|
|
|
|
{
|
2013-01-28 15:59:29 -08:00
|
|
|
return mNode->Context();
|
2012-10-16 18:19:06 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual JSObject* WrapObject(JSContext* aCx, JSObject* aScope,
|
|
|
|
bool* aTriedToWrap);
|
|
|
|
|
|
|
|
// We override SetValueCurveAtTime to convert the Float32Array to the wrapper
|
|
|
|
// object.
|
2012-11-19 12:52:29 -08:00
|
|
|
void SetValueCurveAtTime(JSContext* cx, const Float32Array& aValues, double aStartTime, double aDuration, ErrorResult& aRv)
|
2012-10-16 18:19:06 -07:00
|
|
|
{
|
2013-01-25 13:46:44 -08:00
|
|
|
AudioParamTimeline::SetValueCurveAtTime(aValues.Data(), aValues.Length(),
|
2012-10-16 18:19:06 -07:00
|
|
|
aStartTime, aDuration, aRv);
|
2013-01-28 15:59:29 -08:00
|
|
|
mCallback(mNode);
|
|
|
|
}
|
|
|
|
|
|
|
|
// We override the rest of the mutating AudioParamTimeline methods in order to make
|
|
|
|
// sure that the callback is called every time that this object gets mutated.
|
|
|
|
void SetValue(float aValue)
|
|
|
|
{
|
|
|
|
AudioParamTimeline::SetValue(aValue);
|
|
|
|
mCallback(mNode);
|
|
|
|
}
|
|
|
|
void SetValueAtTime(float aValue, double aStartTime, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AudioParamTimeline::SetValueAtTime(aValue, aStartTime, aRv);
|
|
|
|
mCallback(mNode);
|
|
|
|
}
|
|
|
|
void LinearRampToValueAtTime(float aValue, double aEndTime, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AudioParamTimeline::LinearRampToValueAtTime(aValue, aEndTime, aRv);
|
|
|
|
mCallback(mNode);
|
|
|
|
}
|
|
|
|
void ExponentialRampToValueAtTime(float aValue, double aEndTime, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AudioParamTimeline::ExponentialRampToValueAtTime(aValue, aEndTime, aRv);
|
|
|
|
mCallback(mNode);
|
|
|
|
}
|
|
|
|
void SetTargetAtTime(float aTarget, double aStartTime, double aTimeConstant, ErrorResult& aRv)
|
|
|
|
{
|
|
|
|
AudioParamTimeline::SetTargetAtTime(aTarget, aStartTime, aTimeConstant, aRv);
|
|
|
|
mCallback(mNode);
|
|
|
|
}
|
|
|
|
void CancelScheduledValues(double aStartTime)
|
|
|
|
{
|
|
|
|
AudioParamTimeline::CancelScheduledValues(aStartTime);
|
|
|
|
mCallback(mNode);
|
2012-10-16 18:19:06 -07:00
|
|
|
}
|
|
|
|
|
2013-01-25 11:26:31 -08:00
|
|
|
float MinValue() const
|
|
|
|
{
|
|
|
|
return mMinValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
float MaxValue() const
|
|
|
|
{
|
|
|
|
return mMaxValue;
|
|
|
|
}
|
|
|
|
|
|
|
|
float DefaultValue() const
|
|
|
|
{
|
|
|
|
return mDefaultValue;
|
|
|
|
}
|
|
|
|
|
2012-10-16 18:19:06 -07:00
|
|
|
private:
|
2013-01-28 15:59:29 -08:00
|
|
|
nsRefPtr<AudioNode> mNode;
|
|
|
|
CallbackType mCallback;
|
2013-01-25 11:26:31 -08:00
|
|
|
const float mDefaultValue;
|
|
|
|
const float mMinValue;
|
|
|
|
const float mMaxValue;
|
2012-10-16 18:19:06 -07:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-10-30 14:39:38 -07:00
|
|
|
#endif
|
|
|
|
|