/[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 343 by capela, Tue Jan 18 12:32:01 2005 UTC revision 388 by capela, Thu Feb 17 17:27:59 2005 UTC
# Line 38  Line 38 
38  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
39  // qsamplerChannel - Sampler channel structure.  // qsamplerChannel - Sampler channel structure.
40  //  //
 bool qsamplerChannel::g_bInstrumentNames = false;  
41    
42  // Constructor.  // Constructor.
43  qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )  qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )
# Line 46  qsamplerChannel::qsamplerChannel ( qsamp Line 45  qsamplerChannel::qsamplerChannel ( qsamp
45      m_pMainForm  = pMainForm;      m_pMainForm  = pMainForm;
46      m_iChannelID = iChannelID;      m_iChannelID = iChannelID;
47    
48  //  m_sEngineName       = QObject::tr("(No engine)");  //  m_sEngineName       = noEngineName();
49  //  m_sInstrumentFile   = QObject::tr("(No instrument)");  //  m_sInstrumentName   = noInstrumentName();
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 182  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 193  bool qsamplerChannel::loadInstrument ( c Line 199  bool qsamplerChannel::loadInstrument ( c
199  {  {
200      if (client() == NULL || m_iChannelID < 0)      if (client() == NULL || m_iChannelID < 0)
201          return false;          return false;
202            if (!isInstrumentFile(sInstrumentFile))
203                return false;
204    
205      if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {      if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {
206          appendMessagesClient("lscp_load_instrument");          appendMessagesClient("lscp_load_instrument");
207          return false;          return false;
208      }      }
209    
210        return setInstrument(sInstrumentFile, iInstrumentNr);
211    }
212    
213    
214    // Special instrument file/name/number settler.
215    bool qsamplerChannel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
216    {
217      m_sInstrumentFile = sInstrumentFile;      m_sInstrumentFile = sInstrumentFile;
218      m_iInstrumentNr = iInstrumentNr;      m_iInstrumentNr = iInstrumentNr;
219    #ifdef CONFIG_INSTRUMENT_NAME
220        m_sInstrumentName = QString::null;  // We'll get it, maybe later, on channel_info...
221    #else
222        m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);
223    #endif
224      m_iInstrumentStatus = 0;      m_iInstrumentStatus = 0;
225    
226      return true;          return true;
227  }  }
228    
229    
# Line 354  bool qsamplerChannel::setVolume ( float Line 374  bool qsamplerChannel::setVolume ( float
374  }  }
375    
376    
377    // Istrument name remapper.
378    void qsamplerChannel::updateInstrumentName (void)
379    {
380    #ifndef CONFIG_INSTRUMENT_NAME
381            m_sInstrumentName = getInstrumentName(m_sInstrumentFile,
382                    m_iInstrumentNr, (options() && options()->bInstrumentNames));
383    #endif
384    }
385    
386    
387  // Update whole channel info state.  // Update whole channel info state.
388  bool qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
389  {  {
# Line 368  bool qsamplerChannel::updateChannelInfo Line 398  bool qsamplerChannel::updateChannelInfo
398          return false;          return false;
399      }      }
400    
401      // Cache in channel information.  #ifdef CONFIG_INSTRUMENT_NAME
402            // We got all actual instrument datum...
403            m_sInstrumentFile = pChannelInfo->instrument_file;
404            m_iInstrumentNr   = pChannelInfo->instrument_nr;
405            m_sInstrumentName = pChannelInfo->instrument_name;
406    #else
407            // First, check if intrument name has changed,
408            // taking care that instrument name lookup might be expensive,
409            // so we better make it only once and when really needed...
410            if ((m_sInstrumentFile != pChannelInfo->instrument_file) ||
411                    (m_iInstrumentNr   != pChannelInfo->instrument_nr)) {
412                    m_sInstrumentFile = pChannelInfo->instrument_file;
413                    m_iInstrumentNr   = pChannelInfo->instrument_nr;
414                    updateInstrumentName();
415            }
416    #endif
417        // Cache in other channel information.
418      m_sEngineName       = pChannelInfo->engine_name;      m_sEngineName       = pChannelInfo->engine_name;
     m_sInstrumentFile   = pChannelInfo->instrument_file;  
     m_iInstrumentNr     = pChannelInfo->instrument_nr;  
