--- qsampler/trunk/src/qsamplerInstrumentForm.cpp 2007/11/22 11:10:44 1509 +++ 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,20 +20,20 @@ *****************************************************************************/ +#include "qsamplerAbout.h" #include "qsamplerInstrumentForm.h" -#include "qsamplerAbout.h" +#include "qsamplerOptions.h" +#include "qsamplerChannel.h" #include "qsamplerMainForm.h" -#include #include +#include +#include // Needed for lroundf() #include - -namespace QSampler { - #ifndef CONFIG_ROUND static inline long lroundf ( float x ) { @@ -44,7 +44,14 @@ } #endif -InstrumentForm::InstrumentForm ( QWidget* pParent ) + +namespace QSampler { + +//------------------------------------------------------------------------- +// QSampler::InstrumentForm -- Instrument map item form implementation. +// + +InstrumentForm::InstrumentForm ( QWidget *pParent ) : QDialog(pParent) { m_ui.setupUi(this); @@ -90,11 +97,11 @@ QObject::connect(m_ui.LoadModeComboBox, SIGNAL(activated(int)), SLOT(changed())); - QObject::connect(m_ui.OkPushButton, - SIGNAL(clicked()), + QObject::connect(m_ui.DialogButtonBox, + SIGNAL(accepted()), SLOT(accept())); - QObject::connect(m_ui.CancelPushButton, - SIGNAL(clicked()), + QObject::connect(m_ui.DialogButtonBox, + SIGNAL(rejected()), SLOT(reject())); } @@ -105,7 +112,7 @@ // Channel dialog setup formal initializer. -void InstrumentForm::setup ( qsamplerInstrument *pInstrument ) +void InstrumentForm::setup ( Instrument *pInstrument ) { m_pInstrument = pInstrument; @@ -123,7 +130,7 @@ if (pMainForm->client() == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; @@ -142,7 +149,7 @@ // Populate maps list. m_ui.MapComboBox->clear(); - m_ui.MapComboBox->insertItems(0, qsamplerInstrument::getMapNames()); + m_ui.MapComboBox->insertItems(0, Instrument::getMapNames()); // Populate Engines list. const char **ppszEngines @@ -161,12 +168,13 @@ int iMap = (bNew ? pOptions->iMidiMap : m_pInstrument->map()); if (iMap < 0) iMap = 0; - const QString& sMapName = qsamplerInstrument::getMapName(iMap); + const QString& sMapName = Instrument::getMapName(iMap); if (!sMapName.isEmpty()) { - m_ui.MapComboBox->setItemText( - m_ui.MapComboBox->currentIndex(), - sMapName); + m_ui.MapComboBox->setCurrentIndex( + m_ui.MapComboBox->findText(sMapName, + Qt::MatchExactly | Qt::MatchCaseSensitive)); } + // It might be no maps around... bool bMapEnabled = (m_ui.MapComboBox->count() > 0); m_ui.MapTextLabel->setEnabled(bMapEnabled); @@ -190,7 +198,7 @@ if (sEngineName.isEmpty() || bNew) sEngineName = pOptions->sEngineName; if (sEngineName.isEmpty()) - sEngineName = qsamplerChannel::noEngineName(); + sEngineName = Channel::noEngineName(); if (m_ui.EngineNameComboBox->findText(sEngineName, Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { m_ui.EngineNameComboBox->addItem(sEngineName); @@ -202,11 +210,11 @@ // Instrument filename and index... QString sInstrumentFile = m_pInstrument->instrumentFile(); if (sInstrumentFile.isEmpty()) - sInstrumentFile = qsamplerChannel::noInstrumentName(); + sInstrumentFile = Channel::noInstrumentName(); m_ui.InstrumentFileComboBox->setEditText(sInstrumentFile); m_ui.InstrumentNrComboBox->clear(); m_ui.InstrumentNrComboBox->insertItems(0, - qsamplerChannel::getInstrumentList(sInstrumentFile, + Channel::getInstrumentList(sInstrumentFile, pOptions->bInstrumentNames)); m_ui.InstrumentNrComboBox->setCurrentIndex(m_pInstrument->instrumentNr()); @@ -223,10 +231,6 @@ // Done. m_iDirtySetup--; stabilizeForm(); - - // Done. - m_iDirtySetup--; - stabilizeForm(); } @@ -248,16 +252,26 @@ 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. + 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. - tr("Instrument files") + " (*.gig *.dls)" // Filter (GIG and DLS files) + pOptions->sInstrumentDir, // Start here. + filter // File filter. ); if (sInstrumentFile.isEmpty()) @@ -275,7 +289,7 @@ if (pMainForm == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; @@ -283,7 +297,7 @@ // to retrieve the REAL instrument names. m_ui.InstrumentNrComboBox->clear(); m_ui.InstrumentNrComboBox->insertItems(0, - qsamplerChannel::getInstrumentList( + Channel::getInstrumentList( m_ui.InstrumentFileComboBox->currentText(), pOptions->bInstrumentNames) ); @@ -319,7 +333,7 @@ if (pMainForm->client() == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; @@ -357,16 +371,18 @@ bool bReject = true; // Check if there's any pending changes... - if (m_iDirtyCount > 0 && m_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; @@ -393,16 +409,15 @@ // Stabilize current form state. void InstrumentForm::stabilizeForm (void) { - bool bValid = - !m_ui.NameLineEdit->text().isEmpty() && - m_ui.EngineNameComboBox->currentIndex() >= 0 && - m_ui.EngineNameComboBox->currentText() != - qsamplerChannel::noEngineName(); + bool bValid = !m_ui.NameLineEdit->text().isEmpty() + && m_ui.EngineNameComboBox->currentIndex() >= 0 + && m_ui.EngineNameComboBox->currentText() != Channel::noEngineName(); const QString& sPath = m_ui.InstrumentFileComboBox->currentText(); bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); - m_ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid); + m_ui.DialogButtonBox->button( + QDialogButtonBox::Ok)->setEnabled(m_iDirtyCount > 0 && bValid); } } // namespace QSampler