/[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 264 by capela, Wed Sep 29 13:12:45 2004 UTC revision 343 by capela, Tue Jan 18 12:32:01 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 22  Line 22 
22  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
23    
24  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
25    #include "qsamplerChannelForm.h"
26    
27  #include "config.h"  #include "config.h"
28    
29    #include <qfileinfo.h>
30    
31    #ifdef CONFIG_LIBGIG
32    #include "gig.h"
33    #endif
34    
35    #define QSAMPLER_INSTRUMENT_MAX 8
36    
37    
38  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
39  // qsamplerChannel - Sampler channel structure.  // qsamplerChannel - Sampler channel structure.
40  //  //
41    bool qsamplerChannel::g_bInstrumentNames = false;
42    
43  // Constructor.  // Constructor.
44  qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )  qsamplerChannel::qsamplerChannel ( qsamplerMainForm *pMainForm, int iChannelID )
# Line 76  lscp_client_t *qsamplerChannel::client ( Line 86  lscp_client_t *qsamplerChannel::client (
86  }  }
87    
88    
89    // Create a new sampler channel, if not already.
90    bool qsamplerChannel::addChannel (void)
91    {
92        if (client() == NULL)
93            return false;
94    
95        // Are we a new channel?
96        if (m_iChannelID < 0) {
97            m_iChannelID = ::lscp_add_channel(client());
98            if (m_iChannelID < 0) {
99                appendMessagesClient("lscp_add_channel");
100                appendMessagesError(QObject::tr("Could not create the new channel.\n\nSorry."));
101            }   // Otherwise it's created...
102            else appendMessages(QObject::tr("Channel %1 created.").arg(m_iChannelID));
103        }
104    
105        // Return whether we're a valid channel...
106        return (m_iChannelID >= 0);
107    }
108    
109    
110    // Remove sampler channel.
111    bool qsamplerChannel::removeChannel (void)
112    {
113        if (client() == NULL)
114            return false;
115    
116        // Are we an existing channel?
117        if (m_iChannelID >= 0) {
118            if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) {
119                appendMessagesClient("lscp_remove_channel");
120                appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));
121            } else {
122                // Otherwise it's removed.
123                appendMessages(QObject::tr("Channel %1 removed.").arg(m_iChannelID));
124                m_iChannelID = -1;
125            }
126        }
127        
128        // Return whether we've removed the channel...
129        return (m_iChannelID < 0);
130    }
131    
132    
133  // Channel-ID (aka Sammpler-Channel) accessors.  // Channel-ID (aka Sammpler-Channel) accessors.
134  int qsamplerChannel::channelID (void)  int qsamplerChannel::channelID (void)
135  {  {
# Line 85  int qsamplerChannel::channelID (void) Line 139  int qsamplerChannel::channelID (void)
139  void qsamplerChannel::setChannelID ( int iChannelID )  void qsamplerChannel::setChannelID ( int iChannelID )
140  {  {
141      m_iChannelID = iChannelID;      m_iChannelID = iChannelID;
142    }
143    
144    
145      updateChannelInfo();  // Readable channel name.
146    QString qsamplerChannel::channelName (void)
147    {
148        return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID));
149  }  }
150    
151    
# Line 98  QString& qsamplerChannel::engineName (vo Line 157  QString& qsamplerChannel::engineName (vo
157    
158  bool qsamplerChannel::loadEngine ( const QString& sEngineName )  bool qsamplerChannel::loadEngine ( const QString& sEngineName )
159  {  {
160      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
161          return false;          return false;
162    
163      if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {      if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {
# Line 132  int qsamplerChannel::instrumentStatus (v Line 191  int qsamplerChannel::instrumentStatus (v
191  // Instrument file loader.  // Instrument file loader.
192  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
193  {  {
194      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
195          return false;          return false;
196    
197      if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {      if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) {
# Line 156  QString& qsamplerChannel::midiDriver (vo Line 215  QString& qsamplerChannel::midiDriver (vo
215    
216  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
217  {  {
218      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
219          return false;          return false;
220    
221      if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {      if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {
# Line 177  int qsamplerChannel::midiDevice (void) Line 236  int qsamplerChannel::midiDevice (void)
236    
237  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
238  {  {
239      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
240          return false;          return false;
241    
242      if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {      if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) {
# Line 198  int qsamplerChannel::midiPort (void) Line 257  int qsamplerChannel::midiPort (void)
257    
258  bool qsamplerChannel::setMidiPort ( int iMidiPort )  bool qsamplerChannel::setMidiPort ( int iMidiPort )
259  {  {
260      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
261          return false;          return false;
262    
263      if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {      if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) {
# Line 219  int qsamplerChannel::midiChannel (void) Line 278  int qsamplerChannel::midiChannel (void)
278    
279  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
280  {  {
281      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
282          return false;          return false;
283    
284      if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {      if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) {
# Line 240  int qsamplerChannel::audioDevice (void) Line 299  int qsamplerChannel::audioDevice (void)
299    
300  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
301  {  {
302      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
303          return false;          return false;
304    
305      if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {      if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) {
# Line 261  QString& qsamplerChannel::audioDriver (v Line 320  QString& qsamplerChannel::audioDriver (v
320    
321  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
322  {  {
323      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
324          return false;          return false;
325    
326      if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {      if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {
# Line 282  float qsamplerChannel::volume (void) Line 341  float qsamplerChannel::volume (void)
341    
342  bool qsamplerChannel::setVolume ( float fVolume )  bool qsamplerChannel::setVolume ( float fVolume )
343  {  {
344      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
345          return false;          return false;
346    
347      if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {      if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) {
# Line 296  bool qsamplerChannel::setVolume ( float Line 355  bool qsamplerChannel::setVolume ( float
355    
356    
357  // Update whole channel info state.  // Update whole channel info state.
358  void qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
359  {  {
360      // Check if we're up and connected.      if (client() == NULL || m_iChannelID < 0)
361      if (client() == NULL)          return false;
         return;  
362    
363      // Read channel information.      // Read channel information.
364      lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);      lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);
365      if (pChannelInfo == NULL) {      if (pChannelInfo == NULL) {
366          appendMessagesClient("lscp_get_channel_info");          appendMessagesClient("lscp_get_channel_info");
367          appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));          appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
368      } else {          return false;
         // Cache in channel information.  
         m_sEngineName       = pChannelInfo->engine_name;  
         m_sInstrumentFile   = pChannelInfo->instrument_file;  
         m_iInstrumentNr     = pChannelInfo->instrument_nr;  
         m_iInstrumentStatus = pChannelInfo->instrument_status;  
         m_iMidiDevice       = pChannelInfo->midi_device;  
         m_iMidiPort         = pChannelInfo->midi_port;  
         m_iMidiChannel      = pChannelInfo->midi_channel;  
         m_iAudioDevice      = pChannelInfo->audio_device;  
         m_fVolume           = pChannelInfo->volume;  
         // Some sanity checks.  
         if (m_sEngineName == "NONE")  
             m_sEngineName = QString::null;  
         if (m_sInstrumentFile == "NONE")  
             m_sInstrumentFile = QString::null;  
369      }      }
370    
371        // Cache in channel information.
372        m_sEngineName       = pChannelInfo->engine_name;
373        m_sInstrumentFile   = pChannelInfo->instrument_file;
374        m_iInstrumentNr     = pChannelInfo->instrument_nr;
375        m_iInstrumentStatus = pChannelInfo->instrument_status;
376        m_iMidiDevice       = pChannelInfo->midi_device;
377        m_iMidiPort         = pChannelInfo->midi_port;
378        m_iMidiChannel      = pChannelInfo->midi_channel;
379        m_iAudioDevice      = pChannelInfo->audio_device;
380        m_fVolume           = pChannelInfo->volume;
381        // Some sanity checks.
382        if (m_sEngineName == "NONE")
383            m_sEngineName = QString::null;
384        if (m_sInstrumentFile == "NONE")
385            m_sInstrumentFile = QString::null;
386    
387        return true;
388  }  }
389    
390    
391  // Reset channel method.  // Reset channel method.
392  void qsamplerChannel::resetChannel (void)  bool qsamplerChannel::resetChannel (void)
393  {  {
394      // Check if we're up and connected.      if (client() == NULL || m_iChannelID < 0)
395      if (client() == NULL)          return false;
         return;  
396    
397      if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK)      if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) {
398          appendMessagesClient("lscp_reset_channel");          appendMessagesClient("lscp_reset_channel");
399      else          return false;
400          appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID));      }
401    
402        appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID));
403        return true;
404    }
405    
406    
407    // Channel setup dialog form.
408    bool qsamplerChannel::channelSetup ( QWidget *pParent )
409    {
410        bool bResult = false;
411    
412        qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent);
413        if (pChannelForm) {
414            pChannelForm->setup(this);
415            bResult = pChannelForm->exec();
416            delete pChannelForm;
417        }
418    
419        return bResult;
420  }  }
421    
422    
423  // Redirected messages output methods.  // Redirected messages output methods.
424  void qsamplerChannel::appendMessages( const QString& s )  void qsamplerChannel::appendMessages( const QString& s )
425  {  {
426      m_pMainForm->appendMessages(s);      if (m_pMainForm) m_pMainForm->appendMessages(s);
427  }  }
428    
429  void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c )  void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c )
430  {  {
431      m_pMainForm->appendMessagesColor(s, c);      if (m_pMainForm) m_pMainForm->appendMessagesColor(s, c);
432  }  }
433    
434  void qsamplerChannel::appendMessagesText( const QString& s )  void qsamplerChannel::appendMessagesText( const QString& s )
435  {  {
436      m_pMainForm->appendMessagesText(s);      if (m_pMainForm) m_pMainForm->appendMessagesText(s);
437  }  }
438    
439  void qsamplerChannel::appendMessagesError( const QString& s )  void qsamplerChannel::appendMessagesError( const QString& s )
440  {  {
441      m_pMainForm->appendMessagesError(s);      if (m_pMainForm) m_pMainForm->appendMessagesError(s);
442  }  }
443    
444  void qsamplerChannel::appendMessagesClient( const QString& s )  void qsamplerChannel::appendMessagesClient( const QString& s )
445  {  {
446      m_pMainForm->appendMessagesClient(s);      if (m_pMainForm) m_pMainForm->appendMessagesClient(s);
447    }
448    
449    
450    // Context menu event handler.
451    void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )
452    {
453        if (m_pMainForm) m_pMainForm->contextMenuEvent(pEvent);
454    }
455    
456    
457    // Retrieve the instrument list of a instrument file (.gig).
458    QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile )
459    {
460        QFileInfo fileinfo(sInstrumentFile);
461        QString sInstrumentName = fileinfo.fileName();
462        QStringList instlist;
463    
464        if (fileinfo.exists()) {
465    #ifdef CONFIG_LIBGIG
466                    if (g_bInstrumentNames) {
467                    RIFF::File *pRiff = new RIFF::File(sInstrumentFile);
468                    gig::File  *pGig  = new gig::File(pRiff);
469                    gig::Instrument *pInstrument = pGig->GetFirstInstrument();
470                    while (pInstrument) {
471                        instlist.append((pInstrument->pInfo)->Name.c_str());
472                        pInstrument = pGig->GetNextInstrument();
473                    }
474                    delete pGig;
475                    delete pRiff;
476                    }
477                    else
478    #endif
479            for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)
480                instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");
481        }
482        else instlist.append(sInstrumentName);
483    
484        return instlist;
485    }
486    
487    
488    // Retrieve the spacific instrument name of a instrument file (.gig), given its index.
489    QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, int iInstrumentNr )
490    {
491        QFileInfo fileinfo(sInstrumentFile);
492        QString sInstrumentName = fileinfo.fileName();
493    
494        if (fileinfo.exists()) {
495    #ifdef CONFIG_LIBGIG
496                    if (g_bInstrumentNames) {
497                    RIFF::File *pRiff = new RIFF::File(sInstrumentFile);
498                    gig::File  *pGig  = new gig::File(pRiff);
499                    int iIndex = 0;
500                    gig::Instrument *pInstrument = pGig->GetFirstInstrument();
501                    while (pInstrument) {
502                        if (iIndex == iInstrumentNr) {
503                            sInstrumentName = (pInstrument->pInfo)->Name.c_str();
504                            break;
505                        }
506                        iIndex++;
507                        pInstrument = pGig->GetNextInstrument();
508                    }
509                    delete pGig;
510                    delete pRiff;
511                    }
512                    else
513    #endif
514            sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
515        }
516    
517        return sInstrumentName;
518    }
519    
520    
521    // Instrument name(s) retrieval mode--global option.
522    bool qsamplerChannel::instrumentNames (void)
523    {
524            return g_bInstrumentNames;
525    }
526    
527    void qsamplerChannel::setInstrumentNames ( bool bInstrumentNames )
528    {
529            g_bInstrumentNames = bInstrumentNames;
530  }  }
531    
532    

Legend:
Removed from v.264  
changed lines
  Added in v.343

  ViewVC Help
Powered by ViewVC