/[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 1499 by capela, Tue Nov 20 16:48:04 2007 UTC revision 1558 by capela, Thu Dec 6 09:35:33 2007 UTC
# Line 28  Line 28 
28  #include <QDragEnterEvent>  #include <QDragEnterEvent>
29  #include <QUrl>  #include <QUrl>
30    
 #include <math.h>  
   
31  // Channel status/usage usage limit control.  // Channel status/usage usage limit control.
32  #define QSAMPLER_ERROR_LIMIT    3  #define QSAMPLER_ERROR_LIMIT    3
33    
34    // Needed for lroundf()
35    #include <math.h>
36    
37    #ifndef CONFIG_ROUND
38    static inline long lroundf ( float x )
39    {
40            if (x >= 0.0f)
41                    return long(x + 0.5f);
42            else
43                    return long(x - 0.5f);
44    }
45    #endif
46    
47    
48  namespace QSampler {  namespace QSampler {
49    
50  ChannelStrip::ChannelStrip(QWidget* parent, Qt::WFlags f) : QWidget(parent, f) {  //-------------------------------------------------------------------------
51      ui.setupUi(this);  // QSampler::ChannelStrip -- Channel strip form implementation.
52    //
53    
54    // Channel strip activation/selection.
55    ChannelStrip *ChannelStrip::g_pSelectedStrip = NULL;
56    
57    ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags )
58            : QWidget(pParent, wflags)
59    {
60            m_ui.setupUi(this);
61    
62      // Initialize locals.          // Initialize locals.
63      m_pChannel     = NULL;          m_pChannel     = NULL;
64      m_iDirtyChange = 0;          m_iDirtyChange = 0;
65      m_iErrorCount  = 0;          m_iErrorCount  = 0;
66    
67      // Try to restore normal window positioning.          // Try to restore normal window positioning.
68      adjustSize();          adjustSize();
69    
70          QObject::connect(ui.ChannelSetupPushButton,          QObject::connect(m_ui.ChannelSetupPushButton,
71                  SIGNAL(clicked()),                  SIGNAL(clicked()),
72                  SLOT(channelSetup()));                  SLOT(channelSetup()));
73          QObject::connect(ui.ChannelMutePushButton,          QObject::connect(m_ui.ChannelMutePushButton,
74                  SIGNAL(toggled(bool)),                  SIGNAL(toggled(bool)),
75                  SLOT(channelMute(bool)));                  SLOT(channelMute(bool)));
76          QObject::connect(ui.ChannelSoloPushButton,          QObject::connect(m_ui.ChannelSoloPushButton,
77                  SIGNAL(toggled(bool)),                  SIGNAL(toggled(bool)),
78                  SLOT(channelSolo(bool)));                  SLOT(channelSolo(bool)));
79          QObject::connect(ui.VolumeSlider,          QObject::connect(m_ui.VolumeSlider,
80                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
81                  SLOT(volumeChanged(int)));                  SLOT(volumeChanged(int)));
82          QObject::connect(ui.VolumeSpinBox,          QObject::connect(m_ui.VolumeSpinBox,
83                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
84                  SLOT(volumeChanged(int)));                  SLOT(volumeChanged(int)));
85          QObject::connect(ui.ChannelEditPushButton,          QObject::connect(m_ui.ChannelEditPushButton,
86                  SIGNAL(clicked()),                  SIGNAL(clicked()),
87                  SLOT(channelEdit()));                  SLOT(channelEdit()));
88    
89            setSelected(false);
90  }  }
91    
92  ChannelStrip::~ChannelStrip() {  
93      // Destroy existing channel descriptor.  ChannelStrip::~ChannelStrip (void)
94      if (m_pChannel)  {
95          delete m_pChannel;          setSelected(false);
96      m_pChannel = NULL;  
97            // Destroy existing channel descriptor.
98            if (m_pChannel)
99                    delete m_pChannel;
100            m_pChannel = NULL;
101  }  }
102    
103    
# Line 89  void ChannelStrip::dragEnterEvent ( QDra Line 116  void ChannelStrip::dragEnterEvent ( QDra
116                          while (iter.hasNext()) {                          while (iter.hasNext()) {
117                                  const QString& sFilename = iter.next().toLocalFile();                                  const QString& sFilename = iter.next().toLocalFile();
118                                  if (!sFilename.isEmpty()) {                                  if (!sFilename.isEmpty()) {
119                                          bAccept = qsamplerChannel::isInstrumentFile(sFilename);                                          bAccept = Channel::isInstrumentFile(sFilename);
120                                          break;                                          break;
121                                  }                                  }
122                          }                          }
# Line 130  void ChannelStrip::dropEvent ( QDropEven Line 157  void ChannelStrip::dropEvent ( QDropEven
157    
158    
159  // Channel strip setup formal initializer.  // Channel strip setup formal initializer.
160  void ChannelStrip::setup ( qsamplerChannel *pChannel )  void ChannelStrip::setup ( Channel *pChannel )
161  {  {
162      // Destroy any previous channel descriptor;          // Destroy any previous channel descriptor;
163      // (remember that once setup we own it!)          // (remember that once setup we own it!)
164      if (m_pChannel)          if (m_pChannel)
165          delete m_pChannel;                  delete m_pChannel;
166    
167      // Set the new one...          // Set the new one...
168      m_pChannel = pChannel;          m_pChannel = pChannel;
169    
170      // Stabilize this around.          // Stabilize this around.
171      updateChannelInfo();          updateChannelInfo();
172    
173          // We'll accept drops from now on...          // We'll accept drops from now on...
174          if (m_pChannel)          if (m_pChannel)
175                  setAcceptDrops(true);                  setAcceptDrops(true);
176  }  }
177    
178    
179  // Channel secriptor accessor.  // Channel secriptor accessor.
180  qsamplerChannel *ChannelStrip::channel (void)  Channel *ChannelStrip::channel (void) const
181  {  {
182      return m_pChannel;          return m_pChannel;
183  }  }
184    
185    
186  // Messages view font accessors.  // Messages view font accessors.
187  QFont ChannelStrip::displayFont (void)  QFont ChannelStrip::displayFont (void) const
188  {  {
189      return ui.EngineNameTextLabel->font();          return m_ui.EngineNameTextLabel->font();
190  }  }
191    
192  void ChannelStrip::setDisplayFont ( const QFont & font )  void ChannelStrip::setDisplayFont ( const QFont & font )
193  {  {
194      ui.EngineNameTextLabel->setFont(font);          m_ui.EngineNameTextLabel->setFont(font);
195      ui.MidiPortChannelTextLabel->setFont(font);          m_ui.MidiPortChannelTextLabel->setFont(font);
196      ui.InstrumentNameTextLabel->setFont(font);          m_ui.InstrumentNameTextLabel->setFont(font);
197      ui.InstrumentStatusTextLabel->setFont(font);          m_ui.InstrumentStatusTextLabel->setFont(font);
198  }  }
199    
200    
# Line 174  void ChannelStrip::setDisplayFont ( cons Line 202  void ChannelStrip::setDisplayFont ( cons
202  void ChannelStrip::setDisplayEffect ( bool bDisplayEffect )  void ChannelStrip::setDisplayEffect ( bool bDisplayEffect )
203  {  {
204          QPalette pal;          QPalette pal;
205            pal.setColor(QPalette::Foreground, Qt::yellow);
206            m_ui.EngineNameTextLabel->setPalette(pal);
207            m_ui.MidiPortChannelTextLabel->setPalette(pal);
208          pal.setColor(QPalette::Foreground, Qt::green);          pal.setColor(QPalette::Foreground, Qt::green);
209          if (bDisplayEffect) {          if (bDisplayEffect) {
210                  QPixmap pm(":/icons/displaybg1.png");                  QPixmap pm(":/icons/displaybg1.png");
# Line 181  void ChannelStrip::setDisplayEffect ( bo Line 212  void ChannelStrip::setDisplayEffect ( bo
212          } else {          } else {
213                  pal.setColor(QPalette::Background, Qt::black);                  pal.setColor(QPalette::Background, Qt::black);
214          }          }
215          ui.ChannelInfoFrame->setPalette(pal);          m_ui.ChannelInfoFrame->setPalette(pal);
216          ui.StreamVoiceCountTextLabel->setPalette(pal);          m_ui.StreamVoiceCountTextLabel->setPalette(pal);
217  }  }
218    
219    
220  // Maximum volume slider accessors.  // Maximum volume slider accessors.
221  void ChannelStrip::setMaxVolume ( int iMaxVolume )  void ChannelStrip::setMaxVolume ( int iMaxVolume )
222  {  {
223      m_iDirtyChange++;          m_iDirtyChange++;
224      ui.VolumeSlider->setRange(0, iMaxVolume);          m_ui.VolumeSlider->setRange(0, iMaxVolume);
225      ui.VolumeSpinBox->setRange(0, iMaxVolume);          m_ui.VolumeSpinBox->setRange(0, iMaxVolume);
226      m_iDirtyChange--;          m_iDirtyChange--;
227  }  }
228    
229    
# Line 282  bool ChannelStrip::updateInstrumentName Line 313  bool ChannelStrip::updateInstrumentName
313    
314          // Instrument name...          // Instrument name...
315          if (m_pChannel->instrumentName().isEmpty()) {          if (m_pChannel->instrumentName().isEmpty()) {
316                  if (m_pChannel->instrumentStatus() >= 0)                  if (m_pChannel->instrumentStatus() >= 0) {
317                          ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument());                          m_ui.InstrumentNameTextLabel->setText(
318                  else                                  ' ' + Channel::loadingInstrument());
319                          ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());                  } else {
320          } else                          m_ui.InstrumentNameTextLabel->setText(
321                  ui.InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());                                  ' ' + Channel::noInstrumentName());
322                    }
323            } else {
324                    m_ui.InstrumentNameTextLabel->setText(
325                            ' ' + m_pChannel->instrumentName());
326            }
327    
328          return true;          return true;
329  }  }
# Line 296  bool ChannelStrip::updateInstrumentName Line 332  bool ChannelStrip::updateInstrumentName
332  // Do the dirty volume change.  // Do the dirty volume change.
333  bool ChannelStrip::updateChannelVolume (void)  bool ChannelStrip::updateChannelVolume (void)
334  {  {
335      if (m_pChannel == NULL)          if (m_pChannel == NULL)
336          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  
337    
338      // And clip...          // Convert...
339      if (iVolume < 0)          int iVolume = ::lroundf(100.0f * m_pChannel->volume());
340          iVolume = 0;          // And clip...
341            if (iVolume < 0)
342      // Flag it here, to avoid infinite recursion.                  iVolume = 0;
343      m_iDirtyChange++;  
344      ui.VolumeSlider->setValue(iVolume);          // Flag it here, to avoid infinite recursion.
345      ui.VolumeSpinBox->setValue(iVolume);          m_iDirtyChange++;
346      m_iDirtyChange--;          m_ui.VolumeSlider->setValue(iVolume);
347            m_ui.VolumeSpinBox->setValue(iVolume);
348            m_iDirtyChange--;
349    
350      return true;          return true;
351  }  }
352    
353    
354  // Update whole channel info state.  // Update whole channel info state.
355  bool ChannelStrip::updateChannelInfo (void)  bool ChannelStrip::updateChannelInfo (void)
356  {  {
357      if (m_pChannel == NULL)          if (m_pChannel == NULL)
358          return false;                  return false;
359    
360          // Check for error limit/recycle...          // Check for error limit/recycle...
361          if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)          if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)
362                  return true;                  return true;
363    
364      // Update strip caption.          // Update strip caption.
365      QString sText = m_pChannel->channelName();          QString sText = m_pChannel->channelName();
366      setWindowTitle(sText);          setWindowTitle(sText);
367      ui.ChannelSetupPushButton->setText(sText);          m_ui.ChannelSetupPushButton->setText('&' + sText);
368    
369      // Check if we're up and connected.          // Check if we're up and connected.
370          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
371          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
372                  return false;                  return false;
373    
374      // Read actual channel information.          // Read actual channel information.
375      m_pChannel->updateChannelInfo();          m_pChannel->updateChannelInfo();
376    
377      // Engine name...          // Engine name...
378      if (m_pChannel->engineName().isEmpty())          if (m_pChannel->engineName().isEmpty()) {
379          ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());                  m_ui.EngineNameTextLabel->setText(
380      else                          ' ' + Channel::noEngineName());
381          ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName());          } else {
382                    m_ui.EngineNameTextLabel->setText(
383                            ' ' + m_pChannel->engineName());
384            }
385    
386          // Instrument name...          // Instrument name...
387          updateInstrumentName(false);          updateInstrumentName(false);
388    
389      // MIDI Port/Channel...          // MIDI Port/Channel...
390          QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";          QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";
391          if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)          if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
392                  sMidiPortChannel += tr("All");                  sMidiPortChannel += tr("All");
393          else          else
394                  sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1);                  sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1);
395          ui.MidiPortChannelTextLabel->setText(sMidiPortChannel);          m_ui.MidiPortChannelTextLabel->setText(sMidiPortChannel);
396    
397          // Common palette...          // Common palette...
398          QPalette pal;          QPalette pal;
399          const QColor& rgbFore = pal.color(QPalette::Foreground);          const QColor& rgbFore = pal.color(QPalette::Foreground);
400    
401      // Instrument status...          // Instrument status...
402      int iInstrumentStatus = m_pChannel->instrumentStatus();          int iInstrumentStatus = m_pChannel->instrumentStatus();
403      if (iInstrumentStatus < 0) {          if (iInstrumentStatus < 0) {
404                  pal.setColor(QPalette::Foreground, Qt::red);                  pal.setColor(QPalette::Foreground, Qt::red);
405                  ui.InstrumentStatusTextLabel->setPalette(pal);                  m_ui.InstrumentStatusTextLabel->setPalette(pal);
406          ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));                  m_ui.InstrumentStatusTextLabel->setText(
407          m_iErrorCount++;                          tr("ERR%1").arg(iInstrumentStatus));
408          return false;                  m_iErrorCount++;
409      }                  return false;
410      // All seems normal...          }
411            // All seems normal...
412          pal.setColor(QPalette::Foreground,          pal.setColor(QPalette::Foreground,
413                  iInstrumentStatus < 100 ? Qt::yellow : Qt::green);                  iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
414      ui.InstrumentStatusTextLabel->setPalette(pal);          m_ui.InstrumentStatusTextLabel->setPalette(pal);
415      ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%');          m_ui.InstrumentStatusTextLabel->setText(
416      m_iErrorCount = 0;                  QString::number(iInstrumentStatus) + '%');
417            m_iErrorCount = 0;
418    
419  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
420      // Mute/Solo button state coloring...          // Mute/Solo button state coloring...
421      bool bMute = m_pChannel->channelMute();          bool bMute = m_pChannel->channelMute();
422          const QColor& rgbButton = pal.color(QPalette::Button);          const QColor& rgbButton = pal.color(QPalette::Button);
423          pal.setColor(QPalette::Foreground, rgbFore);          pal.setColor(QPalette::Foreground, rgbFore);
424          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);
425          ui.ChannelMutePushButton->setPalette(pal);          m_ui.ChannelMutePushButton->setPalette(pal);
426          ui.ChannelMutePushButton->setDown(bMute);          m_ui.ChannelMutePushButton->setDown(bMute);
427      bool bSolo = m_pChannel->channelSolo();          bool bSolo = m_pChannel->channelSolo();
428          pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);            pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);  
429          ui.ChannelSoloPushButton->setPalette(pal);          m_ui.ChannelSoloPushButton->setPalette(pal);
430          ui.ChannelSoloPushButton->setDown(bSolo);          m_ui.ChannelSoloPushButton->setDown(bSolo);
431  #else  #else
432          ui.ChannelMutePushButton->setEnabled(false);          m_ui.ChannelMutePushButton->setEnabled(false);
433          ui.ChannelSoloPushButton->setEnabled(false);          m_ui.ChannelSoloPushButton->setEnabled(false);
434  #endif  #endif
435    
436      // And update the both GUI volume elements;          // And update the both GUI volume elements;
437      // return success if, and only if, intrument is fully loaded...          // return success if, and only if, intrument is fully loaded...
438      return updateChannelVolume() && (iInstrumentStatus == 100);          return updateChannelVolume() && (iInstrumentStatus == 100);
439  }  }
440    
441    
442  // Update whole channel usage state.  // Update whole channel usage state.
443  bool ChannelStrip::updateChannelUsage (void)  bool ChannelStrip::updateChannelUsage (void)
444  {  {
445      if (m_pChannel == NULL)          if (m_pChannel == NULL)
446          return false;                  return false;
447    
448          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
449          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 422  bool ChannelStrip::updateChannelUsage (v Line 451  bool ChannelStrip::updateChannelUsage (v
451    
452          // This only makes sense on fully loaded channels...          // This only makes sense on fully loaded channels...
453          if (m_pChannel->instrumentStatus() < 100)          if (m_pChannel->instrumentStatus() < 100)
454              return false;                  return false;
455    
456      // Get current channel voice count.          // Get current channel voice count.
457      int iVoiceCount  = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID());          int iVoiceCount  = ::lscp_get_channel_voice_count(
458     // Get current stream count.                  pMainForm->client(), m_pChannel->channelID());
459      int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID());  // Get current stream count.
460      // Get current channel buffer fill usage.          int iStreamCount = ::lscp_get_channel_stream_count(
461      // As benno has suggested this is the percentage usage                  pMainForm->client(), m_pChannel->channelID());
462      // of the least filled buffer stream...          // Get current channel buffer fill usage.
463      int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());;          // As benno has suggested this is the percentage usage
464            // of the least filled buffer stream...
465      // Update the GUI elements...          int iStreamUsage = ::lscp_get_channel_stream_usage(
466      ui.StreamUsageProgressBar->setValue(iStreamUsage);                  pMainForm->client(), m_pChannel->channelID());;
467      ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));  
468            // Update the GUI elements...
469            m_ui.StreamUsageProgressBar->setValue(iStreamUsage);
470            m_ui.StreamVoiceCountTextLabel->setText(
471                    QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
472    
473      // We're clean.          // We're clean.
474      return true;          return true;
475  }  }
476    
477    
478  // Volume change slot.  // Volume change slot.
479  void ChannelStrip::volumeChanged ( int iVolume )  void ChannelStrip::volumeChanged ( int iVolume )
480  {  {
481      if (m_pChannel == NULL)          if (m_pChannel == NULL)
482          return;                  return;
483    
484            // Avoid recursion.
485            if (m_iDirtyChange > 0)
486                    return;
487    
488      // Avoid recursion.          // Convert and clip.
489      if (m_iDirtyChange > 0)          float fVolume = (float) iVolume / 100.0f;
490          return;          if (fVolume < 0.001f)
491                    fVolume = 0.0f;
492      // Convert and clip.  
493      float fVolume = (float) iVolume / 100.0;          // Update the GUI elements.
494      if (fVolume < 0.001)          if (m_pChannel->setVolume(fVolume)) {
495          fVolume = 0.0;                  updateChannelVolume();
496                    emit channelChanged(this);
497      // Update the GUI elements.          }
     if (m_pChannel->setVolume(fVolume)) {  
         updateChannelVolume();  
         emit channelChanged(this);  
     }  
498  }  }
499    
500    
501  // Context menu event handler.  // Context menu event handler.
502  void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )  void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
503  {  {
504      if (m_pChannel == NULL)          if (m_pChannel == NULL)
505          return;                  return;
506    
507      // 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).
508      m_pChannel->contextMenuEvent(pEvent);          m_pChannel->contextMenuEvent(pEvent);
509  }  }
510    
511    
# Line 482  void ChannelStrip::resetErrorCount (void Line 515  void ChannelStrip::resetErrorCount (void
515          m_iErrorCount = 0;          m_iErrorCount = 0;
516  }  }
517    
518    
519    // Channel strip activation/selection.
520    void ChannelStrip::setSelected ( bool bSelected )
521    {
522            if (bSelected) {
523                    if (g_pSelectedStrip == this)
524                            return;
525                    if (g_pSelectedStrip)
526                            g_pSelectedStrip->setSelected(false);
527                    g_pSelectedStrip = this;
528            } else {
529                    if (g_pSelectedStrip == this)
530                            g_pSelectedStrip = NULL;
531            }
532    
533            QPalette pal;
534            if (bSelected) {
535                    const QColor& color = pal.midlight().color();
536                    pal.setColor(QPalette::Background, color.dark(150));
537                    pal.setColor(QPalette::Foreground, color.light(150));
538            }
539            QWidget::setPalette(pal);
540    }
541    
542    
543    bool ChannelStrip::isSelected (void) const
544    {
545            return (this == g_pSelectedStrip);
546    }
547    
548    
549  } // namespace QSampler  } // namespace QSampler
550    
551    

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

  ViewVC Help
Powered by ViewVC