/[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 467 by capela, Tue Mar 15 23:54:14 2005 UTC revision 1490 by schoenebeck, Mon Nov 19 04:09:30 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       Copyright (C) 2007, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 13  Line 14 
14     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15     GNU General Public License for more details.     GNU General Public License for more details.
16    
17     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License along
18     along with this program; if not, write to the Free Software     with this program; if not, write to the Free Software Foundation, Inc.,
19     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23    #include "qsamplerUtilities.h"
24    #include "qsamplerAbout.h"
25  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
26    
27  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
28  #include "qsamplerChannelForm.h"  #include "qsamplerChannelForm.h"
29    
 #include "config.h"  
   
30  #include <qfileinfo.h>  #include <qfileinfo.h>
31    #include <qcombobox.h>
32    
33  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
34  #include "gig.h"  #include "gig.h"
35  #endif  #endif
36    
37  #define QSAMPLER_INSTRUMENT_MAX 8  #define QSAMPLER_INSTRUMENT_MAX 100
38    
39    #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))
40    
41    using namespace QSampler;
42    
43  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
44  // qsamplerChannel - Sampler channel structure.  // qsamplerChannel - Sampler channel structure.
45  //  //
46    
47  // Constructor.  // Constructor.
48  qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )  qsamplerChannel::qsamplerChannel ( int iChannelID )
49  {  {
         m_pMainForm  = pMainForm;  
50          m_iChannelID = iChannelID;          m_iChannelID = iChannelID;
51    
52  //  m_sEngineName       = noEngineName();  //  m_sEngineName       = noEngineName();
# Line 50  qsamplerChannel::qsamplerChannel ( qsamp Line 54  qsamplerChannel::qsamplerChannel ( qsamp
54  //  m_sInstrumentFile   = m_sInstrumentName;  //  m_sInstrumentFile   = m_sInstrumentName;
55          m_iInstrumentNr     = -1;          m_iInstrumentNr     = -1;
56          m_iInstrumentStatus = -1;          m_iInstrumentStatus = -1;
57          m_sMidiDriver       = "Alsa";   // DEPRECATED.          m_sMidiDriver       = "ALSA";
58          m_iMidiDevice       = -1;          m_iMidiDevice       = -1;
59          m_iMidiPort         = -1;          m_iMidiPort         = -1;
60          m_iMidiChannel      = -1;          m_iMidiChannel      = -1;
61          m_sAudioDriver      = "Alsa";   // DEPRECATED.          m_iMidiMap          = -1;
62            m_sAudioDriver      = "ALSA";
63          m_iAudioDevice      = -1;          m_iAudioDevice      = -1;
64          m_fVolume           = 0.0;          m_fVolume           = 0.0;
65            m_bMute             = false;
66            m_bSolo             = false;
67  }  }
68    
69  // Default destructor.  // Default destructor.
# Line 66  qsamplerChannel::~qsamplerChannel (void) Line 72  qsamplerChannel::~qsamplerChannel (void)
72  }  }
73    
74    
 // The global options settings delegated property.  
 qsamplerOptions *qsamplerChannel::options (void)  
 {  
         if (m_pMainForm == NULL)  
                 return NULL;  
   
         return m_pMainForm->options();  
 }  
   
   
 // The client descriptor delegated property.  
 lscp_client_t *qsamplerChannel::client (void)  
 {  
         if (m_pMainForm == NULL)  
                 return NULL;  
   
         return m_pMainForm->client();  
 }  
   
   
