/[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 371 by capela, Fri Feb 11 15:36:06 2005 UTC revision 400 by capela, Mon Feb 21 15:02:58 2005 UTC
# Line 45  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_sInstrumentName   = QObject::tr("(No instrument)");  //  m_sInstrumentName   = noInstrumentName();
50  //  m_sInstrumentFile   = m_sInstrumentName;  //  m_sInstrumentFile   = m_sInstrumentName;
51      m_iInstrumentNr     = -1;      m_iInstrumentNr     = -1;
52      m_iInstrumentStatus = -1;      m_iInstrumentStatus = -1;
# Line 159  bool qsamplerChannel::loadEngine ( const Line 159  bool qsamplerChannel::loadEngine ( const
159  {  {
160      if (client() == NULL || m_iChannelID < 0)      if (client() == NULL || m_iChannelID < 0)
161          return false;          return false;
162            if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
163                return true;
164                
165      if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {      if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {
166          appendMessagesClient("lscp_load_engine");          appendMessagesClient("lscp_load_engine");
167          return false;          return false;
# Line 170  bool qsamplerChannel::loadEngine ( const Line 172  bool qsamplerChannel::loadEngine ( const
172  }  }
173    
174    
 // Instrument name accessor.  
 QString& qsamplerChannel::instrumentName (void)  
 {  
     return m_sInstrumentName;  
 }  
   
175  // Instrument filename accessor.  // Instrument filename accessor.
176  QString& qsamplerChannel::instrumentFile (void)  QString& qsamplerChannel::instrumentFile (void)
177  {  {
# Line 188  int qsamplerChannel::instrumentNr (void) Line 184  int qsamplerChannel::instrumentNr (void)
184      return m_iInstrumentNr;      return m_iInstrumentNr;
185  }  }
186    
187    // Instrument name accessor.
188    QString& qsamplerChannel::instrumentName (void)
189    {
190        return m_sInstrumentName;
191    }
192    
193  // Instrument status accessor.  // Instrument status accessor.
194  int qsamplerChannel::instrumentStatus (void)  int qsamplerChannel::instrumentStatus (void)
195  {  {
# Line 199  bool qsamplerChannel::loadInstrument ( c Line 201  bool qsamplerChannel::loadInstrument ( c
201  {  {
202      if (client() == NULL || m_iChannelID < 0)      if (client() == NULL || m_iChannelID < 0)
203          return false;          return false;
204            if (!isInstrumentFile(sInstrumentFile))
205                return false;
206            if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)
207                return true;
208    
209      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) {
210          appendMessagesClient("lscp_load_instrument");          appendMessagesClient("lscp_load_instrument");
211          return false;          return false;
212      }      }
213    
214      m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);      return setInstrument(sInstrumentFile, iInstrumentNr);
215    }
216    
217    
218    // Special instrument file/name/number settler.
219    bool qsamplerChannel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
220    {
221      m_sInstrumentFile = sInstrumentFile;      m_sInstrumentFile = sInstrumentFile;
222      m_iInstrumentNr = iInstrumentNr;      m_iInstrumentNr = iInstrumentNr;
223    #ifdef CONFIG_INSTRUMENT_NAME
224        m_sInstrumentName = QString::null;  // We'll get it, maybe later, on channel_info...
225    #else
226        m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);
227    #endif
228      m_iInstrumentStatus = 0;      m_iInstrumentStatus = 0;
229    
230      return true;          return true;
231  }  }
232    
233    
# Line 224  bool qsamplerChannel::setMidiDriver ( co Line 241  bool qsamplerChannel::setMidiDriver ( co
241  {  {
242      if (client() == NULL || m_iChannelID < 0)      if (client() == NULL || m_iChannelID < 0)
243          return false;          return false;
244            if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
245                return true;
246    
247      if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {      if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {
248          appendMessagesClient("lscp_set_channel_midi_type");          appendMessagesClient("lscp_set_channel_midi_type");
# Line 245  bool qsamplerChannel::setMidiDevice ( in Line 264  bool qsamplerChannel::setMidiDevice ( in
264  {  {
265      if (client() == NULL || m_iChannelID < 0)      if (client() == NULL || m_iChannelID < 0)
266          return false;          return false;
267            if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)
268                return true;
269    
270      if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {      if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {
271          appendMessagesClient("lscp_set_channel_midi_device");          appendMessagesClient("lscp_set_channel_midi_device");
# Line 266  bool qsamplerChannel::setMidiPort ( int Line 287  bool qsamplerChannel::setMidiPort ( int
287  {  {
288      if (client() == NULL || m_iChannelID < 0)      if (client() == NULL || m_iChannelID < 0)
289          return false;          return false;
290            if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)
291                return true;
292    
293      if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {      if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {
294          appendMessagesClient("lscp_set_channel_midi_port");          appendMessagesClient("lscp_set_channel_midi_port");
# Line 287  bool qsamplerChannel::setMidiChannel ( i Line 310  bool qsamplerChannel::setMidiChannel ( i
310  {  {
311      if (client() == NULL || m_iChannelID < 0)      if (client() == NULL || m_iChannelID < 0)
312          return false;          return false;
313            if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)
314                return true;
315    
316      if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {      if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {
317          appendMessagesClient("lscp_set_channel_midi_channel");          appendMessagesClient("lscp_set_channel_midi_channel");
# Line 308  bool qsamplerChannel::setAudioDevice ( i Line 333  bool qsamplerChannel::setAudioDevice ( i
333  {  {
334      if (client() == NULL || m_iChannelID < 0)      if (client() == NULL || m_iChannelID < 0)
335          return false;          return false;
336            if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)
337                return true;
338    
339      if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {      if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {
340          appendMessagesClient("lscp_set_channel_audio_device");          appendMessagesClient("lscp_set_channel_audio_device");
# Line 329  bool qsamplerChannel::setAudioDriver ( c Line 356  bool qsamplerChannel::setAudioDriver ( c
356  {  {
357      if (client() == NULL || m_iChannelID < 0)      if (client() == NULL || m_iChannelID < 0)
358          return false;          return false;
359            if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
360                return true;
361    
362      if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {      if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {
363          appendMessagesClient("lscp_set_channel_audio_type");          appendMessagesClient("lscp_set_channel_audio_type");
# Line 350  bool qsamplerChannel::setVolume ( float Line 379  bool qsamplerChannel::setVolume ( float
379  {  {
380      if (client() == NULL || m_iChannelID < 0)      if (client() == NULL || m_iChannelID < 0)
381          return false;          return false;
382            if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)
383                return true;
384    
385      if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {      if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {
386          appendMessagesClient("lscp_set_channel_volume");          appendMessagesClient("lscp_set_channel_volume");
# Line 364  bool qsamplerChannel::setVolume ( float Line 395  bool qsamplerChannel::setVolume ( float
395  // Istrument name remapper.  // Istrument name remapper.
396  void qsamplerChannel::updateInstrumentName (void)  void qsamplerChannel::updateInstrumentName (void)
397  {  {
398    #ifndef CONFIG_INSTRUMENT_NAME
399          m_sInstrumentName = getInstrumentName(m_sInstrumentFile,          m_sInstrumentName = getInstrumentName(m_sInstrumentFile,
400                  m_iInstrumentNr, (options() && options()->bInstrumentNames));                  m_iInstrumentNr, (options() && options()->bInstrumentNames));
401    #endif
402  }  }
403    
404    
# Line 383  bool qsamplerChannel::updateChannelInfo Line 416  bool qsamplerChannel::updateChannelInfo
416          return false;          return false;
417      }      }
418    
419    #ifdef CONFIG_INSTRUMENT_NAME
420            // We got all actual instrument datum...
421            m_sInstrumentFile = pChannelInfo->instrument_file;
422            m_iInstrumentNr   = pChannelInfo->instrument_nr;
423            m_sInstrumentName = pChannelInfo->instrument_name;
424    #else
425          // First, check if intrument name has changed,          // First, check if intrument name has changed,
426          // taking care that instrument name lookup might be expensive,          // taking care that instrument name lookup might be expensive,
427          // so we better make it only once and when really needed...          // so we better make it only once and when really needed...
# Line 392  bool qsamplerChannel::updateChannelInfo Line 431  bool qsamplerChannel::updateChannelInfo
431                  m_iInstrumentNr   = pChannelInfo->instrument_nr;                  m_iInstrumentNr   = pChannelInfo->instrument_nr;
432                  updateInstrumentName();                  updateInstrumentName();
433          }          }
434    #endif
435      // Cache in other channel information.      // Cache in other channel information.
436      m_sEngineName       = pChannelInfo->engine_name;      m_sEngineName       = pChannelInfo->engine_name;
437      m_iInstrumentStatus = pChannelInfo->instrument_status;      m_iInstrumentStatus = pChannelInfo->instrument_status;
# Line 413  bool qsamplerChannel::updateChannelInfo Line 453  bool qsamplerChannel::updateChannelInfo
453    
454    
455  // Reset channel method.  // Reset channel method.
456  bool qsamplerChannel::resetChannel (void)  bool qsamplerChannel::channelReset (void)
457  {  {
458      if (client() == NULL || m_iChannelID < 0)      if (client() == NULL || m_iChannelID < 0)
459          return false;          return false;
# Line 478  void qsamplerChannel::contextMenuEvent( Line 518  void qsamplerChannel::contextMenuEvent(
518  }  }
519    
520    
521    // FIXME: Check whether a given file is an instrument file.
522    bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile )
523    {
524            bool bResult = false;
525    
526            QFile file(sInstrumentFile);
527            if (file.open(IO_ReadOnly)) {
528                    char achHeader[4];
529                    if (file.readBlock(achHeader, 4)) {
530                            bResult = (achHeader[0] == 'R'
531                                            && achHeader[1] == 'I'
532                                            && achHeader[2] == 'F'
533                                            && achHeader[3] == 'F');
534                    }
535                    file.close();
536            }
537    
538            return bResult;
539    }
540    
541    
542  // Retrieve the instrument list of a instrument file (.gig).  // Retrieve the instrument list of a instrument file (.gig).
543  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile,  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile,
544          bool bInstrumentNames )          bool bInstrumentNames )
545  {  {
546      QFileInfo fileinfo(sInstrumentFile);      QString sInstrumentName = QFileInfo(sInstrumentFile).fileName();
     QString sInstrumentName = fileinfo.fileName();  
547      QStringList instlist;      QStringList instlist;
548    
549      if (fileinfo.exists()) {      if (isInstrumentFile(sInstrumentFile)) {
550  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
551                  if (bInstrumentNames) {                  if (bInstrumentNames) {
552                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);
# Line 504  QStringList qsamplerChannel::getInstrume Line 564  QStringList qsamplerChannel::getInstrume
564          for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)          for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)
565              instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");              instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");
566      }      }
567      else instlist.append(sInstrumentName);      else instlist.append(noInstrumentName());
568    
569      return instlist;      return instlist;
570  }  }
# Line 514  QStringList qsamplerChannel::getInstrume Line 574  QStringList qsamplerChannel::getInstrume
574  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile,  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile,
575          int iInstrumentNr, bool bInstrumentNames )          int iInstrumentNr, bool bInstrumentNames )
576  {  {
577      QFileInfo fileinfo(sInstrumentFile);      QString sInstrumentName;
     QString sInstrumentName = fileinfo.fileName();  
578    
579      if (fileinfo.exists()) {      if (isInstrumentFile(sInstrumentFile)) {
580                    sInstrumentName = QFileInfo(sInstrumentFile).fileName();
581  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
582                  if (bInstrumentNames) {                  if (bInstrumentNames) {
583                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                  RIFF::File *pRiff = new RIFF::File(sInstrumentFile);
# Line 539  QString qsamplerChannel::getInstrumentNa Line 599  QString qsamplerChannel::getInstrumentNa
599  #endif  #endif
600          sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";          sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
601      }      }
602        else sInstrumentName = noInstrumentName();
603    
604      return sInstrumentName;      return sInstrumentName;
605  }  }
606    
607    
608    // Common invalid name-helpers.
609    QString qsamplerChannel::noEngineName (void)
610    {
611            return QObject::tr("(No engine)");
612    }
613    
614    QString qsamplerChannel::noInstrumentName (void)
615    {
616            return QObject::tr("(No instrument)");
617    }
618    
619    
620  // end of qsamplerChannel.cpp  // end of qsamplerChannel.cpp

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

  ViewVC Help
Powered by ViewVC