--- qsampler/trunk/src/qsamplerChannel.cpp 2004/11/19 10:18:59 303 +++ qsampler/trunk/src/qsamplerChannel.cpp 2005/02/11 15:36:06 371 @@ -1,7 +1,7 @@ // qsamplerChannel.cpp // /**************************************************************************** - Copyright (C) 2003-2004, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2003-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 @@ -30,10 +30,10 @@ #ifdef CONFIG_LIBGIG #include "gig.h" -#else -#define QSAMPLER_INSTRUMENT_MAX 8 #endif +#define QSAMPLER_INSTRUMENT_MAX 8 + //------------------------------------------------------------------------- // qsamplerChannel - Sampler channel structure. @@ -46,7 +46,8 @@ m_iChannelID = iChannelID; // m_sEngineName = QObject::tr("(No engine)"); -// m_sInstrumentFile = QObject::tr("(No instrument)"); +// m_sInstrumentName = QObject::tr("(No instrument)"); +// m_sInstrumentFile = m_sInstrumentName; m_iInstrumentNr = -1; m_iInstrumentStatus = -1; m_sMidiDriver = "Alsa"; // DEPRECATED. @@ -169,6 +170,12 @@ } +// Instrument name accessor. +QString& qsamplerChannel::instrumentName (void) +{ + return m_sInstrumentName; +} + // Instrument filename accessor. QString& qsamplerChannel::instrumentFile (void) { @@ -198,6 +205,7 @@ return false; } + m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true); m_sInstrumentFile = sInstrumentFile; m_iInstrumentNr = iInstrumentNr; m_iInstrumentStatus = 0; @@ -353,6 +361,14 @@ } +// Istrument name remapper. +void qsamplerChannel::updateInstrumentName (void) +{ + m_sInstrumentName = getInstrumentName(m_sInstrumentFile, + m_iInstrumentNr, (options() && options()->bInstrumentNames)); +} + + // Update whole channel info state. bool qsamplerChannel::updateChannelInfo (void) { @@ -367,10 +383,17 @@ return false; } - // Cache in channel information. + // 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... + if ((m_sInstrumentFile != pChannelInfo->instrument_file) || + (m_iInstrumentNr != pChannelInfo->instrument_nr)) { + m_sInstrumentFile = pChannelInfo->instrument_file; + m_iInstrumentNr = pChannelInfo->instrument_nr; + updateInstrumentName(); + } + // Cache in other channel information. 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; @@ -380,8 +403,10 @@ // Some sanity checks. if (m_sEngineName == "NONE") m_sEngineName = QString::null; - if (m_sInstrumentFile == "NONE") + if (m_sInstrumentFile == "NONE") { m_sInstrumentFile = QString::null; + m_sInstrumentName = QString::null; + } return true; } @@ -454,7 +479,8 @@ // Retrieve the instrument list of a instrument file (.gig). -QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile ) +QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile, + bool bInstrumentNames ) { QFileInfo fileinfo(sInstrumentFile); QString sInstrumentName = fileinfo.fileName(); @@ -462,52 +488,56 @@ if (fileinfo.exists()) { #ifdef CONFIG_LIBGIG - RIFF::File *pRiff = new RIFF::File(sInstrumentFile); - gig::File *pGig = new gig::File(pRiff); - gig::Instrument *pInstrument = pGig->GetFirstInstrument(); - while (pInstrument) { - sInstrumentName = (pInstrument->pInfo)->Name; - instlist.append(sInstrumentName); - pInstrument = pGig->GetNextInstrument(); - } - delete pGig; - delete pRiff; -#else + if (bInstrumentNames) { + RIFF::File *pRiff = new RIFF::File(sInstrumentFile); + gig::File *pGig = new gig::File(pRiff); + gig::Instrument *pInstrument = pGig->GetFirstInstrument(); + while (pInstrument) { + instlist.append((pInstrument->pInfo)->Name.c_str()); + pInstrument = pGig->GetNextInstrument(); + } + delete pGig; + delete pRiff; + } + else +#endif for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); -#endif } else instlist.append(sInstrumentName); - + return instlist; } // Retrieve the spacific instrument name of a instrument file (.gig), given its index. -QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, int iInstrumentNr ) +QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, + int iInstrumentNr, bool bInstrumentNames ) { QFileInfo fileinfo(sInstrumentFile); QString sInstrumentName = fileinfo.fileName(); if (fileinfo.exists()) { #ifdef CONFIG_LIBGIG - RIFF::File *pRiff = new RIFF::File(sInstrumentFile); - gig::File *pGig = new gig::File(pRiff); - int iIndex = 0; - gig::Instrument *pInstrument = pGig->GetFirstInstrument(); - while (pInstrument) { - if (iIndex == iInstrumentNr) { - sInstrumentName = (pInstrument->pInfo)->Name; - break; - } - iIndex++; - pInstrument = pGig->GetNextInstrument(); - } - delete pGig; - delete pRiff; -#else - sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; + if (bInstrumentNames) { + RIFF::File *pRiff = new RIFF::File(sInstrumentFile); + gig::File *pGig = new gig::File(pRiff); + int iIndex = 0; + gig::Instrument *pInstrument = pGig->GetFirstInstrument(); + while (pInstrument) { + if (iIndex == iInstrumentNr) { + sInstrumentName = (pInstrument->pInfo)->Name.c_str(); + break; + } + iIndex++; + pInstrument = pGig->GetNextInstrument(); + } + delete pGig; + delete pRiff; + } + else #endif + sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; } return sInstrumentName;