/[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 759 by capela, Sun Aug 28 11:44:10 2005 UTC revision 3855 by capela, Thu Feb 4 10:09:42 2021 UTC
# Line 1  Line 1 
1  // qsamplerChannel.cpp  // qsamplerChannel.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2003-2005, 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
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 13  Line 14 
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License along
18     along with this program; if not, write to the Free Software     with this program; if not, write to the Free Software Foundation, Inc.,
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
24  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
25    #include "qsamplerUtilities.h"
26    
27  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
28  #include "qsamplerChannelForm.h"  #include "qsamplerChannelForm.h"
29    
30  #include <qfileinfo.h>  #include <QFileInfo>
31  #include <qcombobox.h>  #include <QComboBox>
32    
33  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
34    #if defined(Q_CC_GNU) || defined(Q_CC_MINGW)
35    #pragma GCC diagnostic push
36    #pragma GCC diagnostic ignored "-Wunused-parameter"
37    #endif
38  #include "gig.h"  #include "gig.h"
39    #ifdef CONFIG_LIBGIG_SF2
40    #pragma GCC diagnostic ignored "-Wunused-variable"
41    #include "SF.h"
42    #endif
43    #if defined(Q_CC_GNU) || defined(Q_CC_MINGW)
44    #pragma GCC diagnostic pop
45    #endif
46  #endif  #endif
47    
48  #define QSAMPLER_INSTRUMENT_MAX 8  namespace QSampler {
49    
50    #define QSAMPLER_INSTRUMENT_MAX 128
51    
52    #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))
53    
54    
55  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
56  // qsamplerChannel - Sampler channel structure.  // QSampler::Channel - Sampler channel structure.
57  //  //
58    
59  // Constructor.  // Constructor.
60  qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )  Channel::Channel ( int iChannelID )
61  {  {
         m_pMainForm  = pMainForm;  
62          m_iChannelID = iChannelID;          m_iChannelID = iChannelID;
63    
64  //  m_sEngineName       = noEngineName();  //  m_sEngineName       = noEngineName();
# Line 54  qsamplerChannel::qsamplerChannel ( qsamp Line 70  qsamplerChannel::qsamplerChannel ( qsamp
70          m_iMidiDevice       = -1;          m_iMidiDevice       = -1;
71          m_iMidiPort         = -1;          m_iMidiPort         = -1;
72          m_iMidiChannel      = -1;          m_iMidiChannel      = -1;
73            m_iMidiMap          = -1;
74          m_sAudioDriver      = "ALSA";          m_sAudioDriver      = "ALSA";
75          m_iAudioDevice      = -1;          m_iAudioDevice      = -1;
76          m_fVolume           = 0.0;          m_fVolume           = 0.0f;
77          m_bMute             = false;          m_bMute             = false;
78          m_bSolo             = false;          m_bSolo             = false;
79  }  }
80    
81  // Default destructor.  // Default destructor.
82  qsamplerChannel::~qsamplerChannel (void)  Channel::~Channel (void)
83  {  {
84  }  }
85    
86    
 // Main application form accessor.  
 qsamplerMainForm *qsamplerChannel::mainForm(void) const  
 {  
         return m_pMainForm;  
 }  
   
   
 // The global options settings delegated property.  
 qsamplerOptions *qsamplerChannel::options (void) const  
 {  
         if (m_pMainForm == NULL)  
                 return NULL;  
   
         return m_pMainForm->options();  
 }  
   
   
 // The client descriptor delegated property.  
 lscp_client_t *qsamplerChannel::client (void) const  
 {  
         if (m_pMainForm == NULL)  
                 return NULL;  
   
         return m_pMainForm->client();  
 }  
   
   
