/[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 2108 by capela, Thu Jul 15 08:03:32 2010 UTC revision 3849 by capela, Thu Jan 7 16:18:02 2021 UTC
# Line 1  Line 1 
1  // qsamplerChannel.cpp  // qsamplerChannel.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2010, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2021, 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 31  Line 31 
31  #include <QComboBox>  #include <QComboBox>
32    
33  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
34    #pragma GCC diagnostic push
35    #pragma GCC diagnostic ignored "-Wunused-parameter"
36  #include "gig.h"  #include "gig.h"
37    #ifdef CONFIG_LIBGIG_SF2
38    #pragma GCC diagnostic ignored "-Wunused-variable"
39    #include "SF.h"
40    #endif
41    #pragma GCC diagnostic pop
42  #endif  #endif
43    
44  namespace QSampler {  namespace QSampler {
45    
46  #define QSAMPLER_INSTRUMENT_MAX 100  #define QSAMPLER_INSTRUMENT_MAX 128
47    
48  #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))  #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))
49    
# Line 77  Channel::~Channel (void) Line 84  Channel::~Channel (void)
84  bool Channel::addChannel (void)  bool Channel::addChannel (void)
85  {  {
86          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
87          if (pMainForm == NULL)          if (pMainForm == nullptr)
88                  return false;                  return false;
89          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
90                  return false;                  return false;
91    
92          // Are we a new channel?          // Are we a new channel?
# Line 102  bool Channel::addChannel (void) Line 109  bool Channel::addChannel (void)
109  bool Channel::removeChannel (void)  bool Channel::removeChannel (void)
110  {  {
111          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
112          if (pMainForm == NULL)          if (pMainForm == nullptr)
113                  return false;                  return false;
114          if (pMainForm->client() == NULL)          if (pMainForm->client() == nullptr)
115                  return false;                  return false;
116    
117          // Are we an existing channel?          // Are we an existing channel?
# Line 152  const QString& Channel::engineName (void Line 159  const QString& Channel::engineName (void
159  bool Channel::loadEngine ( const QString& sEngineName )  bool Channel::loadEngine ( const QString& sEngineName )
160  {  {
161          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
162          if (pMainForm == NULL)          if (pMainForm == nullptr)
163                  return false;                  return false;
164          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
165                  return false;                  return false;
166          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
167                  return true;                  return true;
# Line 200  int Channel::instrumentStatus (void) con Line 207  int Channel::instrumentStatus (void) con
207  bool Channel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool Channel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
208  {  {
209          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
210          if (pMainForm == NULL)          if (pMainForm == nullptr)
211                  return false;                  return false;
212          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
213                  return false;                  return false;
214          if (!QFileInfo(sInstrumentFile).exists())          if (!QFileInfo(sInstrumentFile).exists())
215                  return false;                  return false;
# Line 234  bool Channel::setInstrument ( const QStr Line 241  bool Channel::setInstrument ( const QStr
241          m_sInstrumentFile = sInstrumentFile;          m_sInstrumentFile = sInstrumentFile;
242          m_iInstrumentNr = iInstrumentNr;          m_iInstrumentNr = iInstrumentNr;
243  #ifdef CONFIG_INSTRUMENT_NAME  #ifdef CONFIG_INSTRUMENT_NAME
244          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...
245  #else  #else
246          m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);          m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);
247  #endif  #endif
# Line 253  const QString& Channel::midiDriver (void Line 260  const QString& Channel::midiDriver (void
260  bool Channel::setMidiDriver ( const QString& sMidiDriver )  bool Channel::setMidiDriver ( const QString& sMidiDriver )
261  {  {
262          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
263          if (pMainForm == NULL)          if (pMainForm == nullptr)
264                  return false;                  return false;
265          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
266                  return false;                  return false;
267          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
268                  return true;                  return true;
# Line 282  int Channel::midiDevice (void) const Line 289  int Channel::midiDevice (void) const
289  bool Channel::setMidiDevice ( int iMidiDevice )  bool Channel::setMidiDevice ( int iMidiDevice )
290  {  {
291          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
292          if (pMainForm == NULL)          if (pMainForm == nullptr)
293                  return false;                  return false;
294          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
295                  return false;                  return false;
296          if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)          if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)
297                  return true;                  return true;
# Line 310  int Channel::midiPort (void) const Line 317  int Channel::midiPort (void) const
317  bool Channel::setMidiPort ( int iMidiPort )  bool Channel::setMidiPort ( int iMidiPort )
318  {  {
319          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
320          if (pMainForm == NULL)          if (pMainForm == nullptr)
321                  return false;                  return false;
322          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
323                  return false;                  return false;
324          if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)          if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)
325                  return true;                  return true;
# Line 338  int Channel::midiChannel (void) const Line 345  int Channel::midiChannel (void) const
345  bool Channel::setMidiChannel ( int iMidiChannel )  bool Channel::setMidiChannel ( int iMidiChannel )
346  {  {
347          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
348          if (pMainForm == NULL)          if (pMainForm == nullptr)
349                  return false;                  return false;
350          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
351                  return false;                  return false;
352          if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)          if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)
353                  return true;                  return true;
# Line 366  int Channel::midiMap (void) const Line 373  int Channel::midiMap (void) const
373  bool Channel::setMidiMap ( int iMidiMap )  bool Channel::setMidiMap ( int iMidiMap )
374  {  {
375          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
376          if (pMainForm == NULL)          if (pMainForm == nullptr)
377                  return false;                  return false;
378          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
379                  return false;                  return false;
380          if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap)          if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap)
381                  return true;                  return true;
# Line 394  int Channel::audioDevice (void) const Line 401  int Channel::audioDevice (void) const
401  bool Channel::setAudioDevice ( int iAudioDevice )  bool Channel::setAudioDevice ( int iAudioDevice )
402  {  {
403          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
404          if (pMainForm == NULL)          if (pMainForm == nullptr)
405                  return false;                  return false;
406          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
407                  return false;                  return false;
408          if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)          if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)
409                  return true;                  return true;
# Line 422  const QString& Channel::audioDriver (voi Line 429  const QString& Channel::audioDriver (voi
429  bool Channel::setAudioDriver ( const QString& sAudioDriver )  bool Channel::setAudioDriver ( const QString& sAudioDriver )
430  {  {
431          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
432          if (pMainForm == NULL)          if (pMainForm == nullptr)
433                  return false;                  return false;
434          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
435                  return false;                  return false;
436          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
437                  return true;                  return true;
# Line 451  float Channel::volume (void) const Line 458  float Channel::volume (void) const
458  bool Channel::setVolume ( float fVolume )  bool Channel::setVolume ( float fVolume )
459  {  {
460          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
461          if (pMainForm == NULL)          if (pMainForm == nullptr)
462                  return false;                  return false;
463          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
464                  return false;                  return false;
465          if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)          if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)
466                  return true;                  return true;
# Line 479  bool Channel::channelMute (void) const Line 486  bool Channel::channelMute (void) const
486  bool Channel::setChannelMute ( bool bMute )  bool Channel::setChannelMute ( bool bMute )
487  {  {
488          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
489          if (pMainForm == NULL)          if (pMainForm == nullptr)
490                  return false;                  return false;
491          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
492                  return false;                  return false;
493          if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))          if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))
494                  return true;                  return true;
# Line 509  bool Channel::channelSolo (void) const Line 516  bool Channel::channelSolo (void) const
516  bool Channel::setChannelSolo ( bool bSolo )  bool Channel::setChannelSolo ( bool bSolo )
517  {  {
518          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
519          if (pMainForm == NULL)          if (pMainForm == nullptr)
520                  return false;                  return false;
521          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
522                  return false;                  return false;
523          if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))          if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))
524                  return true;                  return true;
# Line 539  int Channel::audioChannel ( int iAudioOu Line 546  int Channel::audioChannel ( int iAudioOu
546  bool Channel::setAudioChannel ( int iAudioOut, int iAudioIn )  bool Channel::setAudioChannel ( int iAudioOut, int iAudioIn )
547  {  {
548          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
549          if (pMainForm == NULL)          if (pMainForm == nullptr)
550                  return false;                  return false;
551          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
552                  return false;                  return false;
553          if (m_iInstrumentStatus == 100 &&          if (m_iInstrumentStatus == 100 &&
554                          m_audioRouting[iAudioOut] == iAudioIn)                          m_audioRouting[iAudioOut] == iAudioIn)
# Line 581  void Channel::updateInstrumentName (void Line 588  void Channel::updateInstrumentName (void
588  bool Channel::updateChannelInfo (void)  bool Channel::updateChannelInfo (void)
589  {  {
590          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
591          if (pMainForm == NULL)          if (pMainForm == nullptr)
592                  return false;                  return false;
593          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
594                  return false;                  return false;
595    
596          // Read channel information.          // Read channel information.
597          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);
598          if (pChannelInfo == NULL) {          if (pChannelInfo == nullptr) {
599                  appendMessagesClient("lscp_get_channel_info");                  appendMessagesClient("lscp_get_channel_info");
600                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
601                  return false;                  return false;
# Line 629  bool Channel::updateChannelInfo (void) Line 636  bool Channel::updateChannelInfo (void)
636  #endif  #endif
637          // Some sanity checks.          // Some sanity checks.
638          if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())          if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())
639                  m_sEngineName = QString::null;                  m_sEngineName.clear();
640          if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) {          if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) {
641                  m_sInstrumentFile = QString::null;                  m_sInstrumentFile.clear();
642                  m_sInstrumentName = QString::null;                  m_sInstrumentName.clear();
643          }          }
644    
645          // Time for device info grabbing...          // Time for device info grabbing...
# Line 640  bool Channel::updateChannelInfo (void) Line 647  bool Channel::updateChannelInfo (void)
647          const QString sNone = QObject::tr("(none)");          const QString sNone = QObject::tr("(none)");
648          // Audio device driver type.          // Audio device driver type.
649          pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice);          pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice);
650          if (pDeviceInfo == NULL) {          if (pDeviceInfo == nullptr) {
651                  appendMessagesClient("lscp_get_audio_device_info");                  appendMessagesClient("lscp_get_audio_device_info");
652                  m_sAudioDriver = sNone;                  m_sAudioDriver = sNone;
653          } else {          } else {
# Line 648  bool Channel::updateChannelInfo (void) Line 655  bool Channel::updateChannelInfo (void)
655          }          }
656          // MIDI device driver type.          // MIDI device driver type.
657          pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice);          pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice);
658          if (pDeviceInfo == NULL) {          if (pDeviceInfo == nullptr) {
659                  appendMessagesClient("lscp_get_midi_device_info");                  appendMessagesClient("lscp_get_midi_device_info");
660                  m_sMidiDriver = sNone;                  m_sMidiDriver = sNone;
661          } else {          } else {
# Line 675  bool Channel::updateChannelInfo (void) Line 682  bool Channel::updateChannelInfo (void)
682  bool Channel::channelReset (void)  bool Channel::channelReset (void)
683  {  {
684          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
685          if (pMainForm == NULL)          if (pMainForm == nullptr)
686                  return false;                  return false;
687          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
688                  return false;                  return false;
689    
690          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 704  bool Channel::editChannel (void)
704  #ifdef CONFIG_EDIT_INSTRUMENT  #ifdef CONFIG_EDIT_INSTRUMENT
705    
706          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
707          if (pMainForm == NULL)          if (pMainForm == nullptr)
708                  return false;                  return false;
709          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == nullptr || m_iChannelID < 0)
710                  return false;                  return false;
711    
712          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 745  bool Channel::editChannel (void)
745  bool Channel::channelSetup ( QWidget *pParent )  bool Channel::channelSetup ( QWidget *pParent )
746  {  {
747          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
748          if (pMainForm == NULL)          if (pMainForm == nullptr)
749                  return false;                  return false;
750    
751          bool bResult = false;          bool bResult = false;
# Line 757  bool Channel::channelSetup ( QWidget *pP Line 764  bool Channel::channelSetup ( QWidget *pP
764    
765    
766  // Redirected messages output methods.  // Redirected messages output methods.
767  void Channel::appendMessages( const QString& s ) const  void Channel::appendMessages ( const QString& sText ) const
768  {  {
769          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
770          if (pMainForm)          if (pMainForm)
771                  pMainForm->appendMessages(channelName() + ' ' + s);                  pMainForm->appendMessages(channelName() + ' ' + sText);
772  }  }
773    
774  void Channel::appendMessagesColor( const QString& s,  void Channel::appendMessagesColor (
775          const QString& c ) const          const QString& sText, const QColor& rgb ) const
776  {  {
777          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
778          if (pMainForm)          if (pMainForm)
779                  pMainForm->appendMessagesColor(channelName() + ' ' + s, c);                  pMainForm->appendMessagesColor(channelName() + ' ' + sText, rgb);
780  }  }
781    
782  void Channel::appendMessagesText( const QString& s ) const  void Channel::appendMessagesText ( const QString& sText ) const
783  {  {
784          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
785          if (pMainForm)          if (pMainForm)
786                  pMainForm->appendMessagesText(channelName() + ' ' + s);                  pMainForm->appendMessagesText(channelName() + ' ' + sText);
787  }  }
788    
789  void Channel::appendMessagesError( const QString& s ) const  void Channel::appendMessagesError ( const QString& sText ) const
790  {  {
791          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
792          if (pMainForm)          if (pMainForm)
793                  pMainForm->appendMessagesError(channelName() + "\n\n" + s);                  pMainForm->appendMessagesError(channelName() + "\n\n" + sText);
794  }  }
795    
796  void Channel::appendMessagesClient( const QString& s ) const  void Channel::appendMessagesClient ( const QString& sText ) const
797  {  {
798          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
799          if (pMainForm)          if (pMainForm)
800                  pMainForm->appendMessagesClient(channelName() + ' ' + s);                  pMainForm->appendMessagesClient(channelName() + ' ' + sText);
801  }  }
802    
803    
804  // Context menu event handler.  // Context menu event handler.
805  void Channel::contextMenuEvent( QContextMenuEvent *pEvent )  void Channel::contextMenuEvent ( QContextMenuEvent *pEvent )
806  {  {
807          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
808          if (pMainForm)          if (pMainForm)
# Line 822  bool Channel::isDlsInstrumentFile ( cons Line 829  bool Channel::isDlsInstrumentFile ( cons
829  }  }
830    
831    
832    // FIXME: Check whether a given file is an instrument file (SF2 only).
833    bool Channel::isSf2InstrumentFile ( const QString& sInstrumentFile )
834    {
835            bool bResult = false;
836    
837            QFile file(sInstrumentFile);
838            if (file.open(QIODevice::ReadOnly)) {
839                    char achHeader[12];
840                    if (file.read(achHeader, 12) > 0) {
841                            bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0
842                                            && ::memcmp(&achHeader[8], "sfbk", 4) == 0);
843                    }
844                    file.close();
845            }
846    
847            return bResult;
848    }
849    
850    
851  // Retrieve the instrument list of a instrument file (.gig).  // Retrieve the instrument list of a instrument file (.gig).
852  QStringList Channel::getInstrumentList( const QString& sInstrumentFile,  QStringList Channel::getInstrumentList (
853          bool bInstrumentNames )          const QString& sInstrumentFile, bool bInstrumentNames )
854  {  {
855          QStringList instlist;          QStringList instlist;
856    
857          if (isDlsInstrumentFile(sInstrumentFile)) {          const QFileInfo fi(sInstrumentFile);
858          #ifdef CONFIG_LIBGIG          if (!fi.exists()) {
859                  if (bInstrumentNames) {                  instlist.append(noInstrumentName());
860                    return instlist;
861            }
862    
863    #ifdef CONFIG_LIBGIG
864            if (bInstrumentNames) {
865                    if (isDlsInstrumentFile(sInstrumentFile)) {
866                          RIFF::File *pRiff                          RIFF::File *pRiff
867                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());
868                          gig::File  *pGig  = new gig::File(pRiff);                          gig::File *pGig = new gig::File(pRiff);
869                  #if HAVE_LIBGIG_SETAUTOLOAD                  #ifdef CONFIG_LIBGIG_SETAUTOLOAD
870                          // prevent sleepy response time on large .gig files                          // prevent sleepy response time on large .gig files
871                          pGig->SetAutoLoad(false);                          pGig->SetAutoLoad(false);
872                  #endif                  #endif
# Line 846  QStringList Channel::getInstrumentList( Line 878  QStringList Channel::getInstrumentList(
878                          delete pGig;                          delete pGig;
879                          delete pRiff;                          delete pRiff;
880                  }                  }
881            #ifdef CONFIG_LIBGIG_SF2
882                    else
883                    if (isSf2InstrumentFile(sInstrumentFile)) {
884                            RIFF::File *pRiff
885                                    = new RIFF::File(sInstrumentFile.toUtf8().constData());
886                            sf2::File *pSf2 = new sf2::File(pRiff);
887                            const int iPresetCount = pSf2->GetPresetCount();
888                            for (int iIndex = 0; iIndex < iPresetCount; ++iIndex) {
889                                    sf2::Preset *pPreset = pSf2->GetPreset(iIndex);
890                                    if (pPreset) {
891                                            instlist.append(pPreset->Name.c_str());
892                                    } else {
893                                            instlist.append(fi.fileName()
894                                                    + " [" + QString::number(iIndex) + "]");
895                                    }
896                            }
897                            delete pSf2;
898                            delete pRiff;
899                    }
900          #endif          #endif
901          }          }
902    #endif
903    
904          if (instlist.isEmpty()) {          if (instlist.isEmpty()) {
905                  QFileInfo fi(sInstrumentFile);                  for (int iIndex = 0; iIndex < QSAMPLER_INSTRUMENT_MAX; ++iIndex) {
906                  if (fi.exists()) {                          instlist.append(fi.fileName()
907                          QString sInstrumentName = fi.fileName();                                  + " [" + QString::number(iIndex) + "]");
                         int iInstrumentNr = 0;  
                         while (iInstrumentNr < QSAMPLER_INSTRUMENT_MAX) {  
                                 instlist.append(sInstrumentName  
                                         + " [" + QString::number(++iInstrumentNr) + "]");  
                         }  
908                  }                  }
                 else instlist.append(noInstrumentName());  
909          }          }
910    
911          return instlist;          return instlist;
# Line 867  QStringList Channel::getInstrumentList( Line 913  QStringList Channel::getInstrumentList(
913    
914    
915  // 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.
916  QString Channel::getInstrumentName( const QString& sInstrumentFile,  QString Channel::getInstrumentName (
917          int iInstrumentNr, bool bInstrumentNames )          const QString& sInstrumentFile, int iInstrumentNr, bool bInstrumentNames )
918  {  {
919            const QFileInfo fi(sInstrumentFile);
920            if (!fi.exists())
921                    return noInstrumentName();
922    
923          QString sInstrumentName;          QString sInstrumentName;
924    
925          if (isDlsInstrumentFile(sInstrumentFile)) {  #ifdef CONFIG_LIBGIG
926          #ifdef CONFIG_LIBGIG          if (bInstrumentNames) {
927                  if (bInstrumentNames) {                  if (isDlsInstrumentFile(sInstrumentFile)) {
928                          RIFF::File *pRiff                          RIFF::File *pRiff
929                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());
930                          gig::File *pGig = new gig::File(pRiff);                          gig::File *pGig = new gig::File(pRiff);
931                  #if HAVE_LIBGIG_SETAUTOLOAD                  #ifdef CONFIG_LIBGIG_SETAUTOLOAD
932                          // prevent sleepy response time on large .gig files                          // prevent sleepy response time on large .gig files
933                          pGig->SetAutoLoad(false);                          pGig->SetAutoLoad(false);
934                  #endif                  #endif
# Line 895  QString Channel::getInstrumentName( cons Line 945  QString Channel::getInstrumentName( cons
945                          delete pGig;                          delete pGig;
946                          delete pRiff;                          delete pRiff;
947                  }                  }
948            #ifdef CONFIG_LIBGIG_SF2
949                    else
950                    if (isSf2InstrumentFile(sInstrumentFile)) {
951                            RIFF::File *pRiff
952                                    = new RIFF::File(sInstrumentFile.toUtf8().constData());
953                            sf2::File *pSf2 = new sf2::File(pRiff);
954                            sf2::Preset *pPreset = pSf2->GetPreset(iInstrumentNr);
955                            if (pPreset)
956                                    sInstrumentName = pPreset->Name.c_str();
957                            delete pSf2;
958                            delete pRiff;
959                    }
960          #endif          #endif
961          }          }
962    #endif
963    
964          if (sInstrumentName.isEmpty()) {          if (sInstrumentName.isEmpty()) {
965                  QFileInfo fi(sInstrumentFile);                  sInstrumentName  = fi.fileName();
966                  if (fi.exists()) {                  sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
                         sInstrumentName  = fi.fileName();  
                         sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";  
                 }  
                 else sInstrumentName = noInstrumentName();  
967          }          }
968    
969          return sInstrumentName;          return sInstrumentName;
# Line 932  QString Channel::loadingInstrument (void Line 991  QString Channel::loadingInstrument (void
991  //                                 (used for QTableView)  //                                 (used for QTableView)
992    
993  ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent )  ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent )
994          : QAbstractTableModel(pParent), m_pDevice(NULL)          : QAbstractTableModel(pParent), m_pDevice(nullptr)
995  {  {
996  }  }
997    
# Line 1021  void ChannelRoutingModel::refresh ( Devi Line 1080  void ChannelRoutingModel::refresh ( Devi
1080          m_pDevice = pDevice;          m_pDevice = pDevice;
1081          m_routing = routing;          m_routing = routing;
1082          // inform the outer world (QTableView) that our data changed          // inform the outer world (QTableView) that our data changed
1083    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1084          QAbstractTableModel::reset();          QAbstractTableModel::reset();
1085    #else
1086            QAbstractTableModel::beginResetModel();
1087            QAbstractTableModel::endResetModel();
1088    #endif
1089  }  }
1090    
1091    
# Line 1039  QWidget* ChannelRoutingDelegate::createE Line 1103  QWidget* ChannelRoutingDelegate::createE
1103          const QStyleOptionViewItem & option, const QModelIndex& index ) const          const QStyleOptionViewItem & option, const QModelIndex& index ) const
1104  {  {
1105          if (!index.isValid())          if (!index.isValid())
1106                  return NULL;                  return nullptr;
1107    
1108          if (index.column() != 0)          if (index.column() != 0)
1109                  return NULL;                  return nullptr;
1110    
1111          ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();          ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1112    
# Line 1050  QWidget* ChannelRoutingDelegate::createE Line 1114  QWidget* ChannelRoutingDelegate::createE
1114          pComboBox->addItems(item.options);          pComboBox->addItems(item.options);
1115          pComboBox->setCurrentIndex(item.selection);          pComboBox->setCurrentIndex(item.selection);
1116          pComboBox->setEnabled(true);          pComboBox->setEnabled(true);
1117            pComboBox->setEditable(true);
1118          pComboBox->setGeometry(option.rect);          pComboBox->setGeometry(option.rect);
1119          return pComboBox;          return pComboBox;
1120  }  }

Legend:
Removed from v.2108  
changed lines
  Added in v.3849

  ViewVC Help
Powered by ViewVC