419      m_iInstrumentStatus = pChannelInfo->instrument_status;      m_iInstrumentStatus = pChannelInfo->instrument_status;
420      m_iMidiDevice       = pChannelInfo->midi_device;      m_iMidiDevice       = pChannelInfo->midi_device;
421      m_iMidiPort         = pChannelInfo->midi_port;      m_iMidiPort         = pChannelInfo->midi_port;
# Line 381  bool qsamplerChannel::updateChannelInfo Line 425  bool qsamplerChannel::updateChannelInfo
425      // Some sanity checks.      // Some sanity checks.
426      if (m_sEngineName == "NONE")      if (m_sEngineName == "NONE")
427          m_sEngineName = QString::null;          m_sEngineName = QString::null;
428      if (m_sInstrumentFile == "NONE")      if (m_sInstrumentFile == "NONE") {
429          m_sInstrumentFile = QString::null;          m_sInstrumentFile = QString::null;
430            m_sInstrumentName = QString::null;
431            }
432    
433      return true;      return true;
434  }  }
# Line 454  void qsamplerChannel::contextMenuEvent( Line 500  void qsamplerChannel::contextMenuEvent(
500  }  }
501    
502    
503    // FIXME: Check whether a given file is an instrument file.
504    bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile )
505    {
506            bool bResult = false;
507    
508            QFile file(sInstrumentFile);
509            if (file.open(IO_ReadOnly)) {
510                    char achHeader[4];
511                    if (file.readBlock(achHeader, 4)) {
512                            bResult = (achHeader[0] == 'R'
513                                            && achHeader[1] == 'I'
514                                            && achHeader[2] == 'F'
515                                            && achHeader[3] == 'F');
516                    }
517                    file.close();
518            }
519    
520            return bResult;
521    }
522    
523    
524  // Retrieve the instrument list of a instrument file (.gig).  // Retrieve the instrument list of a instrument file (.gig).
525  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile )  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile,
526            bool bInstrumentNames )
527  {  {
528      QFileInfo fileinfo(sInstrumentFile);      QString sInstrumentName = QFileInfo(sInstrumentFile).fileName();
     QString sInstrumentName = fileinfo.fileName();  
529      QStringList instlist;      QStringList instlist;
530    
531      if (fileinfo.exists()) {      if (isInstrumentFile(sInstrumentFile)) {
532  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
533                  if (g_bInstrumentNames) {                  if (bInstrumentNames) {
534                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);
535                  gig::File  *pGig  = new gig::File(pRiff);                  gig::File  *pGig  = new gig::File(pRiff);
536                  gig::Instrument *pInstrument = pGig->GetFirstInstrument();                  gig::Instrument *pInstrument = pGig->GetFirstInstrument();
# Line 479  QStringList qsamplerChannel::getInstrume Line 546  QStringList qsamplerChannel::getInstrume
546          for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)          for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)
547              instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");              instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");
548      }      }
549      else instlist.append(sInstrumentName);      else instlist.append(noInstrumentName());
550    
551      return instlist;      return instlist;
552  }  }
553    
554    
555  // 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.
556  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, int iInstrumentNr )  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile,
557            int iInstrumentNr, bool bInstrumentNames )
558  {  {
559      QFileInfo fileinfo(sInstrumentFile);      QString sInstrumentName;
     QString sInstrumentName = fileinfo.fileName();  
560    
561      if (fileinfo.exists()) {      if (isInstrumentFile(sInstrumentFile)) {
562                    sInstrumentName = QFileInfo(sInstrumentFile).fileName();
563  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
564                  if (g_bInstrumentNames) {                  if (bInstrumentNames) {
565                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);
566                  gig::File  *pGig  = new gig::File(pRiff);                  gig::File  *pGig  = new gig::File(pRiff);
567                  int iIndex = 0;                  int iIndex = 0;
# Line 513  QString qsamplerChannel::getInstrumentNa Line 581  QString qsamplerChannel::getInstrumentNa
581  #endif  #endif
582          sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";          sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
583      }      }
584        else sInstrumentName = noInstrumentName();
585    
586      return sInstrumentName;      return sInstrumentName;
587  }  }
588    
589    
590  // Instrument name(s) retrieval mode--global option.  // Common invalid name-helpers.
591  bool qsamplerChannel::instrumentNames (void)  QString qsamplerChannel::noEngineName (void)
592  {  {
593          return g_bInstrumentNames;          return QObject::tr("(No engine)");
594  }  }
595    
596  void qsamplerChannel::setInstrumentNames ( bool bInstrumentNames )  QString qsamplerChannel::noInstrumentName (void)
597  {  {
598          g_bInstrumentNames = bInstrumentNames;          return QObject::tr("(No instrument)");
599  }  }
600    
601    

Legend:
Removed from v.343  
changed lines
  Added in v.388

  ViewVC Help
Powered by ViewVC