--- qsampler/trunk/src/qsamplerChannelForm.cpp 2007/11/22 11:10:44 1509 +++ qsampler/trunk/src/qsamplerChannelForm.cpp 2008/02/26 16:00:00 1710 @@ -2,7 +2,7 @@ // /**************************************************************************** Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. - Copyright (C) 2007, Christian Schoenebeck + 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 @@ -38,10 +38,14 @@ namespace QSampler { +//------------------------------------------------------------------------- +// QSampler::Channelform -- Channel form implementation. +// + ChannelForm::ChannelForm ( QWidget* pParent ) : QDialog(pParent) { - m_ui.setupUi(this); + m_ui.setupUi(this); // Initialize locals. m_pChannel = NULL; @@ -54,13 +58,17 @@ 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... + // on setup() for currently existing channels... m_ui.AudioRoutingTable->hide(); // Try to restore normal window positioning. @@ -137,7 +145,7 @@ // Channel dialog setup formal initializer. -void ChannelForm::setup ( qsamplerChannel *pChannel ) +void ChannelForm::setup ( Channel *pChannel ) { m_pChannel = pChannel; @@ -148,7 +156,7 @@ return; // It can be a brand new channel, remember? - bool bNew = (m_pChannel->channelID() < 0); + const bool bNew = (m_pChannel->channelID() < 0); setWindowTitle(QSAMPLER_TITLE ": " + m_pChannel->channelName()); // Check if we're up and connected. @@ -158,7 +166,7 @@ if (pMainForm->client() == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; @@ -180,17 +188,17 @@ // Populate Audio output type list. m_ui.AudioDriverComboBox->clear(); m_ui.AudioDriverComboBox->insertItems(0, - qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Audio)); + Device::getDrivers(pMainForm->client(), Device::Audio)); // Populate MIDI input type list. m_ui.MidiDriverComboBox->clear(); m_ui.MidiDriverComboBox->insertItems(0, - qsamplerDevice::getDrivers(pMainForm->client(), qsamplerDevice::Midi)); + Device::getDrivers(pMainForm->client(), Device::Midi)); // Populate Maps list. m_ui.MidiMapComboBox->clear(); m_ui.MidiMapComboBox->insertItems(0, - qsamplerInstrument::getMapNames()); + Instrument::getMapNames()); // Read proper channel information, // and populate the channel form fields. @@ -200,7 +208,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); @@ -212,16 +220,19 @@ // Instrument filename and index... QString sInstrumentFile = pChannel->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(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) @@ -231,9 +242,10 @@ Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { m_ui.MidiDriverComboBox->insertItem(0, sMidiDriver); } - m_ui.MidiDriverComboBox->setItemText( - m_ui.MidiDriverComboBox->currentIndex(), - sMidiDriver); + m_ui.MidiDriverComboBox->setCurrentIndex( + m_ui.MidiDriverComboBox->findText(sMidiDriver, + Qt::MatchExactly | Qt::MatchCaseSensitive) + ); } selectMidiDriverItem(sMidiDriver); if (!bNew) { @@ -255,7 +267,7 @@ // When new, try to suggest a sensible MIDI map... if (iMidiMap < 0) iMidiMap = 0; - const QString& sMapName = qsamplerInstrument::getMapName(iMidiMap); + const QString& sMapName = Instrument::getMapName(iMidiMap); if (!sMapName.isEmpty()) { m_ui.MidiMapComboBox->setItemText( m_ui.MidiMapComboBox->currentIndex(), @@ -267,7 +279,7 @@ 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) @@ -277,9 +289,10 @@ Qt::MatchExactly | Qt::MatchCaseSensitive) < 0) { m_ui.AudioDriverComboBox->insertItem(0, sAudioDriver); } - m_ui.AudioDriverComboBox->setItemText( - m_ui.AudioDriverComboBox->currentIndex(), - sAudioDriver); + m_ui.AudioDriverComboBox->setCurrentIndex( + m_ui.AudioDriverComboBox->findText(sAudioDriver, + Qt::MatchExactly | Qt::MatchCaseSensitive) + ); } selectAudioDriverItem(sAudioDriver); if (!bNew) { @@ -293,10 +306,19 @@ // 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--; @@ -316,7 +338,7 @@ if (pMainForm->client() == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; @@ -334,18 +356,18 @@ if (!m_pChannel->setAudioDriver(m_ui.AudioDriverComboBox->currentText())) iErrors++; } else { - qsamplerDevice *pDevice = NULL; + Device *pDevice = NULL; int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex(); if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count()) pDevice = m_audioDevices.at(iAudioItem); - qsamplerChannelRoutingMap routingMap = m_routingModel.routingMap(); + ChannelRoutingMap routingMap = m_routingModel.routingMap(); if (pDevice == NULL) iErrors++; else if (!m_pChannel->setAudioDevice(pDevice->deviceID())) iErrors++; else if (!routingMap.isEmpty()) { // Set the audio route changes... - qsamplerChannelRoutingMap::ConstIterator iter; + ChannelRoutingMap::ConstIterator iter; for (iter = routingMap.begin(); iter != routingMap.end(); ++iter) { if (!m_pChannel->setAudioChannel(iter.key(), iter.value())) @@ -358,7 +380,7 @@ if (!m_pChannel->setMidiDriver(m_ui.MidiDriverComboBox->currentText())) iErrors++; } else { - qsamplerDevice *pDevice = NULL; + Device *pDevice = NULL; int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex(); if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count()) pDevice = m_midiDevices.at(iMidiItem); @@ -386,8 +408,10 @@ 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... @@ -441,7 +465,7 @@ if (pMainForm->client() == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; @@ -470,7 +494,7 @@ if (pMainForm->client() == NULL) return; - qsamplerOptions *pOptions = pMainForm->options(); + Options *pOptions = pMainForm->options(); if (pOptions == NULL) return; @@ -478,7 +502,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) ); @@ -488,13 +512,10 @@ // Show device options dialog. -void ChannelForm::setupDevice ( qsamplerDevice *pDevice, - qsamplerDevice::DeviceType deviceTypeMode, +void ChannelForm::setupDevice ( Device *pDevice, + Device::DeviceType deviceTypeMode, const QString& sDriverName ) { - if (pDevice == NULL) - return; - MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return; @@ -504,7 +525,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())); } @@ -534,7 +555,7 @@ // Save current device id. // Save current device id. int iDeviceID = 0; - qsamplerDevice *pDevice = NULL; + Device *pDevice = NULL; int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex(); if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count()) pDevice = m_midiDevices.at(iMidiItem); @@ -548,12 +569,13 @@ // Populate with the current ones... const QPixmap midiPixmap(":/icons/midi2.png"); - int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), - qsamplerDevice::Midi); + int *piDeviceIDs = Device::getDevices(pMainForm->client(), + Device::Midi); for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { - pDevice = new qsamplerDevice(qsamplerDevice::Midi, piDeviceIDs[i]); + pDevice = new Device(Device::Midi, piDeviceIDs[i]); if (pDevice->driverName().toUpper() == sDriverName) { - m_ui.MidiDeviceComboBox->insertItem(0, midiPixmap, pDevice->deviceName()); + m_ui.MidiDeviceComboBox->insertItem(0, + midiPixmap, pDevice->deviceName()); m_midiDevices.append(pDevice); } else { delete pDevice; @@ -565,7 +587,7 @@ if (bEnabled) { // Select the previous current device... iMidiItem = 0; - QListIterator iter(m_midiDevices); + QListIterator iter(m_midiDevices); while (iter.hasNext()) { pDevice = iter.next(); if (pDevice->deviceID() == iDeviceID) { @@ -598,11 +620,11 @@ // Select MIDI device item. void ChannelForm::selectMidiDeviceItem ( int iMidiItem ) { - qsamplerDevice *pDevice = NULL; + 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(); m_ui.MidiPortTextLabel->setEnabled(iPorts > 0); m_ui.MidiPortSpinBox->setEnabled(iPorts > 0); @@ -626,12 +648,12 @@ // MIDI device options. void ChannelForm::setupMidiDevice (void) { - qsamplerDevice *pDevice = NULL; + Device *pDevice = NULL; int iMidiItem = m_ui.MidiDeviceComboBox->currentIndex(); if (iMidiItem >= 0 && iMidiItem < m_midiDevices.count()) pDevice = m_midiDevices.at(iMidiItem); setupDevice(pDevice, - qsamplerDevice::Midi, m_ui.MidiDriverComboBox->currentText()); + Device::Midi, m_ui.MidiDriverComboBox->currentText()); } @@ -648,7 +670,7 @@ // Save current device id. int iDeviceID = 0; - qsamplerDevice *pDevice = NULL; + Device *pDevice = NULL; int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex(); if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count()) pDevice = m_audioDevices.at(iAudioItem); @@ -662,12 +684,13 @@ // Populate with the current ones... const QPixmap audioPixmap(":/icons/audio2.png"); - int *piDeviceIDs = qsamplerDevice::getDevices(pMainForm->client(), - qsamplerDevice::Audio); + int *piDeviceIDs = Device::getDevices(pMainForm->client(), + Device::Audio); for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { - pDevice = new qsamplerDevice(qsamplerDevice::Audio, piDeviceIDs[i]); + pDevice = new Device(Device::Audio, piDeviceIDs[i]); if (pDevice->driverName().toUpper() == sDriverName) { - m_ui.AudioDeviceComboBox->insertItem(0, audioPixmap, pDevice->deviceName()); + m_ui.AudioDeviceComboBox->insertItem(0, + audioPixmap, pDevice->deviceName()); m_audioDevices.append(pDevice); } else { delete pDevice; @@ -679,7 +702,7 @@ if (bEnabled) { // Select the previous current device... iAudioItem = 0; - QListIterator iter(m_audioDevices); + QListIterator iter(m_audioDevices); while (iter.hasNext()) { pDevice = iter.next(); if (pDevice->deviceID() == iDeviceID) { @@ -714,7 +737,7 @@ // Select Audio device item. void ChannelForm::selectAudioDeviceItem ( int iAudioItem ) { - qsamplerDevice *pDevice = NULL; + Device *pDevice = NULL; if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count()) pDevice = m_audioDevices.at(iAudioItem); if (pDevice) { @@ -740,12 +763,12 @@ // Audio device options. void ChannelForm::setupAudioDevice (void) { - qsamplerDevice *pDevice = NULL; + Device *pDevice = NULL; int iAudioItem = m_ui.AudioDeviceComboBox->currentIndex(); if (iAudioItem >= 0 && iAudioItem < m_audioDevices.count()) pDevice = m_audioDevices.at(iAudioItem); setupDevice(pDevice, - qsamplerDevice::Audio, m_ui.AudioDriverComboBox->currentText()); + Device::Audio, m_ui.AudioDriverComboBox->currentText()); } // UPdate all device lists slot. @@ -776,8 +799,8 @@ { const bool bValid = m_ui.EngineNameComboBox->currentIndex() >= 0 && - m_ui.EngineNameComboBox->currentText() != - qsamplerChannel::noEngineName(); + m_ui.EngineNameComboBox->currentText() + != Channel::noEngineName(); #if 0 const QString& sPath = InstrumentFileComboBox->currentText(); bValid = bValid && !sPath.isEmpty() && QFileInfo(sPath).exists(); @@ -788,9 +811,9 @@ void ChannelForm::updateTableCellRenderers (void) { - const int rows = m_routingModel.rowCount(); - const int cols = m_routingModel.columnCount(); - updateTableCellRenderers( + 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)); } @@ -799,12 +822,12 @@ 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); - } - } + 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