/[svn]/qsampler/trunk/src/qsamplerChannelStrip.cpp
ViewVC logotype

Diff of /qsampler/trunk/src/qsamplerChannelStrip.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1464 by capela, Thu Nov 1 17:14:21 2007 UTC revision 2569 by schoenebeck, Tue May 20 20:04:19 2014 UTC
# Line 1  Line 1 
1  // qsamplerChannelStrip.cpp  // qsamplerChannelStrip.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2014, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, 2008, 2014 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 20  Line 20 
20    
21  *****************************************************************************/  *****************************************************************************/
22    
23    #include "qsamplerAbout.h"
24  #include "qsamplerChannelStrip.h"  #include "qsamplerChannelStrip.h"
25    
26  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
27    
28  #include <q3dragobject.h>  #include "qsamplerChannelFxForm.h"
29    
30    #include <QMessageBox>
31    #include <QDragEnterEvent>
32    #include <QFileInfo>
33    #include <QTimer>
34  #include <QUrl>  #include <QUrl>
35    #include <QMenu>
36    
37  #include <math.h>  #if QT_VERSION >= 0x050000
38    #include <QMimeData>
39    #endif
40    
41  // Channel status/usage usage limit control.  // Channel status/usage usage limit control.
42  #define QSAMPLER_ERROR_LIMIT    3  #define QSAMPLER_ERROR_LIMIT    3
43    
44    // Needed for lroundf()
45    #include <math.h>
46    
47    #ifndef CONFIG_ROUND
48    static inline long lroundf ( float x )
49    {
50            if (x >= 0.0f)
51                    return long(x + 0.5f);
52            else
53                    return long(x - 0.5f);
54    }
55    #endif
56    
57    
58  namespace QSampler {  namespace QSampler {
59    
60  ChannelStrip::ChannelStrip(QWidget* parent, Qt::WFlags f) : QWidget(parent, f) {  //-------------------------------------------------------------------------
61      ui.setupUi(this);  // QSampler::ChannelStrip -- Channel strip form implementation.
62    //
63    
64      // Initialize locals.  // MIDI activity pixmap common resources.
65      m_pChannel     = NULL;  int      ChannelStrip::g_iMidiActivityRefCount = 0;
66      m_iDirtyChange = 0;  QPixmap *ChannelStrip::g_pMidiActivityLedOn    = NULL;
67      m_iErrorCount  = 0;  QPixmap *ChannelStrip::g_pMidiActivityLedOff   = NULL;
68    
69    // Channel strip activation/selection.
70    ChannelStrip *ChannelStrip::g_pSelectedStrip = NULL;
71    
72    ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags )
73            : QWidget(pParent, wflags)
74    {
75            m_ui.setupUi(this);
76    
77            // Initialize locals.
78            m_pChannel     = NULL;
79            m_iDirtyChange = 0;
80            m_iErrorCount  = 0;
81            m_instrumentListPopupMenu = NULL;
82    
83            if (++g_iMidiActivityRefCount == 1) {
84                    g_pMidiActivityLedOn  = new QPixmap(":/images/ledon1.png");
85                    g_pMidiActivityLedOff = new QPixmap(":/images/ledoff1.png");
86            }
87    
88      // Try to restore normal window positioning.          m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOff);
89      adjustSize();  
90  }  #ifndef CONFIG_EVENT_CHANNEL_MIDI
91            m_ui.MidiActivityLabel->setToolTip("MIDI activity (disabled)");
92    #endif
93    
94  ChannelStrip::~ChannelStrip() {          m_pMidiActivityTimer = new QTimer(this);
95      // Destroy existing channel descriptor.          m_pMidiActivityTimer->setSingleShot(true);
96      if (m_pChannel)  
97          delete m_pChannel;          QObject::connect(m_pMidiActivityTimer,
98      m_pChannel = NULL;                  SIGNAL(timeout()),
99                    SLOT(midiActivityLedOff())
100            );
101    
102            // Try to restore normal window positioning.
103            adjustSize();
104    
105            QObject::connect(m_ui.ChannelSetupPushButton,
106                    SIGNAL(clicked()),
107                    SLOT(channelSetup()));
108            QObject::connect(m_ui.ChannelMutePushButton,
109                    SIGNAL(toggled(bool)),
110                    SLOT(channelMute(bool)));
111            QObject::connect(m_ui.ChannelSoloPushButton,
112                    SIGNAL(toggled(bool)),
113                    SLOT(channelSolo(bool)));
114            QObject::connect(m_ui.VolumeSlider,
115                    SIGNAL(valueChanged(int)),
116                    SLOT(volumeChanged(int)));
117            QObject::connect(m_ui.VolumeSpinBox,
118                    SIGNAL(valueChanged(int)),
119                    SLOT(volumeChanged(int)));
120            QObject::connect(m_ui.ChannelEditPushButton,
121                    SIGNAL(clicked()),
122                    SLOT(channelEdit()));
123            QObject::connect(m_ui.FxPushButton,
124                    SIGNAL(clicked()),
125                    SLOT(channelFxEdit()));
126    
127            setSelected(false);
128  }  }
129    
130    
131  // Drag'n'drop file handler.  ChannelStrip::~ChannelStrip (void)
 bool ChannelStrip::decodeDragFile ( const QMimeSource *pEvent, QString& sInstrumentFile )  
132  {  {
133          if (m_pChannel == NULL)          setSelected(false);
134                  return false;  
135          if (Q3TextDrag::canDecode(pEvent)) {          // Destroy existing channel descriptor.
136                  QString sText;          if (m_pChannel)
137                  if (Q3TextDrag::decode(pEvent, sText)) {                  delete m_pChannel;
138                          QStringList files = QStringList::split('\n', sText);          m_pChannel = NULL;
139                          for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) {  
140                                  *iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path();          if (--g_iMidiActivityRefCount == 0) {
141                                  if (qsamplerChannel::isInstrumentFile(*iter)) {                  if (g_pMidiActivityLedOn)
142                                          sInstrumentFile = *iter;                          delete g_pMidiActivityLedOn;
143                                          return true;                  g_pMidiActivityLedOn = NULL;
144                                  }                  if (g_pMidiActivityLedOff)
145                          }                          delete g_pMidiActivityLedOff;
146                  }                  g_pMidiActivityLedOff = NULL;
147          }          }
         // Fail.  
         return false;  
148  }  }
149    
150    
151  // Window drag-n-drop event handlers.  // Window drag-n-drop event handlers.
152  void ChannelStrip::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )  void ChannelStrip::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )
153  {  {
154          QString sInstrumentFile;          if (m_pChannel == NULL)
155          pDragEnterEvent->accept(decodeDragFile(pDragEnterEvent, sInstrumentFile));                  return;
156    
157            bool bAccept = false;
158    
159            if (pDragEnterEvent->source() == NULL) {
160                    const QMimeData *pMimeData = pDragEnterEvent->mimeData();
161                    if (pMimeData && pMimeData->hasUrls()) {
162                            QListIterator<QUrl> iter(pMimeData->urls());
163                            while (iter.hasNext()) {
164                                    const QString& sFilename = iter.next().toLocalFile();
165                                    if (!sFilename.isEmpty()) {
166                                    //      bAccept = Channel::isDlsInstrumentFile(sFilename);
167                                            bAccept = QFileInfo(sFilename).exists();
168                                            break;
169                                    }
170                            }
171                    }
172            }
173    
174            if (bAccept)
175                    pDragEnterEvent->accept();
176            else
177                    pDragEnterEvent->ignore();
178  }  }
179    
180    
181  void ChannelStrip::dropEvent ( QDropEvent* pDropEvent )  void ChannelStrip::dropEvent ( QDropEvent* pDropEvent )
182  {  {
183          QString sInstrumentFile;          if (m_pChannel == NULL)
184                    return;
185    
186            if (pDropEvent->source())
187                    return;
188    
189          if (decodeDragFile(pDropEvent, sInstrumentFile)) {          const QMimeData *pMimeData = pDropEvent->mimeData();
190                  // Go and set the dropped instrument filename...          if (pMimeData && pMimeData->hasUrls()) {
191                  m_pChannel->setInstrument(sInstrumentFile, 0);                  QStringList files;
192                  // Open up the channel dialog.                  QListIterator<QUrl> iter(pMimeData->urls());
193                  channelSetup();                  while (iter.hasNext()) {
194                            const QString& sFilename = iter.next().toLocalFile();
195                            if (!sFilename.isEmpty()) {
196                                    // Go and set the dropped instrument filename...
197                                    m_pChannel->setInstrument(sFilename, 0);
198                                    // Open up the channel dialog.
199                                    channelSetup();
200                                    break;
201                            }
202                    }
203          }          }
204  }  }
205    
206    
207  // Channel strip setup formal initializer.  // Channel strip setup formal initializer.
208  void ChannelStrip::setup ( qsamplerChannel *pChannel )  void ChannelStrip::setup ( Channel *pChannel )
209  {  {
210      // Destroy any previous channel descriptor;          // Destroy any previous channel descriptor;
211      // (remember that once setup we own it!)          // (remember that once setup we own it!)
212      if (m_pChannel)          if (m_pChannel)
213          delete m_pChannel;                  delete m_pChannel;
214    
215      // Set the new one...          // Set the new one...
216      m_pChannel = pChannel;          m_pChannel = pChannel;
217    
218      // Stabilize this around.          // Stabilize this around.
219      updateChannelInfo();          updateChannelInfo();
220    
221          // We'll accept drops from now on...          // We'll accept drops from now on...
222          if (m_pChannel)          if (m_pChannel)
223                  setAcceptDrops(true);                  setAcceptDrops(true);
224  }  }
225    
226    
227  // Channel secriptor accessor.  // Channel secriptor accessor.
228  qsamplerChannel *ChannelStrip::channel (void)  Channel *ChannelStrip::channel (void) const
229  {  {
230      return m_pChannel;          return m_pChannel;
231  }  }
232    
233    
234  // Messages view font accessors.  // Messages view font accessors.
235  QFont ChannelStrip::displayFont (void)  QFont ChannelStrip::displayFont (void) const
236  {  {
237      return ui.EngineNameTextLabel->font();          return m_ui.EngineNameTextLabel->font();
238  }  }
239    
240  void ChannelStrip::setDisplayFont ( const QFont & font )  void ChannelStrip::setDisplayFont ( const QFont & font )
241  {  {
242      ui.EngineNameTextLabel->setFont(font);          m_ui.EngineNameTextLabel->setFont(font);
243      ui.MidiPortChannelTextLabel->setFont(font);          m_ui.MidiPortChannelTextLabel->setFont(font);
244      ui.InstrumentNameTextLabel->setFont(font);          m_ui.InstrumentNamePushButton->setFont(font);
245      ui.InstrumentStatusTextLabel->setFont(font);          m_ui.InstrumentNamePushButton->setFont(font);
246            m_ui.InstrumentStatusTextLabel->setFont(font);
247  }  }
248    
249    
250  // Channel display background effect.  // Channel display background effect.
251  void ChannelStrip::setDisplayEffect ( bool bDisplayEffect )  void ChannelStrip::setDisplayEffect ( bool bDisplayEffect )
252  {  {
253      QPixmap pm =          QPalette pal;
254          (bDisplayEffect) ?          pal.setColor(QPalette::Foreground, Qt::yellow);
255              QPixmap(":/qsampler/pixmaps/displaybg1.png") : QPixmap();          pal.setColor(QPalette::ButtonText, Qt::yellow);
256      setDisplayBackground(pm);          m_ui.EngineNameTextLabel->setPalette(pal);
257  }          m_ui.MidiPortChannelTextLabel->setPalette(pal);
258            pal.setColor(QPalette::Foreground, Qt::green);
259            if (bDisplayEffect) {
260  // Update main display background pixmap.                  QPixmap pm(":/images/displaybg1.png");
261  void ChannelStrip::setDisplayBackground ( const QPixmap& pm )                  pal.setBrush(QPalette::Background, QBrush(pm));
262  {          } else {
263      // Set the main origin...                  pal.setColor(QPalette::Background, Qt::black);
264      ui.ChannelInfoFrame->setPaletteBackgroundPixmap(pm);          }
265            m_ui.ChannelInfoFrame->setPalette(pal);
266      // Iterate for every child text label...          m_ui.InstrumentNamePushButton->setPalette(pal);
267      QList<QObject*> list = ui.ChannelInfoFrame->queryList("QLabel");          m_ui.StreamVoiceCountTextLabel->setPalette(pal);
     for (QList<QObject*>::iterator iter = list.begin(); iter != list.end(); iter++) {  
         static_cast<QLabel*>(*iter)->setPaletteBackgroundPixmap(pm);  
     }  
   
     // And this standalone too.  
     ui.StreamVoiceCountTextLabel->setPaletteBackgroundPixmap(pm);  
268  }  }
269    
270    
271  // Maximum volume slider accessors.  // Maximum volume slider accessors.
272  void ChannelStrip::setMaxVolume ( int iMaxVolume )  void ChannelStrip::setMaxVolume ( int iMaxVolume )
273  {  {
274      m_iDirtyChange++;          m_iDirtyChange++;
275      ui.VolumeSlider->setRange(0, iMaxVolume);          m_ui.VolumeSlider->setRange(0, iMaxVolume);
276      ui.VolumeSpinBox->setRange(0, iMaxVolume);          m_ui.VolumeSpinBox->setRange(0, iMaxVolume);
277      m_iDirtyChange--;          m_iDirtyChange--;
278  }  }
279    
280    
# Line 234  void ChannelStrip::channelEdit (void) Line 335  void ChannelStrip::channelEdit (void)
335          m_pChannel->editChannel();          m_pChannel->editChannel();
336  }  }
337    
338    bool ChannelStrip::channelFxEdit (void)
339    {
340            MainForm *pMainForm = MainForm::getInstance();
341            if (!pMainForm || !channel())
342                    return false;
343    
344            pMainForm->appendMessages(QObject::tr("channel fx sends..."));
345    
346            bool bResult = false;
347    
348    #if CONFIG_FXSEND
349            ChannelFxForm *pChannelFxForm =
350                    new ChannelFxForm(channel(), parentWidget());
351            if (pChannelFxForm) {
352                    //pChannelForm->setup(this);
353                    bResult = pChannelFxForm->exec();
354                    delete pChannelFxForm;
355            }
356    #else // CONFIG_FXSEND
357            QMessageBox::critical(this,
358                    QSAMPLER_TITLE ": " + tr("Unavailable"),
359                            tr("Sorry, QSampler was built without FX send support!\n\n"
360                               "(Make sure you have a recent liblscp when recompiling QSampler)"));
361    #endif // CONFIG_FXSEND
362    
363            return bResult;
364    }
365    
366  // Channel reset slot.  // Channel reset slot.
367  bool ChannelStrip::channelReset (void)  bool ChannelStrip::channelReset (void)
# Line 263  bool ChannelStrip::updateInstrumentName Line 391  bool ChannelStrip::updateInstrumentName
391    
392          // Instrument name...          // Instrument name...
393          if (m_pChannel->instrumentName().isEmpty()) {          if (m_pChannel->instrumentName().isEmpty()) {
394                  if (m_pChannel->instrumentStatus() >= 0)                  if (m_pChannel->instrumentStatus() >= 0) {
395                          ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument());                          m_ui.InstrumentNamePushButton->setText(
396                  else                                  ' ' + Channel::loadingInstrument());
397                          ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());                  } else {
398          } else                          m_ui.InstrumentNamePushButton->setText(
399                  ui.InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());                                  ' ' + Channel::noInstrumentName());
400                    }
401            } else {
402                    m_ui.InstrumentNamePushButton->setText(
403                            ' ' + m_pChannel->instrumentName());
404            }
405            
406            bool bShowInstrumentPopup = false;
407    
408            // Instrument list popup (for fast switching among sounds of the same file)
409            if (!m_pChannel->instrumentFile().isEmpty()) {
410                    QStringList instruments = Channel::getInstrumentList(
411                            m_pChannel->instrumentFile(), true
412                    );
413                    if (!instruments.isEmpty()) {
414                            bShowInstrumentPopup = true;
415                            if (!m_instrumentListPopupMenu) {
416                                    m_instrumentListPopupMenu = new QMenu(m_ui.InstrumentNamePushButton);
417                                    m_instrumentListPopupMenu->setTitle(tr("Instruments"));
418                                    m_instrumentListPopupMenu->setMinimumWidth(118); // for cosmetical reasons, should have at least the width of the instrument name label
419                                    m_ui.InstrumentNamePushButton->setMenu(m_instrumentListPopupMenu);
420                                    QObject::connect(
421                                            m_instrumentListPopupMenu, SIGNAL(triggered(QAction*)),
422                                            this, SLOT(instrumentListPopupItemClicked(QAction*))
423                                    );
424                            } else m_instrumentListPopupMenu->clear();
425    
426                            for (int i = 0; i < instruments.size(); ++i) {
427                                    QAction* action =
428                                            m_instrumentListPopupMenu->addAction(instruments.at(i));
429                                    action->setData(i);
430                                    if (i == m_pChannel->instrumentNr()) {
431                                            action->setCheckable(true);
432                                            action->setChecked(true);
433                                    }
434                            }
435                    }
436            }
437    
438            if (!bShowInstrumentPopup && m_instrumentListPopupMenu) {
439                    delete m_instrumentListPopupMenu;
440                    m_instrumentListPopupMenu = NULL;
441            }
442    
443          return true;          return true;
444  }  }
445    
446    void ChannelStrip::instrumentListPopupItemClicked (QAction* action)
447    {
448            if (!action) return;
449    
450            QVariant data = action->data();
451            if (data.isValid() && !m_pChannel->instrumentFile().isEmpty()) {
452                    m_pChannel->loadInstrument(m_pChannel->instrumentFile(), data.toInt());
453                    emit channelChanged(this);
454            }
455    }
456    
457  // Do the dirty volume change.  // Do the dirty volume change.
458  bool ChannelStrip::updateChannelVolume (void)  bool ChannelStrip::updateChannelVolume (void)
459  {  {
460      if (m_pChannel == NULL)          if (m_pChannel == NULL)
461          return false;                  return false;
   
     // Convert...  
 #ifdef CONFIG_ROUND  
     int iVolume = (int) ::round(100.0 * m_pChannel->volume());  
 #else  
     double fIPart = 0.0;  
     double fFPart = ::modf(100.0 * m_pChannel->volume(), &fIPart);  
     int iVolume = (int) fIPart;  
     if (fFPart >= +0.5)  
         iVolume++;  
     else  
     if (fFPart <= -0.5)  
         iVolume--;  
 #endif  
462    
463      // And clip...          // Convert...
464      if (iVolume < 0)          int iVolume = ::lroundf(100.0f * m_pChannel->volume());
465          iVolume = 0;          // And clip...
466            if (iVolume < 0)
467      // Flag it here, to avoid infinite recursion.                  iVolume = 0;
468      m_iDirtyChange++;  
469      ui.VolumeSlider->setValue(iVolume);          // Flag it here, to avoid infinite recursion.
470      ui.VolumeSpinBox->setValue(iVolume);          m_iDirtyChange++;
471      m_iDirtyChange--;          m_ui.VolumeSlider->setValue(iVolume);
472            m_ui.VolumeSpinBox->setValue(iVolume);
473            m_iDirtyChange--;
474    
475      return true;          return true;
476  }  }
477    
478    
479  // Update whole channel info state.  // Update whole channel info state.
480  bool ChannelStrip::updateChannelInfo (void)  bool ChannelStrip::updateChannelInfo (void)
481  {  {
482      if (m_pChannel == NULL)          if (m_pChannel == NULL)
483          return false;                  return false;
484    
485          // Check for error limit/recycle...          // Check for error limit/recycle...
486          if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)          if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)
487                  return true;                  return true;
488    
489      // Update strip caption.          // Update strip caption.
490      QString sText = m_pChannel->channelName();          QString sText = m_pChannel->channelName();
491      setCaption(sText);          setWindowTitle(sText);
492      ui.ChannelSetupPushButton->setText(sText);          m_ui.ChannelSetupPushButton->setText('&' + sText);
493    
494      // Check if we're up and connected.          // Check if we're up and connected.
495          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
496          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
497                  return false;                  return false;
498    
499      // Read actual channel information.          // Read actual channel information.
500      m_pChannel->updateChannelInfo();          m_pChannel->updateChannelInfo();
501    
502      // Engine name...          // Engine name...
503      if (m_pChannel->engineName().isEmpty())          if (m_pChannel->engineName().isEmpty()) {
504          ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());                  m_ui.EngineNameTextLabel->setText(
505      else                          ' ' + Channel::noEngineName());
506          ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName());          } else {
507                    m_ui.EngineNameTextLabel->setText(
508                            ' ' + m_pChannel->engineName());
509            }
510    
511          // Instrument name...          // Instrument name...
512          updateInstrumentName(false);          updateInstrumentName(false);
513    
514      // MIDI Port/Channel...          // MIDI Port/Channel...
515          QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";          QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";
516          if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)          if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
517                  sMidiPortChannel += tr("All");                  sMidiPortChannel += tr("All");
518          else          else
519                  sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1);                  sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1);
520          ui.MidiPortChannelTextLabel->setText(sMidiPortChannel);          m_ui.MidiPortChannelTextLabel->setText(sMidiPortChannel);
521    
522      // Instrument status...          // Common palette...
523      int iInstrumentStatus = m_pChannel->instrumentStatus();          QPalette pal;
524      if (iInstrumentStatus < 0) {          const QColor& rgbFore = pal.color(QPalette::Foreground);
525          ui.InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);  
526          ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));          // Instrument status...
527          m_iErrorCount++;          int iInstrumentStatus = m_pChannel->instrumentStatus();
528          return false;          if (iInstrumentStatus < 0) {
529      }                  pal.setColor(QPalette::Foreground, Qt::red);
530      // All seems normal...                  m_ui.InstrumentStatusTextLabel->setPalette(pal);
531      ui.InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);                  m_ui.InstrumentStatusTextLabel->setText(
532      ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%');                          tr("ERR%1").arg(iInstrumentStatus));
533      m_iErrorCount = 0;                  m_iErrorCount++;
534                    return false;
535            }
536            // All seems normal...
537            pal.setColor(QPalette::Foreground,
538                    iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
539            m_ui.InstrumentStatusTextLabel->setPalette(pal);
540            m_ui.InstrumentStatusTextLabel->setText(
541                    QString::number(iInstrumentStatus) + '%');
542            m_iErrorCount = 0;
543    
544  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
545      // Mute/Solo button state coloring...          // Mute/Solo button state coloring...
546      const QColor& rgbNormal = ChannelSetupPushButton->paletteBackgroundColor();          bool bMute = m_pChannel->channelMute();
547      bool bMute = m_pChannel->channelMute();          const QColor& rgbButton = pal.color(QPalette::Button);
548      ChannelMutePushButton->setPaletteBackgroundColor(bMute ? Qt::yellow : rgbNormal);          const QColor& rgbButtonText = pal.color(QPalette::ButtonText);
549      ChannelMutePushButton->setDown(bMute);          pal.setColor(QPalette::Foreground, rgbFore);
550      bool bSolo = m_pChannel->channelSolo();          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);
551      ChannelSoloPushButton->setPaletteBackgroundColor(bSolo ? Qt::cyan : rgbNormal);          pal.setColor(QPalette::ButtonText, bMute ? Qt::darkYellow : rgbButtonText);
552      ChannelSoloPushButton->setDown(bSolo);          m_ui.ChannelMutePushButton->setPalette(pal);
553            m_ui.ChannelMutePushButton->setDown(bMute);
554            bool bSolo = m_pChannel->channelSolo();
555            pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);  
556            pal.setColor(QPalette::ButtonText, bSolo ? Qt::darkCyan : rgbButtonText);
557            m_ui.ChannelSoloPushButton->setPalette(pal);
558            m_ui.ChannelSoloPushButton->setDown(bSolo);
559  #else  #else
560          ui.ChannelMutePushButton->setEnabled(false);          m_ui.ChannelMutePushButton->setEnabled(false);
561          ui.ChannelSoloPushButton->setEnabled(false);          m_ui.ChannelSoloPushButton->setEnabled(false);
562  #endif  #endif
563    
564      // And update the both GUI volume elements;          // And update the both GUI volume elements;
565      // return success if, and only if, intrument is fully loaded...          // return success if, and only if, intrument is fully loaded...
566      return updateChannelVolume() && (iInstrumentStatus == 100);          return updateChannelVolume() && (iInstrumentStatus == 100);
567  }  }
568    
569    
570  // Update whole channel usage state.  // Update whole channel usage state.
571  bool ChannelStrip::updateChannelUsage (void)  bool ChannelStrip::updateChannelUsage (void)
572  {  {
573      if (m_pChannel == NULL)          if (m_pChannel == NULL)
574          return false;                  return false;
575    
576          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
577          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 393  bool ChannelStrip::updateChannelUsage (v Line 579  bool ChannelStrip::updateChannelUsage (v
579    
580          // This only makes sense on fully loaded channels...          // This only makes sense on fully loaded channels...
581          if (m_pChannel->instrumentStatus() < 100)          if (m_pChannel->instrumentStatus() < 100)
582              return false;                  return false;
583    
584      // Get current channel voice count.          // Get current channel voice count.
585      int iVoiceCount  = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID());          int iVoiceCount  = ::lscp_get_channel_voice_count(
586      // Get current stream count.                  pMainForm->client(), m_pChannel->channelID());
587      int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID());  // Get current stream count.
588      // Get current channel buffer fill usage.          int iStreamCount = ::lscp_get_channel_stream_count(
589      // As benno has suggested this is the percentage usage                  pMainForm->client(), m_pChannel->channelID());
590      // of the least filled buffer stream...          // Get current channel buffer fill usage.
591      int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());;          // As benno has suggested this is the percentage usage
592            // of the least filled buffer stream...
593      // Update the GUI elements...          int iStreamUsage = ::lscp_get_channel_stream_usage(
594      ui.StreamUsageProgressBar->setValue(iStreamUsage);                  pMainForm->client(), m_pChannel->channelID());;
595      ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));  
596            // Update the GUI elements...
597            m_ui.StreamUsageProgressBar->setValue(iStreamUsage);
598            m_ui.StreamVoiceCountTextLabel->setText(
599                    QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
600    
601      // We're clean.          // We're clean.
602      return true;          return true;
603  }  }
604    
605    
606  // Volume change slot.  // Volume change slot.
607  void ChannelStrip::volumeChanged ( int iVolume )  void ChannelStrip::volumeChanged ( int iVolume )
608  {  {
609      if (m_pChannel == NULL)          if (m_pChannel == NULL)
610          return;                  return;
611    
612            // Avoid recursion.
613            if (m_iDirtyChange > 0)
614                    return;
615    
616      // Avoid recursion.          // Convert and clip.
617      if (m_iDirtyChange > 0)          float fVolume = (float) iVolume / 100.0f;
618          return;          if (fVolume < 0.001f)
619                    fVolume = 0.0f;
620      // Convert and clip.  
621      float fVolume = (float) iVolume / 100.0;          // Update the GUI elements.
622      if (fVolume < 0.001)          if (m_pChannel->setVolume(fVolume)) {
623          fVolume = 0.0;                  updateChannelVolume();
624                    emit channelChanged(this);
625      // Update the GUI elements.          }
     if (m_pChannel->setVolume(fVolume)) {  
         updateChannelVolume();  
         emit channelChanged(this);  
     }  
626  }  }
627    
628    
629  // Context menu event handler.  // Context menu event handler.
630  void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )  void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
631  {  {
632      if (m_pChannel == NULL)          if (m_pChannel == NULL)
633          return;                  return;
634    
635      // We'll just show up the main form's edit menu (thru qsamplerChannel).          // We'll just show up the main form's edit menu (thru qsamplerChannel).
636      m_pChannel->contextMenuEvent(pEvent);          m_pChannel->contextMenuEvent(pEvent);
637    }
638    
639    
640    void ChannelStrip::midiActivityLedOn (void)
641    {
642            m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOn);
643            m_pMidiActivityTimer->start(100);
644    }
645    
646    
647    void ChannelStrip::midiActivityLedOff (void)
648    {
649            m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOff);
650  }  }
651    
652    
# Line 453  void ChannelStrip::resetErrorCount (void Line 656  void ChannelStrip::resetErrorCount (void
656          m_iErrorCount = 0;          m_iErrorCount = 0;
657  }  }
658    
659    
660    // Channel strip activation/selection.
661    void ChannelStrip::setSelected ( bool bSelected )
662    {
663            if (bSelected) {
664                    if (g_pSelectedStrip == this)
665                            return;
666                    if (g_pSelectedStrip)
667                            g_pSelectedStrip->setSelected(false);
668                    g_pSelectedStrip = this;
669            } else {
670                    if (g_pSelectedStrip == this)
671                            g_pSelectedStrip = NULL;
672            }
673    
674            QPalette pal;
675            if (bSelected) {
676                    const QColor& color = pal.midlight().color();
677                    pal.setColor(QPalette::Background, color.dark(150));
678                    pal.setColor(QPalette::Foreground, color.light(150));
679            }
680            QWidget::setPalette(pal);
681    }
682    
683    
684    bool ChannelStrip::isSelected (void) const
685    {
686            return (this == g_pSelectedStrip);
687    }
688    
689    
690  } // namespace QSampler  } // namespace QSampler
691    
692    

Legend:
Removed from v.1464  
changed lines
  Added in v.2569

  ViewVC Help
Powered by ViewVC