/[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 1510 by capela, Thu Nov 22 14:17:24 2007 UTC revision 2074 by capela, Mon Mar 29 17:00:30 2010 UTC
# Line 1  Line 1 
1  // qsamplerChannelStrip.cpp  // qsamplerChannelStrip.cpp
2  //  //
3  /****************************************************************************  /****************************************************************************
4     Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved.     Copyright (C) 2004-2010, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, 2008 Christian Schoenebeck
6    
7     This program is free software; you can redistribute it and/or     This program is free software; you can redistribute it and/or
8     modify it under the terms of the GNU General Public License     modify it under the terms of the GNU General Public License
# Line 25  Line 25 
25    
26  #include "qsamplerMainForm.h"  #include "qsamplerMainForm.h"
27    
28    #include "qsamplerChannelFxForm.h"
29    
30    #include <QMessageBox>
31  #include <QDragEnterEvent>  #include <QDragEnterEvent>
32    #include <QTimer>
33  #include <QUrl>  #include <QUrl>
34    
35    
36  // Channel status/usage usage limit control.  // Channel status/usage usage limit control.
37  #define QSAMPLER_ERROR_LIMIT    3  #define QSAMPLER_ERROR_LIMIT    3
38    
39  // Needed for lroundf()  // Needed for lroundf()
40  #include <math.h>  #include <math.h>
41    
 namespace QSampler {  
   
42  #ifndef CONFIG_ROUND  #ifndef CONFIG_ROUND
43  static inline long lroundf ( float x )  static inline long lroundf ( float x )
44  {  {
# Line 46  static inline long lroundf ( float x ) Line 49  static inline long lroundf ( float x )
49  }  }
50  #endif  #endif
51    
52    
53    namespace QSampler {
54    
55    //-------------------------------------------------------------------------
56    // QSampler::ChannelStrip -- Channel strip form implementation.
57    //
58    
59    // MIDI activity pixmap common resources.
60    int      ChannelStrip::g_iMidiActivityRefCount = 0;
61    QPixmap *ChannelStrip::g_pMidiActivityLedOn    = NULL;
62    QPixmap *ChannelStrip::g_pMidiActivityLedOff   = NULL;
63    
64    // Channel strip activation/selection.
65    ChannelStrip *ChannelStrip::g_pSelectedStrip = NULL;
66    
67  ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags )  ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags )
68          : QWidget(pParent, wflags)          : QWidget(pParent, wflags)
69  {  {
# Line 56  ChannelStrip::ChannelStrip ( QWidget* pP Line 74  ChannelStrip::ChannelStrip ( QWidget* pP
74          m_iDirtyChange = 0;          m_iDirtyChange = 0;
75          m_iErrorCount  = 0;          m_iErrorCount  = 0;
76    
77            if (++g_iMidiActivityRefCount == 1) {
78                    g_pMidiActivityLedOn  = new QPixmap(":/images/ledon1.png");
79                    g_pMidiActivityLedOff = new QPixmap(":/images/ledoff1.png");
80            }
81    
82            m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOff);
83    
84    #ifndef CONFIG_EVENT_CHANNEL_MIDI
85            m_ui.MidiActivityLabel->setToolTip("MIDI activity (disabled)");
86    #endif
87    
88            m_pMidiActivityTimer = new QTimer(this);
89            m_pMidiActivityTimer->setSingleShot(true);
90    
91            QObject::connect(m_pMidiActivityTimer,
92                    SIGNAL(timeout()),
93                    SLOT(midiActivityLedOff())
94            );
95    
96          // Try to restore normal window positioning.          // Try to restore normal window positioning.
97          adjustSize();          adjustSize();
98    
# Line 77  ChannelStrip::ChannelStrip ( QWidget* pP Line 114  ChannelStrip::ChannelStrip ( QWidget* pP
114          QObject::connect(m_ui.ChannelEditPushButton,          QObject::connect(m_ui.ChannelEditPushButton,
115                  SIGNAL(clicked()),                  SIGNAL(clicked()),
116                  SLOT(channelEdit()));                  SLOT(channelEdit()));
117            QObject::connect(m_ui.FxPushButton,
118                    SIGNAL(clicked()),
119                    SLOT(channelFxEdit()));
120    
121            setSelected(false);
122  }  }
123    
124  ChannelStrip::~ChannelStrip() {  
125    ChannelStrip::~ChannelStrip (void)
126    {
127            setSelected(false);
128    
129          // Destroy existing channel descriptor.          // Destroy existing channel descriptor.
130          if (m_pChannel)          if (m_pChannel)
131                  delete m_pChannel;                  delete m_pChannel;
132          m_pChannel = NULL;          m_pChannel = NULL;
133    
134            if (--g_iMidiActivityRefCount == 0) {
135                    if (g_pMidiActivityLedOn)
136                            delete g_pMidiActivityLedOn;
137                    g_pMidiActivityLedOn = NULL;
138                    if (g_pMidiActivityLedOff)
139                            delete g_pMidiActivityLedOff;
140                    g_pMidiActivityLedOff = NULL;
141            }
142  }  }
143    
144    
# Line 102  void ChannelStrip::dragEnterEvent ( QDra Line 157  void ChannelStrip::dragEnterEvent ( QDra
157                          while (iter.hasNext()) {                          while (iter.hasNext()) {
158                                  const QString& sFilename = iter.next().toLocalFile();                                  const QString& sFilename = iter.next().toLocalFile();
159                                  if (!sFilename.isEmpty()) {                                  if (!sFilename.isEmpty()) {
160                                          bAccept = qsamplerChannel::isInstrumentFile(sFilename);                                          bAccept = Channel::isInstrumentFile(sFilename);
161                                          break;                                          break;
162                                  }                                  }
163                          }                          }
# Line 143  void ChannelStrip::dropEvent ( QDropEven Line 198  void ChannelStrip::dropEvent ( QDropEven
198    
199    
200  // Channel strip setup formal initializer.  // Channel strip setup formal initializer.
201  void ChannelStrip::setup ( qsamplerChannel *pChannel )  void ChannelStrip::setup ( Channel *pChannel )
202  {  {
203          // Destroy any previous channel descriptor;          // Destroy any previous channel descriptor;
204          // (remember that once setup we own it!)          // (remember that once setup we own it!)
# Line 161  void ChannelStrip::setup ( qsamplerChann Line 216  void ChannelStrip::setup ( qsamplerChann
216                  setAcceptDrops(true);                  setAcceptDrops(true);
217  }  }
218    
219    
220  // Channel secriptor accessor.  // Channel secriptor accessor.
221  qsamplerChannel *ChannelStrip::channel (void) const  Channel *ChannelStrip::channel (void) const
222  {  {
223          return m_pChannel;          return m_pChannel;
224  }  }
# Line 192  void ChannelStrip::setDisplayEffect ( bo Line 248  void ChannelStrip::setDisplayEffect ( bo
248          m_ui.MidiPortChannelTextLabel->setPalette(pal);          m_ui.MidiPortChannelTextLabel->setPalette(pal);
249          pal.setColor(QPalette::Foreground, Qt::green);          pal.setColor(QPalette::Foreground, Qt::green);
250          if (bDisplayEffect) {          if (bDisplayEffect) {
251                  QPixmap pm(":/icons/displaybg1.png");                  QPixmap pm(":/images/displaybg1.png");
252                  pal.setBrush(QPalette::Background, QBrush(pm));                  pal.setBrush(QPalette::Background, QBrush(pm));
253          } else {          } else {
254                  pal.setColor(QPalette::Background, Qt::black);                  pal.setColor(QPalette::Background, Qt::black);
255          }          }
256          m_ui.ChannelInfoFrame->setPalette(pal);          m_ui.ChannelInfoFrame->setPalette(pal);
257            m_ui.InstrumentNameTextLabel->setPalette(pal);
258          m_ui.StreamVoiceCountTextLabel->setPalette(pal);          m_ui.StreamVoiceCountTextLabel->setPalette(pal);
259  }  }
260    
# Line 269  void ChannelStrip::channelEdit (void) Line 326  void ChannelStrip::channelEdit (void)
326          m_pChannel->editChannel();          m_pChannel->editChannel();
327  }  }
328    
329    bool ChannelStrip::channelFxEdit (void)
330    {
331            MainForm *pMainForm = MainForm::getInstance();
332            if (!pMainForm || !channel())
333                    return false;
334    
335            pMainForm->appendMessages(QObject::tr("channel fx sends..."));
336    
337            bool bResult = false;
338    
339    #if CONFIG_FXSEND
340            ChannelFxForm *pChannelFxForm =
341                    new ChannelFxForm(channel(), parentWidget());
342            if (pChannelFxForm) {
343                    //pChannelForm->setup(this);
344                    bResult = pChannelFxForm->exec();
345                    delete pChannelFxForm;
346            }
347    #else // CONFIG_FXSEND
348            QMessageBox::critical(this,
349                    QSAMPLER_TITLE ": " + tr("Unavailable"),
350                            tr("Sorry, QSampler was built without FX send support!\n\n"
351                               "(Make sure you have a recent liblscp when recompiling QSampler)"));
352    #endif // CONFIG_FXSEND
353    
354            return bResult;
355    }
356    
357  // Channel reset slot.  // Channel reset slot.
358  bool ChannelStrip::channelReset (void)  bool ChannelStrip::channelReset (void)
# Line 298  bool ChannelStrip::updateInstrumentName Line 382  bool ChannelStrip::updateInstrumentName
382    
383          // Instrument name...          // Instrument name...
384          if (m_pChannel->instrumentName().isEmpty()) {          if (m_pChannel->instrumentName().isEmpty()) {
385                  if (m_pChannel->instrumentStatus() >= 0)                  if (m_pChannel->instrumentStatus() >= 0) {
386                          m_ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::loadingInstrument());                          m_ui.InstrumentNameTextLabel->setText(
387                  else                                  ' ' + Channel::loadingInstrument());
388                          m_ui.InstrumentNameTextLabel->setText(' ' + qsamplerChannel::noInstrumentName());                  } else {
389          } else                          m_ui.InstrumentNameTextLabel->setText(
390                  m_ui.InstrumentNameTextLabel->setText(' ' + m_pChannel->instrumentName());                                  ' ' + Channel::noInstrumentName());
391                    }
392            } else {
393                    m_ui.InstrumentNameTextLabel->setText(
394                            ' ' + m_pChannel->instrumentName());
395            }
396    
397          return true;          return true;
398  }  }
# Line 344  bool ChannelStrip::updateChannelInfo (vo Line 433  bool ChannelStrip::updateChannelInfo (vo
433          // Update strip caption.          // Update strip caption.
434          QString sText = m_pChannel->channelName();          QString sText = m_pChannel->channelName();
435          setWindowTitle(sText);          setWindowTitle(sText);
436          m_ui.ChannelSetupPushButton->setText(sText);          m_ui.ChannelSetupPushButton->setText('&' + sText);
437    
438          // Check if we're up and connected.          // Check if we're up and connected.
439          MainForm* pMainForm = MainForm::getInstance();          MainForm* pMainForm = MainForm::getInstance();
# Line 355  bool ChannelStrip::updateChannelInfo (vo Line 444  bool ChannelStrip::updateChannelInfo (vo
444          m_pChannel->updateChannelInfo();          m_pChannel->updateChannelInfo();
445    
446          // Engine name...          // Engine name...
447          if (m_pChannel->engineName().isEmpty())          if (m_pChannel->engineName().isEmpty()) {
448                  m_ui.EngineNameTextLabel->setText(' ' + qsamplerChannel::noEngineName());                  m_ui.EngineNameTextLabel->setText(
449          else                          ' ' + Channel::noEngineName());
450                  m_ui.EngineNameTextLabel->setText(' ' + m_pChannel->engineName());          } else {
451                    m_ui.EngineNameTextLabel->setText(
452                            ' ' + m_pChannel->engineName());
453            }
454    
455          // Instrument name...          // Instrument name...
456          updateInstrumentName(false);          updateInstrumentName(false);
# Line 380  bool ChannelStrip::updateChannelInfo (vo Line 472  bool ChannelStrip::updateChannelInfo (vo
472          if (iInstrumentStatus < 0) {          if (iInstrumentStatus < 0) {
473                  pal.setColor(QPalette::Foreground, Qt::red);                  pal.setColor(QPalette::Foreground, Qt::red);
474                  m_ui.InstrumentStatusTextLabel->setPalette(pal);                  m_ui.InstrumentStatusTextLabel->setPalette(pal);
475                  m_ui.InstrumentStatusTextLabel->setText(tr("ERR%1").arg(iInstrumentStatus));                  m_ui.InstrumentStatusTextLabel->setText(
476                            tr("ERR%1").arg(iInstrumentStatus));
477                  m_iErrorCount++;                  m_iErrorCount++;
478                  return false;                  return false;
479          }          }
# Line 388  bool ChannelStrip::updateChannelInfo (vo Line 481  bool ChannelStrip::updateChannelInfo (vo
481          pal.setColor(QPalette::Foreground,          pal.setColor(QPalette::Foreground,
482                  iInstrumentStatus < 100 ? Qt::yellow : Qt::green);                  iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
483          m_ui.InstrumentStatusTextLabel->setPalette(pal);          m_ui.InstrumentStatusTextLabel->setPalette(pal);
484          m_ui.InstrumentStatusTextLabel->setText(QString::number(iInstrumentStatus) + '%');          m_ui.InstrumentStatusTextLabel->setText(
485                    QString::number(iInstrumentStatus) + '%');
486          m_iErrorCount = 0;          m_iErrorCount = 0;
487    
488  #ifdef CONFIG_MUTE_SOLO  #ifdef CONFIG_MUTE_SOLO
489          // Mute/Solo button state coloring...          // Mute/Solo button state coloring...
490          bool bMute = m_pChannel->channelMute();          bool bMute = m_pChannel->channelMute();
491          const QColor& rgbButton = pal.color(QPalette::Button);          const QColor& rgbButton = pal.color(QPalette::Button);
492            const QColor& rgbButtonText = pal.color(QPalette::ButtonText);
493          pal.setColor(QPalette::Foreground, rgbFore);          pal.setColor(QPalette::Foreground, rgbFore);
494          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);
495            pal.setColor(QPalette::ButtonText, bMute ? Qt::darkYellow : rgbButtonText);
496          m_ui.ChannelMutePushButton->setPalette(pal);          m_ui.ChannelMutePushButton->setPalette(pal);
497          m_ui.ChannelMutePushButton->setDown(bMute);          m_ui.ChannelMutePushButton->setDown(bMute);
498          bool bSolo = m_pChannel->channelSolo();          bool bSolo = m_pChannel->channelSolo();
499          pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);            pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);  
500            pal.setColor(QPalette::ButtonText, bSolo ? Qt::darkCyan : rgbButtonText);
501          m_ui.ChannelSoloPushButton->setPalette(pal);          m_ui.ChannelSoloPushButton->setPalette(pal);
502          m_ui.ChannelSoloPushButton->setDown(bSolo);          m_ui.ChannelSoloPushButton->setDown(bSolo);
503  #else  #else
# Line 429  bool ChannelStrip::updateChannelUsage (v Line 526  bool ChannelStrip::updateChannelUsage (v
526                  return false;                  return false;
527    
528          // Get current channel voice count.          // Get current channel voice count.
529          int iVoiceCount  = ::lscp_get_channel_voice_count(pMainForm->client(), m_pChannel->channelID());          int iVoiceCount  = ::lscp_get_channel_voice_count(
530                    pMainForm->client(), m_pChannel->channelID());
531  // Get current stream count.  // Get current stream count.
532          int iStreamCount = ::lscp_get_channel_stream_count(pMainForm->client(), m_pChannel->channelID());          int iStreamCount = ::lscp_get_channel_stream_count(
533                    pMainForm->client(), m_pChannel->channelID());
534          // Get current channel buffer fill usage.          // Get current channel buffer fill usage.
535          // As benno has suggested this is the percentage usage          // As benno has suggested this is the percentage usage
536          // of the least filled buffer stream...          // of the least filled buffer stream...
537          int iStreamUsage = ::lscp_get_channel_stream_usage(pMainForm->client(), m_pChannel->channelID());;          int iStreamUsage = ::lscp_get_channel_stream_usage(
538                    pMainForm->client(), m_pChannel->channelID());;
539    
540          // Update the GUI elements...          // Update the GUI elements...
541          m_ui.StreamUsageProgressBar->setValue(iStreamUsage);          m_ui.StreamUsageProgressBar->setValue(iStreamUsage);
542          m_ui.StreamVoiceCountTextLabel->setText(QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));          m_ui.StreamVoiceCountTextLabel->setText(
543                    QString("%1 / %2").arg(iStreamCount).arg(iVoiceCount));
544    
545          // We're clean.          // We're clean.
546          return true;          return true;
# Line 480  void ChannelStrip::contextMenuEvent( QCo Line 581  void ChannelStrip::contextMenuEvent( QCo
581  }  }
582    
583    
584    void ChannelStrip::midiActivityLedOn (void)
585    {
586            m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOn);
587            m_pMidiActivityTimer->start(100);
588    }
589    
590    
591    void ChannelStrip::midiActivityLedOff (void)
592    {
593            m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOff);
594    }
595    
596    
597  // Error count hackish accessors.  // Error count hackish accessors.
598  void ChannelStrip::resetErrorCount (void)  void ChannelStrip::resetErrorCount (void)
599  {  {
600          m_iErrorCount = 0;          m_iErrorCount = 0;
601  }  }
602    
603    
604    // Channel strip activation/selection.
605    void ChannelStrip::setSelected ( bool bSelected )
606    {
607            if (bSelected) {
608                    if (g_pSelectedStrip == this)
609                            return;
610                    if (g_pSelectedStrip)
611                            g_pSelectedStrip->setSelected(false);
612                    g_pSelectedStrip = this;
613            } else {
614                    if (g_pSelectedStrip == this)
615                            g_pSelectedStrip = NULL;
616            }
617    
618            QPalette pal;
619            if (bSelected) {
620                    const QColor& color = pal.midlight().color();
621                    pal.setColor(QPalette::Background, color.dark(150));
622                    pal.setColor(QPalette::Foreground, color.light(150));
623            }
624            QWidget::setPalette(pal);
625    }
626    
627    
628    bool ChannelStrip::isSelected (void) const
629    {
630            return (this == g_pSelectedStrip);
631    }
632    
633    
634  } // namespace QSampler  } // namespace QSampler
635    
636    

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

  ViewVC Help
Powered by ViewVC