2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
2018-06-28 01:15:32 +02:00
|
|
|
* This file was part of Amarok / Clementine
|
2018-02-27 18:06:05 +01:00
|
|
|
* Copyright 2003 Mark Kretschmann
|
2018-06-28 01:15:32 +02:00
|
|
|
* Copyright 2004 - 2005 Max Howell, <max.howell@methylblue.com>
|
|
|
|
* Copyright 2010 David Sansome <me@davidsansome.com>
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2017-2021 Jonas Kvinge <jonas@jkvinge.net>
|
2018-02-27 18:06:05 +01:00
|
|
|
*
|
|
|
|
* Strawberry 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.
|
|
|
|
*
|
|
|
|
* Strawberry 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
|
2019-02-22 20:24:38 +01:00
|
|
|
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
2018-02-27 18:06:05 +01:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
2018-05-01 00:41:33 +02:00
|
|
|
|
|
|
|
#include <QtGlobal>
|
2018-06-28 01:15:32 +02:00
|
|
|
#include <QVariant>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QUrl>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QSettings>
|
|
|
|
|
|
|
|
#include "core/timeconstants.h"
|
2020-11-04 22:22:26 +01:00
|
|
|
#include "core/networkproxyfactory.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "engine_fwd.h"
|
|
|
|
#include "enginebase.h"
|
2018-06-28 01:15:32 +02:00
|
|
|
#include "settings/backendsettingspage.h"
|
2020-11-04 22:16:20 +01:00
|
|
|
#include "settings/networkproxysettingspage.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
Engine::Base::Base()
|
2019-03-09 16:48:45 +01:00
|
|
|
: volume_(100),
|
2018-02-27 18:06:05 +01:00
|
|
|
beginning_nanosec_(0),
|
|
|
|
end_nanosec_(0),
|
|
|
|
scope_(kScopeSize),
|
2018-06-28 01:15:32 +02:00
|
|
|
output_(""),
|
2018-06-28 23:12:39 +02:00
|
|
|
device_(QVariant()),
|
2018-06-28 01:15:32 +02:00
|
|
|
rg_enabled_(false),
|
|
|
|
rg_mode_(0),
|
2021-04-22 21:55:26 +02:00
|
|
|
rg_preamp_(0.0),
|
|
|
|
rg_fallbackgain_(0.0),
|
2018-06-28 01:15:32 +02:00
|
|
|
rg_compression_(true),
|
2020-10-07 20:29:26 +02:00
|
|
|
buffer_duration_nanosec_(BackendSettingsPage::kDefaultBufferDuration * kNsecPerMsec),
|
|
|
|
buffer_low_watermark_(BackendSettingsPage::kDefaultBufferLowWatermark),
|
|
|
|
buffer_high_watermark_(BackendSettingsPage::kDefaultBufferHighWatermark),
|
2018-02-27 18:06:05 +01:00
|
|
|
fadeout_enabled_(true),
|
|
|
|
crossfade_enabled_(true),
|
|
|
|
autocrossfade_enabled_(false),
|
|
|
|
crossfade_same_album_(false),
|
2019-04-08 18:46:11 +02:00
|
|
|
fadeout_pause_enabled_(false),
|
2018-06-28 01:15:32 +02:00
|
|
|
fadeout_duration_(2),
|
|
|
|
fadeout_duration_nanosec_(2 * kNsecPerSec),
|
2020-11-04 22:16:20 +01:00
|
|
|
proxy_authentication_(false),
|
2018-02-27 18:06:05 +01:00
|
|
|
about_to_end_emitted_(false) {}
|
|
|
|
|
|
|
|
Engine::Base::~Base() {}
|
|
|
|
|
2019-09-07 23:34:13 +02:00
|
|
|
bool Engine::Base::Load(const QUrl &stream_url, const QUrl &original_url, TrackChangeFlags, bool force_stop_at_end, quint64 beginning_nanosec, qint64 end_nanosec) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
Q_UNUSED(force_stop_at_end);
|
|
|
|
|
2019-09-07 23:34:13 +02:00
|
|
|
stream_url_ = stream_url;
|
2018-09-22 23:13:56 +02:00
|
|
|
original_url_ = original_url;
|
2018-02-27 18:06:05 +01:00
|
|
|
beginning_nanosec_ = beginning_nanosec;
|
|
|
|
end_nanosec_ = end_nanosec;
|
|
|
|
|
|
|
|
about_to_end_emitted_ = false;
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-09-07 23:34:13 +02:00
|
|
|
bool Engine::Base::Play(const QUrl &stream_url, const QUrl &original_url, TrackChangeFlags flags, bool force_stop_at_end, quint64 beginning_nanosec, qint64 end_nanosec) {
|
2018-06-28 01:15:32 +02:00
|
|
|
|
2019-09-07 23:34:13 +02:00
|
|
|
if (!Load(stream_url, original_url, flags, force_stop_at_end, beginning_nanosec, end_nanosec))
|
2018-06-28 01:15:32 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
return Play(0);
|
2018-09-22 23:13:56 +02:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
}
|
|
|
|
|
2019-11-08 23:07:21 +01:00
|
|
|
void Engine::Base::SetVolume(const uint value) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
volume_ = value;
|
|
|
|
SetVolumeSW(MakeVolumeLogarithmic(value));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
uint Engine::Base::MakeVolumeLogarithmic(uint volume) {
|
|
|
|
// We're using a logarithmic function to make the volume ramp more natural.
|
|
|
|
return static_cast<uint>( 100 - 100.0 * std::log10( ( 100 - volume ) * 0.09 + 1.0 ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Engine::Base::ReloadSettings() {
|
|
|
|
|
|
|
|
QSettings s;
|
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
s.beginGroup(BackendSettingsPage::kSettingsGroup);
|
2019-01-09 20:02:40 +01:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
output_ = s.value("output").toString();
|
|
|
|
device_ = s.value("device");
|
2019-01-09 20:02:40 +01:00
|
|
|
|
2019-03-09 16:48:45 +01:00
|
|
|
volume_control_ = s.value("volume_control", true).toBool();
|
|
|
|
|
2020-10-07 20:29:26 +02:00
|
|
|
buffer_duration_nanosec_ = s.value("bufferduration", BackendSettingsPage::kDefaultBufferDuration).toLongLong() * kNsecPerMsec;
|
|
|
|
buffer_low_watermark_ = s.value("bufferlowwatermark", BackendSettingsPage::kDefaultBufferLowWatermark).toDouble();
|
|
|
|
buffer_high_watermark_ = s.value("bufferhighwatermark", BackendSettingsPage::kDefaultBufferHighWatermark).toDouble();
|
2019-01-09 20:02:40 +01:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
rg_enabled_ = s.value("rgenabled", false).toBool();
|
|
|
|
rg_mode_ = s.value("rgmode", 0).toInt();
|
2021-04-22 21:55:26 +02:00
|
|
|
rg_preamp_ = s.value("rgpreamp", 0.0).toDouble();
|
|
|
|
rg_fallbackgain_ = s.value("rgfallbackgain", 0.0).toDouble();
|
2018-06-28 01:15:32 +02:00
|
|
|
rg_compression_ = s.value("rgcompression", true).toBool();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
fadeout_enabled_ = s.value("FadeoutEnabled", false).toBool();
|
|
|
|
crossfade_enabled_ = s.value("CrossfadeEnabled", false).toBool();
|
|
|
|
autocrossfade_enabled_ = s.value("AutoCrossfadeEnabled", false).toBool();
|
|
|
|
crossfade_same_album_ = !s.value("NoCrossfadeSameAlbum", true).toBool();
|
|
|
|
fadeout_pause_enabled_ = s.value("FadeoutPauseEnabled", false).toBool();
|
2018-06-28 01:15:32 +02:00
|
|
|
fadeout_duration_ = s.value("FadeoutDuration", 2000).toLongLong();
|
|
|
|
fadeout_duration_nanosec_ = (fadeout_duration_ * kNsecPerMsec);
|
|
|
|
fadeout_pause_duration_ = s.value("FadeoutPauseDuration", 250).toLongLong();
|
|
|
|
fadeout_pause_duration_nanosec_ = (fadeout_pause_duration_ * kNsecPerMsec);
|
2019-01-09 20:02:40 +01:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
s.endGroup();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-11-04 22:16:20 +01:00
|
|
|
s.beginGroup(NetworkProxySettingsPage::kSettingsGroup);
|
2020-11-04 22:22:26 +01:00
|
|
|
NetworkProxyFactory::Mode proxy_mode = NetworkProxyFactory::Mode(s.value("mode", NetworkProxyFactory::Mode_System).toInt());
|
|
|
|
if (proxy_mode == NetworkProxyFactory::Mode_Manual && s.contains("engine") && s.value("engine").toBool()) {
|
2020-11-04 22:16:20 +01:00
|
|
|
QString proxy_host = s.value("hostname").toString();
|
|
|
|
int proxy_port = s.value("port").toInt();
|
|
|
|
if (proxy_host.isEmpty() || proxy_port <= 0) {
|
|
|
|
proxy_address_.clear();
|
|
|
|
proxy_authentication_ = false;
|
|
|
|
proxy_user_.clear();
|
|
|
|
proxy_pass_.clear();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
proxy_address_ = QString("%1:%2").arg(proxy_host).arg(proxy_port);
|
|
|
|
proxy_authentication_ = s.value("use_authentication").toBool();
|
|
|
|
proxy_user_ = s.value("username").toString();
|
|
|
|
proxy_pass_ = s.value("password").toString();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
proxy_address_.clear();
|
|
|
|
proxy_authentication_ = false;
|
|
|
|
proxy_user_.clear();
|
|
|
|
proxy_pass_.clear();
|
|
|
|
}
|
|
|
|
s.endGroup();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void Engine::Base::EmitAboutToEnd() {
|
|
|
|
|
|
|
|
if (about_to_end_emitted_)
|
|
|
|
return;
|
|
|
|
|
|
|
|
about_to_end_emitted_ = true;
|
|
|
|
emit TrackAboutToEnd();
|
|
|
|
}
|
2018-07-01 01:29:52 +02:00
|
|
|
|
|
|
|
bool Engine::Base::ValidOutput(const QString &output) {
|
|
|
|
|
2019-09-15 20:27:32 +02:00
|
|
|
Q_UNUSED(output);
|
|
|
|
|
2018-07-01 01:29:52 +02:00
|
|
|
return (true);
|
|
|
|
|
|
|
|
}
|