/[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 1514 by capela, Fri Nov 23 10:51:37 2007 UTC revision 2570 by capela, Wed May 21 16:56:18 2014 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-2014, rncbc aka Rui Nuno Capela. All rights reserved.
5     Copyright (C) 2007, Christian Schoenebeck     Copyright (C) 2007, 2008, 2014 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 <QFileInfo>
33    #include <QTimer>
34  #include <QUrl>  #include <QUrl>
35    #include <QMenu>
36    
37    #if QT_VERSION >= 0x050000
38    #include <QMimeData>
39    #endif
40    
41  // Channel status/usage usage limit control.  // Channel status/usage usage limit control.
42  #define QSAMPLER_ERROR_LIMIT    3  #define QSAMPLER_ERROR_LIMIT    3
# Line 47  static inline long lroundf ( float x ) Line 57  static inline long lroundf ( float x )
57    
58  namespace QSampler {  namespace QSampler {
59    
60    //-------------------------------------------------------------------------
61    // QSampler::ChannelStrip -- Channel strip form implementation.
62    //
63    
64    // MIDI activity pixmap common resources.
65    int      ChannelStrip::g_iMidiActivityRefCount = 0;
66    QPixmap *ChannelStrip::g_pMidiActivityLedOn    = NULL;
67    QPixmap *ChannelStrip::g_pMidiActivityLedOff   = NULL;
68    
69  // Channel strip activation/selection.  // Channel strip activation/selection.
70  ChannelStrip *ChannelStrip::g_pSelectedStrip = NULL;  ChannelStrip *ChannelStrip::g_pSelectedStrip = NULL;
71    
   
72  ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags )  ChannelStrip::ChannelStrip ( QWidget* pParent, Qt::WindowFlags wflags )
73          : QWidget(pParent, wflags)          : QWidget(pParent, wflags)
74  {  {
# Line 60  ChannelStrip::ChannelStrip ( QWidget* pP Line 78  ChannelStrip::ChannelStrip ( QWidget* pP
78          m_pChannel     = NULL;          m_pChannel     = NULL;
79          m_iDirtyChange = 0;          m_iDirtyChange = 0;
80          m_iErrorCount  = 0;          m_iErrorCount  = 0;
81            m_instrumentListPopupMenu = NULL;
82    
83            if (++g_iMidiActivityRefCount == 1) {
84                    g_pMidiActivityLedOn  = new QPixmap(":/images/ledon1.png");
85                    g_pMidiActivityLedOff = new QPixmap(":/images/ledoff1.png");
86            }
87    
88            m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOff);
89    
90    #ifndef CONFIG_EVENT_CHANNEL_MIDI
91            m_ui.MidiActivityLabel->setToolTip("MIDI activity (disabled)");
92    #endif
93    
94            m_pMidiActivityTimer = new QTimer(this);
95            m_pMidiActivityTimer->setSingleShot(true);
96    
97            QObject::connect(m_pMidiActivityTimer,
98                    SIGNAL(timeout()),
99                    SLOT(midiActivityLedOff())
100            );
101    
102          // Try to restore normal window positioning.          // Try to restore normal window positioning.
103          adjustSize();          adjustSize();
         setSelected(false);  
104    
105          QObject::connect(m_ui.ChannelSetupPushButton,          QObject::connect(m_ui.ChannelSetupPushButton,
106                  SIGNAL(clicked()),                  SIGNAL(clicked()),
# Line 83  ChannelStrip::ChannelStrip ( QWidget* pP Line 120  ChannelStrip::ChannelStrip ( QWidget* pP
120          QObject::connect(m_ui.ChannelEditPushButton,          QObject::connect(m_ui.ChannelEditPushButton,
121                  SIGNAL(clicked()),                  SIGNAL(clicked()),
122                  SLOT(channelEdit()));                  SLOT(channelEdit()));
123            QObject::connect(m_ui.FxPushButton,
124                    SIGNAL(clicked()),
125                    SLOT(channelFxEdit()));
126    
127            setSelected(false);
128  }  }
129    
130    
131  ChannelStrip::~ChannelStrip (void)  ChannelStrip::~ChannelStrip (void)
132  {  {
133            setSelected(false);
134    
135          // Destroy existing channel descriptor.          // Destroy existing channel descriptor.
136          if (m_pChannel)          if (m_pChannel)
137                  delete m_pChannel;                  delete m_pChannel;
138          m_pChannel = NULL;          m_pChannel = NULL;
139    
140            if (--g_iMidiActivityRefCount == 0) {
141                    if (g_pMidiActivityLedOn)
142                            delete g_pMidiActivityLedOn;
143                    g_pMidiActivityLedOn = NULL;
144                    if (g_pMidiActivityLedOff)
145                            delete g_pMidiActivityLedOff;
146                    g_pMidiActivityLedOff = NULL;
147            }
148  }  }
149    
150    
# Line 110  void ChannelStrip::dragEnterEvent ( QDra Line 163  void ChannelStrip::dragEnterEvent ( QDra
163                          while (iter.hasNext()) {                          while (iter.hasNext()) {
164                                  const QString& sFilename = iter.next().toLocalFile();                                  const QString& sFilename = iter.next().toLocalFile();
165                                  if (!sFilename.isEmpty()) {                                  if (!sFilename.isEmpty()) {
166                                          bAccept = qsamplerChannel::isInstrumentFile(sFilename);                                  //      bAccept = Channel::isDlsInstrumentFile(sFilename);
167                                            bAccept = QFileInfo(sFilename).exists();
168                                          break;                                          break;
169                                  }                                  }
170                          }                          }
# Line 151  void ChannelStrip::dropEvent ( QDropEven Line 205  void ChannelStrip::dropEvent ( QDropEven
205    
206    
207  // Channel strip setup formal initializer.  // Channel strip setup formal initializer.
208  void ChannelStrip::setup ( qsamplerChannel *pChannel )  void ChannelStrip::setup ( Channel *pChannel )
209  {  {
210          // Destroy any previous channel descriptor;          // Destroy any previous channel descriptor;
211          // (remember that once setup we own it!)          // (remember that once setup we own it!)
# Line 171  void ChannelStrip::setup ( qsamplerChann Line 225  void ChannelStrip::setup ( qsamplerChann
225    
226    
227  // Channel secriptor accessor.  // Channel secriptor accessor.
228  qsamplerChannel *ChannelStrip::channel (void) const  Channel *ChannelStrip::channel (void) const
229  {  {
230          return m_pChannel;          return m_pChannel;
231  }  }
# Line 187  void ChannelStrip::setDisplayFont ( cons Line 241  void ChannelStrip::setDisplayFont ( cons
241  {  {
242          m_ui.EngineNameTextLabel->setFont(font);          m_ui.EngineNameTextLabel->setFont(font);
243          m_ui.MidiPortChannelTextLabel->setFont(font);          m_ui.MidiPortChannelTextLabel->setFont(font);
244          m_ui.InstrumentNameTextLabel->setFont(font);          m_ui.InstrumentNamePushButton->setFont(font);
245          m_ui.InstrumentStatusTextLabel->setFont(font);          m_ui.InstrumentStatusTextLabel->setFont(font);
246  }  }
247    
# Line 197  void ChannelStrip::setDisplayEffect ( bo Line 251  void ChannelStrip::setDisplayEffect ( bo
251  {  {
252          QPalette pal;          QPalette pal;
253          pal.setColor(QPalette::Foreground, Qt::yellow);          pal.setColor(QPalette::Foreground, Qt::yellow);
254            pal.setColor(QPalette::ButtonText, Qt::yellow);
255          m_ui.EngineNameTextLabel->setPalette(pal);          m_ui.EngineNameTextLabel->setPalette(pal);
256          m_ui.MidiPortChannelTextLabel->setPalette(pal);          m_ui.MidiPortChannelTextLabel->setPalette(pal);
257          pal.setColor(QPalette::Foreground, Qt::green);          pal.setColor(QPalette::Foreground, Qt::green);
258            pal.setColor(QPalette::ButtonText, Qt::green);
259          if (bDisplayEffect) {          if (bDisplayEffect) {
260                  QPixmap pm(":/icons/displaybg1.png");                  QPixmap pm(":/images/displaybg1.png");
261                  pal.setBrush(QPalette::Background, QBrush(pm));                  pal.setBrush(QPalette::Background, QBrush(pm));
262          } else {          } else {
263                  pal.setColor(QPalette::Background, Qt::black);                  pal.setColor(QPalette::Background, Qt::black);
264          }          }
265          m_ui.ChannelInfoFrame->setPalette(pal);          m_ui.ChannelInfoFrame->setPalette(pal);
266            m_ui.InstrumentNamePushButton->setPalette(pal);
267          m_ui.StreamVoiceCountTextLabel->setPalette(pal);          m_ui.StreamVoiceCountTextLabel->setPalette(pal);
268  }  }
269    
# Line 278  void ChannelStrip::channelEdit (void) Line 335  void ChannelStrip::channelEdit (void)
335          m_pChannel->editChannel();          m_pChannel->editChannel();
336  }  }
337    
338    bool ChannelStrip::channelFxEdit (void)
339    {
340            MainForm *pMainForm = MainForm::getInstance();
341            if (!pMainForm || !channel())
342                    return false;
343    
344            pMainForm->appendMessages(QObject::tr("channel fx sends..."));
345    
346            bool bResult = false;
347    
348    #if CONFIG_FXSEND
349            ChannelFxForm *pChannelFxForm =
350                    new ChannelFxForm(channel(), parentWidget());
351            if (pChannelFxForm) {
352                    //pChannelForm->setup(this);
353                    bResult = pChannelFxForm->exec();
354                    delete pChannelFxForm;
355            }
356    #else // CONFIG_FXSEND
357            QMessageBox::critical(this,
358                    QSAMPLER_TITLE ": " + tr("Unavailable"),
359                            tr("Sorry, QSampler was built without FX send support!\n\n"
360                               "(Make sure you have a recent liblscp when recompiling QSampler)"));
361    #endif // CONFIG_FXSEND
362    
363            return bResult;
364    }
365    
366  // Channel reset slot.  // Channel reset slot.
367  bool ChannelStrip::channelReset (void)  bool ChannelStrip::channelReset (void)
# Line 308  bool ChannelStrip::updateInstrumentName Line 392  bool ChannelStrip::updateInstrumentName
392          // Instrument name...          // Instrument name...
393          if (m_pChannel->instrumentName().isEmpty()) {          if (m_pChannel->instrumentName().isEmpty()) {
394                  if (m_pChannel->instrumentStatus() >= 0) {                  if (m_pChannel->instrumentStatus() >= 0) {
395                          m_ui.InstrumentNameTextLabel->setText(                          m_ui.InstrumentNamePushButton->setText(
396                                  ' ' + qsamplerChannel::loadingInstrument());                                  ' ' + Channel::loadingInstrument());
397                  } else {                  } else {
398                          m_ui.InstrumentNameTextLabel->setText(                          m_ui.InstrumentNamePushButton->setText(
399                                  ' ' + qsamplerChannel::noInstrumentName());                                  ' ' + Channel::noInstrumentName());
400                  }                  }
401          } else {          } else {
402                  m_ui.InstrumentNameTextLabel->setText(                  m_ui.InstrumentNamePushButton->setText(
403                          ' ' + m_pChannel->instrumentName());                          ' ' + m_pChannel->instrumentName());
404          }          }
405            
406            bool bShowInstrumentPopup = false;
407    
408            // Instrument list popup (for fast switching among sounds of the same file)
409            if (!m_pChannel->instrumentFile().isEmpty()) {
410                    const QStringList instruments
411                            = Channel::getInstrumentList(m_pChannel->instrumentFile(), true);
412                    if (!instruments.isEmpty()) {
413                            bShowInstrumentPopup = true;
414                            if (!m_instrumentListPopupMenu) {
415                                    m_instrumentListPopupMenu
416                                            = new QMenu(m_ui.InstrumentNamePushButton);
417                                    m_instrumentListPopupMenu->setTitle(tr("Instruments"));
418                                    // for cosmetical reasons, should have at least
419                                    // the width of the instrument name label...
420                                    m_instrumentListPopupMenu->setMinimumWidth(120);
421                                    m_ui.InstrumentNamePushButton->setMenu(m_instrumentListPopupMenu);
422                                    QObject::connect(m_instrumentListPopupMenu,
423                                            SIGNAL(triggered(QAction*)),
424                                            SLOT(instrumentListPopupItemClicked(QAction *)));
425                            } else {
426                                    m_instrumentListPopupMenu->clear();
427                            }
428                            QAction *action;
429                            for (int i = 0; i < instruments.size(); ++i) {
430                                    action = m_instrumentListPopupMenu->addAction(instruments.at(i));
431                                    action->setData(i);
432                                    action->setCheckable(true);
433                                    action->setChecked(i == m_pChannel->instrumentNr());
434                            }
435                    }
436            }
437    
438            if (!bShowInstrumentPopup && m_instrumentListPopupMenu) {
439                    delete m_instrumentListPopupMenu;
440                    m_instrumentListPopupMenu = NULL;
441            }
442    
443          return true;          return true;
444  }  }
445    
446    void ChannelStrip::instrumentListPopupItemClicked ( QAction *action )
447    {
448            if (!action) return;
449    
450            QVariant data = action->data();
451            if (data.isValid() && !m_pChannel->instrumentFile().isEmpty()) {
452                    m_pChannel->loadInstrument(m_pChannel->instrumentFile(), data.toInt());
453                    emit channelChanged(this);
454            }
455    }
456    
457  // Do the dirty volume change.  // Do the dirty volume change.
458  bool ChannelStrip::updateChannelVolume (void)  bool ChannelStrip::updateChannelVolume (void)
# Line 371  bool ChannelStrip::updateChannelInfo (vo Line 502  bool ChannelStrip::updateChannelInfo (vo
502          // Engine name...          // Engine name...
503          if (m_pChannel->engineName().isEmpty()) {          if (m_pChannel->engineName().isEmpty()) {
504                  m_ui.EngineNameTextLabel->setText(                  m_ui.EngineNameTextLabel->setText(
505                          ' ' + qsamplerChannel::noEngineName());                          ' ' + Channel::noEngineName());
506          } else {          } else {
507                  m_ui.EngineNameTextLabel->setText(                  m_ui.EngineNameTextLabel->setText(
508                          ' ' + m_pChannel->engineName());                          ' ' + m_pChannel->engineName());
# Line 393  bool ChannelStrip::updateChannelInfo (vo Line 524  bool ChannelStrip::updateChannelInfo (vo
524          const QColor& rgbFore = pal.color(QPalette::Foreground);          const QColor& rgbFore = pal.color(QPalette::Foreground);
525    
526          // Instrument status...          // Instrument status...
527          int iInstrumentStatus = m_pChannel->instrumentStatus();          const int iInstrumentStatus = m_pChannel->instrumentStatus();
528          if (iInstrumentStatus < 0) {          if (iInstrumentStatus < 0) {
529                  pal.setColor(QPalette::Foreground, Qt::red);                  pal.setColor(QPalette::Foreground, Qt::red);
530                  m_ui.InstrumentStatusTextLabel->setPalette(pal);                  m_ui.InstrumentStatusTextLabel->setPalette(pal);
# Line 402  bool ChannelStrip::updateChannelInfo (vo Line 533  bool ChannelStrip::updateChannelInfo (vo
533                  m_iErrorCount++;                  m_iErrorCount++;
534                  return false;                  return false;
535          }          }
536    
537          // All seems normal...          // All seems normal...
538          pal.setColor(QPalette::Foreground,          pal.setColor(QPalette::Foreground,
539                  iInstrumentStatus < 100 ? Qt::yellow : Qt::green);                  iInstrumentStatus < 100 ? Qt::yellow : Qt::green);
# Line 414  bool ChannelStrip::updateChannelInfo (vo Line 546  bool ChannelStrip::updateChannelInfo (vo
546          // Mute/Solo button state coloring...          // Mute/Solo button state coloring...
547          bool bMute = m_pChannel->channelMute();          bool bMute = m_pChannel->channelMute();
548          const QColor& rgbButton = pal.color(QPalette::Button);          const QColor& rgbButton = pal.color(QPalette::Button);
549            const QColor& rgbButtonText = pal.color(QPalette::ButtonText);
550          pal.setColor(QPalette::Foreground, rgbFore);          pal.setColor(QPalette::Foreground, rgbFore);
551          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);          pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton);
552            pal.setColor(QPalette::ButtonText, bMute ? Qt::darkYellow : rgbButtonText);
553          m_ui.ChannelMutePushButton->setPalette(pal);          m_ui.ChannelMutePushButton->setPalette(pal);
554          m_ui.ChannelMutePushButton->setDown(bMute);          m_ui.ChannelMutePushButton->setDown(bMute);
555          bool bSolo = m_pChannel->channelSolo();          bool bSolo = m_pChannel->channelSolo();
556          pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);            pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton);  
557            pal.setColor(QPalette::ButtonText, bSolo ? Qt::darkCyan : rgbButtonText);
558          m_ui.ChannelSoloPushButton->setPalette(pal);          m_ui.ChannelSoloPushButton->setPalette(pal);
559          m_ui.ChannelSoloPushButton->setDown(bSolo);          m_ui.ChannelSoloPushButton->setDown(bSolo);
560  #else  #else
# Line 503  void ChannelStrip::contextMenuEvent( QCo Line 638  void ChannelStrip::contextMenuEvent( QCo
638  }  }
639    
640    
641    void ChannelStrip::midiActivityLedOn (void)
642    {
643            m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOn);
644            m_pMidiActivityTimer->start(100);
645    }
646    
647    
648    void ChannelStrip::midiActivityLedOff (void)
649    {
650            m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOff);
651    }
652    
653    
654  // Error count hackish accessors.  // Error count hackish accessors.
655  void ChannelStrip::resetErrorCount (void)  void ChannelStrip::resetErrorCount (void)
656  {  {

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

  ViewVC Help
Powered by ViewVC