/[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 1510 by capela, Thu Nov 22 14:17:24 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 69  ChannelStrip::ChannelStrip ( QWidget* pP Line 80  ChannelStrip::ChannelStrip ( QWidget* pP
80  }  }
81    
82  ChannelStrip::~ChannelStrip() {  ChannelStrip::~ChannelStrip() {
83      // Destroy existing channel descriptor.          // Destroy existing channel descriptor.
84      if (m_pChannel)          if (m_pChannel)
85          delete m_pChannel;                  delete m_pChannel;
86      m_pChannel = NULL;          m_pChannel = NULL;
87  }  }
88    
89    
# Line 134  void ChannelStrip::dropEvent ( QDropEven Line 145  void ChannelStrip::dropEvent ( QDropEven
145  // Channel strip setup formal initializer.  // Channel strip setup formal initializer.
146  void ChannelStrip::setup ( qsamplerChannel *pChannel )  void ChannelStrip::setup ( qsamplerChannel *pChannel )
147  {  {
148      // Destroy any previous channel descriptor;          // Destroy any previous channel descriptor;
149      // (remember that once setup we own it!)          // (remember that once setup we own it!)
150      if (m_pChannel)          if (m_pChannel)
151          delete m_pChannel;                  delete m_pChannel;
152    
153      // Set the new one...          // Set the new one...
154      m_pChannel = pChannel;          m_pChannel = pChannel;
155    
156      // Stabilize this around.          // Stabilize this around.
157      updateChannelInfo();          updateChannelInfo();
158    
159          // We'll accept drops from now on...          // We'll accept drops from now on...
160          if (m_pChannel)          if (m_pChannel)
# Line 153  void ChannelStrip::setup ( qsamplerChann Line 164  void ChannelStrip::setup ( qsamplerChann
164  // Channel secriptor accessor.  // Channel secriptor accessor.
165  qsamplerChannel *ChannelStrip::channel (void) const  qsamplerChannel *ChannelStrip::channel (void) const
166  {  {
167      return m_pChannel;          return m_pChannel;
168  }  }
169    
170    
171  // Messages view font accessors.  // Messages view font accessors.
172  QFont ChannelStrip::displayFont (void) const  QFont ChannelStrip::displayFont (void) const
173  {  {
174      return m_ui.EngineNameTextLabel->font();          return m_ui.EngineNameTextLabel->font();
175  }  }
176    
177  void ChannelStrip::setDisplayFont ( const QFont & font )  void ChannelStrip::setDisplayFont ( const QFont & font )
178  {  {
179      m_ui.EngineNameTextLabel->setFont(font);          m_ui.EngineNameTextLabel->setFont(font);
180      m_ui.MidiPortChannelTextLabel->setFont(font);          m_ui.MidiPortChannelTextLabel->setFont(font);
181      m_ui.InstrumentNameTextLabel->setFont(font);          m_ui.InstrumentNameTextLabel->setFont(font);
182      m_ui.InstrumentStatusTextLabel->setFont(font);          m_ui.InstrumentStatusTextLabel->setFont(font);
183  }  }
184    
185    
# Line 194  void ChannelStrip::setDisplayEffect ( bo Line 205  void ChannelStrip::setDisplayEffect ( bo
205  // Maximum volume slider accessors.  // Maximum volume slider accessors.
206  void ChannelStrip::setMaxVolume ( int iMaxVolume )  void ChannelStrip::setMaxVolume ( int iMaxVolume )
207  {  {
208      m_iDirtyChange++;          m_iDirtyChange++;
209      m_ui.VolumeSlider->setRange(0, iMaxVolume);          m_ui.VolumeSlider->setRange(0, iMaxVolume);
210      m_ui.VolumeSpinBox->setRange(0, iMaxVolume);          m_ui.VolumeSpinBox->setRange(0, iMaxVolume);
211      m_iDirtyChange--;          m_iDirtyChange--;
212  }  }
213    
214    
# Line 301  bool ChannelStrip::updateInstrumentName Line 312  bool ChannelStrip::updateInstrumentName
312  // Do the dirty volume change.  // Do the dirty volume change.
313  bool ChannelStrip::updateChannelVolume (void)  bool ChannelStrip::updateChannelVolume (void)
314  {  {
315      if (m_pChannel == NULL)          if (m_pChannel == NULL)
316          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  
317    
318      // And clip...          // Convert...
319      if (iVolume < 0)          int iVolume = ::lroundf(100.0f * m_pChannel->volume());
320          iVolume = 0;          // And clip...
321            if (iVolume < 0)
322      // Flag it here, to avoid infinite recursion.                  iVolume = 0;
323      m_iDirtyChange++;  
324      m_ui.VolumeSlider->setValue(iVolume);          // Flag it here, to avoid infinite recursion.
325      m_ui.VolumeSpinBox->setValue(iVolume);          m_iDirtyChange++;
326      m_iDirtyChange--;          m_ui.VolumeSlider->setValue(iVolume);
327            m_ui.VolumeSpinBox->setValue(iVolume);
328            m_iDirtyChange--;
329    
330      return true;          return true;
331  }  }
332    
333    
334  // Update whole channel info state.  // Update whole channel info state.
335  bool ChannelStrip::updateChannelInfo (void)  bool ChannelStrip::updateChannelInfo (void)
336  {  {
337      if (m_pChannel == NULL)          if (m_pChannel == NULL)
338          return false;                  return false;
339    
340          // Check for error limit/recycle...          // Check for error limit/recycle...
341          if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)          if (m_iErrorCount > QSAMPLER_ERROR_LIMIT)
342                  return true;                  return true;
343    
344      // Update strip caption.          // Update strip caption.
345      QString sText = m_pChannel->channelName();          QString sText = m_pChannel->channelName();
346      setWindowTitle(sText);          setWindowTitle(sText);
347      m_ui.ChannelSetupPushButton->setText(sText);          m_ui.ChannelSetupPushButton->setText(sText);
348    
349      // Check if we're up and connected.          // Check if we're up and connected.
350          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
351          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
352                  return false;                  return false;
353    
354      // Read actual channel information.          // Read actual channel information.
355      m_pChannel->updateChannelInfo();          m_pChannel->updateChannelInfo();
356    
357      // Engine name...          // Engine name...
358      if (m_pChannel->engineName().isEmpty())          if (m_pChannel->engineName().isEmpty())
359          m_ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());                  m_ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());
360      else          else
361          m_ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName());                  m_ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName());
362    
363          // Instrument name...          // Instrument name...
364          updateInstrumentName(false);          updateInstrumentName(false);
365    
366      // MIDI Port/Channel...          // MIDI Port/Channel...
367          QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";          QString sMidiPortChannel = QString::number(m_pChannel->midiPort()) + " / ";
368          if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)          if (m_pChannel->midiChannel() == LSCP_MIDI_CHANNEL_ALL)
369                  sMidiPortChannel += tr("All");                  sMidiPortChannel += tr("All");
# Line 376  bool ChannelStrip::updateChannelInfo (vo Line 375  bool ChannelStrip::updateChannelInfo (vo
375          QPalette pal;          QPalette pal;
376          const QColor& rgbFore = pal.color(QPalette::Foreground);          const QColor& rgbFore = pal.color(QPalette::Foreground);
377    
378      // Instrument status...          // Instrument status...
379      int iInstrumentStatus = m_pChannel->instrumentStatus();          int iInstrumentStatus = m_pChannel->instrumentStatus();
380      if (iInstrumentStatus < 0) {          if (iInstrumentStatus < 0) {
381                  pal.setColor(QPalette::Foreground, Qt::red);                  pal.setColor(QPalette::Foreground, Qt::red);
382                  m_ui.InstrumentStatusTextLabel->setPalette(pal);                  m_ui.InstrumentStatusTextLabel->setPalette(pal);
383          m_ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));                  m_ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));
384          m_iErrorCount++;                  m_iErrorCount++;
385          return false;                  return false;
386      }          }
387      // All seems normal...          // All seems normal...
388          pal.setColor(QPalette::Foreground,          pal.setColor(QPalette::Foreground,
389                  iInstrumentStatus < 100 ? Qt::yellow : Qt::green);                  iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
390      m_ui.InstrumentStatusTextLabel->setPalette(pal);          m_ui.InstrumentStatusTextLabel->setPalette(pal);
391      m_ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%');          m_ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%');
392      m_iErrorCount = 0;          m_iErrorCount = 0;
393    
394  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
395      // Mute/Solo button state coloring...          // Mute/Solo button state coloring...
396      bool bMute = m_pChannel->channelMute();          bool bMute = m_pChannel->channelMute();
397          const QColor& rgbButton = pal.color(QPalette::Button);          const QColor& rgbButton = pal.color(QPalette::Button);
398          pal.setColor(QPalette::Foreground, rgbFore);          pal.setColor(QPalette::Foreground, rgbFore);
399          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);
400          m_ui.ChannelMutePushButton->setPalette(pal);          m_ui.ChannelMutePushButton->setPalette(pal);
401          m_ui.ChannelMutePushButton->setDown(bMute);          m_ui.ChannelMutePushButton->setDown(bMute);
402      bool bSolo = m_pChannel->channelSolo();          bool bSolo = m_pChannel->channelSolo();
403          pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);            pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);  
404          m_ui.ChannelSoloPushButton->setPalette(pal);          m_ui.ChannelSoloPushButton->setPalette(pal);
405          m_ui.ChannelSoloPushButton->setDown(bSolo);          m_ui.ChannelSoloPushButton->setDown(bSolo);
# Line 409  bool ChannelStrip::updateChannelInfo (vo Line 408  bool ChannelStrip::updateChannelInfo (vo
408          m_ui.ChannelSoloPushButton->setEnabled(false);          m_ui.ChannelSoloPushButton->setEnabled(false);
409  #endif  #endif
410    
411      // And update the both GUI volume elements;          // And update the both GUI volume elements;
412      // return success if, and only if, intrument is fully loaded...          // return success if, and only if, intrument is fully loaded...
413      return updateChannelVolume() && (iInstrumentStatus == 100);          return updateChannelVolume() && (iInstrumentStatus == 100);
414  }  }
415    
416    
417  // Update whole channel usage state.  // Update whole channel usage state.
418  bool ChannelStrip::updateChannelUsage (void)  bool ChannelStrip::updateChannelUsage (void)
419  {  {
420      if (m_pChannel == NULL)          if (m_pChannel == NULL)
421          return false;                  return false;
422    
423          MainForm *pMainForm = MainForm::getInstance();          MainForm *pMainForm = MainForm::getInstance();
424          if (pMainForm->client() == NULL)          if (pMainForm->client() == NULL)
# Line 427  bool ChannelStrip::updateChannelUsage (v Line 426  bool ChannelStrip::updateChannelUsage (v
426    
427          // This only makes sense on fully loaded channels...          // This only makes sense on fully loaded channels...
428          if (m_pChannel->instrumentStatus() < 100)          if (m_pChannel->instrumentStatus() < 100)
429              return false;                  return false;
430    
431      // Get current channel voice count.          // Get current channel voice count.
432      int iVoiceCount  = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID());          int iVoiceCount  = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID());
433     // Get current stream count.  // Get current stream count.
434      int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID());          int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID());
435      // Get current channel buffer fill usage.          // Get current channel buffer fill usage.
436      // As benno has suggested this is the percentage usage          // As benno has suggested this is the percentage usage
437      // of the least filled buffer stream...          // of the least filled buffer stream...
438      int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());;          int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());;
439    
440      // Update the GUI elements...          // Update the GUI elements...
441      m_ui.StreamUsageProgressBar->setValue(iStreamUsage);          m_ui.StreamUsageProgressBar->setValue(iStreamUsage);
442      m_ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));          m_ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
443    
444      // We're clean.          // We're clean.
445      return true;          return true;
446  }  }
447    
448    
449  // Volume change slot.  // Volume change slot.
450  void ChannelStrip::volumeChanged ( int iVolume )  void ChannelStrip::volumeChanged ( int iVolume )
451  {  {
452      if (m_pChannel == NULL)          if (m_pChannel == NULL)
453          return;                  return;
454    
455            // Avoid recursion.
456            if (m_iDirtyChange > 0)
457                    return;
458    
459      // Avoid recursion.          // Convert and clip.
460      if (m_iDirtyChange > 0)          float fVolume = (float) iVolume / 100.0f;
461          return;          if (fVolume < 0.001f)
462                    fVolume = 0.0f;
463      // Convert and clip.  
464      float fVolume = (float) iVolume / 100.0;          // Update the GUI elements.
465      if (fVolume < 0.001)          if (m_pChannel->setVolume(fVolume)) {
466          fVolume = 0.0;                  updateChannelVolume();
467                    emit channelChanged(this);
468      // Update the GUI elements.          }
     if (m_pChannel->setVolume(fVolume)) {  
         updateChannelVolume();  
         emit channelChanged(this);  
     }  
469  }  }
470    
471    
472  // Context menu event handler.  // Context menu event handler.
473  void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )  void ChannelStrip::contextMenuEvent( QContextMenuEvent *pEvent )
474  {  {
475      if (m_pChannel == NULL)          if (m_pChannel == NULL)
476          return;                  return;
477    
478      // 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).
479      m_pChannel->contextMenuEvent(pEvent);          m_pChannel->contextMenuEvent(pEvent);
480  }  }
481    
482    

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

  ViewVC Help
Powered by ViewVC