/[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 1509 by capela, Thu Nov 22 11:10:44 2007 UTC revision 1514 by capela, Fri Nov 23 10:51:37 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    // Channel strip activation/selection.
51    ChannelStrip *ChannelStrip::g_pSelectedStrip = NULL;
52    
53    
54  ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags )  ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags )
55          : QWidget(pParent, wflags)          : QWidget(pParent, wflags)
56  {  {
57      m_ui.setupUi(this);          m_ui.setupUi(this);
58    
59      // Initialize locals.          // Initialize locals.
60      m_pChannel     = NULL;          m_pChannel     = NULL;
61      m_iDirtyChange = 0;          m_iDirtyChange = 0;
62      m_iErrorCount  = 0;          m_iErrorCount  = 0;
63    
64      // Try to restore normal window positioning.          // Try to restore normal window positioning.
65      adjustSize();          adjustSize();
66            setSelected(false);
67    
68          QObject::connect(m_ui.ChannelSetupPushButton,          QObject::connect(m_ui.ChannelSetupPushButton,
69                  SIGNAL(clicked()),                  SIGNAL(clicked()),
# Line 68  ChannelStrip::ChannelStrip ( QWidget* pP Line 85  ChannelStrip::ChannelStrip ( QWidget* pP
85                  SLOT(channelEdit()));                  SLOT(channelEdit()));
86  }  }
87    
88  ChannelStrip::~ChannelStrip() {  
89      // Destroy existing channel descriptor.  ChannelStrip::~ChannelStrip (void)
90      if (m_pChannel)  {
91          delete m_pChannel;          // Destroy existing channel descriptor.
92      m_pChannel = NULL;          if (m_pChannel)
93                    delete m_pChannel;
94            m_pChannel = NULL;
95  }  }
96    
97    
# Line 134  void ChannelStrip::dropEvent ( QDropEven Line 153  void ChannelStrip::dropEvent ( QDropEven
153  // Channel strip setup formal initializer.  // Channel strip setup formal initializer.
154  void ChannelStrip::setup ( qsamplerChannel *pChannel )  void ChannelStrip::setup ( qsamplerChannel *pChannel )
155  {  {
156      // Destroy any previous channel descriptor;          // Destroy any previous channel descriptor;
157      // (remember that once setup we own it!)          // (remember that once setup we own it!)
158      if (m_pChannel)          if (m_pChannel)
159          delete m_pChannel;                  delete m_pChannel;
160    
161      // Set the new one...          // Set the new one...
162      m_pChannel = pChannel;          m_pChannel = pChannel;
163    
164      // Stabilize this around.          // Stabilize this around.
165      updateChannelInfo();          updateChannelInfo();
166    
167          // We'll accept drops from now on...          // We'll accept drops from now on...
168          if (m_pChannel)          if (m_pChannel)
169                  setAcceptDrops(true);                  setAcceptDrops(true);
170  }  }
171    
172    
173  // Channel secriptor accessor.  // Channel secriptor accessor.
174  qsamplerChannel *ChannelStrip::channel (void) const  qsamplerChannel *ChannelStrip::channel (void) const
175  {  {
176      return m_pChannel;          return m_pChannel;
177  }  }
178    
179    
180  // Messages view font accessors.  // Messages view font accessors.
181  QFont ChannelStrip::displayFont (void) const  QFont ChannelStrip::displayFont (void) const
182  {  {
183      return m_ui.EngineNameTextLabel->font();          return m_ui.EngineNameTextLabel->font();
184  }  }
185    
186  void ChannelStrip::setDisplayFont ( const QFont & font )  void ChannelStrip::setDisplayFont ( const QFont & font )
187  {  {
188      m_ui.EngineNameTextLabel->setFont(font);          m_ui.EngineNameTextLabel->setFont(font);
189      m_ui.MidiPortChannelTextLabel->setFont(font);          m_ui.MidiPortChannelTextLabel->setFont(font);
190      m_ui.InstrumentNameTextLabel->setFont(font);          m_ui.InstrumentNameTextLabel->setFont(font);
191      m_ui.InstrumentStatusTextLabel->setFont(font);          m_ui.InstrumentStatusTextLabel->setFont(font);
192  }  }
193    
194    
# Line 194  void ChannelStrip::setDisplayEffect ( bo Line 214  void ChannelStrip::setDisplayEffect ( bo
214  // Maximum volume slider accessors.  // Maximum volume slider accessors.
215  void ChannelStrip::setMaxVolume ( int iMaxVolume )  void ChannelStrip::setMaxVolume ( int iMaxVolume )
216  {  {
217      m_iDirtyChange++;          m_iDirtyChange++;
218      m_ui.VolumeSlider->setRange(0, iMaxVolume);          m_ui.VolumeSlider->setRange(0, iMaxVolume);
219      m_ui.VolumeSpinBox->setRange(0, iMaxVolume);          m_ui.VolumeSpinBox->setRange(0, iMaxVolume);
220      m_iDirtyChange--;          m_iDirtyChange--;
221  }  }
222    
223    
# Line 287  bool ChannelStrip::updateInstrumentName Line 307  bool ChannelStrip::updateInstrumentName
307    
308          // Instrument name...          // Instrument name...
309          if (m_pChannel->instrumentName().isEmpty()) {          if (m_pChannel->instrumentName().isEmpty()) {
310                  if (m_pChannel->instrumentStatus() >= 0)                  if (m_pChannel->instrumentStatus() >= 0) {
311                          m_ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument());                          m_ui.InstrumentNameTextLabel->setText(
312                  else                                  ' ' + qsamplerChannel::loadingInstrument());
313                          m_ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());                  } else {
314          } else                          m_ui.InstrumentNameTextLabel->setText(
315                  m_ui.InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());                                  ' ' + qsamplerChannel::noInstrumentName());
316                    }
317            } else {
318                    m_ui.InstrumentNameTextLabel->setText(
319                            ' ' + m_pChannel->instrumentName());
320            }
321    
322          return true;          return true;
323  }  }
# Line 301  bool ChannelStrip::updateInstrumentName Line 326  bool ChannelStrip::updateInstrumentName
326  // Do the dirty volume change.  // Do the dirty volume change.
327  bool ChannelStrip::updateChannelVolume (void)  bool ChannelStrip::updateChannelVolume (void)
328  {  {
329      if (m_pChannel == NULL)          if (m_pChannel == NULL)
330          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  
331    
332      // And clip...          // Convert...
333      if (iVolume < 0)          int iVolume = ::lroundf(100.0f * m_pChannel->volume());
334          iVolume = 0;          // And clip...
335            if (iVolume < 0)
336      // Flag it here, to avoid infinite recursion.                  iVolume = 0;
337      m_iDirtyChange++;  
338      m_ui.VolumeSlider->setValue(iVolume);          // Flag it here, to avoid infinite recursion.
339      m_ui.VolumeSpinBox->setValue(iVolume);          m_iDirtyChange++;
340      m_iDirtyChange--;          m_ui.VolumeSlider->setValue(iVolume);
341            m_ui.VolumeSpinBox->setValue(iVolume);
342            m_iDirtyChange--;
343    
344      return true;          return true;
345  }  }
346    
347    
348  // Update whole channel info state.  // Update whole channel info state.
349  bool ChannelStrip::updateChannelInfo (void)  bool ChannelStrip::updateChannelInfo (void)
350  {  {
351      if (m_pChannel == NULL)          if (m_pChannel == NULL)
352          return false;                  return false;
353    
354          // Check for error limit/recycle...          // Check for error limit/recycle...
355          if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)          if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)
356                  return true;                  return true;
357    
358      // Update strip caption.          // Update strip caption.
359      QString sText = m_pChannel->channelName();          QString sText = m_pChannel->channelName();
360      setWindowTitle(sText);          setWindowTitle(sText);
361      m_ui.ChannelSetupPushButton->setText(sText);          m_ui.ChannelSetupPushButton->setText('&' + sText);
362    
363      // Check if we're up and connected.          // Check if we're up and connected.
364          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
365          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
366                  return false;                  return false;
367    
368      // Read actual channel information.          // Read actual channel information.
369      m_pChannel->updateChannelInfo();          m_pChannel->updateChannelInfo();
370    
371      // Engine name...          // Engine name...
372      if (m_pChannel->engineName().isEmpty())          if (m_pChannel->engineName().isEmpty()) {
373          m_ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());                  m_ui.EngineNameTextLabel->setText(
374      else                          ' ' + qsamplerChannel::noEngineName());
375          m_ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName());          } else {
376                    m_ui.EngineNameTextLabel->setText(
377                            ' ' + m_pChannel->engineName());
378            }
379    
380          // Instrument name...          // Instrument name...
381          updateInstrumentName(false);          updateInstrumentName(false);
382    
383      // MIDI Port/Channel...          // MIDI Port/Channel...
384          QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";          QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";
385          if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)          if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
386                  sMidiPortChannel += tr("All");                  sMidiPortChannel += tr("All");
# Line 376  bool ChannelStrip::updateChannelInfo (vo Line 392  bool ChannelStrip::updateChannelInfo (vo
392          QPalette pal;          QPalette pal;
393          const QColor& rgbFore = pal.color(QPalette::Foreground);          const QColor& rgbFore = pal.color(QPalette::Foreground);
394    
395      // Instrument status...          // Instrument status...
396      int iInstrumentStatus = m_pChannel->instrumentStatus();          int iInstrumentStatus = m_pChannel->instrumentStatus();
397      if (iInstrumentStatus < 0) {          if (iInstrumentStatus < 0) {
398                  pal.setColor(QPalette::Foreground, Qt::red);                  pal.setColor(QPalette::Foreground, Qt::red);
399                  m_ui.InstrumentStatusTextLabel->setPalette(pal);                  m_ui.InstrumentStatusTextLabel->setPalette(pal);
400          m_ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));                  m_ui.InstrumentStatusTextLabel->setText(
401          m_iErrorCount++;                          tr("ERR%1").arg(iInstrumentStatus));
402          return false;                  m_iErrorCount++;
403      }                  return false;
404      // All seems normal...          }
405            // All seems normal...
406          pal.setColor(QPalette::Foreground,          pal.setColor(QPalette::Foreground,
407                  iInstrumentStatus < 100 ? Qt::yellow : Qt::green);                  iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
408      m_ui.InstrumentStatusTextLabel->setPalette(pal);          m_ui.InstrumentStatusTextLabel->setPalette(pal);
409      m_ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%');          m_ui.InstrumentStatusTextLabel->setText(
410      m_iErrorCount = 0;                  QString::number(iInstrumentStatus) + '%');
411            m_iErrorCount = 0;
412    
413  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
414      // Mute/Solo button state coloring...          // Mute/Solo button state coloring...
415      bool bMute = m_pChannel->channelMute();          bool bMute = m_pChannel->channelMute();
416          const QColor& rgbButton = pal.color(QPalette::Button);          const QColor& rgbButton = pal.color(QPalette::Button);
417          pal.setColor(QPalette::Foreground, rgbFore);          pal.setColor(QPalette::Foreground, rgbFore);
418          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);
419          m_ui.ChannelMutePushButton->setPalette(pal);          m_ui.ChannelMutePushButton->setPalette(pal);
420          m_ui.ChannelMutePushButton->setDown(bMute);          m_ui.ChannelMutePushButton->setDown(bMute);
421      bool bSolo = m_pChannel->channelSolo();          bool bSolo = m_pChannel->channelSolo();
422          pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);            pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);  
423          m_ui.ChannelSoloPushButton->setPalette(pal);          m_ui.ChannelSoloPushButton->setPalette(pal);
424          m_ui.ChannelSoloPushButton->setDown(bSolo);          m_ui.ChannelSoloPushButton->setDown(bSolo);
# Line 409  bool ChannelStrip::updateChannelInfo (vo Line 427  bool ChannelStrip::updateChannelInfo (vo
427          m_ui.ChannelSoloPushButton->setEnabled(false);          m_ui.ChannelSoloPushButton->setEnabled(false);
428  #endif  #endif
429    
430      // And update the both GUI volume elements;          // And update the both GUI volume elements;
431      // return success if, and only if, intrument is fully loaded...          // return success if, and only if, intrument is fully loaded...
432      return updateChannelVolume() && (iInstrumentStatus == 100);          return updateChannelVolume() && (iInstrumentStatus == 100);
433  }  }
434    
435    
436  // Update whole channel usage state.  // Update whole channel usage state.
437  bool ChannelStrip::updateChannelUsage (void)  bool ChannelStrip::updateChannelUsage (void)
438  {  {
439      if (m_pChannel == NULL)          if (m_pChannel == NULL)
440          return false;                  return false;
441    
442          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
443          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 427  bool ChannelStrip::updateChannelUsage (v Line 445  bool ChannelStrip::updateChannelUsage (v
445    
446          // This only makes sense on fully loaded channels...          // This only makes sense on fully loaded channels...
447          if (m_pChannel->instrumentStatus() < 100)          if (m_pChannel->instrumentStatus() < 100)
448              return false;                  return false;
449    
450      // Get current channel voice count.          // Get current channel voice count.
451      int iVoiceCount  = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID());          int iVoiceCount  = ::lscp_get_channel_voice_count(
452     // Get current stream count.                  pMainForm->client(), m_pChannel->channelID());
453      int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID());  // Get current stream count.
454      // Get current channel buffer fill usage.          int iStreamCount = ::lscp_get_channel_stream_count(
455      // As benno has suggested this is the percentage usage                  pMainForm->client(), m_pChannel->channelID());
456      // of the least filled buffer stream...          // Get current channel buffer fill usage.
457      int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());;          // As benno has suggested this is the percentage usage
458            // of the least filled buffer stream...
459      // Update the GUI elements...          int iStreamUsage = ::lscp_get_channel_stream_usage(
460      m_ui.StreamUsageProgressBar->setValue(iStreamUsage);                  pMainForm->client(), m_pChannel->channelID());;
461      m_ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));  
462            // Update the GUI elements...
463            m_ui.StreamUsageProgressBar->setValue(iStreamUsage);
464            m_ui.StreamVoiceCountTextLabel->setText(
465                    QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
466    
467      // We're clean.          // We're clean.
468      return true;          return true;
469  }  }
470    
471    
472  // Volume change slot.  // Volume change slot.
473  void ChannelStrip::volumeChanged ( int iVolume )  void ChannelStrip::volumeChanged ( int iVolume )
474  {  {
475      if (m_pChannel == NULL)          if (m_pChannel == NULL)
476          return;                  return;
477    
478            // Avoid recursion.
479            if (m_iDirtyChange > 0)
480                    return;
481    
482      // Avoid recursion.          // Convert and clip.
483      if (m_iDirtyChange > 0)          float fVolume = (float) iVolume / 100.0f;
484          return;          if (fVolume < 0.001f)
485                    fVolume = 0.0f;
486      // Convert and clip.  
487      float fVolume = (float) iVolume / 100.0;          // Update the GUI elements.
488      if (fVolume < 0.001)          if (m_pChannel->setVolume(fVolume)) {
489          fVolume = 0.0;                  updateChannelVolume();
490                    emit channelChanged(this);
491      // Update the GUI elements.          }
     if (m_pChannel->setVolume(fVolume)) {  
         updateChannelVolume();  
         emit channelChanged(this);  
     }  
492  }  }
493    
494    
495  // Context menu event handler.  // Context menu event handler.
496  void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )  void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
497  {  {
498      if (m_pChannel == NULL)          if (m_pChannel == NULL)
499          return;                  return;
500    
501      // 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).
502      m_pChannel->contextMenuEvent(pEvent);          m_pChannel->contextMenuEvent(pEvent);
503  }  }
504    
505    
# Line 487  void ChannelStrip::resetErrorCount (void Line 509  void ChannelStrip::resetErrorCount (void
509          m_iErrorCount = 0;          m_iErrorCount = 0;
510  }  }
511    
512    
513    // Channel strip activation/selection.
514    void ChannelStrip::setSelected ( bool bSelected )
515    {
516            if (bSelected) {
517                    if (g_pSelectedStrip == this)
518                            return;
519                    if (g_pSelectedStrip)
520                            g_pSelectedStrip->setSelected(false);
521                    g_pSelectedStrip = this;
522            } else {
523                    if (g_pSelectedStrip == this)
524                            g_pSelectedStrip = NULL;
525            }
526    
527            QPalette pal;
528            if (bSelected) {
529                    const QColor& color = pal.midlight().color();
530                    pal.setColor(QPalette::Background, color.dark(150));
531                    pal.setColor(QPalette::Foreground, color.light(150));
532            }
533            QWidget::setPalette(pal);
534    }
535    
536    
537    bool ChannelStrip::isSelected (void) const
538    {
539            return (this == g_pSelectedStrip);
540    }
541    
542    
543  } // namespace QSampler  } // namespace QSampler
544    
545    

Legend:
Removed from v.1509  
changed lines
  Added in v.1514

  ViewVC Help
Powered by ViewVC