25 |
#include "qsamplerAbout.h" |
#include "qsamplerAbout.h" |
26 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
27 |
|
|
28 |
|
#include <QFileDialog> |
29 |
|
#include <QMessageBox> |
30 |
|
|
31 |
// Needed for lroundf() |
// Needed for lroundf() |
32 |
#include <math.h> |
#include <math.h> |
33 |
|
|
34 |
|
|
35 |
namespace QSampler { |
namespace QSampler { |
36 |
|
|
37 |
#ifndef CONFIG_ROUND |
#ifndef CONFIG_ROUND |
44 |
} |
} |
45 |
#endif |
#endif |
46 |
|
|
47 |
InstrumentForm::InstrumentForm(QWidget* parent) : QDialog(parent) { |
InstrumentForm::InstrumentForm ( QWidget* pParent ) |
48 |
|
: QDialog(pParent) |
49 |
|
{ |
50 |
ui.setupUi(this); |
ui.setupUi(this); |
51 |
|
|
52 |
// Initialize locals. |
// Initialize locals. |
70 |
SIGNAL(valueChanged(int)), |
SIGNAL(valueChanged(int)), |
71 |
SLOT(changed())); |
SLOT(changed())); |
72 |
QObject::connect(ui.NameLineEdit, |
QObject::connect(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(ui.EngineNameComboBox, |
76 |
SIGNAL(activated(int)), |
SIGNAL(activated(int)), |
77 |
SLOT(changed())); |
SLOT(changed())); |
78 |
QObject::connect(ui.InstrumentFileComboBox, |
QObject::connect(ui.InstrumentFileComboBox, |
79 |
SIGNAL(activated(const QString&)), |
SIGNAL(activated(const QString&)), |
80 |
SLOT(updateInstrumentName())); |
SLOT(updateInstrumentName())); |
81 |
QObject::connect(ui.InstrumentFileToolButton, |
QObject::connect(ui.InstrumentFileToolButton, |
82 |
SIGNAL(clicked()), |
SIGNAL(clicked()), |
98 |
SLOT(reject())); |
SLOT(reject())); |
99 |
} |
} |
100 |
|
|
101 |
InstrumentForm::~InstrumentForm() { |
|
102 |
|
InstrumentForm::~InstrumentForm (void) |
103 |
|
{ |
104 |
} |
} |
105 |
|
|
106 |
|
|
107 |
// Channel dialog setup formal initializer. |
// Channel dialog setup formal initializer. |
108 |
void InstrumentForm::setup ( qsamplerInstrument *pInstrument ) |
void InstrumentForm::setup ( qsamplerInstrument *pInstrument ) |
109 |
{ |
{ |
142 |
|
|
143 |
// Populate maps list. |
// Populate maps list. |
144 |
ui.MapComboBox->clear(); |
ui.MapComboBox->clear(); |
145 |
ui.MapComboBox->insertStringList(qsamplerInstrument::getMapNames()); |
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 = ::lscp_list_available_engines(pMainForm->client()); |
149 |
if (ppszEngines) { |
if (ppszEngines) { |
150 |
ui.EngineNameComboBox->clear(); |
ui.EngineNameComboBox->clear(); |
151 |
for (int iEngine = 0; ppszEngines[iEngine]; iEngine++) |
for (int iEngine = 0; ppszEngines[iEngine]; iEngine++) |
152 |
ui.EngineNameComboBox->insertItem(ppszEngines[iEngine]); |
ui.EngineNameComboBox->addItem(ppszEngines[iEngine]); |
153 |
} |
} |
154 |
else pMainForm->appendMessagesClient("lscp_list_available_engines"); |
else pMainForm->appendMessagesClient("lscp_list_available_engines"); |
155 |
|
|
161 |
if (iMap < 0) |
if (iMap < 0) |
162 |
iMap = 0; |
iMap = 0; |
163 |
const QString& sMapName = qsamplerInstrument::getMapName(iMap); |
const QString& sMapName = qsamplerInstrument::getMapName(iMap); |
164 |
if (!sMapName.isEmpty()) |
if (!sMapName.isEmpty()) { |
165 |
ui.MapComboBox->setCurrentText(sMapName); |
ui.MapComboBox->setItemText( |
166 |
|
ui.MapComboBox->currentIndex(), |
167 |
|
sMapName); |
168 |
|
} |
169 |
// It might be no maps around... |
// It might be no maps around... |
170 |
bool bMapEnabled = (ui.MapComboBox->count() > 0); |
bool bMapEnabled = (ui.MapComboBox->count() > 0); |
171 |
ui.MapTextLabel->setEnabled(bMapEnabled); |
ui.MapTextLabel->setEnabled(bMapEnabled); |
191 |
if (sEngineName.isEmpty()) |
if (sEngineName.isEmpty()) |
192 |
sEngineName = qsamplerChannel::noEngineName(); |
sEngineName = qsamplerChannel::noEngineName(); |
193 |
if (ui.EngineNameComboBox->findText(sEngineName, |
if (ui.EngineNameComboBox->findText(sEngineName, |
194 |
Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) { |
Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { |
195 |
ui.EngineNameComboBox->insertItem(sEngineName); |
ui.EngineNameComboBox->addItem(sEngineName); |
196 |
} |
} |
197 |
ui.EngineNameComboBox->setCurrentText(sEngineName); |
ui.EngineNameComboBox->setCurrentIndex( |
198 |
|
ui.EngineNameComboBox->findText(sEngineName, |
199 |
|
Qt::MatchExactly | Qt::MatchCaseSensitive)); |
200 |
|
|
201 |
// Instrument filename and index... |
// Instrument filename and index... |
202 |
QString sInstrumentFile = m_pInstrument->instrumentFile(); |
QString sInstrumentFile = m_pInstrument->instrumentFile(); |
203 |
if (sInstrumentFile.isEmpty()) |
if (sInstrumentFile.isEmpty()) |
204 |
sInstrumentFile = qsamplerChannel::noInstrumentName(); |
sInstrumentFile = qsamplerChannel::noInstrumentName(); |
205 |
ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
ui.InstrumentFileComboBox->setEditText(sInstrumentFile); |
206 |
ui.InstrumentNrComboBox->clear(); |
ui.InstrumentNrComboBox->clear(); |
207 |
ui.InstrumentNrComboBox->insertStringList( |
ui.InstrumentNrComboBox->insertItems(0, |
208 |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
qsamplerChannel::getInstrumentList(sInstrumentFile, |
209 |
pOptions->bInstrumentNames)); |
pOptions->bInstrumentNames)); |
210 |
ui.InstrumentNrComboBox->setCurrentItem(m_pInstrument->instrumentNr()); |
ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr()); |
211 |
|
|
212 |
// Instrument volume.... |
// Instrument volume.... |
213 |
int iVolume = (bNew ? pOptions->iVolume : |
int iVolume = (bNew ? pOptions->iVolume : |
217 |
// Instrument load mode... |
// Instrument load mode... |
218 |
int iLoadMode = (bNew ? pOptions->iLoadMode : |
int iLoadMode = (bNew ? pOptions->iLoadMode : |
219 |
m_pInstrument->loadMode()); |
m_pInstrument->loadMode()); |
220 |
ui.LoadModeComboBox->setCurrentItem(iLoadMode); |
ui.LoadModeComboBox->setCurrentIndex(iLoadMode); |
221 |
|
|
222 |
// Done. |
// Done. |
223 |
m_iDirtySetup--; |
m_iDirtySetup--; |
253 |
|
|
254 |
// FIXME: the instrument file filters should be restricted, |
// FIXME: the instrument file filters should be restricted, |
255 |
// depending on the current engine. |
// depending on the current engine. |
256 |
QString sInstrumentFile = QFileDialog::getOpenFileName( |
QString sInstrumentFile = QFileDialog::getOpenFileName(this, |
257 |
pOptions->sInstrumentDir, // Start here. |
QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption. |
258 |
tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files) |
pOptions->sInstrumentDir, // Start here. |
259 |
this, 0, // Parent and name (none) |
tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files) |
|
QSAMPLER_TITLE ": " + tr("Instrument files")// Caption. |
|
260 |
); |
); |
261 |
|
|
262 |
if (sInstrumentFile.isEmpty()) |
if (sInstrumentFile.isEmpty()) |
263 |
return; |
return; |
264 |
|
|
265 |
ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile); |
ui.InstrumentFileComboBox->setEditText(sInstrumentFile); |
266 |
updateInstrumentName(); |
updateInstrumentName(); |
267 |
} |
} |
268 |
|
|
281 |
// TODO: this better idea would be to use libgig |
// TODO: this better idea would be to use libgig |
282 |
// to retrieve the REAL instrument names. |
// to retrieve the REAL instrument names. |
283 |
ui.InstrumentNrComboBox->clear(); |
ui.InstrumentNrComboBox->clear(); |
284 |
ui.InstrumentNrComboBox->insertStringList( |
ui.InstrumentNrComboBox->insertItems(0, |
285 |
qsamplerChannel::getInstrumentList( |
qsamplerChannel::getInstrumentList( |
286 |
ui.InstrumentFileComboBox->currentText(), |
ui.InstrumentFileComboBox->currentText(), |
287 |
pOptions->bInstrumentNames) |
pOptions->bInstrumentNames) |
323 |
return; |
return; |
324 |
|
|
325 |
if (m_iDirtyCount > 0) { |
if (m_iDirtyCount > 0) { |
326 |
m_pInstrument->setMap(ui.MapComboBox->currentItem()); |
m_pInstrument->setMap(ui.MapComboBox->currentIndex()); |
327 |
m_pInstrument->setBank(ui.BankSpinBox->value()); |
m_pInstrument->setBank(ui.BankSpinBox->value()); |
328 |
m_pInstrument->setProg(ui.ProgSpinBox->value() - 1); |
m_pInstrument->setProg(ui.ProgSpinBox->value() - 1); |
329 |
m_pInstrument->setName(ui.NameLineEdit->text()); |
m_pInstrument->setName(ui.NameLineEdit->text()); |
330 |
m_pInstrument->setEngineName(ui.EngineNameComboBox->currentText()); |
m_pInstrument->setEngineName(ui.EngineNameComboBox->currentText()); |
331 |
m_pInstrument->setInstrumentFile(ui.InstrumentFileComboBox->currentText()); |
m_pInstrument->setInstrumentFile(ui.InstrumentFileComboBox->currentText()); |
332 |
m_pInstrument->setInstrumentNr(ui.InstrumentNrComboBox->currentItem()); |
m_pInstrument->setInstrumentNr(ui.InstrumentNrComboBox->currentIndex()); |
333 |
m_pInstrument->setVolume(0.01f * float(ui.VolumeSpinBox->value())); |
m_pInstrument->setVolume(0.01f * float(ui.VolumeSpinBox->value())); |
334 |
m_pInstrument->setLoadMode(ui.LoadModeComboBox->currentItem()); |
m_pInstrument->setLoadMode(ui.LoadModeComboBox->currentIndex()); |
335 |
} |
} |
336 |
|
|
337 |
// Save default engine name, instrument directory and history... |
// Save default engine name, instrument directory and history... |
338 |
pOptions->sInstrumentDir = QFileInfo(ui.InstrumentFileComboBox->currentText()).dirPath(true); |
pOptions->sInstrumentDir = QFileInfo( |
339 |
|
ui.InstrumentFileComboBox->currentText()).dir().absolutePath(); |
340 |
pOptions->sEngineName = ui.EngineNameComboBox->currentText(); |
pOptions->sEngineName = ui.EngineNameComboBox->currentText(); |
341 |
pOptions->iMidiMap = ui.MapComboBox->currentItem(); |
pOptions->iMidiMap = ui.MapComboBox->currentIndex(); |
342 |
pOptions->iMidiBank = ui.BankSpinBox->value(); |
pOptions->iMidiBank = ui.BankSpinBox->value(); |
343 |
pOptions->iMidiProg = ui.ProgSpinBox->value(); |
pOptions->iMidiProg = ui.ProgSpinBox->value(); |
344 |
pOptions->iVolume = ui.VolumeSpinBox->value(); |
pOptions->iVolume = ui.VolumeSpinBox->value(); |
345 |
pOptions->iLoadMode = ui.LoadModeComboBox->currentItem(); |
pOptions->iLoadMode = ui.LoadModeComboBox->currentIndex(); |
346 |
pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox); |
pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox); |
347 |
|
|
348 |
// Just go with dialog acceptance. |
// Just go with dialog acceptance. |
392 |
// Stabilize current form state. |
// Stabilize current form state. |
393 |
void InstrumentForm::stabilizeForm (void) |
void InstrumentForm::stabilizeForm (void) |
394 |
{ |
{ |
395 |
bool bValid = !ui.NameLineEdit->text().isEmpty(); |
bool bValid = |
396 |
|
!ui.NameLineEdit->text().isEmpty() && |
397 |
|
ui.EngineNameComboBox->currentIndex() >= 0 && |
398 |
|
ui.EngineNameComboBox->currentText() != |
399 |
|
qsamplerChannel::noEngineName(); |
400 |
|
|
401 |
const QString& sPath = ui.InstrumentFileComboBox->currentText(); |
const QString& sPath = ui.InstrumentFileComboBox->currentText(); |
402 |
bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); |
bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); |