87  // Create a new sampler channel, if not already.  // Create a new sampler channel, if not already.
88  bool qsamplerChannel::addChannel (void)  bool Channel::addChannel (void)
89  {  {
90          if (client() == NULL)          MainForm* pMainForm = MainForm::getInstance();
91            if (pMainForm == nullptr)
92                    return false;
93            if (pMainForm->client() == nullptr)
94                  return false;                  return false;
95    
96          // Are we a new channel?          // Are we a new channel?
97          if (m_iChannelID < 0) {          if (m_iChannelID < 0) {
98                  m_iChannelID = ::lscp_add_channel(client());                  m_iChannelID = ::lscp_add_channel(pMainForm->client());
99                  if (m_iChannelID < 0) {                  if (m_iChannelID < 0) {
100                          appendMessagesClient("lscp_add_channel");                          appendMessagesClient("lscp_add_channel");
101                          appendMessagesError(QObject::tr("Could not add channel.\n\nSorry."));                          appendMessagesError(
102                                    QObject::tr("Could not add channel.\n\nSorry."));
103                  }   // Otherwise it's created...                  }   // Otherwise it's created...
104                  else appendMessages(QObject::tr("added."));                  else appendMessages(QObject::tr("added."));
105          }          }
# Line 116  bool qsamplerChannel::addChannel (void) Line 110  bool qsamplerChannel::addChannel (void)
110    
111    
112  // Remove sampler channel.  // Remove sampler channel.
113  bool qsamplerChannel::removeChannel (void)  bool Channel::removeChannel (void)
114  {  {
115          if (client() == NULL)          MainForm *pMainForm = MainForm::getInstance();
116            if (pMainForm == nullptr)
117                    return false;
118            if (pMainForm->client() == nullptr)
119                  return false;                  return false;
120    
121          // Are we an existing channel?          // Are we an existing channel?
122          if (m_iChannelID >= 0) {          if (m_iChannelID >= 0) {
123                  if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) {                  if (::lscp_remove_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
124                          appendMessagesClient("lscp_remove_channel");                          appendMessagesClient("lscp_remove_channel");
125                          appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));                          appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));
126                  } else {                  } else {
# Line 139  bool qsamplerChannel::removeChannel (voi Line 136  bool qsamplerChannel::removeChannel (voi
136    
137    
138  // Channel-ID (aka Sammpler-Channel) accessors.  // Channel-ID (aka Sammpler-Channel) accessors.
139  int qsamplerChannel::channelID (void) const  int Channel::channelID (void) const
140  {  {
141          return m_iChannelID;          return m_iChannelID;
142  }  }
143    
144  void qsamplerChannel::setChannelID ( int iChannelID )  void Channel::setChannelID ( int iChannelID )
145  {  {
146          m_iChannelID = iChannelID;          m_iChannelID = iChannelID;
147  }  }
148    
149    
150  // Readable channel name.  // Readable channel name.
151  QString qsamplerChannel::channelName (void) const  QString Channel::channelName (void) const
152  {  {
153          return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID));          return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID));
154  }  }
155    
156    
157  // Engine name accessors.  // Engine name accessors.
158  const QString& qsamplerChannel::engineName (void) const  const QString& Channel::engineName (void) const
159  {  {
160          return m_sEngineName;          return m_sEngineName;
161  }  }
162    
163  bool qsamplerChannel::loadEngine ( const QString& sEngineName )  bool Channel::loadEngine ( const QString& sEngineName )
164  {  {
165          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
166            if (pMainForm == nullptr)
167                    return false;
168            if (pMainForm->client() == nullptr || m_iChannelID < 0)
169                  return false;                  return false;
170          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
171                  return true;                  return true;
172    
173          if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {          if (::lscp_load_engine(pMainForm->client(),
174                            sEngineName.toUtf8().constData(), m_iChannelID) != LSCP_OK) {
175                  appendMessagesClient("lscp_load_engine");                  appendMessagesClient("lscp_load_engine");
176                  return false;                  return false;
177          }          }
178    
179          appendMessages(QObject::tr("Engine: %1.").arg(sEngineName));          appendMessages(QObject::tr("Engine: %1.").arg(sEngineName));
180    
181          m_sEngineName = sEngineName;          m_sEngineName = sEngineName;
# Line 182  bool qsamplerChannel::loadEngine ( const Line 184  bool qsamplerChannel::loadEngine ( const
184    
185    
186  // Instrument filename accessor.  // Instrument filename accessor.
187  const QString& qsamplerChannel::instrumentFile (void) const  const QString& Channel::instrumentFile (void) const
188  {  {
189          return m_sInstrumentFile;          return m_sInstrumentFile;
190  }  }
191    
192  // Instrument index accessor.  // Instrument index accessor.
193  int qsamplerChannel::instrumentNr (void) const  int Channel::instrumentNr (void) const
194  {  {
195          return m_iInstrumentNr;          return m_iInstrumentNr;
196  }  }
197    
198  // Instrument name accessor.  // Instrument name accessor.
199  const QString& qsamplerChannel::instrumentName (void) const  const QString& Channel::instrumentName (void) const
200  {  {
201          return m_sInstrumentName;          return m_sInstrumentName;
202  }  }
203    
204  // Instrument status accessor.  // Instrument status accessor.
205  int qsamplerChannel::instrumentStatus (void) const  int Channel::instrumentStatus (void) const
206  {  {
207          return m_iInstrumentStatus;          return m_iInstrumentStatus;
208  }  }
209    
210  // Instrument file loader.  // Instrument file loader.
211  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool Channel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
212  {  {
213          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
214            if (pMainForm == nullptr)
215                    return false;
216            if (pMainForm->client() == nullptr || m_iChannelID < 0)
217                  return false;                  return false;
218          if (!isInstrumentFile(sInstrumentFile))          if (!QFileInfo(sInstrumentFile).exists())
219                  return false;                  return false;
220          if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)          if (m_iInstrumentStatus == 100
221                    && m_sInstrumentFile == sInstrumentFile
222                    && m_iInstrumentNr == iInstrumentNr)
223                  return true;                  return true;
224    
225          if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {          if (::lscp_load_instrument_non_modal(
226                            pMainForm->client(),
227                            qsamplerUtilities::lscpEscapePath(
228                                    sInstrumentFile).toUtf8().constData(),
229                            iInstrumentNr, m_iChannelID
230                    ) != LSCP_OK) {
231                  appendMessagesClient("lscp_load_instrument");                  appendMessagesClient("lscp_load_instrument");
232                  return false;                  return false;
233          }          }
# Line 228  bool qsamplerChannel::loadInstrument ( c Line 240  bool qsamplerChannel::loadInstrument ( c
240    
241    
242  // Special instrument file/name/number settler.  // Special instrument file/name/number settler.
243  bool qsamplerChannel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool Channel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
244  {  {
245          m_sInstrumentFile = sInstrumentFile;          m_sInstrumentFile = sInstrumentFile;
246          m_iInstrumentNr = iInstrumentNr;          m_iInstrumentNr = iInstrumentNr;
247  #ifdef CONFIG_INSTRUMENT_NAME  #ifdef CONFIG_INSTRUMENT_NAME
248          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...
249  #else  #else
250          m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);          m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);
251  #endif  #endif
# Line 244  bool qsamplerChannel::setInstrument ( co Line 256  bool qsamplerChannel::setInstrument ( co
256    
257    
258  // MIDI driver type accessors (DEPRECATED).  // MIDI driver type accessors (DEPRECATED).
259  const QString& qsamplerChannel::midiDriver (void) const  const QString& Channel::midiDriver (void) const
260  {  {
261          return m_sMidiDriver;          return m_sMidiDriver;
262  }  }
263    
264  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )  bool Channel::setMidiDriver ( const QString& sMidiDriver )
265  {  {
266          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
267            if (pMainForm == nullptr)
268                    return false;
269            if (pMainForm->client() == nullptr || m_iChannelID < 0)
270                  return false;                  return false;
271          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
272                  return true;                  return true;
273    
274          if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {          if (::lscp_set_channel_midi_type(pMainForm->client(),
275                            m_iChannelID, sMidiDriver.toUtf8().constData()) != LSCP_OK) {
276                  appendMessagesClient("lscp_set_channel_midi_type");                  appendMessagesClient("lscp_set_channel_midi_type");
277                  return false;                  return false;
278          }          }
# Line 269  bool qsamplerChannel::setMidiDriver ( co Line 285  bool qsamplerChannel::setMidiDriver ( co
285    
286    
287  // MIDI device accessors.  // MIDI device accessors.
288  int qsamplerChannel::midiDevice (void) const  int Channel::midiDevice (void) const
289  {  {
290          return m_iMidiDevice;          return m_iMidiDevice;
291  }  }
292    
293  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )  bool Channel::setMidiDevice ( int iMidiDevice )
294  {  {
295          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
296            if (pMainForm == nullptr)
297                    return false;
298            if (pMainForm->client() == nullptr || m_iChannelID < 0)
299                  return false;                  return false;
300          if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)          if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)
301                  return true;                  return true;
302    
303          if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {          if (::lscp_set_channel_midi_device(pMainForm->client(), m_iChannelID, iMidiDevice) != LSCP_OK) {
304                  appendMessagesClient("lscp_set_channel_midi_device");                  appendMessagesClient("lscp_set_channel_midi_device");
305                  return false;                  return false;
306          }          }
# Line 294  bool qsamplerChannel::setMidiDevice ( in Line 313  bool qsamplerChannel::setMidiDevice ( in
313    
314    
315  // MIDI port number accessor.  // MIDI port number accessor.
316  int qsamplerChannel::midiPort (void) const  int Channel::midiPort (void) const
317  {  {
318          return m_iMidiPort;          return m_iMidiPort;
319  }  }
320    
321  bool qsamplerChannel::setMidiPort ( int iMidiPort )  bool Channel::setMidiPort ( int iMidiPort )
322  {  {
323          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
324            if (pMainForm == nullptr)
325                    return false;
326            if (pMainForm->client() == nullptr || m_iChannelID < 0)
327                  return false;                  return false;
328          if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)          if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)
329                  return true;                  return true;
330    
331          if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {          if (::lscp_set_channel_midi_port(pMainForm->client(), m_iChannelID, iMidiPort) != LSCP_OK) {
332                  appendMessagesClient("lscp_set_channel_midi_port");                  appendMessagesClient("lscp_set_channel_midi_port");
333                  return false;                  return false;
334          }          }
# Line 319  bool qsamplerChannel::setMidiPort ( int Line 341  bool qsamplerChannel::setMidiPort ( int
341    
342    
343  // MIDI channel accessor.  // MIDI channel accessor.
344  int qsamplerChannel::midiChannel (void) const  int Channel::midiChannel (void) const
345  {  {
346          return m_iMidiChannel;          return m_iMidiChannel;
347  }  }
348    
349  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )  bool Channel::setMidiChannel ( int iMidiChannel )
350  {  {
351          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
352            if (pMainForm == nullptr)
353                    return false;
354            if (pMainForm->client() == nullptr || m_iChannelID < 0)
355                  return false;                  return false;
356          if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)          if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)
357                  return true;                  return true;
358    
359          if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {          if (::lscp_set_channel_midi_channel(pMainForm->client(), m_iChannelID, iMidiChannel) != LSCP_OK) {
360                  appendMessagesClient("lscp_set_channel_midi_channel");                  appendMessagesClient("lscp_set_channel_midi_channel");
361                  return false;                  return false;
362          }          }
# Line 343  bool qsamplerChannel::setMidiChannel ( i Line 368  bool qsamplerChannel::setMidiChannel ( i
368  }  }
369    
370    
371    // MIDI instrument map accessor.
372    int Channel::midiMap (void) const
373    {
374            return m_iMidiMap;
375    }
376    
377    bool Channel::setMidiMap ( int iMidiMap )
378    {
379            MainForm *pMainForm = MainForm::getInstance();
380            if (pMainForm == nullptr)
381                    return false;
382            if (pMainForm->client() == nullptr || m_iChannelID < 0)
383                    return false;
384            if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap)
385                    return true;
386    #ifdef CONFIG_MIDI_INSTRUMENT
387            if (::lscp_set_channel_midi_map(pMainForm->client(), m_iChannelID, iMidiMap) != LSCP_OK) {
388                    appendMessagesClient("lscp_set_channel_midi_map");
389                    return false;
390            }
391    #endif
392            appendMessages(QObject::tr("MIDI map: %1.").arg(iMidiMap));
393    
394            m_iMidiMap = iMidiMap;
395            return true;
396    }
397    
398    
399  // Audio device accessor.  // Audio device accessor.
400  int qsamplerChannel::audioDevice (void) const  int Channel::audioDevice (void) const
401  {  {
402          return m_iAudioDevice;          return m_iAudioDevice;
403  }  }
404    
405  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )  bool Channel::setAudioDevice ( int iAudioDevice )
406  {  {
407          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
408            if (pMainForm == nullptr)
409                    return false;
410            if (pMainForm->client() == nullptr || m_iChannelID < 0)
411                  return false;                  return false;
412          if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)          if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)
413                  return true;                  return true;
414    
415          if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {          if (::lscp_set_channel_audio_device(pMainForm->client(), m_iChannelID, iAudioDevice) != LSCP_OK) {
416                  appendMessagesClient("lscp_set_channel_audio_device");                  appendMessagesClient("lscp_set_channel_audio_device");
417                  return false;                  return false;
418          }          }
# Line 369  bool qsamplerChannel::setAudioDevice ( i Line 425  bool qsamplerChannel::setAudioDevice ( i
425    
426    
427  // Audio driver type accessors (DEPRECATED).  // Audio driver type accessors (DEPRECATED).
428  const QString& qsamplerChannel::audioDriver (void) const  const QString& Channel::audioDriver (void) const
429  {  {
430          return m_sAudioDriver;          return m_sAudioDriver;
431  }  }
432    
433  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )  bool Channel::setAudioDriver ( const QString& sAudioDriver )
434  {  {
435          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
436            if (pMainForm == nullptr)
437                    return false;
438            if (pMainForm->client() == nullptr || m_iChannelID < 0)
439                  return false;                  return false;
440          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
441                  return true;                  return true;
442    
443          if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {          if (::lscp_set_channel_audio_type(pMainForm->client(),
444                            m_iChannelID, sAudioDriver.toUtf8().constData()) != LSCP_OK) {
445                  appendMessagesClient("lscp_set_channel_audio_type");                  appendMessagesClient("lscp_set_channel_audio_type");
446                  return false;                  return false;
447          }          }
# Line 394  bool qsamplerChannel::setAudioDriver ( c Line 454  bool qsamplerChannel::setAudioDriver ( c
454    
455    
456  // Channel volume accessors.  // Channel volume accessors.
457  float qsamplerChannel::volume (void) const  float Channel::volume (void) const
458  {  {
459          return m_fVolume;          return m_fVolume;
460  }  }
461    
462  bool qsamplerChannel::setVolume ( float fVolume )  bool Channel::setVolume ( float fVolume )
463  {  {
464          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
465            if (pMainForm == nullptr)
466                    return false;
467            if (pMainForm->client() == nullptr || m_iChannelID < 0)
468                  return false;                  return false;
469          if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)          if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)
470                  return true;                  return true;
471    
472          if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {          if (::lscp_set_channel_volume(pMainForm->client(), m_iChannelID, fVolume) != LSCP_OK) {
473                  appendMessagesClient("lscp_set_channel_volume");                  appendMessagesClient("lscp_set_channel_volume");
474                  return false;                  return false;
475          }          }
# Line 419  bool qsamplerChannel::setVolume ( float Line 482  bool qsamplerChannel::setVolume ( float
482    
483    
484  // Sampler channel mute state.  // Sampler channel mute state.
485  bool qsamplerChannel::channelMute (void) const  bool Channel::channelMute (void) const
486  {  {
487          return m_bMute;          return m_bMute;
488  }  }
489    
490  bool qsamplerChannel::setChannelMute ( bool bMute )  bool Channel::setChannelMute ( bool bMute )
491  {  {
492          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
493            if (pMainForm == nullptr)
494                    return false;
495            if (pMainForm->client() == nullptr || m_iChannelID < 0)
496                  return false;                  return false;
497          if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))          if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))
498                  return true;                  return true;
499    
500  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
501          if (::lscp_set_channel_mute(client(), m_iChannelID, bMute) != LSCP_OK) {          if (::lscp_set_channel_mute(pMainForm->client(), m_iChannelID, bMute) != LSCP_OK) {
502                  appendMessagesClient("lscp_set_channel_mute");                  appendMessagesClient("lscp_set_channel_mute");
503                  return false;                  return false;
504          }          }
# Line 446  bool qsamplerChannel::setChannelMute ( b Line 512  bool qsamplerChannel::setChannelMute ( b
512    
513    
514  // Sampler channel solo state.  // Sampler channel solo state.
515  bool qsamplerChannel::channelSolo (void) const  bool Channel::channelSolo (void) const
516  {  {
517          return m_bSolo;          return m_bSolo;
518  }  }
519    
520  bool qsamplerChannel::setChannelSolo ( bool bSolo )  bool Channel::setChannelSolo ( bool bSolo )
521  {  {
522          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
523            if (pMainForm == nullptr)
524                    return false;
525            if (pMainForm->client() == nullptr || m_iChannelID < 0)
526                  return false;                  return false;
527          if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))          if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))
528                  return true;                  return true;
529    
530  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
531          if (::lscp_set_channel_solo(client(), m_iChannelID, bSolo) != LSCP_OK) {          if (::lscp_set_channel_solo(pMainForm->client(), m_iChannelID, bSolo) != LSCP_OK) {
532                  appendMessagesClient("lscp_set_channel_solo");                  appendMessagesClient("lscp_set_channel_solo");
533                  return false;                  return false;
534          }          }
# Line 473  bool qsamplerChannel::setChannelSolo ( b Line 542  bool qsamplerChannel::setChannelSolo ( b
542    
543    
544  // Audio routing accessors.  // Audio routing accessors.
545  int qsamplerChannel::audioChannel ( int iAudioOut ) const  int Channel::audioChannel ( int iAudioOut ) const
546  {  {
547          return m_audioRouting[iAudioOut];          return m_audioRouting[iAudioOut];
548  }  }
549    
550  bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )  bool Channel::setAudioChannel ( int iAudioOut, int iAudioIn )
551  {  {
552          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
553            if (pMainForm == nullptr)
554                    return false;
555            if (pMainForm->client() == nullptr || m_iChannelID < 0)
556                  return false;                  return false;
557          if (m_iInstrumentStatus == 100 &&          if (m_iInstrumentStatus == 100 &&
558                          m_audioRouting[iAudioOut] == iAudioIn)                          m_audioRouting[iAudioOut] == iAudioIn)
559                  return true;                  return true;
560    
561          if (::lscp_set_channel_audio_channel(client(),          if (::lscp_set_channel_audio_channel(pMainForm->client(),
562                          m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) {                          m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) {
563                  appendMessagesClient("lscp_set_channel_audio_channel");                  appendMessagesClient("lscp_set_channel_audio_channel");
564                  return false;                  return false;
# Line 500  bool qsamplerChannel::setAudioChannel ( Line 572  bool qsamplerChannel::setAudioChannel (
572  }  }
573    
574  // The audio routing map itself.  // The audio routing map itself.
575  const qsamplerChannelRoutingMap& qsamplerChannel::audioRouting (void) const  const ChannelRoutingMap& Channel::audioRouting (void) const
576  {  {
577          return m_audioRouting;          return m_audioRouting;
578  }  }
579    
580    
581  // Istrument name remapper.  // Istrument name remapper.
582  void qsamplerChannel::updateInstrumentName (void)  void Channel::updateInstrumentName (void)
583  {  {
584  #ifndef CONFIG_INSTRUMENT_NAME  #ifndef CONFIG_INSTRUMENT_NAME
585          m_sInstrumentName = getInstrumentName(m_sInstrumentFile,          m_sInstrumentName = getInstrumentName(m_sInstrumentFile,
# Line 517  void qsamplerChannel::updateInstrumentNa Line 589  void qsamplerChannel::updateInstrumentNa
589    
590    
591  // Update whole channel info state.  // Update whole channel info state.
592  bool qsamplerChannel::updateChannelInfo (void)  bool Channel::updateChannelInfo (void)
593  {  {
594          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
595            if (pMainForm == nullptr)
596                    return false;
597            if (pMainForm->client() == nullptr || m_iChannelID < 0)
598                  return false;                  return false;
599    
600          // Read channel information.          // Read channel information.
601          lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);          lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(pMainForm->client(), m_iChannelID);
602          if (pChannelInfo == NULL) {          if (pChannelInfo == nullptr) {
603                  appendMessagesClient("lscp_get_channel_info");                  appendMessagesClient("lscp_get_channel_info");
604                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
605                  return false;                  return false;
# Line 532  bool qsamplerChannel::updateChannelInfo Line 607  bool qsamplerChannel::updateChannelInfo
607    
608  #ifdef CONFIG_INSTRUMENT_NAME  #ifdef CONFIG_INSTRUMENT_NAME
609          // We got all actual instrument datum...          // We got all actual instrument datum...
610          m_sInstrumentFile = pChannelInfo->instrument_file;          m_sInstrumentFile =
611                    qsamplerUtilities::lscpEscapedPathToPosix(pChannelInfo->instrument_file);
612          m_iInstrumentNr   = pChannelInfo->instrument_nr;          m_iInstrumentNr   = pChannelInfo->instrument_nr;
613          m_sInstrumentName = pChannelInfo->instrument_name;          m_sInstrumentName =
614                    qsamplerUtilities::lscpEscapedTextToRaw(pChannelInfo->instrument_name);
615  #else  #else
616          // First, check if intrument name has changed,          // First, check if intrument name has changed,
617          // taking care that instrument name lookup might be expensive,          // taking care that instrument name lookup might be expensive,
# Line 552  bool qsamplerChannel::updateChannelInfo Line 629  bool qsamplerChannel::updateChannelInfo
629          m_iMidiDevice       = pChannelInfo->midi_device;          m_iMidiDevice       = pChannelInfo->midi_device;
630          m_iMidiPort         = pChannelInfo->midi_port;          m_iMidiPort         = pChannelInfo->midi_port;
631          m_iMidiChannel      = pChannelInfo->midi_channel;          m_iMidiChannel      = pChannelInfo->midi_channel;
632    #ifdef CONFIG_MIDI_INSTRUMENT
633            m_iMidiMap          = pChannelInfo->midi_map;
634    #endif
635          m_iAudioDevice      = pChannelInfo->audio_device;          m_iAudioDevice      = pChannelInfo->audio_device;
636          m_fVolume           = pChannelInfo->volume;          m_fVolume           = pChannelInfo->volume;
637  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
# Line 560  bool qsamplerChannel::updateChannelInfo Line 640  bool qsamplerChannel::updateChannelInfo
640  #endif  #endif
641          // Some sanity checks.          // Some sanity checks.
642          if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())          if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())
643                  m_sEngineName = QString::null;                  m_sEngineName.clear();
644          if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) {          if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) {
645                  m_sInstrumentFile = QString::null;                  m_sInstrumentFile.clear();
646                  m_sInstrumentName = QString::null;                  m_sInstrumentName.clear();
647          }          }
648    
649          // Time for device info grabbing...          // Time for device info grabbing...
650          lscp_device_info_t *pDeviceInfo;          lscp_device_info_t *pDeviceInfo;
651          const QString sNone = QObject::tr("(none)");          const QString sNone = QObject::tr("(none)");
652          // Audio device driver type.          // Audio device driver type.
653          pDeviceInfo = ::lscp_get_audio_device_info(client(), m_iAudioDevice);          pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice);
654          if (pDeviceInfo == NULL) {          if (pDeviceInfo == nullptr) {
655                  appendMessagesClient("lscp_get_audio_device_info");                  appendMessagesClient("lscp_get_audio_device_info");
656                  m_sAudioDriver = sNone;                  m_sAudioDriver = sNone;
657          } else {          } else {
658                  m_sAudioDriver = pDeviceInfo->driver;                  m_sAudioDriver = pDeviceInfo->driver;
659          }          }
660          // MIDI device driver type.          // MIDI device driver type.
661          pDeviceInfo = ::lscp_get_midi_device_info(client(), m_iMidiDevice);          pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice);
662          if (pDeviceInfo == NULL) {          if (pDeviceInfo == nullptr) {
663                  appendMessagesClient("lscp_get_midi_device_info");                  appendMessagesClient("lscp_get_midi_device_info");
664                  m_sMidiDriver = sNone;                  m_sMidiDriver = sNone;
665          } else {          } else {
# Line 588  bool qsamplerChannel::updateChannelInfo Line 668  bool qsamplerChannel::updateChannelInfo
668    
669          // Set the audio routing map.          // Set the audio routing map.
670          m_audioRouting.clear();          m_audioRouting.clear();
671          char **ppszRouting = pChannelInfo->audio_routing;  #ifdef CONFIG_AUDIO_ROUTING
672          for (int i = 0; ppszRouting && ppszRouting[i]; i++) {          int *piAudioRouting = pChannelInfo->audio_routing;
673                  m_audioRouting[i] = ::atoi(ppszRouting[i]);          for (int i = 0; piAudioRouting && piAudioRouting[i] >= 0; i++)
674          }                  m_audioRouting[i] = piAudioRouting[i];
675    #else
676            char **ppszAudioRouting = pChannelInfo->audio_routing;
677            for (int i = 0; ppszAudioRouting && ppszAudioRouting[i]; i++)
678                    m_audioRouting[i] = ::atoi(ppszAudioRouting[i]);
679    #endif
680    
681          return true;          return true;
682  }  }
683    
684    
685  // Reset channel method.  // Reset channel method.
686  bool qsamplerChannel::channelReset (void)  bool Channel::channelReset (void)
687  {  {
688          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
689            if (pMainForm == nullptr)
690                    return false;
691            if (pMainForm->client() == nullptr || m_iChannelID < 0)
692                  return false;                  return false;
693    
694          if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) {          if (::lscp_reset_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
695                  appendMessagesClient("lscp_reset_channel");                  appendMessagesClient("lscp_reset_channel");
696                  return false;                  return false;
697          }          }
# Line 614  bool qsamplerChannel::channelReset (void Line 702  bool qsamplerChannel::channelReset (void
702  }  }
703    
704    
705    // Spawn instrument editor method.
706    bool Channel::editChannel (void)
707    {
708    #ifdef CONFIG_EDIT_INSTRUMENT
709    
710            MainForm *pMainForm = MainForm::getInstance();
711            if (pMainForm == nullptr)
712                    return false;
713            if (pMainForm->client() == nullptr || m_iChannelID < 0)
714                    return false;
715    
716            if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID)
717                    != LSCP_OK) {
718                    appendMessagesClient("lscp_edit_channel_instrument");
719                    appendMessagesError(QObject::tr(
720                            "Could not launch an appropriate instrument editor "
721                            "for the given instrument!\n\n"
722                            "Make sure you have an appropriate "
723                            "instrument editor like 'gigedit' installed "
724                            "and that it placed its mandatory DLL file "
725                            "into the sampler's plugin directory.")
726                    );
727                    return false;
728            }
729    
730            appendMessages(QObject::tr("edit instrument."));
731    
732            return true;
733    
734    #else
735    
736            appendMessagesError(QObject::tr(
737                    "Sorry, QSampler was compiled for a version of liblscp "
738                    "which lacks this feature.\n\n"
739                    "You may want to update liblscp and recompile QSampler afterwards.")
740            );
741    
742            return false;
743    
744    #endif
745    }
746    
747    
748  // Channel setup dialog form.  // Channel setup dialog form.
749  bool qsamplerChannel::channelSetup ( QWidget *pParent )  bool Channel::channelSetup ( QWidget *pParent )
750  {  {
751            MainForm *pMainForm = MainForm::getInstance();
752            if (pMainForm == nullptr)
753                    return false;
754    
755          bool bResult = false;          bool bResult = false;
756    
757          appendMessages(QObject::tr("setup..."));          appendMessages(QObject::tr("setup..."));
758    
759          qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent);          ChannelForm *pChannelForm = new ChannelForm(pParent);
760          if (pChannelForm) {          if (pChannelForm) {
761                  pChannelForm->setup(this);                  pChannelForm->setup(this);
762                  bResult = pChannelForm->exec();                  bResult = pChannelForm->exec();
# Line 633  bool qsamplerChannel::channelSetup ( QWi Line 768  bool qsamplerChannel::channelSetup ( QWi
768    
769    
770  // Redirected messages output methods.  // Redirected messages output methods.
771  void qsamplerChannel::appendMessages( const QString& s ) const  void Channel::appendMessages ( const QString& sText ) const
772  {  {
773          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
774                  m_pMainForm->appendMessages(channelName() + ' ' + s);          if (pMainForm)
775                    pMainForm->appendMessages(channelName() + ' ' + sText);
776  }  }
777    
778  void qsamplerChannel::appendMessagesColor( const QString& s,  void Channel::appendMessagesColor (
779          const QString& c ) const          const QString& sText, const QColor& rgb ) const
780  {  {
781          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
782                  m_pMainForm->appendMessagesColor(channelName() + ' ' + s, c);          if (pMainForm)
783                    pMainForm->appendMessagesColor(channelName() + ' ' + sText, rgb);
784  }  }
785    
786  void qsamplerChannel::appendMessagesText( const QString& s ) const  void Channel::appendMessagesText ( const QString& sText ) const
787  {  {
788          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
789                  m_pMainForm->appendMessagesText(channelName() + ' ' + s);          if (pMainForm)
790                    pMainForm->appendMessagesText(channelName() + ' ' + sText);
791  }  }
792    
793  void qsamplerChannel::appendMessagesError( const QString& s ) const  void Channel::appendMessagesError ( const QString& sText ) const
794  {  {
795          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
796                  m_pMainForm->appendMessagesError(channelName() + "\n\n" + s);          if (pMainForm)
797                    pMainForm->appendMessagesError(channelName() + "\n\n" + sText);
798  }  }
799    
800  void qsamplerChannel::appendMessagesClient( const QString& s ) const  void Channel::appendMessagesClient ( const QString& sText ) const
801  {  {
802          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
803                  m_pMainForm->appendMessagesClient(channelName() + ' ' + s);          if (pMainForm)
804                    pMainForm->appendMessagesClient(channelName() + ' ' + sText);
805  }  }
806    
807    
808  // Context menu event handler.  // Context menu event handler.
809  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )  void Channel::contextMenuEvent ( QContextMenuEvent *pEvent )
810  {  {
811          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
812                  m_pMainForm->contextMenuEvent(pEvent);          if (pMainForm)
813                    pMainForm->contextMenuEvent(pEvent);
814  }  }
815    
816    
817  // FIXME: Check whether a given file is an instrument file.  // FIXME: Check whether a given file is an instrument file (DLS only).
818  bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile )  bool Channel::isDlsInstrumentFile ( const QString& sInstrumentFile )
819  {  {
820          bool bResult = false;          bool bResult = false;
821    
822          QFile file(sInstrumentFile);          QFile file(sInstrumentFile);
823          if (file.open(IO_ReadOnly)) {          if (file.open(QIODevice::ReadOnly)) {
824                  char achHeader[16];                  char achHeader[16];
825                  if (file.readBlock(achHeader, 16)) {                  if (file.read(achHeader, 16) > 0) {
826                          bResult = (::memcmp(&achHeader[0], "RIFF", 4)     == 0                          bResult = (::memcmp(&achHeader[0], "RIFF", 4)     == 0
827                                          && ::memcmp(&achHeader[8], "DLS LIST", 8) == 0);                                          && ::memcmp(&achHeader[8], "DLS LIST", 8) == 0);
828                  }                  }
# Line 692  bool qsamplerChannel::isInstrumentFile ( Line 833  bool qsamplerChannel::isInstrumentFile (
833  }  }
834    
835    
836    // FIXME: Check whether a given file is an instrument file (SF2 only).
837    bool Channel::isSf2InstrumentFile ( const QString& sInstrumentFile )
838    {
839            bool bResult = false;
840    
841            QFile file(sInstrumentFile);
842            if (file.open(QIODevice::ReadOnly)) {
843                    char achHeader[12];
844                    if (file.read(achHeader, 12) > 0) {
845                            bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0
846                                            && ::memcmp(&achHeader[8], "sfbk", 4) == 0);
847                    }
848                    file.close();
849            }
850    
851            return bResult;
852    }
853    
854    
855  // Retrieve the instrument list of a instrument file (.gig).  // Retrieve the instrument list of a instrument file (.gig).
856  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile,  QStringList Channel::getInstrumentList (
857          bool bInstrumentNames )          const QString& sInstrumentFile, bool bInstrumentNames )
858  {  {
         QString sInstrumentName = QFileInfo(sInstrumentFile).fileName();  
859          QStringList instlist;          QStringList instlist;
860    
861          if (isInstrumentFile(sInstrumentFile)) {          const QFileInfo fi(sInstrumentFile);
862            if (!fi.exists()) {
863                    instlist.append(noInstrumentName());
864                    return instlist;
865            }
866    
867  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
868                  if (bInstrumentNames) {          if (bInstrumentNames) {
869                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());                  if (isDlsInstrumentFile(sInstrumentFile)) {
870                          gig::File  *pGig  = new gig::File(pRiff);                          RIFF::File *pRiff
871                                    = new RIFF::File(sInstrumentFile.toUtf8().constData());
872                            gig::File *pGig = new gig::File(pRiff);
873                    #ifdef CONFIG_LIBGIG_SETAUTOLOAD
874                            // prevent sleepy response time on large .gig files
875                            pGig->SetAutoLoad(false);
876                    #endif
877                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
878                          while (pInstrument) {                          while (pInstrument) {
879                                  instlist.append((pInstrument->pInfo)->Name.c_str());                                  instlist.append((pInstrument->pInfo)->Name.c_str());
# Line 712  QStringList qsamplerChannel::getInstrume Line 882  QStringList qsamplerChannel::getInstrume
882                          delete pGig;                          delete pGig;
883                          delete pRiff;                          delete pRiff;
884                  }                  }
885            #ifdef CONFIG_LIBGIG_SF2
886                  else                  else
887                    if (isSf2InstrumentFile(sInstrumentFile)) {
888                            RIFF::File *pRiff
889                                    = new RIFF::File(sInstrumentFile.toUtf8().constData());
890                            sf2::File *pSf2 = new sf2::File(pRiff);
891                            const int iPresetCount = pSf2->GetPresetCount();
892                            for (int iIndex = 0; iIndex < iPresetCount; ++iIndex) {
893                                    sf2::Preset *pPreset = pSf2->GetPreset(iIndex);
894                                    if (pPreset) {
895                                            instlist.append(pPreset->Name.c_str());
896                                    } else {
897                                            instlist.append(fi.fileName()
898                                                    + " [" + QString::number(iIndex) + "]");
899                                    }
900                            }
901                            delete pSf2;
902                            delete pRiff;
903                    }
904            #endif
905            }
906  #endif  #endif
907                  for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)  
908                          instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");          if (instlist.isEmpty()) {
909                    for (int iIndex = 0; iIndex < QSAMPLER_INSTRUMENT_MAX; ++iIndex) {
910                            instlist.append(fi.fileName()
911                                    + " [" + QString::number(iIndex) + "]");
912                    }
913          }          }
         else instlist.append(noInstrumentName());  
914    
915          return instlist;          return instlist;
916  }  }
917    
918    
919  // 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.
920  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile,  QString Channel::getInstrumentName (
921          int iInstrumentNr, bool bInstrumentNames )          const QString& sInstrumentFile, int iInstrumentNr, bool bInstrumentNames )
922  {  {
923            const QFileInfo fi(sInstrumentFile);
924            if (!fi.exists())
925                    return noInstrumentName();
926    
927          QString sInstrumentName;          QString sInstrumentName;
928    
         if (isInstrumentFile(sInstrumentFile)) {  
                 sInstrumentName = QFileInfo(sInstrumentFile).fileName();  
929  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
930                  if (bInstrumentNames) {          if (bInstrumentNames) {
931                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());                  if (isDlsInstrumentFile(sInstrumentFile)) {
932                          gig::File  *pGig  = new gig::File(pRiff);                          RIFF::File *pRiff
933                                    = new RIFF::File(sInstrumentFile.toUtf8().constData());
934                            gig::File *pGig = new gig::File(pRiff);
935                    #ifdef CONFIG_LIBGIG_SETAUTOLOAD
936                            // prevent sleepy response time on large .gig files
937                            pGig->SetAutoLoad(false);
938                    #endif
939                          int iIndex = 0;                          int iIndex = 0;
940                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
941                          while (pInstrument) {                          while (pInstrument) {
# Line 748  QString qsamplerChannel::getInstrumentNa Line 949  QString qsamplerChannel::getInstrumentNa
949                          delete pGig;                          delete pGig;
950                          delete pRiff;                          delete pRiff;
951                  }                  }
952            #ifdef CONFIG_LIBGIG_SF2
953                  else                  else
954                    if (isSf2InstrumentFile(sInstrumentFile)) {
955                            RIFF::File *pRiff
956                                    = new RIFF::File(sInstrumentFile.toUtf8().constData());
957                            sf2::File *pSf2 = new sf2::File(pRiff);
958                            sf2::Preset *pPreset = pSf2->GetPreset(iInstrumentNr);
959                            if (pPreset)
960                                    sInstrumentName = pPreset->Name.c_str();
961                            delete pSf2;
962                            delete pRiff;
963                    }
964            #endif
965            }
966  #endif  #endif
967    
968            if (sInstrumentName.isEmpty()) {
969                    sInstrumentName  = fi.fileName();
970                  sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";                  sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
971          }          }
         else sInstrumentName = noInstrumentName();  
972    
973          return sInstrumentName;          return sInstrumentName;
974  }  }
975    
976    
977  // Common invalid name-helpers.  // Common invalid name-helpers.
978  QString qsamplerChannel::noEngineName (void)  QString Channel::noEngineName (void)
979  {  {
980          return QObject::tr("(No engine)");          return QObject::tr("(No engine)");
981  }  }
982    
983  QString qsamplerChannel::noInstrumentName (void)  QString Channel::noInstrumentName (void)
984  {  {
985          return QObject::tr("(No instrument)");          return QObject::tr("(No instrument)");
986  }  }
987    
988  QString qsamplerChannel::loadingInstrument (void) {  QString Channel::loadingInstrument (void) {
989          return QObject::tr("(Loading instrument...)");          return QObject::tr("(Loading instrument...)");
990  }  }
991    
992    
   
993  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
994  // qsamplerChannelRoutingTable - Channel routing table.  // QSampler::ChannelRoutingModel - data model for audio routing
995  //  //                                 (used for QTableView)
996    
997  // Constructor.  ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent )
998  qsamplerChannelRoutingTable::qsamplerChannelRoutingTable (          : QAbstractTableModel(pParent), m_pDevice(nullptr)
999          QWidget *pParent, const char *pszName )  {
         : QTable(pParent, pszName)  
 {  
         // Set fixed number of columns.  
         QTable::setNumCols(2);  
         QTable::setShowGrid(false);  
         QTable::setSorting(false);  
         QTable::setFocusStyle(QTable::FollowStyle);  
         QTable::setSelectionMode(QTable::NoSelection);  
         // No vertical header.  
         QTable::verticalHeader()->hide();  
         QTable::setLeftMargin(0);  
         // Initialize the fixed table column headings.  
         QHeader *pHeader = QTable::horizontalHeader();  
         pHeader->setLabel(0, tr("Sampler Channel"));  
         pHeader->setLabel(1, tr("Device Channel"));  
         // Set read-onlyness of each column  
         QTable::setColumnReadOnly(0, true);  
 //      QTable::setColumnReadOnly(1, false); -- of course not.  
         QTable::setColumnStretchable(1, true);  
1000  }  }
1001    
1002  // Default destructor.  
1003  qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void)  int ChannelRoutingModel::rowCount ( const QModelIndex& /*parent*/) const
1004  {  {
1005            return (m_pDevice) ? m_routing.size() : 0;
1006  }  }
1007    
1008    
1009  // Routing map table renderer.  int ChannelRoutingModel::columnCount ( const QModelIndex& /*parent*/) const
 void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice,  
         const qsamplerChannelRoutingMap& routing )  
