/[svn]/qsampler/trunk/src/qsamplerChannel.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerChannel.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 303 by capela, Fri Nov 19 10:18:59 2004 UTC revision 382 by capela, Mon Feb 14 15:42:38 2005 UTC
# Line 1  Line 1 
1  // qsamplerChannel.cpp  // qsamplerChannel.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2003-2004, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2003-2005, rncbc aka Rui Nuno Capela. All rights reserved.
5    
6     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
7     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 30  Line 30 
30    
31  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
32  #include "gig.h"  #include "gig.h"
 #else  
 #define QSAMPLER_INSTRUMENT_MAX 8  
33  #endif  #endif
34    
35    #define QSAMPLER_INSTRUMENT_MAX 8
36    
37    
38  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
39  // qsamplerChannel - Sampler channel structure.  // qsamplerChannel - Sampler channel structure.
# Line 46  qsamplerChannel::qsamplerChannel ( qsamp Line 46  qsamplerChannel::qsamplerChannel ( qsamp
46      m_iChannelID = iChannelID;      m_iChannelID = iChannelID;
47    
48  //  m_sEngineName       = QObject::tr("(No engine)");  //  m_sEngineName       = QObject::tr("(No engine)");
49  //  m_sInstrumentFile   = QObject::tr("(No instrument)");  //  m_sInstrumentName   = QObject::tr("(No instrument)");
50    //  m_sInstrumentFile   = m_sInstrumentName;
51      m_iInstrumentNr     = -1;      m_iInstrumentNr     = -1;
52      m_iInstrumentStatus = -1;      m_iInstrumentStatus = -1;
53      m_sMidiDriver       = "Alsa";   // DEPRECATED.      m_sMidiDriver       = "Alsa";   // DEPRECATED.
# Line 181  int qsamplerChannel::instrumentNr (void) Line 182  int qsamplerChannel::instrumentNr (void)
182      return m_iInstrumentNr;      return m_iInstrumentNr;
183  }  }
184    
185    // Instrument name accessor.
186    QString& qsamplerChannel::instrumentName (void)
187    {
188        return m_sInstrumentName;
189    }
190    
191  // Instrument status accessor.  // Instrument status accessor.
192  int qsamplerChannel::instrumentStatus (void)  int qsamplerChannel::instrumentStatus (void)
193  {  {
# Line 200  bool qsamplerChannel::loadInstrument ( c Line 207  bool qsamplerChannel::loadInstrument ( c
207    
208      m_sInstrumentFile = sInstrumentFile;      m_sInstrumentFile = sInstrumentFile;
209      m_iInstrumentNr = iInstrumentNr;      m_iInstrumentNr = iInstrumentNr;
210    #ifdef CONFIG_INSTRUMENT_NAME
211        m_sInstrumentName = QString::null;  // We'll get it later on channel_info...
212    #else
213        m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);
214    #endif
215      m_iInstrumentStatus = 0;      m_iInstrumentStatus = 0;
216    
217      return true;      return true;
# Line 353  bool qsamplerChannel::setVolume ( float Line 365  bool qsamplerChannel::setVolume ( float
365  }  }
366    
367    
368    // Istrument name remapper.
369    void qsamplerChannel::updateInstrumentName (void)
370    {
371    #ifndef CONFIG_INSTRUMENT_NAME
372            m_sInstrumentName = getInstrumentName(m_sInstrumentFile,
373                    m_iInstrumentNr, (options() && options()->bInstrumentNames));
374    #endif
375    }
376    
377    
378  // Update whole channel info state.  // Update whole channel info state.
379  bool qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
380  {  {
# Line 367  bool qsamplerChannel::updateChannelInfo Line 389  bool qsamplerChannel::updateChannelInfo
389          return false;          return false;
390      }      }
391    
392      // Cache in channel information.  #ifdef CONFIG_INSTRUMENT_NAME
393            // We got all actual instrument datum...
394            m_sInstrumentFile = pChannelInfo->instrument_file;
395            m_iInstrumentNr   = pChannelInfo->instrument_nr;
396            m_sInstrumentName = pChannelInfo->instrument_name;
397    #else
398            // First, check if intrument name has changed,
399            // taking care that instrument name lookup might be expensive,
400            // so we better make it only once and when really needed...
401            if ((m_sInstrumentFile != pChannelInfo->instrument_file) ||
402                    (m_iInstrumentNr   != pChannelInfo->instrument_nr)) {
403                    m_sInstrumentFile = pChannelInfo->instrument_file;
404                    m_iInstrumentNr   = pChannelInfo->instrument_nr;
405                    updateInstrumentName();
406            }
407    #endif
408        // Cache in other channel information.
409      m_sEngineName       = pChannelInfo->engine_name;      m_sEngineName       = pChannelInfo->engine_name;
     m_sInstrumentFile   = pChannelInfo->instrument_file;  
     m_iInstrumentNr     = pChannelInfo->instrument_nr;  
