--- qsampler/trunk/src/qsamplerChannel.cpp 2005/02/11 15:36:06 371 +++ qsampler/trunk/src/qsamplerChannel.cpp 2005/02/21 15:02:58 400 @@ -45,8 +45,8 @@ m_pMainForm = pMainForm; m_iChannelID = iChannelID; -// m_sEngineName = QObject::tr("(No engine)"); -// m_sInstrumentName = QObject::tr("(No instrument)"); +// m_sEngineName = noEngineName(); +// m_sInstrumentName = noInstrumentName(); // m_sInstrumentFile = m_sInstrumentName; m_iInstrumentNr = -1; m_iInstrumentStatus = -1; @@ -159,7 +159,9 @@ { if (client() == NULL || m_iChannelID < 0) return false; - + if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName) + return true; + if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { appendMessagesClient("lscp_load_engine"); return false; @@ -170,12 +172,6 @@ } -// Instrument name accessor. -QString& qsamplerChannel::instrumentName (void) -{ - return m_sInstrumentName; -} - // Instrument filename accessor. QString& qsamplerChannel::instrumentFile (void) { @@ -188,6 +184,12 @@ return m_iInstrumentNr; } +// Instrument name accessor. +QString& qsamplerChannel::instrumentName (void) +{ + return m_sInstrumentName; +} + // Instrument status accessor. int qsamplerChannel::instrumentStatus (void) { @@ -199,18 +201,33 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (!isInstrumentFile(sInstrumentFile)) + return false; + if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr) + return true; if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { appendMessagesClient("lscp_load_instrument"); return false; } - m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true); + return setInstrument(sInstrumentFile, iInstrumentNr); +} + + +// Special instrument file/name/number settler. +bool qsamplerChannel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) +{ m_sInstrumentFile = sInstrumentFile; m_iInstrumentNr = iInstrumentNr; +#ifdef CONFIG_INSTRUMENT_NAME + m_sInstrumentName = QString::null; // We'll get it, maybe later, on channel_info... +#else + m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true); +#endif m_iInstrumentStatus = 0; - return true; + return true; } @@ -224,6 +241,8 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver) + return true; if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { appendMessagesClient("lscp_set_channel_midi_type"); @@ -245,6 +264,8 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice) + return true; if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) { appendMessagesClient("lscp_set_channel_midi_device"); @@ -266,6 +287,8 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort) + return true; if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) { appendMessagesClient("lscp_set_channel_midi_port"); @@ -287,6 +310,8 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel) + return true; if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) { appendMessagesClient("lscp_set_channel_midi_channel"); @@ -308,6 +333,8 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice) + return true; if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) { appendMessagesClient("lscp_set_channel_audio_device"); @@ -329,6 +356,8 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver) + return true; if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { appendMessagesClient("lscp_set_channel_audio_type"); @@ -350,6 +379,8 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_fVolume == fVolume) + return true; if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) { appendMessagesClient("lscp_set_channel_volume"); @@ -364,8 +395,10 @@ // Istrument name remapper. void qsamplerChannel::updateInstrumentName (void) { +#ifndef CONFIG_INSTRUMENT_NAME m_sInstrumentName = getInstrumentName(m_sInstrumentFile, m_iInstrumentNr, (options() && options()->bInstrumentNames)); +#endif } @@ -383,6 +416,12 @@ return false; } +#ifdef CONFIG_INSTRUMENT_NAME + // We got all actual instrument datum... + m_sInstrumentFile = pChannelInfo->instrument_file; + m_iInstrumentNr = pChannelInfo->instrument_nr; + m_sInstrumentName = pChannelInfo->instrument_name; +#else // First, check if intrument name has changed, // taking care that instrument name lookup might be expensive, // so we better make it only once and when really needed... @@ -392,6 +431,7 @@ m_iInstrumentNr = pChannelInfo->instrument_nr; updateInstrumentName(); } +#endif // Cache in other channel information. m_sEngineName = pChannelInfo->engine_name; m_iInstrumentStatus = pChannelInfo->instrument_status; @@ -413,7 +453,7 @@ // Reset channel method. -bool qsamplerChannel::resetChannel (void) +bool qsamplerChannel::channelReset (void) { if (client() == NULL || m_iChannelID < 0) return false; @@ -478,15 +518,35 @@ } +// FIXME: Check whether a given file is an instrument file. +bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile ) +{ + bool bResult = false; + + QFile file(sInstrumentFile); + if (file.open(IO_ReadOnly)) { + char achHeader[4]; + if (file.readBlock(achHeader, 4)) { + bResult = (achHeader[0] == 'R' + && achHeader[1] == 'I' + && achHeader[2] == 'F' + && achHeader[3] == 'F'); + } + file.close(); + } + + return bResult; +} + + // Retrieve the instrument list of a instrument file (.gig). QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile, bool bInstrumentNames ) { - QFileInfo fileinfo(sInstrumentFile); - QString sInstrumentName = fileinfo.fileName(); + QString sInstrumentName = QFileInfo(sInstrumentFile).fileName(); QStringList instlist; - if (fileinfo.exists()) { + if (isInstrumentFile(sInstrumentFile)) { #ifdef CONFIG_LIBGIG if (bInstrumentNames) { RIFF::File *pRiff = new RIFF::File(sInstrumentFile); @@ -504,7 +564,7 @@ for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); } - else instlist.append(sInstrumentName); + else instlist.append(noInstrumentName()); return instlist; } @@ -514,10 +574,10 @@ QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, int iInstrumentNr, bool bInstrumentNames ) { - QFileInfo fileinfo(sInstrumentFile); - QString sInstrumentName = fileinfo.fileName(); + QString sInstrumentName; - if (fileinfo.exists()) { + if (isInstrumentFile(sInstrumentFile)) { + sInstrumentName = QFileInfo(sInstrumentFile).fileName(); #ifdef CONFIG_LIBGIG if (bInstrumentNames) { RIFF::File *pRiff = new RIFF::File(sInstrumentFile); @@ -539,9 +599,22 @@ #endif sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; } + else sInstrumentName = noInstrumentName(); return sInstrumentName; } +// Common invalid name-helpers. +QString qsamplerChannel::noEngineName (void) +{ + return QObject::tr("(No engine)"); +} + +QString qsamplerChannel::noInstrumentName (void) +{ + return QObject::tr("(No instrument)"); +} + + // end of qsamplerChannel.cpp