/[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 295 by capela, Tue Nov 16 15:26:18 2004 UTC revision 1386 by schoenebeck, Fri Oct 5 17:41:49 2007 UTC
# Line 1  Line 1 
1  // qsamplerChannel.cpp  // qsamplerChannel.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2003-2004, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5    
6     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
7     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 13  Line 13 
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.     GNU General Public License for more details.
15    
16     You should have received a copy of the GNU General Public License     You should have received a copy of the GNU General Public License along
17     along with this program; if not, write to the Free Software     with this program; if not, write to the Free Software Foundation, Inc.,
18     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.     51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19    
20  *****************************************************************************/  *****************************************************************************/
21    
22    #include "qsamplerUtilities.h"
23    #include "qsamplerAbout.h"
24  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
25    
26  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
27    #include "qsamplerChannelForm.h"
28    
29  #include "config.h"  #include <qfileinfo.h>
30    #include <qcombobox.h>
31    
32    #ifdef CONFIG_LIBGIG
33    #include "gig.h"
34    #endif
35    
36    #define QSAMPLER_INSTRUMENT_MAX 100
37    
38    
39  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
# Line 31  Line 41 
41  //  //
42    
43  // Constructor.  // Constructor.
44  qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )  qsamplerChannel::qsamplerChannel ( int iChannelID )
45  {  {
46      m_pMainForm  = pMainForm;          m_iChannelID = iChannelID;
     m_iChannelID = iChannelID;  
   
 //  m_sEngineName       = QObject::tr("(No engine)");  
 //  m_sInstrumentFile   = QObject::tr("(No instrument)");  
     m_iInstrumentNr     = -1;  
     m_iInstrumentStatus = -1;  
     m_sMidiDriver       = "Alsa";   // DEPRECATED.  
     m_iMidiDevice       = -1;  
     m_iMidiPort         = -1;  
     m_iMidiChannel      = -1;  
     m_sAudioDriver      = "Alsa";   // DEPRECATED.  
     m_iAudioDevice      = -1;  
     m_fVolume           = 0.0;  
47    
48    //  m_sEngineName       = noEngineName();
49    //  m_sInstrumentName   = noInstrumentName();
50    //  m_sInstrumentFile   = m_sInstrumentName;
51            m_iInstrumentNr     = -1;
52            m_iInstrumentStatus = -1;
53            m_sMidiDriver       = "ALSA";
54            m_iMidiDevice       = -1;
55            m_iMidiPort         = -1;
56            m_iMidiChannel      = -1;
57            m_iMidiMap          = -1;
58            m_sAudioDriver      = "ALSA";
59            m_iAudioDevice      = -1;
60            m_fVolume           = 0.0;
61            m_bMute             = false;
62            m_bSolo             = false;
63  }  }
64    
65  // Default destructor.  // Default destructor.
# Line 56  qsamplerChannel::~qsamplerChannel (void) Line 68  qsamplerChannel::~qsamplerChannel (void)
68  }  }
69    
70    
 // 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();  
 }  
   
   
71  // Create a new sampler channel, if not already.  // Create a new sampler channel, if not already.
72  bool qsamplerChannel::addChannel (void)  bool qsamplerChannel::addChannel (void)
73  {  {
74      if (client() == NULL)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
75          return false;          if (pMainForm == NULL)
76                    return false;
77            if (pMainForm->client() == NULL)
78                    return false;
79    
80            // Are we a new channel?
81            if (m_iChannelID < 0) {
82                    m_iChannelID = ::lscp_add_channel(pMainForm->client());
83                    if (m_iChannelID < 0) {
84                            appendMessagesClient("lscp_add_channel");
85                            appendMessagesError(
86                                    QObject::tr("Could not add channel.\n\nSorry."));
87                    }   // Otherwise it's created...
88                    else appendMessages(QObject::tr("added."));
89            }
90    
91      // Are we a new channel?          // Return whether we're a valid channel...
92      if (m_iChannelID < 0) {          return (m_iChannelID >= 0);
         m_iChannelID = ::lscp_add_channel(client());  
         if (m_iChannelID < 0) {  
             appendMessagesClient("lscp_add_channel");  
             appendMessagesError(QObject::tr("Could not create the new channel.\n\nSorry."));  
         }   // Otherwise it's created...  
         else appendMessages(QObject::tr("Channel %1 created.").arg(m_iChannelID));  
     }  
   
     // Return whether we're a valid channel...  
     return (m_iChannelID >= 0);  
93  }  }
94    
95    
96  // Remove sampler channel.  // Remove sampler channel.
97  bool qsamplerChannel::removeChannel (void)  bool qsamplerChannel::removeChannel (void)
98  {  {
99      if (client() == NULL)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
100          return false;          if (pMainForm == NULL)
101                    return false;
102            if (pMainForm->client() == NULL)
103                    return false;
104    
105            // Are we an existing channel?
106            if (m_iChannelID >= 0) {
107                    if (::lscp_remove_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
108                            appendMessagesClient("lscp_remove_channel");
109                            appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));
110                    } else {
111                            // Otherwise it's removed.
112                            appendMessages(QObject::tr("removed."));
113                            m_iChannelID = -1;
114                    }
115            }
116    
117      // Are we an existing channel?          // Return whether we've removed the channel...
118      if (m_iChannelID >= 0) {          return (m_iChannelID < 0);
         if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) {  
             appendMessagesClient("lscp_remove_channel");  
             appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));  
         } else {  
             // Otherwise it's removed.  
             appendMessages(QObject::tr("Channel %1 removed.").arg(m_iChannelID));  
             m_iChannelID = -1;  
         }  
     }  
       
     // Return whether we've removed the channel...  
     return (m_iChannelID < 0);  
