/[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 300 by capela, Wed Nov 17 15:55:02 2004 UTC
# Line 25  Line 25 
25    
26  #include "config.h"  #include "config.h"
27    
28    #include <qfileinfo.h>
29    
30    #ifdef CONFIG_LIBGIG
31    #include "gig.h"
32    #else
33    #define QSAMPLER_INSTRUMENT_MAX 8
34    #endif
35    
36    
37  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
38  // qsamplerChannel - Sampler channel structure.  // qsamplerChannel - Sampler channel structure.
# Line 76  lscp_client_t *qsamplerChannel::client ( Line 84  lscp_client_t *qsamplerChannel::client (
84  }  }
85    
86    
87    // Create a new sampler channel, if not already.
88    bool qsamplerChannel::addChannel (void)
89    {
90        if (client() == NULL)
91            return false;
92    
93        // Are we a new channel?
94        if (m_iChannelID < 0) {
95            m_iChannelID = ::lscp_add_channel(client());
96            if (m_iChannelID < 0) {
97                appendMessagesClient("lscp_add_channel");
98                appendMessagesError(QObject::tr("Could not create the new channel.\n\nSorry."));
99            }   // Otherwise it's created...
100            else appendMessages(QObject::tr("Channel %1 created.").arg(m_iChannelID));
101        }
102    
103        // Return whether we're a valid channel...
104        return (m_iChannelID >= 0);
105    }
106    
107    
108    // Remove sampler channel.
109    bool qsamplerChannel::removeChannel (void)
110    {
111        if (client() == NULL)
112            return false;
113    
114        // Are we an existing channel?
115        if (m_iChannelID >= 0) {
116            if (::lscp_remove_channel(client(), m_iChannelID) != LSCP_OK) {
117                appendMessagesClient("lscp_remove_channel");
118                appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry."));
119            } else {
120                // Otherwise it's removed.
121                appendMessages(QObject::tr("Channel %1 removed.").arg(m_iChannelID));
122                m_iChannelID = -1;
123            }
124        }
125        
126        // Return whether we've removed the channel...
127        return (m_iChannelID < 0);
128    }
129    
130    
131  // Channel-ID (aka Sammpler-Channel) accessors.  // Channel-ID (aka Sammpler-Channel) accessors.
132  int qsamplerChannel::channelID (void)  int qsamplerChannel::channelID (void)
133  {  {
# Line 85  int qsamplerChannel::channelID (void) Line 137  int qsamplerChannel::channelID (void)
137  void qsamplerChannel::setChannelID ( int iChannelID )  void qsamplerChannel::setChannelID ( int iChannelID )
138  {  {
139      m_iChannelID = iChannelID;      m_iChannelID = iChannelID;
140    }
141    
142    
143      updateChannelInfo();  // Readable channel name.
144    QString qsamplerChannel::channelName (void)
145    {
146        return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID));
147  }  }
148    
149    
# Line 98  QString& qsamplerChannel::engineName (vo Line 155  QString& qsamplerChannel::engineName (vo
155    
156  bool qsamplerChannel::loadEngine ( const QString& sEngineName )  bool qsamplerChannel::loadEngine ( const QString& sEngineName )
157  {  {
158      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
159          return false;          return false;
160    
161      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 189  int qsamplerChannel::instrumentStatus (v
189  // Instrument file loader.  // Instrument file loader.
190  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
191  {  {
192      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
193          return false;          return false;
194    
195      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 213  QString& qsamplerChannel::midiDriver (vo
213    
214  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
215  {  {
216      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
217          return false;          return false;
218    
219      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 234  int qsamplerChannel::midiDevice (void)
234    
235  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
236  {  {
237      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
238          return false;          return false;
239    
240      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 255  int qsamplerChannel::midiPort (void)
255    
256  bool qsamplerChannel::setMidiPort ( int iMidiPort )  bool qsamplerChannel::setMidiPort ( int iMidiPort )
257  {  {
258      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
259          return false;          return false;
260    
261      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 276  int qsamplerChannel::midiChannel (void)
276    
277  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
278  {  {
279      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
280          return false;          return false;
281    
282      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 297  int qsamplerChannel::audioDevice (void)
297    
298  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
299  {  {
300      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
301          return false;          return false;
302    
303      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 318  QString& qsamplerChannel::audioDriver (v
318    
319  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
320  {  {
321      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
322          return false;          return false;
323    
324      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 339  float qsamplerChannel::volume (void)
339    
340  bool qsamplerChannel::setVolume ( float fVolume )  bool qsamplerChannel::setVolume ( float fVolume )
341  {  {
342      if (client() == NULL)      if (client() == NULL || m_iChannelID < 0)
343          return false;          return false;
344    
345      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 353  bool qsamplerChannel::setVolume ( float
353    
354    
355  // Update whole channel info state.  // Update whole channel info state.
356  void qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
357  {  {
358      // Check if we're up and connected.      if (client() == NULL || m_iChannelID < 0)
359      if (client() == NULL)          return false;
         return;  
360    
361      // Read channel information.      // Read channel information.
362      lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);      lscp_channel_info_t *pChannelInfo = ::lscp_get_channel_info(client(), m_iChannelID);
363      if (pChannelInfo == NULL) {      if (pChannelInfo == NULL) {
364          appendMessagesClient("lscp_get_channel_info");          appendMessagesClient("lscp_get_channel_info");
365          appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));          appendMessagesError(QObject::tr("Could not get channel information.\n\nSorry."));
366      } 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;  
367      }      }
368    
369        // Cache in channel information.
370        m_sEngineName       = pChannelInfo->engine_name;
371        m_sInstrumentFile   = pChannelInfo->instrument_file;
372        m_iInstrumentNr     = pChannelInfo->instrument_nr;
373        m_iInstrumentStatus = pChannelInfo->instrument_status;
374        m_iMidiDevice       = pChannelInfo->midi_device;
375        m_iMidiPort         = pChannelInfo->midi_port;
376        m_iMidiChannel      = pChannelInfo->midi_channel;
377        m_iAudioDevice      = pChannelInfo->audio_device;
378        m_fVolume           = pChannelInfo->volume;
379        // Some sanity checks.
380        if (m_sEngineName == "NONE")
381            m_sEngineName = QString::null;
382        if (m_sInstrumentFile == "NONE")
383            m_sInstrumentFile = QString::null;
384    
385        return true;
386  }  }
387    
388    
389  // Reset channel method.  // Reset channel method.
390  void qsamplerChannel::resetChannel (void)  bool qsamplerChannel::resetChannel (void)
391  {  {
392      // Check if we're up and connected.      if (client() == NULL || m_iChannelID < 0)
393      if (client() == NULL)          return false;
         return;  
394    
395      if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK)      if (::lscp_reset_channel(client(), m_iChannelID) != LSCP_OK) {
396          appendMessagesClient("lscp_reset_channel");          appendMessagesClient("lscp_reset_channel");
397      else          return false;
398          appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID));      }
399    
400        appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID));
401        return true;
402  }  }
403    
404    
# Line 368  void qsamplerChannel::appendMessagesClie Line 429  void qsamplerChannel::appendMessagesClie
429  }  }
430    
431    
432    // Retrieve the instrument list of a instrument file (.gig).
433    QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile )
434    {
435        QFileInfo fileinfo(sInstrumentFile);
436        QString sInstrumentName = fileinfo.fileName();
437        QStringList instlist;
438    
439        if (fileinfo.exists()) {
440    #ifdef CONFIG_LIBGIG
441            RIFF::File *pRiff = new RIFF::File(sInstrumentFile);
442            gig::File  *pGig  = new gig::File(pRiff);
443            gig::Instrument *pInstrument = pGig->GetFirstInstrument();
444            while (pInstrument) {
445                sInstrumentName = (pInstrument->pInfo)->Name;
446                instlist.append(sInstrumentName);
447                pInstrument = pGig->GetNextInstrument();
448            }
449            delete pGig;
450            delete pRiff;
451    #else
452            for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++)
453                instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]");
454    #endif
455        }
456        else instlist.append(sInstrumentName);
457        
458        return instlist;
459    }
460    
461    
462    // Retrieve the spacific instrument name of a instrument file (.gig), given its index.
463    QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, int iInstrumentNr )
464    {
465        QFileInfo fileinfo(sInstrumentFile);
466        QString sInstrumentName = fileinfo.fileName();
467    
468        if (fileinfo.exists()) {
469    #ifdef CONFIG_LIBGIG
470            RIFF::File *pRiff = new RIFF::File(sInstrumentFile);
471            gig::File  *pGig  = new gig::File(pRiff);
472            int iIndex = 0;
473            gig::Instrument *pInstrument = pGig->GetFirstInstrument();
474            while (pInstrument) {
475                if (iIndex == iInstrumentNr) {
476                    sInstrumentName = (pInstrument->pInfo)->Name;
477                    break;
478                }
479                iIndex++;
480                pInstrument = pGig->GetNextInstrument();
481            }
482            delete pGig;
483            delete pRiff;
484    #else
485            sInstrumentName += " [" + QString::number(iInstrumentNr) + "]";
486    #endif
487        }
488    
489        return sInstrumentName;
490    }
491    
492    
493  // end of qsamplerChannel.cpp  // end of qsamplerChannel.cpp

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

  ViewVC Help
Powered by ViewVC