2018-02-27 18:06:05 +01:00
|
|
|
/*
|
|
|
|
* Strawberry Music Player
|
2021-03-20 21:14:47 +01:00
|
|
|
* Copyright 2013-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
|
|
|
|
* along with Strawberry. If not, see <http://www.gnu.org/licenses/>.
|
2018-08-09 18:39:44 +02:00
|
|
|
*
|
2018-02-27 18:06:05 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QtGlobal>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QWidget>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QSettings>
|
2020-10-24 03:32:40 +02:00
|
|
|
#include <QMetaType>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QList>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QVariant>
|
2018-03-04 03:10:07 +01:00
|
|
|
#include <QString>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QStringList>
|
2020-07-18 04:05:07 +02:00
|
|
|
#include <QRegularExpression>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QFontMetrics>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QAbstractItemView>
|
|
|
|
#include <QListView>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QGroupBox>
|
|
|
|
#include <QCheckBox>
|
|
|
|
#include <QComboBox>
|
|
|
|
#include <QSlider>
|
|
|
|
#include <QSpinBox>
|
|
|
|
#include <QLabel>
|
2020-02-09 02:29:35 +01:00
|
|
|
#include <QRadioButton>
|
2018-05-01 00:41:33 +02:00
|
|
|
|
|
|
|
#include "backendsettingspage.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
#include "core/application.h"
|
|
|
|
#include "core/iconloader.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "core/player.h"
|
2018-06-28 01:15:32 +02:00
|
|
|
#include "core/logging.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "engine/engine_fwd.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
#include "engine/enginebase.h"
|
2019-11-03 19:53:08 +01:00
|
|
|
#include "engine/devicefinders.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "engine/enginetype.h"
|
|
|
|
#include "engine/devicefinder.h"
|
|
|
|
#include "widgets/lineedit.h"
|
|
|
|
#include "widgets/stickyslider.h"
|
2018-04-05 21:40:05 +02:00
|
|
|
#include "dialogs/errordialog.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "settings/settingspage.h"
|
|
|
|
#include "settingsdialog.h"
|
|
|
|
#include "ui_backendsettingspage.h"
|
2018-04-05 21:40:05 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
const char *BackendSettingsPage::kSettingsGroup = "Backend";
|
2021-05-11 19:14:00 +02:00
|
|
|
const char *BackendSettingsPage::kOutputAutomaticallySelect = "Automatically select";
|
|
|
|
const char *BackendSettingsPage::kOutputCustom = "Custom";
|
2020-10-07 20:29:26 +02:00
|
|
|
const qint64 BackendSettingsPage::kDefaultBufferDuration = 4000;
|
|
|
|
const double BackendSettingsPage::kDefaultBufferLowWatermark = 0.33;
|
|
|
|
const double BackendSettingsPage::kDefaultBufferHighWatermark = 0.99;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
BackendSettingsPage::BackendSettingsPage(SettingsDialog *dialog) :
|
|
|
|
SettingsPage(dialog),
|
|
|
|
ui_(new Ui_BackendSettingsPage),
|
|
|
|
configloaded_(false),
|
|
|
|
engineloaded_(false) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
ui_->setupUi(this);
|
|
|
|
setWindowIcon(IconLoader::Load("soundcard"));
|
|
|
|
|
2019-07-08 23:27:45 +02:00
|
|
|
#if (QT_VERSION >= QT_VERSION_CHECK(5, 11, 0))
|
2019-07-08 22:19:14 +02:00
|
|
|
ui_->label_replaygainpreamp->setMinimumWidth(QFontMetrics(ui_->label_replaygainpreamp->font()).horizontalAdvance("-WW.W dB"));
|
2021-04-22 21:55:26 +02:00
|
|
|
ui_->label_replaygainfallbackgain->setMinimumWidth(QFontMetrics(ui_->label_replaygainfallbackgain->font()).horizontalAdvance("-WW.W dB"));
|
2019-07-08 23:27:45 +02:00
|
|
|
#else
|
|
|
|
ui_->label_replaygainpreamp->setMinimumWidth(QFontMetrics(ui_->label_replaygainpreamp->font()).width("-WW.W dB"));
|
2021-04-22 21:55:26 +02:00
|
|
|
ui_->label_replaygainfallbackgain->setMinimumWidth(QFontMetrics(ui_->label_replaygainfallbackgain->font()).width("-WW.W dB"));
|
2019-07-08 23:27:45 +02:00
|
|
|
#endif
|
2018-04-05 21:40:05 +02:00
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
QObject::connect(ui_->combobox_engine, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &BackendSettingsPage::EngineChanged);
|
|
|
|
QObject::connect(ui_->combobox_output, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &BackendSettingsPage::OutputChanged);
|
|
|
|
QObject::connect(ui_->combobox_device, QOverload<int>::of(&QComboBox::currentIndexChanged), this, &BackendSettingsPage::DeviceSelectionChanged);
|
|
|
|
QObject::connect(ui_->lineedit_device, &QLineEdit::textChanged, this, &BackendSettingsPage::DeviceStringChanged);
|
|
|
|
#ifdef HAVE_ALSA
|
|
|
|
QObject::connect(ui_->radiobutton_alsa_hw, &QRadioButton::clicked, this, &BackendSettingsPage::radiobutton_alsa_hw_clicked);
|
|
|
|
QObject::connect(ui_->radiobutton_alsa_plughw, &QRadioButton::clicked, this, &BackendSettingsPage::radiobutton_alsa_plughw_clicked);
|
|
|
|
QObject::connect(ui_->radiobutton_alsa_pcm, &QRadioButton::clicked, this, &BackendSettingsPage::radiobutton_alsa_pcm_clicked);
|
|
|
|
#endif
|
|
|
|
QObject::connect(ui_->stickyslider_replaygainpreamp, &StickySlider::valueChanged, this, &BackendSettingsPage::RgPreampChanged);
|
|
|
|
QObject::connect(ui_->stickyslider_replaygainfallbackgain, &StickySlider::valueChanged, this, &BackendSettingsPage::RgFallbackGainChanged);
|
|
|
|
QObject::connect(ui_->checkbox_fadeout_stop, &QCheckBox::toggled, this, &BackendSettingsPage::FadingOptionsChanged);
|
|
|
|
QObject::connect(ui_->checkbox_fadeout_cross, &QCheckBox::toggled, this, &BackendSettingsPage::FadingOptionsChanged);
|
|
|
|
QObject::connect(ui_->checkbox_fadeout_auto, &QCheckBox::toggled, this, &BackendSettingsPage::FadingOptionsChanged);
|
|
|
|
QObject::connect(ui_->checkbox_volume_control, &QCheckBox::toggled, this, &BackendSettingsPage::FadingOptionsChanged);
|
|
|
|
QObject::connect(ui_->checkbox_channels, &QCheckBox::toggled, ui_->widget_channels, &QSpinBox::setEnabled);
|
|
|
|
QObject::connect(ui_->button_buffer_defaults, &QPushButton::clicked, this, &BackendSettingsPage::BufferDefaults);
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
BackendSettingsPage::~BackendSettingsPage() {
|
|
|
|
|
|
|
|
delete ui_;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackendSettingsPage::Load() {
|
|
|
|
|
|
|
|
configloaded_ = false;
|
2018-06-28 01:15:32 +02:00
|
|
|
engineloaded_ = false;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-10-01 22:04:38 +02:00
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
|
|
|
Engine::EngineType enginetype = Engine::EngineTypeFromName(s.value("engine", EngineName(Engine::None)).toString());
|
2018-07-01 01:29:52 +02:00
|
|
|
if (enginetype == Engine::None && engine()) enginetype = engine()->type();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
ui_->combobox_engine->clear();
|
|
|
|
#ifdef HAVE_GSTREAMER
|
2020-08-16 18:22:10 +02:00
|
|
|
ui_->combobox_engine->addItem(IconLoader::Load("gstreamer"), EngineDescription(Engine::GStreamer), QVariant::fromValue(static_cast<int>(Engine::GStreamer)));
|
2018-02-27 18:06:05 +01:00
|
|
|
#endif
|
|
|
|
#ifdef HAVE_VLC
|
2020-08-16 18:22:10 +02:00
|
|
|
ui_->combobox_engine->addItem(IconLoader::Load("vlc"), EngineDescription(Engine::VLC), QVariant::fromValue(static_cast<int>(Engine::VLC)));
|
2018-06-28 01:15:32 +02:00
|
|
|
#endif
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-07-01 01:29:52 +02:00
|
|
|
enginetype_current_ = enginetype;
|
2020-10-01 22:04:38 +02:00
|
|
|
output_current_ = s.value("output", QString()).toString();
|
|
|
|
device_current_ = s.value("device", QVariant());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-08-16 18:22:10 +02:00
|
|
|
ui_->combobox_engine->setCurrentIndex(ui_->combobox_engine->findData(static_cast<int>(enginetype)));
|
2020-10-17 17:29:09 +02:00
|
|
|
if (EngineInitialized()) Load_Engine(enginetype);
|
2018-04-05 21:40:05 +02:00
|
|
|
|
2020-10-01 22:04:38 +02:00
|
|
|
ui_->checkbox_volume_control->setChecked(s.value("volume_control", true).toBool());
|
2019-06-17 02:23:51 +02:00
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
ui_->checkbox_channels->setChecked(s.value("channels_enabled", false).toBool());
|
|
|
|
ui_->spinbox_channels->setValue(s.value("channels", 2).toInt());
|
|
|
|
ui_->widget_channels->setEnabled(ui_->checkbox_channels->isChecked());
|
2020-10-07 20:29:26 +02:00
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
ui_->spinbox_bufferduration->setValue(s.value("bufferduration", kDefaultBufferDuration).toInt());
|
2020-10-07 20:29:26 +02:00
|
|
|
ui_->spinbox_low_watermark->setValue(s.value("bufferlowwatermark", kDefaultBufferLowWatermark).toDouble());
|
|
|
|
ui_->spinbox_high_watermark->setValue(s.value("bufferhighwatermark", kDefaultBufferHighWatermark).toDouble());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-10-01 22:04:38 +02:00
|
|
|
ui_->checkbox_replaygain->setChecked(s.value("rgenabled", false).toBool());
|
|
|
|
ui_->combobox_replaygainmode->setCurrentIndex(s.value("rgmode", 0).toInt());
|
2021-04-22 21:55:26 +02:00
|
|
|
ui_->stickyslider_replaygainpreamp->setValue(static_cast<int>(s.value("rgpreamp", 0.0).toDouble() * 10 + 600));
|
2020-10-01 22:04:38 +02:00
|
|
|
ui_->checkbox_replaygaincompression->setChecked(s.value("rgcompression", true).toBool());
|
2021-04-22 21:55:26 +02:00
|
|
|
ui_->stickyslider_replaygainfallbackgain->setValue(static_cast<int>(s.value("rgfallbackgain", 0.0).toDouble() * 10 + 600));
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
#ifdef HAVE_ALSA
|
2019-02-20 21:21:33 +01:00
|
|
|
bool fade_default = false;
|
|
|
|
#else
|
|
|
|
bool fade_default = true;
|
|
|
|
#endif
|
|
|
|
|
2020-10-01 22:04:38 +02:00
|
|
|
ui_->checkbox_fadeout_stop->setChecked(s.value("FadeoutEnabled", fade_default).toBool());
|
|
|
|
ui_->checkbox_fadeout_cross->setChecked(s.value("CrossfadeEnabled", fade_default).toBool());
|
|
|
|
ui_->checkbox_fadeout_auto->setChecked(s.value("AutoCrossfadeEnabled", false).toBool());
|
|
|
|
ui_->checkbox_fadeout_samealbum->setChecked(s.value("NoCrossfadeSameAlbum", true).toBool());
|
|
|
|
ui_->checkbox_fadeout_pauseresume->setChecked(s.value("FadeoutPauseEnabled", false).toBool());
|
|
|
|
ui_->spinbox_fadeduration->setValue(s.value("FadeoutDuration", 2000).toInt());
|
|
|
|
ui_->spinbox_fadeduration_pauseresume->setValue(s.value("FadeoutPauseDuration", 250).toInt());
|
2019-01-09 20:02:40 +01:00
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
#ifdef HAVE_ALSA
|
2019-03-09 16:48:45 +01:00
|
|
|
ui_->lineedit_device->show();
|
|
|
|
ui_->widget_alsa_plugin->show();
|
2020-10-01 22:04:38 +02:00
|
|
|
int alsaplug_int = alsa_plugin(s.value("alsaplugin", 0).toInt());
|
2018-09-21 23:29:00 +02:00
|
|
|
if (alsa_plugin(alsaplug_int)) {
|
|
|
|
alsa_plugin alsaplugin = alsa_plugin(alsaplug_int);
|
|
|
|
switch (alsaplugin) {
|
|
|
|
case alsa_plugin::alsa_hw:
|
|
|
|
ui_->radiobutton_alsa_hw->setChecked(true);
|
|
|
|
break;
|
|
|
|
case alsa_plugin::alsa_plughw:
|
|
|
|
ui_->radiobutton_alsa_plughw->setChecked(true);
|
|
|
|
break;
|
2021-05-11 19:14:00 +02:00
|
|
|
case alsa_plugin::alsa_pcm:
|
|
|
|
ui_->radiobutton_alsa_pcm->setChecked(true);
|
|
|
|
break;
|
2018-09-21 23:29:00 +02:00
|
|
|
}
|
|
|
|
}
|
2019-03-09 16:48:45 +01:00
|
|
|
#else
|
|
|
|
ui_->lineedit_device->hide();
|
|
|
|
ui_->widget_alsa_plugin->hide();
|
|
|
|
#endif
|
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (!EngineInitialized()) return;
|
2018-04-06 22:13:11 +02:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
if (engine()->state() == Engine::Empty) {
|
|
|
|
if (ui_->combobox_engine->count() > 1) ui_->combobox_engine->setEnabled(true);
|
|
|
|
else ui_->combobox_engine->setEnabled(false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui_->combobox_engine->setEnabled(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
configloaded_ = true;
|
|
|
|
|
2019-06-17 02:23:51 +02:00
|
|
|
FadingOptionsChanged();
|
2021-04-22 21:55:26 +02:00
|
|
|
RgPreampChanged(ui_->stickyslider_replaygainpreamp->value());
|
|
|
|
RgFallbackGainChanged(ui_->stickyslider_replaygainfallbackgain->value());
|
2019-06-17 02:23:51 +02:00
|
|
|
|
2020-05-26 00:02:16 +02:00
|
|
|
Init(ui_->layout_backendsettingspage->parentWidget());
|
2020-10-12 17:20:18 +02:00
|
|
|
if (!QSettings().childGroups().contains(kSettingsGroup)) set_changed();
|
2020-05-25 23:56:54 +02:00
|
|
|
|
2020-10-01 19:53:07 +02:00
|
|
|
// Check if engine, output or device is set to a different setting than the configured to force saving settings.
|
|
|
|
|
|
|
|
enginetype = ui_->combobox_engine->itemData(ui_->combobox_engine->currentIndex()).value<Engine::EngineType>();
|
|
|
|
QString output_name;
|
|
|
|
if (ui_->combobox_output->currentText().isEmpty()) output_name = engine()->DefaultOutput();
|
|
|
|
else {
|
|
|
|
EngineBase::OutputDetails output = ui_->combobox_output->itemData(ui_->combobox_output->currentIndex()).value<EngineBase::OutputDetails>();
|
|
|
|
output_name = output.name;
|
|
|
|
}
|
|
|
|
QVariant device_value;
|
|
|
|
if (ui_->combobox_device->currentText().isEmpty()) device_value = QVariant();
|
2021-05-11 19:14:00 +02:00
|
|
|
else if (ui_->combobox_device->currentText() == kOutputCustom) device_value = ui_->lineedit_device->text();
|
2020-10-01 19:53:07 +02:00
|
|
|
else device_value = ui_->combobox_device->itemData(ui_->combobox_device->currentIndex()).value<QVariant>();
|
|
|
|
|
|
|
|
if (enginetype_current_ != enginetype || output_name != output_current_ || device_value != device_current_) {
|
|
|
|
set_changed();
|
|
|
|
}
|
|
|
|
|
2020-10-01 22:04:38 +02:00
|
|
|
s.endGroup();
|
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
}
|
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
bool BackendSettingsPage::EngineInitialized() {
|
2018-06-28 01:15:32 +02:00
|
|
|
|
|
|
|
if (!engine() || engine()->type() == Engine::None) {
|
|
|
|
errordialog_.ShowMessage("Engine is not initialized! Please restart.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return true;
|
2018-04-05 21:40:05 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
2020-10-07 20:29:26 +02:00
|
|
|
void BackendSettingsPage::Load_Engine(const Engine::EngineType enginetype) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (!EngineInitialized()) return;
|
2018-06-28 01:15:32 +02:00
|
|
|
|
2018-07-01 01:29:52 +02:00
|
|
|
QString output = output_current_;
|
|
|
|
QVariant device = device_current_;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
ui_->combobox_output->clear();
|
|
|
|
ui_->combobox_device->clear();
|
|
|
|
|
|
|
|
ui_->combobox_output->setEnabled(false);
|
|
|
|
ui_->combobox_device->setEnabled(false);
|
|
|
|
|
|
|
|
ui_->lineedit_device->setEnabled(false);
|
2020-10-01 19:53:07 +02:00
|
|
|
ui_->lineedit_device->clear();
|
2018-07-01 01:29:52 +02:00
|
|
|
|
2018-04-05 21:40:05 +02:00
|
|
|
ui_->groupbox_replaygain->setEnabled(false);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
if (engine()->type() != enginetype) {
|
2018-07-01 01:29:52 +02:00
|
|
|
qLog(Debug) << "Switching engine.";
|
2018-10-17 22:55:36 +02:00
|
|
|
Engine::EngineType new_enginetype = dialog()->app()->player()->CreateEngine(enginetype);
|
2018-02-27 18:06:05 +01:00
|
|
|
dialog()->app()->player()->Init();
|
2018-10-17 22:55:36 +02:00
|
|
|
if (new_enginetype != enginetype) {
|
2020-08-16 18:22:10 +02:00
|
|
|
ui_->combobox_engine->setCurrentIndex(ui_->combobox_engine->findData(static_cast<int>(engine()->type())));
|
2018-10-17 22:55:36 +02:00
|
|
|
}
|
2020-10-01 19:53:07 +02:00
|
|
|
set_changed();
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
engineloaded_ = true;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
Load_Output(output, device);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
void BackendSettingsPage::Load_Output(QString output, QVariant device) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (!EngineInitialized()) return;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-10-17 22:55:36 +02:00
|
|
|
if (output.isEmpty()) output = engine()->DefaultOutput();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
ui_->combobox_output->clear();
|
2018-06-28 01:15:32 +02:00
|
|
|
for (const EngineBase::OutputDetails &o : engine()->GetOutputsList()) {
|
2018-04-05 21:40:05 +02:00
|
|
|
ui_->combobox_output->addItem(IconLoader::Load(o.iconname), o.description, QVariant::fromValue(o));
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
2020-04-23 21:08:28 +02:00
|
|
|
if (ui_->combobox_output->count() > 1) ui_->combobox_output->setEnabled(true);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
bool found(false);
|
2018-02-27 18:06:05 +01:00
|
|
|
for (int i = 0; i < ui_->combobox_output->count(); ++i) {
|
2018-04-05 21:40:05 +02:00
|
|
|
EngineBase::OutputDetails o = ui_->combobox_output->itemData(i).value<EngineBase::OutputDetails>();
|
|
|
|
if (o.name == output) {
|
2018-02-27 18:06:05 +01:00
|
|
|
ui_->combobox_output->setCurrentIndex(i);
|
2018-06-28 01:15:32 +02:00
|
|
|
found = true;
|
2018-02-27 18:06:05 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2018-06-28 01:15:32 +02:00
|
|
|
if (!found) { // Output is invalid for this engine, reset to default output.
|
|
|
|
output = engine()->DefaultOutput();
|
2018-10-17 22:55:36 +02:00
|
|
|
device = (engine()->CustomDeviceSupport(output) ? QString() : QVariant());
|
2018-06-28 01:15:32 +02:00
|
|
|
for (int i = 0; i < ui_->combobox_output->count(); ++i) {
|
|
|
|
EngineBase::OutputDetails o = ui_->combobox_output->itemData(i).value<EngineBase::OutputDetails>();
|
|
|
|
if (o.name == output) {
|
|
|
|
ui_->combobox_output->setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-07-01 01:29:52 +02:00
|
|
|
if (engine()->type() == Engine::GStreamer) {
|
|
|
|
ui_->groupbox_buffer->setEnabled(true);
|
|
|
|
ui_->groupbox_replaygain->setEnabled(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui_->groupbox_buffer->setEnabled(false);
|
|
|
|
ui_->groupbox_replaygain->setEnabled(false);
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-01-09 20:02:40 +01:00
|
|
|
if (ui_->combobox_output->count() >= 1) Load_Device(output, device);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-06-17 02:23:51 +02:00
|
|
|
FadingOptionsChanged();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
2020-10-07 20:29:26 +02:00
|
|
|
void BackendSettingsPage::Load_Device(const QString &output, const QVariant &device) {
|
2018-06-28 01:15:32 +02:00
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (!EngineInitialized()) return;
|
2018-06-28 01:15:32 +02:00
|
|
|
|
|
|
|
int devices = 0;
|
|
|
|
DeviceFinder::Device df_device;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
ui_->combobox_device->clear();
|
2020-10-01 19:53:07 +02:00
|
|
|
ui_->lineedit_device->clear();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-06-28 23:12:39 +02:00
|
|
|
#ifdef Q_OS_WIN
|
|
|
|
if (engine()->type() != Engine::GStreamer)
|
2018-02-27 18:06:05 +01:00
|
|
|
#endif
|
2021-05-11 19:14:00 +02:00
|
|
|
ui_->combobox_device->addItem(IconLoader::Load("soundcard"), kOutputAutomaticallySelect, QVariant());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-11-03 19:53:08 +01:00
|
|
|
for (DeviceFinder *f : dialog()->app()->device_finders()->ListFinders()) {
|
2018-06-28 01:15:32 +02:00
|
|
|
if (!f->outputs().contains(output)) continue;
|
|
|
|
for (const DeviceFinder::Device &d : f->ListDevices()) {
|
|
|
|
devices++;
|
|
|
|
ui_->combobox_device->addItem(IconLoader::Load(d.iconname), d.description, d.value);
|
|
|
|
if (d.value == device) { df_device = d; }
|
|
|
|
}
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
if (engine()->CustomDeviceSupport(output)) {
|
2021-05-11 19:14:00 +02:00
|
|
|
ui_->combobox_device->addItem(IconLoader::Load("soundcard"), kOutputCustom, QVariant());
|
2018-06-28 01:15:32 +02:00
|
|
|
ui_->lineedit_device->setEnabled(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui_->lineedit_device->setEnabled(false);
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-03-09 16:48:45 +01:00
|
|
|
#ifdef HAVE_ALSA
|
2018-09-21 23:29:00 +02:00
|
|
|
if (engine()->ALSADeviceSupport(output)) {
|
2021-05-11 19:14:00 +02:00
|
|
|
ui_->widget_alsa_plugin->setEnabled(true);
|
2018-09-21 23:29:00 +02:00
|
|
|
ui_->radiobutton_alsa_hw->setEnabled(true);
|
|
|
|
ui_->radiobutton_alsa_plughw->setEnabled(true);
|
2021-05-11 19:14:00 +02:00
|
|
|
ui_->radiobutton_alsa_pcm->setEnabled(true);
|
|
|
|
if (device.toString().contains(QRegularExpression("^hw:.*"))) {
|
|
|
|
ui_->radiobutton_alsa_hw->setChecked(true);
|
|
|
|
SwitchALSADevices(alsa_plugin::alsa_hw);
|
|
|
|
}
|
|
|
|
else if (device.toString().contains(QRegularExpression("^plughw:.*"))) {
|
2018-09-21 23:29:00 +02:00
|
|
|
ui_->radiobutton_alsa_plughw->setChecked(true);
|
|
|
|
SwitchALSADevices(alsa_plugin::alsa_plughw);
|
|
|
|
}
|
2021-06-13 23:42:08 +02:00
|
|
|
else if (device.toString().contains(QRegularExpression("^.*:CARD=.*")) || device.toString().contains(QRegularExpression("^.*DEV=.*"))) {
|
2021-05-11 19:14:00 +02:00
|
|
|
ui_->radiobutton_alsa_pcm->setChecked(true);
|
|
|
|
SwitchALSADevices(alsa_plugin::alsa_pcm);
|
|
|
|
}
|
2018-09-21 23:29:00 +02:00
|
|
|
else {
|
|
|
|
ui_->radiobutton_alsa_hw->setChecked(true);
|
|
|
|
SwitchALSADevices(alsa_plugin::alsa_hw);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2021-05-11 19:14:00 +02:00
|
|
|
ui_->widget_alsa_plugin->setDisabled(true);
|
2018-09-21 23:29:00 +02:00
|
|
|
ui_->radiobutton_alsa_hw->setChecked(false);
|
|
|
|
ui_->radiobutton_alsa_plughw->setChecked(false);
|
2021-05-11 19:14:00 +02:00
|
|
|
ui_->radiobutton_alsa_pcm->setChecked(false);
|
2018-09-21 23:29:00 +02:00
|
|
|
}
|
2019-03-09 16:48:45 +01:00
|
|
|
#endif
|
2018-09-21 23:29:00 +02:00
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
bool found = false;
|
2018-06-28 01:15:32 +02:00
|
|
|
for (int i = 0; i < ui_->combobox_device->count(); ++i) {
|
|
|
|
QVariant d = ui_->combobox_device->itemData(i).value<QVariant>();
|
2018-10-22 22:10:27 +02:00
|
|
|
if (df_device.value.isValid() && df_device.value == d) {
|
2018-06-28 01:15:32 +02:00
|
|
|
ui_->combobox_device->setCurrentIndex(i);
|
|
|
|
found = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// This allows a custom ALSA device string ie: "hw:0,0" even if it is not listed.
|
2020-10-24 03:32:40 +02:00
|
|
|
if (engine()->CustomDeviceSupport(output) &&
|
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
device.metaType().id() == QMetaType::QString
|
|
|
|
#else
|
|
|
|
device.type() == QVariant::String
|
|
|
|
#endif
|
|
|
|
&& !device.toString().isEmpty()) {
|
2018-06-28 01:15:32 +02:00
|
|
|
ui_->lineedit_device->setText(device.toString());
|
|
|
|
if (!found) {
|
|
|
|
for (int i = 0; i < ui_->combobox_device->count(); ++i) {
|
2021-05-11 19:14:00 +02:00
|
|
|
if (ui_->combobox_device->itemText(i) == kOutputCustom) {
|
|
|
|
if (ui_->combobox_device->currentText() != kOutputCustom) ui_->combobox_device->setCurrentIndex(i);
|
2018-06-28 01:15:32 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-10-01 19:53:07 +02:00
|
|
|
ui_->combobox_device->setEnabled(devices > 0 || engine()->CustomDeviceSupport(output));
|
2019-02-20 21:21:33 +01:00
|
|
|
|
2019-01-09 20:02:40 +01:00
|
|
|
FadingOptionsChanged();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackendSettingsPage::Save() {
|
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (!EngineInitialized()) return;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
QVariant enginetype_v = ui_->combobox_engine->itemData(ui_->combobox_engine->currentIndex());
|
|
|
|
Engine::EngineType enginetype = enginetype_v.value<Engine::EngineType>();
|
|
|
|
QString output_name;
|
|
|
|
QVariant device_value;
|
|
|
|
|
|
|
|
if (ui_->combobox_output->currentText().isEmpty()) output_name = engine()->DefaultOutput();
|
|
|
|
else {
|
|
|
|
EngineBase::OutputDetails output = ui_->combobox_output->itemData(ui_->combobox_output->currentIndex()).value<EngineBase::OutputDetails>();
|
|
|
|
output_name = output.name;
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
2018-09-21 23:29:00 +02:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
if (ui_->combobox_device->currentText().isEmpty()) device_value = QVariant();
|
2021-05-11 19:14:00 +02:00
|
|
|
else if (ui_->combobox_device->currentText() == kOutputCustom) device_value = ui_->lineedit_device->text();
|
2018-06-28 01:15:32 +02:00
|
|
|
else device_value = ui_->combobox_device->itemData(ui_->combobox_device->currentIndex()).value<QVariant>();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-10-01 22:04:38 +02:00
|
|
|
QSettings s;
|
|
|
|
s.beginGroup(kSettingsGroup);
|
|
|
|
|
|
|
|
s.setValue("engine", EngineName(enginetype));
|
|
|
|
s.setValue("output", output_name);
|
|
|
|
s.setValue("device", device_value);
|
2018-04-05 21:40:05 +02:00
|
|
|
|
2020-10-01 22:04:38 +02:00
|
|
|
s.setValue("bufferduration", ui_->spinbox_bufferduration->value());
|
2020-10-07 20:29:26 +02:00
|
|
|
s.setValue("bufferlowwatermark", ui_->spinbox_low_watermark->value());
|
|
|
|
s.setValue("bufferhighwatermark", ui_->spinbox_high_watermark->value());
|
2019-01-09 20:02:40 +01:00
|
|
|
|
2020-10-01 22:04:38 +02:00
|
|
|
s.setValue("rgenabled", ui_->checkbox_replaygain->isChecked());
|
|
|
|
s.setValue("rgmode", ui_->combobox_replaygainmode->currentIndex());
|
2021-04-22 21:55:26 +02:00
|
|
|
s.setValue("rgpreamp", double(ui_->stickyslider_replaygainpreamp->value()) / 10 - 60);
|
|
|
|
s.setValue("rgfallbackgain", double(ui_->stickyslider_replaygainfallbackgain->value()) / 10 - 60);
|
2020-10-01 22:04:38 +02:00
|
|
|
s.setValue("rgcompression", ui_->checkbox_replaygaincompression->isChecked());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-10-01 22:04:38 +02:00
|
|
|
s.setValue("FadeoutEnabled", ui_->checkbox_fadeout_stop->isChecked());
|
|
|
|
s.setValue("CrossfadeEnabled", ui_->checkbox_fadeout_cross->isChecked());
|
|
|
|
s.setValue("AutoCrossfadeEnabled", ui_->checkbox_fadeout_auto->isChecked());
|
|
|
|
s.setValue("NoCrossfadeSameAlbum", ui_->checkbox_fadeout_samealbum->isChecked());
|
|
|
|
s.setValue("FadeoutPauseEnabled", ui_->checkbox_fadeout_pauseresume->isChecked());
|
|
|
|
s.setValue("FadeoutDuration", ui_->spinbox_fadeduration->value());
|
|
|
|
s.setValue("FadeoutPauseDuration", ui_->spinbox_fadeduration_pauseresume->value());
|
2019-01-09 20:02:40 +01:00
|
|
|
|
2019-03-09 16:48:45 +01:00
|
|
|
#ifdef HAVE_ALSA
|
2020-10-01 22:04:38 +02:00
|
|
|
if (ui_->radiobutton_alsa_hw->isChecked()) s.setValue("alsaplugin", static_cast<int>(alsa_plugin::alsa_hw));
|
|
|
|
else if (ui_->radiobutton_alsa_plughw->isChecked()) s.setValue("alsaplugin", static_cast<int>(alsa_plugin::alsa_plughw));
|
2021-05-11 19:14:00 +02:00
|
|
|
else if (ui_->radiobutton_alsa_pcm->isChecked()) s.setValue("alsaplugin", static_cast<int>(alsa_plugin::alsa_pcm));
|
2020-10-01 22:04:38 +02:00
|
|
|
else s.remove("alsaplugin");
|
2019-03-09 16:48:45 +01:00
|
|
|
#endif
|
|
|
|
|
2020-10-01 22:04:38 +02:00
|
|
|
s.setValue("volume_control", ui_->checkbox_volume_control->isChecked());
|
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
s.setValue("channels_enabled", ui_->checkbox_channels->isChecked());
|
|
|
|
s.setValue("channels", ui_->spinbox_channels->value());
|
|
|
|
|
2020-10-01 22:04:38 +02:00
|
|
|
s.endGroup();
|
2018-09-21 23:29:00 +02:00
|
|
|
|
2018-07-01 01:29:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackendSettingsPage::Cancel() {
|
2021-05-11 19:14:00 +02:00
|
|
|
|
2018-07-01 01:29:52 +02:00
|
|
|
if (engine() && engine()->type() != enginetype_current_) { // Reset engine back to the original because user cancelled.
|
|
|
|
dialog()->app()->player()->CreateEngine(enginetype_current_);
|
|
|
|
dialog()->app()->player()->Init();
|
|
|
|
}
|
2021-05-11 19:14:00 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
2020-10-07 20:29:26 +02:00
|
|
|
void BackendSettingsPage::EngineChanged(const int index) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (!configloaded_ || !EngineInitialized()) return;
|
2018-09-21 23:29:00 +02:00
|
|
|
|
2018-07-01 01:29:52 +02:00
|
|
|
QVariant v = ui_->combobox_engine->itemData(index);
|
|
|
|
Engine::EngineType enginetype = v.value<Engine::EngineType>();
|
|
|
|
|
|
|
|
if (engine()->type() == enginetype) return;
|
2018-06-28 01:15:32 +02:00
|
|
|
|
|
|
|
if (engine()->state() != Engine::Empty) {
|
2020-10-01 19:53:07 +02:00
|
|
|
errordialog_.ShowMessage("Can't switch engine while playing!");
|
|
|
|
ui_->combobox_engine->setCurrentIndex(ui_->combobox_engine->findData(static_cast<int>(engine()->type())));
|
|
|
|
return;
|
2018-04-05 21:40:05 +02:00
|
|
|
}
|
2018-06-28 01:15:32 +02:00
|
|
|
|
|
|
|
engineloaded_ = false;
|
2018-02-27 18:06:05 +01:00
|
|
|
Load_Engine(enginetype);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2020-10-07 20:29:26 +02:00
|
|
|
void BackendSettingsPage::OutputChanged(const int index) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (!configloaded_ || !EngineInitialized()) return;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-04-05 21:40:05 +02:00
|
|
|
EngineBase::OutputDetails output = ui_->combobox_output->itemData(index).value<EngineBase::OutputDetails>();
|
2018-06-07 19:38:40 +02:00
|
|
|
Load_Device(output.name, QVariant());
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackendSettingsPage::DeviceSelectionChanged(int index) {
|
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (!configloaded_ || !EngineInitialized()) return;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
EngineBase::OutputDetails output = ui_->combobox_output->itemData(ui_->combobox_output->currentIndex()).value<EngineBase::OutputDetails>();
|
2018-04-05 21:40:05 +02:00
|
|
|
QVariant device = ui_->combobox_device->itemData(index).value<QVariant>();
|
2018-06-28 01:15:32 +02:00
|
|
|
|
|
|
|
if (engine()->CustomDeviceSupport(output.name)) {
|
2018-04-05 21:40:05 +02:00
|
|
|
ui_->lineedit_device->setEnabled(true);
|
2021-05-11 19:14:00 +02:00
|
|
|
if (ui_->combobox_device->currentText() != kOutputCustom) {
|
2020-10-24 03:32:40 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
if (device.metaType().id() == QMetaType::QString)
|
|
|
|
#else
|
|
|
|
if (device.type() == QVariant::String)
|
|
|
|
#endif
|
|
|
|
ui_->lineedit_device->setText(device.toString());
|
2020-10-01 19:53:07 +02:00
|
|
|
else ui_->lineedit_device->clear();
|
2018-10-23 20:18:07 +02:00
|
|
|
}
|
2018-06-28 01:15:32 +02:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui_->lineedit_device->setEnabled(false);
|
2020-10-01 19:53:07 +02:00
|
|
|
if (!ui_->lineedit_device->text().isEmpty()) ui_->lineedit_device->clear();
|
2018-04-05 21:40:05 +02:00
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-01-09 20:02:40 +01:00
|
|
|
FadingOptionsChanged();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void BackendSettingsPage::DeviceStringChanged() {
|
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (!configloaded_ || !EngineInitialized()) return;
|
2018-06-28 01:15:32 +02:00
|
|
|
|
|
|
|
EngineBase::OutputDetails output = ui_->combobox_output->itemData(ui_->combobox_output->currentIndex()).value<EngineBase::OutputDetails>();
|
2021-05-11 19:14:00 +02:00
|
|
|
bool found = false;
|
2018-06-28 01:15:32 +02:00
|
|
|
|
2019-03-09 16:48:45 +01:00
|
|
|
#ifdef HAVE_ALSA
|
2018-09-21 23:29:00 +02:00
|
|
|
if (engine()->ALSADeviceSupport(output.name)) {
|
2020-07-18 04:05:07 +02:00
|
|
|
if (ui_->lineedit_device->text().contains(QRegularExpression("^hw:.*")) && !ui_->radiobutton_alsa_hw->isChecked()) {
|
2018-09-21 23:29:00 +02:00
|
|
|
ui_->radiobutton_alsa_hw->setChecked(true);
|
|
|
|
SwitchALSADevices(alsa_plugin::alsa_hw);
|
|
|
|
}
|
2020-07-18 04:05:07 +02:00
|
|
|
else if (ui_->lineedit_device->text().contains(QRegularExpression("^plughw:.*")) && !ui_->radiobutton_alsa_plughw->isChecked()) {
|
2018-09-21 23:29:00 +02:00
|
|
|
ui_->radiobutton_alsa_plughw->setChecked(true);
|
|
|
|
SwitchALSADevices(alsa_plugin::alsa_plughw);
|
|
|
|
}
|
2021-06-13 23:42:08 +02:00
|
|
|
else if ((ui_->lineedit_device->text().contains(QRegularExpression("^.*:CARD=.*")) || ui_->lineedit_device->text().contains(QRegularExpression("^.*DEV=.*"))) && !ui_->radiobutton_alsa_pcm->isChecked()) {
|
2021-05-11 19:14:00 +02:00
|
|
|
ui_->radiobutton_alsa_pcm->setChecked(true);
|
|
|
|
SwitchALSADevices(alsa_plugin::alsa_plughw);
|
|
|
|
}
|
2018-09-21 23:29:00 +02:00
|
|
|
}
|
2019-03-09 16:48:45 +01:00
|
|
|
#endif
|
2018-09-21 23:29:00 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
for (int i = 0; i < ui_->combobox_device->count(); ++i) {
|
2018-06-28 01:15:32 +02:00
|
|
|
QVariant device = ui_->combobox_device->itemData(i).value<QVariant>();
|
2020-10-24 03:32:40 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
if (device.metaType().id() != QMetaType::QString) continue;
|
|
|
|
#else
|
2018-06-28 01:15:32 +02:00
|
|
|
if (device.type() != QVariant::String) continue;
|
2020-10-24 03:32:40 +02:00
|
|
|
#endif
|
2021-05-11 19:14:00 +02:00
|
|
|
QString device_str = device.toString();
|
|
|
|
if (device_str.isEmpty()) continue;
|
|
|
|
if (ui_->combobox_device->itemText(i) == kOutputCustom) continue;
|
|
|
|
if (device_str == ui_->lineedit_device->text()) {
|
2018-06-28 01:15:32 +02:00
|
|
|
if (ui_->combobox_device->currentIndex() != i) ui_->combobox_device->setCurrentIndex(i);
|
|
|
|
found = true;
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
}
|
2018-05-01 00:41:33 +02:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
if (engine()->CustomDeviceSupport(output.name)) {
|
|
|
|
ui_->lineedit_device->setEnabled(true);
|
2021-05-11 19:14:00 +02:00
|
|
|
if ((!found) && (ui_->combobox_device->currentText() != kOutputCustom)) {
|
2018-06-28 01:15:32 +02:00
|
|
|
for (int i = 0; i < ui_->combobox_device->count(); ++i) {
|
2021-05-11 19:14:00 +02:00
|
|
|
if (ui_->combobox_device->itemText(i) == kOutputCustom) {
|
2018-06-28 01:15:32 +02:00
|
|
|
ui_->combobox_device->setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
2018-04-05 21:40:05 +02:00
|
|
|
}
|
|
|
|
}
|
2021-05-11 19:14:00 +02:00
|
|
|
if (ui_->combobox_device->currentText() == kOutputCustom) {
|
2018-06-28 01:15:32 +02:00
|
|
|
if ((ui_->lineedit_device->text().isEmpty()) && (ui_->combobox_device->count() > 0) && (ui_->combobox_device->currentIndex() != 0)) ui_->combobox_device->setCurrentIndex(0);
|
|
|
|
}
|
2018-04-05 21:40:05 +02:00
|
|
|
}
|
2018-06-28 01:15:32 +02:00
|
|
|
else {
|
|
|
|
ui_->lineedit_device->setEnabled(false);
|
2020-10-01 19:53:07 +02:00
|
|
|
if (!ui_->lineedit_device->text().isEmpty()) ui_->lineedit_device->clear();
|
2018-06-28 01:15:32 +02:00
|
|
|
if ((!found) && (ui_->combobox_device->count() > 0) && (ui_->combobox_device->currentIndex() != 0)) ui_->combobox_device->setCurrentIndex(0);
|
2018-04-05 21:40:05 +02:00
|
|
|
}
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2019-01-09 20:02:40 +01:00
|
|
|
FadingOptionsChanged();
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
}
|
|
|
|
|
2020-10-07 20:29:26 +02:00
|
|
|
void BackendSettingsPage::RgPreampChanged(const int value) {
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2021-04-22 21:55:26 +02:00
|
|
|
double db = double(value) / 10 - 60;
|
2019-12-21 21:56:48 +01:00
|
|
|
QString db_str = QString::asprintf("%+.1f dB", db);
|
2018-02-27 18:06:05 +01:00
|
|
|
ui_->label_replaygainpreamp->setText(db_str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2021-04-22 21:55:26 +02:00
|
|
|
void BackendSettingsPage::RgFallbackGainChanged(const int value) {
|
|
|
|
|
|
|
|
double db = double(value) / 10 - 60;
|
|
|
|
QString db_str = QString::asprintf("%+.1f dB", db);
|
|
|
|
ui_->label_replaygainfallbackgain->setText(db_str);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-03-09 16:48:45 +01:00
|
|
|
#ifdef HAVE_ALSA
|
2020-10-07 20:29:26 +02:00
|
|
|
void BackendSettingsPage::SwitchALSADevices(const alsa_plugin alsaplugin) {
|
2018-09-21 23:29:00 +02:00
|
|
|
|
|
|
|
// All ALSA devices are listed twice, one for "hw" and one for "plughw"
|
|
|
|
// Only show one of them by making the other ones invisible based on the alsa plugin radiobuttons
|
|
|
|
for (int i = 0; i < ui_->combobox_device->count(); ++i) {
|
2021-05-11 19:14:00 +02:00
|
|
|
QListView *view = qobject_cast<QListView*>(ui_->combobox_device->view());
|
2018-09-21 23:29:00 +02:00
|
|
|
if (!view) continue;
|
2021-05-11 19:14:00 +02:00
|
|
|
if ((ui_->combobox_device->itemData(i).toString().contains(QRegularExpression("^hw:.*")) && alsaplugin != alsa_plugin::alsa_hw)
|
|
|
|
||
|
|
|
|
(ui_->combobox_device->itemData(i).toString().contains(QRegularExpression("^plughw:.*")) && alsaplugin != alsa_plugin::alsa_plughw)
|
|
|
|
||
|
2021-06-13 23:42:08 +02:00
|
|
|
((ui_->combobox_device->itemData(i).toString().contains(QRegularExpression("^.*:CARD=.*")) || ui_->combobox_device->itemData(i).toString().contains(QRegularExpression("^.*DEV=.*"))) && alsaplugin != alsa_plugin::alsa_pcm)
|
2021-05-11 19:14:00 +02:00
|
|
|
) {
|
2018-09-21 23:29:00 +02:00
|
|
|
view->setRowHidden(i, true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
view->setRowHidden(i, false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2019-10-03 23:29:52 +02:00
|
|
|
#endif
|
2018-09-21 23:29:00 +02:00
|
|
|
|
2020-10-07 20:29:26 +02:00
|
|
|
void BackendSettingsPage::radiobutton_alsa_hw_clicked(const bool checked) {
|
2018-09-21 23:29:00 +02:00
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
if (!checked) return;
|
2019-09-15 20:27:32 +02:00
|
|
|
|
2019-10-03 23:29:52 +02:00
|
|
|
#ifdef HAVE_ALSA
|
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (!configloaded_ || !EngineInitialized()) return;
|
2018-09-21 23:29:00 +02:00
|
|
|
|
|
|
|
EngineBase::OutputDetails output = ui_->combobox_output->itemData(ui_->combobox_output->currentIndex()).value<EngineBase::OutputDetails>();
|
|
|
|
if (!engine()->ALSADeviceSupport(output.name)) return;
|
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
SwitchALSADevices(alsa_plugin::alsa_hw);
|
|
|
|
|
|
|
|
QString device_new = ui_->lineedit_device->text();
|
|
|
|
|
|
|
|
if (device_new.contains(QRegularExpression("^plughw:.*"))) {
|
|
|
|
device_new = device_new.replace(QRegularExpression("^plughw:"), "hw:");
|
2018-09-21 23:29:00 +02:00
|
|
|
}
|
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
if (!device_new.contains(QRegularExpression("^hw:.*"))) {
|
|
|
|
device_new.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectDevice(device_new);
|
|
|
|
|
2019-10-03 23:29:52 +02:00
|
|
|
#endif
|
|
|
|
|
2018-09-21 23:29:00 +02:00
|
|
|
}
|
|
|
|
|
2020-10-07 20:29:26 +02:00
|
|
|
void BackendSettingsPage::radiobutton_alsa_plughw_clicked(const bool checked) {
|
2018-09-21 23:29:00 +02:00
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
if (!checked) return;
|
2019-09-15 20:27:32 +02:00
|
|
|
|
2019-10-03 23:29:52 +02:00
|
|
|
#ifdef HAVE_ALSA
|
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (!configloaded_ || !EngineInitialized()) return;
|
2018-09-21 23:29:00 +02:00
|
|
|
|
|
|
|
EngineBase::OutputDetails output = ui_->combobox_output->itemData(ui_->combobox_output->currentIndex()).value<EngineBase::OutputDetails>();
|
|
|
|
if (!engine()->ALSADeviceSupport(output.name)) return;
|
|
|
|
|
2021-05-11 19:14:00 +02:00
|
|
|
SwitchALSADevices(alsa_plugin::alsa_plughw);
|
|
|
|
|
|
|
|
QString device_new = ui_->lineedit_device->text();
|
|
|
|
|
|
|
|
if (device_new.contains(QRegularExpression("^hw:.*"))) {
|
|
|
|
device_new = device_new.replace(QRegularExpression("^hw:"), "plughw:");
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!device_new.contains(QRegularExpression("^plughw:.*"))) {
|
|
|
|
device_new.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectDevice(device_new);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackendSettingsPage::radiobutton_alsa_pcm_clicked(const bool checked) {
|
|
|
|
|
|
|
|
if (!checked) return;
|
|
|
|
|
|
|
|
#ifdef HAVE_ALSA
|
|
|
|
|
|
|
|
if (!configloaded_ || !EngineInitialized()) return;
|
|
|
|
|
|
|
|
EngineBase::OutputDetails output = ui_->combobox_output->itemData(ui_->combobox_output->currentIndex()).value<EngineBase::OutputDetails>();
|
|
|
|
if (!engine()->ALSADeviceSupport(output.name)) return;
|
|
|
|
|
|
|
|
SwitchALSADevices(alsa_plugin::alsa_pcm);
|
|
|
|
|
|
|
|
QString device_new = ui_->lineedit_device->text();
|
|
|
|
|
2021-06-13 23:44:15 +02:00
|
|
|
if (!device_new.contains(QRegularExpression("^.*:CARD=.*")) && !device_new.contains(QRegularExpression("^.*DEV=.*"))) {
|
2021-05-11 19:14:00 +02:00
|
|
|
device_new.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
SelectDevice(device_new);
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void BackendSettingsPage::SelectDevice(const QString &device_new) {
|
|
|
|
|
|
|
|
if (device_new.isEmpty()) {
|
2018-09-21 23:29:00 +02:00
|
|
|
for (int i = 0; i < ui_->combobox_device->count(); ++i) {
|
2021-05-11 19:14:00 +02:00
|
|
|
if (ui_->combobox_device->itemText(i) == kOutputAutomaticallySelect && ui_->combobox_device->currentIndex() != i) {
|
|
|
|
ui_->combobox_device->setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
bool found = false;
|
|
|
|
for (int i = 0; i < ui_->combobox_device->count(); ++i) {
|
|
|
|
QListView *view = qobject_cast<QListView*>(ui_->combobox_device->view());
|
|
|
|
if (view && view->isRowHidden(i)) continue;
|
2018-09-21 23:29:00 +02:00
|
|
|
QVariant device = ui_->combobox_device->itemData(i).value<QVariant>();
|
2020-10-24 03:32:40 +02:00
|
|
|
#if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)
|
|
|
|
if (device.metaType().id() != QMetaType::QString) continue;
|
|
|
|
#else
|
2018-09-21 23:29:00 +02:00
|
|
|
if (device.type() != QVariant::String) continue;
|
2020-10-24 03:32:40 +02:00
|
|
|
#endif
|
2021-05-11 19:14:00 +02:00
|
|
|
QString device_str = device.toString();
|
|
|
|
if (device_str.isEmpty()) continue;
|
|
|
|
if (device_str == device_new) {
|
2018-09-21 23:29:00 +02:00
|
|
|
if (ui_->combobox_device->currentIndex() != i) ui_->combobox_device->setCurrentIndex(i);
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
}
|
2021-05-11 19:14:00 +02:00
|
|
|
if (!found) {
|
|
|
|
ui_->lineedit_device->setText(device_new);
|
|
|
|
for (int i = 0; i < ui_->combobox_device->count(); ++i) {
|
|
|
|
if (ui_->combobox_device->itemText(i) == kOutputCustom && ui_->combobox_device->currentIndex() != i) {
|
|
|
|
ui_->combobox_device->setCurrentIndex(i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-21 23:29:00 +02:00
|
|
|
}
|
|
|
|
|
2019-10-03 23:29:52 +02:00
|
|
|
}
|
|
|
|
|
2019-01-09 20:02:40 +01:00
|
|
|
void BackendSettingsPage::FadingOptionsChanged() {
|
|
|
|
|
2020-10-17 17:29:09 +02:00
|
|
|
if (!configloaded_ || !EngineInitialized()) return;
|
2019-06-17 02:23:51 +02:00
|
|
|
|
|
|
|
EngineBase::OutputDetails output = ui_->combobox_output->itemData(ui_->combobox_output->currentIndex()).value<EngineBase::OutputDetails>();
|
|
|
|
if (engine()->type() == Engine::GStreamer && !(engine()->ALSADeviceSupport(output.name) && !ui_->lineedit_device->text().isEmpty()) && ui_->checkbox_volume_control->isChecked()) {
|
|
|
|
ui_->groupbox_fading->setDisabled(false);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ui_->groupbox_fading->setDisabled(true);
|
|
|
|
ui_->checkbox_fadeout_stop->setChecked(false);
|
|
|
|
ui_->checkbox_fadeout_cross->setChecked(false);
|
|
|
|
ui_->checkbox_fadeout_auto->setChecked(false);
|
2019-01-09 20:02:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
ui_->widget_fading_options->setEnabled(ui_->checkbox_fadeout_stop->isChecked() || ui_->checkbox_fadeout_cross->isChecked() || ui_->checkbox_fadeout_auto->isChecked());
|
2021-01-30 23:16:19 +01:00
|
|
|
ui_->checkbox_fadeout_samealbum->setEnabled(ui_->checkbox_fadeout_auto->isChecked());
|
2019-01-09 20:02:40 +01:00
|
|
|
|
|
|
|
}
|
2020-10-07 20:29:26 +02:00
|
|
|
|
|
|
|
|
|
|
|
void BackendSettingsPage::BufferDefaults() {
|
|
|
|
|
|
|
|
ui_->spinbox_bufferduration->setValue(kDefaultBufferDuration);
|
|
|
|
ui_->spinbox_low_watermark->setValue(kDefaultBufferLowWatermark);
|
|
|
|
ui_->spinbox_high_watermark->setValue(kDefaultBufferHighWatermark);
|
|
|
|
|
|
|
|
}
|