1010  {  {
1011          if (pDevice == NULL)          return 1;
1012                  return;  }
1013    
1014    
1015    Qt::ItemFlags ChannelRoutingModel::flags ( const QModelIndex& /*index*/) const
1016    {
1017            return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
1018    }
1019    
1020          // Always (re)start it empty.  
1021          QTable::setUpdatesEnabled(false);  bool ChannelRoutingModel::setData ( const QModelIndex& index,
1022          QTable::setNumRows(0);          const QVariant& value, int /*role*/)
1023    {
1024            if (!index.isValid())
1025                    return false;
1026    
1027            m_routing[index.row()] = value.toInt();
1028    
1029            emit dataChanged(index, index);
1030            return true;
1031    }
1032    
1033    
1034    QVariant ChannelRoutingModel::data ( const QModelIndex &index, int role ) const
1035    {
1036            if (!index.isValid())
1037                    return QVariant();
1038            if (role != Qt::DisplayRole)
1039                    return QVariant();
1040            if (index.column() != 0)
1041                    return QVariant();
1042    
1043            ChannelRoutingItem item;
1044    
1045          // The common device port item list.          // The common device port item list.
1046          QStringList opts;          DevicePortList& ports = m_pDevice->ports();
1047          qsamplerDevicePortList& ports = pDevice->ports();          QListIterator<DevicePort *> iter(ports);
1048          qsamplerDevicePort *pPort;          while (iter.hasNext()) {
1049          for (pPort = ports.first(); pPort; pPort = ports.next()) {                  DevicePort *pPort = iter.next();
1050                  opts.append(pDevice->deviceTypeName()                  item.options.append(
1051                          + ' ' + pDevice->driverName()                          m_pDevice->deviceTypeName()
1052                          + ' ' + pPort->portName());                          + ' ' + m_pDevice->driverName()
1053          }                          + ' ' + pPort->portName()
1054                    );
1055          // Those items shall have a proper pixmap...          }
1056          QPixmap pmChannel = QPixmap::fromMimeSource("qsamplerChannel.png");  
1057          QPixmap pmDevice;          item.selection = m_routing[index.row()];
1058          switch (pDevice->deviceType()) {  
1059          case qsamplerDevice::Audio:          return QVariant::fromValue(item);
1060                  pmDevice = QPixmap::fromMimeSource("audio2.png");  }
                 break;  
         case qsamplerDevice::Midi:  
                 pmDevice = QPixmap::fromMimeSource("midi2.png");  
                 break;  
         case qsamplerDevice::None:  
                 break;  
         }  
   
         // Fill the routing table...  
         QTable::insertRows(0, routing.count());  
         int iRow = 0;  
         qsamplerChannelRoutingMap::ConstIterator iter;  
         for (iter = routing.begin(); iter != routing.end(); ++iter) {  
                 QTable::setPixmap(iRow, 0, pmChannel);  
                 QTable::setText(iRow, 0, pDevice->deviceTypeName()  
                         + ' ' + QString::number(iter.key()));  
                 qsamplerChannelRoutingComboBox *pComboItem =  
                         new qsamplerChannelRoutingComboBox(this, opts, pmDevice);  
                 pComboItem->setCurrentItem(iter.data());  
                 QTable::setItem(iRow, 1, pComboItem);  
                 ++iRow;  
         }  
   
         // Adjust optimal column widths.  
         QTable::adjustColumn(0);  
         QTable::adjustColumn(1);  
1061    
1062          QTable::setUpdatesEnabled(true);  
1063          QTable::updateContents();  QVariant ChannelRoutingModel::headerData ( int section,
1064            Qt::Orientation orientation, int role) const
1065    {
1066            if (role != Qt::DisplayRole)
1067                    return QVariant();
1068    
1069            switch (orientation) {
1070                    case Qt::Horizontal:
1071                            return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel");
1072                    case Qt::Vertical:
1073                            return QObject::tr("Audio Channel ") +
1074                                    QString::number(section) + " " + UNICODE_RIGHT_ARROW;
1075                    default:
1076                            return QVariant();
1077            }
1078    }
1079    
1080    
1081    void ChannelRoutingModel::refresh ( Device *pDevice,
1082            const ChannelRoutingMap& routing )
1083    {
1084            m_pDevice = pDevice;
1085            m_routing = routing;
1086            // inform the outer world (QTableView) that our data changed
1087    #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
1088            QAbstractTableModel::reset();
1089    #else
1090            QAbstractTableModel::beginResetModel();
1091            QAbstractTableModel::endResetModel();
1092    #endif
1093  }  }
1094    
1095    
1096  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
1097  // qsamplerChannelRoutingComboBox - Custom combo box for routing table.  // QSampler::ChannelRoutingDelegate - table cell renderer for audio routing
1098  //  //
1099    
1100  // Constructor.  ChannelRoutingDelegate::ChannelRoutingDelegate ( QObject *pParent )
1101  qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox (          : QItemDelegate(pParent)
         QTable *pTable, const QStringList& list, const QPixmap& pixmap )  
         : QTableItem(pTable, QTableItem::OnTyping, QString::null, pixmap),  
         m_list(list)  
1102  {  {
         m_iCurrentItem = 0;  
1103  }  }
1104    
1105  // Public accessors.  
1106  void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem )  QWidget* ChannelRoutingDelegate::createEditor ( QWidget *pParent,
1107            const QStyleOptionViewItem & option, const QModelIndex& index ) const
1108  {  {
1109          m_iCurrentItem = iCurrentItem;          if (!index.isValid())
1110                    return nullptr;
1111    
1112            if (index.column() != 0)
1113                    return nullptr;
1114    
1115          QTableItem::setText(m_list[iCurrentItem]);          ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1116    
1117            QComboBox* pComboBox = new QComboBox(pParent);
1118            pComboBox->addItems(item.options);
1119            pComboBox->setCurrentIndex(item.selection);
1120            pComboBox->setEnabled(true);
1121            pComboBox->setEditable(true);
1122            pComboBox->setGeometry(option.rect);
1123            return pComboBox;
1124  }  }
1125    
1126  int qsamplerChannelRoutingComboBox::currentItem (void) const  
1127    void ChannelRoutingDelegate::setEditorData ( QWidget *pEditor,
1128            const QModelIndex &index) const
1129  {  {
1130          return m_iCurrentItem;          ChannelRoutingItem item = index.model()->data(index,
1131                    Qt::DisplayRole).value<ChannelRoutingItem> ();
1132            QComboBox* pComboBox = static_cast<QComboBox*> (pEditor);
1133            pComboBox->setCurrentIndex(item.selection);
1134  }  }
1135    
1136  // Virtual implemetations.  
1137  QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const  void ChannelRoutingDelegate::setModelData ( QWidget* pEditor,
1138            QAbstractItemModel *pModel, const QModelIndex& index ) const
1139  {  {
1140          QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport());          QComboBox *pComboBox = static_cast<QComboBox*> (pEditor);
1141          QObject::connect(pComboBox, SIGNAL(activated(int)),          pModel->setData(index, pComboBox->currentIndex());
                 QTableItem::table(), SLOT(doValueChanged()));  
         for (QStringList::ConstIterator iter = m_list.begin();  
                         iter != m_list.end(); iter++) {  
                 pComboBox->insertItem(QTableItem::pixmap(), *iter);  
         }  
         pComboBox->setCurrentItem(m_iCurrentItem);  
         return pComboBox;  
1142  }  }
1143    
1144  void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget )  
1145    void ChannelRoutingDelegate::updateEditorGeometry ( QWidget *pEditor,
1146            const QStyleOptionViewItem& option, const QModelIndex &/* index */) const
1147  {  {
1148          if (pWidget->inherits("QComboBox")) {          pEditor->setGeometry(option.rect);
                 QComboBox *pComboBox = (QComboBox *) pWidget;  
                 m_iCurrentItem = pComboBox->currentItem();  
                 QTableItem::setText(pComboBox->currentText());  
         }  
         else QTableItem::setContentFromEditor(pWidget);  
1149  }  }
1150    
1151    } // namespace QSampler
1152    
1153    
1154  // end of qsamplerChannel.cpp  // end of qsamplerChannel.cpp

Legend:
Removed from v.759  
changed lines
  Added in v.3855

  ViewVC Help
Powered by ViewVC