Commit 38a3df7b authored by Dmitry Kazakov's avatar Dmitry Kazakov

Implement a slider for configuring Volume of the audio channel in the document

parent 9087e641
......@@ -40,6 +40,7 @@ struct KisImageAnimationInterface::Private
frameInvalidationBlocked(false),
cachedLastFrameValue(-1),
audioChannelMuted(false),
audioChannelVolume(0.5),
m_currentTime(0),
m_currentUITime(0)
{
......@@ -55,6 +56,7 @@ struct KisImageAnimationInterface::Private
cachedLastFrameValue(-1),
audioChannelFileName(rhs.audioChannelFileName),
audioChannelMuted(rhs.audioChannelMuted),
audioChannelVolume(rhs.audioChannelVolume),
m_currentTime(rhs.m_currentTime),
m_currentUITime(rhs.m_currentUITime)
{
......@@ -70,6 +72,7 @@ struct KisImageAnimationInterface::Private
int cachedLastFrameValue;
QString audioChannelFileName;
bool audioChannelMuted;
qreal audioChannelVolume;
KisSwitchTimeStrokeStrategy::SharedTokenWSP switchToken;
......@@ -189,6 +192,17 @@ void KisImageAnimationInterface::setAudioMuted(bool value)
emit sigAudioChannelChanged();
}
qreal KisImageAnimationInterface::audioVolume() const
{
return m_d->audioChannelVolume;
}
void KisImageAnimationInterface::setAudioVolume(qreal value)
{
m_d->audioChannelVolume = value;
emit sigAudioVolumeChanged();
}
void KisImageAnimationInterface::setFramerate(int fps)
{
m_d->framerate = fps;
......
......@@ -143,6 +143,16 @@ public:
*/
void setAudioMuted(bool value);
/**
* Returns the preferred audio value in rangle [0, 1]
*/
qreal audioVolume() const;
/**
* Set the preferred volume for the audio channel in range [0, 1]
*/
void setAudioVolume(qreal value);
public Q_SLOTS:
void setFramerate(int fps);
public:
......@@ -184,6 +194,12 @@ Q_SIGNALS:
*/
void sigAudioChannelChanged();
/**
* Emitted when audion volume changes. Please note that it doesn't change
* when you mute the channel! When muting, sigAudioChannelChanged() is used instead!
*/
void sigAudioVolumeChanged();
private:
struct Private;
const QScopedPointer<Private> m_d;
......
......@@ -79,6 +79,11 @@ bool KisSyncedAudioPlayback::isPlaying() const
return m_d->player.state() == QMediaPlayer::PlayingState;
}
void KisSyncedAudioPlayback::setVolume(qreal value)
{
m_d->player.setVolume(qRound(100.0 * value));
}
void KisSyncedAudioPlayback::setSpeed(qreal value)
{
if (qFuzzyCompare(value, m_d->player.playbackRate())) return;
......
......@@ -16,6 +16,8 @@ public:
bool isPlaying() const;
void setVolume(qreal value);
public Q_SLOTS:
void setSpeed(qreal value);
void play(qint64 startPosition);
......
......@@ -157,6 +157,7 @@ KisAnimationPlayer::KisAnimationPlayer(KisCanvas2 *canvas)
connect(&m_d->stopAudioOnScrubbingCompressor, SIGNAL(timeout()), SLOT(slotTryStopScrubbingAudio()));
connect(m_d->canvas->image()->animationInterface(), SIGNAL(sigAudioChannelChanged()), SLOT(slotAudioChannelChanged()));
connect(m_d->canvas->image()->animationInterface(), SIGNAL(sigAudioVolumeChanged()), SLOT(slotAudioVolumeChanged()));
slotAudioChannelChanged();
}
......@@ -195,15 +196,25 @@ void KisAnimationPlayer::slotTryStopScrubbingAudio()
void KisAnimationPlayer::slotAudioChannelChanged()
{
QString fileName = m_d->canvas->image()->animationInterface()->audioChannelFileName();
KisImageAnimationInterface *interface = m_d->canvas->image()->animationInterface();
QString fileName = interface->audioChannelFileName();
QFileInfo info(fileName);
if (info.exists() && !m_d->canvas->image()->animationInterface()->isAudioMuted()) {
if (info.exists() && !interface->isAudioMuted()) {
m_d->syncedAudio.reset(new KisSyncedAudioPlayback(info.absoluteFilePath()));
m_d->syncedAudio->setVolume(interface->audioVolume());
} else {
m_d->syncedAudio.reset();
}
}
void KisAnimationPlayer::slotAudioVolumeChanged()
{
KisImageAnimationInterface *interface = m_d->canvas->image()->animationInterface();
if (m_d->syncedAudio) {
m_d->syncedAudio->setVolume(interface->audioVolume());
}
}
void KisAnimationPlayer::connectCancelSignals()
{
m_d->cancelStrokeConnections.addConnection(
......
......@@ -64,6 +64,7 @@ private Q_SLOTS:
void slotSyncScrubbingAudio(int msecTime);
void slotTryStopScrubbingAudio();
void slotAudioChannelChanged();
void slotAudioVolumeChanged();
Q_SIGNALS:
void sigFrameChanged();
......
......@@ -239,6 +239,8 @@ void TimelineFramesModel::setDummiesFacade(KisDummiesFacadeBase *dummiesFacade,
SIGNAL(sigFullClipRangeChanged()), SIGNAL(sigInfiniteTimelineUpdateNeeded()));
connect(m_d->image->animationInterface(),
SIGNAL(sigAudioChannelChanged()), SIGNAL(sigAudioChannelChanged()));
connect(m_d->image->animationInterface(),
SIGNAL(sigAudioVolumeChanged()), SIGNAL(sigAudioChannelChanged()));
}
if (m_d->dummiesFacade != oldDummiesFacade) {
......@@ -670,3 +672,14 @@ void TimelineFramesModel::setAudioMuted(bool value)
KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->image);
m_d->image->animationInterface()->setAudioMuted(value);
}
qreal TimelineFramesModel::audioVolume() const
{
return m_d->image ? m_d->image->animationInterface()->audioVolume() : 0.5;
}
void TimelineFramesModel::setAudioVolume(qreal value)
{
KIS_SAFE_ASSERT_RECOVER_RETURN(m_d->image);
m_d->image->animationInterface()->setAudioVolume(value);
}
......@@ -57,6 +57,9 @@ public:
bool isAudioMuted() const;
void setAudioMuted(bool value);
qreal audioVolume() const;
void setAudioVolume(qreal value);
void setLastClickedIndex(const QModelIndex &index);
int rowCount(const QModelIndex &parent = QModelIndex()) const;
......
......@@ -54,9 +54,11 @@
#include "kis_signal_compressor.h"
#include "kis_time_range.h"
#include "kis_color_label_selector_widget.h"
#include "kis_slider_spin_box.h"
#include <KoFileDialog.h>
#include <QDesktopServices>
#include <QWidgetAction>
#include "config-qtmultimedia.h"
......@@ -100,6 +102,8 @@ struct TimelineFramesView::Private
QMenu *audioOptionsMenu;
QAction *openAudioAction;
QAction *audioMuteAction;
KisSliderSpinBox *volumeSlider;
QMenu *layerEditingMenu;
QMenu *existingLayersMenu;
......@@ -214,9 +218,23 @@ TimelineFramesView::TimelineFramesView(QWidget *parent)
connect(m_d->audioMuteAction, SIGNAL(triggered(bool)), SLOT(slotAudioChannelMute(bool)));
m_d->audioOptionsMenu->addAction(m_d->audioMuteAction);
m_d->audioOptionsMenu->addAction(i18nc("@item:inmenu", "Remove audio"), this, SLOT(slotAudioChannelRemove()));
m_d->audioOptionsMenu->addSeparator();
m_d->volumeSlider = new KisSliderSpinBox(this);
m_d->volumeSlider->setRange(0, 100);
m_d->volumeSlider->setSuffix("%");
m_d->volumeSlider->setPrefix(i18nc("@item:inmenu, slider", "Volume:"));
m_d->volumeSlider->setSingleStep(1);
m_d->volumeSlider->setPageStep(10);
m_d->volumeSlider->setSizePolicy(QSizePolicy::Ignored, QSizePolicy::Fixed);
connect(m_d->volumeSlider, SIGNAL(valueChanged(int)), SLOT(slotAudioVolumeChanged(int)));
QWidgetAction *volumeAction = new QWidgetAction(m_d->audioOptionsMenu);
volumeAction->setDefaultWidget(m_d->volumeSlider);
m_d->audioOptionsMenu->addAction(volumeAction);
m_d->audioOptionsButton->setMenu(m_d->audioOptionsMenu);
/********** Frame Editing Context Menu ***********************************************/
......@@ -450,6 +468,16 @@ void TimelineFramesView::slotUpdateAudioActions()
}
m_d->audioOptionsButton->setIcon(audioIcon);
m_d->volumeSlider->setEnabled(!m_d->model->isAudioMuted());
KisSignalsBlocker b(m_d->volumeSlider);
m_d->volumeSlider->setValue(qRound(m_d->model->audioVolume() * 100.0));
}
void TimelineFramesView::slotAudioVolumeChanged(int value)
{
m_d->model->setAudioVolume(qreal(value) / 100.0);
}
void TimelineFramesView::slotUpdateInfiniteFramesCount()
......
......@@ -77,6 +77,7 @@ private Q_SLOTS:
void slotAudioChannelMute(bool value);
void slotAudioChannelRemove();
void slotUpdateAudioActions();
void slotAudioVolumeChanged(int value);
private:
void setFramesPerSecond(int fps);
......
......@@ -1117,8 +1117,6 @@ void KisKraLoader::loadAudio(const KoXmlElement& elem, KisImageSP image)
fileName = QDir::toNativeSeparators(fileName);
QDir baseDirectory = QFileInfo(m_d->document->localFilePath()).absoluteDir();
qDebug() << ppVar(baseDirectory);
fileName = baseDirectory.absoluteFilePath(fileName);
QFileInfo info(fileName);
......@@ -1129,4 +1127,14 @@ void KisKraLoader::loadAudio(const KoXmlElement& elem, KisImageSP image)
image->animationInterface()->setAudioChannelFileName(info.absoluteFilePath());
}
}
bool audioMuted = false;
if (KisDomUtils::loadValue(qElement, "audioMuted", &audioMuted)) {
image->animationInterface()->setAudioMuted(audioMuted);
}
qreal audioVolume = 0.5;
if (KisDomUtils::loadValue(qElement, "audioVolume", &audioVolume)) {
image->animationInterface()->setAudioVolume(audioVolume);
}
}
......@@ -424,7 +424,8 @@ bool KisKraSaver::saveGuides(QDomDocument& doc, QDomElement& element)
bool KisKraSaver::saveAudio(QDomDocument& doc, QDomElement& element)
{
QString fileName = m_d->doc->image()->animationInterface()->audioChannelFileName();
const KisImageAnimationInterface *interface = m_d->doc->image()->animationInterface();
QString fileName = interface->audioChannelFileName();
if (fileName.isEmpty()) return true;
if (!QFileInfo::exists(fileName)) {
......@@ -442,6 +443,8 @@ bool KisKraSaver::saveAudio(QDomDocument& doc, QDomElement& element)
QDomElement audioElement = doc.createElement("audio");
KisDomUtils::saveValue(&audioElement, "masterChannelPath", fileName);
KisDomUtils::saveValue(&audioElement, "audioMuted", interface->isAudioMuted());
KisDomUtils::saveValue(&audioElement, "audioVolume", interface->audioVolume());
element.appendChild(audioElement);
return true;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment