/[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 490 by capela, Fri Apr 1 00:34:58 2005 UTC revision 1463 by capela, Thu Nov 1 13:01:27 2007 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-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5    
6     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
7     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 13 
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.     GNU General Public License for more details.
15    
16     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
17     along with this program; if not, write to the Free Software     with this program; if not, write to the Free Software Foundation, Inc.,
18     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19    
20  *****************************************************************************/  *****************************************************************************/
21    
22    #include "qsamplerUtilities.h"
23    #include "qsamplerAbout.h"
24  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
25    
26  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
27  #include "qsamplerChannelForm.h"  #include "qsamplerChannelForm.h"
28    
 #include "config.h"  
   
29  #include <qfileinfo.h>  #include <qfileinfo.h>
30    #include <qcombobox.h>
31    
32  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
33  #include "gig.h"  #include "gig.h"
34  #endif  #endif
35    
36  #define QSAMPLER_INSTRUMENT_MAX 8  #define QSAMPLER_INSTRUMENT_MAX 100
37    
38    using namespace QSampler;
39    
40  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
41  // qsamplerChannel - Sampler channel structure.  // qsamplerChannel - Sampler channel structure.
42  //  //
43    
44  // Constructor.  // Constructor.
45  qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )  qsamplerChannel::qsamplerChannel ( int iChannelID )
46  {  {
         m_pMainForm  = pMainForm;  
47          m_iChannelID = iChannelID;          m_iChannelID = iChannelID;
48    
49  //  m_sEngineName       = noEngineName();  //  m_sEngineName       = noEngineName();
# Line 54  qsamplerChannel::qsamplerChannel ( qsamp Line 55  qsamplerChannel::qsamplerChannel ( qsamp
55          m_iMidiDevice       = -1;          m_iMidiDevice       = -1;
56          m_iMidiPort         = -1;          m_iMidiPort         = -1;
57          m_iMidiChannel      = -1;          m_iMidiChannel      = -1;
58            m_iMidiMap          = -1;
59          m_sAudioDriver      = "ALSA";          m_sAudioDriver      = "ALSA";
60          m_iAudioDevice      = -1;          m_iAudioDevice      = -1;
61          m_fVolume           = 0.0;          m_fVolume           = 0.0;
62            m_bMute             = false;
63            m_bSolo             = false;
64  }  }
65    
66  // Default destructor.  // Default destructor.
# Line 66  qsamplerChannel::~qsamplerChannel (void) Line 69  qsamplerChannel::~qsamplerChannel (void)
69  }  }
70    
71    
 // 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();  
 }  
   
   
