/[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 1513 by capela, Fri Nov 23 09:32:06 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  namespace QSampler {  namespace QSampler {
38    
39    #ifndef CONFIG_ROUND
40    static inline long lroundf ( float x )
41    {
42            if (x >= 0.0f)
43                    return long(x + 0.5f);
44            else
45                    return long(x - 0.5f);
46    }
47    #endif
48    
49  ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags )  ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags )
50          : QWidget(pParent, wflags)          : QWidget(pParent, wflags)
51  {  {
52      m_ui.setupUi(this);          m_ui.setupUi(this);
53    
54      // Initialize locals.          // Initialize locals.
55      m_pChannel     = NULL;          m_pChannel     = NULL;
56      m_iDirtyChange = 0;          m_iDirtyChange = 0;
57      m_iErrorCount  = 0;          m_iErrorCount  = 0;
58    
59      // Try to restore normal window positioning.          // Try to restore normal window positioning.
60      adjustSize();          adjustSize();
61    
62          QObject::connect(m_ui.ChannelSetupPushButton,          QObject::connect(m_ui.ChannelSetupPushButton,
63                  SIGNAL(clicked()),                  SIGNAL(clicked()),
# Line 68  ChannelStrip::ChannelStrip ( QWidget* pP Line 79  ChannelStrip::ChannelStrip ( QWidget* pP
79                  SLOT(channelEdit()));                  SLOT(channelEdit()));
80  }  }
81    
82  ChannelStrip::~ChannelStrip() {  
83      // Destroy existing channel descriptor.  ChannelStrip::~ChannelStrip (void)
84      if (m_pChannel)  {
85          delete m_pChannel;          // Destroy existing channel descriptor.
86      m_pChannel = NULL;          if (m_pChannel)
87                    delete m_pChannel;
88            m_pChannel = NULL;
89  }  }
90    
91    
# Line 134  void ChannelStrip::dropEvent ( QDropEven Line 147  void ChannelStrip::dropEvent ( QDropEven
147  // Channel strip setup formal initializer.  // Channel strip setup formal initializer.
148  void ChannelStrip::setup ( qsamplerChannel *pChannel )  void ChannelStrip::setup ( qsamplerChannel *pChannel )
149  {  {
150      // Destroy any previous channel descriptor;          // Destroy any previous channel descriptor;
151      // (remember that once setup we own it!)          // (remember that once setup we own it!)
152      if (m_pChannel)          if (m_pChannel)
153          delete m_pChannel;                  delete m_pChannel;
154    
155      // Set the new one...          // Set the new one...
156      m_pChannel = pChannel;          m_pChannel = pChannel;
157    
158      // Stabilize this around.          // Stabilize this around.
159      updateChannelInfo();          updateChannelInfo();
160    
161          // We'll accept drops from now on...          // We'll accept drops from now on...
162          if (m_pChannel)          if (m_pChannel)
163                  setAcceptDrops(true);                  setAcceptDrops(true);
164  }  }
165    
166    
167  // Channel secriptor accessor.  // Channel secriptor accessor.
168  qsamplerChannel *ChannelStrip::channel (void) const  qsamplerChannel *ChannelStrip::channel (void) const
169  {  {
170      return m_pChannel;          return m_pChannel;
171  }  }
172    
173    
174  // Messages view font accessors.  // Messages view font accessors.
175  QFont ChannelStrip::displayFont (void) const  QFont ChannelStrip::displayFont (void) const
176  {  {
177      return m_ui.EngineNameTextLabel->font();          return m_ui.EngineNameTextLabel->font();
178  }  }
179    
180  void ChannelStrip::setDisplayFont ( const QFont & font )  void ChannelStrip::setDisplayFont ( const QFont & font )
181  {  {
182      m_ui.EngineNameTextLabel->setFont(font);          m_ui.EngineNameTextLabel->setFont(font);
183      m_ui.MidiPortChannelTextLabel->setFont(font);          m_ui.MidiPortChannelTextLabel->setFont(font);
184      m_ui.InstrumentNameTextLabel->setFont(font);          m_ui.InstrumentNameTextLabel->setFont(font);
185      m_ui.InstrumentStatusTextLabel->setFont(font);          m_ui.InstrumentStatusTextLabel->setFont(font);
186  }  }
187    
188    
# Line 194  void ChannelStrip::setDisplayEffect ( bo Line 208  void ChannelStrip::setDisplayEffect ( bo
208  // Maximum volume slider accessors.  // Maximum volume slider accessors.
209  void ChannelStrip::setMaxVolume ( int iMaxVolume )  void ChannelStrip::setMaxVolume ( int iMaxVolume )
210  {  {
211      m_iDirtyChange++;          m_iDirtyChange++;
212      m_ui.VolumeSlider->setRange(0, iMaxVolume);          m_ui.VolumeSlider->setRange(0, iMaxVolume);
213      m_ui.VolumeSpinBox->setRange(0, iMaxVolume);          m_ui.VolumeSpinBox->setRange(0, iMaxVolume);
214      m_iDirtyChange--;          m_iDirtyChange--;
215  }  }
216    
217    
# Line 287  bool ChannelStrip::updateInstrumentName Line 301  bool ChannelStrip::updateInstrumentName
301    
302          // Instrument name...          // Instrument name...
303          if (m_pChannel->instrumentName().isEmpty()) {          if (m_pChannel->instrumentName().isEmpty()) {
304                  if (m_pChannel->instrumentStatus() >= 0)                  if (m_pChannel->instrumentStatus() >= 0) {
305                          m_ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument());                          m_ui.InstrumentNameTextLabel->setText(
306                  else                                  ' ' + qsamplerChannel::loadingInstrument());
307                          m_ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());                  } else {
308          } else                          m_ui.InstrumentNameTextLabel->setText(
309                  m_ui.InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());                                  ' ' + qsamplerChannel::noInstrumentName());
310                    }
311            } else {
312                    m_ui.InstrumentNameTextLabel->setText(
313                            ' ' + m_pChannel->instrumentName());
314            }
315    
316          return true;          return true;
317  }  }
# Line 301  bool ChannelStrip::updateInstrumentName Line 320  bool ChannelStrip::updateInstrumentName
320  // Do the dirty volume change.  // Do the dirty volume change.
321  bool ChannelStrip::updateChannelVolume (void)  bool ChannelStrip::updateChannelVolume (void)
322  {  {
323      if (m_pChannel == NULL)          if (m_pChannel == NULL)
324          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  
325    
326      // And clip...          // Convert...
327      if (iVolume < 0)          int iVolume = ::lroundf(100.0f * m_pChannel->volume());
328          iVolume = 0;          // And clip...
329            if (iVolume < 0)
330      // Flag it here, to avoid infinite recursion.                  iVolume = 0;
331      m_iDirtyChange++;  
332      m_ui.VolumeSlider->setValue(iVolume);          // Flag it here, to avoid infinite recursion.
333      m_ui.VolumeSpinBox->setValue(iVolume);          m_iDirtyChange++;
334      m_iDirtyChange--;          m_ui.VolumeSlider->setValue(iVolume);
335            m_ui.VolumeSpinBox->setValue(iVolume);
336            m_iDirtyChange--;
337    
338      return true;          return true;
339  }  }
340    
341    
342  // Update whole channel info state.  // Update whole channel info state.
343  bool ChannelStrip::updateChannelInfo (void)  bool ChannelStrip::updateChannelInfo (void)
344  {  {
345      if (m_pChannel == NULL)          if (m_pChannel == NULL)
346          return false;                  return false;
347    
348          // Check for error limit/recycle...          // Check for error limit/recycle...
349          if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)          if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)
350                  return true;                  return true;
351    
352      // Update strip caption.          // Update strip caption.
353      QString sText = m_pChannel->channelName();          QString sText = m_pChannel->channelName();
354      setWindowTitle(sText);          setWindowTitle(sText);
355      m_ui.ChannelSetupPushButton->setText(sText);          m_ui.ChannelSetupPushButton->setText('&' + sText);
356    
357      // Check if we're up and connected.          // Check if we're up and connected.
358          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
359          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
360                  return false;                  return false;
361    
362      // Read actual channel information.          // Read actual channel information.
363      m_pChannel->updateChannelInfo();          m_pChannel->updateChannelInfo();
364    
365      // Engine name...          // Engine name...
366      if (m_pChannel->engineName().isEmpty())          if (m_pChannel->engineName().isEmpty()) {
367          m_ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());                  m_ui.EngineNameTextLabel->setText(
368      else                          ' ' + qsamplerChannel::noEngineName());
369          m_ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName());          } else {
370                    m_ui.EngineNameTextLabel->setText(
371                            ' ' + m_pChannel->engineName());
372            }
373    
374          // Instrument name...          // Instrument name...
375          updateInstrumentName(false);          updateInstrumentName(false);
376    
377      // MIDI Port/Channel...          // MIDI Port/Channel...
378          QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";          QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";
379          if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)          if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
380                  sMidiPortChannel += tr("All");                  sMidiPortChannel += tr("All");
# Line 376  bool ChannelStrip::updateChannelInfo (vo Line 386  bool ChannelStrip::updateChannelInfo (vo
386          QPalette pal;          QPalette pal;
387          const QColor& rgbFore = pal.color(QPalette::Foreground);          const QColor& rgbFore = pal.color(QPalette::Foreground);
388    
389      // Instrument status...          // Instrument status...
390      int iInstrumentStatus = m_pChannel->instrumentStatus();          int iInstrumentStatus = m_pChannel->instrumentStatus();
391      if (iInstrumentStatus < 0) {          if (iInstrumentStatus < 0) {
392                  pal.setColor(QPalette::Foreground, Qt::red);                  pal.setColor(QPalette::Foreground, Qt::red);
393                  m_ui.InstrumentStatusTextLabel->setPalette(pal);                  m_ui.InstrumentStatusTextLabel->setPalette(pal);
394          m_ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));                  m_ui.InstrumentStatusTextLabel->setText(
395          m_iErrorCount++;                          tr("ERR%1").arg(iInstrumentStatus));
396          return false;                  m_iErrorCount++;
397      }                  return false;
398      // All seems normal...          }
399            // All seems normal...
400          pal.setColor(QPalette::Foreground,          pal.setColor(QPalette::Foreground,
401                  iInstrumentStatus < 100 ? Qt::yellow : Qt::green);                  iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
402      m_ui.InstrumentStatusTextLabel->setPalette(pal);          m_ui.InstrumentStatusTextLabel->setPalette(pal);
403      m_ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%');          m_ui.InstrumentStatusTextLabel->setText(
404      m_iErrorCount = 0;                  QString::number(iInstrumentStatus) + '%');
405            m_iErrorCount = 0;
406    
407  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
408      // Mute/Solo button state coloring...          // Mute/Solo button state coloring...
409      bool bMute = m_pChannel->channelMute();          bool bMute = m_pChannel->channelMute();
410          const QColor& rgbButton = pal.color(QPalette::Button);          const QColor& rgbButton = pal.color(QPalette::Button);
411          pal.setColor(QPalette::Foreground, rgbFore);          pal.setColor(QPalette::Foreground, rgbFore);
412          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);
413          m_ui.ChannelMutePushButton->setPalette(pal);          m_ui.ChannelMutePushButton->setPalette(pal);
414          m_ui.ChannelMutePushButton->setDown(bMute);          m_ui.ChannelMutePushButton->setDown(bMute);
415      bool bSolo = m_pChannel->channelSolo();          bool bSolo = m_pChannel->channelSolo();
416          pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);            pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);  
417          m_ui.ChannelSoloPushButton->setPalette(pal);          m_ui.ChannelSoloPushButton->setPalette(pal);
418          m_ui.ChannelSoloPushButton->setDown(bSolo);          m_ui.ChannelSoloPushButton->setDown(bSolo);
# Line 409  bool ChannelStrip::updateChannelInfo (vo Line 421  bool ChannelStrip::updateChannelInfo (vo
421          m_ui.ChannelSoloPushButton->setEnabled(false);          m_ui.ChannelSoloPushButton->setEnabled(false);
422  #endif  #endif
423    
424      // And update the both GUI volume elements;          // And update the both GUI volume elements;
425      // return success if, and only if, intrument is fully loaded...          // return success if, and only if, intrument is fully loaded...
426      return updateChannelVolume() && (iInstrumentStatus == 100);          return updateChannelVolume() && (iInstrumentStatus == 100);
427  }  }
428    
429    
430  // Update whole channel usage state.  // Update whole channel usage state.
431  bool ChannelStrip::updateChannelUsage (void)  bool ChannelStrip::updateChannelUsage (void)
432  {  {
433      if (m_pChannel == NULL)          if (m_pChannel == NULL)
434          return false;                  return false;
435    
436          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
437          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 427  bool ChannelStrip::updateChannelUsage (v Line 439  bool ChannelStrip::updateChannelUsage (v
439    
440          // This only makes sense on fully loaded channels...          // This only makes sense on fully loaded channels...
441          if (m_pChannel->instrumentStatus() < 100)          if (m_pChannel->instrumentStatus() < 100)
442              return false;                  return false;
443    
444      // Get current channel voice count.          // Get current channel voice count.
445      int iVoiceCount  = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID());          int iVoiceCount  = ::lscp_get_channel_voice_count(
446     // Get current stream count.                  pMainForm->client(), m_pChannel->channelID());
447      int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID());  // Get current stream count.
448      // Get current channel buffer fill usage.          int iStreamCount = ::lscp_get_channel_stream_count(
449      // As benno has suggested this is the percentage usage                  pMainForm->client(), m_pChannel->channelID());
450      // of the least filled buffer stream...          // Get current channel buffer fill usage.
451      int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());;          // As benno has suggested this is the percentage usage
452            // of the least filled buffer stream...
453      // Update the GUI elements...          int iStreamUsage = ::lscp_get_channel_stream_usage(
454      m_ui.StreamUsageProgressBar->setValue(iStreamUsage);                  pMainForm->client(), m_pChannel->channelID());;
455      m_ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));  
456            // Update the GUI elements...
457            m_ui.StreamUsageProgressBar->setValue(iStreamUsage);
458            m_ui.StreamVoiceCountTextLabel->setText(
459                    QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
460    
461      // We're clean.          // We're clean.
462      return true;          return true;
463  }  }
464    
465    
466  // Volume change slot.  // Volume change slot.
467  void ChannelStrip::volumeChanged ( int iVolume )  void ChannelStrip::volumeChanged ( int iVolume )
468  {  {
469      if (m_pChannel == NULL)          if (m_pChannel == NULL)
470          return;                  return;
471    
472            // Avoid recursion.
473            if (m_iDirtyChange > 0)
474                    return;
475    
476      // Avoid recursion.          // Convert and clip.
477      if (m_iDirtyChange > 0)          float fVolume = (float) iVolume / 100.0f;
478          return;          if (fVolume < 0.001f)
479                    fVolume = 0.0f;
480      // Convert and clip.  
481      float fVolume = (float) iVolume / 100.0;          // Update the GUI elements.
482      if (fVolume < 0.001)          if (m_pChannel->setVolume(fVolume)) {
483          fVolume = 0.0;                  updateChannelVolume();
484                    emit channelChanged(this);
485      // Update the GUI elements.          }
     if (m_pChannel->setVolume(fVolume)) {  
         updateChannelVolume();  
         emit channelChanged(this);  
     }  
486  }  }
487    
488    
489  // Context menu event handler.  // Context menu event handler.
490  void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )  void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
491  {  {
492      if (m_pChannel == NULL)          if (m_pChannel == NULL)
493          return;                  return;
494    
495      // 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).
496      m_pChannel->contextMenuEvent(pEvent);          m_pChannel->contextMenuEvent(pEvent);
497  }  }
498    
499    

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

  ViewVC Help
Powered by ViewVC