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> |
#include <QFileDialog> |
49 |
InstrumentForm::InstrumentForm ( QWidget* pParent ) |
InstrumentForm::InstrumentForm ( QWidget* pParent ) |
50 |
: QDialog(pParent) |
: QDialog(pParent) |
51 |
{ |
{ |
52 |
ui.setupUi(this); |
m_ui.setupUi(this); |
53 |
|
|
54 |
// Initialize locals. |
// Initialize locals. |
55 |
m_pInstrument = NULL; |
m_pInstrument = NULL; |
62 |
adjustSize(); |
adjustSize(); |
63 |
|
|
64 |
|
|
65 |
QObject::connect(ui.MapComboBox, |
QObject::connect(m_ui.MapComboBox, |
66 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
67 |
SLOT(changed())); |
SLOT(changed())); |
68 |
QObject::connect(ui.BankSpinBox, |
QObject::connect(m_ui.BankSpinBox, |
69 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
70 |
SLOT(changed())); |
SLOT(changed())); |
71 |
QObject::connect(ui.ProgSpinBox, |
QObject::connect(m_ui.ProgSpinBox, |
72 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
73 |
SLOT(changed())); |
SLOT(changed())); |
74 |
QObject::connect(ui.NameLineEdit, |
QObject::connect(m_ui.NameLineEdit, |
75 |
SIGNAL(textChanged(const QString&)), |
SIGNAL(textChanged(const QString&)), |
76 |
SLOT(nameChanged(const QString&))); |
SLOT(nameChanged(const QString&))); |
77 |
QObject::connect(ui.EngineNameComboBox, |
QObject::connect(m_ui.EngineNameComboBox, |
78 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
79 |
SLOT(changed())); |
SLOT(changed())); |
80 |
QObject::connect(ui.InstrumentFileComboBox, |
QObject::connect(m_ui.InstrumentFileComboBox, |
81 |
SIGNAL(activated(const QString&)), |
SIGNAL(activated(const QString&)), |
82 |
SLOT(updateInstrumentName())); |
SLOT(updateInstrumentName())); |
83 |
QObject::connect(ui.InstrumentFileToolButton, |
QObject::connect(m_ui.InstrumentFileToolButton, |
84 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
85 |
SLOT(openInstrumentFile())); |
SLOT(openInstrumentFile())); |
86 |
QObject::connect(ui.InstrumentNrComboBox, |
QObject::connect(m_ui.InstrumentNrComboBox, |
87 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
88 |
SLOT(instrumentNrChanged())); |
SLOT(instrumentNrChanged())); |
89 |
QObject::connect(ui.VolumeSpinBox, |
QObject::connect(m_ui.VolumeSpinBox, |
90 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
91 |
SLOT(changed())); |
SLOT(changed())); |
92 |
QObject::connect(ui.LoadModeComboBox, |
QObject::connect(m_ui.LoadModeComboBox, |
93 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
94 |
SLOT(changed())); |
SLOT(changed())); |
95 |
QObject::connect(ui.OkPushButton, |
QObject::connect(m_ui.OkPushButton, |
96 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
97 |
SLOT(accept())); |
SLOT(accept())); |
98 |
QObject::connect(ui.CancelPushButton, |
QObject::connect(m_ui.CancelPushButton, |
99 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
100 |
SLOT(reject())); |
SLOT(reject())); |
101 |
} |
} |
140 |
m_iDirtySetup++; |
m_iDirtySetup++; |
141 |
|
|
142 |
// Load combo box history... |
// Load combo box history... |
143 |
pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox); |
pOptions->loadComboBoxHistory(m_ui.InstrumentFileComboBox); |
144 |
|
|
145 |
// Populate maps list. |
// Populate maps list. |
146 |
ui.MapComboBox->clear(); |
m_ui.MapComboBox->clear(); |
147 |
ui.MapComboBox->insertItems(0, qsamplerInstrument::getMapNames()); |
m_ui.MapComboBox->insertItems(0, qsamplerInstrument::getMapNames()); |
148 |
|
|
149 |
// Populate Engines list. |
// Populate Engines list. |
150 |
const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client()); |
const char **ppszEngines |
151 |
|
= ::lscp_list_available_engines(pMainForm->client()); |
152 |
if (ppszEngines) { |
if (ppszEngines) { |
153 |
ui.EngineNameComboBox->clear(); |
m_ui.EngineNameComboBox->clear(); |
154 |
for (int iEngine = 0; ppszEngines[iEngine]; iEngine++) |
for (int iEngine = 0; ppszEngines[iEngine]; iEngine++) |
155 |
ui.EngineNameComboBox->addItem(ppszEngines[iEngine]); |
m_ui.EngineNameComboBox->addItem(ppszEngines[iEngine]); |
156 |
} |
} |
157 |
else pMainForm->appendMessagesClient("lscp_list_available_engines"); |
else pMainForm->appendMessagesClient("lscp_list_available_engines"); |
158 |
|
|
165 |
iMap = 0; |
iMap = 0; |
166 |
const QString& sMapName = qsamplerInstrument::getMapName(iMap); |
const QString& sMapName = qsamplerInstrument::getMapName(iMap); |
167 |
if (!sMapName.isEmpty()) { |
if (!sMapName.isEmpty()) { |
168 |
ui.MapComboBox->setItemText( |
m_ui.MapComboBox->setItemText( |
169 |
ui.MapComboBox->currentIndex(), |
m_ui.MapComboBox->currentIndex(), |
170 |
sMapName); |
sMapName); |
171 |
} |
} |
172 |
// It might be no maps around... |
// It might be no maps around... |
173 |
bool bMapEnabled = (ui.MapComboBox->count() > 0); |
bool bMapEnabled = (m_ui.MapComboBox->count() > 0); |
174 |
ui.MapTextLabel->setEnabled(bMapEnabled); |
m_ui.MapTextLabel->setEnabled(bMapEnabled); |
175 |
ui.MapComboBox->setEnabled(bMapEnabled); |
m_ui.MapComboBox->setEnabled(bMapEnabled); |
176 |
|
|
177 |
// Instrument bank/program... |
// Instrument bank/program... |
178 |
int iBank = (bNew ? pOptions->iMidiBank : m_pInstrument->bank()); |
int iBank = (bNew ? pOptions->iMidiBank : m_pInstrument->bank()); |
181 |
iProg = 1; |
iProg = 1; |
182 |
iBank++; |
iBank++; |
183 |
} |
} |
184 |
ui.BankSpinBox->setValue(iBank); |
m_ui.BankSpinBox->setValue(iBank); |
185 |
ui.ProgSpinBox->setValue(iProg); |
m_ui.ProgSpinBox->setValue(iProg); |
186 |
|
|
187 |
// Instrument name... |
// Instrument name... |
188 |
ui.NameLineEdit->setText(m_pInstrument->name()); |
m_ui.NameLineEdit->setText(m_pInstrument->name()); |
189 |
|
|
190 |
// Engine name... |
// Engine name... |
191 |
QString sEngineName = m_pInstrument->engineName(); |
QString sEngineName = m_pInstrument->engineName(); |
193 |
sEngineName = pOptions->sEngineName; |
sEngineName = pOptions->sEngineName; |
194 |
if (sEngineName.isEmpty()) |
if (sEngineName.isEmpty()) |
195 |
sEngineName = qsamplerChannel::noEngineName(); |
sEngineName = qsamplerChannel::noEngineName(); |
196 |
if (ui.EngineNameComboBox->findText(sEngineName, |
if (m_ui.EngineNameComboBox->findText(sEngineName, |
197 |
Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { |
Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { |
198 |
ui.EngineNameComboBox->addItem(sEngineName); |
m_ui.EngineNameComboBox->addItem(sEngineName); |
199 |
} |
} |
200 |
ui.EngineNameComboBox->setCurrentIndex( |
m_ui.EngineNameComboBox->setCurrentIndex( |
201 |
ui.EngineNameComboBox->findText(sEngineName, |
m_ui.EngineNameComboBox->findText(sEngineName, |
202 |
Qt::MatchExactly | Qt::MatchCaseSensitive)); |
Qt::MatchExactly | Qt::MatchCaseSensitive)); |
203 |
|
|
204 |
// Instrument filename and index... |
// Instrument filename and index... |
205 |
QString sInstrumentFile = m_pInstrument->instrumentFile(); |
QString sInstrumentFile = m_pInstrument->instrumentFile(); |
206 |
if (sInstrumentFile.isEmpty()) |
if (sInstrumentFile.isEmpty()) |
207 |
sInstrumentFile = qsamplerChannel::noInstrumentName(); |
sInstrumentFile = qsamplerChannel::noInstrumentName(); |
208 |
ui.InstrumentFileComboBox->setItemText( |
m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile); |
209 |
ui.InstrumentFileComboBox->currentIndex(), |
m_ui.InstrumentNrComboBox->clear(); |
210 |
sInstrumentFile); |
m_ui.InstrumentNrComboBox->insertItems(0, |
|
ui.InstrumentNrComboBox->clear(); |
|
|
ui.InstrumentNrComboBox->insertItems(0, |
|
211 |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
212 |
pOptions->bInstrumentNames)); |
pOptions->bInstrumentNames)); |
213 |
ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr()); |
m_ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr()); |
214 |
|
|
215 |
// Instrument volume.... |
// Instrument volume.... |
216 |
int iVolume = (bNew ? pOptions->iVolume : |
int iVolume = (bNew ? pOptions->iVolume : |
217 |
::lroundf(100.0f * m_pInstrument->volume())); |
::lroundf(100.0f * m_pInstrument->volume())); |
218 |
ui.VolumeSpinBox->setValue(iVolume); |
m_ui.VolumeSpinBox->setValue(iVolume); |
219 |
|
|
220 |
// Instrument load mode... |
// Instrument load mode... |
221 |
int iLoadMode = (bNew ? pOptions->iLoadMode : |
int iLoadMode = (bNew ? pOptions->iLoadMode : |
222 |
m_pInstrument->loadMode()); |
m_pInstrument->loadMode()); |
223 |
ui.LoadModeComboBox->setCurrentIndex(iLoadMode); |
m_ui.LoadModeComboBox->setCurrentIndex(iLoadMode); |
224 |
|
|
225 |
// Done. |
// Done. |
226 |
m_iDirtySetup--; |
m_iDirtySetup--; |
265 |
if (sInstrumentFile.isEmpty()) |
if (sInstrumentFile.isEmpty()) |
266 |
return; |
return; |
267 |
|
|
268 |
ui.InstrumentFileComboBox->setItemText( |
m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile); |
|
ui.InstrumentFileComboBox->currentIndex(), |
|
|
sInstrumentFile); |
|
|
|
|
269 |
updateInstrumentName(); |
updateInstrumentName(); |
270 |
} |
} |
271 |
|
|
283 |
|
|
284 |
// TODO: this better idea would be to use libgig |
// TODO: this better idea would be to use libgig |
285 |
// to retrieve the REAL instrument names. |
// to retrieve the REAL instrument names. |
286 |
ui.InstrumentNrComboBox->clear(); |
m_ui.InstrumentNrComboBox->clear(); |
287 |
ui.InstrumentNrComboBox->insertItems(0, |
m_ui.InstrumentNrComboBox->insertItems(0, |
288 |
qsamplerChannel::getInstrumentList( |
qsamplerChannel::getInstrumentList( |
289 |
ui.InstrumentFileComboBox->currentText(), |
m_ui.InstrumentFileComboBox->currentText(), |
290 |
pOptions->bInstrumentNames) |
pOptions->bInstrumentNames) |
291 |
); |
); |
292 |
|
|
300 |
if (m_iDirtySetup > 0) |
if (m_iDirtySetup > 0) |
301 |
return; |
return; |
302 |
|
|
303 |
if (ui.NameLineEdit->text().isEmpty() || m_iDirtyName == 0) { |
if (m_ui.NameLineEdit->text().isEmpty() || m_iDirtyName == 0) { |
304 |
ui.NameLineEdit->setText(ui.InstrumentNrComboBox->currentText()); |
m_ui.NameLineEdit->setText(m_ui.InstrumentNrComboBox->currentText()); |
305 |
m_iDirtyName = 0; |
m_iDirtyName = 0; |
306 |
} |
} |
307 |
|
|
326 |
return; |
return; |
327 |
|
|
328 |
if (m_iDirtyCount > 0) { |
if (m_iDirtyCount > 0) { |
329 |
m_pInstrument->setMap(ui.MapComboBox->currentIndex()); |
m_pInstrument->setMap(m_ui.MapComboBox->currentIndex()); |
330 |
m_pInstrument->setBank(ui.BankSpinBox->value()); |
m_pInstrument->setBank(m_ui.BankSpinBox->value()); |
331 |
m_pInstrument->setProg(ui.ProgSpinBox->value() - 1); |
m_pInstrument->setProg(m_ui.ProgSpinBox->value() - 1); |
332 |
m_pInstrument->setName(ui.NameLineEdit->text()); |
m_pInstrument->setName(m_ui.NameLineEdit->text()); |
333 |
m_pInstrument->setEngineName(ui.EngineNameComboBox->currentText()); |
m_pInstrument->setEngineName(m_ui.EngineNameComboBox->currentText()); |
334 |
m_pInstrument->setInstrumentFile(ui.InstrumentFileComboBox->currentText()); |
m_pInstrument->setInstrumentFile(m_ui.InstrumentFileComboBox->currentText()); |
335 |
m_pInstrument->setInstrumentNr(ui.InstrumentNrComboBox->currentIndex()); |
m_pInstrument->setInstrumentNr(m_ui.InstrumentNrComboBox->currentIndex()); |
336 |
m_pInstrument->setVolume(0.01f * float(ui.VolumeSpinBox->value())); |
m_pInstrument->setVolume(0.01f * float(m_ui.VolumeSpinBox->value())); |
337 |
m_pInstrument->setLoadMode(ui.LoadModeComboBox->currentIndex()); |
m_pInstrument->setLoadMode(m_ui.LoadModeComboBox->currentIndex()); |
338 |
} |
} |
339 |
|
|
340 |
// Save default engine name, instrument directory and history... |
// Save default engine name, instrument directory and history... |
341 |
pOptions->sInstrumentDir = QFileInfo( |
pOptions->sInstrumentDir = QFileInfo( |
342 |
ui.InstrumentFileComboBox->currentText()).dir().absolutePath(); |
m_ui.InstrumentFileComboBox->currentText()).dir().absolutePath(); |
343 |
pOptions->sEngineName = ui.EngineNameComboBox->currentText(); |
pOptions->sEngineName = m_ui.EngineNameComboBox->currentText(); |
344 |
pOptions->iMidiMap = ui.MapComboBox->currentIndex(); |
pOptions->iMidiMap = m_ui.MapComboBox->currentIndex(); |
345 |
pOptions->iMidiBank = ui.BankSpinBox->value(); |
pOptions->iMidiBank = m_ui.BankSpinBox->value(); |
346 |
pOptions->iMidiProg = ui.ProgSpinBox->value(); |
pOptions->iMidiProg = m_ui.ProgSpinBox->value(); |
347 |
pOptions->iVolume = ui.VolumeSpinBox->value(); |
pOptions->iVolume = m_ui.VolumeSpinBox->value(); |
348 |
pOptions->iLoadMode = ui.LoadModeComboBox->currentIndex(); |
pOptions->iLoadMode = m_ui.LoadModeComboBox->currentIndex(); |
349 |
pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox); |
pOptions->saveComboBoxHistory(m_ui.InstrumentFileComboBox); |
350 |
|
|
351 |
// Just go with dialog acceptance. |
// Just go with dialog acceptance. |
352 |
QDialog::accept(); |
QDialog::accept(); |
359 |
bool bReject = true; |
bool bReject = true; |
360 |
|
|
361 |
// Check if there's any pending changes... |
// Check if there's any pending changes... |
362 |
if (m_iDirtyCount > 0 && ui.OkPushButton->isEnabled()) { |
if (m_iDirtyCount > 0 && m_ui.OkPushButton->isEnabled()) { |
363 |
switch (QMessageBox::warning(this, |
switch (QMessageBox::warning(this, |
364 |
QSAMPLER_TITLE ": " + tr("Warning"), |
QSAMPLER_TITLE ": " + tr("Warning"), |
365 |
tr("Some channel settings have been changed.\n\n" |
tr("Some channel settings have been changed.\n\n" |
395 |
// Stabilize current form state. |
// Stabilize current form state. |
396 |
void InstrumentForm::stabilizeForm (void) |
void InstrumentForm::stabilizeForm (void) |
397 |
{ |
{ |
398 |
bool bValid = !ui.NameLineEdit->text().isEmpty(); |
bool bValid = |
399 |
|
!m_ui.NameLineEdit->text().isEmpty() && |
400 |
|
m_ui.EngineNameComboBox->currentIndex() >= 0 && |
401 |
|
m_ui.EngineNameComboBox->currentText() != |
402 |
|
qsamplerChannel::noEngineName(); |
403 |
|
|
404 |
const QString& sPath = ui.InstrumentFileComboBox->currentText(); |
const QString& sPath = m_ui.InstrumentFileComboBox->currentText(); |
405 |
bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); |
bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); |
406 |
|
|
407 |
ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid); |
m_ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid); |
408 |
} |
} |
409 |
|
|
410 |
} // namespace QSampler |
} // namespace QSampler |