72  // Create a new sampler channel, if not already.  // Create a new sampler channel, if not already.
73  bool qsamplerChannel::addChannel (void)  bool qsamplerChannel::addChannel (void)
74  {  {
75          if (client() == NULL)          MainForm* pMainForm = MainForm::getInstance();
76            if (pMainForm == NULL)
77                    return false;
78            if (pMainForm->client() == NULL)
79                  return false;                  return false;
80    
81          // Are we a new channel?          // Are we a new channel?
82          if (m_iChannelID < 0) {          if (m_iChannelID < 0) {
83                  m_iChannelID = ::lscp_add_channel(client());                  m_iChannelID = ::lscp_add_channel(pMainForm->client());
84                  if (m_iChannelID < 0) {                  if (m_iChannelID < 0) {
85                          appendMessagesClient("lscp_add_channel");                          appendMessagesClient("lscp_add_channel");
86                          appendMessagesError(QObject::tr("Could not add channel.\n\nSorry."));                          appendMessagesError(
87                                    QObject::tr("Could not add channel.\n\nSorry."));
88                  }   // Otherwise it's created...                  }   // Otherwise it's created...
89                  else appendMessages(QObject::tr("added."));                  else appendMessages(QObject::tr("added."));
90          }          }
# Line 117  bool qsamplerChannel::addChannel (void) Line 97  bool qsamplerChannel::addChannel (void)
97  // Remove sampler channel.  // Remove sampler channel.
98  bool qsamplerChannel::removeChannel (void)  bool qsamplerChannel::removeChannel (void)
99  {  {
100          if (client() == NULL)          MainForm *pMainForm = MainForm::getInstance();
101            if (pMainForm == NULL)
102                    return false;
103            if (pMainForm->client() == NULL)
104                  return false;                  return false;
105    
106          // Are we an existing channel?          // Are we an existing channel?
107          if (m_iChannelID >= 0) {          if (m_iChannelID >= 0) {
108                  if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) {                  if (::lscp_remove_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
109                          appendMessagesClient("lscp_remove_channel");                          appendMessagesClient("lscp_remove_channel");
110                          appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));                          appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));
111                  } else {                  } else {
# Line 164  const QString& qsamplerChannel::engineNa Line 147  const QString& qsamplerChannel::engineNa
147    
148  bool qsamplerChannel::loadEngine ( const QString& sEngineName )  bool qsamplerChannel::loadEngine ( const QString& sEngineName )
149  {  {
150          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
151            if (pMainForm == NULL)
152                    return false;
153            if (pMainForm->client() == NULL || m_iChannelID < 0)
154                  return false;                  return false;
155          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
156                  return true;                  return true;
157    
158          if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {          if (::lscp_load_engine(pMainForm->client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {
159                  appendMessagesClient("lscp_load_engine");                  appendMessagesClient("lscp_load_engine");
160                  return false;                  return false;
161          }          }
162    
163          appendMessages(QObject::tr("Engine: %1.").arg(sEngineName));          appendMessages(QObject::tr("Engine: %1.").arg(sEngineName));
164    
165          m_sEngineName = sEngineName;          m_sEngineName = sEngineName;
# Line 207  int qsamplerChannel::instrumentStatus (v Line 194  int qsamplerChannel::instrumentStatus (v
194  // Instrument file loader.  // Instrument file loader.
195  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
196  {  {
197          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
198            if (pMainForm == NULL)
199                    return false;
200            if (pMainForm->client() == NULL || m_iChannelID < 0)
201                  return false;                  return false;
202          if (!isInstrumentFile(sInstrumentFile))          if (!isInstrumentFile(sInstrumentFile))
203                  return false;                  return false;
204          if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)          if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)
205                  return true;                  return true;
206    
207          if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {          if (
208                    ::lscp_load_instrument_non_modal(
209                            pMainForm->client(),
210                            qsamplerUtilities::lscpEscapePath(sInstrumentFile).latin1(),
211                            iInstrumentNr, m_iChannelID
212                    ) != LSCP_OK
213            ) {
214                  appendMessagesClient("lscp_load_instrument");                  appendMessagesClient("lscp_load_instrument");
215                  return false;                  return false;
216          }          }
# Line 250  const QString& qsamplerChannel::midiDriv Line 246  const QString& qsamplerChannel::midiDriv
246    
247  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
248  {  {
249          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
250            if (pMainForm == NULL)
251                    return false;
252            if (pMainForm->client() == NULL || m_iChannelID < 0)
253                  return false;                  return false;
254          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
255                  return true;                  return true;
256    
257          if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {          if (::lscp_set_channel_midi_type(pMainForm->client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {
258                  appendMessagesClient("lscp_set_channel_midi_type");                  appendMessagesClient("lscp_set_channel_midi_type");
259                  return false;                  return false;
260          }          }
# Line 275  int qsamplerChannel::midiDevice (void) c Line 274  int qsamplerChannel::midiDevice (void) c
274    
275  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
276  {  {
277          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
278            if (pMainForm == NULL)
279                    return false;
280            if (pMainForm->client() == NULL || m_iChannelID < 0)
281                  return false;                  return false;
282          if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)          if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)
283                  return true;                  return true;
284    
285          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) {
286                  appendMessagesClient("lscp_set_channel_midi_device");                  appendMessagesClient("lscp_set_channel_midi_device");
287                  return false;                  return false;
288          }          }
# Line 300  int qsamplerChannel::midiPort (void) con Line 302  int qsamplerChannel::midiPort (void) con
302    
303  bool qsamplerChannel::setMidiPort ( int iMidiPort )  bool qsamplerChannel::setMidiPort ( int iMidiPort )
304  {  {
305          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
306            if (pMainForm == NULL)
307                    return false;
308            if (pMainForm->client() == NULL || m_iChannelID < 0)
309                  return false;                  return false;
310          if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)          if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)
311                  return true;                  return true;
312    
313          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) {
314                  appendMessagesClient("lscp_set_channel_midi_port");                  appendMessagesClient("lscp_set_channel_midi_port");
315                  return false;                  return false;
316          }          }
# Line 325  int qsamplerChannel::midiChannel (void) Line 330  int qsamplerChannel::midiChannel (void)
330    
331  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
332  {  {
333          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
334            if (pMainForm == NULL)
335                    return false;
336            if (pMainForm->client() == NULL || m_iChannelID < 0)
337                  return false;                  return false;
338          if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)          if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)
339                  return true;                  return true;
340    
341          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) {
342                  appendMessagesClient("lscp_set_channel_midi_channel");                  appendMessagesClient("lscp_set_channel_midi_channel");
343                  return false;                  return false;
344          }          }
# Line 342  bool qsamplerChannel::setMidiChannel ( i Line 350  bool qsamplerChannel::setMidiChannel ( i
350  }  }
351    
352    
353    // MIDI instrument map accessor.
354    int qsamplerChannel::midiMap (void) const
355    {
356            return m_iMidiMap;
357    }
358    
359    bool qsamplerChannel::setMidiMap ( int iMidiMap )
360    {
361            MainForm *pMainForm = MainForm::getInstance();
362            if (pMainForm == NULL)
363                    return false;
364            if (pMainForm->client() == NULL || m_iChannelID < 0)
365                    return false;
366            if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap)
367                    return true;
368    #ifdef CONFIG_MIDI_INSTRUMENT
369            if (::lscp_set_channel_midi_map(pMainForm->client(), m_iChannelID, iMidiMap) != LSCP_OK) {
370                    appendMessagesClient("lscp_set_channel_midi_map");
371                    return false;
372            }
373    #endif
374            appendMessages(QObject::tr("MIDI map: %1.").arg(iMidiMap));
375    
376            m_iMidiMap = iMidiMap;
377            return true;
378    }
379    
380    
381  // Audio device accessor.  // Audio device accessor.
382  int qsamplerChannel::audioDevice (void) const  int qsamplerChannel::audioDevice (void) const
383  {  {
# Line 350  int qsamplerChannel::audioDevice (void) Line 386  int qsamplerChannel::audioDevice (void)
386    
387  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
388  {  {
389          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
390            if (pMainForm == NULL)
391                    return false;
392            if (pMainForm->client() == NULL || m_iChannelID < 0)
393                  return false;                  return false;
394          if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)          if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)
395                  return true;                  return true;
396    
397          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) {
398                  appendMessagesClient("lscp_set_channel_audio_device");                  appendMessagesClient("lscp_set_channel_audio_device");
399                  return false;                  return false;
400          }          }
# Line 375  const QString& qsamplerChannel::audioDri Line 414  const QString& qsamplerChannel::audioDri
414    
415  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
416  {  {
417          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
418            if (pMainForm == NULL)
419                    return false;
420            if (pMainForm->client() == NULL || m_iChannelID < 0)
421                  return false;                  return false;
422          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
423                  return true;                  return true;
424    
425          if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {          if (::lscp_set_channel_audio_type(pMainForm->client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {
426                  appendMessagesClient("lscp_set_channel_audio_type");                  appendMessagesClient("lscp_set_channel_audio_type");
427                  return false;                  return false;
428          }          }
# Line 400  float qsamplerChannel::volume (void) con Line 442  float qsamplerChannel::volume (void) con
442    
443  bool qsamplerChannel::setVolume ( float fVolume )  bool qsamplerChannel::setVolume ( float fVolume )
444  {  {
445          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
446            if (pMainForm == NULL)
447                    return false;
448            if (pMainForm->client() == NULL || m_iChannelID < 0)
449                  return false;                  return false;
450          if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)          if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)
451                  return true;                  return true;
452    
453          if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {          if (::lscp_set_channel_volume(pMainForm->client(), m_iChannelID, fVolume) != LSCP_OK) {
454                  appendMessagesClient("lscp_set_channel_volume");                  appendMessagesClient("lscp_set_channel_volume");
455                  return false;                  return false;
456          }          }
# Line 417  bool qsamplerChannel::setVolume ( float Line 462  bool qsamplerChannel::setVolume ( float
462  }  }
463    
464    
465    // Sampler channel mute state.
466    bool qsamplerChannel::channelMute (void) const
467    {
468            return m_bMute;
469    }
470    
471    bool qsamplerChannel::setChannelMute ( bool bMute )
472    {
473            MainForm *pMainForm = MainForm::getInstance();
474            if (pMainForm == NULL)
475                    return false;
476            if (pMainForm->client() == NULL || m_iChannelID < 0)
477                    return false;
478            if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))
479                    return true;
480    
481    #ifdef CONFIG_MUTE_SOLO
482            if (::lscp_set_channel_mute(pMainForm->client(), m_iChannelID, bMute) != LSCP_OK) {
483                    appendMessagesClient("lscp_set_channel_mute");
484                    return false;
485            }
486            appendMessages(QObject::tr("Mute: %1.").arg((int) bMute));
487            m_bMute = bMute;
488            return true;
489    #else
490            return false;
491    #endif
492    }
493    
494    
495    // Sampler channel solo state.
496    bool qsamplerChannel::channelSolo (void) const
497    {
498            return m_bSolo;
499    }
500    
501    bool qsamplerChannel::setChannelSolo ( bool bSolo )
502    {
503            MainForm *pMainForm = MainForm::getInstance();
504            if (pMainForm == NULL)
505                    return false;
506            if (pMainForm->client() == NULL || m_iChannelID < 0)
507                    return false;
508            if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))
509                    return true;
510    
511    #ifdef CONFIG_MUTE_SOLO
512            if (::lscp_set_channel_solo(pMainForm->client(), m_iChannelID, bSolo) != LSCP_OK) {
513                    appendMessagesClient("lscp_set_channel_solo");
514                    return false;
515            }
516            appendMessages(QObject::tr("Solo: %1.").arg((int) bSolo));
517            m_bSolo = bSolo;
518            return true;
519    #else
520            return false;
521    #endif
522    }
523    
524    
525    // Audio routing accessors.
526    int qsamplerChannel::audioChannel ( int iAudioOut ) const
527    {
528            return m_audioRouting[iAudioOut];
529    }
530    
531    bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )
532    {
533            MainForm *pMainForm = MainForm::getInstance();
534            if (pMainForm == NULL)
535                    return false;
536            if (pMainForm->client() == NULL || m_iChannelID < 0)
537                    return false;
538            if (m_iInstrumentStatus == 100 &&
539                            m_audioRouting[iAudioOut] == iAudioIn)
540                    return true;
541    
542            if (::lscp_set_channel_audio_channel(pMainForm->client(),
543                            m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) {
544                    appendMessagesClient("lscp_set_channel_audio_channel");
545                    return false;
546            }
547    
548            appendMessages(QObject::tr("Audio Channel: %1 -> %2.")
549                    .arg(iAudioOut).arg(iAudioIn));
550    
551            m_audioRouting[iAudioOut] = iAudioIn;
552            return true;
553    }
554    
555    // The audio routing map itself.
556    const qsamplerChannelRoutingMap& qsamplerChannel::audioRouting (void) const
557    {
558            return m_audioRouting;
559    }
560    
561    
562  // Istrument name remapper.  // Istrument name remapper.
563  void qsamplerChannel::updateInstrumentName (void)  void qsamplerChannel::updateInstrumentName (void)
564  {  {
# Line 430  void qsamplerChannel::updateInstrumentNa Line 572  void qsamplerChannel::updateInstrumentNa
572  // Update whole channel info state.  // Update whole channel info state.
573  bool qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
574  {  {
575          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
576            if (pMainForm == NULL)
577                    return false;
578            if (pMainForm->client() == NULL || m_iChannelID < 0)
579                  return false;                  return false;
580    
581          // Read channel information.          // Read channel information.
582          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);
583          if (pChannelInfo == NULL) {          if (pChannelInfo == NULL) {
584                  appendMessagesClient("lscp_get_channel_info");                  appendMessagesClient("lscp_get_channel_info");
585                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
# Line 443  bool qsamplerChannel::updateChannelInfo Line 588  bool qsamplerChannel::updateChannelInfo
588    
589  #ifdef CONFIG_INSTRUMENT_NAME  #ifdef CONFIG_INSTRUMENT_NAME
590          // We got all actual instrument datum...          // We got all actual instrument datum...
591          m_sInstrumentFile = pChannelInfo->instrument_file;          m_sInstrumentFile =
592                    qsamplerUtilities::lscpEscapedPathToPosix(pChannelInfo->instrument_file);
593          m_iInstrumentNr   = pChannelInfo->instrument_nr;          m_iInstrumentNr   = pChannelInfo->instrument_nr;
594          m_sInstrumentName = pChannelInfo->instrument_name;          m_sInstrumentName =
595                    qsamplerUtilities::lscpEscapedTextToRaw(pChannelInfo->instrument_name);
596  #else  #else
597          // First, check if intrument name has changed,          // First, check if intrument name has changed,
598          // taking care that instrument name lookup might be expensive,          // taking care that instrument name lookup might be expensive,
# Line 463  bool qsamplerChannel::updateChannelInfo Line 610  bool qsamplerChannel::updateChannelInfo
610          m_iMidiDevice       = pChannelInfo->midi_device;          m_iMidiDevice       = pChannelInfo->midi_device;
611          m_iMidiPort         = pChannelInfo->midi_port;          m_iMidiPort         = pChannelInfo->midi_port;
612          m_iMidiChannel      = pChannelInfo->midi_channel;          m_iMidiChannel      = pChannelInfo->midi_channel;
613    #ifdef CONFIG_MIDI_INSTRUMENT
614            m_iMidiMap          = pChannelInfo->midi_map;
615    #endif
616          m_iAudioDevice      = pChannelInfo->audio_device;          m_iAudioDevice      = pChannelInfo->audio_device;
617          m_fVolume           = pChannelInfo->volume;          m_fVolume           = pChannelInfo->volume;
618    #ifdef CONFIG_MUTE_SOLO
619            m_bMute             = pChannelInfo->mute;
620            m_bSolo             = pChannelInfo->solo;
621    #endif
622          // Some sanity checks.          // Some sanity checks.
623          if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())          if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())
624                  m_sEngineName = QString::null;                  m_sEngineName = QString::null;
# Line 477  bool qsamplerChannel::updateChannelInfo Line 631  bool qsamplerChannel::updateChannelInfo
631          lscp_device_info_t *pDeviceInfo;          lscp_device_info_t *pDeviceInfo;
632          const QString sNone = QObject::tr("(none)");          const QString sNone = QObject::tr("(none)");
633          // Audio device driver type.          // Audio device driver type.
634          pDeviceInfo = ::lscp_get_audio_device_info(client(), m_iAudioDevice);          pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice);
635          if (pDeviceInfo == NULL) {          if (pDeviceInfo == NULL) {
636                  appendMessagesClient("lscp_get_audio_device_info");                  appendMessagesClient("lscp_get_audio_device_info");
637                  m_sAudioDriver = sNone;                  m_sAudioDriver = sNone;
# Line 485  bool qsamplerChannel::updateChannelInfo Line 639  bool qsamplerChannel::updateChannelInfo
639                  m_sAudioDriver = pDeviceInfo->driver;                  m_sAudioDriver = pDeviceInfo->driver;
640          }          }
641          // MIDI device driver type.          // MIDI device driver type.
642          pDeviceInfo = ::lscp_get_midi_device_info(client(), m_iMidiDevice);          pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice);
643          if (pDeviceInfo == NULL) {          if (pDeviceInfo == NULL) {
644                  appendMessagesClient("lscp_get_midi_device_info");                  appendMessagesClient("lscp_get_midi_device_info");
645                  m_sMidiDriver = sNone;                  m_sMidiDriver = sNone;
# Line 493  bool qsamplerChannel::updateChannelInfo Line 647  bool qsamplerChannel::updateChannelInfo
647                  m_sMidiDriver = pDeviceInfo->driver;                  m_sMidiDriver = pDeviceInfo->driver;
648          }          }
649    
650            // Set the audio routing map.
651            m_audioRouting.clear();
652    #ifdef CONFIG_AUDIO_ROUTING
653            int *piAudioRouting = pChannelInfo->audio_routing;
654            for (int i = 0; piAudioRouting && piAudioRouting[i] >= 0; i++)
655                    m_audioRouting[i] = piAudioRouting[i];
656    #else
657            char **ppszAudioRouting = pChannelInfo->audio_routing;
658            for (int i = 0; ppszAudioRouting && ppszAudioRouting[i]; i++)
659                    m_audioRouting[i] = ::atoi(ppszAudioRouting[i]);
660    #endif
661    
662          return true;          return true;
663  }  }
664    
# Line 500  bool qsamplerChannel::updateChannelInfo Line 666  bool qsamplerChannel::updateChannelInfo
666  // Reset channel method.  // Reset channel method.
667  bool qsamplerChannel::channelReset (void)  bool qsamplerChannel::channelReset (void)
668  {  {
669          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
670            if (pMainForm == NULL)
671                    return false;
672            if (pMainForm->client() == NULL || m_iChannelID < 0)
673                  return false;                  return false;
674    
675          if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) {          if (::lscp_reset_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
676                  appendMessagesClient("lscp_reset_channel");                  appendMessagesClient("lscp_reset_channel");
677                  return false;                  return false;
678          }          }
# Line 514  bool qsamplerChannel::channelReset (void Line 683  bool qsamplerChannel::channelReset (void
683  }  }
684    
685    
686    // Spawn instrument editor method.
687    bool qsamplerChannel::editChannel (void)
688    {
689    #ifdef CONFIG_EDIT_INSTRUMENT
690    
691            MainForm *pMainForm = MainForm::getInstance();
692            if (pMainForm == NULL)
693                    return false;
694            if (pMainForm->client() == NULL || m_iChannelID < 0)
695                    return false;
696    
697            if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID)
698                    != LSCP_OK) {
699                    appendMessagesClient("lscp_edit_channel_instrument");
700                    appendMessagesError(QObject::tr(
701                            "Could not launch an appropriate instrument editor "
702                            "for the given instrument!\n"
703                            "Make sure you have an appropriate "
704                            "instrument editor like 'gigedit' installed\n"
705                            "and that it placed its mandatory DLL file "
706                            "into the sampler's plugin directory.")
707                    );
708                    return false;
709            }
710    
711            appendMessages(QObject::tr("edit instrument."));
712    
713            return true;
714    
715    #else
716    
717            appendMessagesError(QObject::tr(
718                    "Sorry, QSampler was compiled for a version of liblscp "
719                    "which lacks this feature.\n"
720                    "You may want to update liblscp and recompile QSampler afterwards.")
721            );
722    
723            return false;
724    
725    #endif
726    }
727    
728    
729  // Channel setup dialog form.  // Channel setup dialog form.
730  bool qsamplerChannel::channelSetup ( QWidget *pParent )  bool qsamplerChannel::channelSetup ( QWidget *pParent )
731  {  {
732            MainForm *pMainForm = MainForm::getInstance();
733            if (pMainForm == NULL)
734                    return false;
735    
736          bool bResult = false;          bool bResult = false;
737    
738          appendMessages(QObject::tr("setup..."));          appendMessages(QObject::tr("setup..."));
739    
740          qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent);          ChannelForm *pChannelForm = new ChannelForm(pParent);
741          if (pChannelForm) {          if (pChannelForm) {
742                  pChannelForm->setup(this);                  pChannelForm->setup(this);
743                  bResult = pChannelForm->exec();                  bResult = pChannelForm->exec();
# Line 535  bool qsamplerChannel::channelSetup ( QWi Line 751  bool qsamplerChannel::channelSetup ( QWi
751  // Redirected messages output methods.  // Redirected messages output methods.
752  void qsamplerChannel::appendMessages( const QString& s ) const  void qsamplerChannel::appendMessages( const QString& s ) const
753  {  {
754          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
755                  m_pMainForm->appendMessages(channelName() + ' ' + s);          if (pMainForm)
756                    pMainForm->appendMessages(channelName() + ' ' + s);
757  }  }
758    
759  void qsamplerChannel::appendMessagesColor( const QString& s,  void qsamplerChannel::appendMessagesColor( const QString& s,
760          const QString& c ) const          const QString& c ) const
761  {  {
762          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
763                  m_pMainForm->appendMessagesColor(channelName() + ' ' + s, c);          if (pMainForm)
764                    pMainForm->appendMessagesColor(channelName() + ' ' + s, c);
765  }  }
766    
767  void qsamplerChannel::appendMessagesText( const QString& s ) const  void qsamplerChannel::appendMessagesText( const QString& s ) const
768  {  {
769          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
770                  m_pMainForm->appendMessagesText(channelName() + ' ' + s);          if (pMainForm)
771                    pMainForm->appendMessagesText(channelName() + ' ' + s);
772  }  }
773    
774  void qsamplerChannel::appendMessagesError( const QString& s ) const  void qsamplerChannel::appendMessagesError( const QString& s ) const
775  {  {
776          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
777                  m_pMainForm->appendMessagesError(channelName() + "\n\n" + s);          if (pMainForm)
778                    pMainForm->appendMessagesError(channelName() + "\n\n" + s);
779  }  }
780    
781  void qsamplerChannel::appendMessagesClient( const QString& s ) const  void qsamplerChannel::appendMessagesClient( const QString& s ) const
782  {  {
783          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
784                  m_pMainForm->appendMessagesClient(channelName() + ' ' + s);          if (pMainForm)
785                    pMainForm->appendMessagesClient(channelName() + ' ' + s);
786  }  }
787    
788    
789  // Context menu event handler.  // Context menu event handler.
790  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )
791  {  {
792          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
793                  m_pMainForm->contextMenuEvent(pEvent);          if (pMainForm)
794                    pMainForm->contextMenuEvent(pEvent);
795  }  }
796    
797    
# Line 602  QStringList qsamplerChannel::getInstrume Line 824  QStringList qsamplerChannel::getInstrume
824          if (isInstrumentFile(sInstrumentFile)) {          if (isInstrumentFile(sInstrumentFile)) {
825  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
826                  if (bInstrumentNames) {                  if (bInstrumentNames) {
827                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());
828                          gig::File  *pGig  = new gig::File(pRiff);                          gig::File  *pGig  = new gig::File(pRiff);
829                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
830                          while (pInstrument) {                          while (pInstrument) {
# Line 633  QString qsamplerChannel::getInstrumentNa Line 855  QString qsamplerChannel::getInstrumentNa
855                  sInstrumentName = QFileInfo(sInstrumentFile).fileName();                  sInstrumentName = QFileInfo(sInstrumentFile).fileName();
856  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
857                  if (bInstrumentNames) {                  if (bInstrumentNames) {
858                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());
859                          gig::File  *pGig  = new gig::File(pRiff);                          gig::File  *pGig  = new gig::File(pRiff);
860                          int iIndex = 0;                          int iIndex = 0;
861                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
# Line 669  QString qsamplerChannel::noInstrumentNam Line 891  QString qsamplerChannel::noInstrumentNam
891          return QObject::tr("(No instrument)");          return QObject::tr("(No instrument)");
892  }  }
893    
894    QString qsamplerChannel::loadingInstrument (void) {
895            return QObject::tr("(Loading instrument...)");
896    }
897    
898    
899    
900    //-------------------------------------------------------------------------
901    // qsamplerChannelRoutingTable - Channel routing table.
902    //
903    #if 0
904    // Constructor.
905    qsamplerChannelRoutingTable::qsamplerChannelRoutingTable (
906            QWidget *pParent, const char *pszName )
907            : QTable(pParent, pszName)
908    {
909            // Set fixed number of columns.
910            QTable::setNumCols(2);
911            QTable::setShowGrid(false);
912            QTable::setSorting(false);
913            QTable::setFocusStyle(QTable::FollowStyle);
914            QTable::setSelectionMode(QTable::NoSelection);
915            // No vertical header.
916            QTable::verticalHeader()->hide();
917            QTable::setLeftMargin(0);
918            // Initialize the fixed table column headings.
919            QHeader *pHeader = QTable::horizontalHeader();
920            pHeader->setLabel(0, tr("Sampler Channel"));
921            pHeader->setLabel(1, tr("Device Channel"));
922            // Set read-onlyness of each column
923            QTable::setColumnReadOnly(0, true);
924    //      QTable::setColumnReadOnly(1, false); -- of course not.
925            QTable::setColumnStretchable(1, true);
926    }
927    
928    // Default destructor.
929    qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void)
930    {
931    }
932    
933    
934    // Routing map table renderer.
935    void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice,
936            const qsamplerChannelRoutingMap& routing )
937    {
938            if (pDevice == NULL)
939                    return;
940    
941            // Always (re)start it empty.
942            QTable::setUpdatesEnabled(false);
943            QTable::setNumRows(0);
944    
945            // The common device port item list.
946            QStringList opts;
947            qsamplerDevicePortList& ports = pDevice->ports();
948            qsamplerDevicePort *pPort;
949            for (pPort = ports.first(); pPort; pPort = ports.next()) {
950                    opts.append(pDevice->deviceTypeName()
951                            + ' ' + pDevice->driverName()
952                            + ' ' + pPort->portName());
953            }
954    
955            // Those items shall have a proper pixmap...
956            QPixmap pmChannel = QPixmap(":/icons/qsamplerChannel.png");
957            QPixmap pmDevice;
958            switch (pDevice->deviceType()) {
959            case qsamplerDevice::Audio:
960                    pmDevice = QPixmap(":/icons/audio2.png");
961                    break;
962            case qsamplerDevice::Midi:
963                    pmDevice = QPixmap(":/icons/midi2.png");
964                    break;
965            case qsamplerDevice::None:
966                    break;
967            }
968    
969            // Fill the routing table...
970            QTable::insertRows(0, routing.count());
971            int iRow = 0;
972            qsamplerChannelRoutingMap::ConstIterator iter;
973            for (iter = routing.begin(); iter != routing.end(); ++iter) {
974                    QTable::setPixmap(iRow, 0, pmChannel);
975                    QTable::setText(iRow, 0, pDevice->deviceTypeName()
976                            + ' ' + QString::number(iter.key()));
977                    qsamplerChannelRoutingComboBox *pComboItem =
978                            new qsamplerChannelRoutingComboBox(this, opts, pmDevice);
979                    pComboItem->setCurrentItem(iter.data());
980                    QTable::setItem(iRow, 1, pComboItem);
981                    ++iRow;
982            }
983    
984            // Adjust optimal column widths.
985            QTable::adjustColumn(0);
986            QTable::adjustColumn(1);
987    
988            QTable::setUpdatesEnabled(true);
989            QTable::updateContents();
990    }
991    
992    
993    // Commit any pending editing.
994    void qsamplerChannelRoutingTable::flush (void)
995    {
996            if (QTable::isEditing())
997                QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true);
998    }
999    #endif
1000    
1001    ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) {
1002    }
1003    
1004    int ChannelRoutingModel::rowCount(const QModelIndex& /*parent*/) const {
1005        return routing.size();
1006    }
1007    
1008    int ChannelRoutingModel::columnCount(const QModelIndex& /*parent*/) const {
1009        return 1;
1010    }
1011    
1012    QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const {
1013        if (!index.isValid())
1014            return QVariant();
1015        if (role != Qt::DisplayRole)
1016            return QVariant();
1017    
1018        ChannelRoutingItem item;
1019    
1020        // The common device port item list.
1021        qsamplerDevicePortList& ports = pDevice->ports();
1022        qsamplerDevicePort* pPort;
1023        for (pPort = ports.first(); pPort; pPort = ports.next()) {
1024            item.options.append(
1025                pDevice->deviceTypeName()
1026                + ' ' + pDevice->driverName()
1027                + ' ' + pPort->portName()
1028            );
1029        }
1030    
1031        item.selection = routing[index.column()];
1032    
1033        return QVariant::fromValue(item);
1034    }
1035    
1036    QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const {
1037        if (role != Qt::DisplayRole) return QVariant();
1038    
1039        if (orientation == Qt::Horizontal)
1040            return QObject::tr("Device Channel");
1041    
1042        if (orientation == Qt::Vertical)
1043            return QObject::tr("Sampler Channel Output ") +
1044                   QString(section);
1045    
1046        return QVariant();
1047    }
1048    
1049    void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice,
1050            const qsamplerChannelRoutingMap& routing )
1051    {
1052        this->pDevice = pDevice;
1053        this->routing = routing;
1054    }
1055    
1056    
1057    
1058  // end of qsamplerChannel.cpp  
1059    ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) {
1060    }
1061    
1062    QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent,
1063            const QStyleOptionViewItem &/* option */,
1064            const QModelIndex& index) const
1065    {
1066        ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1067    
1068        QComboBox* editor = new QComboBox(parent);
1069        editor->addItems(item.options);
1070        editor->setCurrentIndex(item.selection);
1071        editor->installEventFilter(const_cast<ChannelRoutingDelegate*>(this));
1072        return editor;
1073    }
1074    
1075    void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
1076        ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1077        QComboBox* comboBox = static_cast<QComboBox*>(editor);
1078        comboBox->setCurrentIndex(item.selection);
1079    }
1080    
1081    void ChannelRoutingDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const {
1082        QComboBox* comboBox = static_cast<QComboBox*>(editor);
1083        model->setData(index, comboBox->currentIndex());
1084    }
1085    
1086    void ChannelRoutingDelegate::updateEditorGeometry(QWidget *editor,
1087            const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
1088    {
1089        editor->setGeometry(option.rect);
1090    }
1091    
1092    
1093    
1094    //-------------------------------------------------------------------------
1095    // qsamplerChannelRoutingComboBox - Custom combo box for routing table.
1096    //
1097    
1098    #if 0
1099    // Constructor.
1100    qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox (
1101            QTable *pTable, const QStringList& list, const QPixmap& pixmap )
1102            : QTableItem(pTable, QTableItem::WhenCurrent, QString::null, pixmap),
1103            m_list(list)
1104    {
1105            m_iCurrentItem = 0;
1106    }
1107    
1108    // Public accessors.
1109    void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem )
1110    {
1111            m_iCurrentItem = iCurrentItem;
1112    
1113            QTableItem::setText(m_list[iCurrentItem]);
1114    }
1115    
1116    int qsamplerChannelRoutingComboBox::currentItem (void) const
1117    {
1118            return m_iCurrentItem;
1119    }
1120    
1121    // Virtual implemetations.
1122    QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const
1123    {
1124            QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport());
1125            QObject::connect(pComboBox, SIGNAL(activated(int)),
1126                    QTableItem::table(), SLOT(doValueChanged()));
1127            for (QStringList::ConstIterator iter = m_list.begin();
1128                            iter != m_list.end(); iter++) {
1129                    pComboBox->insertItem(QTableItem::pixmap(), *iter);
1130            }
1131            pComboBox->setCurrentItem(m_iCurrentItem);
1132            return pComboBox;
1133    }
1134    
1135    void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget )
1136    {
1137            if (pWidget->inherits("QComboBox")) {
1138                    QComboBox *pComboBox = (QComboBox *) pWidget;
1139                    m_iCurrentItem = pComboBox->currentItem();
1140                    QTableItem::setText(pComboBox->currentText());
1141            }
1142            else QTableItem::setContentFromEditor(pWidget);
1143    }
1144    
1145    #endif

Legend:
Removed from v.490  
changed lines
  Added in v.1463

  ViewVC Help
Powered by ViewVC