--- qsampler/trunk/src/qsamplerInstrumentForm.cpp 2007/10/28 23:30:36 1461 +++ qsampler/trunk/src/qsamplerInstrumentForm.cpp 2007/11/21 11:46:40 1504 @@ -1,11 +1,37 @@ +// qsamplerInstrumentForm.cpp +// +/**************************************************************************** + Copyright (C) 2003-2007, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2007, Christian Schoenebeck + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public License + as published by the Free Software Foundation; either version 2 + of the License, or (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*****************************************************************************/ + #include "qsamplerInstrumentForm.h" #include "qsamplerAbout.h" #include "qsamplerMainForm.h" +#include +#include + // Needed for lroundf() #include + namespace QSampler { #ifndef CONFIG_ROUND @@ -18,7 +44,9 @@ } #endif -InstrumentForm::InstrumentForm(QWidget* parent) : QDialog(parent) { +InstrumentForm::InstrumentForm ( QWidget* pParent ) + : QDialog(pParent) +{ ui.setupUi(this); // Initialize locals. @@ -30,11 +58,52 @@ // Try to restore normal window positioning. adjustSize(); + + + QObject::connect(ui.MapComboBox, + SIGNAL(activated(int)), + SLOT(changed())); + QObject::connect(ui.BankSpinBox, + SIGNAL(valueChanged(int)), + SLOT(changed())); + QObject::connect(ui.ProgSpinBox, + SIGNAL(valueChanged(int)), + SLOT(changed())); + QObject::connect(ui.NameLineEdit, + SIGNAL(textChanged(const QString&)), + SLOT(nameChanged(const QString&))); + QObject::connect(ui.EngineNameComboBox, + SIGNAL(activated(int)), + SLOT(changed())); + QObject::connect(ui.InstrumentFileComboBox, + SIGNAL(activated(const QString&)), + SLOT(updateInstrumentName())); + QObject::connect(ui.InstrumentFileToolButton, + SIGNAL(clicked()), + SLOT(openInstrumentFile())); + QObject::connect(ui.InstrumentNrComboBox, + SIGNAL(activated(int)), + SLOT(instrumentNrChanged())); + QObject::connect(ui.VolumeSpinBox, + SIGNAL(valueChanged(int)), + SLOT(changed())); + QObject::connect(ui.LoadModeComboBox, + SIGNAL(activated(int)), + SLOT(changed())); + QObject::connect(ui.OkPushButton, + SIGNAL(clicked()), + SLOT(accept())); + QObject::connect(ui.CancelPushButton, + SIGNAL(clicked()), + SLOT(reject())); } -InstrumentForm::~InstrumentForm() { + +InstrumentForm::~InstrumentForm (void) +{ } + // Channel dialog setup formal initializer. void InstrumentForm::setup ( qsamplerInstrument *pInstrument ) { @@ -73,14 +142,14 @@ // Populate maps list. ui.MapComboBox->clear(); - ui.MapComboBox->insertStringList(qsamplerInstrument::getMapNames()); + ui.MapComboBox->insertItems(0, qsamplerInstrument::getMapNames()); // Populate Engines list. const char **ppszEngines = ::lscp_list_available_engines(pMainForm->client()); if (ppszEngines) { ui.EngineNameComboBox->clear(); for (int iEngine = 0; ppszEngines[iEngine]; iEngine++) - ui.EngineNameComboBox->insertItem(ppszEngines[iEngine]); + ui.EngineNameComboBox->addItem(ppszEngines[iEngine]); } else pMainForm->appendMessagesClient("lscp_list_available_engines"); @@ -92,8 +161,11 @@ if (iMap < 0) iMap = 0; const QString& sMapName = qsamplerInstrument::getMapName(iMap); - if (!sMapName.isEmpty()) - ui.MapComboBox->setCurrentText(sMapName); + if (!sMapName.isEmpty()) { + ui.MapComboBox->setItemText( + ui.MapComboBox->currentIndex(), + sMapName); + } // It might be no maps around... bool bMapEnabled = (ui.MapComboBox->count() > 0); ui.MapTextLabel->setEnabled(bMapEnabled); @@ -119,20 +191,25 @@ if (sEngineName.isEmpty()) sEngineName = qsamplerChannel::noEngineName(); if (ui.EngineNameComboBox->findText(sEngineName, - Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) { - ui.EngineNameComboBox->insertItem(sEngineName); + Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { + ui.EngineNameComboBox->addItem(sEngineName); } - ui.EngineNameComboBox->setCurrentText(sEngineName); + ui.EngineNameComboBox->setCurrentIndex( + 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.InstrumentFileComboBox->setItemText( + ui.InstrumentFileComboBox->currentIndex(), + sInstrumentFile); ui.InstrumentNrComboBox->clear(); - ui.InstrumentNrComboBox->insertStringList( + ui.InstrumentNrComboBox->insertItems(0, qsamplerChannel::getInstrumentList(sInstrumentFile, pOptions->bInstrumentNames)); - ui.InstrumentNrComboBox->setCurrentItem(m_pInstrument->instrumentNr()); + ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr()); // Instrument volume.... int iVolume = (bNew ? pOptions->iVolume : @@ -142,7 +219,7 @@ // Instrument load mode... int iLoadMode = (bNew ? pOptions->iLoadMode : m_pInstrument->loadMode()); - ui.LoadModeComboBox->setCurrentItem(iLoadMode); + ui.LoadModeComboBox->setCurrentIndex(iLoadMode); // Done. m_iDirtySetup--; @@ -178,17 +255,19 @@ // 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. + QString sInstrumentFile = QFileDialog::getOpenFileName(this, + QSAMPLER_TITLE ": " + tr("Instrument files"), // Caption. + pOptions->sInstrumentDir, // Start here. + tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files) ); if (sInstrumentFile.isEmpty()) return; - ui.InstrumentFileComboBox->setCurrentText(sInstrumentFile); + ui.InstrumentFileComboBox->setItemText( + ui.InstrumentFileComboBox->currentIndex(), + sInstrumentFile); + updateInstrumentName(); } @@ -207,7 +286,7 @@ // TODO: this better idea would be to use libgig // to retrieve the REAL instrument names. ui.InstrumentNrComboBox->clear(); - ui.InstrumentNrComboBox->insertStringList( + ui.InstrumentNrComboBox->insertItems(0, qsamplerChannel::getInstrumentList( ui.InstrumentFileComboBox->currentText(), pOptions->bInstrumentNames) @@ -249,25 +328,26 @@ return; if (m_iDirtyCount > 0) { - m_pInstrument->setMap(ui.MapComboBox->currentItem()); + m_pInstrument->setMap(ui.MapComboBox->currentIndex()); 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->setInstrumentNr(ui.InstrumentNrComboBox->currentIndex()); m_pInstrument->setVolume(0.01f * float(ui.VolumeSpinBox->value())); - m_pInstrument->setLoadMode(ui.LoadModeComboBox->currentItem()); + m_pInstrument->setLoadMode(ui.LoadModeComboBox->currentIndex()); } // Save default engine name, instrument directory and history... - pOptions->sInstrumentDir = QFileInfo(ui.InstrumentFileComboBox->currentText()).dirPath(true); + pOptions->sInstrumentDir = QFileInfo( + ui.InstrumentFileComboBox->currentText()).dir().absolutePath(); pOptions->sEngineName = ui.EngineNameComboBox->currentText(); - pOptions->iMidiMap = ui.MapComboBox->currentItem(); + pOptions->iMidiMap = ui.MapComboBox->currentIndex(); pOptions->iMidiBank = ui.BankSpinBox->value(); pOptions->iMidiProg = ui.ProgSpinBox->value(); pOptions->iVolume = ui.VolumeSpinBox->value(); - pOptions->iLoadMode = ui.LoadModeComboBox->currentItem(); + pOptions->iLoadMode = ui.LoadModeComboBox->currentIndex(); pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox); // Just go with dialog acceptance. @@ -326,3 +406,6 @@ } } // namespace QSampler + + +// end of qsamplerInstrumentForm.cpp