2010-03-24 00:11:46 +01:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-03-24 00:11:46 +01:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
// Copyright: (C) 2003 Mark Kretschmann
|
2009-12-24 20:16:07 +01:00
|
|
|
// (C) 2004,2005 Max Howell, <max.howell@methylblue.com>
|
2014-02-07 16:34:20 +01:00
|
|
|
// License: See COPYING
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
#include "enginebase.h"
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
#include <QSettings>
|
2009-12-24 20:16:07 +01:00
|
|
|
#include <cmath>
|
|
|
|
|
2020-09-18 16:15:19 +02:00
|
|
|
#include "core/timeconstants.h"
|
2010-04-12 01:03:39 +02:00
|
|
|
|
2010-02-03 17:51:56 +01:00
|
|
|
const char* Engine::Base::kSettingsGroup = "Player";
|
2009-12-24 20:16:07 +01:00
|
|
|
|
|
|
|
Engine::Base::Base()
|
2014-02-07 16:34:20 +01:00
|
|
|
: volume_(50),
|
|
|
|
beginning_nanosec_(0),
|
|
|
|
end_nanosec_(0),
|
|
|
|
scope_(kScopeSize),
|
|
|
|
fadeout_enabled_(true),
|
|
|
|
fadeout_duration_nanosec_(2 * kNsecPerSec), // 2s
|
|
|
|
crossfade_enabled_(true),
|
|
|
|
autocrossfade_enabled_(false),
|
|
|
|
crossfade_same_album_(false),
|
|
|
|
about_to_end_emitted_(false) {}
|
|
|
|
|
|
|
|
Engine::Base::~Base() {}
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2020-02-18 07:24:07 +01:00
|
|
|
bool Engine::Base::Load(const MediaPlaybackRequest& req, TrackChangeFlags,
|
2014-02-07 16:34:20 +01:00
|
|
|
bool force_stop_at_end, quint64 beginning_nanosec,
|
|
|
|
qint64 end_nanosec) {
|
2011-03-29 00:11:07 +02:00
|
|
|
Q_UNUSED(force_stop_at_end);
|
|
|
|
|
2020-02-18 07:24:07 +01:00
|
|
|
playback_req_ = req;
|
2011-02-13 19:29:27 +01:00
|
|
|
beginning_nanosec_ = beginning_nanosec;
|
|
|
|
end_nanosec_ = end_nanosec;
|
2011-01-02 19:53:45 +01:00
|
|
|
|
2010-04-12 01:52:16 +02:00
|
|
|
about_to_end_emitted_ = false;
|
2010-04-12 01:24:03 +02:00
|
|
|
return true;
|
|
|
|
}
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-04-12 01:24:03 +02:00
|
|
|
void Engine::Base::SetVolume(uint value) {
|
|
|
|
volume_ = value;
|
2009-12-24 20:16:07 +01:00
|
|
|
|
2010-04-12 01:24:03 +02:00
|
|
|
SetVolumeSW(MakeVolumeLogarithmic(value));
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
|
|
|
|
2010-04-12 01:24:03 +02:00
|
|
|
uint Engine::Base::MakeVolumeLogarithmic(uint volume) {
|
|
|
|
// We're using a logarithmic function to make the volume ramp more natural.
|
2014-02-07 16:34:20 +01:00
|
|
|
return static_cast<uint>(100 -
|
|
|
|
100.0 * std::log10((100 - volume) * 0.09 + 1.0));
|
2009-12-24 20:16:07 +01:00
|
|
|
}
|
2010-04-12 01:03:39 +02:00
|
|
|
|
|
|
|
void Engine::Base::ReloadSettings() {
|
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
|
|
|
fadeout_enabled_ = s.value("FadeoutEnabled", true).toBool();
|
2014-02-07 16:34:20 +01:00
|
|
|
fadeout_duration_nanosec_ =
|
|
|
|
s.value("FadeoutDuration", 2000).toLongLong() * kNsecPerMsec;
|
2010-04-12 01:03:39 +02:00
|
|
|
crossfade_enabled_ = s.value("CrossfadeEnabled", true).toBool();
|
2010-04-12 01:52:16 +02:00
|
|
|
autocrossfade_enabled_ = s.value("AutoCrossfadeEnabled", false).toBool();
|
2011-03-13 19:37:46 +01:00
|
|
|
crossfade_same_album_ = !s.value("NoCrossfadeSameAlbum", true).toBool();
|
2013-04-22 21:42:04 +02:00
|
|
|
fadeout_pause_enabled_ = s.value("FadeoutPauseEnabled", false).toBool();
|
2014-02-07 16:34:20 +01:00
|
|
|
fadeout_pause_duration_nanosec_ =
|
|
|
|
s.value("FadeoutPauseDuration", 250).toLongLong() * kNsecPerMsec;
|
2010-04-12 01:52:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Engine::Base::EmitAboutToEnd() {
|
2014-02-07 16:34:20 +01:00
|
|
|
if (about_to_end_emitted_) return;
|
2010-04-12 01:52:16 +02:00
|
|
|
|
|
|
|
about_to_end_emitted_ = true;
|
|
|
|
emit TrackAboutToEnd();
|
2010-04-12 01:03:39 +02:00
|
|
|
}
|
2010-06-14 21:15:10 +02:00
|
|
|
|
2014-02-07 16:34:20 +01:00
|
|
|
int Engine::Base::AddBackgroundStream(const QUrl& url) { return -1; }
|
2010-09-26 22:59:41 +02:00
|
|
|
|
2020-02-18 07:24:07 +01:00
|
|
|
bool Engine::Base::Play(const MediaPlaybackRequest& req, TrackChangeFlags c,
|
2014-02-07 16:34:20 +01:00
|
|
|
bool force_stop_at_end, quint64 beginning_nanosec,
|
|
|
|
qint64 end_nanosec) {
|
2020-02-18 07:24:07 +01:00
|
|
|
if (!Load(req, c, force_stop_at_end, beginning_nanosec, end_nanosec))
|
2010-09-26 22:59:41 +02:00
|
|
|
return false;
|
2011-01-02 19:53:45 +01:00
|
|
|
|
|
|
|
return Play(0);
|
2010-09-26 22:59:41 +02:00
|
|
|
}
|