/[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 303 by capela, Fri Nov 19 10:18:59 2004 UTC revision 758 by capela, Sun Aug 28 00:31:34 2005 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) 2003-2005, 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 19  Line 19 
19    
20  *****************************************************************************/  *****************************************************************************/
21    
22    #include "qsamplerAbout.h"
23  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
24    
25  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
26  #include "qsamplerChannelForm.h"  #include "qsamplerChannelForm.h"
27    
 #include "config.h"  
   
28  #include <qfileinfo.h>  #include <qfileinfo.h>
29    
30  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
31  #include "gig.h"  #include "gig.h"
 #else  
 #define QSAMPLER_INSTRUMENT_MAX 8  
32  #endif  #endif
33    
34    #define QSAMPLER_INSTRUMENT_MAX 8
35    
36    
37  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
38  // qsamplerChannel - Sampler channel structure.  // qsamplerChannel - Sampler channel structure.
# Line 42  Line 41 
41  // Constructor.  // Constructor.
42  qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )  qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )
43  {  {
44      m_pMainForm  = pMainForm;          m_pMainForm  = pMainForm;
45      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;  
46    
47    //  m_sEngineName       = noEngineName();
48    //  m_sInstrumentName   = noInstrumentName();
49    //  m_sInstrumentFile   = m_sInstrumentName;
50            m_iInstrumentNr     = -1;
51            m_iInstrumentStatus = -1;
52            m_sMidiDriver       = "ALSA";
53            m_iMidiDevice       = -1;
54            m_iMidiPort         = -1;
55            m_iMidiChannel      = -1;
56            m_sAudioDriver      = "ALSA";
57            m_iAudioDevice      = -1;
58            m_fVolume           = 0.0;
59            m_bMute             = false;
60            m_bSolo             = false;
61  }  }
62    
63  // Default destructor.  // Default destructor.
# Line 65  qsamplerChannel::~qsamplerChannel (void) Line 66  qsamplerChannel::~qsamplerChannel (void)
66  }  }
67    
68    
69    // Main application form accessor.
70    qsamplerMainForm *qsamplerChannel::mainForm(void) const
71    {
72            return m_pMainForm;
73    }
74    
75    
76  // The global options settings delegated property.  // The global options settings delegated property.
77  qsamplerOptions *qsamplerChannel::options (void)  qsamplerOptions *qsamplerChannel::options (void) const
78  {  {
79      if (m_pMainForm == NULL)          if (m_pMainForm == NULL)
80          return NULL;                  return NULL;
81    
82      return m_pMainForm->options();          return m_pMainForm->options();
83  }  }
84    
85    
86  // The client descriptor delegated property.  // The client descriptor delegated property.
87  lscp_client_t *qsamplerChannel::client (void)  lscp_client_t *qsamplerChannel::client (void) const
88  {  {
89      if (m_pMainForm == NULL)          if (m_pMainForm == NULL)
90          return NULL;                  return NULL;
91    
92      return m_pMainForm->client();          return m_pMainForm->client();
93  }  }
94    
95    
96  // Create a new sampler channel, if not already.  // Create a new sampler channel, if not already.
97  bool qsamplerChannel::addChannel (void)  bool qsamplerChannel::addChannel (void)
98  {  {
99      if (client() == NULL)          if (client() == NULL)
100          return false;                  return false;
101    
102      // Are we a new channel?          // Are we a new channel?
103      if (m_iChannelID < 0) {          if (m_iChannelID < 0) {
104          m_iChannelID = ::lscp_add_channel(client());                  m_iChannelID = ::lscp_add_channel(client());
105          if (m_iChannelID < 0) {                  if (m_iChannelID < 0) {
106              appendMessagesClient("lscp_add_channel");                          appendMessagesClient("lscp_add_channel");
107              appendMessagesError(QObject::tr("Could not create the new channel.\n\nSorry."));                          appendMessagesError(QObject::tr("Could not add channel.\n\nSorry."));
108          }   // Otherwise it's created...                  }   // Otherwise it's created...
109          else appendMessages(QObject::tr("Channel %1 created.").arg(m_iChannelID));                  else appendMessages(QObject::tr("added."));
110      }          }
111    
112      // Return whether we're a valid channel...          // Return whether we're a valid channel...
113      return (m_iChannelID >= 0);          return (m_iChannelID >= 0);
114  }  }
115    
116    
117  // Remove sampler channel.  // Remove sampler channel.
118  bool qsamplerChannel::removeChannel (void)  bool qsamplerChannel::removeChannel (void)
119  {  {
120      if (client() == NULL)          if (client() == NULL)
121          return false;                  return false;
122    
123      // Are we an existing channel?          // Are we an existing channel?
124      if (m_iChannelID >= 0) {          if (m_iChannelID >= 0) {
125          if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) {                  if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) {
126              appendMessagesClient("lscp_remove_channel");                          appendMessagesClient("lscp_remove_channel");
127              appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));                          appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));
128          } else {                  } else {
129              // Otherwise it's removed.                          // Otherwise it's removed.
130              appendMessages(QObject::tr("Channel %1 removed.").arg(m_iChannelID));                          appendMessages(QObject::tr("removed."));
131              m_iChannelID = -1;                          m_iChannelID = -1;
132          }                  }
133      }          }
134        
135      // Return whether we've removed the channel...          // Return whether we've removed the channel...
136      return (m_iChannelID < 0);          return (m_iChannelID < 0);
137  }  }
138    
139    
140  // Channel-ID (aka Sammpler-Channel) accessors.  // Channel-ID (aka Sammpler-Channel) accessors.
141  int qsamplerChannel::channelID (void)  int qsamplerChannel::channelID (void) const
142  {  {
143      return m_iChannelID;          return m_iChannelID;
144  }  }
145    
146  void qsamplerChannel::setChannelID ( int iChannelID )  void qsamplerChannel::setChannelID ( int iChannelID )
147  {  {
148      m_iChannelID = iChannelID;          m_iChannelID = iChannelID;
149  }  }
150    
151    
152  // Readable channel name.  // Readable channel name.
153  QString qsamplerChannel::channelName (void)  QString qsamplerChannel::channelName (void) const
154  {  {
155      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));
156  }  }
157    
158    
159  // Engine name accessors.  // Engine name accessors.
160  QString& qsamplerChannel::engineName (void)  const QString& qsamplerChannel::engineName (void) const
161  {  {
162      return m_sEngineName;          return m_sEngineName;
163  }  }
164    
165  bool qsamplerChannel::loadEngine ( const QString& sEngineName )  bool qsamplerChannel::loadEngine ( const QString& sEngineName )
166  {  {
167      if (client() == NULL || m_iChannelID < 0)          if (client() == NULL || m_iChannelID < 0)
168          return false;                  return false;
169            if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
170      if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {                  return true;
171          appendMessagesClient("lscp_load_engine");  
172          return false;          if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {
173      }                  appendMessagesClient("lscp_load_engine");
174                    return false;
175            }
176            appendMessages(QObject::tr("Engine: %1.").arg(sEngineName));
177    
178      m_sEngineName = sEngineName;          m_sEngineName = sEngineName;
179      return true;          return true;
180  }  }
181    
182    
183  // Instrument filename accessor.  // Instrument filename accessor.
184  QString& qsamplerChannel::instrumentFile (void)  const QString& qsamplerChannel::instrumentFile (void) const
185  {  {
186      return m_sInstrumentFile;          return m_sInstrumentFile;
187  }  }
188    
189  // Instrument index accessor.  // Instrument index accessor.
190  int qsamplerChannel::instrumentNr (void)  int qsamplerChannel::instrumentNr (void) const
191  {  {
192      return m_iInstrumentNr;          return m_iInstrumentNr;
193    }
194    
195    // Instrument name accessor.
196    const QString& qsamplerChannel::instrumentName (void) const
197    {
198            return m_sInstrumentName;
199  }  }
200    
201  // Instrument status accessor.  // Instrument status accessor.
202  int qsamplerChannel::instrumentStatus (void)  int qsamplerChannel::instrumentStatus (void) const
203  {  {
204      return m_iInstrumentStatus;          return m_iInstrumentStatus;
205  }  }
206    
207  // Instrument file loader.  // Instrument file loader.
208  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
209  {  {
210      if (client() == NULL || m_iChannelID < 0)          if (client() == NULL || m_iChannelID < 0)
211          return false;                  return false;
212            if (!isInstrumentFile(sInstrumentFile))
213                    return false;
214            if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr)
215                    return true;
216    
217            if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {
218                    appendMessagesClient("lscp_load_instrument");
219                    return false;
220            }
221    
222            appendMessages(QObject::tr("Instrument: \"%1\" (%2).")
223                    .arg(sInstrumentFile).arg(iInstrumentNr));
224    
225            return setInstrument(sInstrumentFile, iInstrumentNr);
226    }
227    
     if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {  
         appendMessagesClient("lscp_load_instrument");  
         return false;  
     }  
   
     m_sInstrumentFile = sInstrumentFile;  
     m_iInstrumentNr = iInstrumentNr;  
     m_iInstrumentStatus = 0;  