119  }  }
120    
121    
122  // Channel-ID (aka Sammpler-Channel) accessors.  // Channel-ID (aka Sammpler-Channel) accessors.
123  int qsamplerChannel::channelID (void)  int qsamplerChannel::channelID (void) const
124  {  {
125      return m_iChannelID;          return m_iChannelID;
126  }  }
127    
128  void qsamplerChannel::setChannelID ( int iChannelID )  void qsamplerChannel::setChannelID ( int iChannelID )
129  {  {
130      m_iChannelID = iChannelID;          m_iChannelID = iChannelID;
131  }  }
132    
133    
134  // Readable channel name.  // Readable channel name.
135  QString qsamplerChannel::channelName (void)  QString qsamplerChannel::channelName (void) const
136  {  {
137      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));
138  }  }
139    
140    
141  // Engine name accessors.  // Engine name accessors.
142  QString& qsamplerChannel::engineName (void)  const QString& qsamplerChannel::engineName (void) const
143  {  {
144      return m_sEngineName;          return m_sEngineName;
145  }  }
146    
147  bool qsamplerChannel::loadEngine ( const QString& sEngineName )  bool qsamplerChannel::loadEngine ( const QString& sEngineName )
148  {  {
149      if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
150          return false;          if (pMainForm == NULL)
151                    return false;
152            if (pMainForm->client() == NULL || m_iChannelID < 0)
153                    return false;
154            if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
155                    return true;
156    
157            if (::lscp_load_engine(pMainForm->client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {
158                    appendMessagesClient("lscp_load_engine");
159                    return false;
160            }
161    
162      if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {          appendMessages(QObject::tr("Engine: %1.").arg(sEngineName));
         appendMessagesClient("lscp_load_engine");  
         return false;  
     }  
163    
164      m_sEngineName = sEngineName;          m_sEngineName = sEngineName;
165      return true;          return true;
166  }  }
167    
168    
169  // Instrument filename accessor.  // Instrument filename accessor.
170  QString& qsamplerChannel::instrumentFile (void)  const QString& qsamplerChannel::instrumentFile (void) const
171  {  {
172      return m_sInstrumentFile;          return m_sInstrumentFile;
173  }  }
174    
175  // Instrument index accessor.  // Instrument index accessor.
176  int qsamplerChannel::instrumentNr (void)  int qsamplerChannel::instrumentNr (void) const
177  {  {
178      return m_iInstrumentNr;          return m_iInstrumentNr;
179    }
180    
181    // Instrument name accessor.
182    const QString& qsamplerChannel::instrumentName (void) const
183    {
184            return m_sInstrumentName;
185  }  }
186    
187  // Instrument status accessor.  // Instrument status accessor.
188  int qsamplerChannel::instrumentStatus (void)  int qsamplerChannel::instrumentStatus (void) const
189  {  {
190      return m_iInstrumentStatus;          return m_iInstrumentStatus;
191  }  }
192    
193  // Instrument file loader.  // Instrument file loader.
194  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
195  {  {
196      if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
197          return false;          if (pMainForm == NULL)
198                    return false;
199            if (pMainForm->client() == NULL || m_iChannelID < 0)
200                    return false;
201            if (!isInstrumentFile(sInstrumentFile))
202                    return false;
203            if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)
204                    return true;
205    
206            if (
207                    ::lscp_load_instrument_non_modal(
208                            pMainForm->client(),
209                            lscpEscapePath(sInstrumentFile).latin1(),
210                            iInstrumentNr, m_iChannelID
211                    ) != LSCP_OK
212            ) {
213                    appendMessagesClient("lscp_load_instrument");
214                    return false;
215            }
216    
217            appendMessages(QObject::tr("Instrument: \"%1\" (%2).")
218                    .arg(sInstrumentFile).arg(iInstrumentNr));
219    
220            return setInstrument(sInstrumentFile, iInstrumentNr);
221    }
222    
223    
224      if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {  // Special instrument file/name/number settler.
225          appendMessagesClient("lscp_load_instrument");  bool qsamplerChannel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
226          return false;  {
227      }          m_sInstrumentFile = sInstrumentFile;
228            m_iInstrumentNr = iInstrumentNr;
229      m_sInstrumentFile = sInstrumentFile;  #ifdef CONFIG_INSTRUMENT_NAME
230      m_iInstrumentNr = iInstrumentNr;          m_sInstrumentName = QString::null;  // We'll get it, maybe later, on channel_info...
231      m_iInstrumentStatus = 0;  #else
232            m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);
233    #endif
234            m_iInstrumentStatus = 0;
235    
236      return true;          return true;
237  }  }
238    
239    
240  // MIDI driver type accessors (DEPRECATED).  // MIDI driver type accessors (DEPRECATED).
241  QString& qsamplerChannel::midiDriver (void)  const QString& qsamplerChannel::midiDriver (void) const
242  {  {
243      return m_sMidiDriver;          return m_sMidiDriver;
244  }  }
245    
246  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
247  {  {
248      if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
249          return false;          if (pMainForm == NULL)
250                    return false;
251            if (pMainForm->client() == NULL || m_iChannelID < 0)
252                    return false;
253            if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
254                    return true;
255    
256            if (::lscp_set_channel_midi_type(pMainForm->client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {
257                    appendMessagesClient("lscp_set_channel_midi_type");
258                    return false;
259            }
260    
261      if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {          appendMessages(QObject::tr("MIDI driver: %1.").arg(sMidiDriver));
         appendMessagesClient("lscp_set_channel_midi_type");  
         return false;  
     }  
262    
263      m_sMidiDriver = sMidiDriver;          m_sMidiDriver = sMidiDriver;
264      return true;          return true;
265  }  }
266    
267    
268  // MIDI device accessors.  // MIDI device accessors.
269  int qsamplerChannel::midiDevice (void)  int qsamplerChannel::midiDevice (void) const
270  {  {
271      return m_iMidiDevice;          return m_iMidiDevice;
272  }  }
273    
274  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
275  {  {
276      if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
277          return false;          if (pMainForm == NULL)
278                    return false;
279            if (pMainForm->client() == NULL || m_iChannelID < 0)
280                    return false;
281            if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)
282                    return true;
283    
284            if (::lscp_set_channel_midi_device(pMainForm->client(), m_iChannelID, iMidiDevice) != LSCP_OK) {
285                    appendMessagesClient("lscp_set_channel_midi_device");
286                    return false;
287            }
288    
289      if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {          appendMessages(QObject::tr("MIDI device: %1.").arg(iMidiDevice));
         appendMessagesClient("lscp_set_channel_midi_device");  
         return false;  
     }  
290    
291      m_iMidiDevice = iMidiDevice;          m_iMidiDevice = iMidiDevice;
292      return true;          return true;
293  }  }
294    
295    
296  // MIDI port number accessor.  // MIDI port number accessor.
297  int qsamplerChannel::midiPort (void)  int qsamplerChannel::midiPort (void) const
298  {  {
299      return m_iMidiPort;          return m_iMidiPort;
300  }  }
301    
302  bool qsamplerChannel::setMidiPort ( int iMidiPort )  bool qsamplerChannel::setMidiPort ( int iMidiPort )
303  {  {
304      if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
305          return false;          if (pMainForm == NULL)
306                    return false;
307            if (pMainForm->client() == NULL || m_iChannelID < 0)
308                    return false;
309            if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)
310                    return true;
311    
312            if (::lscp_set_channel_midi_port(pMainForm->client(), m_iChannelID, iMidiPort) != LSCP_OK) {
313                    appendMessagesClient("lscp_set_channel_midi_port");
314                    return false;
315            }
316    
317      if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {          appendMessages(QObject::tr("MIDI port: %1.").arg(iMidiPort));
         appendMessagesClient("lscp_set_channel_midi_port");  
         return false;  
     }  
318    
319      m_iMidiPort = iMidiPort;          m_iMidiPort = iMidiPort;
320      return true;          return true;
321  }  }
322    
323    
324  // MIDI channel accessor.  // MIDI channel accessor.
325  int qsamplerChannel::midiChannel (void)  int qsamplerChannel::midiChannel (void) const
326  {  {
327      return m_iMidiChannel;          return m_iMidiChannel;
328  }  }
329    
330  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
331  {  {
332      if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
333          return false;          if (pMainForm == NULL)
334                    return false;
335            if (pMainForm->client() == NULL || m_iChannelID < 0)
336                    return false;
337            if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)
338                    return true;
339    
340            if (::lscp_set_channel_midi_channel(pMainForm->client(), m_iChannelID, iMidiChannel) != LSCP_OK) {
341                    appendMessagesClient("lscp_set_channel_midi_channel");
342                    return false;
343            }
344    
345            appendMessages(QObject::tr("MIDI channel: %1.").arg(iMidiChannel));
346    
347            m_iMidiChannel = iMidiChannel;
348            return true;
349    }
350    
351    
352      if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {  // MIDI instrument map accessor.
353          appendMessagesClient("lscp_set_channel_midi_channel");  int qsamplerChannel::midiMap (void) const
354          return false;  {
355      }          return m_iMidiMap;
356    }
357    
358    bool qsamplerChannel::setMidiMap ( int iMidiMap )
359    {
360            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
361            if (pMainForm == NULL)
362                    return false;
363            if (pMainForm->client() == NULL || m_iChannelID < 0)
364                    return false;
365            if (m_iInstrumentStatus == 100 && m_iMidiMap == iMidiMap)
366                    return true;
367    #ifdef CONFIG_MIDI_INSTRUMENT
368            if (::lscp_set_channel_midi_map(pMainForm->client(), m_iChannelID, iMidiMap) != LSCP_OK) {
369                    appendMessagesClient("lscp_set_channel_midi_map");
370                    return false;
371            }
372    #endif
373            appendMessages(QObject::tr("MIDI map: %1.").arg(iMidiMap));
374    
375      m_iMidiChannel = iMidiChannel;          m_iMidiMap = iMidiMap;
376      return true;          return true;
377  }  }
378    
379    
380  // Audio device accessor.  // Audio device accessor.
381  int qsamplerChannel::audioDevice (void)  int qsamplerChannel::audioDevice (void) const
382  {  {
383      return m_iAudioDevice;          return m_iAudioDevice;
384  }  }
385    
386  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
387  {  {
388      if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
389          return false;          if (pMainForm == NULL)
390                    return false;
391            if (pMainForm->client() == NULL || m_iChannelID < 0)
392                    return false;
393            if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)
394                    return true;
395    
396            if (::lscp_set_channel_audio_device(pMainForm->client(), m_iChannelID, iAudioDevice) != LSCP_OK) {
397                    appendMessagesClient("lscp_set_channel_audio_device");
398                    return false;
399            }
400    
401      if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {          appendMessages(QObject::tr("Audio device: %1.").arg(iAudioDevice));
         appendMessagesClient("lscp_set_channel_audio_device");  
         return false;  
     }  
402    
403      m_iAudioDevice = iAudioDevice;          m_iAudioDevice = iAudioDevice;
404      return true;          return true;
405  }  }
406    
407    
408  // Audio driver type accessors (DEPRECATED).  // Audio driver type accessors (DEPRECATED).
409  QString& qsamplerChannel::audioDriver (void)  const QString& qsamplerChannel::audioDriver (void) const
410  {  {
411      return m_sAudioDriver;          return m_sAudioDriver;
412  }  }
413    
414  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
415  {  {
416      if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
417          return false;          if (pMainForm == NULL)
418                    return false;
419            if (pMainForm->client() == NULL || m_iChannelID < 0)
420                    return false;
421            if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
422                    return true;
423    
424            if (::lscp_set_channel_audio_type(pMainForm->client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {
425                    appendMessagesClient("lscp_set_channel_audio_type");
426                    return false;
427            }
428    
429      if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {          appendMessages(QObject::tr("Audio driver: %1.").arg(sAudioDriver));
         appendMessagesClient("lscp_set_channel_audio_type");  
         return false;  
     }  
430    
431      m_sAudioDriver = sAudioDriver;          m_sAudioDriver = sAudioDriver;
432      return true;          return true;
433  }  }
434    
435    
436  // Channel volume accessors.  // Channel volume accessors.
437  float qsamplerChannel::volume (void)  float qsamplerChannel::volume (void) const
438  {  {
439      return m_fVolume;          return m_fVolume;
440  }  }
441    
442  bool qsamplerChannel::setVolume ( float fVolume )  bool qsamplerChannel::setVolume ( float fVolume )
443  {  {
444      if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
445          return false;          if (pMainForm == NULL)
446                    return false;
447            if (pMainForm->client() == NULL || m_iChannelID < 0)
448                    return false;
449            if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)
450                    return true;
451    
452            if (::lscp_set_channel_volume(pMainForm->client(), m_iChannelID, fVolume) != LSCP_OK) {
453                    appendMessagesClient("lscp_set_channel_volume");
454                    return false;
455            }
456    
457            appendMessages(QObject::tr("Volume: %1.").arg(fVolume));
458    
459            m_fVolume = fVolume;
460            return true;
461    }
462    
463    
464    // Sampler channel mute state.
465    bool qsamplerChannel::channelMute (void) const
466    {
467            return m_bMute;
468    }
469    
470    bool qsamplerChannel::setChannelMute ( bool bMute )
471    {
472            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
473            if (pMainForm == NULL)
474                    return false;
475            if (pMainForm->client() == NULL || m_iChannelID < 0)
476                    return false;
477            if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))
478                    return true;
479    
480    #ifdef CONFIG_MUTE_SOLO
481            if (::lscp_set_channel_mute(pMainForm->client(), m_iChannelID, bMute) != LSCP_OK) {
482                    appendMessagesClient("lscp_set_channel_mute");
483                    return false;
484            }
485            appendMessages(QObject::tr("Mute: %1.").arg((int) bMute));
486            m_bMute = bMute;
487            return true;
488    #else
489            return false;
490    #endif
491    }
492    
493    
494    // Sampler channel solo state.
495    bool qsamplerChannel::channelSolo (void) const
496    {
497            return m_bSolo;
498    }
499    
500    bool qsamplerChannel::setChannelSolo ( bool bSolo )
501    {
502            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
503            if (pMainForm == NULL)
504                    return false;
505            if (pMainForm->client() == NULL || m_iChannelID < 0)
506                    return false;
507            if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))
508                    return true;
509    
510      if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {  #ifdef CONFIG_MUTE_SOLO
511          appendMessagesClient("lscp_set_channel_volume");          if (::lscp_set_channel_solo(pMainForm->client(), m_iChannelID, bSolo) != LSCP_OK) {
512          return false;                  appendMessagesClient("lscp_set_channel_solo");
513      }                  return false;
514            }
515            appendMessages(QObject::tr("Solo: %1.").arg((int) bSolo));
516            m_bSolo = bSolo;
517            return true;
518    #else
519            return false;
520    #endif
521    }
522    
523      m_fVolume = fVolume;  
524      return true;  // Audio routing accessors.
525    int qsamplerChannel::audioChannel ( int iAudioOut ) const
526    {
527            return m_audioRouting[iAudioOut];
528    }
529    
530    bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )
531    {
532            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
533            if (pMainForm == NULL)
534                    return false;
535            if (pMainForm->client() == NULL || m_iChannelID < 0)
536                    return false;
537            if (m_iInstrumentStatus == 100 &&
538                            m_audioRouting[iAudioOut] == iAudioIn)
539                    return true;
540    
541            if (::lscp_set_channel_audio_channel(pMainForm->client(),
542                            m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) {
543                    appendMessagesClient("lscp_set_channel_audio_channel");
544                    return false;
545            }
546    
547            appendMessages(QObject::tr("Audio Channel: %1 -> %2.")
548                    .arg(iAudioOut).arg(iAudioIn));
549    
550            m_audioRouting[iAudioOut] = iAudioIn;
551            return true;
552    }
553    
554    // The audio routing map itself.
555    const qsamplerChannelRoutingMap& qsamplerChannel::audioRouting (void) const
556    {
557            return m_audioRouting;
558    }
559    
560    
561    // Istrument name remapper.
562    void qsamplerChannel::updateInstrumentName (void)
563    {
564    #ifndef CONFIG_INSTRUMENT_NAME
565            m_sInstrumentName = getInstrumentName(m_sInstrumentFile,
566                    m_iInstrumentNr, (options() && options()->bInstrumentNames));
567    #endif
568  }  }
569    
570    
571  // Update whole channel info state.  // Update whole channel info state.
572  bool qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
573  {  {
574      if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
575          return false;          if (pMainForm == NULL)
576                    return false;
577      // Read channel information.          if (pMainForm->client() == NULL || m_iChannelID < 0)
578      lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);                  return false;
579      if (pChannelInfo == NULL) {  
580          appendMessagesClient("lscp_get_channel_info");          // Read channel information.
581          appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));          lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(pMainForm->client(), m_iChannelID);
582          return false;          if (pChannelInfo == NULL) {
583      }                  appendMessagesClient("lscp_get_channel_info");
584                    appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
585      // Cache in channel information.                  return false;
586      m_sEngineName       = pChannelInfo->engine_name;          }
587      m_sInstrumentFile   = pChannelInfo->instrument_file;  
588      m_iInstrumentNr     = pChannelInfo->instrument_nr;  #ifdef CONFIG_INSTRUMENT_NAME
589      m_iInstrumentStatus = pChannelInfo->instrument_status;          // We got all actual instrument datum...
590      m_iMidiDevice       = pChannelInfo->midi_device;          m_sInstrumentFile = pChannelInfo->instrument_file;
591      m_iMidiPort         = pChannelInfo->midi_port;          m_iInstrumentNr   = pChannelInfo->instrument_nr;
592      m_iMidiChannel      = pChannelInfo->midi_channel;          m_sInstrumentName = pChannelInfo->instrument_name;
593      m_iAudioDevice      = pChannelInfo->audio_device;  #else
594      m_fVolume           = pChannelInfo->volume;          // First, check if intrument name has changed,
595      // Some sanity checks.          // taking care that instrument name lookup might be expensive,
596      if (m_sEngineName == "NONE")          // so we better make it only once and when really needed...
597          m_sEngineName = QString::null;          if ((m_sInstrumentFile != pChannelInfo->instrument_file) ||
598      if (m_sInstrumentFile == "NONE")                  (m_iInstrumentNr   != pChannelInfo->instrument_nr)) {
599          m_sInstrumentFile = QString::null;                  m_sInstrumentFile = pChannelInfo->instrument_file;
600                    m_iInstrumentNr   = pChannelInfo->instrument_nr;
601                    updateInstrumentName();
602            }
603    #endif
604            // Cache in other channel information.
605            m_sEngineName       = pChannelInfo->engine_name;
606            m_iInstrumentStatus = pChannelInfo->instrument_status;
607            m_iMidiDevice       = pChannelInfo->midi_device;
608            m_iMidiPort         = pChannelInfo->midi_port;
609            m_iMidiChannel      = pChannelInfo->midi_channel;
610    #ifdef CONFIG_MIDI_INSTRUMENT
611            m_iMidiMap          = pChannelInfo->midi_map;
612    #endif
613            m_iAudioDevice      = pChannelInfo->audio_device;
614            m_fVolume           = pChannelInfo->volume;
615    #ifdef CONFIG_MUTE_SOLO
616            m_bMute             = pChannelInfo->mute;
617            m_bSolo             = pChannelInfo->solo;
618    #endif
619            // Some sanity checks.
620            if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())
621                    m_sEngineName = QString::null;
622            if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) {
623                    m_sInstrumentFile = QString::null;
624                    m_sInstrumentName = QString::null;
625            }
626    
627            // Time for device info grabbing...
628            lscp_device_info_t *pDeviceInfo;
629            const QString sNone = QObject::tr("(none)");
630            // Audio device driver type.
631            pDeviceInfo = ::lscp_get_audio_device_info(pMainForm->client(), m_iAudioDevice);
632            if (pDeviceInfo == NULL) {
633                    appendMessagesClient("lscp_get_audio_device_info");
634                    m_sAudioDriver = sNone;
635            } else {
636                    m_sAudioDriver = pDeviceInfo->driver;
637            }
638            // MIDI device driver type.
639            pDeviceInfo = ::lscp_get_midi_device_info(pMainForm->client(), m_iMidiDevice);
640            if (pDeviceInfo == NULL) {
641                    appendMessagesClient("lscp_get_midi_device_info");
642                    m_sMidiDriver = sNone;
643            } else {
644                    m_sMidiDriver = pDeviceInfo->driver;
645            }
646    
647            // Set the audio routing map.
648            m_audioRouting.clear();
649    #ifdef CONFIG_AUDIO_ROUTING
650            int *piAudioRouting = pChannelInfo->audio_routing;
651            for (int i = 0; piAudioRouting && piAudioRouting[i] >= 0; i++)
652                    m_audioRouting[i] = piAudioRouting[i];
653    #else
654            char **ppszAudioRouting = pChannelInfo->audio_routing;
655            for (int i = 0; ppszAudioRouting && ppszAudioRouting[i]; i++)
656                    m_audioRouting[i] = ::atoi(ppszAudioRouting[i]);
657    #endif
658    
659      return true;          return true;
660  }  }
661    
662    
663  // Reset channel method.  // Reset channel method.
664  bool qsamplerChannel::resetChannel (void)  bool qsamplerChannel::channelReset (void)
665    {
666            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
667            if (pMainForm == NULL)
668                    return false;
669            if (pMainForm->client() == NULL || m_iChannelID < 0)
670                    return false;
671    
672            if (::lscp_reset_channel(pMainForm->client(), m_iChannelID) != LSCP_OK) {
673                    appendMessagesClient("lscp_reset_channel");
674                    return false;
675            }
676    
677            appendMessages(QObject::tr("reset."));
678    
679            return true;
680    }
681    
682    
683    // Spawn instrument editor method.
684    bool qsamplerChannel::editChannel (void)
685    {
686    #ifdef CONFIG_EDIT_INSTRUMENT
687    
688            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
689            if (pMainForm == NULL)
690                    return false;
691            if (pMainForm->client() == NULL || m_iChannelID < 0)
692                    return false;
693    
694            if (::lscp_edit_instrument(pMainForm->client(), m_iChannelID) != LSCP_OK) {
695                    appendMessagesClient("lscp_edit_instrument");
696                    appendMessagesError(QObject::tr(
697                            "Could not launch an appropriate instrument editor "
698                            "for the given instrument!\n"
699                            "Make sure you have an appropriate "
700                            "instrument editor like 'gigedit' installed\n"
701                            "and that it placed its mandatory DLL file "
702                            "into the sampler's plugin directory.")
703                    );
704                    return false;
705            }
706    
707            appendMessages(QObject::tr("edit instrument."));
708    
709            return true;
710    
711    #else
712    
713            appendMessagesError(QObject::tr(
714                    "Sorry, QSampler was compiled for a version of liblscp "
715                    "which lacks this feature.\n"
716                    "You may want to update liblscp and recompile QSampler afterwards.")
717            );
718    
719            return false;
720    
721    #endif
722    }
723    
724    
725    // Channel setup dialog form.
726    bool qsamplerChannel::channelSetup ( QWidget *pParent )
727  {  {
728      if (client() == NULL || m_iChannelID < 0)          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
729          return false;          if (pMainForm == NULL)
730                    return false;
731    
732            bool bResult = false;
733    
734            appendMessages(QObject::tr("setup..."));
735    
736      if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) {          qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent);
737          appendMessagesClient("lscp_reset_channel");          if (pChannelForm) {
738          return false;                  pChannelForm->setup(this);
739      }                  bResult = pChannelForm->exec();
740                    delete pChannelForm;
741            }
742    
743      appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID));          return bResult;
     return true;  
