--- qsampler/trunk/src/qsamplerInstrumentForm.cpp 2007/11/01 17:14:21 1464 +++ qsampler/trunk/src/qsamplerInstrumentForm.cpp 2010/07/17 12:21:01 2110 @@ -1,7 +1,7 @@ // qsamplerInstrumentForm.cpp // /**************************************************************************** - Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2003-2010, rncbc aka Rui Nuno Capela. All rights reserved. Copyright (C) 2007, Christian Schoenebeck This program is free software; you can redistribute it and/or @@ -20,16 +20,20 @@ *****************************************************************************/ +#include "qsamplerAbout.h" #include "qsamplerInstrumentForm.h" -#include "qsamplerAbout.h" +#include "qsamplerOptions.h" +#include "qsamplerChannel.h" #include "qsamplerMainForm.h" +#include +#include +#include + // Needed for lroundf() #include -namespace QSampler { - #ifndef CONFIG_ROUND static inline long lroundf ( float x ) { @@ -40,8 +44,17 @@ } #endif -InstrumentForm::InstrumentForm(QWidget* parent) : QDialog(parent) { - ui.setupUi(this); + +namespace QSampler { + +//------------------------------------------------------------------------- +// QSampler::InstrumentForm -- Instrument map item form implementation. +// + +InstrumentForm::InstrumentForm ( QWidget *pParent ) + : QDialog(pParent) +{ + m_ui.setupUi(this); // Initialize locals. m_pInstrument = NULL; @@ -52,13 +65,54 @@ // Try to restore normal window positioning. adjustSize(); + + + QObject::connect(m_ui.MapComboBox, + SIGNAL(activated(int)), + SLOT(changed())); + QObject::connect(m_ui.BankSpinBox, + SIGNAL(valueChanged(int)), + SLOT(changed())); + QObject::connect(m_ui.ProgSpinBox, + SIGNAL(valueChanged(int)), + SLOT(changed())); + QObject::connect(m_ui.NameLineEdit, + SIGNAL(textChanged(const QString&)), + SLOT(nameChanged(const QString&))); + QObject::connect(m_ui.EngineNameComboBox, + SIGNAL(activated(int)), + SLOT(changed())); + QObject::connect(m_ui.InstrumentFileComboBox, + SIGNAL(activated(const QString&)), + SLOT(updateInstrumentName())); + QObject::connect(m_ui.InstrumentFileToolButton, + SIGNAL(clicked()), + SLOT(openInstrumentFile())); + QObject::connect(m_ui.InstrumentNrComboBox, + SIGNAL(activated(int)), + SLOT(instrumentNrChanged())); + QObject::connect(m_ui.VolumeSpinBox, + SIGNAL(valueChanged(int)), + SLOT(changed())); + QObject::connect(m_ui.LoadModeComboBox, + SIGNAL(activated(int)), + SLOT(changed())); + QObject::connect(m_ui.DialogButtonBox, + SIGNAL(accepted()), + SLOT(accept())); + QObject::connect(m_ui.DialogButtonBox, + SIGNAL(rejected()), + SLOT(reject())); } -InstrumentForm::~InstrumentForm() { + +InstrumentForm::~InstrumentForm (void) +{ } + // Channel dialog setup formal initializer. -void InstrumentForm::setup ( qsamplerInstrument *pInstrument ) +void InstrumentForm::setup ( Instrument *pInstrument ) { m_pInstrument = pInstrument; @@ -76,7 +130,7 @@ if (pMainForm->client() == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; @@ -91,18 +145,19 @@ m_iDirtySetup++; // Load combo box history... - pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox); + pOptions->loadComboBoxHistory(m_ui.InstrumentFileComboBox); // Populate maps list. - ui.MapComboBox->clear(); - ui.MapComboBox->insertStringList(qsamplerInstrument::getMapNames()); + m_ui.MapComboBox->clear(); + m_ui.MapComboBox->insertItems(0, Instrument::getMapNames()); // Populate Engines list. - const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client()); + const char **ppszEngines + = ::lscp_list_available_engines(pMainForm->client()); if (ppszEngines) { - ui.EngineNameComboBox->clear(); + m_ui.EngineNameComboBox->clear(); for (int iEngine = 0; ppszEngines[iEngine]; iEngine++) - ui.EngineNameComboBox->insertItem(ppszEngines[iEngine]); + m_ui.EngineNameComboBox->addItem(ppszEngines[iEngine]); } else pMainForm->appendMessagesClient("lscp_list_available_engines"); @@ -113,13 +168,17 @@ int iMap = (bNew ? pOptions->iMidiMap : m_pInstrument->map()); if (iMap < 0) iMap = 0; - const QString& sMapName = qsamplerInstrument::getMapName(iMap); - if (!sMapName.isEmpty()) - ui.MapComboBox->setCurrentText(sMapName); + const QString& sMapName = Instrument::getMapName(iMap); + if (!sMapName.isEmpty()) { + m_ui.MapComboBox->setCurrentIndex( + m_ui.MapComboBox->findText(sMapName, + Qt::MatchExactly | Qt::MatchCaseSensitive)); + } + // It might be no maps around... - bool bMapEnabled = (ui.MapComboBox->count() > 0); - ui.MapTextLabel->setEnabled(bMapEnabled); - ui.MapComboBox->setEnabled(bMapEnabled); + bool bMapEnabled = (m_ui.MapComboBox->count() > 0); + m_ui.MapTextLabel->setEnabled(bMapEnabled); + m_ui.MapComboBox->setEnabled(bMapEnabled); // Instrument bank/program... int iBank = (bNew ? pOptions->iMidiBank : m_pInstrument->bank()); @@ -128,47 +187,46 @@ iProg = 1; iBank++; } - ui.BankSpinBox->setValue(iBank); - ui.ProgSpinBox->setValue(iProg); + m_ui.BankSpinBox->setValue(iBank); + m_ui.ProgSpinBox->setValue(iProg); // Instrument name... - ui.NameLineEdit->setText(m_pInstrument->name()); + m_ui.NameLineEdit->setText(m_pInstrument->name()); // Engine name... QString sEngineName = m_pInstrument->engineName(); if (sEngineName.isEmpty() || bNew) sEngineName = pOptions->sEngineName; if (sEngineName.isEmpty()) - sEngineName = qsamplerChannel::noEngineName(); - if (ui.EngineNameComboBox->findText(sEngineName, - Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) { - ui.EngineNameComboBox->insertItem(sEngineName); + sEngineName = Channel::noEngineName(); + if (m_ui.EngineNameComboBox->findText(sEngineName, + Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { + m_ui.EngineNameComboBox->addItem(sEngineName); } - ui.EngineNameComboBox->setCurrentText(sEngineName); + m_ui.EngineNameComboBox->setCurrentIndex( + m_ui.EngineNameComboBox->findText(sEngineName, + Qt::MatchExactly | Qt::MatchCaseSensitive)); + // Instrument filename and index... QString sInstrumentFile = m_pInstrument->instrumentFile(); if (sInstrumentFile.isEmpty()) - sInstrumentFile = qsamplerChannel::noInstrumentName(); - ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile); - ui.InstrumentNrComboBox->clear(); - ui.InstrumentNrComboBox->insertStringList( - qsamplerChannel::getInstrumentList(sInstrumentFile, + sInstrumentFile = Channel::noInstrumentName(); + m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile); + m_ui.InstrumentNrComboBox->clear(); + m_ui.InstrumentNrComboBox->insertItems(0, + Channel::getInstrumentList(sInstrumentFile, pOptions->bInstrumentNames)); - ui.InstrumentNrComboBox->setCurrentItem(m_pInstrument->instrumentNr()); + m_ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr()); // Instrument volume.... int iVolume = (bNew ? pOptions->iVolume : ::lroundf(100.0f * m_pInstrument->volume())); - ui.VolumeSpinBox->setValue(iVolume); + m_ui.VolumeSpinBox->setValue(iVolume); // Instrument load mode... int iLoadMode = (bNew ? pOptions->iLoadMode : m_pInstrument->loadMode()); - ui.LoadModeComboBox->setCurrentItem(iLoadMode); - - // Done. - m_iDirtySetup--; - stabilizeForm(); + m_ui.LoadModeComboBox->setCurrentIndex(iLoadMode); // Done. m_iDirtySetup--; @@ -194,23 +252,32 @@ if (pMainForm == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; // FIXME: the instrument file filters should be restricted, // depending on the current engine. - QString sInstrumentFile = QFileDialog::getOpenFileName( - pOptions->sInstrumentDir, // Start here. - tr("Instrument files") + " (*.gig *.dls)", // Filter (GIG and DLS files) - this, 0, // Parent and name (none) - QSAMPLER_TITLE ": " + tr("Instrument files")// Caption. + const QString& sEngineName = m_ui.EngineNameComboBox->currentText().toUpper(); + QStringList filters; + if (sEngineName.contains("GIG")) + filters << tr("GIG Instrument files") + " (*.gig *.dls)"; + if (sEngineName.contains("SFZ")) + filters << tr("SFZ Instrument files") + " (*.sfz)"; + if (sEngineName.contains("SF2")) + filters << tr("SF2 Instrument files") + " (*.sf2)"; + const QString& filter = filters.join(";;"); + + QString sInstrumentFile = QFileDialog::getOpenFileName(this, + QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption. + pOptions->sInstrumentDir, // Start here. + filter // File filter. ); if (sInstrumentFile.isEmpty()) return; - ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile); + m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile); updateInstrumentName(); } @@ -222,16 +289,16 @@ if (pMainForm == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; // TODO: this better idea would be to use libgig // to retrieve the REAL instrument names. - ui.InstrumentNrComboBox->clear(); - ui.InstrumentNrComboBox->insertStringList( - qsamplerChannel::getInstrumentList( - ui.InstrumentFileComboBox->currentText(), + m_ui.InstrumentNrComboBox->clear(); + m_ui.InstrumentNrComboBox->insertItems(0, + Channel::getInstrumentList( + m_ui.InstrumentFileComboBox->currentText(), pOptions->bInstrumentNames) ); @@ -245,8 +312,8 @@ if (m_iDirtySetup > 0) return; - if (ui.NameLineEdit->text().isEmpty() || m_iDirtyName == 0) { - ui.NameLineEdit->setText(ui.InstrumentNrComboBox->currentText()); + if (m_ui.NameLineEdit->text().isEmpty() || m_iDirtyName == 0) { + m_ui.NameLineEdit->setText(m_ui.InstrumentNrComboBox->currentText()); m_iDirtyName = 0; } @@ -266,31 +333,32 @@ if (pMainForm->client() == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; if (m_iDirtyCount > 0) { - m_pInstrument->setMap(ui.MapComboBox->currentItem()); - m_pInstrument->setBank(ui.BankSpinBox->value()); - m_pInstrument->setProg(ui.ProgSpinBox->value() - 1); - m_pInstrument->setName(ui.NameLineEdit->text()); - m_pInstrument->setEngineName(ui.EngineNameComboBox->currentText()); - m_pInstrument->setInstrumentFile(ui.InstrumentFileComboBox->currentText()); - m_pInstrument->setInstrumentNr(ui.InstrumentNrComboBox->currentItem()); - m_pInstrument->setVolume(0.01f * float(ui.VolumeSpinBox->value())); - m_pInstrument->setLoadMode(ui.LoadModeComboBox->currentItem()); + m_pInstrument->setMap(m_ui.MapComboBox->currentIndex()); + m_pInstrument->setBank(m_ui.BankSpinBox->value()); + m_pInstrument->setProg(m_ui.ProgSpinBox->value() - 1); + m_pInstrument->setName(m_ui.NameLineEdit->text()); + m_pInstrument->setEngineName(m_ui.EngineNameComboBox->currentText()); + m_pInstrument->setInstrumentFile(m_ui.InstrumentFileComboBox->currentText()); + m_pInstrument->setInstrumentNr(m_ui.InstrumentNrComboBox->currentIndex()); + m_pInstrument->setVolume(0.01f * float(m_ui.VolumeSpinBox->value())); + m_pInstrument->setLoadMode(m_ui.LoadModeComboBox->currentIndex()); } // Save default engine name, instrument directory and history... - pOptions->sInstrumentDir = QFileInfo(ui.InstrumentFileComboBox->currentText()).dirPath(true); - pOptions->sEngineName = ui.EngineNameComboBox->currentText(); - pOptions->iMidiMap = ui.MapComboBox->currentItem(); - pOptions->iMidiBank = ui.BankSpinBox->value(); - pOptions->iMidiProg = ui.ProgSpinBox->value(); - pOptions->iVolume = ui.VolumeSpinBox->value(); - pOptions->iLoadMode = ui.LoadModeComboBox->currentItem(); - pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox); + pOptions->sInstrumentDir = QFileInfo( + m_ui.InstrumentFileComboBox->currentText()).dir().absolutePath(); + pOptions->sEngineName = m_ui.EngineNameComboBox->currentText(); + pOptions->iMidiMap = m_ui.MapComboBox->currentIndex(); + pOptions->iMidiBank = m_ui.BankSpinBox->value(); + pOptions->iMidiProg = m_ui.ProgSpinBox->value(); + pOptions->iVolume = m_ui.VolumeSpinBox->value(); + pOptions->iLoadMode = m_ui.LoadModeComboBox->currentIndex(); + pOptions->saveComboBoxHistory(m_ui.InstrumentFileComboBox); // Just go with dialog acceptance. QDialog::accept(); @@ -303,16 +371,18 @@ bool bReject = true; // Check if there's any pending changes... - if (m_iDirtyCount > 0 && ui.OkPushButton->isEnabled()) { + if (m_iDirtyCount > 0) { switch (QMessageBox::warning(this, QSAMPLER_TITLE ": " + tr("Warning"), tr("Some channel settings have been changed.\n\n" "Do you want to apply the changes?"), - tr("Apply"), tr("Discard"), tr("Cancel"))) { - case 0: // Apply... + QMessageBox::Apply | + QMessageBox::Discard | + QMessageBox::Cancel)) { + case QMessageBox::Apply: accept(); return; - case 1: // Discard + case QMessageBox::Discard: break; default: // Cancel. bReject = false; @@ -339,12 +409,15 @@ // Stabilize current form state. void InstrumentForm::stabilizeForm (void) { - bool bValid = !ui.NameLineEdit->text().isEmpty(); + bool bValid = !m_ui.NameLineEdit->text().isEmpty() + && m_ui.EngineNameComboBox->currentIndex() >= 0 + && m_ui.EngineNameComboBox->currentText() != Channel::noEngineName(); - const QString& sPath = ui.InstrumentFileComboBox->currentText(); + const QString& sPath = m_ui.InstrumentFileComboBox->currentText(); bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); - ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid); + m_ui.DialogButtonBox->button( + QDialogButtonBox::Ok)->setEnabled(m_iDirtyCount > 0 && bValid); } } // namespace QSampler