228    
229      return true;  // Special instrument file/name/number settler.
230    bool qsamplerChannel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
231    {
232            m_sInstrumentFile = sInstrumentFile;
233            m_iInstrumentNr = iInstrumentNr;
234    #ifdef CONFIG_INSTRUMENT_NAME
235            m_sInstrumentName = QString::null;  // We'll get it, maybe later, on channel_info...
236    #else
237            m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true);
238    #endif
239            m_iInstrumentStatus = 0;
240    
241            return true;
242  }  }
243    
244    
245  // MIDI driver type accessors (DEPRECATED).  // MIDI driver type accessors (DEPRECATED).
246  QString& qsamplerChannel::midiDriver (void)  const QString& qsamplerChannel::midiDriver (void) const
247  {  {
248      return m_sMidiDriver;          return m_sMidiDriver;
249  }  }
250    
251  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
252  {  {
253      if (client() == NULL || m_iChannelID < 0)          if (client() == NULL || m_iChannelID < 0)
254          return false;                  return false;
255            if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
256                    return true;
257    
258            if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {
259                    appendMessagesClient("lscp_set_channel_midi_type");
260                    return false;
261            }
262    
263      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;  
     }  
264    
265      m_sMidiDriver = sMidiDriver;          m_sMidiDriver = sMidiDriver;
266      return true;          return true;
267  }  }
268    
269    
270  // MIDI device accessors.  // MIDI device accessors.
271  int qsamplerChannel::midiDevice (void)  int qsamplerChannel::midiDevice (void) const
272  {  {
273      return m_iMidiDevice;          return m_iMidiDevice;
274  }  }
275    
276  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
277  {  {
278      if (client() == NULL || m_iChannelID < 0)          if (client() == NULL || m_iChannelID < 0)
279          return false;                  return false;
280            if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice)
281                    return true;
282    
283            if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {
284                    appendMessagesClient("lscp_set_channel_midi_device");
285                    return false;
286            }
287    
288      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;  
     }  
