1 |
// qsamplerInstrumentForm.cpp |
// qsamplerInstrumentForm.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2003-2009, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, Christian Schoenebeck |
Copyright (C) 2007, Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
23 |
|
#include "qsamplerAbout.h" |
24 |
#include "qsamplerInstrumentForm.h" |
#include "qsamplerInstrumentForm.h" |
25 |
|
|
26 |
#include "qsamplerAbout.h" |
#include "qsamplerOptions.h" |
27 |
|
#include "qsamplerChannel.h" |
28 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
29 |
|
|
30 |
|
#include <QFileDialog> |
31 |
|
#include <QMessageBox> |
32 |
|
|
33 |
// Needed for lroundf() |
// Needed for lroundf() |
34 |
#include <math.h> |
#include <math.h> |
35 |
|
|
|
namespace QSampler { |
|
|
|
|
36 |
#ifndef CONFIG_ROUND |
#ifndef CONFIG_ROUND |
37 |
static inline long lroundf ( float x ) |
static inline long lroundf ( float x ) |
38 |
{ |
{ |
43 |
} |
} |
44 |
#endif |
#endif |
45 |
|
|
46 |
InstrumentForm::InstrumentForm(QWidget* parent) : QDialog(parent) { |
|
47 |
ui.setupUi(this); |
namespace QSampler { |
48 |
|
|
49 |
|
//------------------------------------------------------------------------- |
50 |
|
// QSampler::InstrumentForm -- Instrument map item form implementation. |
51 |
|
// |
52 |
|
|
53 |
|
InstrumentForm::InstrumentForm ( QWidget* pParent ) |
54 |
|
: QDialog(pParent) |
55 |
|
{ |
56 |
|
m_ui.setupUi(this); |
57 |
|
|
58 |
// Initialize locals. |
// Initialize locals. |
59 |
m_pInstrument = NULL; |
m_pInstrument = NULL; |
66 |
adjustSize(); |
adjustSize(); |
67 |
|
|
68 |
|
|
69 |
QObject::connect(ui.MapComboBox, |
QObject::connect(m_ui.MapComboBox, |
70 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
71 |
SLOT(changed())); |
SLOT(changed())); |
72 |
QObject::connect(ui.BankSpinBox, |
QObject::connect(m_ui.BankSpinBox, |
73 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
74 |
SLOT(changed())); |
SLOT(changed())); |
75 |
QObject::connect(ui.ProgSpinBox, |
QObject::connect(m_ui.ProgSpinBox, |
76 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
77 |
SLOT(changed())); |
SLOT(changed())); |
78 |
QObject::connect(ui.NameLineEdit, |
QObject::connect(m_ui.NameLineEdit, |
79 |
SIGNAL(textChanged(const QString&)), |
SIGNAL(textChanged(const QString&)), |
80 |
SLOT(nameChanged(const QString&))); |
SLOT(nameChanged(const QString&))); |
81 |
QObject::connect(ui.EngineNameComboBox, |
QObject::connect(m_ui.EngineNameComboBox, |
82 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
83 |
SLOT(changed())); |
SLOT(changed())); |
84 |
QObject::connect(ui.InstrumentFileComboBox, |
QObject::connect(m_ui.InstrumentFileComboBox, |
85 |
SIGNAL(activated(const QString&)), |
SIGNAL(activated(const QString&)), |
86 |
SLOT(updateInstrumentName())); |
SLOT(updateInstrumentName())); |
87 |
QObject::connect(ui.InstrumentFileToolButton, |
QObject::connect(m_ui.InstrumentFileToolButton, |
88 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
89 |
SLOT(openInstrumentFile())); |
SLOT(openInstrumentFile())); |
90 |
QObject::connect(ui.InstrumentNrComboBox, |
QObject::connect(m_ui.InstrumentNrComboBox, |
91 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
92 |
SLOT(instrumentNrChanged())); |
SLOT(instrumentNrChanged())); |
93 |
QObject::connect(ui.VolumeSpinBox, |
QObject::connect(m_ui.VolumeSpinBox, |
94 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
95 |
SLOT(changed())); |
SLOT(changed())); |
96 |
QObject::connect(ui.LoadModeComboBox, |
QObject::connect(m_ui.LoadModeComboBox, |
97 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
98 |
SLOT(changed())); |
SLOT(changed())); |
99 |
QObject::connect(ui.OkPushButton, |
QObject::connect(m_ui.OkPushButton, |
100 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
101 |
SLOT(accept())); |
SLOT(accept())); |
102 |
QObject::connect(ui.CancelPushButton, |
QObject::connect(m_ui.CancelPushButton, |
103 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
104 |
SLOT(reject())); |
SLOT(reject())); |
105 |
} |
} |
106 |
|
|
107 |
InstrumentForm::~InstrumentForm() { |
|
108 |
|
InstrumentForm::~InstrumentForm (void) |
109 |
|
{ |
110 |
} |
} |
111 |
|
|
112 |
|
|
113 |
// Channel dialog setup formal initializer. |
// Channel dialog setup formal initializer. |
114 |
void InstrumentForm::setup ( qsamplerInstrument *pInstrument ) |
void InstrumentForm::setup ( Instrument *pInstrument ) |
115 |
{ |
{ |
116 |
m_pInstrument = pInstrument; |
m_pInstrument = pInstrument; |
117 |
|
|
129 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
130 |
return; |
return; |
131 |
|
|
132 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
133 |
if (pOptions == NULL) |
if (pOptions == NULL) |
134 |
return; |
return; |
135 |
|
|
144 |
m_iDirtySetup++; |
m_iDirtySetup++; |
145 |
|
|
146 |
// Load combo box history... |
// Load combo box history... |
147 |
pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox); |
pOptions->loadComboBoxHistory(m_ui.InstrumentFileComboBox); |
148 |
|
|
149 |
// Populate maps list. |
// Populate maps list. |
150 |
ui.MapComboBox->clear(); |
m_ui.MapComboBox->clear(); |
151 |
ui.MapComboBox->insertStringList(qsamplerInstrument::getMapNames()); |
m_ui.MapComboBox->insertItems(0, Instrument::getMapNames()); |
152 |
|
|
153 |
// Populate Engines list. |
// Populate Engines list. |
154 |
const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client()); |
const char **ppszEngines |
155 |
|
= ::lscp_list_available_engines(pMainForm->client()); |
156 |
if (ppszEngines) { |
if (ppszEngines) { |
157 |
ui.EngineNameComboBox->clear(); |
m_ui.EngineNameComboBox->clear(); |
158 |
for (int iEngine = 0; ppszEngines[iEngine]; iEngine++) |
for (int iEngine = 0; ppszEngines[iEngine]; iEngine++) |
159 |
ui.EngineNameComboBox->insertItem(ppszEngines[iEngine]); |
m_ui.EngineNameComboBox->addItem(ppszEngines[iEngine]); |
160 |
} |
} |
161 |
else pMainForm->appendMessagesClient("lscp_list_available_engines"); |
else pMainForm->appendMessagesClient("lscp_list_available_engines"); |
162 |
|
|
167 |
int iMap = (bNew ? pOptions->iMidiMap : m_pInstrument->map()); |
int iMap = (bNew ? pOptions->iMidiMap : m_pInstrument->map()); |
168 |
if (iMap < 0) |
if (iMap < 0) |
169 |
iMap = 0; |
iMap = 0; |
170 |
const QString& sMapName = qsamplerInstrument::getMapName(iMap); |
const QString& sMapName = Instrument::getMapName(iMap); |
171 |
if (!sMapName.isEmpty()) |
if (!sMapName.isEmpty()) { |
172 |
ui.MapComboBox->setCurrentText(sMapName); |
m_ui.MapComboBox->setCurrentIndex( |
173 |
|
m_ui.MapComboBox->findText(sMapName, |
174 |
|
Qt::MatchExactly | Qt::MatchCaseSensitive)); |
175 |
|
} |
176 |
|
|
177 |
// It might be no maps around... |
// It might be no maps around... |
178 |
bool bMapEnabled = (ui.MapComboBox->count() > 0); |
bool bMapEnabled = (m_ui.MapComboBox->count() > 0); |
179 |
ui.MapTextLabel->setEnabled(bMapEnabled); |
m_ui.MapTextLabel->setEnabled(bMapEnabled); |
180 |
ui.MapComboBox->setEnabled(bMapEnabled); |
m_ui.MapComboBox->setEnabled(bMapEnabled); |
181 |
|
|
182 |
// Instrument bank/program... |
// Instrument bank/program... |
183 |
int iBank = (bNew ? pOptions->iMidiBank : m_pInstrument->bank()); |
int iBank = (bNew ? pOptions->iMidiBank : m_pInstrument->bank()); |
186 |
iProg = 1; |
iProg = 1; |
187 |
iBank++; |
iBank++; |
188 |
} |
} |
189 |
ui.BankSpinBox->setValue(iBank); |
m_ui.BankSpinBox->setValue(iBank); |
190 |
ui.ProgSpinBox->setValue(iProg); |
m_ui.ProgSpinBox->setValue(iProg); |
191 |
|
|
192 |
// Instrument name... |
// Instrument name... |
193 |
ui.NameLineEdit->setText(m_pInstrument->name()); |
m_ui.NameLineEdit->setText(m_pInstrument->name()); |
194 |
|
|
195 |
// Engine name... |
// Engine name... |
196 |
QString sEngineName = m_pInstrument->engineName(); |
QString sEngineName = m_pInstrument->engineName(); |
197 |
if (sEngineName.isEmpty() || bNew) |
if (sEngineName.isEmpty() || bNew) |
198 |
sEngineName = pOptions->sEngineName; |
sEngineName = pOptions->sEngineName; |
199 |
if (sEngineName.isEmpty()) |
if (sEngineName.isEmpty()) |
200 |
sEngineName = qsamplerChannel::noEngineName(); |
sEngineName = Channel::noEngineName(); |
201 |
if (ui.EngineNameComboBox->findText(sEngineName, |
if (m_ui.EngineNameComboBox->findText(sEngineName, |
202 |
Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { |
Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { |
203 |
ui.EngineNameComboBox->insertItem(sEngineName); |
m_ui.EngineNameComboBox->addItem(sEngineName); |
204 |
} |
} |
205 |
ui.EngineNameComboBox->setCurrentText(sEngineName); |
m_ui.EngineNameComboBox->setCurrentIndex( |
206 |
|
m_ui.EngineNameComboBox->findText(sEngineName, |
207 |
|
Qt::MatchExactly | Qt::MatchCaseSensitive)); |
208 |
|
|
209 |
// Instrument filename and index... |
// Instrument filename and index... |
210 |
QString sInstrumentFile = m_pInstrument->instrumentFile(); |
QString sInstrumentFile = m_pInstrument->instrumentFile(); |
211 |
if (sInstrumentFile.isEmpty()) |
if (sInstrumentFile.isEmpty()) |
212 |
sInstrumentFile = qsamplerChannel::noInstrumentName(); |
sInstrumentFile = Channel::noInstrumentName(); |
213 |
ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile); |
214 |
ui.InstrumentNrComboBox->clear(); |
m_ui.InstrumentNrComboBox->clear(); |
215 |
ui.InstrumentNrComboBox->insertStringList( |
m_ui.InstrumentNrComboBox->insertItems(0, |
216 |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
Channel::getInstrumentList(sInstrumentFile, |
217 |
pOptions->bInstrumentNames)); |
pOptions->bInstrumentNames)); |
218 |
ui.InstrumentNrComboBox->setCurrentItem(m_pInstrument->instrumentNr()); |
m_ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr()); |
219 |
|
|
220 |
// Instrument volume.... |
// Instrument volume.... |
221 |
int iVolume = (bNew ? pOptions->iVolume : |
int iVolume = (bNew ? pOptions->iVolume : |
222 |
::lroundf(100.0f * m_pInstrument->volume())); |
::lroundf(100.0f * m_pInstrument->volume())); |
223 |
ui.VolumeSpinBox->setValue(iVolume); |
m_ui.VolumeSpinBox->setValue(iVolume); |
224 |
|
|
225 |
// Instrument load mode... |
// Instrument load mode... |
226 |
int iLoadMode = (bNew ? pOptions->iLoadMode : |
int iLoadMode = (bNew ? pOptions->iLoadMode : |
227 |
m_pInstrument->loadMode()); |
m_pInstrument->loadMode()); |
228 |
ui.LoadModeComboBox->setCurrentItem(iLoadMode); |
m_ui.LoadModeComboBox->setCurrentIndex(iLoadMode); |
229 |
|
|
230 |
// Done. |
// Done. |
231 |
m_iDirtySetup--; |
m_iDirtySetup--; |
255 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
256 |
return; |
return; |
257 |
|
|
258 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
259 |
if (pOptions == NULL) |
if (pOptions == NULL) |
260 |
return; |
return; |
261 |
|
|
262 |
// FIXME: the instrument file filters should be restricted, |
// FIXME: the instrument file filters should be restricted, |
263 |
// depending on the current engine. |
// depending on the current engine. |
264 |
QString sInstrumentFile = QFileDialog::getOpenFileName( |
QString sInstrumentFile = QFileDialog::getOpenFileName(this, |
265 |
pOptions->sInstrumentDir, // Start here. |
QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption. |
266 |
tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files) |
pOptions->sInstrumentDir, // Start here. |
267 |
this, 0, // Parent and name (none) |
tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files) |
|
QSAMPLER_TITLE ": " + tr("Instrument files")// Caption. |
|
268 |
); |
); |
269 |
|
|
270 |
if (sInstrumentFile.isEmpty()) |
if (sInstrumentFile.isEmpty()) |
271 |
return; |
return; |
272 |
|
|
273 |
ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile); |
274 |
updateInstrumentName(); |
updateInstrumentName(); |
275 |
} |
} |
276 |
|
|
282 |
if (pMainForm == NULL) |
if (pMainForm == NULL) |
283 |
return; |
return; |
284 |
|
|
285 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
286 |
if (pOptions == NULL) |
if (pOptions == NULL) |
287 |
return; |
return; |
288 |
|
|
289 |
// TODO: this better idea would be to use libgig |
// TODO: this better idea would be to use libgig |
290 |
// to retrieve the REAL instrument names. |
// to retrieve the REAL instrument names. |
291 |
ui.InstrumentNrComboBox->clear(); |
m_ui.InstrumentNrComboBox->clear(); |
292 |
ui.InstrumentNrComboBox->insertStringList( |
m_ui.InstrumentNrComboBox->insertItems(0, |
293 |
qsamplerChannel::getInstrumentList( |
Channel::getInstrumentList( |
294 |
ui.InstrumentFileComboBox->currentText(), |
m_ui.InstrumentFileComboBox->currentText(), |
295 |
pOptions->bInstrumentNames) |
pOptions->bInstrumentNames) |
296 |
); |
); |
297 |
|
|
305 |
if (m_iDirtySetup > 0) |
if (m_iDirtySetup > 0) |
306 |
return; |
return; |
307 |
|
|
308 |
if (ui.NameLineEdit->text().isEmpty() || m_iDirtyName == 0) { |
if (m_ui.NameLineEdit->text().isEmpty() || m_iDirtyName == 0) { |
309 |
ui.NameLineEdit->setText(ui.InstrumentNrComboBox->currentText()); |
m_ui.NameLineEdit->setText(m_ui.InstrumentNrComboBox->currentText()); |
310 |
m_iDirtyName = 0; |
m_iDirtyName = 0; |
311 |
} |
} |
312 |
|
|
326 |
if (pMainForm->client() == NULL) |
if (pMainForm->client() == NULL) |
327 |
return; |
return; |
328 |
|
|
329 |
qsamplerOptions *pOptions = pMainForm->options(); |
Options *pOptions = pMainForm->options(); |
330 |
if (pOptions == NULL) |
if (pOptions == NULL) |
331 |
return; |
return; |
332 |
|
|
333 |
if (m_iDirtyCount > 0) { |
if (m_iDirtyCount > 0) { |
334 |
m_pInstrument->setMap(ui.MapComboBox->currentItem()); |
m_pInstrument->setMap(m_ui.MapComboBox->currentIndex()); |
335 |
m_pInstrument->setBank(ui.BankSpinBox->value()); |
m_pInstrument->setBank(m_ui.BankSpinBox->value()); |
336 |
m_pInstrument->setProg(ui.ProgSpinBox->value() - 1); |
m_pInstrument->setProg(m_ui.ProgSpinBox->value() - 1); |
337 |
m_pInstrument->setName(ui.NameLineEdit->text()); |
m_pInstrument->setName(m_ui.NameLineEdit->text()); |
338 |
m_pInstrument->setEngineName(ui.EngineNameComboBox->currentText()); |
m_pInstrument->setEngineName(m_ui.EngineNameComboBox->currentText()); |
339 |
m_pInstrument->setInstrumentFile(ui.InstrumentFileComboBox->currentText()); |
m_pInstrument->setInstrumentFile(m_ui.InstrumentFileComboBox->currentText()); |
340 |
m_pInstrument->setInstrumentNr(ui.InstrumentNrComboBox->currentItem()); |
m_pInstrument->setInstrumentNr(m_ui.InstrumentNrComboBox->currentIndex()); |
341 |
m_pInstrument->setVolume(0.01f * float(ui.VolumeSpinBox->value())); |
m_pInstrument->setVolume(0.01f * float(m_ui.VolumeSpinBox->value())); |
342 |
m_pInstrument->setLoadMode(ui.LoadModeComboBox->currentItem()); |
m_pInstrument->setLoadMode(m_ui.LoadModeComboBox->currentIndex()); |
343 |
} |
} |
344 |
|
|
345 |
// Save default engine name, instrument directory and history... |
// Save default engine name, instrument directory and history... |
346 |
pOptions->sInstrumentDir = QFileInfo(ui.InstrumentFileComboBox->currentText()).dirPath(true); |
pOptions->sInstrumentDir = QFileInfo( |
347 |
pOptions->sEngineName = ui.EngineNameComboBox->currentText(); |
m_ui.InstrumentFileComboBox->currentText()).dir().absolutePath(); |
348 |
pOptions->iMidiMap = ui.MapComboBox->currentItem(); |
pOptions->sEngineName = m_ui.EngineNameComboBox->currentText(); |
349 |
pOptions->iMidiBank = ui.BankSpinBox->value(); |
pOptions->iMidiMap = m_ui.MapComboBox->currentIndex(); |
350 |
pOptions->iMidiProg = ui.ProgSpinBox->value(); |
pOptions->iMidiBank = m_ui.BankSpinBox->value(); |
351 |
pOptions->iVolume = ui.VolumeSpinBox->value(); |
pOptions->iMidiProg = m_ui.ProgSpinBox->value(); |
352 |
pOptions->iLoadMode = ui.LoadModeComboBox->currentItem(); |
pOptions->iVolume = m_ui.VolumeSpinBox->value(); |
353 |
pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox); |
pOptions->iLoadMode = m_ui.LoadModeComboBox->currentIndex(); |
354 |
|
pOptions->saveComboBoxHistory(m_ui.InstrumentFileComboBox); |
355 |
|
|
356 |
// Just go with dialog acceptance. |
// Just go with dialog acceptance. |
357 |
QDialog::accept(); |
QDialog::accept(); |
364 |
bool bReject = true; |
bool bReject = true; |
365 |
|
|
366 |
// Check if there's any pending changes... |
// Check if there's any pending changes... |
367 |
if (m_iDirtyCount > 0 && ui.OkPushButton->isEnabled()) { |
if (m_iDirtyCount > 0 && m_ui.OkPushButton->isEnabled()) { |
368 |
switch (QMessageBox::warning(this, |
switch (QMessageBox::warning(this, |
369 |
QSAMPLER_TITLE ": " + tr("Warning"), |
QSAMPLER_TITLE ": " + tr("Warning"), |
370 |
tr("Some channel settings have been changed.\n\n" |
tr("Some channel settings have been changed.\n\n" |
371 |
"Do you want to apply the changes?"), |
"Do you want to apply the changes?"), |
372 |
tr("Apply"), tr("Discard"), tr("Cancel"))) { |
QMessageBox::Apply | |
373 |
case 0: // Apply... |
QMessageBox::Discard | |
374 |
|
QMessageBox::Cancel)) { |
375 |
|
case QMessageBox::Apply: |
376 |
accept(); |
accept(); |
377 |
return; |
return; |
378 |
case 1: // Discard |
case QMessageBox::Discard: |
379 |
break; |
break; |
380 |
default: // Cancel. |
default: // Cancel. |
381 |
bReject = false; |
bReject = false; |
402 |
// Stabilize current form state. |
// Stabilize current form state. |
403 |
void InstrumentForm::stabilizeForm (void) |
void InstrumentForm::stabilizeForm (void) |
404 |
{ |
{ |
405 |
bool bValid = !ui.NameLineEdit->text().isEmpty(); |
bool bValid = |
406 |
|
!m_ui.NameLineEdit->text().isEmpty() && |
407 |
|
m_ui.EngineNameComboBox->currentIndex() >= 0 && |
408 |
|
m_ui.EngineNameComboBox->currentText() != |
409 |
|
Channel::noEngineName(); |
410 |
|
|
411 |
const QString& sPath = ui.InstrumentFileComboBox->currentText(); |
const QString& sPath = m_ui.InstrumentFileComboBox->currentText(); |
412 |
bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); |
bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); |
413 |
|
|
414 |
ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid); |
m_ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid); |
415 |
} |
} |
416 |
|
|
417 |
} // namespace QSampler |
} // namespace QSampler |