/[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 371 by capela, Fri Feb 11 15:36:06 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 169  bool qsamplerChannel::loadEngine ( const Line 170  bool qsamplerChannel::loadEngine ( const
170  }  }
171    
172    
173    // Instrument name accessor.
174    QString& qsamplerChannel::instrumentName (void)
175    {
176        return m_sInstrumentName;
177    }
178    
179  // Instrument filename accessor.  // Instrument filename accessor.
180  QString& qsamplerChannel::instrumentFile (void)  QString& qsamplerChannel::instrumentFile (void)
181  {  {
# Line 198  bool qsamplerChannel::loadInstrument ( c Line 205  bool qsamplerChannel::loadInstrument ( c
205          return false;          return false;
206      }      }
207    
208        m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);
209      m_sInstrumentFile = sInstrumentFile;      m_sInstrumentFile = sInstrumentFile;
210      m_iInstrumentNr = iInstrumentNr;      m_iInstrumentNr = iInstrumentNr;
211      m_iInstrumentStatus = 0;      m_iInstrumentStatus = 0;
# Line 353  bool qsamplerChannel::setVolume ( float Line 361  bool qsamplerChannel::setVolume ( float
361  }  }
362    
363    
364    // Istrument name remapper.
365    void qsamplerChannel::updateInstrumentName (void)
366    {
367            m_sInstrumentName = getInstrumentName(m_sInstrumentFile,
368                    m_iInstrumentNr, (options() && options()->bInstrumentNames));
369    }
370    
371    
372  // Update whole channel info state.  // Update whole channel info state.
373  bool qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
374  {  {
# Line 367  bool qsamplerChannel::updateChannelInfo Line 383  bool qsamplerChannel::updateChannelInfo
383          return false;          return false;
384      }      }
385    
386      // Cache in channel information.          // First, check if intrument name has changed,
387            // taking care that instrument name lookup might be expensive,
388            // so we better make it only once and when really needed...
389            if ((m_sInstrumentFile != pChannelInfo->instrument_file) ||
390                    (m_iInstrumentNr   != pChannelInfo->instrument_nr)) {
391                    m_sInstrumentFile = pChannelInfo->instrument_file;
392                    m_iInstrumentNr   = pChannelInfo->instrument_nr;
393                    updateInstrumentName();
394            }
395        // Cache in other channel information.
396      m_sEngineName       = pChannelInfo->engine_name;      m_sEngineName       = pChannelInfo->engine_name;
     m_sInstrumentFile   = pChannelInfo->instrument_file;  
     m_iInstrumentNr     = pChannelInfo->instrument_nr;  
397      m_iInstrumentStatus = pChannelInfo->instrument_status;      m_iInstrumentStatus = pChannelInfo->instrument_status;
398      m_iMidiDevice       = pChannelInfo->midi_device;      m_iMidiDevice       = pChannelInfo->midi_device;
399      m_iMidiPort         = pChannelInfo->midi_port;      m_iMidiPort         = pChannelInfo->midi_port;
# Line 380  bool qsamplerChannel::updateChannelInfo Line 403  bool qsamplerChannel::updateChannelInfo
403      // Some sanity checks.      // Some sanity checks.
404      if (m_sEngineName == "NONE")      if (m_sEngineName == "NONE")
405          m_sEngineName = QString::null;          m_sEngineName = QString::null;
406      if (m_sInstrumentFile == "NONE")      if (m_sInstrumentFile == "NONE") {
407          m_sInstrumentFile = QString::null;          m_sInstrumentFile = QString::null;
408            m_sInstrumentName = QString::null;
409            }
410    
411      return true;      return true;
412  }  }
# Line 454  void qsamplerChannel::contextMenuEvent( Line 479  void qsamplerChannel::contextMenuEvent(
479    
480    
481  // Retrieve the instrument list of a instrument file (.gig).  // Retrieve the instrument list of a instrument file (.gig).
482  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile )  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile,
483            bool bInstrumentNames )
484  {  {
485      QFileInfo fileinfo(sInstrumentFile);      QFileInfo fileinfo(sInstrumentFile);
486      QString sInstrumentName = fileinfo.fileName();      QString sInstrumentName = fileinfo.fileName();
# Line 462  QStringList qsamplerChannel::getInstrume Line 488  QStringList qsamplerChannel::getInstrume
488    
489      if (fileinfo.exists()) {      if (fileinfo.exists()) {
490  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
491          RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                  if (bInstrumentNames) {
492          gig::File  *pGig  = new gig::File(pRiff);                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);
493          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                  gig::File  *pGig  = new gig::File(pRiff);
494          while (pInstrument) {                  gig::Instrument *pInstrument = pGig->GetFirstInstrument();
495              sInstrumentName = (pInstrument->pInfo)->Name;                  while (pInstrument) {
496              instlist.append(sInstrumentName);                      instlist.append((pInstrument->pInfo)->Name.c_str());
497              pInstrument = pGig->GetNextInstrument();                      pInstrument = pGig->GetNextInstrument();
498          }                  }
499          delete pGig;                  delete pGig;
500          delete pRiff;                  delete pRiff;
501  #else                  }
502                    else
503    #endif
504          for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)          for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)
505              instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");              instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");
 #endif  
506      }      }
507      else instlist.append(sInstrumentName);      else instlist.append(sInstrumentName);
508        
509      return instlist;      return instlist;
510  }  }
511    
512    
513  // 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.
514  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, int iInstrumentNr )  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile,
515            int iInstrumentNr, bool bInstrumentNames )
516  {  {
517      QFileInfo fileinfo(sInstrumentFile);      QFileInfo fileinfo(sInstrumentFile);
518      QString sInstrumentName = fileinfo.fileName();      QString sInstrumentName = fileinfo.fileName();
519    
520      if (fileinfo.exists()) {      if (fileinfo.exists()) {
521  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
522          RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                  if (bInstrumentNames) {
523          gig::File  *pGig  = new gig::File(pRiff);                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);
524          int iIndex = 0;                  gig::File  *pGig  = new gig::File(pRiff);
525          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                  int iIndex = 0;
526          while (pInstrument) {                  gig::Instrument *pInstrument = pGig->GetFirstInstrument();
527              if (iIndex == iInstrumentNr) {                  while (pInstrument) {
528                  sInstrumentName = (pInstrument->pInfo)->Name;                      if (iIndex == iInstrumentNr) {
529                  break;                          sInstrumentName = (pInstrument->pInfo)->Name.c_str();
530              }                          break;
531              iIndex++;                      }
532              pInstrument = pGig->GetNextInstrument();                      iIndex++;
533          }                      pInstrument = pGig->GetNextInstrument();
534          delete pGig;                  }
535          delete pRiff;                  delete pGig;
536  #else                  delete pRiff;
537          sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";                  }
538                    else
539  #endif  #endif
540            sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
541      }      }
542    
543      return sInstrumentName;      return sInstrumentName;

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

  ViewVC Help
Powered by ViewVC