1
/* This file is part of the KDE project.
3
Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
5
This library is free software: you can redistribute it and/or modify
6
it under the terms of the GNU Lesser General Public License as published by
7
the Free Software Foundation, either version 2.1 or 3 of the License.
9
This library is distributed in the hope that it will be useful,
10
but WITHOUT ANY WARRANTY; without even the implied warranty of
11
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
GNU Lesser General Public License for more details.
14
You should have received a copy of the GNU Lesser General Public License
15
along with this library. If not, see <http://www.gnu.org/licenses/>.
18
#include "volumefadereffect.h"
21
#include <gst/gstbin.h>
22
#include <gst/gstghostpad.h>
23
#include <gst/gstutils.h>
25
#include <QtCore/QEvent>
29
#ifndef QT_NO_PHONON_VOLUMEFADEREFFECT
34
VolumeFaderEffect::VolumeFaderEffect(Backend *backend, QObject *parent)
35
: Effect(backend, parent, AudioSource | AudioSink)
36
, m_fadeCurve(Phonon::VolumeFaderEffect::Fade3Decibel)
42
m_effectElement = gst_element_factory_make ("volume", NULL);
47
VolumeFaderEffect::~VolumeFaderEffect()
50
killTimer(m_fadeTimer);
53
GstElement* VolumeFaderEffect::createEffectBin()
55
GstElement *audioBin = gst_bin_new(NULL);
57
// We need a queue to handle tee-connections from parent node
58
GstElement *queue= gst_element_factory_make ("queue", NULL);
59
gst_bin_add(GST_BIN(audioBin), queue);
61
GstElement *mconv= gst_element_factory_make ("audioconvert", NULL);
62
gst_bin_add(GST_BIN(audioBin), mconv);
63
gst_bin_add(GST_BIN(audioBin), m_effectElement);
66
GstPad *srcPad= gst_element_get_pad (m_effectElement, "src");
67
gst_element_add_pad (audioBin, gst_ghost_pad_new ("src", srcPad));
68
gst_object_unref (srcPad);
71
gst_element_link_many(queue, mconv, m_effectElement, (const char*)NULL);
72
GstPad *sinkpad = gst_element_get_pad (queue, "sink");
73
gst_element_add_pad (audioBin, gst_ghost_pad_new ("sink", sinkpad));
74
gst_object_unref (sinkpad);
78
float VolumeFaderEffect::volume() const
82
g_object_get(G_OBJECT(m_effectElement), "volume", &val, (const char*)NULL);
86
void VolumeFaderEffect::setVolume(float volume)
88
g_object_set(G_OBJECT(m_effectElement), "volume", volume, (const char*)NULL);
91
Phonon::VolumeFaderEffect::FadeCurve VolumeFaderEffect::fadeCurve() const
96
void VolumeFaderEffect::setFadeCurve(Phonon::VolumeFaderEffect::FadeCurve fadeCurve)
98
m_fadeCurve = fadeCurve;
101
void VolumeFaderEffect::fadeTo(float targetVolume, int fadeTime)
103
m_fadeToVolume = targetVolume;
104
m_fadeDuration = fadeTime;
105
m_fadeFromVolume = volume();
106
m_fadeStartTime.start();
109
killTimer(m_fadeTimer);
110
m_fadeTimer = startTimer(30);
113
void VolumeFaderEffect::updateFade()
115
double currVal = 0.0;
116
float step = float(m_fadeStartTime.elapsed()) / float(m_fadeDuration);
120
killTimer(m_fadeTimer);
124
// This is a very loose and interpretation of the API
125
// But in fact when fading between arbitrary values, the decibel values make no sense
126
// Note : seems like we will change the API to re-use names from QTimeline for this
127
switch (fadeCurve()) {
128
case Phonon::VolumeFaderEffect::Fade3Decibel: // Slow in the beginning
129
currVal = step * step;
131
case Phonon::VolumeFaderEffect::Fade6Decibel: // Linear fade
134
case Phonon::VolumeFaderEffect::Fade9Decibel: // Fast in the beginning / Linear
135
currVal = step * 0.5 + (1.0-(1.0-step)*(1.0-step)) * 0.5;
137
case Phonon::VolumeFaderEffect::Fade12Decibel: // Fast in the beginning
138
currVal = 1.0 - (1.0-step) * (1.0-step);
143
const double volume = (1.0 - currVal) * m_fadeFromVolume + currVal * m_fadeToVolume;
147
bool VolumeFaderEffect::event(QEvent *event)
149
switch (event->type()){
152
QTimerEvent *timerEvent = static_cast<QTimerEvent *>(event);
153
if (timerEvent->timerId() == m_fadeTimer)
160
return QObject::event(event);
163
}} //namespace Phonon::Gstreamer
164
#endif //QT_NO_PHONON_VOLUMEFADEREFFECT
167
#include "moc_volumefadereffect.cpp"