744  }  }
745    
746    
747  // Redirected messages output methods.  // Redirected messages output methods.
748  void qsamplerChannel::appendMessages( const QString& s )  void qsamplerChannel::appendMessages( const QString& s ) const
749    {
750            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
751            if (pMainForm)
752                    pMainForm->appendMessages(channelName() + ' ' + s);
753    }
754    
755    void qsamplerChannel::appendMessagesColor( const QString& s,
756            const QString& c ) const
757    {
758            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
759            if (pMainForm)
760                    pMainForm->appendMessagesColor(channelName() + ' ' + s, c);
761    }
762    
763    void qsamplerChannel::appendMessagesText( const QString& s ) const
764    {
765            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
766            if (pMainForm)
767                    pMainForm->appendMessagesText(channelName() + ' ' + s);
768    }
769    
770    void qsamplerChannel::appendMessagesError( const QString& s ) const
771    {
772            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
773            if (pMainForm)
774                    pMainForm->appendMessagesError(channelName() + "\n\n" + s);
775    }
776    
777    void qsamplerChannel::appendMessagesClient( const QString& s ) const
778    {
779            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
780            if (pMainForm)
781                    pMainForm->appendMessagesClient(channelName() + ' ' + s);
782    }
783    
784    
785    // Context menu event handler.
786    void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )
787    {
788            qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();
789            if (pMainForm)
790                    pMainForm->contextMenuEvent(pEvent);
791    }
792    
793    
794    // FIXME: Check whether a given file is an instrument file.
795    bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile )
796    {
797            bool bResult = false;
798    
799            QFile file(sInstrumentFile);
800            if (file.open(IO_ReadOnly)) {
801                    char achHeader[16];
802                    if (file.readBlock(achHeader, 16)) {
803                            bResult = (::memcmp(&achHeader[0], "RIFF", 4)     == 0
804                                            && ::memcmp(&achHeader[8], "DLS LIST", 8) == 0);
805                    }
806                    file.close();
807            }
808    
809            return bResult;
810    }
811    
812    
813    // Retrieve the instrument list of a instrument file (.gig).
814    QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile,
815            bool bInstrumentNames )
816    {
817            QString sInstrumentName = QFileInfo(sInstrumentFile).fileName();
818            QStringList instlist;
819    
820            if (isInstrumentFile(sInstrumentFile)) {
821    #ifdef CONFIG_LIBGIG
822                    if (bInstrumentNames) {
823                            RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());
824                            gig::File  *pGig  = new gig::File(pRiff);
825                            gig::Instrument *pInstrument = pGig->GetFirstInstrument();
826                            while (pInstrument) {
827                                    instlist.append((pInstrument->pInfo)->Name.c_str());
828                                    pInstrument = pGig->GetNextInstrument();
829                            }
830                            delete pGig;
831                            delete pRiff;
832                    }
833                    else
834    #endif
835                    for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)
836                            instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");
837            }
838            else instlist.append(noInstrumentName());
839    
840            return instlist;
841    }
842    
843    
844    // Retrieve the spacific instrument name of a instrument file (.gig), given its index.
845    QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile,
846            int iInstrumentNr, bool bInstrumentNames )
847    {
848            QString sInstrumentName;
849    
850            if (isInstrumentFile(sInstrumentFile)) {
851                    sInstrumentName = QFileInfo(sInstrumentFile).fileName();
852    #ifdef CONFIG_LIBGIG
853                    if (bInstrumentNames) {
854                            RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());
855                            gig::File  *pGig  = new gig::File(pRiff);
856                            int iIndex = 0;
857                            gig::Instrument *pInstrument = pGig->GetFirstInstrument();
858                            while (pInstrument) {
859                                    if (iIndex == iInstrumentNr) {
860                                            sInstrumentName = (pInstrument->pInfo)->Name.c_str();
861                                            break;
862                                    }
863                                    iIndex++;
864                                    pInstrument = pGig->GetNextInstrument();
865                            }
866                            delete pGig;
867                            delete pRiff;
868                    }
869                    else
870    #endif
871                    sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
872            }
873            else sInstrumentName = noInstrumentName();
874    
875            return sInstrumentName;
876    }
877    
878    
879    // Common invalid name-helpers.
880    QString qsamplerChannel::noEngineName (void)
881  {  {
882      m_pMainForm->appendMessages(s);          return QObject::tr("(No engine)");
883  }  }
884    
885  void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c )  QString qsamplerChannel::noInstrumentName (void)
886  {  {
887      m_pMainForm->appendMessagesColor(s, c);          return QObject::tr("(No instrument)");
888    }
889    
890    QString qsamplerChannel::loadingInstrument (void) {
891            return QObject::tr("(Loading instrument...)");
892    }
893    
894    
895    
896    //-------------------------------------------------------------------------
897    // qsamplerChannelRoutingTable - Channel routing table.
898    //
899    
900    // Constructor.
901    qsamplerChannelRoutingTable::qsamplerChannelRoutingTable (
902            QWidget *pParent, const char *pszName )
903            : QTable(pParent, pszName)
904    {
905            // Set fixed number of columns.
906            QTable::setNumCols(2);
907            QTable::setShowGrid(false);
908            QTable::setSorting(false);
909            QTable::setFocusStyle(QTable::FollowStyle);
910            QTable::setSelectionMode(QTable::NoSelection);
911            // No vertical header.
912            QTable::verticalHeader()->hide();
913            QTable::setLeftMargin(0);
914            // Initialize the fixed table column headings.
915            QHeader *pHeader = QTable::horizontalHeader();
916            pHeader->setLabel(0, tr("Sampler Channel"));
917            pHeader->setLabel(1, tr("Device Channel"));
918            // Set read-onlyness of each column
919            QTable::setColumnReadOnly(0, true);
920    //      QTable::setColumnReadOnly(1, false); -- of course not.
921            QTable::setColumnStretchable(1, true);
922    }
923    
924    // Default destructor.
925    qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void)
926    {
927    }
928    
929    
930    // Routing map table renderer.
931    void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice,
932            const qsamplerChannelRoutingMap& routing )
933    {
934            if (pDevice == NULL)
935                    return;
936    
937            // Always (re)start it empty.
938            QTable::setUpdatesEnabled(false);
939            QTable::setNumRows(0);
940    
941            // The common device port item list.
942            QStringList opts;
943            qsamplerDevicePortList& ports = pDevice->ports();
944            qsamplerDevicePort *pPort;
945            for (pPort = ports.first(); pPort; pPort = ports.next()) {
946                    opts.append(pDevice->deviceTypeName()
947                            + ' ' + pDevice->driverName()
948                            + ' ' + pPort->portName());
949            }
950    
951            // Those items shall have a proper pixmap...
952            QPixmap pmChannel = QPixmap::fromMimeSource("qsamplerChannel.png");
953            QPixmap pmDevice;
954            switch (pDevice->deviceType()) {
955            case qsamplerDevice::Audio:
956                    pmDevice = QPixmap::fromMimeSource("audio2.png");
957                    break;
958            case qsamplerDevice::Midi:
959                    pmDevice = QPixmap::fromMimeSource("midi2.png");
960                    break;
961            case qsamplerDevice::None:
962                    break;
963            }
964    
965            // Fill the routing table...
966            QTable::insertRows(0, routing.count());
967            int iRow = 0;
968            qsamplerChannelRoutingMap::ConstIterator iter;
969            for (iter = routing.begin(); iter != routing.end(); ++iter) {
970                    QTable::setPixmap(iRow, 0, pmChannel);
971                    QTable::setText(iRow, 0, pDevice->deviceTypeName()
972                            + ' ' + QString::number(iter.key()));
973                    qsamplerChannelRoutingComboBox *pComboItem =
974                            new qsamplerChannelRoutingComboBox(this, opts, pmDevice);
975                    pComboItem->setCurrentItem(iter.data());
976                    QTable::setItem(iRow, 1, pComboItem);
977                    ++iRow;
978            }
979    
980            // Adjust optimal column widths.
981            QTable::adjustColumn(0);
982            QTable::adjustColumn(1);
983    
984            QTable::setUpdatesEnabled(true);
985            QTable::updateContents();
986    }
987    
988    
989    // Commit any pending editing.
990    void qsamplerChannelRoutingTable::flush (void)
991    {
992            if (QTable::isEditing())
993                QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true);
994    }
995    
996    
997    //-------------------------------------------------------------------------
998    // qsamplerChannelRoutingComboBox - Custom combo box for routing table.
999    //
1000    
1001    // Constructor.
1002    qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox (
1003            QTable *pTable, const QStringList& list, const QPixmap& pixmap )
1004            : QTableItem(pTable, QTableItem::WhenCurrent, QString::null, pixmap),
1005            m_list(list)
1006    {
1007            m_iCurrentItem = 0;
1008    }
1009    
1010    // Public accessors.
1011    void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem )
1012    {
1013            m_iCurrentItem = iCurrentItem;
1014    
1015            QTableItem::setText(m_list[iCurrentItem]);
1016  }  }
1017    
1018  void qsamplerChannel::appendMessagesText( const QString& s )  int qsamplerChannelRoutingComboBox::currentItem (void) const
1019  {  {
1020      m_pMainForm->appendMessagesText(s);          return m_iCurrentItem;
1021  }  }
1022    
1023  void qsamplerChannel::appendMessagesError( const QString& s )  // Virtual implemetations.
1024    QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const
1025  {  {
1026      m_pMainForm->appendMessagesError(s);          QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport());
1027            QObject::connect(pComboBox, SIGNAL(activated(int)),
1028                    QTableItem::table(), SLOT(doValueChanged()));
1029            for (QStringList::ConstIterator iter = m_list.begin();
1030                            iter != m_list.end(); iter++) {
1031                    pComboBox->insertItem(QTableItem::pixmap(), *iter);
1032            }
1033            pComboBox->setCurrentItem(m_iCurrentItem);
1034            return pComboBox;
1035  }  }
1036    
1037  void qsamplerChannel::appendMessagesClient( const QString& s )  void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget )
1038  {  {
1039      m_pMainForm->appendMessagesClient(s);          if (pWidget->inherits("QComboBox")) {
1040                    QComboBox *pComboBox = (QComboBox *) pWidget;
1041                    m_iCurrentItem = pComboBox->currentItem();
1042                    QTableItem::setText(pComboBox->currentText());
1043            }
1044            else QTableItem::setContentFromEditor(pWidget);
1045  }  }
1046    
1047    

Legend:
Removed from v.295  
changed lines
  Added in v.1386

  ViewVC Help
Powered by ViewVC