--- qsampler/trunk/src/qsamplerChannelForm.cpp 2007/10/28 23:30:36 1461 +++ qsampler/trunk/src/qsamplerChannelForm.cpp 2010/07/15 17:01:35 2109 @@ -1,3 +1,25 @@ +// qsamplerChannelForm.cpp +// +/**************************************************************************** + Copyright (C) 2004-2010, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2007, 2008 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., + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + +*****************************************************************************/ + #include "qsamplerChannelForm.h" #include "qsamplerAbout.h" @@ -6,15 +28,24 @@ #include "qsamplerMainForm.h" #include "qsamplerInstrument.h" -#include -#include -#include -#include +#include +#include +#include +#include + +#include + namespace QSampler { -ChannelForm::ChannelForm(QWidget* parent) : QDialog(parent) { - ui.setupUi(this); +//------------------------------------------------------------------------- +// QSampler::Channelform -- Channel form implementation. +// + +ChannelForm::ChannelForm ( QWidget* pParent ) + : QDialog(pParent) +{ + m_ui.setupUi(this); // Initialize locals. m_pChannel = NULL; @@ -22,24 +53,99 @@ m_iDirtySetup = 0; m_iDirtyCount = 0; - m_midiDevices.setAutoDelete(true); - m_audioDevices.setAutoDelete(true); +// m_midiDevices.setAutoDelete(true); +// m_audioDevices.setAutoDelete(true); m_pDeviceForm = NULL; + int iRowHeight = m_ui.AudioRoutingTable->fontMetrics().height() + 4; + m_ui.AudioRoutingTable->verticalHeader()->setDefaultSectionSize(iRowHeight); + m_ui.AudioRoutingTable->horizontalHeader()->setDefaultAlignment(Qt::AlignLeft); + + m_ui.AudioRoutingTable->setModel(&m_routingModel); + m_ui.AudioRoutingTable->setItemDelegate(&m_routingDelegate); + m_ui.AudioRoutingTable->horizontalHeader()->setResizeMode(0, QHeaderView::Stretch); +// m_ui.AudioRoutingTable->verticalHeader()->hide(); + + // This goes initially hidden, and will be shown + // on setup() for currently existing channels... + m_ui.AudioRoutingTable->hide(); + // Try to restore normal window positioning. adjustSize(); + + QObject::connect(m_ui.EngineNameComboBox, + SIGNAL(activated(int)), + SLOT(optionsChanged())); + 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(optionsChanged())); + QObject::connect(m_ui.MidiDriverComboBox, + SIGNAL(activated(const QString&)), + SLOT(selectMidiDriver(const QString&))); + QObject::connect(m_ui.MidiDeviceComboBox, + SIGNAL(activated(int)), + SLOT(selectMidiDevice(int))); + QObject::connect(m_ui.MidiPortSpinBox, + SIGNAL(valueChanged(int)), + SLOT(optionsChanged())); + QObject::connect(m_ui.MidiChannelComboBox, + SIGNAL(activated(int)), + SLOT(optionsChanged())); + QObject::connect(m_ui.MidiMapComboBox, + SIGNAL(activated(int)), + SLOT(optionsChanged())); + QObject::connect(m_ui.AudioDriverComboBox, + SIGNAL(activated(const QString&)), + SLOT(selectAudioDriver(const QString&))); + QObject::connect(m_ui.AudioDeviceComboBox, + SIGNAL(activated(int)), + SLOT(selectAudioDevice(int))); + QObject::connect(m_ui.DialogButtonBox, + SIGNAL(accepted()), + SLOT(accept())); + QObject::connect(m_ui.DialogButtonBox, + SIGNAL(rejected()), + SLOT(reject())); + QObject::connect(m_ui.MidiDeviceToolButton, + SIGNAL(clicked()), + SLOT(setupMidiDevice())); + QObject::connect(m_ui.AudioDeviceToolButton, + SIGNAL(clicked()), + SLOT(setupAudioDevice())); + QObject::connect(&m_routingModel, + SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), + SLOT(optionsChanged())); + QObject::connect(&m_routingModel, + SIGNAL(dataChanged(const QModelIndex&, const QModelIndex&)), + SLOT(updateTableCellRenderers(const QModelIndex&, const QModelIndex&))); + QObject::connect(&m_routingModel, + SIGNAL(modelReset()), + SLOT(updateTableCellRenderers())); } -ChannelForm::~ChannelForm() { +ChannelForm::~ChannelForm() +{ if (m_pDeviceForm) delete m_pDeviceForm; m_pDeviceForm = NULL; + + qDeleteAll(m_midiDevices); + m_midiDevices.clear(); + + qDeleteAll(m_audioDevices); + m_audioDevices.clear(); } // Channel dialog setup formal initializer. -void ChannelForm::setup ( qsamplerChannel *pChannel ) +void ChannelForm::setup ( Channel *pChannel ) { m_pChannel = pChannel; @@ -50,8 +156,8 @@ return; // It can be a brand new channel, remember? - bool bNew = (m_pChannel->channelID() < 0); - setCaption(QSAMPLER_TITLE ": " + m_pChannel->channelName()); + const bool bNew = (m_pChannel->channelID() < 0); + setWindowTitle(QSAMPLER_TITLE ": " + m_pChannel->channelName()); // Check if we're up and connected. MainForm *pMainForm = MainForm::getInstance(); @@ -60,7 +166,7 @@ if (pMainForm->client() == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; @@ -68,34 +174,31 @@ m_iDirtySetup++; // Load combo box history... - pOptions->loadComboBoxHistory(ui.InstrumentFileComboBox); - - // Notify.that we've just changed one audio route. - QObject::connect(ui.AudioRoutingTable, SIGNAL(valueChanged(int,int)), - this, SLOT(changeAudioRouting(int,int))); + pOptions->loadComboBoxHistory(m_ui.InstrumentFileComboBox); // Populate Engines list. 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(QString(ppszEngines[iEngine])); } else m_pChannel->appendMessagesClient("lscp_list_available_engines"); // Populate Audio output type list. - ui.AudioDriverComboBox->clear(); - ui.AudioDriverComboBox->insertStringList( - qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Audio)); + m_ui.AudioDriverComboBox->clear(); + m_ui.AudioDriverComboBox->insertItems(0, + Device::getDrivers(pMainForm->client(), Device::Audio)); // Populate MIDI input type list. - ui.MidiDriverComboBox->clear(); - ui.MidiDriverComboBox->insertStringList( - qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Midi)); + m_ui.MidiDriverComboBox->clear(); + m_ui.MidiDriverComboBox->insertItems(0, + Device::getDrivers(pMainForm->client(), Device::Midi)); // Populate Maps list. - ui.MidiMapComboBox->clear(); - ui.MidiMapComboBox->insertStringList(qsamplerInstrument::getMapNames()); + m_ui.MidiMapComboBox->clear(); + m_ui.MidiMapComboBox->insertItems(0, + Instrument::getMapNames()); // Read proper channel information, // and populate the channel form fields. @@ -105,83 +208,117 @@ 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); - } - ui.EngineNameComboBox->setCurrentText(sEngineName); + sEngineName = Channel::noEngineName(); + if (m_ui.EngineNameComboBox->findText(sEngineName, + Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { + m_ui.EngineNameComboBox->addItem(sEngineName); + } + m_ui.EngineNameComboBox->setCurrentIndex( + m_ui.EngineNameComboBox->findText(sEngineName, + Qt::MatchExactly | Qt::MatchCaseSensitive)); + // Instrument filename and index... QString sInstrumentFile = pChannel->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(pChannel->instrumentNr()); + int iInstrumentNr = pChannel->instrumentNr(); + if (iInstrumentNr < 0) + iInstrumentNr = 0; + m_ui.InstrumentNrComboBox->setCurrentIndex(iInstrumentNr); // MIDI input device... - qsamplerDevice midiDevice(qsamplerDevice::Midi, m_pChannel->midiDevice()); + Device midiDevice(Device::Midi, m_pChannel->midiDevice()); // MIDI input driver... QString sMidiDriver = midiDevice.driverName(); if (sMidiDriver.isEmpty() || bNew) - sMidiDriver = pOptions->sMidiDriver.upper(); + sMidiDriver = pOptions->sMidiDriver.toUpper(); if (!sMidiDriver.isEmpty()) { - if (ui.MidiDriverComboBox->findText(sMidiDriver, - Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) { - ui.MidiDriverComboBox->insertItem(sMidiDriver); + if (m_ui.MidiDriverComboBox->findText(sMidiDriver, + Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { + m_ui.MidiDriverComboBox->insertItem(0, sMidiDriver); } - ui.MidiDriverComboBox->setCurrentText(sMidiDriver); + m_ui.MidiDriverComboBox->setCurrentIndex( + m_ui.MidiDriverComboBox->findText(sMidiDriver, + Qt::MatchExactly | Qt::MatchCaseSensitive) + ); } selectMidiDriverItem(sMidiDriver); - if (!bNew) - ui.MidiDeviceComboBox->setCurrentText(midiDevice.deviceName()); - selectMidiDeviceItem(ui.MidiDeviceComboBox->currentItem()); + if (!bNew) { + m_ui.MidiDeviceComboBox->setItemText( + m_ui.MidiDeviceComboBox->currentIndex(), + midiDevice.deviceName()); + } + selectMidiDeviceItem(m_ui.MidiDeviceComboBox->currentIndex()); // MIDI input port... - ui.MidiPortSpinBox->setValue(pChannel->midiPort()); + m_ui.MidiPortSpinBox->setValue(pChannel->midiPort()); // MIDI input channel... int iMidiChannel = pChannel->midiChannel(); // When new, try to suggest a sensible MIDI channel... if (iMidiChannel < 0) iMidiChannel = (::lscp_get_channels(pMainForm->client()) % 16); - ui.MidiChannelComboBox->setCurrentItem(iMidiChannel); + m_ui.MidiChannelComboBox->setCurrentIndex(iMidiChannel); // MIDI instrument map... int iMidiMap = (bNew ? pOptions->iMidiMap : pChannel->midiMap()); // When new, try to suggest a sensible MIDI map... if (iMidiMap < 0) iMidiMap = 0; - const QString& sMapName = qsamplerInstrument::getMapName(iMidiMap); - if (!sMapName.isEmpty()) - ui.MidiMapComboBox->setCurrentText(sMapName); + const QString& sMapName = Instrument::getMapName(iMidiMap); + if (!sMapName.isEmpty()) { + m_ui.MidiMapComboBox->setItemText( + m_ui.MidiMapComboBox->currentIndex(), + sMapName); + } // It might be no maps around... - bool bMidiMapEnabled = (ui.MidiMapComboBox->count() > 0); - ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled); - ui.MidiMapComboBox->setEnabled(bMidiMapEnabled); + bool bMidiMapEnabled = (m_ui.MidiMapComboBox->count() > 0); + m_ui.MidiMapTextLabel->setEnabled(bMidiMapEnabled); + m_ui.MidiMapComboBox->setEnabled(bMidiMapEnabled); // Audio output device... - qsamplerDevice audioDevice(qsamplerDevice::Audio, m_pChannel->audioDevice()); + Device audioDevice(Device::Audio, m_pChannel->audioDevice()); // Audio output driver... QString sAudioDriver = audioDevice.driverName(); if (sAudioDriver.isEmpty() || bNew) - sAudioDriver = pOptions->sAudioDriver.upper(); + sAudioDriver = pOptions->sAudioDriver.toUpper(); if (!sAudioDriver.isEmpty()) { - if (ui.AudioDriverComboBox->findText(sAudioDriver, - Qt::MatchExactly | Qt::MatchCaseSensitive) == 0) { - ui.AudioDriverComboBox->insertItem(sAudioDriver); + if (m_ui.AudioDriverComboBox->findText(sAudioDriver, + Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { + m_ui.AudioDriverComboBox->insertItem(0, sAudioDriver); } - ui.AudioDriverComboBox->setCurrentText(sAudioDriver); + m_ui.AudioDriverComboBox->setCurrentIndex( + m_ui.AudioDriverComboBox->findText(sAudioDriver, + Qt::MatchExactly | Qt::MatchCaseSensitive) + ); } selectAudioDriverItem(sAudioDriver); - if (!bNew) - ui.AudioDeviceComboBox->setCurrentText(audioDevice.deviceName()); - selectAudioDeviceItem(ui.AudioDeviceComboBox->currentItem()); + if (!bNew) { + m_ui.AudioDeviceComboBox->setItemText( + m_ui.AudioDeviceComboBox->currentIndex(), + audioDevice.deviceName()); + } + selectAudioDeviceItem(m_ui.AudioDeviceComboBox->currentIndex()); + + // Let the audio routing table see the light, + // if we're editing an existing sampler channel... + m_ui.AudioRoutingTable->setVisible(!bNew); + + const QString sInstrumentNrToolTip = + (pOptions->bInstrumentNames) ? + "Select an instrument of the file" : + "You might want to enable instrument name retrieval in the " + "settings dialog"; + m_ui.InstrumentNrComboBox->setToolTip( + QObject::tr(sInstrumentNrToolTip.toUtf8().data()) + ); // As convenient, make it ready on stabilizeForm() for // prompt acceptance, if we got the minimum required... -/* if (sEngineName != qsamplerChannel::noEngineName() && - sInstrumentFile != qsamplerChannel::noInstrumentName()) +/* if (sEngineName != Channel::noEngineName() && + sInstrumentFile != Channel::noInstrumentName()) m_iDirtyCount++; */ // Done. m_iDirtySetup--; @@ -201,12 +338,12 @@ if (pMainForm->client() == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; // Flush any pending editing... - //ui.AudioRoutingTable->flush(); + //m_ui.AudioRoutingTable->flush(); // We'll go for it! if (m_iDirtyCount > 0) { @@ -216,65 +353,75 @@ iErrors++; // Accept Audio driver or device selection... if (m_audioDevices.isEmpty()) { - if (!m_pChannel->setAudioDriver(ui.AudioDriverComboBox->currentText())) + if (!m_pChannel->setAudioDriver(m_ui.AudioDriverComboBox->currentText())) iErrors++; } else { - qsamplerDevice *pDevice = m_audioDevices.at(ui.AudioDeviceComboBox->currentItem()); + Device *pDevice = NULL; + int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex(); + if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count()) + pDevice = m_audioDevices.at(iAudioItem); + ChannelRoutingMap routingMap = m_routingModel.routingMap(); if (pDevice == NULL) iErrors++; else if (!m_pChannel->setAudioDevice(pDevice->deviceID())) iErrors++; - else if (!m_audioRouting.isEmpty()) { + else if (!routingMap.isEmpty()) { // Set the audio route changes... - qsamplerChannelRoutingMap::ConstIterator iter; - for (iter = m_audioRouting.begin(); - iter != m_audioRouting.end(); ++iter) { - if (!m_pChannel->setAudioChannel(iter.key(), iter.data())) + ChannelRoutingMap::ConstIterator iter; + for (iter = routingMap.begin(); + iter != routingMap.end(); ++iter) { + if (!m_pChannel->setAudioChannel(iter.key(), iter.value())) iErrors++; } } } // Accept MIDI driver or device selection... if (m_midiDevices.isEmpty()) { - if (!m_pChannel->setMidiDriver(ui.MidiDriverComboBox->currentText())) + if (!m_pChannel->setMidiDriver(m_ui.MidiDriverComboBox->currentText())) iErrors++; } else { - qsamplerDevice *pDevice = m_midiDevices.at(ui.MidiDeviceComboBox->currentItem()); + Device *pDevice = NULL; + int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex(); + if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count()) + pDevice = m_midiDevices.at(iMidiItem); if (pDevice == NULL) iErrors++; else if (!m_pChannel->setMidiDevice(pDevice->deviceID())) iErrors++; } // MIDI input port number... - if (!m_pChannel->setMidiPort(ui.MidiPortSpinBox->value())) + if (!m_pChannel->setMidiPort(m_ui.MidiPortSpinBox->value())) iErrors++; // MIDI input channel... - if (!m_pChannel->setMidiChannel(ui.MidiChannelComboBox->currentItem())) + if (!m_pChannel->setMidiChannel(m_ui.MidiChannelComboBox->currentIndex())) iErrors++; // Engine name... - if (!m_pChannel->loadEngine(ui.EngineNameComboBox->currentText())) + if (!m_pChannel->loadEngine(m_ui.EngineNameComboBox->currentText())) iErrors++; // Instrument file and index... - const QString& sPath = ui.InstrumentFileComboBox->currentText(); + const QString& sPath = m_ui.InstrumentFileComboBox->currentText(); if (!sPath.isEmpty() && QFileInfo(sPath).exists()) { - if (!m_pChannel->loadInstrument(sPath, ui.InstrumentNrComboBox->currentItem())) + if (!m_pChannel->loadInstrument(sPath, m_ui.InstrumentNrComboBox->currentIndex())) iErrors++; } // MIDI intrument map... - if (!m_pChannel->setMidiMap(ui.MidiMapComboBox->currentItem())) + if (!m_pChannel->setMidiMap(m_ui.MidiMapComboBox->currentIndex())) iErrors++; // Show error messages? - if (iErrors > 0) - m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry.")); + if (iErrors > 0) { + m_pChannel->appendMessagesError( + tr("Some channel settings could not be set.\n\nSorry.")); + } } // Save default engine name, instrument directory and history... - pOptions->sInstrumentDir = QFileInfo(ui.InstrumentFileComboBox->currentText()).dirPath(true); - pOptions->sEngineName = ui.EngineNameComboBox->currentText(); - pOptions->sAudioDriver = ui.AudioDriverComboBox->currentText(); - pOptions->sMidiDriver = ui.MidiDriverComboBox->currentText(); - pOptions->iMidiMap = ui.MidiMapComboBox->currentItem(); - pOptions->saveComboBoxHistory(ui.InstrumentFileComboBox); + pOptions->sInstrumentDir = QFileInfo( + m_ui.InstrumentFileComboBox->currentText()).dir().absolutePath(); + pOptions->sEngineName = m_ui.EngineNameComboBox->currentText(); + pOptions->sAudioDriver = m_ui.AudioDriverComboBox->currentText(); + pOptions->sMidiDriver = m_ui.MidiDriverComboBox->currentText(); + pOptions->iMidiMap = m_ui.MidiMapComboBox->currentIndex(); + pOptions->saveComboBoxHistory(m_ui.InstrumentFileComboBox); // Just go with dialog acceptance. QDialog::accept(); @@ -287,16 +434,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; @@ -318,23 +467,29 @@ if (pMainForm->client() == 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. + QStringList filters; + filters << tr("GIG Instrument files") + " (*.gig *.dls)"; + filters << tr("SFZ Instrument files") + " (*.sfz)"; + filters << tr("SF2 Instrument files") + " (*.sf2)"; + filters << tr("All files") + " (*.*)"; + 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(); } @@ -348,16 +503,16 @@ if (pMainForm->client() == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; // Finally 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) ); @@ -366,8 +521,8 @@ // Show device options dialog. -void ChannelForm::setupDevice ( qsamplerDevice *pDevice, - qsamplerDevice::qsamplerDeviceType deviceTypeMode, +void ChannelForm::setupDevice ( Device *pDevice, + Device::DeviceType deviceTypeMode, const QString& sDriverName ) { MainForm *pMainForm = MainForm::getInstance(); @@ -379,7 +534,7 @@ // Create the device form if not already... if (m_pDeviceForm == NULL) { m_pDeviceForm = new DeviceForm(this, Qt::Dialog); - m_pDeviceForm->setAttribute(Qt::WA_ShowModal); + m_pDeviceForm->setAttribute(Qt::WA_ShowModal); QObject::connect(m_pDeviceForm, SIGNAL(devicesChanged()), this, SLOT(updateDevices())); } @@ -404,26 +559,32 @@ if (pMainForm->client() == NULL) return; - const QString sDriverName = sMidiDriver.upper(); + const QString sDriverName = sMidiDriver.toUpper(); // Save current device id. + // Save current device id. int iDeviceID = 0; - qsamplerDevice *pDevice = m_midiDevices.at(ui.MidiDeviceComboBox->currentItem()); + Device *pDevice = NULL; + int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex(); + if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count()) + pDevice = m_midiDevices.at(iMidiItem); if (pDevice) iDeviceID = pDevice->deviceID(); // Clean maplist. - ui.MidiDeviceComboBox->clear(); + m_ui.MidiDeviceComboBox->clear(); + qDeleteAll(m_midiDevices); m_midiDevices.clear(); // Populate with the current ones... - const QPixmap midiPixmap(":/qsampler/pixmaps/midi2.png"); - int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), - qsamplerDevice::Midi); + const QPixmap midiPixmap(":/images/midi2.png"); + int *piDeviceIDs = Device::getDevices(pMainForm->client(), + Device::Midi); for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { - pDevice = new qsamplerDevice(qsamplerDevice::Midi, piDeviceIDs[i]); - if (pDevice->driverName().upper() == sDriverName) { - ui.MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName()); + pDevice = new Device(Device::Midi, piDeviceIDs[i]); + if (pDevice->driverName().toUpper() == sDriverName) { + m_ui.MidiDeviceComboBox->insertItem(0, + midiPixmap, pDevice->deviceName()); m_midiDevices.append(pDevice); } else { delete pDevice; @@ -434,23 +595,23 @@ bool bEnabled = !m_midiDevices.isEmpty(); if (bEnabled) { // Select the previous current device... - int iMidiItem = 0; - for (pDevice = m_midiDevices.first(); - pDevice; - pDevice = m_midiDevices.next()) { + iMidiItem = 0; + QListIterator iter(m_midiDevices); + while (iter.hasNext()) { + pDevice = iter.next(); if (pDevice->deviceID() == iDeviceID) { - ui.MidiDeviceComboBox->setCurrentItem(iMidiItem); + m_ui.MidiDeviceComboBox->setCurrentIndex(iMidiItem); selectMidiDeviceItem(iMidiItem); break; } iMidiItem++; } } else { - ui.MidiDeviceComboBox->insertItem( + m_ui.MidiDeviceComboBox->insertItem(0, tr("(New MIDI %1 device)").arg(sMidiDriver)); } - ui.MidiDeviceTextLabel->setEnabled(bEnabled); - ui.MidiDeviceComboBox->setEnabled(bEnabled); + m_ui.MidiDeviceTextLabel->setEnabled(bEnabled); + m_ui.MidiDeviceComboBox->setEnabled(bEnabled); } @@ -468,14 +629,16 @@ // Select MIDI device item. void ChannelForm::selectMidiDeviceItem ( int iMidiItem ) { - qsamplerDevice *pDevice = m_midiDevices.at(iMidiItem); + Device *pDevice = NULL; + if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count()) + pDevice = m_midiDevices.at(iMidiItem); if (pDevice) { - const qsamplerDeviceParamMap& params = pDevice->params(); + const DeviceParamMap& params = pDevice->params(); int iPorts = params["PORTS"].value.toInt(); - ui.MidiPortTextLabel->setEnabled(iPorts > 0); - ui.MidiPortSpinBox->setEnabled(iPorts > 0); + m_ui.MidiPortTextLabel->setEnabled(iPorts > 0); + m_ui.MidiPortSpinBox->setEnabled(iPorts > 0); if (iPorts > 0) - ui.MidiPortSpinBox->setMaxValue(iPorts - 1); + m_ui.MidiPortSpinBox->setMaximum(iPorts - 1); } } @@ -494,8 +657,12 @@ // MIDI device options. void ChannelForm::setupMidiDevice (void) { - setupDevice(m_midiDevices.at(ui.MidiDeviceComboBox->currentItem()), - qsamplerDevice::Midi, ui.MidiDriverComboBox->currentText()); + Device *pDevice = NULL; + int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex(); + if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count()) + pDevice = m_midiDevices.at(iMidiItem); + setupDevice(pDevice, + Device::Midi, m_ui.MidiDriverComboBox->currentText()); } @@ -508,26 +675,31 @@ if (pMainForm->client() == NULL) return; - const QString sDriverName = sAudioDriver.upper(); + const QString sDriverName = sAudioDriver.toUpper(); // Save current device id. int iDeviceID = 0; - qsamplerDevice *pDevice = m_audioDevices.at(ui.AudioDeviceComboBox->currentItem()); + Device *pDevice = NULL; + int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex(); + if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count()) + pDevice = m_audioDevices.at(iAudioItem); if (pDevice) iDeviceID = pDevice->deviceID(); // Clean maplist. - ui.AudioDeviceComboBox->clear(); + m_ui.AudioDeviceComboBox->clear(); + qDeleteAll(m_audioDevices); m_audioDevices.clear(); // Populate with the current ones... - const QPixmap audioPixmap(":/qsampler/pixmaps/audio2.png"); - int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), - qsamplerDevice::Audio); + const QPixmap audioPixmap(":/images/audio2.png"); + int *piDeviceIDs = Device::getDevices(pMainForm->client(), + Device::Audio); for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { - pDevice = new qsamplerDevice(qsamplerDevice::Audio, piDeviceIDs[i]); - if (pDevice->driverName().upper() == sDriverName) { - ui.AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName()); + pDevice = new Device(Device::Audio, piDeviceIDs[i]); + if (pDevice->driverName().toUpper() == sDriverName) { + m_ui.AudioDeviceComboBox->insertItem(0, + audioPixmap, pDevice->deviceName()); m_audioDevices.append(pDevice); } else { delete pDevice; @@ -538,25 +710,25 @@ bool bEnabled = !m_audioDevices.isEmpty(); if (bEnabled) { // Select the previous current device... - int iAudioItem = 0; - for (pDevice = m_audioDevices.first(); - pDevice; - pDevice = m_audioDevices.next()) { + iAudioItem = 0; + QListIterator iter(m_audioDevices); + while (iter.hasNext()) { + pDevice = iter.next(); if (pDevice->deviceID() == iDeviceID) { - ui.AudioDeviceComboBox->setCurrentItem(iAudioItem); + m_ui.AudioDeviceComboBox->setCurrentIndex(iAudioItem); selectAudioDeviceItem(iAudioItem); break; } iAudioItem++; } } else { - ui.AudioDeviceComboBox->insertItem( + m_ui.AudioDeviceComboBox->insertItem(0, tr("(New Audio %1 device)").arg(sAudioDriver)); - //ui.AudioRoutingTable->setNumRows(0); + //m_ui.AudioRoutingTable->setNumRows(0); } - ui.AudioDeviceTextLabel->setEnabled(bEnabled); - ui.AudioDeviceComboBox->setEnabled(bEnabled); - ui.AudioRoutingTable->setEnabled(bEnabled); + m_ui.AudioDeviceTextLabel->setEnabled(bEnabled); + m_ui.AudioDeviceComboBox->setEnabled(bEnabled); + m_ui.AudioRoutingTable->setEnabled(bEnabled); } @@ -574,12 +746,14 @@ // Select Audio device item. void ChannelForm::selectAudioDeviceItem ( int iAudioItem ) { - qsamplerDevice *pDevice = m_audioDevices.at(iAudioItem); + Device *pDevice = NULL; + if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count()) + pDevice = m_audioDevices.at(iAudioItem); if (pDevice) { // Refresh the audio routing table. - routingModel.refresh(pDevice, m_pChannel->audioRouting()); + m_routingModel.refresh(pDevice, m_pChannel->audioRouting()); // Reset routing change map. - m_audioRouting.clear(); + m_routingModel.clear(); } } @@ -598,44 +772,22 @@ // Audio device options. void ChannelForm::setupAudioDevice (void) { - setupDevice(m_audioDevices.at(ui.AudioDeviceComboBox->currentItem()), - qsamplerDevice::Audio, ui.AudioDriverComboBox->currentText()); + Device *pDevice = NULL; + int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex(); + if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count()) + pDevice = m_audioDevices.at(iAudioItem); + setupDevice(pDevice, + Device::Audio, m_ui.AudioDriverComboBox->currentText()); } - -// Audio routing change slot. -void ChannelForm::changeAudioRouting ( int iRow, int iCol ) -{ -#if 0 - if (m_iDirtySetup > 0) - return; - if (iRow < 0 || iCol < 0) - return; - - // Verify that this is a QComboTableItem (magic rtti == 1) - QTableItem *pItem = ui.AudioRoutingTable->item(iRow, iCol); - if (pItem == NULL) - return; - qsamplerChannelRoutingComboBox *pComboItem = - static_cast (pItem); - // FIXME: Its not garanteed that we must have - // iAudioOut == iRow on all times forth! - m_audioRouting[iRow] = pComboItem->currentItem(); - - // And let's get dirty... - optionsChanged(); -#endif -} - - // UPdate all device lists slot. void ChannelForm::updateDevices (void) { if (m_iDirtySetup > 0) return; - selectMidiDriverItem(ui.MidiDriverComboBox->currentText()); - selectAudioDriverItem(ui.AudioDriverComboBox->currentText()); + selectMidiDriverItem(m_ui.MidiDriverComboBox->currentText()); + selectAudioDriverItem(m_ui.AudioDriverComboBox->currentText()); optionsChanged(); } @@ -654,13 +806,41 @@ // Stabilize current form state. void ChannelForm::stabilizeForm (void) { - bool bValid = true; + const bool bValid = + m_ui.EngineNameComboBox->currentIndex() >= 0 && + m_ui.EngineNameComboBox->currentText() + != Channel::noEngineName(); #if 0 const QString& sPath = InstrumentFileComboBox->currentText(); bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); #endif - ui.OkPushButton->setEnabled(m_iDirtyCount > 0 && bValid); + m_ui.DialogButtonBox->button( + QDialogButtonBox::Ok)->setEnabled(m_iDirtyCount > 0 && bValid); } +void ChannelForm::updateTableCellRenderers (void) +{ + const int rows = m_routingModel.rowCount(); + const int cols = m_routingModel.columnCount(); + updateTableCellRenderers( + m_routingModel.index(0, 0), + m_routingModel.index(rows - 1, cols - 1)); +} + + +void ChannelForm::updateTableCellRenderers ( + const QModelIndex& topLeft, const QModelIndex& bottomRight ) +{ + for (int r = topLeft.row(); r <= bottomRight.row(); r++) { + for (int c = topLeft.column(); c <= bottomRight.column(); c++) { + const QModelIndex index = m_routingModel.index(r, c); + m_ui.AudioRoutingTable->openPersistentEditor(index); + } + } +} + } // namespace QSampler + + +// end of qsamplerChannelForm.cpp