410      m_iInstrumentStatus = pChannelInfo->instrument_status;      m_iInstrumentStatus = pChannelInfo->instrument_status;
411      m_iMidiDevice       = pChannelInfo->midi_device;      m_iMidiDevice       = pChannelInfo->midi_device;
412      m_iMidiPort         = pChannelInfo->midi_port;      m_iMidiPort         = pChannelInfo->midi_port;
# Line 380  bool qsamplerChannel::updateChannelInfo Line 416  bool qsamplerChannel::updateChannelInfo
416      // Some sanity checks.      // Some sanity checks.
417      if (m_sEngineName == "NONE")      if (m_sEngineName == "NONE")
418          m_sEngineName = QString::null;          m_sEngineName = QString::null;
419      if (m_sInstrumentFile == "NONE")      if (m_sInstrumentFile == "NONE") {
420          m_sInstrumentFile = QString::null;          m_sInstrumentFile = QString::null;
421            m_sInstrumentName = QString::null;
422            }
423    
424      return true;      return true;
425  }  }
# Line 454  void qsamplerChannel::contextMenuEvent( Line 492  void qsamplerChannel::contextMenuEvent(
492    
493    
494  // Retrieve the instrument list of a instrument file (.gig).  // Retrieve the instrument list of a instrument file (.gig).
495  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile )  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile,
496            bool bInstrumentNames )
497  {  {
498      QFileInfo fileinfo(sInstrumentFile);      QFileInfo fileinfo(sInstrumentFile);
499      QString sInstrumentName = fileinfo.fileName();      QString sInstrumentName = fileinfo.fileName();
# Line 462  QStringList qsamplerChannel::getInstrume Line 501  QStringList qsamplerChannel::getInstrume
501    
502      if (fileinfo.exists()) {      if (fileinfo.exists()) {
503  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
504          RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                  if (bInstrumentNames) {
505          gig::File  *pGig  = new gig::File(pRiff);                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);
506          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                  gig::File  *pGig  = new gig::File(pRiff);
507          while (pInstrument) {                  gig::Instrument *pInstrument = pGig->GetFirstInstrument();
508              sInstrumentName = (pInstrument->pInfo)->Name;                  while (pInstrument) {
509              instlist.append(sInstrumentName);                      instlist.append((pInstrument->pInfo)->Name.c_str());
510              pInstrument = pGig->GetNextInstrument();                      pInstrument = pGig->GetNextInstrument();
511          }                  }
512          delete pGig;                  delete pGig;
513          delete pRiff;                  delete pRiff;
514  #else                  }
515                    else
516    #endif
517          for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)          for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)
518              instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");              instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");
 #endif  
519      }      }
520      else instlist.append(sInstrumentName);      else instlist.append(sInstrumentName);
521        
522      return instlist;      return instlist;
523  }  }
524    
525    
526  // Retrieve the spacific instrument name of a instrument file (.gig), given its index.  // Retrieve the spacific instrument name of a instrument file (.gig), given its index.
527  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, int iInstrumentNr )  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile,
528            int iInstrumentNr, bool bInstrumentNames )
529  {  {
530      QFileInfo fileinfo(sInstrumentFile);      QFileInfo fileinfo(sInstrumentFile);
531      QString sInstrumentName = fileinfo.fileName();      QString sInstrumentName = fileinfo.fileName();
532    
533      if (fileinfo.exists()) {      if (fileinfo.exists()) {
534  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
535          RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                  if (bInstrumentNames) {
536          gig::File  *pGig  = new gig::File(pRiff);                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);
537          int iIndex = 0;                  gig::File  *pGig  = new gig::File(pRiff);
538          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                  int iIndex = 0;
539          while (pInstrument) {                  gig::Instrument *pInstrument = pGig->GetFirstInstrument();
540              if (iIndex == iInstrumentNr) {                  while (pInstrument) {
541                  sInstrumentName = (pInstrument->pInfo)->Name;                      if (iIndex == iInstrumentNr) {
542                  break;                          sInstrumentName = (pInstrument->pInfo)->Name.c_str();
543              }                          break;
544              iIndex++;                      }
545              pInstrument = pGig->GetNextInstrument();                      iIndex++;
546          }                      pInstrument = pGig->GetNextInstrument();
547          delete pGig;                  }
548          delete pRiff;                  delete pGig;
549  #else                  delete pRiff;
550          sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";                  }
551                    else
552  #endif  #endif
553            sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
554      }      }
555    
556      return sInstrumentName;      return sInstrumentName;

Legend:
Removed from v.303  
changed lines
  Added in v.382

  ViewVC Help
Powered by ViewVC