75  // Create a new sampler channel, if not already.  // Create a new sampler channel, if not already.
76  bool qsamplerChannel::addChannel (void)  bool qsamplerChannel::addChannel (void)
77  {  {
78          if (client() == NULL)          MainForm* pMainForm = MainForm::getInstance();
79            if (pMainForm == NULL)
80                    return false;
81            if (pMainForm->client() == NULL)
82                  return false;                  return false;
83    
84          // Are we a new channel?          // Are we a new channel?
85          if (m_iChannelID < 0) {          if (m_iChannelID < 0) {
86                  m_iChannelID = ::lscp_add_channel(client());                  m_iChannelID = ::lscp_add_channel(pMainForm->client());
87                  if (m_iChannelID < 0) {                  if (m_iChannelID < 0) {
88                          appendMessagesClient("lscp_add_channel");                          appendMessagesClient("lscp_add_channel");
89                          appendMessagesError(QObject::tr("Could not add channel.\n\nSorry."));                          appendMessagesError(
90                                    QObject::tr("Could not add channel.\n\nSorry."));
91                  }   // Otherwise it's created...                  }   // Otherwise it's created...
92                  else appendMessages(QObject::tr("added."));                  else appendMessages(QObject::tr("added."));
93          }          }
# Line 110  bool qsamplerChannel::addChannel (void) Line 100  bool qsamplerChannel::addChannel (void)
100  // Remove sampler channel.  // Remove sampler channel.
101  bool qsamplerChannel::removeChannel (void)  bool qsamplerChannel::removeChannel (void)
102  {  {
103          if (client() == NULL)          MainForm *pMainForm = MainForm::getInstance();
104            if (pMainForm == NULL)
105                    return false;
106            if (pMainForm->client() == NULL)
107                  return false;                  return false;
108    
109          // Are we an existing channel?          // Are we an existing channel?
110          if (m_iChannelID >= 0) {          if (m_iChannelID >= 0) {
111                  if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) {                  if (::lscp_remove_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
112                          appendMessagesClient("lscp_remove_channel");                          appendMessagesClient("lscp_remove_channel");
113                          appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));                          appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));
114                  } else {                  } else {
# Line 124  bool qsamplerChannel::removeChannel (voi Line 117  bool qsamplerChannel::removeChannel (voi
117                          m_iChannelID = -1;                          m_iChannelID = -1;
118                  }                  }
119          }          }
120            
121          // Return whether we've removed the channel...          // Return whether we've removed the channel...
122          return (m_iChannelID < 0);          return (m_iChannelID < 0);
123  }  }
124    
125    
126  // Channel-ID (aka Sammpler-Channel) accessors.  // Channel-ID (aka Sammpler-Channel) accessors.
127  int qsamplerChannel::channelID (void)  int qsamplerChannel::channelID (void) const
128  {  {
129          return m_iChannelID;          return m_iChannelID;
130  }  }
# Line 143  void qsamplerChannel::setChannelID ( int Line 136  void qsamplerChannel::setChannelID ( int
136    
137    
138  // Readable channel name.  // Readable channel name.
139  QString qsamplerChannel::channelName (void)  QString qsamplerChannel::channelName (void) const
140  {  {
141          return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID));          return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID));
142  }  }
143    
144    
145  // Engine name accessors.  // Engine name accessors.
146  QString& qsamplerChannel::engineName (void)  const QString& qsamplerChannel::engineName (void) const
147  {  {
148          return m_sEngineName;          return m_sEngineName;
149  }  }
150    
151  bool qsamplerChannel::loadEngine ( const QString& sEngineName )  bool qsamplerChannel::loadEngine ( const QString& sEngineName )
152  {  {
153          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
154            if (pMainForm == NULL)
155                    return false;
156            if (pMainForm->client() == NULL || m_iChannelID < 0)
157                  return false;                  return false;
158          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
159                  return true;                  return true;
160                    
161          if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {          if (::lscp_load_engine(pMainForm->client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {
162                  appendMessagesClient("lscp_load_engine");                  appendMessagesClient("lscp_load_engine");
163                  return false;                  return false;
164          }          }
165    
166          appendMessages(QObject::tr("Engine: %1.").arg(sEngineName));          appendMessages(QObject::tr("Engine: %1.").arg(sEngineName));
167    
168          m_sEngineName = sEngineName;          m_sEngineName = sEngineName;
# Line 174  bool qsamplerChannel::loadEngine ( const Line 171  bool qsamplerChannel::loadEngine ( const
171    
172    
173  // Instrument filename accessor.  // Instrument filename accessor.
174  QString& qsamplerChannel::instrumentFile (void)  const QString& qsamplerChannel::instrumentFile (void) const
175  {  {
176          return m_sInstrumentFile;          return m_sInstrumentFile;
177  }  }
178    
179  // Instrument index accessor.  // Instrument index accessor.
180  int qsamplerChannel::instrumentNr (void)  int qsamplerChannel::instrumentNr (void) const
181  {  {
182          return m_iInstrumentNr;          return m_iInstrumentNr;
183  }  }
184    
185  // Instrument name accessor.  // Instrument name accessor.
186  QString& qsamplerChannel::instrumentName (void)  const QString& qsamplerChannel::instrumentName (void) const
187  {  {
188          return m_sInstrumentName;          return m_sInstrumentName;
189  }  }
190    
191  // Instrument status accessor.  // Instrument status accessor.
192  int qsamplerChannel::instrumentStatus (void)  int qsamplerChannel::instrumentStatus (void) const
193  {  {
194          return m_iInstrumentStatus;          return m_iInstrumentStatus;
195  }  }
# Line 200  int qsamplerChannel::instrumentStatus (v Line 197  int qsamplerChannel::instrumentStatus (v
197  // Instrument file loader.  // Instrument file loader.
198  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
199  {  {
200          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
201            if (pMainForm == NULL)
202                    return false;
203            if (pMainForm->client() == NULL || m_iChannelID < 0)
204                  return false;                  return false;
205          if (!isInstrumentFile(sInstrumentFile))          if (!isInstrumentFile(sInstrumentFile))
206                  return false;                  return false;
207          if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)          if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)
208                  return true;                  return true;
209    
210          if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {          if (
211                    ::lscp_load_instrument_non_modal(
212                            pMainForm->client(),
213                            qsamplerUtilities::lscpEscapePath(sInstrumentFile).latin1(),
214                            iInstrumentNr, m_iChannelID
215                    ) != LSCP_OK
216            ) {
217                  appendMessagesClient("lscp_load_instrument");                  appendMessagesClient("lscp_load_instrument");
218                  return false;                  return false;
219          }          }
220    
221          appendMessages(QObject::tr("Instrument: \"%1\" (%2).")          appendMessages(QObject::tr("Instrument: \"%1\" (%2).")
222                  .arg(sInstrumentFile).arg(iInstrumentNr));                  .arg(sInstrumentFile).arg(iInstrumentNr));
223                    
224          return setInstrument(sInstrumentFile, iInstrumentNr);          return setInstrument(sInstrumentFile, iInstrumentNr);
225  }  }
226    
# Line 236  bool qsamplerChannel::setInstrument ( co Line 242  bool qsamplerChannel::setInstrument ( co
242    
243    
244  // MIDI driver type accessors (DEPRECATED).  // MIDI driver type accessors (DEPRECATED).
245  QString& qsamplerChannel::midiDriver (void)  const QString& qsamplerChannel::midiDriver (void) const
246  {  {
247          return m_sMidiDriver;          return m_sMidiDriver;
248  }  }
249    
250  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
251  {  {
252          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
253            if (pMainForm == NULL)
254                    return false;
255            if (pMainForm->client() == NULL || m_iChannelID < 0)
256                  return false;                  return false;
257          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
258                  return true;                  return true;
259    
260          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) {
261                  appendMessagesClient("lscp_set_channel_midi_type");                  appendMessagesClient("lscp_set_channel_midi_type");
262                  return false;                  return false;
263          }          }
# Line 261  bool qsamplerChannel::setMidiDriver ( co Line 270  bool qsamplerChannel::setMidiDriver ( co
270    
271    
272  // MIDI device accessors.  // MIDI device accessors.
273  int qsamplerChannel::midiDevice (void)  int qsamplerChannel::midiDevice (void) const
274  {  {
275          return m_iMidiDevice;          return m_iMidiDevice;
276  }  }
277    
278  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
279  {  {
280          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
281            if (pMainForm == NULL)
282                    return false;
283            if (pMainForm->client() == NULL || m_iChannelID < 0)
284                  return false;                  return false;
285          if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)          if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)
286                  return true;                  return true;
287    
288          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) {
289                  appendMessagesClient("lscp_set_channel_midi_device");                  appendMessagesClient("lscp_set_channel_midi_device");
290                  return false;                  return false;
291          }          }
# Line 286  bool qsamplerChannel::setMidiDevice ( in Line 298  bool qsamplerChannel::setMidiDevice ( in
298    
299    
300  // MIDI port number accessor.  // MIDI port number accessor.
301  int qsamplerChannel::midiPort (void)  int qsamplerChannel::midiPort (void) const
302  {  {
303          return m_iMidiPort;          return m_iMidiPort;
304  }  }
305    
306  bool qsamplerChannel::setMidiPort ( int iMidiPort )  bool qsamplerChannel::setMidiPort ( int iMidiPort )
307  {  {
308          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
309            if (pMainForm == NULL)
310                    return false;
311            if (pMainForm->client() == NULL || m_iChannelID < 0)
312                  return false;                  return false;
313          if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)          if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)
314                  return true;                  return true;
315    
316          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) {
317                  appendMessagesClient("lscp_set_channel_midi_port");                  appendMessagesClient("lscp_set_channel_midi_port");
318                  return false;                  return false;
319          }          }
# Line 311  bool qsamplerChannel::setMidiPort ( int Line 326  bool qsamplerChannel::setMidiPort ( int
326    
327    
328  // MIDI channel accessor.  // MIDI channel accessor.
329  int qsamplerChannel::midiChannel (void)  int qsamplerChannel::midiChannel (void) const
330  {  {
331          return m_iMidiChannel;          return m_iMidiChannel;
332  }  }
333    
334  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
335  {  {
336          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
337            if (pMainForm == NULL)
338                    return false;
339            if (pMainForm->client() == NULL || m_iChannelID < 0)
340                  return false;                  return false;
341          if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)          if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)
342                  return true;                  return true;
343    
344          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) {
345                  appendMessagesClient("lscp_set_channel_midi_channel");                  appendMessagesClient("lscp_set_channel_midi_channel");
346                  return false;                  return false;
347          }          }
# Line 335  bool qsamplerChannel::setMidiChannel ( i Line 353  bool qsamplerChannel::setMidiChannel ( i
353  }  }
354    
355    
356    // MIDI instrument map accessor.
357    int qsamplerChannel::midiMap (void) const
358    {
359            return m_iMidiMap;
360    }
361    
362    bool qsamplerChannel::setMidiMap ( int iMidiMap )
363    {
364            MainForm *pMainForm = MainForm::getInstance();
365            if (pMainForm == NULL)
366                    return false;
367            if (pMainForm->client() == NULL || m_iChannelID < 0)
368                    return false;
369            if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap)
370                    return true;
371    #ifdef CONFIG_MIDI_INSTRUMENT
372            if (::lscp_set_channel_midi_map(pMainForm->client(), m_iChannelID, iMidiMap) != LSCP_OK) {
373                    appendMessagesClient("lscp_set_channel_midi_map");
374                    return false;
375            }
376    #endif
377            appendMessages(QObject::tr("MIDI map: %1.").arg(iMidiMap));
378    
379            m_iMidiMap = iMidiMap;
380            return true;
381    }
382    
383    
384  // Audio device accessor.  // Audio device accessor.
385  int qsamplerChannel::audioDevice (void)  int qsamplerChannel::audioDevice (void) const
386  {  {
387          return m_iAudioDevice;          return m_iAudioDevice;
388  }  }
389    
390  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
391  {  {
392          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
393            if (pMainForm == NULL)
394                    return false;
395            if (pMainForm->client() == NULL || m_iChannelID < 0)
396                  return false;                  return false;
397          if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)          if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)
398                  return true;                  return true;
399    
400          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) {
401                  appendMessagesClient("lscp_set_channel_audio_device");                  appendMessagesClient("lscp_set_channel_audio_device");
402                  return false;                  return false;
403          }          }
# Line 361  bool qsamplerChannel::setAudioDevice ( i Line 410  bool qsamplerChannel::setAudioDevice ( i
410    
411    
412  // Audio driver type accessors (DEPRECATED).  // Audio driver type accessors (DEPRECATED).
413  QString& qsamplerChannel::audioDriver (void)  const QString& qsamplerChannel::audioDriver (void) const
414  {  {
415          return m_sAudioDriver;          return m_sAudioDriver;
416  }  }
417    
418  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
419  {  {
420          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
421            if (pMainForm == NULL)
422                    return false;
423            if (pMainForm->client() == NULL || m_iChannelID < 0)
424                  return false;                  return false;
425          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
426                  return true;                  return true;
427    
428          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) {
429                  appendMessagesClient("lscp_set_channel_audio_type");                  appendMessagesClient("lscp_set_channel_audio_type");
430                  return false;                  return false;
431          }          }
# Line 386  bool qsamplerChannel::setAudioDriver ( c Line 438  bool qsamplerChannel::setAudioDriver ( c
438    
439    
440  // Channel volume accessors.  // Channel volume accessors.
441  float qsamplerChannel::volume (void)  float qsamplerChannel::volume (void) const
442  {  {
443          return m_fVolume;          return m_fVolume;
444  }  }
445    
446  bool qsamplerChannel::setVolume ( float fVolume )  bool qsamplerChannel::setVolume ( float fVolume )
447  {  {
448          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
449            if (pMainForm == NULL)
450                    return false;
451            if (pMainForm->client() == NULL || m_iChannelID < 0)
452                  return false;                  return false;
453          if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)          if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)
454                  return true;                  return true;
455    
456          if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {          if (::lscp_set_channel_volume(pMainForm->client(), m_iChannelID, fVolume) != LSCP_OK) {
457                  appendMessagesClient("lscp_set_channel_volume");                  appendMessagesClient("lscp_set_channel_volume");
458                  return false;                  return false;
459          }          }
# Line 410  bool qsamplerChannel::setVolume ( float Line 465  bool qsamplerChannel::setVolume ( float
465  }  }
466    
467    
468    // Sampler channel mute state.
469    bool qsamplerChannel::channelMute (void) const
470    {
471            return m_bMute;
472    }
473    
474    bool qsamplerChannel::setChannelMute ( bool bMute )
475    {
476            MainForm *pMainForm = MainForm::getInstance();
477            if (pMainForm == NULL)
478                    return false;
479            if (pMainForm->client() == NULL || m_iChannelID < 0)
480                    return false;
481            if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))
482                    return true;
483    
484    #ifdef CONFIG_MUTE_SOLO
485            if (::lscp_set_channel_mute(pMainForm->client(), m_iChannelID, bMute) != LSCP_OK) {
486                    appendMessagesClient("lscp_set_channel_mute");
487                    return false;
488            }
489            appendMessages(QObject::tr("Mute: %1.").arg((int) bMute));
490            m_bMute = bMute;
491            return true;
492    #else
493            return false;
494    #endif
495    }
496    
497    
498    // Sampler channel solo state.
499    bool qsamplerChannel::channelSolo (void) const
500    {
501            return m_bSolo;
502    }
503    
504    bool qsamplerChannel::setChannelSolo ( bool bSolo )
505    {
506            MainForm *pMainForm = MainForm::getInstance();
507            if (pMainForm == NULL)
508                    return false;
509            if (pMainForm->client() == NULL || m_iChannelID < 0)
510                    return false;
511            if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))
512                    return true;
513    
514    #ifdef CONFIG_MUTE_SOLO
515            if (::lscp_set_channel_solo(pMainForm->client(), m_iChannelID, bSolo) != LSCP_OK) {
516                    appendMessagesClient("lscp_set_channel_solo");
517                    return false;
518            }
519            appendMessages(QObject::tr("Solo: %1.").arg((int) bSolo));
520            m_bSolo = bSolo;
521            return true;
522    #else
523            return false;
524    #endif
525    }
526    
527    
528    // Audio routing accessors.
529    int qsamplerChannel::audioChannel ( int iAudioOut ) const
530    {
531            return m_audioRouting[iAudioOut];
532    }
533    
534    bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )
535    {
536            MainForm *pMainForm = MainForm::getInstance();
537            if (pMainForm == NULL)
538                    return false;
539            if (pMainForm->client() == NULL || m_iChannelID < 0)
540                    return false;
541            if (m_iInstrumentStatus == 100 &&
542                            m_audioRouting[iAudioOut] == iAudioIn)
543                    return true;
544    
545            if (::lscp_set_channel_audio_channel(pMainForm->client(),
546                            m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) {
547                    appendMessagesClient("lscp_set_channel_audio_channel");
548                    return false;
549            }
550    
551            appendMessages(QObject::tr("Audio Channel: %1 -> %2.")
552                    .arg(iAudioOut).arg(iAudioIn));
553    
554            m_audioRouting[iAudioOut] = iAudioIn;
555            return true;
556    }
557    
558    // The audio routing map itself.
559    const qsamplerChannelRoutingMap& qsamplerChannel::audioRouting (void) const
560    {
561            return m_audioRouting;
562    }
563    
564    
565  // Istrument name remapper.  // Istrument name remapper.
566  void qsamplerChannel::updateInstrumentName (void)  void qsamplerChannel::updateInstrumentName (void)
567  {  {
# Line 423  void qsamplerChannel::updateInstrumentNa Line 575  void qsamplerChannel::updateInstrumentNa
575  // Update whole channel info state.  // Update whole channel info state.
576  bool qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
577  {  {
578          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
579            if (pMainForm == NULL)
580                    return false;
581            if (pMainForm->client() == NULL || m_iChannelID < 0)
582                  return false;                  return false;
583    
584          // Read channel information.          // Read channel information.
585          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);
586          if (pChannelInfo == NULL) {          if (pChannelInfo == NULL) {
587                  appendMessagesClient("lscp_get_channel_info");                  appendMessagesClient("lscp_get_channel_info");
588                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
# Line 436  bool qsamplerChannel::updateChannelInfo Line 591  bool qsamplerChannel::updateChannelInfo
591    
592  #ifdef CONFIG_INSTRUMENT_NAME  #ifdef CONFIG_INSTRUMENT_NAME
593          // We got all actual instrument datum...          // We got all actual instrument datum...
594          m_sInstrumentFile = pChannelInfo->instrument_file;          m_sInstrumentFile =
595                    qsamplerUtilities::lscpEscapedPathToPosix(pChannelInfo->instrument_file);
596          m_iInstrumentNr   = pChannelInfo->instrument_nr;          m_iInstrumentNr   = pChannelInfo->instrument_nr;
597          m_sInstrumentName = pChannelInfo->instrument_name;          m_sInstrumentName =
598                    qsamplerUtilities::lscpEscapedTextToRaw(pChannelInfo->instrument_name);
599  #else  #else
600          // First, check if intrument name has changed,          // First, check if intrument name has changed,
601          // taking care that instrument name lookup might be expensive,          // taking care that instrument name lookup might be expensive,
# Line 456  bool qsamplerChannel::updateChannelInfo Line 613  bool qsamplerChannel::updateChannelInfo
613          m_iMidiDevice       = pChannelInfo->midi_device;          m_iMidiDevice       = pChannelInfo->midi_device;
614          m_iMidiPort         = pChannelInfo->midi_port;          m_iMidiPort         = pChannelInfo->midi_port;
615          m_iMidiChannel      = pChannelInfo->midi_channel;          m_iMidiChannel      = pChannelInfo->midi_channel;
616    #ifdef CONFIG_MIDI_INSTRUMENT
617            m_iMidiMap          = pChannelInfo->midi_map;
618    #endif
619          m_iAudioDevice      = pChannelInfo->audio_device;          m_iAudioDevice      = pChannelInfo->audio_device;
620          m_fVolume           = pChannelInfo->volume;          m_fVolume           = pChannelInfo->volume;
621    #ifdef CONFIG_MUTE_SOLO
622            m_bMute             = pChannelInfo->mute;
623            m_bSolo             = pChannelInfo->solo;
624    #endif
625          // Some sanity checks.          // Some sanity checks.
626          if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())          if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())
627                  m_sEngineName = QString::null;                  m_sEngineName = QString::null;
# Line 465  bool qsamplerChannel::updateChannelInfo Line 629  bool qsamplerChannel::updateChannelInfo
629                  m_sInstrumentFile = QString::null;                  m_sInstrumentFile = QString::null;
630                  m_sInstrumentName = QString::null;                  m_sInstrumentName = QString::null;
631          }          }
632            
633          // FIXME: DEPRECATED...          // Time for device info grabbing...
634          lscp_device_info_t *pDeviceInfo;          lscp_device_info_t *pDeviceInfo;
635          const QString sNone = QObject::tr("(none)");          const QString sNone = QObject::tr("(none)");
636          // Audio device driver type.          // Audio device driver type.
637          pDeviceInfo = ::lscp_get_audio_device_info(client(), m_iAudioDevice);          pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice);
638          if (pDeviceInfo == NULL) {          if (pDeviceInfo == NULL) {
639                  appendMessagesClient("lscp_get_audio_device_info");                  appendMessagesClient("lscp_get_audio_device_info");
640                  m_sAudioDriver = sNone;                  m_sAudioDriver = sNone;
# Line 478  bool qsamplerChannel::updateChannelInfo Line 642  bool qsamplerChannel::updateChannelInfo
642                  m_sAudioDriver = pDeviceInfo->driver;                  m_sAudioDriver = pDeviceInfo->driver;
643          }          }
644          // MIDI device driver type.          // MIDI device driver type.
645          pDeviceInfo = ::lscp_get_midi_device_info(client(), m_iMidiDevice);          pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice);
646          if (pDeviceInfo == NULL) {          if (pDeviceInfo == NULL) {
647                  appendMessagesClient("lscp_get_midi_device_info");                  appendMessagesClient("lscp_get_midi_device_info");
648                  m_sMidiDriver = sNone;                  m_sMidiDriver = sNone;
# Line 486  bool qsamplerChannel::updateChannelInfo Line 650  bool qsamplerChannel::updateChannelInfo
650                  m_sMidiDriver = pDeviceInfo->driver;                  m_sMidiDriver = pDeviceInfo->driver;
651          }          }
652    
653            // Set the audio routing map.
654            m_audioRouting.clear();
655    #ifdef CONFIG_AUDIO_ROUTING
656            int *piAudioRouting = pChannelInfo->audio_routing;
657            for (int i = 0; piAudioRouting && piAudioRouting[i] >= 0; i++)
658                    m_audioRouting[i] = piAudioRouting[i];
659    #else
660            char **ppszAudioRouting = pChannelInfo->audio_routing;
661            for (int i = 0; ppszAudioRouting && ppszAudioRouting[i]; i++)
662                    m_audioRouting[i] = ::atoi(ppszAudioRouting[i]);
663    #endif
664    
665          return true;          return true;
666  }  }
667    
# Line 493  bool qsamplerChannel::updateChannelInfo Line 669  bool qsamplerChannel::updateChannelInfo
669  // Reset channel method.  // Reset channel method.
670  bool qsamplerChannel::channelReset (void)  bool qsamplerChannel::channelReset (void)
671  {  {
672          if (client() == NULL || m_iChannelID < 0)          MainForm *pMainForm = MainForm::getInstance();
673            if (pMainForm == NULL)
674                    return false;
675            if (pMainForm->client() == NULL || m_iChannelID < 0)
676                  return false;                  return false;
677    
678          if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) {          if (::lscp_reset_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
679                  appendMessagesClient("lscp_reset_channel");                  appendMessagesClient("lscp_reset_channel");
680                  return false;                  return false;
681          }          }
# Line 507  bool qsamplerChannel::channelReset (void Line 686  bool qsamplerChannel::channelReset (void
686  }  }
687    
688    
689    // Spawn instrument editor method.
690    bool qsamplerChannel::editChannel (void)
691    {
692    #ifdef CONFIG_EDIT_INSTRUMENT
693    
694            MainForm *pMainForm = MainForm::getInstance();
695            if (pMainForm == NULL)
696                    return false;
697            if (pMainForm->client() == NULL || m_iChannelID < 0)
698                    return false;
699    
700            if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID)
701                    != LSCP_OK) {
702                    appendMessagesClient("lscp_edit_channel_instrument");
703                    appendMessagesError(QObject::tr(
704                            "Could not launch an appropriate instrument editor "
705                            "for the given instrument!\n"
706                            "Make sure you have an appropriate "
707                            "instrument editor like 'gigedit' installed\n"
708                            "and that it placed its mandatory DLL file "
709                            "into the sampler's plugin directory.")
710                    );
711                    return false;
712            }
713    
714            appendMessages(QObject::tr("edit instrument."));
715    
716            return true;
717    
718    #else
719    
720            appendMessagesError(QObject::tr(
721                    "Sorry, QSampler was compiled for a version of liblscp "
722                    "which lacks this feature.\n"
723                    "You may want to update liblscp and recompile QSampler afterwards.")
724            );
725    
726            return false;
727    
728    #endif
729    }
730    
731    
732  // Channel setup dialog form.  // Channel setup dialog form.
733  bool qsamplerChannel::channelSetup ( QWidget *pParent )  bool qsamplerChannel::channelSetup ( QWidget *pParent )
734  {  {
735            MainForm *pMainForm = MainForm::getInstance();
736            if (pMainForm == NULL)
737                    return false;
738    
739          bool bResult = false;          bool bResult = false;
740    
741          appendMessages(QObject::tr("setup..."));          appendMessages(QObject::tr("setup..."));
742            
743          qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent);          ChannelForm *pChannelForm = new ChannelForm(pParent);
744          if (pChannelForm) {          if (pChannelForm) {
745                  pChannelForm->setup(this);                  pChannelForm->setup(this);
746                  bResult = pChannelForm->exec();                  bResult = pChannelForm->exec();
# Line 526  bool qsamplerChannel::channelSetup ( QWi Line 752  bool qsamplerChannel::channelSetup ( QWi
752    
753    
754  // Redirected messages output methods.  // Redirected messages output methods.
755  void qsamplerChannel::appendMessages( const QString& s )  void qsamplerChannel::appendMessages( const QString& s ) const
756  {  {
757          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
758                  m_pMainForm->appendMessages(channelName() + ' ' + s);          if (pMainForm)
759                    pMainForm->appendMessages(channelName() + ' ' + s);
760  }  }
761    
762  void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c )  void qsamplerChannel::appendMessagesColor( const QString& s,
763            const QString& c ) const
764  {  {
765          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
766                  m_pMainForm->appendMessagesColor(channelName() + ' ' + s, c);          if (pMainForm)
767                    pMainForm->appendMessagesColor(channelName() + ' ' + s, c);
768  }  }
769    
770  void qsamplerChannel::appendMessagesText( const QString& s )  void qsamplerChannel::appendMessagesText( const QString& s ) const
771  {  {
772          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
773                  m_pMainForm->appendMessagesText(channelName() + ' ' + s);          if (pMainForm)
774                    pMainForm->appendMessagesText(channelName() + ' ' + s);
775  }  }
776    
777  void qsamplerChannel::appendMessagesError( const QString& s )  void qsamplerChannel::appendMessagesError( const QString& s ) const
778  {  {
779          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
780                  m_pMainForm->appendMessagesError(channelName() + "\n\n" + s);          if (pMainForm)
781                    pMainForm->appendMessagesError(channelName() + "\n\n" + s);
782  }  }
783    
784  void qsamplerChannel::appendMessagesClient( const QString& s )  void qsamplerChannel::appendMessagesClient( const QString& s ) const
785  {  {
786          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
787                  m_pMainForm->appendMessagesClient(channelName() + ' ' + s);          if (pMainForm)
788                    pMainForm->appendMessagesClient(channelName() + ' ' + s);
789  }  }
790    
791    
792  // Context menu event handler.  // Context menu event handler.
793  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )
794  {  {
795          if (m_pMainForm)          MainForm *pMainForm = MainForm::getInstance();
796                  m_pMainForm->contextMenuEvent(pEvent);          if (pMainForm)
797                    pMainForm->contextMenuEvent(pEvent);
798  }  }
799    
800    
# Line 594  QStringList qsamplerChannel::getInstrume Line 827  QStringList qsamplerChannel::getInstrume
827          if (isInstrumentFile(sInstrumentFile)) {          if (isInstrumentFile(sInstrumentFile)) {
828  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
829                  if (bInstrumentNames) {                  if (bInstrumentNames) {
830                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());
831                          gig::File  *pGig  = new gig::File(pRiff);                          gig::File  *pGig  = new gig::File(pRiff);
832                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
833                          while (pInstrument) {                          while (pInstrument) {
# Line 625  QString qsamplerChannel::getInstrumentNa Line 858  QString qsamplerChannel::getInstrumentNa
858                  sInstrumentName = QFileInfo(sInstrumentFile).fileName();                  sInstrumentName = QFileInfo(sInstrumentFile).fileName();
859  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
860                  if (bInstrumentNames) {                  if (bInstrumentNames) {
861                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());
862                          gig::File  *pGig  = new gig::File(pRiff);                          gig::File  *pGig  = new gig::File(pRiff);
863                          int iIndex = 0;                          int iIndex = 0;
864                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
# Line 661  QString qsamplerChannel::noInstrumentNam Line 894  QString qsamplerChannel::noInstrumentNam
894          return QObject::tr("(No instrument)");          return QObject::tr("(No instrument)");
895  }  }
896    
897    QString qsamplerChannel::loadingInstrument (void) {
898            return QObject::tr("(Loading instrument...)");
899    }
900    
901    
902    //-------------------------------------------------------------------------
903    // ChannelRoutingModel - data model for audio routing (used for QTableView)
904    //
905    
906    ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) {
907    }
908    
909    int ChannelRoutingModel::rowCount(const QModelIndex& /*parent*/) const {
910        return routing.size();
911    }
912    
913    int ChannelRoutingModel::columnCount(const QModelIndex& /*parent*/) const {
914        return 1;
915    }
916    
917    Qt::ItemFlags ChannelRoutingModel::flags(const QModelIndex& /*index*/) const {
918        return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
919    }
920    
921    bool ChannelRoutingModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {
922        if (!index.isValid()) {
923            return false;
924        }
925    
926        routing[index.row()] = value.toInt();
927    
928        emit dataChanged(index, index);
929        return true;
930    }
931    
932    QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const {
933        if (!index.isValid())
934            return QVariant();
935        if (role != Qt::DisplayRole)
936            return QVariant();
937        if (index.column() != 0)
938            return QVariant();
939    
940        ChannelRoutingItem item;
941    
942        // The common device port item list.
943        qsamplerDevicePortList& ports = pDevice->ports();
944        qsamplerDevicePort* pPort;
945        for (pPort = ports.first(); pPort; pPort = ports.next()) {
946            item.options.append(
947                pDevice->deviceTypeName()
948                + ' ' + pDevice->driverName()
949                + ' ' + pPort->portName()
950            );
951        }
952    
953        item.selection = routing[index.row()];
954    
955        return QVariant::fromValue(item);
956    }
957    
958    QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const {
959        if (role != Qt::DisplayRole) return QVariant();
960    
961        switch (orientation) {
962            case Qt::Horizontal:
963                return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel");
964            case Qt::Vertical:
965                return QObject::tr("Sampler Channel ") +
966                       QString::number(section) + " " + UNICODE_RIGHT_ARROW;
967            default:
968                return QVariant();
969        }
970    }
971    
972    void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice,
973            const qsamplerChannelRoutingMap& routing )
974    {
975        this->pDevice = pDevice;
976        this->routing = routing;
977        // inform the outer world (QTableView) that our data changed
978        QAbstractTableModel::reset();
979    }
980    
981    
982    //-------------------------------------------------------------------------
983    // ChannelRoutingDelegate - table cell renderer for audio routing
984    //
985    
986    ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) {
987    }
988    
989    QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent,
990            const QStyleOptionViewItem & option ,
991            const QModelIndex& index) const
992    {
993        if (!index.isValid()) {
994            return NULL;
995        }
996    
997        if (index.column() != 0) {
998            return NULL;
999        }
1000    
1001        ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1002    
1003        QComboBox* pComboBox = new QComboBox(parent);
1004        pComboBox->addItems(item.options);
1005        pComboBox->setCurrentIndex(item.selection);
1006        pComboBox->setEnabled(true);
1007        pComboBox->setGeometry(option.rect);
1008        return pComboBox;
1009    }
1010    
1011    void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
1012        ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1013        QComboBox* comboBox = static_cast<QComboBox*>(editor);
1014        comboBox->setCurrentIndex(item.selection);
1015    }
1016    
1017    void ChannelRoutingDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {
1018        QComboBox* comboBox = static_cast<QComboBox*>(editor);
1019        model->setData(index, comboBox->currentIndex());
1020    }
1021    
1022    void ChannelRoutingDelegate::updateEditorGeometry(QWidget *editor,
1023            const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
1024    {
1025        editor->setGeometry(option.rect);
1026    }
1027    
1028  // end of qsamplerChannel.cpp  // end of qsamplerChannel.cpp

Legend:
Removed from v.467  
changed lines
  Added in v.1490

  ViewVC Help
Powered by ViewVC