289    
290      m_iMidiDevice = iMidiDevice;          m_iMidiDevice = iMidiDevice;
291      return true;          return true;
292  }  }
293    
294    
295  // MIDI port number accessor.  // MIDI port number accessor.
296  int qsamplerChannel::midiPort (void)  int qsamplerChannel::midiPort (void) const
297  {  {
298      return m_iMidiPort;          return m_iMidiPort;
299  }  }
300    
301  bool qsamplerChannel::setMidiPort ( int iMidiPort )  bool qsamplerChannel::setMidiPort ( int iMidiPort )
302  {  {
303      if (client() == NULL || m_iChannelID < 0)          if (client() == NULL || m_iChannelID < 0)
304          return false;                  return false;
305            if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort)
306                    return true;
307    
308            if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {
309                    appendMessagesClient("lscp_set_channel_midi_port");
310                    return false;
311            }
312    
313      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;  
     }  
314    
315      m_iMidiPort = iMidiPort;          m_iMidiPort = iMidiPort;
316      return true;          return true;
317  }  }
318    
319    
320  // MIDI channel accessor.  // MIDI channel accessor.
321  int qsamplerChannel::midiChannel (void)  int qsamplerChannel::midiChannel (void) const
322  {  {
323      return m_iMidiChannel;          return m_iMidiChannel;
324  }  }
325    
326  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
327  {  {
328      if (client() == NULL || m_iChannelID < 0)          if (client() == NULL || m_iChannelID < 0)
329          return false;                  return false;
330            if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel)
331                    return true;
332    
333            if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {
334                    appendMessagesClient("lscp_set_channel_midi_channel");
335                    return false;
336            }
337    
338      if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {          appendMessages(QObject::tr("MIDI channel: %1.").arg(iMidiChannel));
         appendMessagesClient("lscp_set_channel_midi_channel");  
         return false;  
     }  
339    
340      m_iMidiChannel = iMidiChannel;          m_iMidiChannel = iMidiChannel;
341      return true;          return true;
342  }  }
343    
344    
345  // Audio device accessor.  // Audio device accessor.
346  int qsamplerChannel::audioDevice (void)  int qsamplerChannel::audioDevice (void) const
347  {  {
348      return m_iAudioDevice;          return m_iAudioDevice;
349  }  }
350    
351  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
352  {  {
353      if (client() == NULL || m_iChannelID < 0)          if (client() == NULL || m_iChannelID < 0)
354          return false;                  return false;
355            if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice)
356                    return true;
357    
358            if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {
359                    appendMessagesClient("lscp_set_channel_audio_device");
360                    return false;
361            }
362    
363      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;  
     }  
