19#include <QDialogButtonBox>
23#include <QStandardPaths>
27#include "ui_sonivoxsettingsdialog.h"
38const QString SonivoxSettingsDialog::QSTR_PREFERENCES = QStringLiteral(
"SonivoxEAS");
39const QString SonivoxSettingsDialog::QSTR_BUFFERTIME = QStringLiteral(
"BufferTime");
40const QString SonivoxSettingsDialog::QSTR_REVERBTYPE = QStringLiteral(
"ReverbType");
41const QString SonivoxSettingsDialog::QSTR_REVERBAMT = QStringLiteral(
"ReverbAmt");
42const QString SonivoxSettingsDialog::QSTR_CHORUSTYPE = QStringLiteral(
"ChorusType");
43const QString SonivoxSettingsDialog::QSTR_CHORUSAMT = QStringLiteral(
"ChorusAmt");
44const QString SonivoxSettingsDialog::QSTR_SOUNDFONT = QStringLiteral(
"InstrumentsDefinition");
45const QString SonivoxSettingsDialog::QSTR_DATADIR = QStringLiteral(
"soundfonts");
46const QString SonivoxSettingsDialog::QSTR_DATADIR2 = QStringLiteral(
"sounds/sf2");
48SonivoxSettingsDialog::SonivoxSettingsDialog(QWidget *parent) :
50 ui(new Ui::SonivoxSettingsDialog)
53 ui->combo_Reverb->addItem(QStringLiteral(
"Large Hall"), 0);
54 ui->combo_Reverb->addItem(QStringLiteral(
"Hall"), 1);
55 ui->combo_Reverb->addItem(QStringLiteral(
"Chamber"), 2);
56 ui->combo_Reverb->addItem(QStringLiteral(
"Room"), 3);
57 ui->combo_Reverb->addItem(QStringLiteral(
"None"), -1);
58 ui->combo_Reverb->setCurrentIndex(4);
60 ui->combo_Chorus->addItem(QStringLiteral(
"Preset 1"), 0);
61 ui->combo_Chorus->addItem(QStringLiteral(
"Preset 2"), 1);
62 ui->combo_Chorus->addItem(QStringLiteral(
"Preset 3"), 2);
63 ui->combo_Chorus->addItem(QStringLiteral(
"Preset 4"), 3);
64 ui->combo_Chorus->addItem(QStringLiteral(
"None"), -1);
65 ui->combo_Chorus->setCurrentIndex(4);
66 connect(ui->btn_soundfont, &QToolButton::clicked,
this, &SonivoxSettingsDialog::showFileDialog);
67 connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::pressed,
68 this, &SonivoxSettingsDialog::restoreDefaults);
75SonivoxSettingsDialog::~SonivoxSettingsDialog()
78 if (m_driver !=
nullptr) {
84void SonivoxSettingsDialog::accept()
88 if (m_driver !=
nullptr) {
90 QVariant varStatus = m_driver->property(
"status");
91 if (varStatus.isValid()) {
92 title = varStatus.toBool() ? tr(
"Sonivox Initialized") : tr(
"Sonivox Initialization Failed");
93 QVariant varDiag = m_driver->property(
"diagnostics");
94 if (varDiag.isValid()) {
95 QString text = varDiag.toStringList().join(QChar::LineFeed).trimmed();
96 if (varStatus.toBool()) {
97 if (!text.isEmpty()) {
98 QMessageBox::information(
this, title, text);
101 QMessageBox::critical(
this, title, text);
110void SonivoxSettingsDialog::showEvent(QShowEvent *event)
117void SonivoxSettingsDialog::readSettings()
120 SettingsFactory settings;
121 settings->beginGroup(QSTR_PREFERENCES);
122 int bufferTime = settings->value(QSTR_BUFFERTIME, 30).toInt();
123 int reverbType = settings->value(QSTR_REVERBTYPE, 1).toInt();
124 int reverbAmt = settings->value(QSTR_REVERBAMT, 25800).toInt();
125 int chorusType = settings->value(QSTR_CHORUSTYPE, -1).toInt();
126 int chorusAmt = settings->value(QSTR_CHORUSAMT, 0).toInt();
127 QString soundfont = settings->value(QSTR_SOUNDFONT, QString()).toString();
128 settings->endGroup();
130 if (qEnvironmentVariableIsSet(
"PULSE_LATENCY_MSEC")) {
131 bufferTime = qEnvironmentVariableIntValue(
"PULSE_LATENCY_MSEC");
134 ui->spnTime->setValue(bufferTime);
135 ui->soundfont_dls->setText(soundfont);
136 ui->dial_Reverb->setValue(reverbAmt);
137 ui->dial_Chorus->setValue(chorusAmt);
138 int reverbIndex = ui->combo_Reverb->findData(reverbType);
139 int chorusIndex = ui->combo_Chorus->findData(chorusType);
140 ui->combo_Reverb->setCurrentIndex(reverbIndex);
141 ui->combo_Chorus->setCurrentIndex(chorusIndex);
143 chkDriverProperties(settings.getQSettings());
146void SonivoxSettingsDialog::writeSettings()
149 SettingsFactory settings;
150 settings->beginGroup(QSTR_PREFERENCES);
151 settings->setValue(QSTR_BUFFERTIME, ui->spnTime->value());
152 settings->setValue(QSTR_REVERBTYPE, ui->combo_Reverb->currentData());
153 settings->setValue(QSTR_CHORUSTYPE, ui->combo_Chorus->currentData());
154 settings->setValue(QSTR_REVERBAMT, ui->dial_Reverb->value());
155 settings->setValue(QSTR_CHORUSAMT, ui->dial_Chorus->value());
156 settings->setValue(QSTR_SOUNDFONT, ui->soundfont_dls->text());
157 settings->endGroup();
159 qputenv(
"PULSE_LATENCY_MSEC", QByteArray::number( ui->spnTime->value() ));
160 chkDriverProperties(settings.getQSettings());
163void SonivoxSettingsDialog::chkDriverProperties(
QSettings *settings)
166 if (m_driver !=
nullptr) {
169 m_driver->initialize(settings);
170 QVariant varVersion = m_driver->property(
"libversion");
171 if (varVersion.isValid()) {
172 ui->lblLibraryText->clear();
173 ui->lblLibraryText->setText(varVersion.toString());
175 QVariant varStatus = m_driver->property(
"status");
176 if (varStatus.isValid()) {
177 ui->lblStatusText->clear();
178 ui->lblStatusText->setText(varStatus.toBool() ? tr(
"Ready") : tr(
"Failed") );
179 ui->lblStatusIcon->setPixmap(varStatus.toBool() ? QPixmap(
":/checked.png") : QPixmap(
":/error.png") );
184void SonivoxSettingsDialog::restoreDefaults()
186 ui->spnTime->setValue(30);
187 ui->soundfont_dls->clear();
188 ui->combo_Reverb->setCurrentIndex(1);
189 ui->dial_Reverb->setValue(25800);
190 ui->combo_Chorus->setCurrentIndex(4);
191 ui->dial_Chorus->setValue(0);
194void SonivoxSettingsDialog::showFileDialog()
196 QDir dir(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QSTR_DATADIR, QStandardPaths::LocateDirectory));
198 dir = QDir(QStandardPaths::locate(QStandardPaths::GenericDataLocation, QSTR_DATADIR2, QStandardPaths::LocateDirectory));
200 QString fileName = QFileDialog::getOpenFileName(
this, tr(
"Select SoundFont"), dir.absolutePath(), tr(
"SoundFont Files (*.dls)"));
201 if (!fileName.isEmpty()) {
202 ui->soundfont_dls->setText(fileName);
206void SonivoxSettingsDialog::changeSoundFont(
const QString& fileName)
209 ui->soundfont_dls->setText(fileName);
BackendManager class declaration.
The QSettings class provides persistent platform-independent application settings.
The BackendManager class manages lists of dynamic and static backends for applications based on drums...
MIDIOutput * outputBackendByName(const QString name)
outputBackendByName
virtual void close()=0
close the MIDI port
SettingsFactory class declaration.
Definition of the Sonivox Synth configuration dialog.