/[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 1402 by schoenebeck, Fri Oct 12 00:03:27 2007 UTC revision 1499 by capela, Tue Nov 20 16:48:04 2007 UTC
# Line 2  Line 2 
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.
5       Copyright (C) 2007, Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 19  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
 #include "qsamplerUtilities.h"  
23  #include "qsamplerAbout.h"  #include "qsamplerAbout.h"
24  #include "qsamplerChannel.h"  #include "qsamplerChannel.h"
25    #include "qsamplerUtilities.h"
26    
27  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
28  #include "qsamplerChannelForm.h"  #include "qsamplerChannelForm.h"
29    
30  #include <qfileinfo.h>  #include <QFileInfo>
31  #include <qcombobox.h>  #include <QComboBox>
32    
33  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
34  #include "gig.h"  #include "gig.h"
# Line 35  Line 36 
36    
37  #define QSAMPLER_INSTRUMENT_MAX 100  #define QSAMPLER_INSTRUMENT_MAX 100
38    
39    #define UNICODE_RIGHT_ARROW     QChar(char(0x92), char(0x21))
40    
41    
42    using namespace QSampler;
43    
44  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
45  // qsamplerChannel - Sampler channel structure.  // qsamplerChannel - Sampler channel structure.
# Line 71  qsamplerChannel::~qsamplerChannel (void) Line 76  qsamplerChannel::~qsamplerChannel (void)
76  // Create a new sampler channel, if not already.  // Create a new sampler channel, if not already.
77  bool qsamplerChannel::addChannel (void)  bool qsamplerChannel::addChannel (void)
78  {  {
79          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
80          if (pMainForm == NULL)          if (pMainForm == NULL)
81                  return false;                  return false;
82          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 96  bool qsamplerChannel::addChannel (void) Line 101  bool qsamplerChannel::addChannel (void)
101  // Remove sampler channel.  // Remove sampler channel.
102  bool qsamplerChannel::removeChannel (void)  bool qsamplerChannel::removeChannel (void)
103  {  {
104          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
105          if (pMainForm == NULL)          if (pMainForm == NULL)
106                  return false;                  return false;
107          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 146  const QString& qsamplerChannel::engineNa Line 151  const QString& qsamplerChannel::engineNa
151    
152  bool qsamplerChannel::loadEngine ( const QString& sEngineName )  bool qsamplerChannel::loadEngine ( const QString& sEngineName )
153  {  {
154          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
155          if (pMainForm == NULL)          if (pMainForm == NULL)
156                  return false;                  return false;
157          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 154  bool qsamplerChannel::loadEngine ( const Line 159  bool qsamplerChannel::loadEngine ( const
159          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)          if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName)
160                  return true;                  return true;
161    
162          if (::lscp_load_engine(pMainForm->client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) {          if (::lscp_load_engine(pMainForm->client(),
163                            sEngineName.toUtf8().constData(), m_iChannelID) != LSCP_OK) {
164                  appendMessagesClient("lscp_load_engine");                  appendMessagesClient("lscp_load_engine");
165                  return false;                  return false;
166          }          }
# Line 193  int qsamplerChannel::instrumentStatus (v Line 199  int qsamplerChannel::instrumentStatus (v
199  // Instrument file loader.  // Instrument file loader.
200  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )  bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr )
201  {  {
202          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
203          if (pMainForm == NULL)          if (pMainForm == NULL)
204                  return false;                  return false;
205          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 206  bool qsamplerChannel::loadInstrument ( c Line 212  bool qsamplerChannel::loadInstrument ( c
212          if (          if (
213                  ::lscp_load_instrument_non_modal(                  ::lscp_load_instrument_non_modal(
214                          pMainForm->client(),                          pMainForm->client(),
215                          qsamplerUtilities::lscpEscapePath(sInstrumentFile).latin1(),                          qsamplerUtilities::lscpEscapePath(
216                                    sInstrumentFile).toUtf8().constData(),
217                          iInstrumentNr, m_iChannelID                          iInstrumentNr, m_iChannelID
218                  ) != LSCP_OK                  ) != LSCP_OK
219          ) {          ) {
# Line 245  const QString& qsamplerChannel::midiDriv Line 252  const QString& qsamplerChannel::midiDriv
252    
253  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )  bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver )
254  {  {
255          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
256          if (pMainForm == NULL)          if (pMainForm == NULL)
257                  return false;                  return false;
258          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 253  bool qsamplerChannel::setMidiDriver ( co Line 260  bool qsamplerChannel::setMidiDriver ( co
260          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)          if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver)
261                  return true;                  return true;
262    
263          if (::lscp_set_channel_midi_type(pMainForm->client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) {          if (::lscp_set_channel_midi_type(pMainForm->client(),
264                            m_iChannelID, sMidiDriver.toUtf8().constData()) != LSCP_OK) {
265                  appendMessagesClient("lscp_set_channel_midi_type");                  appendMessagesClient("lscp_set_channel_midi_type");
266                  return false;                  return false;
267          }          }
# Line 273  int qsamplerChannel::midiDevice (void) c Line 281  int qsamplerChannel::midiDevice (void) c
281    
282  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )  bool qsamplerChannel::setMidiDevice ( int iMidiDevice )
283  {  {
284          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
285          if (pMainForm == NULL)          if (pMainForm == NULL)
286                  return false;                  return false;
287          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 301  int qsamplerChannel::midiPort (void) con Line 309  int qsamplerChannel::midiPort (void) con
309    
310  bool qsamplerChannel::setMidiPort ( int iMidiPort )  bool qsamplerChannel::setMidiPort ( int iMidiPort )
311  {  {
312          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
313          if (pMainForm == NULL)          if (pMainForm == NULL)
314                  return false;                  return false;
315          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 329  int qsamplerChannel::midiChannel (void) Line 337  int qsamplerChannel::midiChannel (void)
337    
338  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )  bool qsamplerChannel::setMidiChannel ( int iMidiChannel )
339  {  {
340          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
341          if (pMainForm == NULL)          if (pMainForm == NULL)
342                  return false;                  return false;
343          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 357  int qsamplerChannel::midiMap (void) cons Line 365  int qsamplerChannel::midiMap (void) cons
365    
366  bool qsamplerChannel::setMidiMap ( int iMidiMap )  bool qsamplerChannel::setMidiMap ( int iMidiMap )
367  {  {
368          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
369          if (pMainForm == NULL)          if (pMainForm == NULL)
370                  return false;                  return false;
371          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 385  int qsamplerChannel::audioDevice (void) Line 393  int qsamplerChannel::audioDevice (void)
393    
394  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )  bool qsamplerChannel::setAudioDevice ( int iAudioDevice )
395  {  {
396          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
397          if (pMainForm == NULL)          if (pMainForm == NULL)
398                  return false;                  return false;
399          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 413  const QString& qsamplerChannel::audioDri Line 421  const QString& qsamplerChannel::audioDri
421    
422  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )  bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver )
423  {  {
424          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
425          if (pMainForm == NULL)          if (pMainForm == NULL)
426                  return false;                  return false;
427          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 421  bool qsamplerChannel::setAudioDriver ( c Line 429  bool qsamplerChannel::setAudioDriver ( c
429          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)          if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver)
430                  return true;                  return true;
431    
432          if (::lscp_set_channel_audio_type(pMainForm->client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) {          if (::lscp_set_channel_audio_type(pMainForm->client(),
433                            m_iChannelID, sAudioDriver.toUtf8().constData()) != LSCP_OK) {
434                  appendMessagesClient("lscp_set_channel_audio_type");                  appendMessagesClient("lscp_set_channel_audio_type");
435                  return false;                  return false;
436          }          }
# Line 441  float qsamplerChannel::volume (void) con Line 450  float qsamplerChannel::volume (void) con
450    
451  bool qsamplerChannel::setVolume ( float fVolume )  bool qsamplerChannel::setVolume ( float fVolume )
452  {  {
453          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
454          if (pMainForm == NULL)          if (pMainForm == NULL)
455                  return false;                  return false;
456          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 469  bool qsamplerChannel::channelMute (void) Line 478  bool qsamplerChannel::channelMute (void)
478    
479  bool qsamplerChannel::setChannelMute ( bool bMute )  bool qsamplerChannel::setChannelMute ( bool bMute )
480  {  {
481          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
482          if (pMainForm == NULL)          if (pMainForm == NULL)
483                  return false;                  return false;
484          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 499  bool qsamplerChannel::channelSolo (void) Line 508  bool qsamplerChannel::channelSolo (void)
508    
509  bool qsamplerChannel::setChannelSolo ( bool bSolo )  bool qsamplerChannel::setChannelSolo ( bool bSolo )
510  {  {
511          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
512          if (pMainForm == NULL)          if (pMainForm == NULL)
513                  return false;                  return false;
514          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 529  int qsamplerChannel::audioChannel ( int Line 538  int qsamplerChannel::audioChannel ( int
538    
539  bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )  bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn )
540  {  {
541          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
542          if (pMainForm == NULL)          if (pMainForm == NULL)
543                  return false;                  return false;
544          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 571  void qsamplerChannel::updateInstrumentNa Line 580  void qsamplerChannel::updateInstrumentNa
580  // Update whole channel info state.  // Update whole channel info state.
581  bool qsamplerChannel::updateChannelInfo (void)  bool qsamplerChannel::updateChannelInfo (void)
582  {  {
583          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
584          if (pMainForm == NULL)          if (pMainForm == NULL)
585                  return false;                  return false;
586          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 665  bool qsamplerChannel::updateChannelInfo Line 674  bool qsamplerChannel::updateChannelInfo
674  // Reset channel method.  // Reset channel method.
675  bool qsamplerChannel::channelReset (void)  bool qsamplerChannel::channelReset (void)
676  {  {
677          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
678          if (pMainForm == NULL)          if (pMainForm == NULL)
679                  return false;                  return false;
680          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
# Line 687  bool qsamplerChannel::editChannel (void) Line 696  bool qsamplerChannel::editChannel (void)
696  {  {
697  #ifdef CONFIG_EDIT_INSTRUMENT  #ifdef CONFIG_EDIT_INSTRUMENT
698    
699          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
700          if (pMainForm == NULL)          if (pMainForm == NULL)
701                  return false;                  return false;
702          if (pMainForm->client() == NULL || m_iChannelID < 0)          if (pMainForm->client() == NULL || m_iChannelID < 0)
703                  return false;                  return false;
704    
705          if (::lscp_edit_instrument(pMainForm->client(), m_iChannelID) != LSCP_OK) {          if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID)
706                  appendMessagesClient("lscp_edit_instrument");                  != LSCP_OK) {
707                    appendMessagesClient("lscp_edit_channel_instrument");
708                  appendMessagesError(QObject::tr(                  appendMessagesError(QObject::tr(
709                          "Could not launch an appropriate instrument editor "                          "Could not launch an appropriate instrument editor "
710                          "for the given instrument!\n"                          "for the given instrument!\n"
# Line 727  bool qsamplerChannel::editChannel (void) Line 737  bool qsamplerChannel::editChannel (void)
737  // Channel setup dialog form.  // Channel setup dialog form.
738  bool qsamplerChannel::channelSetup ( QWidget *pParent )  bool qsamplerChannel::channelSetup ( QWidget *pParent )
739  {  {
740          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
741          if (pMainForm == NULL)          if (pMainForm == NULL)
742                  return false;                  return false;
743    
# Line 735  bool qsamplerChannel::channelSetup ( QWi Line 745  bool qsamplerChannel::channelSetup ( QWi
745    
746          appendMessages(QObject::tr("setup..."));          appendMessages(QObject::tr("setup..."));
747    
748          qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent);          ChannelForm *pChannelForm = new ChannelForm(pParent);
749          if (pChannelForm) {          if (pChannelForm) {
750                  pChannelForm->setup(this);                  pChannelForm->setup(this);
751                  bResult = pChannelForm->exec();                  bResult = pChannelForm->exec();
# Line 749  bool qsamplerChannel::channelSetup ( QWi Line 759  bool qsamplerChannel::channelSetup ( QWi
759  // Redirected messages output methods.  // Redirected messages output methods.
760  void qsamplerChannel::appendMessages( const QString& s ) const  void qsamplerChannel::appendMessages( const QString& s ) const
761  {  {
762          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
763          if (pMainForm)          if (pMainForm)
764                  pMainForm->appendMessages(channelName() + ' ' + s);                  pMainForm->appendMessages(channelName() + ' ' + s);
765  }  }
# Line 757  void qsamplerChannel::appendMessages( co Line 767  void qsamplerChannel::appendMessages( co
767  void qsamplerChannel::appendMessagesColor( const QString& s,  void qsamplerChannel::appendMessagesColor( const QString& s,
768          const QString& c ) const          const QString& c ) const
769  {  {
770          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
771          if (pMainForm)          if (pMainForm)
772                  pMainForm->appendMessagesColor(channelName() + ' ' + s, c);                  pMainForm->appendMessagesColor(channelName() + ' ' + s, c);
773  }  }
774    
775  void qsamplerChannel::appendMessagesText( const QString& s ) const  void qsamplerChannel::appendMessagesText( const QString& s ) const
776  {  {
777          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
778          if (pMainForm)          if (pMainForm)
779                  pMainForm->appendMessagesText(channelName() + ' ' + s);                  pMainForm->appendMessagesText(channelName() + ' ' + s);
780  }  }
781    
782  void qsamplerChannel::appendMessagesError( const QString& s ) const  void qsamplerChannel::appendMessagesError( const QString& s ) const
783  {  {
784          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
785          if (pMainForm)          if (pMainForm)
786                  pMainForm->appendMessagesError(channelName() + "\n\n" + s);                  pMainForm->appendMessagesError(channelName() + "\n\n" + s);
787  }  }
788    
789  void qsamplerChannel::appendMessagesClient( const QString& s ) const  void qsamplerChannel::appendMessagesClient( const QString& s ) const
790  {  {
791          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
792          if (pMainForm)          if (pMainForm)
793                  pMainForm->appendMessagesClient(channelName() + ' ' + s);                  pMainForm->appendMessagesClient(channelName() + ' ' + s);
794  }  }
# Line 787  void qsamplerChannel::appendMessagesClie Line 797  void qsamplerChannel::appendMessagesClie
797  // Context menu event handler.  // Context menu event handler.
798  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )  void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent )
799  {  {
800          qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
801          if (pMainForm)          if (pMainForm)
802                  pMainForm->contextMenuEvent(pEvent);                  pMainForm->contextMenuEvent(pEvent);
803  }  }
# Line 799  bool qsamplerChannel::isInstrumentFile ( Line 809  bool qsamplerChannel::isInstrumentFile (
809          bool bResult = false;          bool bResult = false;
810    
811          QFile file(sInstrumentFile);          QFile file(sInstrumentFile);
812          if (file.open(IO_ReadOnly)) {          if (file.open(QIODevice::ReadOnly)) {
813                  char achHeader[16];                  char achHeader[16];
814                  if (file.readBlock(achHeader, 16)) {                  if (file.read(achHeader, 16) > 0) {
815                          bResult = (::memcmp(&achHeader[0], "RIFF", 4)     == 0                          bResult = (::memcmp(&achHeader[0], "RIFF", 4)     == 0
816                                          && ::memcmp(&achHeader[8], "DLS LIST", 8) == 0);                                          && ::memcmp(&achHeader[8], "DLS LIST", 8) == 0);
817                  }                  }
# Line 822  QStringList qsamplerChannel::getInstrume Line 832  QStringList qsamplerChannel::getInstrume
832          if (isInstrumentFile(sInstrumentFile)) {          if (isInstrumentFile(sInstrumentFile)) {
833  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
834                  if (bInstrumentNames) {                  if (bInstrumentNames) {
835                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());                          RIFF::File *pRiff
836                                    = new RIFF::File(sInstrumentFile.toUtf8().constData());
837                          gig::File  *pGig  = new gig::File(pRiff);                          gig::File  *pGig  = new gig::File(pRiff);
838                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
839                          while (pInstrument) {                          while (pInstrument) {
# Line 853  QString qsamplerChannel::getInstrumentNa Line 864  QString qsamplerChannel::getInstrumentNa
864                  sInstrumentName = QFileInfo(sInstrumentFile).fileName();                  sInstrumentName = QFileInfo(sInstrumentFile).fileName();
865  #ifdef CONFIG_LIBGIG  #ifdef CONFIG_LIBGIG
866                  if (bInstrumentNames) {                  if (bInstrumentNames) {
867                          RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1());                          RIFF::File *pRiff
868                          gig::File  *pGig  = new gig::File(pRiff);                                  = new RIFF::File(sInstrumentFile.toUtf8().constData());
869                            gig::File *pGig = new gig::File(pRiff);
870                          int iIndex = 0;                          int iIndex = 0;
871                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();                          gig::Instrument *pInstrument = pGig->GetFirstInstrument();
872                          while (pInstrument) {                          while (pInstrument) {
# Line 894  QString qsamplerChannel::loadingInstrume Line 906  QString qsamplerChannel::loadingInstrume
906  }  }
907    
908    
   
909  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
910  // qsamplerChannelRoutingTable - Channel routing table.  // ChannelRoutingModel - data model for audio routing (used for QTableView)
911  //  //
912    
913  // Constructor.  ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) {
 qsamplerChannelRoutingTable::qsamplerChannelRoutingTable (  
         QWidget *pParent, const char *pszName )  
         : QTable(pParent, pszName)  
 {  
         // Set fixed number of columns.  
         QTable::setNumCols(2);  
         QTable::setShowGrid(false);  
         QTable::setSorting(false);  
         QTable::setFocusStyle(QTable::FollowStyle);  
         QTable::setSelectionMode(QTable::NoSelection);  
         // No vertical header.  
         QTable::verticalHeader()->hide();  
         QTable::setLeftMargin(0);  
         // Initialize the fixed table column headings.  
         QHeader *pHeader = QTable::horizontalHeader();  
         pHeader->setLabel(0, tr("Sampler Channel"));  
         pHeader->setLabel(1, tr("Device Channel"));  
         // Set read-onlyness of each column  
         QTable::setColumnReadOnly(0, true);  
 //      QTable::setColumnReadOnly(1, false); -- of course not.  
         QTable::setColumnStretchable(1, true);  
914  }  }
915    
916  // Default destructor.  int ChannelRoutingModel::rowCount(const QModelIndex& /*parent*/) const {
917  qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void)      return routing.size();
 {  
918  }  }
919    
920    int ChannelRoutingModel::columnCount(const QModelIndex& /*parent*/) const {
921        return 1;
922    }
923    
924  // Routing map table renderer.  Qt::ItemFlags ChannelRoutingModel::flags(const QModelIndex& /*index*/) const {
925  void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice,      return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled;
926          const qsamplerChannelRoutingMap& routing )  }
 {  
         if (pDevice == NULL)  
                 return;  
927    
928          // Always (re)start it empty.  bool ChannelRoutingModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) {
929          QTable::setUpdatesEnabled(false);      if (!index.isValid()) {
930          QTable::setNumRows(0);          return false;
931        }
932          // The common device port item list.  
933          QStringList opts;      routing[index.row()] = value.toInt();
934          qsamplerDevicePortList& ports = pDevice->ports();  
935          qsamplerDevicePort *pPort;      emit dataChanged(index, index);
936          for (pPort = ports.first(); pPort; pPort = ports.next()) {      return true;
                 opts.append(pDevice->deviceTypeName()  
                         + ' ' + pDevice->driverName()  
                         + ' ' + pPort->portName());  
         }  
   
         // Those items shall have a proper pixmap...  
         QPixmap pmChannel = QPixmap::fromMimeSource("qsamplerChannel.png");  
         QPixmap pmDevice;  
         switch (pDevice->deviceType()) {  
         case qsamplerDevice::Audio:  
                 pmDevice = QPixmap::fromMimeSource("audio2.png");  
                 break;  
         case qsamplerDevice::Midi:  
                 pmDevice = QPixmap::fromMimeSource("midi2.png");  
                 break;  
         case qsamplerDevice::None:  
                 break;  
         }  
   
         // Fill the routing table...  
         QTable::insertRows(0, routing.count());  
         int iRow = 0;  
         qsamplerChannelRoutingMap::ConstIterator iter;  
         for (iter = routing.begin(); iter != routing.end(); ++iter) {  
                 QTable::setPixmap(iRow, 0, pmChannel);  
                 QTable::setText(iRow, 0, pDevice->deviceTypeName()  
                         + ' ' + QString::number(iter.key()));  
                 qsamplerChannelRoutingComboBox *pComboItem =  
                         new qsamplerChannelRoutingComboBox(this, opts, pmDevice);  
                 pComboItem->setCurrentItem(iter.data());  
                 QTable::setItem(iRow, 1, pComboItem);  
                 ++iRow;  
         }  
   
         // Adjust optimal column widths.  
         QTable::adjustColumn(0);  
         QTable::adjustColumn(1);  
   
         QTable::setUpdatesEnabled(true);  
         QTable::updateContents();  
937  }  }
938    
939    QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const {
940        if (!index.isValid())
941            return QVariant();
942        if (role != Qt::DisplayRole)
943            return QVariant();
944        if (index.column() != 0)
945            return QVariant();
946    
947        ChannelRoutingItem item;
948    
949        // The common device port item list.
950        qsamplerDevicePortList& ports = pDevice->ports();
951            QListIterator<qsamplerDevicePort *> iter(ports);
952            while (iter.hasNext()) {
953                    qsamplerDevicePort *pPort = iter.next();
954            item.options.append(
955                pDevice->deviceTypeName()
956                + ' ' + pDevice->driverName()
957                + ' ' + pPort->portName()
958            );
959        }
960    
961  // Commit any pending editing.      item.selection = routing[index.row()];
962  void qsamplerChannelRoutingTable::flush (void)  
963        return QVariant::fromValue(item);
964    }
965    
966    QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const {
967        if (role != Qt::DisplayRole) return QVariant();
968    
969        switch (orientation) {
970            case Qt::Horizontal:
971                return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel");
972            case Qt::Vertical:
973                return QObject::tr("Sampler Channel ") +
974                       QString::number(section) + " " + UNICODE_RIGHT_ARROW;
975            default:
976                return QVariant();
977        }
978    }
979    
980    void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice,
981            const qsamplerChannelRoutingMap& routing )
982  {  {
983          if (QTable::isEditing())      this->pDevice = pDevice;
984              QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true);      this->routing = routing;
985        // inform the outer world (QTableView) that our data changed
986        QAbstractTableModel::reset();
987  }  }
988    
989    
990  //-------------------------------------------------------------------------  //-------------------------------------------------------------------------
991  // qsamplerChannelRoutingComboBox - Custom combo box for routing table.  // ChannelRoutingDelegate - table cell renderer for audio routing
992  //  //
993    
994  // Constructor.  ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) {
 qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox (  
         QTable *pTable, const QStringList& list, const QPixmap& pixmap )  
         : QTableItem(pTable, QTableItem::WhenCurrent, QString::null, pixmap),  
         m_list(list)  
 {  
         m_iCurrentItem = 0;  
995  }  }
996    
997  // Public accessors.  QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent,
998  void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem )          const QStyleOptionViewItem & option ,
999            const QModelIndex& index) const
1000  {  {
1001          m_iCurrentItem = iCurrentItem;      if (!index.isValid()) {
1002            return NULL;
1003        }
1004    
1005        if (index.column() != 0) {
1006            return NULL;
1007        }
1008    
1009          QTableItem::setText(m_list[iCurrentItem]);      ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1010    
1011        QComboBox* pComboBox = new QComboBox(parent);
1012        pComboBox->addItems(item.options);
1013        pComboBox->setCurrentIndex(item.selection);
1014        pComboBox->setEnabled(true);
1015        pComboBox->setGeometry(option.rect);
1016        return pComboBox;
1017  }  }
1018    
1019  int qsamplerChannelRoutingComboBox::currentItem (void) const  void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const {
1020  {      ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>();
1021          return m_iCurrentItem;      QComboBox* comboBox = static_cast<QComboBox*>(editor);
1022        comboBox->setCurrentIndex(item.selection);
1023  }  }
1024    
1025  // Virtual implemetations.  void ChannelRoutingDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const {
1026  QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const      QComboBox* comboBox = static_cast<QComboBox*>(editor);
1027  {      model->setData(index, comboBox->currentIndex());
         QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport());  
         QObject::connect(pComboBox, SIGNAL(activated(int)),  
                 QTableItem::table(), SLOT(doValueChanged()));  
         for (QStringList::ConstIterator iter = m_list.begin();  
                         iter != m_list.end(); iter++) {  
                 pComboBox->insertItem(QTableItem::pixmap(), *iter);  
         }  
         pComboBox->setCurrentItem(m_iCurrentItem);  
         return pComboBox;  
1028  }  }
1029    
1030  void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget )  void ChannelRoutingDelegate::updateEditorGeometry(QWidget *editor,
1031            const QStyleOptionViewItem &option, const QModelIndex &/* index */) const
1032  {  {
1033          if (pWidget->inherits("QComboBox")) {      editor->setGeometry(option.rect);
                 QComboBox *pComboBox = (QComboBox *) pWidget;  
                 m_iCurrentItem = pComboBox->currentItem();  
                 QTableItem::setText(pComboBox->currentText());  
         }  
         else QTableItem::setContentFromEditor(pWidget);  
1034  }  }
1035    
   
1036  // end of qsamplerChannel.cpp  // end of qsamplerChannel.cpp

Legend:
Removed from v.1402  
changed lines
  Added in v.1499

  ViewVC Help
Powered by ViewVC