drumstick  2.1.1
macsynthsettingsdialog.cpp
Go to the documentation of this file.
1 /*
2  Virtual Piano test using the MIDI Sequencer C++ library
3  Copyright (C) 2006-2021, 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 
26 #include "macsynthsettingsdialog.h"
27 #include "ui_macsynthsettingsdialog.h"
29 
35 namespace drumstick {
36 namespace widgets {
37 
38 MacSynthSettingsDialog::MacSynthSettingsDialog(QWidget *parent) :
39  QDialog(parent),
40  ui(new Ui::MacSynthSettingsDialog)
41 {
42  ui->setupUi(this);
43  connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::pressed,
44  this, &MacSynthSettingsDialog::restoreDefaults);
45  connect(ui->btn_soundfont, &QToolButton::pressed, this, &MacSynthSettingsDialog::showFileDialog);
46 }
47 
48 MacSynthSettingsDialog::~MacSynthSettingsDialog()
49 {
50  delete ui;
51 }
52 
53 void MacSynthSettingsDialog::accept()
54 {
55  writeSettings();
56  QDialog::accept();
57 }
58 
59 void MacSynthSettingsDialog::showEvent(QShowEvent *event)
60 {
61  readSettings();
62  event->accept();
63 }
64 
65 void MacSynthSettingsDialog::readSettings()
66 {
67 
68  SettingsFactory settings;
69  settings->beginGroup("DLS Synth");
70  bool reverb = settings->value("reverb_dls", false).toBool();
71  bool def = settings->value("default_dls", true).toBool();
72  QString soundfont = settings->value("soundfont_dls").toString();
73  settings->endGroup();
74 
75  ui->reverb_dls->setChecked(reverb);
76  ui->default_dls->setChecked(def);
77  ui->soundfont_dls->setText(soundfont);
78 }
79 
80 void MacSynthSettingsDialog::writeSettings()
81 {
82  SettingsFactory settings;
83 
84  QString soundfont = ui->soundfont_dls->text();
85  bool reverb = ui->reverb_dls->isChecked();
86  bool def = ui->default_dls->isChecked();
87 
88  settings->beginGroup("DLS Synth");
89  settings->setValue("soundfont_dls", soundfont);
90  settings->setValue("reverb_dls", reverb);
91  settings->setValue("default_dls", def);
92  settings->endGroup();
93  settings->sync();
94 }
95 
96 void MacSynthSettingsDialog::restoreDefaults()
97 {
98  ui->reverb_dls->setChecked(false);
99  ui->default_dls->setChecked(true);
100  ui->soundfont_dls->clear();
101 }
102 
103 void MacSynthSettingsDialog::changeSoundFont(const QString& fileName)
104 {
105  readSettings();
106  ui->soundfont_dls->setText(fileName);
107  writeSettings();
108 }
109 
110 void MacSynthSettingsDialog::showFileDialog()
111 {
112  QDir dir = (QDir::homePath() + "/Library/Audio/Sounds/Banks/");
113  QString fileName = QFileDialog::getOpenFileName(this, tr("Select SoundFont"), dir.absolutePath(), tr("SoundFont Files (*.sf2 *.dls)"));
114  if (!fileName.isEmpty()) {
115  ui->soundfont_dls->setText(fileName);
116  }
117 }
118 
119 } // namespace widgets
120 } // namespace drumstick
Declaration of the Mac Synth configuration dialog.
void DRUMSTICK_EXPORT changeSoundFont(const QString driver, const QString fileName, QWidget *parent=nullptr)
Changes the sound font configuration Some RT output drivers accept soundfonts.
Drumstick common.
Definition: alsaclient.cpp:68
SettingsFactory class declaration.