--- qsampler/trunk/src/qsamplerChannelStrip.ui.h 2004/06/05 11:37:06 109 +++ qsampler/trunk/src/qsamplerChannelStrip.ui.h 2004/07/06 10:54:45 176 @@ -24,6 +24,7 @@ #include #include #include +#include #include @@ -40,16 +41,17 @@ m_pMainForm = NULL; m_iChannelID = 0; -// m_sEngineName = "(No engine)"; -// m_sInstrumentFile = "(No instrument)"; - m_iInstrumentNr = 0; - m_sMidiDriver = "ALSA"; // DEPRECATED. - m_iMidiDevice = 0; - m_iMidiPort = 0; - m_iMidiChannel = 0; - m_sAudioDriver = "ALSA"; // DEPRECATED. - m_iAudioDevice = 0; - m_fVolume = 0.0; +// m_sEngineName = tr("(No engine)"); +// m_sInstrumentFile = tr("(No instrument)"); + m_iInstrumentNr = -1; + m_iInstrumentStatus = -1; + m_sMidiDriver = "Alsa"; // DEPRECATED. + m_iMidiDevice = -1; + m_iMidiPort = -1; + m_iMidiChannel = -1; + m_sAudioDriver = "Alsa"; // DEPRECATED. + m_iAudioDevice = -1; + m_fVolume = 0.0; m_iDirtyChange = 0; @@ -129,30 +131,39 @@ } -// Instrument filename accessors. +// Instrument filename accessor. QString& qsamplerChannelStrip::instrumentFile (void) { return m_sInstrumentFile; } -// Instrument index accessors. +// Instrument index accessor. int qsamplerChannelStrip::instrumentNr (void) { return m_iInstrumentNr; } +// Instrument status accessor. +int qsamplerChannelStrip::instrumentStatus (void) +{ + return m_iInstrumentStatus; +} + +// Instrument file loader. bool qsamplerChannelStrip::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) { if (client() == NULL) return false; - if (::lscp_load_instrument(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { + if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { appendMessagesClient("lscp_load_instrument"); return false; } m_sInstrumentFile = sInstrumentFile; m_iInstrumentNr = iInstrumentNr; + m_iInstrumentStatus = 0; + return true; } @@ -189,11 +200,10 @@ if (client() == NULL) return false; -// FIXME: call this when LSCP becomes stable. -// if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) { -// appendMessagesClient("lscp_set_channel_midi_device"); -// return false; -// } + if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) { + appendMessagesClient("lscp_set_channel_midi_device"); + return false; + } m_iMidiDevice = iMidiDevice; return true; @@ -211,11 +221,10 @@ if (client() == NULL) return false; -// FIXME: call this when LSCP becomes stable. -// if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) { -// appendMessagesClient("lscp_set_channel_midi_port"); -// return false; -// } + if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) { + appendMessagesClient("lscp_set_channel_midi_port"); + return false; + } m_iMidiPort = iMidiPort; return true; @@ -233,11 +242,10 @@ if (client() == NULL) return false; -// FIXME: call this when LSCP becomes stable. -// if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) { -// appendMessagesClient("lscp_set_channel_midi_channel"); -// return false; -// } + if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) { + appendMessagesClient("lscp_set_channel_midi_channel"); + return false; + } m_iMidiChannel = iMidiChannel; return true; @@ -255,11 +263,10 @@ if (client() == NULL) return false; -// FIXME: call this when LSCP becomes stable. -// if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) { -// appendMessagesClient("lscp_set_channel_audio_device"); -// return false; -// } + if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) { + appendMessagesClient("lscp_set_channel_audio_device"); + return false; + } m_iAudioDevice = iAudioDevice; return true; @@ -317,16 +324,17 @@ void qsamplerChannelStrip::setDisplayFont ( const QFont & font ) { EngineNameTextLabel->setFont(font); - InstrumentNameTextLabel->setFont(font); MidiPortChannelTextLabel->setFont(font); + InstrumentNameTextLabel->setFont(font); + InstrumentStatusTextLabel->setFont(font); } // Channel setup dialog. -void qsamplerChannelStrip::channelSetup (void) +void qsamplerChannelStrip::channelSetup ( bool bNew ) { qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(this); if (pChannelForm) { - pChannelForm->setup(this); + pChannelForm->setup(this, bNew); if (pChannelForm->exec()) { updateChannelInfo(); emit channelChanged(this); @@ -352,17 +360,23 @@ lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID); if (pChannelInfo == NULL) { appendMessagesClient("lscp_get_channel_info"); - // appendMessagesError(tr("Could not get channel information.\n\nSorry.")); + appendMessagesError(tr("Could not get channel information.\n\nSorry.")); } else { // Cache in channel information. - m_sEngineName = pChannelInfo->engine_name; - m_sInstrumentFile = pChannelInfo->instrument_file; - m_iInstrumentNr = pChannelInfo->instrument_nr; - m_iMidiDevice = pChannelInfo->midi_device; - m_iMidiPort = pChannelInfo->midi_port; - m_iMidiChannel = pChannelInfo->midi_channel; - m_iAudioDevice = pChannelInfo->audio_device; - m_fVolume = pChannelInfo->volume; + m_sEngineName = pChannelInfo->engine_name; + m_sInstrumentFile = pChannelInfo->instrument_file; + m_iInstrumentNr = pChannelInfo->instrument_nr; + m_iInstrumentStatus = pChannelInfo->instrument_status; + m_iMidiDevice = pChannelInfo->midi_device; + m_iMidiPort = pChannelInfo->midi_port; + m_iMidiChannel = pChannelInfo->midi_channel; + m_iAudioDevice = pChannelInfo->audio_device; + m_fVolume = pChannelInfo->volume; + // Some sanity checks. + if (m_sEngineName == "NONE") + m_sEngineName = QString::null; + if (m_sInstrumentFile == "NONE") + m_sInstrumentFile = QString::null; } // Set some proper display values. @@ -380,6 +394,15 @@ InstrumentNameTextLabel->setText(QString("%1 [%2]") .arg(QFileInfo(m_sInstrumentFile).fileName()).arg(m_iInstrumentNr)); + // Instrument status... + if (m_iInstrumentStatus < 0) { + InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red); + InstrumentStatusTextLabel->setText(tr("ERR%1").arg(m_iInstrumentStatus)); + } else { + InstrumentStatusTextLabel->setPaletteForegroundColor(m_iInstrumentStatus < 100 ? Qt::yellow : Qt::green); + InstrumentStatusTextLabel->setText(QString::number(m_iInstrumentStatus) + "%"); + } + // MIDI Port/Channel... MidiPortChannelTextLabel->setText(QString("%1 / %2") .arg(m_iMidiPort).arg(m_iMidiChannel)); @@ -407,9 +430,7 @@ #endif // And clip... - if (iVolume > 100) - iVolume = 100; - else if (iVolume < 0) + if (iVolume < 0) iVolume = 0; // Flag it here, to avoid infinite recursion. @@ -426,6 +447,19 @@ if (client() == NULL) return; + // Conditionally update whole channel status info. + if (m_iInstrumentStatus >= 0 && m_iInstrumentStatus < 100) { + updateChannelInfo(); + // Once we get a complete instrument load, try a implied reset channel.... + if (m_iInstrumentStatus == 100) { + if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) + appendMessagesClient("lscp_reset_channel"); + } + } + // Leave, if we still have an erroneus or incomplete instrument load. + if (m_iInstrumentStatus < 100) + return; + // Get current channel voice count. int iVoiceCount = ::lscp_get_channel_voice_count(client(), m_iChannelID); // Get current stream count. @@ -433,16 +467,8 @@ // Get current channel buffer fill usage. // As benno has suggested this is the percentage usage // of the least filled buffer stream... - int iStreamUsage = 0; - if (iStreamCount > 0) { - lscp_buffer_fill_t *pBufferFill = ::lscp_get_channel_buffer_fill(client(), LSCP_USAGE_PERCENTAGE, m_iChannelID); - if (pBufferFill) { - for (int iStream = 0; iStream < iStreamCount; iStream++) { - if (iStreamUsage > (int) pBufferFill[iStream].stream_usage || iStream == 0) - iStreamUsage = pBufferFill[iStream].stream_usage; - } - } - } + int iStreamUsage = ::lscp_get_channel_stream_usage(client(), m_iChannelID);; + // Update the GUI elements... StreamUsageProgressBar->setProgress(iStreamUsage); StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount)); @@ -458,9 +484,7 @@ // Convert and clip. float fVolume = (float) iVolume / 100.0; - if (fVolume > 1.0) - fVolume = 1.0; - else if (fVolume < 0.0) + if (fVolume < 0.001) fVolume = 0.0; // Update the GUI elements. @@ -498,5 +522,23 @@ } +// Context menu event handler. +void qsamplerChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent ) +{ + // We'll just show up the main form's edit menu. + m_pMainForm->contextMenuEvent(pEvent); +} + + +// Maximum volume slider accessors. +void qsamplerChannelStrip::setMaxVolume ( int iMaxVolume ) +{ + m_iDirtyChange++; + VolumeSlider->setRange(0, iMaxVolume); + VolumeSpinBox->setRange(0, iMaxVolume); + m_iDirtyChange--; +} + + // end of qsamplerChannelStrip.ui.h