--- qsampler/trunk/src/qsamplerChannelForm.ui.h 2004/06/26 14:27:25 149 +++ qsampler/trunk/src/qsamplerChannelForm.ui.h 2005/03/08 17:23:29 430 @@ -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,8 +26,7 @@ #include #include -#include "qsamplerOptions.h" -#include "qsamplerChannelStrip.h" +#include "qsamplerDevice.h" #include "config.h" @@ -53,7 +52,7 @@ // Channel dialog setup formal initializer. -void qsamplerChannelForm::setup ( qsamplerChannelStrip *pChannel ) +void qsamplerChannelForm::setup ( qsamplerChannel *pChannel ) { m_pChannel = pChannel; @@ -63,7 +62,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 +90,71 @@ 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(); + InstrumentNrComboBox->clear(); + InstrumentNrComboBox->insertStringList( + qsamplerChannel::getInstrumentList(sInstrumentFile, + pOptions->bInstrumentNames)); + InstrumentNrComboBox->setCurrentItem(pChannel->instrumentNr()); + // MIDI input driver... + QString sMidiDriver = pChannel->midiDriver(); + if (sMidiDriver.isEmpty() || bNew) + sMidiDriver = pOptions->sMidiDriver; if (!sMidiDriver.isEmpty()) { if (MidiDriverComboBox->listBox()->findItem(sMidiDriver, Qt::ExactMatch) == NULL) MidiDriverComboBox->insertItem(sMidiDriver); MidiDriverComboBox->setCurrentText(sMidiDriver); } + // MIDI input port... MidiPortSpinBox->setValue(pChannel->midiPort()); - MidiChannelSpinBox->setValue(pChannel->midiChannel()); - // Audio output... - const QString& sAudioDriver = pChannel->audioDriver(); + // 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 driver... + QString sAudioDriver = pChannel->audioDriver(); + if (sAudioDriver.isEmpty() || bNew) + sAudioDriver = pOptions->sAudioDriver; if (!sAudioDriver.isEmpty()) { if (AudioDriverComboBox->listBox()->findItem(sAudioDriver, Qt::ExactMatch) == NULL) AudioDriverComboBox->insertItem(sAudioDriver); AudioDriverComboBox->setCurrentText(sAudioDriver); } + // 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,6 +174,9 @@ // We'll go for it! if (m_iDirtyCount > 0) { int iErrors = 0; + // Are we a new channel? + if (!m_pChannel->addChannel()) + iErrors++; // Audio output driver type... if (!m_pChannel->setAudioDriver(AudioDriverComboBox->currentText())) iErrors++; @@ -164,25 +184,27 @@ if (!m_pChannel->setMidiDriver(MidiDriverComboBox->currentText())) 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 +218,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,10 +264,18 @@ // 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(); }