--- qsampler/trunk/src/qsamplerChannel.cpp 2005/02/11 15:36:06 371 +++ qsampler/trunk/src/qsamplerChannel.cpp 2005/02/17 17:27:59 388 @@ -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; @@ -170,12 +170,6 @@ } -// Instrument name accessor. -QString& qsamplerChannel::instrumentName (void) -{ - return m_sInstrumentName; -} - // Instrument filename accessor. QString& qsamplerChannel::instrumentFile (void) { @@ -188,6 +182,12 @@ return m_iInstrumentNr; } +// Instrument name accessor. +QString& qsamplerChannel::instrumentName (void) +{ + return m_sInstrumentName; +} + // Instrument status accessor. int qsamplerChannel::instrumentStatus (void) { @@ -199,18 +199,31 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (!isInstrumentFile(sInstrumentFile)) + return false; 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; } @@ -364,8 +377,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 +398,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 +413,7 @@ m_iInstrumentNr = pChannelInfo->instrument_nr; updateInstrumentName(); } +#endif // Cache in other channel information. m_sEngineName = pChannelInfo->engine_name; m_iInstrumentStatus = pChannelInfo->instrument_status; @@ -478,15 +500,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 +546,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 +556,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 +581,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