--- qsampler/trunk/src/qsamplerChannelStrip.cpp 2010/01/07 18:42:26 2038 +++ qsampler/trunk/src/qsamplerChannelStrip.cpp 2014/05/21 16:56:18 2570 @@ -1,8 +1,8 @@ // qsamplerChannelStrip.cpp // /**************************************************************************** - Copyright (C) 2004-2010, rncbc aka Rui Nuno Capela. All rights reserved. - Copyright (C) 2007, 2008 Christian Schoenebeck + Copyright (C) 2004-2014, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2007, 2008, 2014 Christian Schoenebeck This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -29,9 +29,14 @@ #include #include +#include #include #include +#include +#if QT_VERSION >= 0x050000 +#include +#endif // Channel status/usage usage limit control. #define QSAMPLER_ERROR_LIMIT 3 @@ -73,10 +78,11 @@ m_pChannel = NULL; m_iDirtyChange = 0; m_iErrorCount = 0; + m_instrumentListPopupMenu = NULL; if (++g_iMidiActivityRefCount == 1) { - g_pMidiActivityLedOn = new QPixmap(":/icons/ledon1.png"); - g_pMidiActivityLedOff = new QPixmap(":/icons/ledoff1.png"); + g_pMidiActivityLedOn = new QPixmap(":/images/ledon1.png"); + g_pMidiActivityLedOff = new QPixmap(":/images/ledoff1.png"); } m_ui.MidiActivityLabel->setPixmap(*g_pMidiActivityLedOff); @@ -157,7 +163,8 @@ while (iter.hasNext()) { const QString& sFilename = iter.next().toLocalFile(); if (!sFilename.isEmpty()) { - bAccept = Channel::isInstrumentFile(sFilename); + // bAccept = Channel::isDlsInstrumentFile(sFilename); + bAccept = QFileInfo(sFilename).exists(); break; } } @@ -234,7 +241,7 @@ { m_ui.EngineNameTextLabel->setFont(font); m_ui.MidiPortChannelTextLabel->setFont(font); - m_ui.InstrumentNameTextLabel->setFont(font); + m_ui.InstrumentNamePushButton->setFont(font); m_ui.InstrumentStatusTextLabel->setFont(font); } @@ -244,17 +251,19 @@ { QPalette pal; pal.setColor(QPalette::Foreground, Qt::yellow); + pal.setColor(QPalette::ButtonText, Qt::yellow); m_ui.EngineNameTextLabel->setPalette(pal); m_ui.MidiPortChannelTextLabel->setPalette(pal); pal.setColor(QPalette::Foreground, Qt::green); + pal.setColor(QPalette::ButtonText, Qt::green); if (bDisplayEffect) { - QPixmap pm(":/icons/displaybg1.png"); + QPixmap pm(":/images/displaybg1.png"); pal.setBrush(QPalette::Background, QBrush(pm)); } else { pal.setColor(QPalette::Background, Qt::black); } m_ui.ChannelInfoFrame->setPalette(pal); - m_ui.InstrumentNameTextLabel->setPalette(pal); + m_ui.InstrumentNamePushButton->setPalette(pal); m_ui.StreamVoiceCountTextLabel->setPalette(pal); } @@ -383,20 +392,67 @@ // Instrument name... if (m_pChannel->instrumentName().isEmpty()) { if (m_pChannel->instrumentStatus() >= 0) { - m_ui.InstrumentNameTextLabel->setText( + m_ui.InstrumentNamePushButton->setText( ' ' + Channel::loadingInstrument()); } else { - m_ui.InstrumentNameTextLabel->setText( + m_ui.InstrumentNamePushButton->setText( ' ' + Channel::noInstrumentName()); } } else { - m_ui.InstrumentNameTextLabel->setText( + m_ui.InstrumentNamePushButton->setText( ' ' + m_pChannel->instrumentName()); } + + bool bShowInstrumentPopup = false; + + // Instrument list popup (for fast switching among sounds of the same file) + if (!m_pChannel->instrumentFile().isEmpty()) { + const QStringList instruments + = Channel::getInstrumentList(m_pChannel->instrumentFile(), true); + if (!instruments.isEmpty()) { + bShowInstrumentPopup = true; + if (!m_instrumentListPopupMenu) { + m_instrumentListPopupMenu + = new QMenu(m_ui.InstrumentNamePushButton); + m_instrumentListPopupMenu->setTitle(tr("Instruments")); + // for cosmetical reasons, should have at least + // the width of the instrument name label... + m_instrumentListPopupMenu->setMinimumWidth(120); + m_ui.InstrumentNamePushButton->setMenu(m_instrumentListPopupMenu); + QObject::connect(m_instrumentListPopupMenu, + SIGNAL(triggered(QAction*)), + SLOT(instrumentListPopupItemClicked(QAction *))); + } else { + m_instrumentListPopupMenu->clear(); + } + QAction *action; + for (int i = 0; i < instruments.size(); ++i) { + action = m_instrumentListPopupMenu->addAction(instruments.at(i)); + action->setData(i); + action->setCheckable(true); + action->setChecked(i == m_pChannel->instrumentNr()); + } + } + } + + if (!bShowInstrumentPopup && m_instrumentListPopupMenu) { + delete m_instrumentListPopupMenu; + m_instrumentListPopupMenu = NULL; + } return true; } +void ChannelStrip::instrumentListPopupItemClicked ( QAction *action ) +{ + if (!action) return; + + QVariant data = action->data(); + if (data.isValid() && !m_pChannel->instrumentFile().isEmpty()) { + m_pChannel->loadInstrument(m_pChannel->instrumentFile(), data.toInt()); + emit channelChanged(this); + } +} // Do the dirty volume change. bool ChannelStrip::updateChannelVolume (void) @@ -468,7 +524,7 @@ const QColor& rgbFore = pal.color(QPalette::Foreground); // Instrument status... - int iInstrumentStatus = m_pChannel->instrumentStatus(); + const int iInstrumentStatus = m_pChannel->instrumentStatus(); if (iInstrumentStatus < 0) { pal.setColor(QPalette::Foreground, Qt::red); m_ui.InstrumentStatusTextLabel->setPalette(pal); @@ -477,6 +533,7 @@ m_iErrorCount++; return false; } + // All seems normal... pal.setColor(QPalette::Foreground, iInstrumentStatus < 100 ? Qt::yellow : Qt::green); @@ -489,12 +546,15 @@ // Mute/Solo button state coloring... bool bMute = m_pChannel->channelMute(); const QColor& rgbButton = pal.color(QPalette::Button); + const QColor& rgbButtonText = pal.color(QPalette::ButtonText); pal.setColor(QPalette::Foreground, rgbFore); pal.setColor(QPalette::Button, bMute ? Qt::yellow : rgbButton); + pal.setColor(QPalette::ButtonText, bMute ? Qt::darkYellow : rgbButtonText); m_ui.ChannelMutePushButton->setPalette(pal); m_ui.ChannelMutePushButton->setDown(bMute); bool bSolo = m_pChannel->channelSolo(); pal.setColor(QPalette::Button, bSolo ? Qt::cyan : rgbButton); + pal.setColor(QPalette::ButtonText, bSolo ? Qt::darkCyan : rgbButtonText); m_ui.ChannelSoloPushButton->setPalette(pal); m_ui.ChannelSoloPushButton->setDown(bSolo); #else