drumstick  2.7.0
sonivoxsettingsdialog.cpp
Go to the documentation of this file.
1 /*
2  Virtual Piano test using the MIDI Sequencer C++ library
3  Copyright (C) 2006-2022, 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 <QPushButton>
21 #include <QMessageBox>
22 
23 #include "sonivoxsettingsdialog.h"
24 #include "ui_sonivoxsettingsdialog.h"
27 
33 namespace drumstick { namespace widgets {
34 
35 const QString SonivoxSettingsDialog::QSTR_PREFERENCES = QStringLiteral("SonivoxEAS");
36 const QString SonivoxSettingsDialog::QSTR_BUFFERTIME = QStringLiteral("BufferTime");
37 const QString SonivoxSettingsDialog::QSTR_REVERBTYPE = QStringLiteral("ReverbType");
38 const QString SonivoxSettingsDialog::QSTR_REVERBAMT = QStringLiteral("ReverbAmt");
39 const QString SonivoxSettingsDialog::QSTR_CHORUSTYPE = QStringLiteral("ChorusType");
40 const QString SonivoxSettingsDialog::QSTR_CHORUSAMT = QStringLiteral("ChorusAmt");
41 
42 SonivoxSettingsDialog::SonivoxSettingsDialog(QWidget *parent) :
43  QDialog(parent),
44  ui(new Ui::SonivoxSettingsDialog)
45 {
46  ui->setupUi(this);
47  ui->combo_Reverb->addItem(QStringLiteral("Large Hall"), 0);
48  ui->combo_Reverb->addItem(QStringLiteral("Hall"), 1);
49  ui->combo_Reverb->addItem(QStringLiteral("Chamber"), 2);
50  ui->combo_Reverb->addItem(QStringLiteral("Room"), 3);
51  ui->combo_Reverb->addItem(QStringLiteral("None"), -1);
52  ui->combo_Reverb->setCurrentIndex(4);
53 
54  ui->combo_Chorus->addItem(QStringLiteral("Preset 1"), 0);
55  ui->combo_Chorus->addItem(QStringLiteral("Preset 2"), 1);
56  ui->combo_Chorus->addItem(QStringLiteral("Preset 3"), 2);
57  ui->combo_Chorus->addItem(QStringLiteral("Preset 4"), 3);
58  ui->combo_Chorus->addItem(QStringLiteral("None"), -1);
59  ui->combo_Chorus->setCurrentIndex(4);
60  connect(ui->buttonBox->button(QDialogButtonBox::RestoreDefaults), &QPushButton::pressed,
61  this, &SonivoxSettingsDialog::restoreDefaults);
62 
64  m_driver = man.outputBackendByName("SonivoxEAS");
65  //qDebug() << Q_FUNC_INFO;
66 }
67 
68 SonivoxSettingsDialog::~SonivoxSettingsDialog()
69 {
70  //qDebug() << Q_FUNC_INFO;
71  if (m_driver != nullptr) {
72  m_driver->close();
73  }
74  delete ui;
75 }
76 
77 void SonivoxSettingsDialog::accept()
78 {
79  //qDebug() << Q_FUNC_INFO;
80  writeSettings();
81  if (m_driver != nullptr) {
82  QString title;
83  QVariant varStatus = m_driver->property("status");
84  if (varStatus.isValid()) {
85  title = varStatus.toBool() ? tr("Sonivox Initialized") : tr("Sonivox Initialization Failed");
86  QVariant varDiag = m_driver->property("diagnostics");
87  if (varDiag.isValid()) {
88  QString text = varDiag.toStringList().join(QChar::LineFeed).trimmed();
89  if (varStatus.toBool()) {
90  if (!text.isEmpty()) {
91  QMessageBox::information(this, title, text);
92  }
93  } else {
94  QMessageBox::critical(this, title, text);
95  return;
96  }
97  }
98  }
99  }
100  QDialog::accept();
101 }
102 
103 void SonivoxSettingsDialog::showEvent(QShowEvent *event)
104 {
105  //qDebug() << Q_FUNC_INFO;
106  readSettings();
107  event->accept();
108 }
109 
110 void SonivoxSettingsDialog::readSettings()
111 {
112  //qDebug() << Q_FUNC_INFO;
113  SettingsFactory settings;
114  settings->beginGroup(QSTR_PREFERENCES);
115  int bufferTime = settings->value(QSTR_BUFFERTIME, 30).toInt();
116  int reverbType = settings->value(QSTR_REVERBTYPE, 1).toInt();
117  int reverbAmt = settings->value(QSTR_REVERBAMT, 25800).toInt();
118  int chorusType = settings->value(QSTR_CHORUSTYPE, -1).toInt();
119  int chorusAmt = settings->value(QSTR_CHORUSAMT, 0).toInt();
120  settings->endGroup();
121 
122  if (qEnvironmentVariableIsSet("PULSE_LATENCY_MSEC")) {
123  bufferTime = qEnvironmentVariableIntValue("PULSE_LATENCY_MSEC");
124  }
125 
126  ui->spnTime->setValue(bufferTime);
127  ui->dial_Reverb->setValue(reverbAmt);
128  ui->dial_Chorus->setValue(chorusAmt);
129  int reverbIndex = ui->combo_Reverb->findData(reverbType);
130  int chorusIndex = ui->combo_Chorus->findData(chorusType);
131  ui->combo_Reverb->setCurrentIndex(reverbIndex);
132  ui->combo_Chorus->setCurrentIndex(chorusIndex);
133 
134  chkDriverProperties(settings.getQSettings());
135 }
136 
137 void SonivoxSettingsDialog::writeSettings()
138 {
139  //qDebug() << Q_FUNC_INFO;
140  SettingsFactory settings;
141  settings->beginGroup(QSTR_PREFERENCES);
142  settings->setValue(QSTR_BUFFERTIME, ui->spnTime->value());
143  settings->setValue(QSTR_REVERBTYPE, ui->combo_Reverb->currentData());
144  settings->setValue(QSTR_CHORUSTYPE, ui->combo_Chorus->currentData());
145  settings->setValue(QSTR_REVERBAMT, ui->dial_Reverb->value());
146  settings->setValue(QSTR_CHORUSAMT, ui->dial_Chorus->value());
147  settings->endGroup();
148  settings->sync();
149  qputenv("PULSE_LATENCY_MSEC", QByteArray::number( ui->spnTime->value() ));
150  chkDriverProperties(settings.getQSettings());
151 }
152 
153 void SonivoxSettingsDialog::chkDriverProperties(QSettings *settings)
154 {
155  //qDebug() << Q_FUNC_INFO;
156  if (m_driver != nullptr) {
157  //drumstick::rt::MIDIConnection conn;
158  m_driver->close();
159  m_driver->initialize(settings);
160  //m_driver->open(conn);
161  }
162  QVariant varStatus = m_driver->property("status");
163  if (varStatus.isValid()) {
164  ui->lblStatusText->clear();
165  ui->lblStatusText->setText(varStatus.toBool() ? tr("Ready") : tr("Failed") );
166  ui->lblStatusIcon->setPixmap(varStatus.toBool() ? QPixmap(":/checked.png") : QPixmap(":/error.png") );
167  }
168 }
169 
170 void SonivoxSettingsDialog::restoreDefaults()
171 {
172  ui->spnTime->setValue(30);
173  ui->combo_Reverb->setCurrentIndex(1);
174  ui->dial_Reverb->setValue(25800);
175  ui->combo_Chorus->setCurrentIndex(4);
176  ui->dial_Chorus->setValue(0);
177 }
178 
179 } // namespace widgets
180 } // namespace drumstick
181 
The QSettings class provides persistent platform-independent application settings.
The BackendManager class manages lists of dynamic and static backends for applications based on drums...
virtual void close()=0
close the MIDI port
BackendManager class declaration.
Drumstick common.
Definition: alsaclient.cpp:68
Definition of the Sonivox Synth configuration dialog.
MIDIOutput * outputBackendByName(const QString name)
outputBackendByName
SettingsFactory class declaration.