364    
365      m_iAudioDevice = iAudioDevice;          m_iAudioDevice = iAudioDevice;
366      return true;          return true;
367  }  }
368    
369    
370  // Audio driver type accessors (DEPRECATED).  // Audio driver type accessors (DEPRECATED).
371  QString& qsamplerChannel::audioDriver (void)  const QString& qsamplerChannel::audioDriver (void) const
372  {  {
373      return m_sAudioDriver;          return m_sAudioDriver;
374  }  }
375    
376  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
377  {  {
378      if (client() == NULL || m_iChannelID < 0)          if (client() == NULL || m_iChannelID < 0)
379          return false;                  return false;
380            if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
381                    return true;
382    
383            if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {
384                    appendMessagesClient("lscp_set_channel_audio_type");
385                    return false;
386            }
387    
388      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;  
     }  
389    
390      m_sAudioDriver = sAudioDriver;          m_sAudioDriver = sAudioDriver;
391      return true;          return true;
392  }  }
393    
394    
395  // Channel volume accessors.  // Channel volume accessors.
396  float qsamplerChannel::volume (void)  float qsamplerChannel::volume (void) const
397  {  {
398      return m_fVolume;          return m_fVolume;
399  }  }
400    
401  bool qsamplerChannel::setVolume ( float fVolume )  bool qsamplerChannel::setVolume ( float fVolume )
402  {  {
403      if (client() == NULL || m_iChannelID < 0)          if (client() == NULL || m_iChannelID < 0)
404          return false;                  return false;
405            if (m_iInstrumentStatus == 100 && m_fVolume == fVolume)
406                    return true;
407    
408            if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {
409                    appendMessagesClient("lscp_set_channel_volume");
410                    return false;
411            }
412    
413            appendMessages(QObject::tr("Volume: %1.").arg(fVolume));
414    
415            m_fVolume = fVolume;
416            return true;
417    }
418    
419    
420    // Sampler channel mute state.
421    bool qsamplerChannel::channelMute (void) const
422    {
423            return m_bMute;
424    }
425    
426    bool qsamplerChannel::setChannelMute ( bool bMute )
427    {
428            if (client() == NULL || m_iChannelID < 0)
429                    return false;
430            if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute)))
431                    return true;
432    
433    #ifdef CONFIG_MUTE_SOLO
434            if (::lscp_set_channel_mute(client(), m_iChannelID, bMute) != LSCP_OK) {
435                    appendMessagesClient("lscp_set_channel_mute");
436                    return false;
437            }
438            appendMessages(QObject::tr("Mute: %1.").arg((int) bMute));
439            m_bMute = bMute;
440            return true;
441    #else
442            return false;
443    #endif
444    }
445    
446    
447    // Sampler channel solo state.
448    bool qsamplerChannel::channelSolo (void) const
449    {
450            return m_bSolo;
451    }
452    
453    bool qsamplerChannel::setChannelSolo ( bool bSolo )
454    {
455            if (client() == NULL || m_iChannelID < 0)
456                    return false;
457            if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo)))
458                    return true;
459    
460    #ifdef CONFIG_MUTE_SOLO
461            if (::lscp_set_channel_solo(client(), m_iChannelID, bSolo) != LSCP_OK) {
462                    appendMessagesClient("lscp_set_channel_solo");
463                    return false;
464            }
465            appendMessages(QObject::tr("Solo: %1.").arg((int) bSolo));
466            m_bSolo = bSolo;
467            return true;
468    #else
469            return false;
470    #endif
471    }
472    
473    
474    // Audio routing accessors.
475    int qsamplerChannel::audioChannel ( int iAudioOut ) const
476    {
477            return m_audioRouting[iAudioOut];
478    }
479    
480    bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )
481    {
482            if (client() == NULL || m_iChannelID < 0)
483                    return false;
484            if (m_iInstrumentStatus == 100 &&
485                            m_audioRouting[iAudioOut] == iAudioIn)
486                    return true;
487    
488      if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {          if (::lscp_set_channel_audio_channel(client(),
489          appendMessagesClient("lscp_set_channel_volume");                          m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) {
490          return false;                  appendMessagesClient("lscp_set_channel_audio_channel");
491      }                  return false;
492            }
493    
494      m_fVolume = fVolume;          appendMessages(QObject::tr("Audio Channel: %1 -> %2.")
495      return true;                  .arg(iAudioOut).arg(iAudioIn));
496    
497            m_audioRouting[iAudioOut] = iAudioIn;
498            return true;
499    }
500    
501    // The audio routing map itself.
502    const qsamplerChannelRoutingMap& qsamplerChannel::audioRouting (void) const
503    {
504            return m_audioRouting;
505    }
506    
507    
508    // Istrument name remapper.
509    void qsamplerChannel::updateInstrumentName (void)
510    {
511    #ifndef CONFIG_INSTRUMENT_NAME
512            m_sInstrumentName = getInstrumentName(m_sInstrumentFile,
513                    m_iInstrumentNr, (options() && options()->bInstrumentNames));
514    #endif
515  }  }
516    
517    
518  // Update whole channel info state.  // Update whole channel info state.
519  bool qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
520  {  {
521      if (client() == NULL || m_iChannelID < 0)          if (client() == NULL || m_iChannelID < 0)
522          return false;                  return false;
523    
524      // Read channel information.          // Read channel information.
525      lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);          lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);
526      if (pChannelInfo == NULL) {          if (pChannelInfo == NULL) {
527          appendMessagesClient("lscp_get_channel_info");                  appendMessagesClient("lscp_get_channel_info");
528          appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));                  appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
529          return false;                  return false;
530      }          }
531    
532      // Cache in channel information.  #ifdef CONFIG_INSTRUMENT_NAME
533      m_sEngineName       = pChannelInfo->engine_name;          // We got all actual instrument datum...
534      m_sInstrumentFile   = pChannelInfo->instrument_file;          m_sInstrumentFile = pChannelInfo->instrument_file;
535      m_iInstrumentNr     = pChannelInfo->instrument_nr;          m_iInstrumentNr   = pChannelInfo->instrument_nr;
536      m_iInstrumentStatus = pChannelInfo->instrument_status;          m_sInstrumentName = pChannelInfo->instrument_name;
537      m_iMidiDevice       = pChannelInfo->midi_device;  #else
538      m_iMidiPort         = pChannelInfo->midi_port;          // First, check if intrument name has changed,
539      m_iMidiChannel      = pChannelInfo->midi_channel;          // taking care that instrument name lookup might be expensive,
540      m_iAudioDevice      = pChannelInfo->audio_device;          // so we better make it only once and when really needed...
541      m_fVolume           = pChannelInfo->volume;          if ((m_sInstrumentFile != pChannelInfo->instrument_file) ||
542      // Some sanity checks.                  (m_iInstrumentNr   != pChannelInfo->instrument_nr)) {
543      if (m_sEngineName == "NONE")                  m_sInstrumentFile = pChannelInfo->instrument_file;
544          m_sEngineName = QString::null;                  m_iInstrumentNr   = pChannelInfo->instrument_nr;
545      if (m_sInstrumentFile == "NONE")                  updateInstrumentName();
546          m_sInstrumentFile = QString::null;          }
547    #endif
548            // Cache in other channel information.
549            m_sEngineName       = pChannelInfo->engine_name;
550            m_iInstrumentStatus = pChannelInfo->instrument_status;
551            m_iMidiDevice       = pChannelInfo->midi_device;
552            m_iMidiPort         = pChannelInfo->midi_port;
553            m_iMidiChannel      = pChannelInfo->midi_channel;
554            m_iAudioDevice      = pChannelInfo->audio_device;
555            m_fVolume           = pChannelInfo->volume;
556    #ifdef CONFIG_MUTE_SOLO
557            m_bMute             = pChannelInfo->mute;
558            m_bSolo             = pChannelInfo->solo;
559    #endif
560            // Some sanity checks.
561            if (m_sEngineName == "NONE" || m_sEngineName.isEmpty())
562                    m_sEngineName = QString::null;
563            if (m_sInstrumentFile == "NONE" || m_sInstrumentFile.isEmpty()) {
564                    m_sInstrumentFile = QString::null;
565                    m_sInstrumentName = QString::null;
566            }
567    
568            // Time for device info grabbing...
569            lscp_device_info_t *pDeviceInfo;
570            const QString sNone = QObject::tr("(none)");
571            // Audio device driver type.
572            pDeviceInfo = ::lscp_get_audio_device_info(client(), m_iAudioDevice);
573            if (pDeviceInfo == NULL) {
574                    appendMessagesClient("lscp_get_audio_device_info");
575                    m_sAudioDriver = sNone;
576            } else {
577                    m_sAudioDriver = pDeviceInfo->driver;
578            }
579            // MIDI device driver type.
580            pDeviceInfo = ::lscp_get_midi_device_info(client(), m_iMidiDevice);
581            if (pDeviceInfo == NULL) {
582                    appendMessagesClient("lscp_get_midi_device_info");
583                    m_sMidiDriver = sNone;
584            } else {
585                    m_sMidiDriver = pDeviceInfo->driver;
586            }
587    
588            // Set the audio routing map.
589            m_audioRouting.clear();
590            char **ppszRouting = pChannelInfo->audio_routing;
591            for (int i = 0; ppszRouting && ppszRouting[i]; i++) {
592                    m_audioRouting[i] = ::atoi(ppszRouting[i]);
593            }
594    
595      return true;          return true;
596  }  }
597    
598    
599  // Reset channel method.  // Reset channel method.
600  bool qsamplerChannel::resetChannel (void)  bool qsamplerChannel::channelReset (void)
601  {  {
602      if (client() == NULL || m_iChannelID < 0)          if (client() == NULL || m_iChannelID < 0)
603          return false;                  return false;
604    
605            if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) {
606                    appendMessagesClient("lscp_reset_channel");
607                    return false;
608            }
609    
610      if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) {          appendMessages(QObject::tr("reset."));
         appendMessagesClient("lscp_reset_channel");  
         return false;  
     }  
