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