--- qsampler/trunk/src/qsamplerChannelForm.ui.h 2004/06/26 14:27:25 149 +++ qsampler/trunk/src/qsamplerChannelForm.ui.h 2005/03/14 10:59:57 454 @@ -2,7 +2,7 @@ // // ui.h extension file, included from the uic-generated form implementation. /**************************************************************************** - Copyright (C) 2004, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2004-2005, rncbc aka Rui Nuno Capela. All rights reserved. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -26,9 +26,6 @@ #include #include -#include "qsamplerOptions.h" -#include "qsamplerChannelStrip.h" - #include "config.h" @@ -41,6 +38,9 @@ m_iDirtySetup = 0; m_iDirtyCount = 0; + m_midiDevices.setAutoDelete(true); + m_audioDevices.setAutoDelete(true); + // Try to restore normal window positioning. adjustSize(); } @@ -53,7 +53,7 @@ // Channel dialog setup formal initializer. -void qsamplerChannelForm::setup ( qsamplerChannelStrip *pChannel ) +void qsamplerChannelForm::setup ( qsamplerChannel *pChannel ) { m_pChannel = pChannel; @@ -63,7 +63,9 @@ if (m_pChannel == NULL) return; - setCaption(m_pChannel->caption()); + // It can be a brand new channel, remember? + bool bNew = (m_pChannel->channelID() < 0); + setCaption(m_pChannel->channelName()); // Check if we're up and connected. if (m_pChannel->client() == NULL) @@ -89,55 +91,86 @@ else m_pChannel->appendMessagesClient("lscp_get_available_engines"); // Populate Audio output type list. - const char **ppszAudioDrivers = ::lscp_get_available_audio_drivers(m_pChannel->client()); - if (ppszAudioDrivers) { - AudioDriverComboBox->clear(); - for (int iAudioDriver = 0; ppszAudioDrivers[iAudioDriver]; iAudioDriver++) - AudioDriverComboBox->insertItem(ppszAudioDrivers[iAudioDriver]); - } - else m_pChannel->appendMessagesClient("lscp_get_available_audio_drivers"); + AudioDriverComboBox->clear(); + AudioDriverComboBox->insertStringList( + qsamplerDevice::getDrivers(m_pChannel->client(), qsamplerDevice::Audio)); // Populate MIDI input type list. - const char **ppszMidiDrivers = ::lscp_get_available_midi_drivers(m_pChannel->client()); - if (ppszMidiDrivers) { - MidiDriverComboBox->clear(); - for (int iMidiDriver = 0; ppszMidiDrivers[iMidiDriver]; iMidiDriver++) - MidiDriverComboBox->insertItem(ppszMidiDrivers[iMidiDriver]); - } - else m_pChannel->appendMessagesClient("lscp_get_available_midi_drivers"); + MidiDriverComboBox->clear(); + MidiDriverComboBox->insertStringList( + qsamplerDevice::getDrivers(m_pChannel->client(), qsamplerDevice::Midi)); // Read proper channel information, // and populate the channel form fields. // Engine name... QString sEngineName = pChannel->engineName(); + if (sEngineName.isEmpty() || bNew) + sEngineName = pOptions->sEngineName; if (sEngineName.isEmpty()) - sEngineName = tr("(No engine)"); + sEngineName = qsamplerChannel::noEngineName(); if (EngineNameComboBox->listBox()->findItem(sEngineName, Qt::ExactMatch) == NULL) EngineNameComboBox->insertItem(sEngineName); EngineNameComboBox->setCurrentText(sEngineName); // Instrument filename and index... QString sInstrumentFile = pChannel->instrumentFile(); if (sInstrumentFile.isEmpty()) - sInstrumentFile = tr("(No instrument)"); + sInstrumentFile = qsamplerChannel::noInstrumentName(); InstrumentFileComboBox->setCurrentText(sInstrumentFile); - InstrumentNrSpinBox->setValue(pChannel->instrumentNr()); - // MIDI input... - const QString& sMidiDriver = pChannel->midiDriver(); - if (!sMidiDriver.isEmpty()) { - if (MidiDriverComboBox->listBox()->findItem(sMidiDriver, Qt::ExactMatch) == NULL) - MidiDriverComboBox->insertItem(sMidiDriver); - MidiDriverComboBox->setCurrentText(sMidiDriver); - } + InstrumentNrComboBox->clear(); + InstrumentNrComboBox->insertStringList( + qsamplerChannel::getInstrumentList(sInstrumentFile, + pOptions->bInstrumentNames)); + InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr()); + + // MIDI input device... + qsamplerDevice midiDevice(m_pChannel->client(), + qsamplerDevice::Midi, m_pChannel->midiDevice()); + // MIDI input driver... + QString sMidiDriver = midiDevice.driverName(); + if (sMidiDriver.isEmpty() || bNew) + sMidiDriver = pOptions->sMidiDriver; + if (!sMidiDriver.isEmpty()) { + if (MidiDriverComboBox->listBox()->findItem(sMidiDriver, Qt::ExactMatch) == NULL) + MidiDriverComboBox->insertItem(sMidiDriver); + MidiDriverComboBox->setCurrentText(sMidiDriver); + } + selectMidiDriver(sMidiDriver); + if (!bNew) + MidiDeviceComboBox->setCurrentText(midiDevice.deviceName()); + // MIDI input port... MidiPortSpinBox->setValue(pChannel->midiPort()); - MidiChannelSpinBox->setValue(pChannel->midiChannel()); - // Audio output... - const QString& sAudioDriver = pChannel->audioDriver(); - if (!sAudioDriver.isEmpty()) { - if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL) - AudioDriverComboBox->insertItem(sAudioDriver); - AudioDriverComboBox->setCurrentText(sAudioDriver); - } + // MIDI input channel... + int iMidiChannel = pChannel->midiChannel(); + // When new, try to suggest a sensible MIDI channel... + if (iMidiChannel < 0) + iMidiChannel = (::lscp_get_channels(m_pChannel->client()) % 16); + MidiChannelComboBox->setCurrentItem(iMidiChannel); + + // Audio output device... + qsamplerDevice audioDevice(m_pChannel->client(), + qsamplerDevice::Audio, m_pChannel->audioDevice()); + // Audio output driver... + QString sAudioDriver = audioDevice.driverName(); + if (sAudioDriver.isEmpty() || bNew) + sAudioDriver = pOptions->sAudioDriver; + if (!sAudioDriver.isEmpty()) { + if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL) + AudioDriverComboBox->insertItem(sAudioDriver); + AudioDriverComboBox->setCurrentText(sAudioDriver); + } + selectAudioDriver(sAudioDriver); + if (!bNew) + AudioDeviceComboBox->setCurrentText(audioDevice.deviceName()); + + // As convenient, make it ready on stabilizeForm() for + // prompt acceptance, if we got the minimum required... + if (sEngineName != qsamplerChannel::noEngineName() && + sInstrumentFile != qsamplerChannel::noInstrumentName()) + m_iDirtyCount++; + // FIXME: These are better leave diabled... + MidiPortTextLabel->setEnabled(false); + MidiPortSpinBox->setEnabled(false); // Done. m_iDirtySetup--; stabilizeForm(); @@ -157,32 +190,53 @@ // We'll go for it! if (m_iDirtyCount > 0) { int iErrors = 0; - // Audio output driver type... - if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText())) - iErrors++; - // MIDI input driver type... - if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText())) + // Are we a new channel? + if (!m_pChannel->addChannel()) iErrors++; + // Accept Audio driver or device selection... + if (m_audioDevices.isEmpty()) { + if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText())) + iErrors++; + } else { + qsamplerDevice *pDevice = m_audioDevices.at(AudioDeviceComboBox->currentItem()); + if (pDevice == NULL) + iErrors++; + else if (!m_pChannel->setAudioDevice(pDevice->deviceID())) + iErrors++; + } + // Accept MIDI driver or device selection... + if (m_midiDevices.isEmpty()) { + if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText())) + iErrors++; + } else { + qsamplerDevice *pDevice = m_midiDevices.at(MidiDeviceComboBox->currentItem()); + if (pDevice == NULL) + iErrors++; + else if (!m_pChannel->setMidiDevice(pDevice->deviceID())) + iErrors++; + } // MIDI input port number... - // FIXME: Should increment error count, when properly implemented. if (!m_pChannel->setMidiPort(MidiPortSpinBox->value())) - /* iErrors++ */; + iErrors++; // MIDI input channel... - if (!m_pChannel->setMidiChannel(MidiChannelSpinBox->value())) + if (!m_pChannel->setMidiChannel(MidiChannelComboBox->currentItem())) iErrors++; // Engine name... if (!m_pChannel->loadEngine(EngineNameComboBox->currentText())) iErrors++; // Instrument file and index... - if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrSpinBox->value())) + if (!m_pChannel->loadInstrument(InstrumentFileComboBox->currentText(), InstrumentNrComboBox->currentItem())) iErrors++; // Show error messages? if (iErrors > 0) m_pChannel->appendMessagesError(tr("Some channel settings could not be set.\n\nSorry.")); } - // Save default instrument directory and history... + // Save default engine name, instrument directory and history... pOptions->sInstrumentDir = QFileInfo(InstrumentFileComboBox->currentText()).dirPath(true); + pOptions->sEngineName = EngineNameComboBox->currentText(); + pOptions->sAudioDriver = AudioDriverComboBox->currentText(); + pOptions->sMidiDriver = MidiDriverComboBox->currentText(); pOptions->saveComboBoxHistory(InstrumentFileComboBox); // Just go with dialog acceptance. @@ -196,7 +250,7 @@ bool bReject = true; // Check if there's any pending changes... - if (m_iDirtyCount > 0) { + if (m_iDirtyCount > 0 && OkPushButton->isEnabled()) { switch (QMessageBox::warning(this, tr("Warning"), tr("Some channel settings have been changed.\n\n" "Do you want to apply the changes?"), @@ -242,15 +296,84 @@ // Refresh the actual instrument name. void qsamplerChannelForm::updateInstrumentName (void) { - // FIXME: A better idea would be to use libgig - // to retrieve the REAL instrument name. - InstrumentNameTextLabel->setText(QFileInfo(InstrumentFileComboBox->currentText()).fileName() - + " [" + QString::number(InstrumentNrSpinBox->value()) + "]"); + qsamplerOptions *pOptions = m_pChannel->options(); + if (pOptions == NULL) + return; + + // Finally this better idea would be to use libgig + // to retrieve the REAL instrument names. + InstrumentNrComboBox->clear(); + InstrumentNrComboBox->insertStringList( + qsamplerChannel::getInstrumentList( + InstrumentFileComboBox->currentText(), + pOptions->bInstrumentNames) + ); optionsChanged(); } +// Refresh MIDI device options. +void qsamplerChannelForm::selectMidiDriver ( const QString& sMidiDriver ) +{ + const QString sDriverName = sMidiDriver.upper(); + + MidiDeviceComboBox->clear(); + m_audioDevices.clear(); + + const QPixmap& midiPixmap = QPixmap::fromMimeSource("midi2.png"); + int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(), + qsamplerDevice::Midi); + for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { + qsamplerDevice *pDevice = new qsamplerDevice(m_pChannel->client(), + qsamplerDevice::Midi, piDeviceIDs[i]); + if (pDevice->driverName().upper() == sDriverName) { + MidiDeviceComboBox->insertItem(midiPixmap, pDevice->deviceName()); + m_midiDevices.append(pDevice); + } else { + delete pDevice; + } + } + + bool bEnabled = !m_midiDevices.isEmpty(); + if (!bEnabled) + MidiDeviceComboBox->insertItem(tr("(New MIDI device)")); + MidiDeviceTextLabel->setEnabled(bEnabled); + MidiDeviceComboBox->setEnabled(bEnabled); + optionsChanged(); +} + + +// Refresh Audio device options. +void qsamplerChannelForm::selectAudioDriver ( const QString& sAudioDriver ) +{ + const QString sDriverName = sAudioDriver.upper(); + + AudioDeviceComboBox->clear(); + m_audioDevices.clear(); + + const QPixmap& audioPixmap = QPixmap::fromMimeSource("audio2.png"); + int *piDeviceIDs = qsamplerDevice::getDevices(m_pChannel->client(), + qsamplerDevice::Audio); + for (int i = 0; piDeviceIDs && piDeviceIDs[i] >= 0; i++) { + qsamplerDevice *pDevice = new qsamplerDevice(m_pChannel->client(), + qsamplerDevice::Audio, piDeviceIDs[i]); + if (pDevice->driverName().upper() == sDriverName) { + AudioDeviceComboBox->insertItem(audioPixmap, pDevice->deviceName()); + m_audioDevices.append(pDevice); + } else { + delete pDevice; + } + } + + bool bEnabled = !m_audioDevices.isEmpty(); + if (!bEnabled) + AudioDeviceComboBox->insertItem(tr("(New Audio device)")); + AudioDeviceTextLabel->setEnabled(bEnabled); + AudioDeviceComboBox->setEnabled(bEnabled); + optionsChanged(); +} + // Dirty up settings. void qsamplerChannelForm::optionsChanged (void)