/[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 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  ChannelStrip::ChannelStrip(QWidget* parent, Qt::WFlags f) : QWidget(parent, f) {  #ifndef CONFIG_ROUND
40      ui.setupUi(this);  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      // Initialize locals.  ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags )
50      m_pChannel     = NULL;          : QWidget(pParent, wflags)
51      m_iDirtyChange = 0;  {
52      m_iErrorCount  = 0;          m_ui.setupUi(this);
53    
54      // Try to restore normal window positioning.          // Initialize locals.
55      adjustSize();          m_pChannel     = NULL;
56            m_iDirtyChange = 0;
57            m_iErrorCount  = 0;
58    
59          QObject::connect(ui.ChannelSetupPushButton,          // Try to restore normal window positioning.
60            adjustSize();
61    
62            QObject::connect(m_ui.ChannelSetupPushButton,
63                  SIGNAL(clicked()),                  SIGNAL(clicked()),
64                  SLOT(channelSetup()));                  SLOT(channelSetup()));
65          QObject::connect(ui.ChannelMutePushButton,          QObject::connect(m_ui.ChannelMutePushButton,
66                  SIGNAL(toggled(bool)),                  SIGNAL(toggled(bool)),
67                  SLOT(channelMute(bool)));                  SLOT(channelMute(bool)));
68          QObject::connect(ui.ChannelSoloPushButton,          QObject::connect(m_ui.ChannelSoloPushButton,
69                  SIGNAL(toggled(bool)),                  SIGNAL(toggled(bool)),
70                  SLOT(channelSolo(bool)));                  SLOT(channelSolo(bool)));
71          QObject::connect(ui.VolumeSlider,          QObject::connect(m_ui.VolumeSlider,
72                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
73                  SLOT(volumeChanged(int)));                  SLOT(volumeChanged(int)));
74          QObject::connect(ui.VolumeSpinBox,          QObject::connect(m_ui.VolumeSpinBox,
75                  SIGNAL(valueChanged(int)),                  SIGNAL(valueChanged(int)),
76                  SLOT(volumeChanged(int)));                  SLOT(volumeChanged(int)));
77          QObject::connect(ui.ChannelEditPushButton,          QObject::connect(m_ui.ChannelEditPushButton,
78                  SIGNAL(clicked()),                  SIGNAL(clicked()),
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 132  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)  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)  QFont ChannelStrip::displayFont (void) const
176  {  {
177      return 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      ui.EngineNameTextLabel->setFont(font);          m_ui.EngineNameTextLabel->setFont(font);
183      ui.MidiPortChannelTextLabel->setFont(font);          m_ui.MidiPortChannelTextLabel->setFont(font);
184      ui.InstrumentNameTextLabel->setFont(font);          m_ui.InstrumentNameTextLabel->setFont(font);
185      ui.InstrumentStatusTextLabel->setFont(font);          m_ui.InstrumentStatusTextLabel->setFont(font);
186  }  }
187    
188    
# Line 174  void ChannelStrip::setDisplayFont ( cons Line 190  void ChannelStrip::setDisplayFont ( cons
190  void ChannelStrip::setDisplayEffect ( bool bDisplayEffect )  void ChannelStrip::setDisplayEffect ( bool bDisplayEffect )
191  {  {
192          QPalette pal;          QPalette pal;
193            pal.setColor(QPalette::Foreground, Qt::yellow);
194            m_ui.EngineNameTextLabel->setPalette(pal);
195            m_ui.MidiPortChannelTextLabel->setPalette(pal);
196          pal.setColor(QPalette::Foreground, Qt::green);          pal.setColor(QPalette::Foreground, Qt::green);
197          if (bDisplayEffect) {          if (bDisplayEffect) {
198                  QPixmap pm(":/icons/displaybg1.png");                  QPixmap pm(":/icons/displaybg1.png");
# Line 181  void ChannelStrip::setDisplayEffect ( bo Line 200  void ChannelStrip::setDisplayEffect ( bo
200          } else {          } else {
201                  pal.setColor(QPalette::Background, Qt::black);                  pal.setColor(QPalette::Background, Qt::black);
202          }          }
203          ui.ChannelInfoFrame->setPalette(pal);          m_ui.ChannelInfoFrame->setPalette(pal);
204          ui.StreamVoiceCountTextLabel->setPalette(pal);          m_ui.StreamVoiceCountTextLabel->setPalette(pal);
205  }  }
206    
207    
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      ui.VolumeSlider->setRange(0, iMaxVolume);          m_ui.VolumeSlider->setRange(0, iMaxVolume);
213      ui.VolumeSpinBox->setRange(0, iMaxVolume);          m_ui.VolumeSpinBox->setRange(0, iMaxVolume);
214      m_iDirtyChange--;          m_iDirtyChange--;
215  }  }
216    
217    
# Line 282  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                          ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument());                          m_ui.InstrumentNameTextLabel->setText(
306                  else                                  ' ' + qsamplerChannel::loadingInstrument());
307                          ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());                  } else {
308          } else                          m_ui.InstrumentNameTextLabel->setText(
309                  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 296  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      ui.VolumeSlider->setValue(iVolume);          // Flag it here, to avoid infinite recursion.
333      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      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          ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());                  m_ui.EngineNameTextLabel->setText(
368      else                          ' ' + qsamplerChannel::noEngineName());
369          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");
381          else          else
382                  sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1);                  sMidiPortChannel += QString::number(m_pChannel->midiChannel() + 1);
383          ui.MidiPortChannelTextLabel->setText(sMidiPortChannel);          m_ui.MidiPortChannelTextLabel->setText(sMidiPortChannel);
384    
385          // Common palette...          // Common palette...
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                  ui.InstrumentStatusTextLabel->setPalette(pal);                  m_ui.InstrumentStatusTextLabel->setPalette(pal);
394          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      ui.InstrumentStatusTextLabel->setPalette(pal);          m_ui.InstrumentStatusTextLabel->setPalette(pal);
403      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          ui.ChannelMutePushButton->setPalette(pal);          m_ui.ChannelMutePushButton->setPalette(pal);
414          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          ui.ChannelSoloPushButton->setPalette(pal);          m_ui.ChannelSoloPushButton->setPalette(pal);
418          ui.ChannelSoloPushButton->setDown(bSolo);          m_ui.ChannelSoloPushButton->setDown(bSolo);
419  #else  #else
420          ui.ChannelMutePushButton->setEnabled(false);          m_ui.ChannelMutePushButton->setEnabled(false);
421          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 422  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      ui.StreamUsageProgressBar->setValue(iStreamUsage);                  pMainForm->client(), m_pChannel->channelID());;
455      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.1499  
changed lines
  Added in v.1513

  ViewVC Help
Powered by ViewVC