611    
612      appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID));          return true;
     return true;  
613  }  }
614    
615    
616  // Channel setup dialog form.  // Channel setup dialog form.
617  bool qsamplerChannel::channelSetup ( QWidget *pParent )  bool qsamplerChannel::channelSetup ( QWidget *pParent )
618  {  {
619      bool bResult = false;          bool bResult = false;
620    
621            appendMessages(QObject::tr("setup..."));
622    
623      qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent);          qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent);
624      if (pChannelForm) {          if (pChannelForm) {
625          pChannelForm->setup(this);                  pChannelForm->setup(this);
626          bResult = pChannelForm->exec();                  bResult = pChannelForm->exec();
627          delete pChannelForm;                  delete pChannelForm;
628      }          }
629    
630      return bResult;          return bResult;
631  }  }
632    
633    
634  // Redirected messages output methods.  // Redirected messages output methods.
635  void qsamplerChannel::appendMessages( const QString& s )  void qsamplerChannel::appendMessages( const QString& s ) const
636  {  {
637      if (m_pMainForm) m_pMainForm->appendMessages(s);          if (m_pMainForm)
638                    m_pMainForm->appendMessages(channelName() + ' ' + s);
639  }  }
640    
641  void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c )  void qsamplerChannel::appendMessagesColor( const QString& s,
642            const QString& c ) const
643  {  {
644      if (m_pMainForm) m_pMainForm->appendMessagesColor(s, c);          if (m_pMainForm)
645                    m_pMainForm->appendMessagesColor(channelName() + ' ' + s, c);
646  }  }
647    
648  void qsamplerChannel::appendMessagesText( const QString& s )  void qsamplerChannel::appendMessagesText( const QString& s ) const
649  {  {
650      if (m_pMainForm) m_pMainForm->appendMessagesText(s);          if (m_pMainForm)
651                    m_pMainForm->appendMessagesText(channelName() + ' ' + s);
652  }  }
653    
654  void qsamplerChannel::appendMessagesError( const QString& s )  void qsamplerChannel::appendMessagesError( const QString& s ) const
655  {  {
656      if (m_pMainForm) m_pMainForm->appendMessagesError(s);          if (m_pMainForm)
657                    m_pMainForm->appendMessagesError(channelName() + "\n\n" + s);
658  }  }
659    
660  void qsamplerChannel::appendMessagesClient( const QString& s )  void qsamplerChannel::appendMessagesClient( const QString& s ) const
661  {  {
662      if (m_pMainForm) m_pMainForm->appendMessagesClient(s);          if (m_pMainForm)
663                    m_pMainForm->appendMessagesClient(channelName() + ' ' + s);
664  }  }
665    
666    
667  // Context menu event handler.  // Context menu event handler.
668  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )
669  {  {
670      if (m_pMainForm) m_pMainForm->contextMenuEvent(pEvent);          if (m_pMainForm)
671                    m_pMainForm->contextMenuEvent(pEvent);
672    }
673    
674    
675    // FIXME: Check whether a given file is an instrument file.
676    bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile )
677    {
678            bool bResult = false;
679    
680            QFile file(sInstrumentFile);
681            if (file.open(IO_ReadOnly)) {
682                    char achHeader[16];
683                    if (file.readBlock(achHeader, 16)) {
684                            bResult = (::memcmp(&achHeader[0], "RIFF", 4)     == 0
685                                            && ::memcmp(&achHeader[8], "DLS LIST", 8) == 0);
686                    }
687                    file.close();
688            }
689    
690            return bResult;
691  }  }
692    
693    
694  // Retrieve the instrument list of a instrument file (.gig).  // Retrieve the instrument list of a instrument file (.gig).
695  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile )  QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile,
696            bool bInstrumentNames )
697  {  {
698      QFileInfo fileinfo(sInstrumentFile);          QString sInstrumentName = QFileInfo(sInstrumentFile).fileName();
699      QString sInstrumentName = fileinfo.fileName();          QStringList instlist;
     QStringList instlist;  
700    
701      if (fileinfo.exists()) {          if (isInstrumentFile(sInstrumentFile)) {
702  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
703          RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                  if (bInstrumentNames) {
704          gig::File  *pGig  = new gig::File(pRiff);                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());
705          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::File  *pGig  = new gig::File(pRiff);
706          while (pInstrument) {                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
707              sInstrumentName = (pInstrument->pInfo)->Name;                          while (pInstrument) {
708              instlist.append(sInstrumentName);                                  instlist.append((pInstrument->pInfo)->Name.c_str());
709              pInstrument = pGig->GetNextInstrument();                                  pInstrument = pGig->GetNextInstrument();
710          }                          }
711          delete pGig;                          delete pGig;
712          delete pRiff;                          delete pRiff;
713  #else                  }
714          for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)                  else
             instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");  
715  #endif  #endif
716      }                  for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)
717      else instlist.append(sInstrumentName);                          instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");
718                }
719      return instlist;          else instlist.append(noInstrumentName());
720    
721            return instlist;
722  }  }
723    
724    
725  // Retrieve the spacific instrument name of a instrument file (.gig), given its index.  // Retrieve the spacific instrument name of a instrument file (.gig), given its index.
726  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, int iInstrumentNr )  QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile,
727            int iInstrumentNr, bool bInstrumentNames )
728  {  {
729      QFileInfo fileinfo(sInstrumentFile);          QString sInstrumentName;
     QString sInstrumentName = fileinfo.fileName();  
730    
731      if (fileinfo.exists()) {          if (isInstrumentFile(sInstrumentFile)) {
732                    sInstrumentName = QFileInfo(sInstrumentFile).fileName();
733  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
734          RIFF::File *pRiff = new RIFF::File(sInstrumentFile);                  if (bInstrumentNames) {
735          gig::File  *pGig  = new gig::File(pRiff);                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());
736          int iIndex = 0;                          gig::File  *pGig  = new gig::File(pRiff);
737          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          int iIndex = 0;
738          while (pInstrument) {                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
739              if (iIndex == iInstrumentNr) {                          while (pInstrument) {
740                  sInstrumentName = (pInstrument->pInfo)->Name;                                  if (iIndex == iInstrumentNr) {
741                  break;                                          sInstrumentName = (pInstrument->pInfo)->Name.c_str();
742              }                                          break;
743              iIndex++;                                  }
744              pInstrument = pGig->GetNextInstrument();                                  iIndex++;
745          }                                  pInstrument = pGig->GetNextInstrument();
746          delete pGig;                          }
747          delete pRiff;                          delete pGig;
748  #else                          delete pRiff;
749          sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";                  }
750                    else
751  #endif  #endif
752      }                  sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
753            }
754            else sInstrumentName = noInstrumentName();
755    
756            return sInstrumentName;
757    }
758    
759    
760    // Common invalid name-helpers.
761    QString qsamplerChannel::noEngineName (void)
762    {
763            return QObject::tr("(No engine)");
764    }
765    
766    QString qsamplerChannel::noInstrumentName (void)
767    {
768            return QObject::tr("(No instrument)");
769    }
770    
771    QString qsamplerChannel::loadingInstrument (void) {
772            return QObject::tr("(Loading instrument...)");
773    }
774    
775    
776    
777    //-------------------------------------------------------------------------
778    // qsamplerChannelRoutingTable - Channel routing table.
779    //
780    
781    // Constructor.
782    qsamplerChannelRoutingTable::qsamplerChannelRoutingTable (
783            QWidget *pParent, const char *pszName )
784            : QTable(pParent, pszName)
785    {
786            // Set fixed number of columns.
787            QTable::setNumCols(2);
788            QTable::setShowGrid(false);
789            QTable::setSorting(false);
790            QTable::setFocusStyle(QTable::FollowStyle);
791            QTable::setSelectionMode(QTable::SingleRow);
792            // No vertical header.
793            QTable::verticalHeader()->hide();
794            QTable::setLeftMargin(0);
795            // Initialize the fixed table column headings.
796            QHeader *pHeader = QTable::horizontalHeader();
797            pHeader->setLabel(0, tr("Sampler Channel"));
798            pHeader->setLabel(1, tr("Device Channel"));
799            // Set read-onlyness of each column
800            QTable::setColumnReadOnly(0, true);
801    //      QTable::setColumnReadOnly(1, false); -- of course not.
802            QTable::setColumnStretchable(1, true);
803    }
804    
805    // Default destructor.
806    qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void)
807    {
808    }
809    
810    
811    // Routing map table renderer.
812    void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice,
813            const qsamplerChannelRoutingMap& routing )
814    {
815            if (pDevice == NULL)
816                    return;
817    
818            // Always (re)start it empty.
819            QTable::setUpdatesEnabled(false);
820            QTable::setNumRows(0);
821    
822            // The common device port item list.
823            QStringList opts;
824            qsamplerDevicePortList& ports = pDevice->ports();
825            qsamplerDevicePort *pPort;
826            for (pPort = ports.first(); pPort; pPort = ports.next()) {
827                    opts.append(pDevice->deviceTypeName()
828                            + ' ' + pDevice->driverName()
829                            + ' ' + pPort->portName());
830            }
831    
832            // Those items shall have a proper pixmap...
833            QPixmap pmDevice;
834            switch (pDevice->deviceType()) {
835            case qsamplerDevice::Audio:
836                    pmDevice = QPixmap::fromMimeSource("audio2.png");
837                    break;
838            case qsamplerDevice::Midi:
839                    pmDevice = QPixmap::fromMimeSource("midi2.png");
840                    break;
841            case qsamplerDevice::None:
842                    break;
843            }
844    
845            // Fill the routing table...
846            QTable::insertRows(0, routing.count());
847            int iRow = 0;
848            qsamplerChannelRoutingMap::ConstIterator iter;
849            for (iter = routing.begin(); iter != routing.end(); ++iter) {
850                    QTable::setPixmap(iRow, 0, pmDevice);
851                    QTable::setText(iRow, 0, pDevice->deviceTypeName()
852                            + ' ' + QString::number(iter.key()));
853                    QComboTableItem *pComboItem = new QComboTableItem(this, opts);
854                    pComboItem->setCurrentItem(iter.data());
855                    QTable::setItem(iRow, 1, pComboItem);
856                    ++iRow;
857            }
858    
859            // Adjust optimal column widths.
860            QTable::adjustColumn(0);
861            QTable::adjustColumn(1);
862    
863      return sInstrumentName;          QTable::setUpdatesEnabled(true);
864            QTable::updateContents();
865  }  }
866    
867    

Legend:
Removed from v.303  
changed lines
  Added in v.758

  ViewVC Help
Powered by ViewVC