Files
qtmultimedia/src/imports/audioengine/qdeclarative_playvariation_p.cpp
Angus Cummings 9e6d03584a Minor doc fixes for QML
renaming QML element to QML type
removing some \fn tags that were making the docs not build
some rewording
some new signal docs

Change-Id: I9b350dad1780276959aef4105e53b91082a6083e
Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
2012-05-16 05:21:25 +02:00

290 lines
7.6 KiB
C++

/****************************************************************************
**
** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/
**
** This file is part of the plugins of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** GNU Lesser General Public License Usage
** This file may be used under the terms of the GNU Lesser General Public
** License version 2.1 as published by the Free Software Foundation and
** appearing in the file LICENSE.LGPL included in the packaging of this
** file. Please review the following information to ensure the GNU Lesser
** General Public License version 2.1 requirements will be met:
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights. These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU General
** Public License version 3.0 as published by the Free Software Foundation
** and appearing in the file LICENSE.GPL included in the packaging of this
** file. Please review the following information to ensure the GNU General
** Public License version 3.0 requirements will be met:
** http://www.gnu.org/copyleft/gpl.html.
**
** Other Usage
** Alternatively, this file may be used in accordance with the terms and
** conditions contained in a signed written agreement between you and Nokia.
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/
#include "qdeclarative_playvariation_p.h"
#include "qdeclarative_audioengine_p.h"
#include "qsoundinstance_p.h"
#include "qdebug.h"
#define DEBUG_AUDIOENGINE
QT_USE_NAMESPACE
/*!
\qmlclass PlayVariation QDeclarativePlayVariation
\since 5.0
\brief The PlayVariation type allows you to define a playback variation for \l {Sound} {sounds}.
So each time the playback of the same sound can be a slightly different even with the same
AudioSample.
\inqmlmodule QtAudioEngine 1
\ingroup multimedia_audioengine
\inherits Item
\preliminary
This type is part of the \b{QtAudioEngine 1.0} module.
PlayVariation must be defined inside a \l Sound.
\qml
import QtQuick 2.0
import QtAudioEngine 1.0
Rectangle {
color:"white"
width: 300
height: 500
AudioEngine {
id:audioengine
AudioSample {
name:"explosion01"
source: "explosion-01.wav"
}
AudioSample {
name:"explosion02"
source: "explosion-02.wav"
}
Sound {
name:"explosion"
PlayVariation {
sample:"explosion01"
minPitch: 0.8
maxPitch: 1.1
}
PlayVariation {
sample:"explosion01"
minGain: 1.1
maxGain: 1.5
}
}
}
}
\endqml
*/
QDeclarativePlayVariation::QDeclarativePlayVariation(QObject *parent)
: QObject(parent)
, m_complete(false)
, m_looping(false)
, m_maxGain(1)
, m_minGain(1)
, m_maxPitch(1)
, m_minPitch(1)
, m_sampleObject(0)
{
}
QDeclarativePlayVariation::~QDeclarativePlayVariation()
{
}
void QDeclarativePlayVariation::classBegin()
{
if (!parent() || !parent()->inherits("QDeclarativeSound")) {
qWarning("PlayVariation must be defined inside Sound!");
return;
}
}
void QDeclarativePlayVariation::componentComplete()
{
if (m_maxGain < m_minGain) {
qWarning("PlayVariation: maxGain must be no less than minGain");
qSwap(m_minGain, m_maxGain);
}
if (m_maxPitch < m_minPitch) {
qWarning("PlayVariation: maxPitch must be no less than minPitch");
qSwap(m_minPitch, m_maxPitch);
}
m_complete = true;
}
/*!
\qmlproperty string QtAudioEngine1::PlayVariation::sample
This property specifies which \l AudioSample this variation will use.
*/
QString QDeclarativePlayVariation::sample() const
{
return m_sample;
}
void QDeclarativePlayVariation::setSample(const QString& sample)
{
if (m_complete) {
qWarning("PlayVariation: cannot change properties after initialization.");
return;
}
m_sample = sample;
}
/*!
\qmlproperty bool QtAudioEngine1::PlayVariation::looping
This property indicates whether the playback will be looped or not.
*/
bool QDeclarativePlayVariation::isLooping() const
{
return m_looping;
}
void QDeclarativePlayVariation::setLooping(bool looping)
{
if (m_complete) {
qWarning("PlayVariation: cannot change properties after initialization.");
return;
}
m_looping = looping;
}
/*!
\qmlproperty real QtAudioEngine1::PlayVariation::maxGain
This property specifies the maximum gain adjustment that can be applied in any playback.
*/
qreal QDeclarativePlayVariation::maxGain() const
{
return m_maxGain;
}
void QDeclarativePlayVariation::setMaxGain(qreal maxGain)
{
if (m_complete) {
qWarning("PlayVariation: cannot change properties after initialization.");
return;
}
if (maxGain <= 0) {
qWarning("PlayVariation: maxGain must be greater than 0");
return;
}
m_maxGain = maxGain;
}
/*!
\qmlproperty real QtAudioEngine1::PlayVariation::minGain
This property specifies the minimum gain adjustment that can be applied in any playback.
*/
qreal QDeclarativePlayVariation::minGain() const
{
return m_minGain;
}
void QDeclarativePlayVariation::setMinGain(qreal minGain)
{
if (m_complete) {
qWarning("PlayVariation: cannot change properties after initialization.");
return;
}
if (minGain < 0) {
qWarning("PlayVariation: minGain must be no less than 0");
return;
}
m_minGain = minGain;
}
/*!
\qmlproperty real QtAudioEngine1::PlayVariation::maxPitch
This property specifies the maximum pitch adjustment that can be applied in any playback.
*/
qreal QDeclarativePlayVariation::maxPitch() const
{
return m_maxPitch;
}
void QDeclarativePlayVariation::setMaxPitch(qreal maxPitch)
{
if (m_complete) {
qWarning("PlayVariation: cannot change properties after initialization.");
return;
}
if (maxPitch < 0) {
qWarning("PlayVariation: maxPitch must be no less than 0");
return;
}
m_maxPitch = maxPitch;
}
/*!
\qmlproperty real QtAudioEngine1::PlayVariation::minPitch
This property specifies the minimum pitch adjustment that can be applied in any playback.
*/
qreal QDeclarativePlayVariation::minPitch() const
{
return m_minPitch;
}
void QDeclarativePlayVariation::setMinPitch(qreal minPitch)
{
if (m_complete) {
qWarning("PlayVariation: cannot change properties after initialization.");
return;
}
if (m_minPitch < 0) {
qWarning("PlayVariation: m_minPitch must be no less than 0");
return;
}
m_minPitch = minPitch;
}
QDeclarativeAudioSample* QDeclarativePlayVariation::sampleObject() const
{
return m_sampleObject;
}
void QDeclarativePlayVariation::setSampleObject(QDeclarativeAudioSample *sampleObject)
{
m_sampleObject = sampleObject;
}
void QDeclarativePlayVariation::applyParameters(QSoundInstance *soundInstance)
{
qreal pitch = qreal(qrand() % 1001) * 0.001f * (m_maxPitch - m_minPitch) + m_minPitch;
qreal gain = qreal(qrand() % 1001) * 0.001f * (m_maxGain - m_minGain) + m_minGain;
soundInstance->updateVariationParameters(pitch, gain, m_looping);
}