/[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 1691 by schoenebeck, Thu Feb 14 22:31:26 2008 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     Copyright (C) 2007, 2008 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 <QUrl>  #include <QUrl>
33    
34  #include <math.h>  #define MIDI_OFF_COLOR                  Qt::darkGreen
35    #define MIDI_ON_COLOR                   Qt::green
36    
37  // Channel status/usage usage limit control.  // Channel status/usage usage limit control.
38  #define QSAMPLER_ERROR_LIMIT    3  #define QSAMPLER_ERROR_LIMIT    3
39    
40    // Needed for lroundf()
41    #include <math.h>
42    
43    #ifndef CONFIG_ROUND
44    static inline long lroundf ( float x )
45    {
46            if (x >= 0.0f)
47                    return long(x + 0.5f);
48            else
49                    return long(x - 0.5f);
50    }
51    #endif
52    
53    
54  namespace QSampler {  namespace QSampler {
55    
56  ChannelStrip::ChannelStrip(QWidget* parent, Qt::WFlags f) : QWidget(parent, f) {  //-------------------------------------------------------------------------
57      ui.setupUi(this);  // QSampler::ChannelStrip -- Channel strip form implementation.
58    //
59    
60    // Channel strip activation/selection.
61    ChannelStrip *ChannelStrip::g_pSelectedStrip = NULL;
62    
63    ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags )
64            : QWidget(pParent, wflags)
65    {
66            m_ui.setupUi(this);
67    
68      // Initialize locals.          // Initialize locals.
69      m_pChannel     = NULL;          m_pChannel     = NULL;
70      m_iDirtyChange = 0;          m_iDirtyChange = 0;
71      m_iErrorCount  = 0;          m_iErrorCount  = 0;
72    
73            // Try to restore normal window positioning.
74            adjustSize();
75    
76            QObject::connect(m_ui.ChannelSetupPushButton,
77                    SIGNAL(clicked()),
78                    SLOT(channelSetup()));
79            QObject::connect(m_ui.ChannelMutePushButton,
80                    SIGNAL(toggled(bool)),
81                    SLOT(channelMute(bool)));
82            QObject::connect(m_ui.ChannelSoloPushButton,
83                    SIGNAL(toggled(bool)),
84                    SLOT(channelSolo(bool)));
85            QObject::connect(m_ui.VolumeSlider,
86                    SIGNAL(valueChanged(int)),
87                    SLOT(volumeChanged(int)));
88            QObject::connect(m_ui.VolumeSpinBox,
89                    SIGNAL(valueChanged(int)),
90                    SLOT(volumeChanged(int)));
91            QObject::connect(m_ui.ChannelEditPushButton,
92                    SIGNAL(clicked()),
93                    SLOT(channelEdit()));
94            QObject::connect(m_ui.FxPushButton,
95                    SIGNAL(clicked()),
96                    SLOT(channelFxEdit()));
97    
98            pMidiActivityTimer = new QTimer(this);
99            pMidiActivityTimer->setSingleShot(true);
100            QObject::connect(
101                    pMidiActivityTimer, SIGNAL(timeout()),
102                    this, SLOT(midiDataCeased())
103            );
104    
105    #if CONFIG_LSCP_CHANNEL_MIDI
106            m_ui.MidiActivityLabel->setPalette(MIDI_OFF_COLOR);
107            m_ui.MidiActivityLabel->setAutoFillBackground(true);
108    #else
109            m_ui.MidiActivityLabel->setText("X");
110            m_ui.MidiActivityLabel->setTooltip("MIDI Activity Disabled");
111    #endif
112    
113      // Try to restore normal window positioning.          setSelected(false);
     adjustSize();  
114  }  }
115    
116  ChannelStrip::~ChannelStrip() {  
117      // Destroy existing channel descriptor.  ChannelStrip::~ChannelStrip (void)
118      if (m_pChannel)  {
119          delete m_pChannel;          setSelected(false);
120      m_pChannel = NULL;  
121            // Destroy existing channel descriptor.
122            if (m_pChannel)
123                    delete m_pChannel;
124            m_pChannel = NULL;
125  }  }
126    
127    
128  // Drag'n'drop file handler.  // Window drag-n-drop event handlers.
129  bool ChannelStrip::decodeDragFile ( const QMimeSource *pEvent, QString& sInstrumentFile )  void ChannelStrip::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )
130  {  {
131          if (m_pChannel == NULL)          if (m_pChannel == NULL)
132                  return false;                  return;
133          if (Q3TextDrag::canDecode(pEvent)) {  
134                  QString sText;          bool bAccept = false;
135                  if (Q3TextDrag::decode(pEvent, sText)) {  
136                          QStringList files = QStringList::split('\n', sText);          if (pDragEnterEvent->source() == NULL) {
137                          for (QStringList::Iterator iter = files.begin(); iter != files.end(); iter++) {                  const QMimeData *pMimeData = pDragEnterEvent->mimeData();
138                                  *iter = QUrl((*iter).stripWhiteSpace().replace(QRegExp("^file:"), QString::null)).path();                  if (pMimeData && pMimeData->hasUrls()) {
139                                  if (qsamplerChannel::isInstrumentFile(*iter)) {                          QListIterator<QUrl> iter(pMimeData->urls());
140                                          sInstrumentFile = *iter;                          while (iter.hasNext()) {
141                                          return true;                                  const QString& sFilename = iter.next().toLocalFile();
142                                    if (!sFilename.isEmpty()) {
143                                            bAccept = Channel::isInstrumentFile(sFilename);
144                                            break;
145                                  }                                  }
146                          }                          }
147                  }                  }
148          }          }
         // Fail.  
         return false;  
 }  
   
149    
150  // Window drag-n-drop event handlers.          if (bAccept)
151  void ChannelStrip::dragEnterEvent ( QDragEnterEvent* pDragEnterEvent )                  pDragEnterEvent->accept();
152  {          else
153          QString sInstrumentFile;                  pDragEnterEvent->ignore();
         pDragEnterEvent->accept(decodeDragFile(pDragEnterEvent, sInstrumentFile));  
154  }  }
155    
156    
157  void ChannelStrip::dropEvent ( QDropEvent* pDropEvent )  void ChannelStrip::dropEvent ( QDropEvent* pDropEvent )
158  {  {
159          QString sInstrumentFile;          if (m_pChannel == NULL)
160                    return;
161    
162          if (decodeDragFile(pDropEvent, sInstrumentFile)) {          if (pDropEvent->source())
163                  // Go and set the dropped instrument filename...                  return;
164                  m_pChannel->setInstrument(sInstrumentFile, 0);  
165                  // Open up the channel dialog.          const QMimeData *pMimeData = pDropEvent->mimeData();
166                  channelSetup();          if (pMimeData && pMimeData->hasUrls()) {
167                    QStringList files;
168                    QListIterator<QUrl> iter(pMimeData->urls());
169                    while (iter.hasNext()) {
170                            const QString& sFilename = iter.next().toLocalFile();
171                            if (!sFilename.isEmpty()) {
172                                    // Go and set the dropped instrument filename...
173                                    m_pChannel->setInstrument(sFilename, 0);
174                                    // Open up the channel dialog.
175                                    channelSetup();
176                                    break;
177                            }
178                    }
179          }          }
180  }  }
181    
182    
183  // Channel strip setup formal initializer.  // Channel strip setup formal initializer.
184  void ChannelStrip::setup ( qsamplerChannel *pChannel )  void ChannelStrip::setup ( Channel *pChannel )
185  {  {
186      // Destroy any previous channel descriptor;          // Destroy any previous channel descriptor;
187      // (remember that once setup we own it!)          // (remember that once setup we own it!)
188      if (m_pChannel)          if (m_pChannel)
189          delete m_pChannel;                  delete m_pChannel;
190    
191      // Set the new one...          // Set the new one...
192      m_pChannel = pChannel;          m_pChannel = pChannel;
193    
194      // Stabilize this around.          // Stabilize this around.
195      updateChannelInfo();          updateChannelInfo();
196    
197          // We'll accept drops from now on...          // We'll accept drops from now on...
198          if (m_pChannel)          if (m_pChannel)
199                  setAcceptDrops(true);                  setAcceptDrops(true);
200  }  }
201    
202    
203  // Channel secriptor accessor.  // Channel secriptor accessor.
204  qsamplerChannel *ChannelStrip::channel (void)  Channel *ChannelStrip::channel (void) const
205  {  {
206      return m_pChannel;          return m_pChannel;
207  }  }
208    
209    
210  // Messages view font accessors.  // Messages view font accessors.
211  QFont ChannelStrip::displayFont (void)  QFont ChannelStrip::displayFont (void) const
212  {  {
213      return ui.EngineNameTextLabel->font();          return m_ui.EngineNameTextLabel->font();
214  }  }
215    
216  void ChannelStrip::setDisplayFont ( const QFont & font )  void ChannelStrip::setDisplayFont ( const QFont & font )
217  {  {
218      ui.EngineNameTextLabel->setFont(font);          m_ui.EngineNameTextLabel->setFont(font);
219      ui.MidiPortChannelTextLabel->setFont(font);          m_ui.MidiPortChannelTextLabel->setFont(font);
220      ui.InstrumentNameTextLabel->setFont(font);          m_ui.InstrumentNameTextLabel->setFont(font);
221      ui.InstrumentStatusTextLabel->setFont(font);          m_ui.InstrumentStatusTextLabel->setFont(font);
222  }  }
223    
224    
225  // Channel display background effect.  // Channel display background effect.
226  void ChannelStrip::setDisplayEffect ( bool bDisplayEffect )  void ChannelStrip::setDisplayEffect ( bool bDisplayEffect )
227  {  {
228      QPixmap pm =          QPalette pal;
229          (bDisplayEffect) ?          pal.setColor(QPalette::Foreground, Qt::yellow);
230              QPixmap(":/qsampler/pixmaps/displaybg1.png") : QPixmap();          m_ui.EngineNameTextLabel->setPalette(pal);
231      setDisplayBackground(pm);          m_ui.MidiPortChannelTextLabel->setPalette(pal);
232  }          pal.setColor(QPalette::Foreground, Qt::green);
233            if (bDisplayEffect) {
234                    QPixmap pm(":/icons/displaybg1.png");
235  // Update main display background pixmap.                  pal.setBrush(QPalette::Background, QBrush(pm));
236  void ChannelStrip::setDisplayBackground ( const QPixmap& pm )          } else {
237  {                  pal.setColor(QPalette::Background, Qt::black);
238      // Set the main origin...          }
239      ui.ChannelInfoFrame->setPaletteBackgroundPixmap(pm);          m_ui.ChannelInfoFrame->setPalette(pal);
240            m_ui.InstrumentNameTextLabel->setPalette(pal);
241      // Iterate for every child text label...          m_ui.StreamVoiceCountTextLabel->setPalette(pal);
     QList<QObject*> list = ui.ChannelInfoFrame->queryList("QLabel");  
     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);  
242  }  }
243    
244    
245  // Maximum volume slider accessors.  // Maximum volume slider accessors.
246  void ChannelStrip::setMaxVolume ( int iMaxVolume )  void ChannelStrip::setMaxVolume ( int iMaxVolume )
247  {  {
248      m_iDirtyChange++;          m_iDirtyChange++;
249      ui.VolumeSlider->setRange(0, iMaxVolume);          m_ui.VolumeSlider->setRange(0, iMaxVolume);
250      ui.VolumeSpinBox->setRange(0, iMaxVolume);          m_ui.VolumeSpinBox->setRange(0, iMaxVolume);
251      m_iDirtyChange--;          m_iDirtyChange--;
252  }  }
253    
254    
# Line 234  void ChannelStrip::channelEdit (void) Line 309  void ChannelStrip::channelEdit (void)
309          m_pChannel->editChannel();          m_pChannel->editChannel();
310  }  }
311    
312    bool ChannelStrip::channelFxEdit (void)
313    {
314            MainForm *pMainForm = MainForm::getInstance();
315            if (!pMainForm || !channel())
316                    return false;
317    
318            pMainForm->appendMessages(QObject::tr("channel fx sends..."));
319    
320            bool bResult = false;
321    
322    #if CONFIG_FXSEND
323            ChannelFxForm *pChannelFxForm =
324                    new ChannelFxForm(channel(), parentWidget());
325            if (pChannelFxForm) {
326                    //pChannelForm->setup(this);
327                    bResult = pChannelFxForm->exec();
328                    delete pChannelFxForm;
329            }
330    #else // CONFIG_FXSEND
331            QMessageBox::critical(this,
332                    QSAMPLER_TITLE ": " + tr("Unavailable"),
333                            tr("Sorry, QSampler was built without FX send support!\n\n"
334                               "(Make sure you have a recent liblscp when recompiling QSampler)"));
335    #endif // CONFIG_FXSEND
336    
337            return bResult;
338    }
339    
340  // Channel reset slot.  // Channel reset slot.
341  bool ChannelStrip::channelReset (void)  bool ChannelStrip::channelReset (void)
# Line 263  bool ChannelStrip::updateInstrumentName Line 365  bool ChannelStrip::updateInstrumentName
365    
366          // Instrument name...          // Instrument name...
367          if (m_pChannel->instrumentName().isEmpty()) {          if (m_pChannel->instrumentName().isEmpty()) {
368                  if (m_pChannel->instrumentStatus() >= 0)                  if (m_pChannel->instrumentStatus() >= 0) {
369                          ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument());                          m_ui.InstrumentNameTextLabel->setText(
370                  else                                  ' ' + Channel::loadingInstrument());
371                          ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());                  } else {
372          } else                          m_ui.InstrumentNameTextLabel->setText(
373                  ui.InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());                                  ' ' + Channel::noInstrumentName());
374                    }
375            } else {
376                    m_ui.InstrumentNameTextLabel->setText(
377                            ' ' + m_pChannel->instrumentName());
378            }
379    
380          return true;          return true;
381  }  }
# Line 277  bool ChannelStrip::updateInstrumentName Line 384  bool ChannelStrip::updateInstrumentName
384  // Do the dirty volume change.  // Do the dirty volume change.
385  bool ChannelStrip::updateChannelVolume (void)  bool ChannelStrip::updateChannelVolume (void)
386  {  {
387      if (m_pChannel == NULL)          if (m_pChannel == NULL)
388          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  
389    
390      // And clip...          // Convert...
391      if (iVolume < 0)          int iVolume = ::lroundf(100.0f * m_pChannel->volume());
392          iVolume = 0;          // And clip...
393            if (iVolume < 0)
394      // Flag it here, to avoid infinite recursion.                  iVolume = 0;
395      m_iDirtyChange++;  
396      ui.VolumeSlider->setValue(iVolume);          // Flag it here, to avoid infinite recursion.
397      ui.VolumeSpinBox->setValue(iVolume);          m_iDirtyChange++;
398      m_iDirtyChange--;          m_ui.VolumeSlider->setValue(iVolume);
399            m_ui.VolumeSpinBox->setValue(iVolume);
400            m_iDirtyChange--;
401    
402      return true;          return true;
403  }  }
404    
405    
406  // Update whole channel info state.  // Update whole channel info state.
407  bool ChannelStrip::updateChannelInfo (void)  bool ChannelStrip::updateChannelInfo (void)
408  {  {
409      if (m_pChannel == NULL)          if (m_pChannel == NULL)
410          return false;                  return false;
411    
412          // Check for error limit/recycle...          // Check for error limit/recycle...
413          if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)          if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)
414                  return true;                  return true;
415    
416      // Update strip caption.          // Update strip caption.
417      QString sText = m_pChannel->channelName();          QString sText = m_pChannel->channelName();
418      setCaption(sText);          setWindowTitle(sText);
419      ui.ChannelSetupPushButton->setText(sText);          m_ui.ChannelSetupPushButton->setText('&' + sText);
420    
421      // Check if we're up and connected.          // Check if we're up and connected.
422          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
423          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
424                  return false;                  return false;
425    
426      // Read actual channel information.          // Read actual channel information.
427      m_pChannel->updateChannelInfo();          m_pChannel->updateChannelInfo();
428    
429      // Engine name...          // Engine name...
430      if (m_pChannel->engineName().isEmpty())          if (m_pChannel->engineName().isEmpty()) {
431          ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());                  m_ui.EngineNameTextLabel->setText(
432      else                          ' ' + Channel::noEngineName());
433          ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName());          } else {
434                    m_ui.EngineNameTextLabel->setText(
435                            ' ' + m_pChannel->engineName());
436            }
437    
438          // Instrument name...          // Instrument name...
439          updateInstrumentName(false);          updateInstrumentName(false);
440    
441      // MIDI Port/Channel...          // MIDI Port/Channel...
442          QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";          QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";
443          if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)          if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
444                  sMidiPortChannel += tr("All");                  sMidiPortChannel += tr("All");
445          else          else
446                  sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1);                  sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1);
447          ui.MidiPortChannelTextLabel->setText(sMidiPortChannel);          m_ui.MidiPortChannelTextLabel->setText(sMidiPortChannel);
448    
449      // Instrument status...          // Common palette...
450      int iInstrumentStatus = m_pChannel->instrumentStatus();          QPalette pal;
451      if (iInstrumentStatus < 0) {          const QColor& rgbFore = pal.color(QPalette::Foreground);
452          ui.InstrumentStatusTextLabel->setPaletteForegroundColor(Qt::red);  
453          ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));          // Instrument status...
454          m_iErrorCount++;          int iInstrumentStatus = m_pChannel->instrumentStatus();
455          return false;          if (iInstrumentStatus < 0) {
456      }                  pal.setColor(QPalette::Foreground, Qt::red);
457      // All seems normal...                  m_ui.InstrumentStatusTextLabel->setPalette(pal);
458      ui.InstrumentStatusTextLabel->setPaletteForegroundColor(iInstrumentStatus < 100 ? Qt::yellow : Qt::green);                  m_ui.InstrumentStatusTextLabel->setText(
459      ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%');                          tr("ERR%1").arg(iInstrumentStatus));
460      m_iErrorCount = 0;                  m_iErrorCount++;
461                    return false;
462            }
463            // All seems normal...
464            pal.setColor(QPalette::Foreground,
465                    iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
466            m_ui.InstrumentStatusTextLabel->setPalette(pal);
467            m_ui.InstrumentStatusTextLabel->setText(
468                    QString::number(iInstrumentStatus) + '%');
469            m_iErrorCount = 0;
470    
471  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
472      // Mute/Solo button state coloring...          // Mute/Solo button state coloring...
473      const QColor& rgbNormal = ChannelSetupPushButton->paletteBackgroundColor();          bool bMute = m_pChannel->channelMute();
474      bool bMute = m_pChannel->channelMute();          const QColor& rgbButton = pal.color(QPalette::Button);
475      ChannelMutePushButton->setPaletteBackgroundColor(bMute ? Qt::yellow : rgbNormal);          pal.setColor(QPalette::Foreground, rgbFore);
476      ChannelMutePushButton->setDown(bMute);          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);
477      bool bSolo = m_pChannel->channelSolo();          m_ui.ChannelMutePushButton->setPalette(pal);
478      ChannelSoloPushButton->setPaletteBackgroundColor(bSolo ? Qt::cyan : rgbNormal);          m_ui.ChannelMutePushButton->setDown(bMute);
479      ChannelSoloPushButton->setDown(bSolo);          bool bSolo = m_pChannel->channelSolo();
480            pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);  
481            m_ui.ChannelSoloPushButton->setPalette(pal);
482            m_ui.ChannelSoloPushButton->setDown(bSolo);
483  #else  #else
484          ui.ChannelMutePushButton->setEnabled(false);          m_ui.ChannelMutePushButton->setEnabled(false);
485          ui.ChannelSoloPushButton->setEnabled(false);          m_ui.ChannelSoloPushButton->setEnabled(false);
486  #endif  #endif
487    
488      // And update the both GUI volume elements;          // And update the both GUI volume elements;
489      // return success if, and only if, intrument is fully loaded...          // return success if, and only if, intrument is fully loaded...
490      return updateChannelVolume() && (iInstrumentStatus == 100);          return updateChannelVolume() && (iInstrumentStatus == 100);
491  }  }
492    
493    
494  // Update whole channel usage state.  // Update whole channel usage state.
495  bool ChannelStrip::updateChannelUsage (void)  bool ChannelStrip::updateChannelUsage (void)
496  {  {
497      if (m_pChannel == NULL)          if (m_pChannel == NULL)
498          return false;                  return false;
499    
500          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
501          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 393  bool ChannelStrip::updateChannelUsage (v Line 503  bool ChannelStrip::updateChannelUsage (v
503    
504          // This only makes sense on fully loaded channels...          // This only makes sense on fully loaded channels...
505          if (m_pChannel->instrumentStatus() < 100)          if (m_pChannel->instrumentStatus() < 100)
506              return false;                  return false;
507    
508      // Get current channel voice count.          // Get current channel voice count.
509      int iVoiceCount  = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID());          int iVoiceCount  = ::lscp_get_channel_voice_count(
510      // Get current stream count.                  pMainForm->client(), m_pChannel->channelID());
511      int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID());  // Get current stream count.
512      // Get current channel buffer fill usage.          int iStreamCount = ::lscp_get_channel_stream_count(
513      // As benno has suggested this is the percentage usage                  pMainForm->client(), m_pChannel->channelID());
514      // of the least filled buffer stream...          // Get current channel buffer fill usage.
515      int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());;          // As benno has suggested this is the percentage usage
516            // of the least filled buffer stream...
517      // Update the GUI elements...          int iStreamUsage = ::lscp_get_channel_stream_usage(
518      ui.StreamUsageProgressBar->setValue(iStreamUsage);                  pMainForm->client(), m_pChannel->channelID());;
519      ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));  
520            // Update the GUI elements...
521            m_ui.StreamUsageProgressBar->setValue(iStreamUsage);
522            m_ui.StreamVoiceCountTextLabel->setText(
523                    QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
524    
525      // We're clean.          // We're clean.
526      return true;          return true;
527  }  }
528    
529    
530  // Volume change slot.  // Volume change slot.
531  void ChannelStrip::volumeChanged ( int iVolume )  void ChannelStrip::volumeChanged ( int iVolume )
532  {  {
533      if (m_pChannel == NULL)          if (m_pChannel == NULL)
534          return;                  return;
535    
536            // Avoid recursion.
537            if (m_iDirtyChange > 0)
538                    return;
539    
540      // Avoid recursion.          // Convert and clip.
541      if (m_iDirtyChange > 0)          float fVolume = (float) iVolume / 100.0f;
542          return;          if (fVolume < 0.001f)
543                    fVolume = 0.0f;
544      // Convert and clip.  
545      float fVolume = (float) iVolume / 100.0;          // Update the GUI elements.
546      if (fVolume < 0.001)          if (m_pChannel->setVolume(fVolume)) {
547          fVolume = 0.0;                  updateChannelVolume();
548                    emit channelChanged(this);
549      // Update the GUI elements.          }
     if (m_pChannel->setVolume(fVolume)) {  
         updateChannelVolume();  
         emit channelChanged(this);  
     }  
550  }  }
551    
552    void ChannelStrip::midiArrived() {
553            m_ui.MidiActivityLabel->setPalette(MIDI_ON_COLOR);
554            pMidiActivityTimer->start(50);
555    }
556    
557  // Context menu event handler.  // Context menu event handler.
558  void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )  void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
559  {  {
560      if (m_pChannel == NULL)          if (m_pChannel == NULL)
561          return;                  return;
562    
563      // 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).
564      m_pChannel->contextMenuEvent(pEvent);          m_pChannel->contextMenuEvent(pEvent);
565  }  }
566    
567    void ChannelStrip::midiDataCeased() {
568            m_ui.MidiActivityLabel->setPalette(MIDI_OFF_COLOR);
569    }
570    
571  // Error count hackish accessors.  // Error count hackish accessors.
572  void ChannelStrip::resetErrorCount (void)  void ChannelStrip::resetErrorCount (void)
# Line 453  void ChannelStrip::resetErrorCount (void Line 574  void ChannelStrip::resetErrorCount (void
574          m_iErrorCount = 0;          m_iErrorCount = 0;
575  }  }
576    
577    
578    // Channel strip activation/selection.
579    void ChannelStrip::setSelected ( bool bSelected )
580    {
581            if (bSelected) {
582                    if (g_pSelectedStrip == this)
583                            return;
584                    if (g_pSelectedStrip)
585                            g_pSelectedStrip->setSelected(false);
586                    g_pSelectedStrip = this;
587            } else {
588                    if (g_pSelectedStrip == this)
589                            g_pSelectedStrip = NULL;
590            }
591    
592            QPalette pal;
593            if (bSelected) {
594                    const QColor& color = pal.midlight().color();
595                    pal.setColor(QPalette::Background, color.dark(150));
596                    pal.setColor(QPalette::Foreground, color.light(150));
597            }
598            QWidget::setPalette(pal);
599    }
600    
601    
602    bool ChannelStrip::isSelected (void) const
603    {
604            return (this == g_pSelectedStrip);
605    }
606    
607    
608  } // namespace QSampler  } // namespace QSampler
609    
610    

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

  ViewVC Help
Powered by ViewVC