drumstick 2.9.0
C++ MIDI libraries using Qt objects, idioms, and style.
macsynthsettingsdialog.cpp
Go to the documentation of this file.
1/*
2 Virtual Piano test using the MIDI Sequencer C++ library
3 Copyright (C) 2006-2023, Pedro Lopez-Cabanillas <plcl@users.sf.net>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19#include <QDialogButtonBox>
20#include <QDir>
21#include <QFileDialog>
22#include <QNetworkInterface>
23#include <QPushButton>
24#include <QStandardPaths>
25#include <QMessageBox>
26
28#include "ui_macsynthsettingsdialog.h"
31
37namespace drumstick {
38namespace widgets {
39
40MacSynthSettingsDialog::MacSynthSettingsDialog(QWidget *parent) :
41 QDialog(parent),
42 ui(new Ui::MacSynthSettingsDialog)
43{
44 ui->setupUi(this);
45 connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::pressed,
46 this, &MacSynthSettingsDialog::restoreDefaults);
47 connect(ui->btn_soundfont, &QToolButton::pressed, this, &MacSynthSettingsDialog::showFileDialog);
48
49 SettingsFactory settings;
51 m_driver = man.outputBackendByName("DLS Synth");
52 if (m_driver != nullptr) {
53 checkDriver(settings.getQSettings());
54 }
55}
56
57MacSynthSettingsDialog::~MacSynthSettingsDialog()
58{
59 if (m_driver != nullptr) {
60 m_driver->close();
61 }
62 delete ui;
63}
64
65void MacSynthSettingsDialog::accept()
66{
67 writeSettings();
68 if (m_driver != nullptr) {
69 QString title;
70 QVariant varStatus = m_driver->property("status");
71 if (varStatus.isValid()) {
72 title = varStatus.toBool() ? tr("DLS Synth Initialized") : tr("DLS Synth Initialization Failed");
73 QVariant varDiag = m_driver->property("diagnostics");
74 if (varDiag.isValid()) {
75 QString text = varDiag.toStringList().join(QChar::LineFeed).trimmed();
76 if (varStatus.toBool()) {
77 if (!text.isEmpty()) {
78 QMessageBox::information(this, title, text);
79 }
80 } else {
81 QMessageBox::critical(this, title, text);
82 return;
83 }
84 }
85 }
86 }
87 QDialog::accept();
88}
89
90void MacSynthSettingsDialog::showEvent(QShowEvent *event)
91{
92 readSettings();
93 event->accept();
94}
95
96void MacSynthSettingsDialog::readSettings()
97{
98
99 SettingsFactory settings;
100 settings->beginGroup("DLS Synth");
101 bool reverb = settings->value("reverb_dls", true).toBool();
102 bool def = settings->value("default_dls", true).toBool();
103 QString soundfont = settings->value("soundfont_dls").toString();
104 settings->endGroup();
105
106 ui->reverb_dls->setChecked(reverb);
107 ui->default_dls->setChecked(def);
108 ui->soundfont_dls->setText(soundfont);
109}
110
111void drumstick::widgets::MacSynthSettingsDialog::checkDriver(QSettings* settings)
112{
113 if (m_driver != nullptr) {
114 m_driver->close();
115 m_driver->initialize(settings);
117 m_driver->open(conn);
118
119 QVariant varStatus = m_driver->property("status");
120 if (varStatus.isValid()) {
121 ui->lblStatusText->clear();
122 ui->lblStatusText->setText(varStatus.toBool() ? tr("Ready") : tr("Failed") );
123 ui->lblStatusIcon->setPixmap(varStatus.toBool() ? QPixmap(":/checked.png") : QPixmap(":/error.png") );
124 }
125 }
126}
127
128void MacSynthSettingsDialog::writeSettings()
129{
130 SettingsFactory settings;
131
132 QString soundfont = ui->soundfont_dls->text();
133 bool reverb = ui->reverb_dls->isChecked();
134 bool def = ui->default_dls->isChecked();
135
136 settings->beginGroup("DLS Synth");
137 settings->setValue("soundfont_dls", soundfont);
138 settings->setValue("reverb_dls", reverb);
139 settings->setValue("default_dls", def);
140 settings->endGroup();
141 settings->sync();
142
143 checkDriver(settings.getQSettings());
144}
145
146void MacSynthSettingsDialog::restoreDefaults()
147{
148 ui->reverb_dls->setChecked(false);
149 ui->default_dls->setChecked(true);
150 ui->soundfont_dls->clear();
151}
152
153void MacSynthSettingsDialog::changeSoundFont(const QString& fileName)
154{
155 readSettings();
156 ui->soundfont_dls->setText(fileName);
157 writeSettings();
158}
159
160void MacSynthSettingsDialog::showFileDialog()
161{
162 QDir dir = (QDir::homePath() + "/Library/Audio/Sounds/Banks/");
163 QString fileName = QFileDialog::getOpenFileName(this, tr("Select SoundFont"), dir.absolutePath(), tr("SoundFont Files (*.sf2 *.dls)"));
164 if (!fileName.isEmpty()) {
165 ui->soundfont_dls->setText(fileName);
166 }
167}
168
169} // namespace widgets
170} // namespace drumstick
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
QPair< QString, QVariant > MIDIConnection
MIDIConnection represents a connection identifier.
Definition: rtmidioutput.h:116
Declaration of the Mac Synth configuration dialog.
Drumstick common.
Definition: alsaclient.cpp:68
SettingsFactory class declaration.