/[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 2387 by capela, Sat Dec 29 00:21:11 2012 UTC revision 3555 by capela, Tue Aug 13 10:19:32 2019 UTC
# Line 1  Line 1 
1  // qsamplerChannel.cpp  // qsamplerChannel.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2012, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2019, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, 2008 Christian Schoenebeck     Copyright (C) 2007, 2008 Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
# Line 32  Line 32 
32    
33  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
34  #include "gig.h"  #include "gig.h"
35    #ifdef CONFIG_LIBGIG_SF2
36    #include "SF.h"
37    #endif
38  #endif  #endif
39    
40  namespace QSampler {  namespace QSampler {
41    
42  #define QSAMPLER_INSTRUMENT_MAX 100  #define QSAMPLER_INSTRUMENT_MAX 128
43    
44  #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))  #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))
45    
# Line 77  Channel::~Channel (void) Line 80  Channel::~Channel (void)
80  bool Channel::addChannel (void)  bool Channel::addChannel (void)
81  {  {
82          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
83          if (pMainForm == NULL)          if (pMainForm == nullptr)
84                  return false;                  return false;
85          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
86                  return false;                  return false;
87    
88          // Are we a new channel?          // Are we a new channel?
# Line 102  bool Channel::addChannel (void) Line 105  bool Channel::addChannel (void)
105  bool Channel::removeChannel (void)  bool Channel::removeChannel (void)
106  {  {
107          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
108          if (pMainForm == NULL)          if (pMainForm == nullptr)
109                  return false;                  return false;
110          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
111                  return false;                  return false;
112    
113          // Are we an existing channel?          // Are we an existing channel?
# Line 152  const QString& Channel::engineName (void Line 155  const QString& Channel::engineName (void
155  bool Channel::loadEngine ( const QString& sEngineName )  bool Channel::loadEngine ( const QString& sEngineName )
156  {  {
157          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
158          if (pMainForm == NULL)          if (pMainForm == nullptr)
159                  return false;                  return false;
160          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
161                  return false;                  return false;
162          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
163                  return true;                  return true;
# Line 200  int Channel::instrumentStatus (void) con Line 203  int Channel::instrumentStatus (void) con
203  bool Channel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool Channel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
204  {  {
205          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
206          if (pMainForm == NULL)          if (pMainForm == nullptr)
207                  return false;                  return false;
208          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
209                  return false;                  return false;
210          if (!QFileInfo(sInstrumentFile).exists())          if (!QFileInfo(sInstrumentFile).exists())
211                  return false;                  return false;
# Line 234  bool Channel::setInstrument ( const QStr Line 237  bool Channel::setInstrument ( const QStr
237          m_sInstrumentFile = sInstrumentFile;          m_sInstrumentFile = sInstrumentFile;
238          m_iInstrumentNr = iInstrumentNr;          m_iInstrumentNr = iInstrumentNr;
239  #ifdef CONFIG_INSTRUMENT_NAME  #ifdef CONFIG_INSTRUMENT_NAME
240          m_sInstrumentName = QString::null;  // We'll get it, maybe later, on channel_info...          m_sInstrumentName.clear();  // We'll get it, maybe later, on channel_info...
241  #else  #else
242          m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);          m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);
243  #endif  #endif
# Line 253  const QString& Channel::midiDriver (void Line 256  const QString& Channel::midiDriver (void
256  bool Channel::setMidiDriver ( const QString& sMidiDriver )  bool Channel::setMidiDriver ( const QString& sMidiDriver )
257  {  {
258          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
259          if (pMainForm == NULL)          if (pMainForm == nullptr)
260                  return false;                  return false;
261          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
262                  return false;                  return false;
263          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
264                  return true;                  return true;
# Line 282  int Channel::midiDevice (void) const Line 285  int Channel::midiDevice (void) const
285  bool Channel::setMidiDevice ( int iMidiDevice )  bool Channel::setMidiDevice ( int iMidiDevice )
286  {  {
287          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
288          if (pMainForm == NULL)          if (pMainForm == nullptr)
289                  return false;                  return false;
290          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
291                  return false;                  return false;
292          if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)          if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)
293                  return true;                  return true;
# Line 310  int Channel::midiPort (void) const Line 313  int Channel::midiPort (void) const
313  bool Channel::setMidiPort ( int iMidiPort )  bool Channel::setMidiPort ( int iMidiPort )
314  {  {
315          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
316          if (pMainForm == NULL)          if (pMainForm == nullptr)
317                  return false;                  return false;
318          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
319                  return false;                  return false;
320          if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)          if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)
321                  return true;                  return true;
# Line 338  int Channel::midiChannel (void) const Line 341  int Channel::midiChannel (void) const
341  bool Channel::setMidiChannel ( int iMidiChannel )  bool Channel::setMidiChannel ( int iMidiChannel )
342  {  {
343          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
344          if (pMainForm == NULL)          if (pMainForm == nullptr)
345                  return false;                  return false;
346          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
347                  return false;                  return false;
348          if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)          if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)
349                  return true;                  return true;
# Line 366  int Channel::midiMap (void) const Line 369  int Channel::midiMap (void) const
369  bool Channel::setMidiMap ( int iMidiMap )  bool Channel::setMidiMap ( int iMidiMap )
370  {  {
371          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
372          if (pMainForm == NULL)          if (pMainForm == nullptr)
373                  return false;                  return false;
374          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
375                  return false;                  return false;
376          if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap)          if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap)
377                  return true;                  return true;
# Line 394  int Channel::audioDevice (void) const Line 397  int Channel::audioDevice (void) const
397  bool Channel::setAudioDevice ( int iAudioDevice )  bool Channel::setAudioDevice ( int iAudioDevice )
398  {  {
399          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
400          if (pMainForm == NULL)          if (pMainForm == nullptr)
401                  return false;                  return false;
402          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
403                  return false;                  return false;
404          if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)          if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)
405                  return true;                  return true;
# Line 422  const QString& Channel::audioDriver (voi Line 425  const QString& Channel::audioDriver (voi
425  bool Channel::setAudioDriver ( const QString& sAudioDriver )  bool Channel::setAudioDriver ( const QString& sAudioDriver )
426  {  {
427          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
428          if (pMainForm == NULL)          if (pMainForm == nullptr)
429                  return false;                  return false;
430          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
431                  return false;                  return false;
432          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
433                  return true;                  return true;
# Line 451  float Channel::volume (void) const Line 454  float Channel::volume (void) const
454  bool Channel::setVolume ( float fVolume )  bool Channel::setVolume ( float fVolume )
455  {  {
456          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
457          if (pMainForm == NULL)          if (pMainForm == nullptr)
458                  return false;                  return false;
459          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
460                  return false;                  return false;
461          if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)          if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)
462                  return true;                  return true;
# Line 479  bool Channel::channelMute (void) const Line 482  bool Channel::channelMute (void) const
482  bool Channel::setChannelMute ( bool bMute )  bool Channel::setChannelMute ( bool bMute )
483  {  {
484          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
485          if (pMainForm == NULL)          if (pMainForm == nullptr)
486                  return false;                  return false;
487          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
488                  return false;                  return false;
489          if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))          if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))
490                  return true;                  return true;
# Line 509  bool Channel::channelSolo (void) const Line 512  bool Channel::channelSolo (void) const
512  bool Channel::setChannelSolo ( bool bSolo )  bool Channel::setChannelSolo ( bool bSolo )
513  {  {
514          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
515          if (pMainForm == NULL)          if (pMainForm == nullptr)
516                  return false;                  return false;
517          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
518                  return false;                  return false;
519          if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))          if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))
520                  return true;                  return true;
# Line 539  int Channel::audioChannel ( int iAudioOu Line 542  int Channel::audioChannel ( int iAudioOu
542  bool Channel::setAudioChannel ( int iAudioOut, int iAudioIn )  bool Channel::setAudioChannel ( int iAudioOut, int iAudioIn )
543  {  {
544          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
545          if (pMainForm == NULL)          if (pMainForm == nullptr)
546                  return false;                  return false;
547          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
548                  return false;                  return false;
549          if (m_iInstrumentStatus == 100 &&          if (m_iInstrumentStatus == 100 &&
550                          m_audioRouting[iAudioOut] == iAudioIn)                          m_audioRouting[iAudioOut] == iAudioIn)
# Line 581  void Channel::updateInstrumentName (void Line 584  void Channel::updateInstrumentName (void
584  bool Channel::updateChannelInfo (void)  bool Channel::updateChannelInfo (void)
585  {  {
586          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
587          if (pMainForm == NULL)          if (pMainForm == nullptr)
588                  return false;                  return false;
589          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
590                  return false;                  return false;
591    
592          // Read channel information.          // Read channel information.
593          lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(pMainForm->client(), m_iChannelID);          lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(pMainForm->client(), m_iChannelID);
594          if (pChannelInfo == NULL) {          if (pChannelInfo == nullptr) {
595                  appendMessagesClient("lscp_get_channel_info");                  appendMessagesClient("lscp_get_channel_info");
596                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
597                  return false;                  return false;
# Line 629  bool Channel::updateChannelInfo (void) Line 632  bool Channel::updateChannelInfo (void)
632  #endif  #endif
633          // Some sanity checks.          // Some sanity checks.
634          if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())          if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())
635                  m_sEngineName = QString::null;                  m_sEngineName.clear();
636          if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) {          if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) {
637                  m_sInstrumentFile = QString::null;                  m_sInstrumentFile.clear();
638                  m_sInstrumentName = QString::null;                  m_sInstrumentName.clear();
639          }          }
640    
641          // Time for device info grabbing...          // Time for device info grabbing...
# Line 640  bool Channel::updateChannelInfo (void) Line 643  bool Channel::updateChannelInfo (void)
643          const QString sNone = QObject::tr("(none)");          const QString sNone = QObject::tr("(none)");
644          // Audio device driver type.          // Audio device driver type.
645          pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice);          pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice);
646          if (pDeviceInfo == NULL) {          if (pDeviceInfo == nullptr) {
647                  appendMessagesClient("lscp_get_audio_device_info");                  appendMessagesClient("lscp_get_audio_device_info");
648                  m_sAudioDriver = sNone;                  m_sAudioDriver = sNone;
649          } else {          } else {
# Line 648  bool Channel::updateChannelInfo (void) Line 651  bool Channel::updateChannelInfo (void)
651          }          }
652          // MIDI device driver type.          // MIDI device driver type.
653          pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice);          pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice);
654          if (pDeviceInfo == NULL) {          if (pDeviceInfo == nullptr) {
655                  appendMessagesClient("lscp_get_midi_device_info");                  appendMessagesClient("lscp_get_midi_device_info");
656                  m_sMidiDriver = sNone;                  m_sMidiDriver = sNone;
657          } else {          } else {
# Line 675  bool Channel::updateChannelInfo (void) Line 678  bool Channel::updateChannelInfo (void)
678  bool Channel::channelReset (void)  bool Channel::channelReset (void)
679  {  {
680          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
681          if (pMainForm == NULL)          if (pMainForm == nullptr)
682                  return false;                  return false;
683          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
684                  return false;                  return false;
685    
686          if (::lscp_reset_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {          if (::lscp_reset_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
# Line 697  bool Channel::editChannel (void) Line 700  bool Channel::editChannel (void)
700  #ifdef CONFIG_EDIT_INSTRUMENT  #ifdef CONFIG_EDIT_INSTRUMENT
701    
702          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
703          if (pMainForm == NULL)          if (pMainForm == nullptr)
704                  return false;                  return false;
705          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
706                  return false;                  return false;
707    
708          if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID)          if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID)
# Line 738  bool Channel::editChannel (void) Line 741  bool Channel::editChannel (void)
741  bool Channel::channelSetup ( QWidget *pParent )  bool Channel::channelSetup ( QWidget *pParent )
742  {  {
743          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
744          if (pMainForm == NULL)          if (pMainForm == nullptr)
745                  return false;                  return false;
746    
747          bool bResult = false;          bool bResult = false;
# Line 757  bool Channel::channelSetup ( QWidget *pP Line 760  bool Channel::channelSetup ( QWidget *pP
760    
761    
762  // Redirected messages output methods.  // Redirected messages output methods.
763  void Channel::appendMessages( const QString& s ) const  void Channel::appendMessages ( const QString& sText ) const
764  {  {
765          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
766          if (pMainForm)          if (pMainForm)
767                  pMainForm->appendMessages(channelName() + ' ' + s);                  pMainForm->appendMessages(channelName() + ' ' + sText);
768  }  }
769    
770  void Channel::appendMessagesColor( const QString& s,  void Channel::appendMessagesColor (
771          const QString& c ) const          const QString& sText, const QString& sColor ) const
772  {  {
773          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
774          if (pMainForm)          if (pMainForm)
775                  pMainForm->appendMessagesColor(channelName() + ' ' + s, c);                  pMainForm->appendMessagesColor(channelName() + ' ' + sText, sColor);
776  }  }
777    
778  void Channel::appendMessagesText( const QString& s ) const  void Channel::appendMessagesText ( const QString& sText ) const
779  {  {
780          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
781          if (pMainForm)          if (pMainForm)
782                  pMainForm->appendMessagesText(channelName() + ' ' + s);                  pMainForm->appendMessagesText(channelName() + ' ' + sText);
783  }  }
784    
785  void Channel::appendMessagesError( const QString& s ) const  void Channel::appendMessagesError ( const QString& sText ) const
786  {  {
787          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
788          if (pMainForm)          if (pMainForm)
789                  pMainForm->appendMessagesError(channelName() + "\n\n" + s);                  pMainForm->appendMessagesError(channelName() + "\n\n" + sText);
790  }  }
791    
792  void Channel::appendMessagesClient( const QString& s ) const  void Channel::appendMessagesClient ( const QString& sText ) const
793  {  {
794          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
795          if (pMainForm)          if (pMainForm)
796                  pMainForm->appendMessagesClient(channelName() + ' ' + s);                  pMainForm->appendMessagesClient(channelName() + ' ' + sText);
797  }  }
798    
799    
800  // Context menu event handler.  // Context menu event handler.
801  void Channel::contextMenuEvent( QContextMenuEvent *pEvent )  void Channel::contextMenuEvent ( QContextMenuEvent *pEvent )
802  {  {
803          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
804          if (pMainForm)          if (pMainForm)
# Line 822  bool Channel::isDlsInstrumentFile ( cons Line 825  bool Channel::isDlsInstrumentFile ( cons
825  }  }
826    
827    
828    // FIXME: Check whether a given file is an instrument file (SF2 only).
829    bool Channel::isSf2InstrumentFile ( const QString& sInstrumentFile )
830    {
831            bool bResult = false;
832    
833            QFile file(sInstrumentFile);
834            if (file.open(QIODevice::ReadOnly)) {
835                    char achHeader[12];
836                    if (file.read(achHeader, 12) > 0) {
837                            bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0
838                                            && ::memcmp(&achHeader[8], "sfbk", 4) == 0);
839                    }
840                    file.close();
841            }
842    
843            return bResult;
844    }
845    
846    
847  // Retrieve the instrument list of a instrument file (.gig).  // Retrieve the instrument list of a instrument file (.gig).
848  QStringList Channel::getInstrumentList( const QString& sInstrumentFile,  QStringList Channel::getInstrumentList (
849          bool bInstrumentNames )          const QString& sInstrumentFile, bool bInstrumentNames )
850  {  {
851          QStringList instlist;          QStringList instlist;
852    
853          if (isDlsInstrumentFile(sInstrumentFile)) {          const QFileInfo fi(sInstrumentFile);
854          #ifdef CONFIG_LIBGIG          if (!fi.exists()) {
855                  if (bInstrumentNames) {                  instlist.append(noInstrumentName());
856                    return instlist;
857            }
858    
859    #ifdef CONFIG_LIBGIG
860            if (bInstrumentNames) {
861                    if (isDlsInstrumentFile(sInstrumentFile)) {
862                          RIFF::File *pRiff                          RIFF::File *pRiff
863                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());
864                          gig::File  *pGig  = new gig::File(pRiff);                          gig::File *pGig = new gig::File(pRiff);
865                  #if HAVE_LIBGIG_SETAUTOLOAD                  #ifdef CONFIG_LIBGIG_SETAUTOLOAD
866                          // prevent sleepy response time on large .gig files                          // prevent sleepy response time on large .gig files
867                          pGig->SetAutoLoad(false);                          pGig->SetAutoLoad(false);
868                  #endif                  #endif
# Line 846  QStringList Channel::getInstrumentList( Line 874  QStringList Channel::getInstrumentList(
874                          delete pGig;                          delete pGig;
875                          delete pRiff;                          delete pRiff;
876                  }                  }
877            #ifdef CONFIG_LIBGIG_SF2
878                    else
879                    if (isSf2InstrumentFile(sInstrumentFile)) {
880                            RIFF::File *pRiff
881                                    = new RIFF::File(sInstrumentFile.toUtf8().constData());
882                            sf2::File *pSf2 = new sf2::File(pRiff);
883                            const int iPresetCount = pSf2->GetPresetCount();
884                            for (int iIndex = 0; iIndex < iPresetCount; ++iIndex) {
885                                    sf2::Preset *pPreset = pSf2->GetPreset(iIndex);
886                                    if (pPreset) {
887                                            instlist.append(pPreset->Name.c_str());
888                                    } else {
889                                            instlist.append(fi.fileName()
890                                                    + " [" + QString::number(iIndex) + "]");
891                                    }
892                            }
893                            delete pSf2;
894                            delete pRiff;
895                    }
896          #endif          #endif
897          }          }
898    #endif
899    
900          if (instlist.isEmpty()) {          if (instlist.isEmpty()) {
901                  QFileInfo fi(sInstrumentFile);                  for (int iIndex = 0; iIndex < QSAMPLER_INSTRUMENT_MAX; ++iIndex) {
902                  if (fi.exists()) {                          instlist.append(fi.fileName()
903                          QString sInstrumentName = fi.fileName();                                  + " [" + QString::number(iIndex) + "]");
                         int iInstrumentNr = 0;  
                         while (iInstrumentNr < QSAMPLER_INSTRUMENT_MAX) {  
                                 instlist.append(sInstrumentName  
                                         + " [" + QString::number(++iInstrumentNr) + "]");  
                         }  
904                  }                  }
                 else instlist.append(noInstrumentName());  
905          }          }
906    
907          return instlist;          return instlist;
# Line 867  QStringList Channel::getInstrumentList( Line 909  QStringList Channel::getInstrumentList(
909    
910    
911  // 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.
912  QString Channel::getInstrumentName( const QString& sInstrumentFile,  QString Channel::getInstrumentName (
913          int iInstrumentNr, bool bInstrumentNames )          const QString& sInstrumentFile, int iInstrumentNr, bool bInstrumentNames )
914  {  {
915            const QFileInfo fi(sInstrumentFile);
916            if (!fi.exists())
917                    return noInstrumentName();
918    
919          QString sInstrumentName;          QString sInstrumentName;
920    
921          if (isDlsInstrumentFile(sInstrumentFile)) {  #ifdef CONFIG_LIBGIG
922          #ifdef CONFIG_LIBGIG          if (bInstrumentNames) {
923                  if (bInstrumentNames) {                  if (isDlsInstrumentFile(sInstrumentFile)) {
924                          RIFF::File *pRiff                          RIFF::File *pRiff
925                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());
926                          gig::File *pGig = new gig::File(pRiff);                          gig::File *pGig = new gig::File(pRiff);
927                  #if HAVE_LIBGIG_SETAUTOLOAD                  #ifdef CONFIG_LIBGIG_SETAUTOLOAD
928                          // prevent sleepy response time on large .gig files                          // prevent sleepy response time on large .gig files
929                          pGig->SetAutoLoad(false);                          pGig->SetAutoLoad(false);
930                  #endif                  #endif
# Line 895  QString Channel::getInstrumentName( cons Line 941  QString Channel::getInstrumentName( cons
941                          delete pGig;                          delete pGig;
942                          delete pRiff;                          delete pRiff;
943                  }                  }
944            #ifdef CONFIG_LIBGIG_SF2
945                    else
946                    if (isSf2InstrumentFile(sInstrumentFile)) {
947                            RIFF::File *pRiff
948                                    = new RIFF::File(sInstrumentFile.toUtf8().constData());
949                            sf2::File *pSf2 = new sf2::File(pRiff);
950                            sf2::Preset *pPreset = pSf2->GetPreset(iInstrumentNr);
951                            if (pPreset)
952                                    sInstrumentName = pPreset->Name.c_str();
953                            delete pSf2;
954                            delete pRiff;
955                    }
956          #endif          #endif
957          }          }
958    #endif
959    
960          if (sInstrumentName.isEmpty()) {          if (sInstrumentName.isEmpty()) {
961                  QFileInfo fi(sInstrumentFile);                  sInstrumentName  = fi.fileName();
962                  if (fi.exists()) {                  sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
                         sInstrumentName  = fi.fileName();  
                         sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";  
                 }  
                 else sInstrumentName = noInstrumentName();  
963          }          }
964    
965          return sInstrumentName;          return sInstrumentName;
# Line 932  QString Channel::loadingInstrument (void Line 987  QString Channel::loadingInstrument (void
987  //                                 (used for QTableView)  //                                 (used for QTableView)
988    
989  ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent )  ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent )
990          : QAbstractTableModel(pParent), m_pDevice(NULL)          : QAbstractTableModel(pParent), m_pDevice(nullptr)
991  {  {
992  }  }
993    
# Line 1021  void ChannelRoutingModel::refresh ( Devi Line 1076  void ChannelRoutingModel::refresh ( Devi
1076          m_pDevice = pDevice;          m_pDevice = pDevice;
1077          m_routing = routing;          m_routing = routing;
1078          // inform the outer world (QTableView) that our data changed          // inform the outer world (QTableView) that our data changed
1079  #if QT_VERSION < 0x050000  #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1080          QAbstractTableModel::reset();          QAbstractTableModel::reset();
1081  #else  #else
1082          QAbstractTableModel::beginResetModel();          QAbstractTableModel::beginResetModel();
# Line 1044  QWidget* ChannelRoutingDelegate::createE Line 1099  QWidget* ChannelRoutingDelegate::createE
1099          const QStyleOptionViewItem & option, const QModelIndex& index ) const          const QStyleOptionViewItem & option, const QModelIndex& index ) const
1100  {  {
1101          if (!index.isValid())          if (!index.isValid())
1102                  return NULL;                  return nullptr;
1103    
1104          if (index.column() != 0)          if (index.column() != 0)
1105                  return NULL;                  return nullptr;
1106    
1107          ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();          ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1108    
# Line 1055  QWidget* ChannelRoutingDelegate::createE Line 1110  QWidget* ChannelRoutingDelegate::createE
1110          pComboBox->addItems(item.options);          pComboBox->addItems(item.options);
1111          pComboBox->setCurrentIndex(item.selection);          pComboBox->setCurrentIndex(item.selection);
1112          pComboBox->setEnabled(true);          pComboBox->setEnabled(true);
1113            pComboBox->setEditable(true);
1114          pComboBox->setGeometry(option.rect);          pComboBox->setGeometry(option.rect);
1115          return pComboBox;          return pComboBox;
1116  }  }

Legend:
Removed from v.2387  
changed lines
  Added in v.3555

  ViewVC Help
Powered by ViewVC