/[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 824 by capela, Fri Dec 23 01:40:56 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"  #include "qsamplerAbout.h"
24  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
25    
# Line 34  Line 35 
35    
36  #define QSAMPLER_INSTRUMENT_MAX 100  #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;
# Line 67  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 118  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 165  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 208  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 251  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 276  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 301  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 326  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 343  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 351  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 376  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 401  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 426  bool qsamplerChannel::channelMute (void) Line 470  bool qsamplerChannel::channelMute (void)
470    
471  bool qsamplerChannel::setChannelMute ( bool bMute )  bool qsamplerChannel::setChannelMute ( bool bMute )
472  {  {
473          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
474            if (pMainForm == NULL)
475                    return false;
476            if (pMainForm->client() == NULL || m_iChannelID < 0)
477                  return false;                  return false;
478          if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))          if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))
479                  return true;                  return true;
480    
481  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
482          if (::lscp_set_channel_mute(client(), m_iChannelID, bMute) != LSCP_OK) {          if (::lscp_set_channel_mute(pMainForm->client(), m_iChannelID, bMute) != LSCP_OK) {
483                  appendMessagesClient("lscp_set_channel_mute");                  appendMessagesClient("lscp_set_channel_mute");
484                  return false;                  return false;
485          }          }
# Line 453  bool qsamplerChannel::channelSolo (void) Line 500  bool qsamplerChannel::channelSolo (void)
500    
501  bool qsamplerChannel::setChannelSolo ( bool bSolo )  bool qsamplerChannel::setChannelSolo ( bool bSolo )
502  {  {
503          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
504            if (pMainForm == NULL)
505                    return false;
506            if (pMainForm->client() == NULL || m_iChannelID < 0)
507                  return false;                  return false;
508          if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))          if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))
509                  return true;                  return true;
510    
511  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
512          if (::lscp_set_channel_solo(client(), m_iChannelID, bSolo) != LSCP_OK) {          if (::lscp_set_channel_solo(pMainForm->client(), m_iChannelID, bSolo) != LSCP_OK) {
513                  appendMessagesClient("lscp_set_channel_solo");                  appendMessagesClient("lscp_set_channel_solo");
514                  return false;                  return false;
515          }          }
# Line 480  int qsamplerChannel::audioChannel ( int Line 530  int qsamplerChannel::audioChannel ( int
530    
531  bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )  bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )
532  {  {
533          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
534            if (pMainForm == NULL)
535                    return false;
536            if (pMainForm->client() == NULL || m_iChannelID < 0)
537                  return false;                  return false;
538          if (m_iInstrumentStatus == 100 &&          if (m_iInstrumentStatus == 100 &&
539                          m_audioRouting[iAudioOut] == iAudioIn)                          m_audioRouting[iAudioOut] == iAudioIn)
540                  return true;                  return true;
541    
542          if (::lscp_set_channel_audio_channel(client(),          if (::lscp_set_channel_audio_channel(pMainForm->client(),
543                          m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) {                          m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) {
544                  appendMessagesClient("lscp_set_channel_audio_channel");                  appendMessagesClient("lscp_set_channel_audio_channel");
545                  return false;                  return false;
# Line 519  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 532  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 552  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  #ifdef CONFIG_MUTE_SOLO
# Line 570  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 578  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 588  bool qsamplerChannel::updateChannelInfo Line 649  bool qsamplerChannel::updateChannelInfo
649    
650          // Set the audio routing map.          // Set the audio routing map.
651          m_audioRouting.clear();          m_audioRouting.clear();
652          char **ppszRouting = pChannelInfo->audio_routing;  #ifdef CONFIG_AUDIO_ROUTING
653          for (int i = 0; ppszRouting && ppszRouting[i]; i++) {          int *piAudioRouting = pChannelInfo->audio_routing;
654                  m_audioRouting[i] = ::atoi(ppszRouting[i]);          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  }  }
# Line 600  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 614  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 635  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 778  QString qsamplerChannel::loadingInstrume Line 900  QString qsamplerChannel::loadingInstrume
900  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
901  // qsamplerChannelRoutingTable - Channel routing table.  // qsamplerChannelRoutingTable - Channel routing table.
902  //  //
903    #if 0
904  // Constructor.  // Constructor.
905  qsamplerChannelRoutingTable::qsamplerChannelRoutingTable (  qsamplerChannelRoutingTable::qsamplerChannelRoutingTable (
906          QWidget *pParent, const char *pszName )          QWidget *pParent, const char *pszName )
# Line 831  void qsamplerChannelRoutingTable::refres Line 953  void qsamplerChannelRoutingTable::refres
953          }          }
954    
955          // Those items shall have a proper pixmap...          // Those items shall have a proper pixmap...
956          QPixmap pmChannel = QPixmap::fromMimeSource("qsamplerChannel.png");          QPixmap pmChannel = QPixmap(":/icons/qsamplerChannel.png");
957          QPixmap pmDevice;          QPixmap pmDevice;
958          switch (pDevice->deviceType()) {          switch (pDevice->deviceType()) {
959          case qsamplerDevice::Audio:          case qsamplerDevice::Audio:
960                  pmDevice = QPixmap::fromMimeSource("audio2.png");                  pmDevice = QPixmap(":/icons/audio2.png");
961                  break;                  break;
962          case qsamplerDevice::Midi:          case qsamplerDevice::Midi:
963                  pmDevice = QPixmap::fromMimeSource("midi2.png");                  pmDevice = QPixmap(":/icons/midi2.png");
964                  break;                  break;
965          case qsamplerDevice::None:          case qsamplerDevice::None:
966                  break;                  break;
# Line 874  void qsamplerChannelRoutingTable::flush Line 996  void qsamplerChannelRoutingTable::flush
996          if (QTable::isEditing())          if (QTable::isEditing())
997              QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true);              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    
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.  // qsamplerChannelRoutingComboBox - Custom combo box for routing table.
1096  //  //
1097    
1098    #if 0
1099  // Constructor.  // Constructor.
1100  qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox (  qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox (
1101          QTable *pTable, const QStringList& list, const QPixmap& pixmap )          QTable *pTable, const QStringList& list, const QPixmap& pixmap )
# Line 926  void qsamplerChannelRoutingComboBox::set Line 1142  void qsamplerChannelRoutingComboBox::set
1142          else QTableItem::setContentFromEditor(pWidget);          else QTableItem::setContentFromEditor(pWidget);
1143  }  }
1144    
1145    #endif
 // end of qsamplerChannel.cpp  

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

  ViewVC Help
Powered by ViewVC