--- qsampler/trunk/src/qsamplerChannel.cpp 2005/03/15 23:54:14 467 +++ qsampler/trunk/src/qsamplerChannel.cpp 2005/08/28 00:31:34 758 @@ -19,13 +19,12 @@ *****************************************************************************/ +#include "qsamplerAbout.h" #include "qsamplerChannel.h" #include "qsamplerMainForm.h" #include "qsamplerChannelForm.h" -#include "config.h" - #include #ifdef CONFIG_LIBGIG @@ -50,14 +49,15 @@ // m_sInstrumentFile = m_sInstrumentName; m_iInstrumentNr = -1; m_iInstrumentStatus = -1; - m_sMidiDriver = "Alsa"; // DEPRECATED. + m_sMidiDriver = "ALSA"; m_iMidiDevice = -1; m_iMidiPort = -1; m_iMidiChannel = -1; - m_sAudioDriver = "Alsa"; // DEPRECATED. + m_sAudioDriver = "ALSA"; m_iAudioDevice = -1; m_fVolume = 0.0; - + m_bMute = false; + m_bSolo = false; } // Default destructor. @@ -66,8 +66,15 @@ } +// Main application form accessor. +qsamplerMainForm *qsamplerChannel::mainForm(void) const +{ + return m_pMainForm; +} + + // The global options settings delegated property. -qsamplerOptions *qsamplerChannel::options (void) +qsamplerOptions *qsamplerChannel::options (void) const { if (m_pMainForm == NULL) return NULL; @@ -77,7 +84,7 @@ // The client descriptor delegated property. -lscp_client_t *qsamplerChannel::client (void) +lscp_client_t *qsamplerChannel::client (void) const { if (m_pMainForm == NULL) return NULL; @@ -124,14 +131,14 @@ m_iChannelID = -1; } } - + // Return whether we've removed the channel... return (m_iChannelID < 0); } // Channel-ID (aka Sammpler-Channel) accessors. -int qsamplerChannel::channelID (void) +int qsamplerChannel::channelID (void) const { return m_iChannelID; } @@ -143,14 +150,14 @@ // Readable channel name. -QString qsamplerChannel::channelName (void) +QString qsamplerChannel::channelName (void) const { return (m_iChannelID < 0 ? QObject::tr("New Channel") : QObject::tr("Channel %1").arg(m_iChannelID)); } // Engine name accessors. -QString& qsamplerChannel::engineName (void) +const QString& qsamplerChannel::engineName (void) const { return m_sEngineName; } @@ -161,7 +168,7 @@ return false; if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName) return true; - + if (::lscp_load_engine(client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { appendMessagesClient("lscp_load_engine"); return false; @@ -174,25 +181,25 @@ // Instrument filename accessor. -QString& qsamplerChannel::instrumentFile (void) +const QString& qsamplerChannel::instrumentFile (void) const { return m_sInstrumentFile; } // Instrument index accessor. -int qsamplerChannel::instrumentNr (void) +int qsamplerChannel::instrumentNr (void) const { return m_iInstrumentNr; } // Instrument name accessor. -QString& qsamplerChannel::instrumentName (void) +const QString& qsamplerChannel::instrumentName (void) const { return m_sInstrumentName; } // Instrument status accessor. -int qsamplerChannel::instrumentStatus (void) +int qsamplerChannel::instrumentStatus (void) const { return m_iInstrumentStatus; } @@ -214,7 +221,7 @@ appendMessages(QObject::tr("Instrument: \"%1\" (%2).") .arg(sInstrumentFile).arg(iInstrumentNr)); - + return setInstrument(sInstrumentFile, iInstrumentNr); } @@ -236,7 +243,7 @@ // MIDI driver type accessors (DEPRECATED). -QString& qsamplerChannel::midiDriver (void) +const QString& qsamplerChannel::midiDriver (void) const { return m_sMidiDriver; } @@ -261,7 +268,7 @@ // MIDI device accessors. -int qsamplerChannel::midiDevice (void) +int qsamplerChannel::midiDevice (void) const { return m_iMidiDevice; } @@ -286,7 +293,7 @@ // MIDI port number accessor. -int qsamplerChannel::midiPort (void) +int qsamplerChannel::midiPort (void) const { return m_iMidiPort; } @@ -311,7 +318,7 @@ // MIDI channel accessor. -int qsamplerChannel::midiChannel (void) +int qsamplerChannel::midiChannel (void) const { return m_iMidiChannel; } @@ -336,7 +343,7 @@ // Audio device accessor. -int qsamplerChannel::audioDevice (void) +int qsamplerChannel::audioDevice (void) const { return m_iAudioDevice; } @@ -361,7 +368,7 @@ // Audio driver type accessors (DEPRECATED). -QString& qsamplerChannel::audioDriver (void) +const QString& qsamplerChannel::audioDriver (void) const { return m_sAudioDriver; } @@ -386,7 +393,7 @@ // Channel volume accessors. -float qsamplerChannel::volume (void) +float qsamplerChannel::volume (void) const { return m_fVolume; } @@ -410,6 +417,94 @@ } +// Sampler channel mute state. +bool qsamplerChannel::channelMute (void) const +{ + return m_bMute; +} + +bool qsamplerChannel::setChannelMute ( bool bMute ) +{ + if (client() == NULL || m_iChannelID < 0) + return false; + if (m_iInstrumentStatus == 100 && ((m_bMute && bMute) || (!m_bMute && !bMute))) + return true; + +#ifdef CONFIG_MUTE_SOLO + if (::lscp_set_channel_mute(client(), m_iChannelID, bMute) != LSCP_OK) { + appendMessagesClient("lscp_set_channel_mute"); + return false; + } + appendMessages(QObject::tr("Mute: %1.").arg((int) bMute)); + m_bMute = bMute; + return true; +#else + return false; +#endif +} + + +// Sampler channel solo state. +bool qsamplerChannel::channelSolo (void) const +{ + return m_bSolo; +} + +bool qsamplerChannel::setChannelSolo ( bool bSolo ) +{ + if (client() == NULL || m_iChannelID < 0) + return false; + if (m_iInstrumentStatus == 100 && ((m_bSolo && bSolo) || (!m_bSolo && !bSolo))) + return true; + +#ifdef CONFIG_MUTE_SOLO + if (::lscp_set_channel_solo(client(), m_iChannelID, bSolo) != LSCP_OK) { + appendMessagesClient("lscp_set_channel_solo"); + return false; + } + appendMessages(QObject::tr("Solo: %1.").arg((int) bSolo)); + m_bSolo = bSolo; + return true; +#else + return false; +#endif +} + + +// Audio routing accessors. +int qsamplerChannel::audioChannel ( int iAudioOut ) const +{ + return m_audioRouting[iAudioOut]; +} + +bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn ) +{ + if (client() == NULL || m_iChannelID < 0) + return false; + if (m_iInstrumentStatus == 100 && + m_audioRouting[iAudioOut] == iAudioIn) + return true; + + if (::lscp_set_channel_audio_channel(client(), + m_iChannelID, iAudioOut, iAudioIn) != LSCP_OK) { + appendMessagesClient("lscp_set_channel_audio_channel"); + return false; + } + + appendMessages(QObject::tr("Audio Channel: %1 -> %2.") + .arg(iAudioOut).arg(iAudioIn)); + + m_audioRouting[iAudioOut] = iAudioIn; + return true; +} + +// The audio routing map itself. +const qsamplerChannelRoutingMap& qsamplerChannel::audioRouting (void) const +{ + return m_audioRouting; +} + + // Istrument name remapper. void qsamplerChannel::updateInstrumentName (void) { @@ -458,6 +553,10 @@ m_iMidiChannel = pChannelInfo->midi_channel; m_iAudioDevice = pChannelInfo->audio_device; m_fVolume = pChannelInfo->volume; +#ifdef CONFIG_MUTE_SOLO + m_bMute = pChannelInfo->mute; + m_bSolo = pChannelInfo->solo; +#endif // Some sanity checks. if (m_sEngineName == "NONE" || m_sEngineName.isEmpty()) m_sEngineName = QString::null; @@ -465,8 +564,8 @@ m_sInstrumentFile = QString::null; m_sInstrumentName = QString::null; } - - // FIXME: DEPRECATED... + + // Time for device info grabbing... lscp_device_info_t *pDeviceInfo; const QString sNone = QObject::tr("(none)"); // Audio device driver type. @@ -486,6 +585,13 @@ m_sMidiDriver = pDeviceInfo->driver; } + // Set the audio routing map. + m_audioRouting.clear(); + char **ppszRouting = pChannelInfo->audio_routing; + for (int i = 0; ppszRouting && ppszRouting[i]; i++) { + m_audioRouting[i] = ::atoi(ppszRouting[i]); + } + return true; } @@ -513,7 +619,7 @@ bool bResult = false; appendMessages(QObject::tr("setup...")); - + qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent); if (pChannelForm) { pChannelForm->setup(this); @@ -526,31 +632,32 @@ // Redirected messages output methods. -void qsamplerChannel::appendMessages( const QString& s ) +void qsamplerChannel::appendMessages( const QString& s ) const { if (m_pMainForm) m_pMainForm->appendMessages(channelName() + ' ' + s); } -void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c ) +void qsamplerChannel::appendMessagesColor( const QString& s, + const QString& c ) const { if (m_pMainForm) m_pMainForm->appendMessagesColor(channelName() + ' ' + s, c); } -void qsamplerChannel::appendMessagesText( const QString& s ) +void qsamplerChannel::appendMessagesText( const QString& s ) const { if (m_pMainForm) m_pMainForm->appendMessagesText(channelName() + ' ' + s); } -void qsamplerChannel::appendMessagesError( const QString& s ) +void qsamplerChannel::appendMessagesError( const QString& s ) const { if (m_pMainForm) m_pMainForm->appendMessagesError(channelName() + "\n\n" + s); } -void qsamplerChannel::appendMessagesClient( const QString& s ) +void qsamplerChannel::appendMessagesClient( const QString& s ) const { if (m_pMainForm) m_pMainForm->appendMessagesClient(channelName() + ' ' + s); @@ -594,7 +701,7 @@ if (isInstrumentFile(sInstrumentFile)) { #ifdef CONFIG_LIBGIG if (bInstrumentNames) { - RIFF::File *pRiff = new RIFF::File(sInstrumentFile); + RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); gig::File *pGig = new gig::File(pRiff); gig::Instrument *pInstrument = pGig->GetFirstInstrument(); while (pInstrument) { @@ -625,7 +732,7 @@ sInstrumentName = QFileInfo(sInstrumentFile).fileName(); #ifdef CONFIG_LIBGIG if (bInstrumentNames) { - RIFF::File *pRiff = new RIFF::File(sInstrumentFile); + RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); gig::File *pGig = new gig::File(pRiff); int iIndex = 0; gig::Instrument *pInstrument = pGig->GetFirstInstrument(); @@ -661,5 +768,101 @@ return QObject::tr("(No instrument)"); } +QString qsamplerChannel::loadingInstrument (void) { + return QObject::tr("(Loading instrument...)"); +} + + + +//------------------------------------------------------------------------- +// qsamplerChannelRoutingTable - Channel routing table. +// + +// Constructor. +qsamplerChannelRoutingTable::qsamplerChannelRoutingTable ( + QWidget *pParent, const char *pszName ) + : QTable(pParent, pszName) +{ + // Set fixed number of columns. + QTable::setNumCols(2); + QTable::setShowGrid(false); + QTable::setSorting(false); + QTable::setFocusStyle(QTable::FollowStyle); + QTable::setSelectionMode(QTable::SingleRow); + // No vertical header. + QTable::verticalHeader()->hide(); + QTable::setLeftMargin(0); + // Initialize the fixed table column headings. + QHeader *pHeader = QTable::horizontalHeader(); + pHeader->setLabel(0, tr("Sampler Channel")); + pHeader->setLabel(1, tr("Device Channel")); + // Set read-onlyness of each column + QTable::setColumnReadOnly(0, true); +// QTable::setColumnReadOnly(1, false); -- of course not. + QTable::setColumnStretchable(1, true); +} + +// Default destructor. +qsamplerChannelRoutingTable::~qsamplerChannelRoutingTable (void) +{ +} + + +// Routing map table renderer. +void qsamplerChannelRoutingTable::refresh ( qsamplerDevice *pDevice, + const qsamplerChannelRoutingMap& routing ) +{ + if (pDevice == NULL) + return; + + // Always (re)start it empty. + QTable::setUpdatesEnabled(false); + QTable::setNumRows(0); + + // The common device port item list. + QStringList opts; + qsamplerDevicePortList& ports = pDevice->ports(); + qsamplerDevicePort *pPort; + for (pPort = ports.first(); pPort; pPort = ports.next()) { + opts.append(pDevice->deviceTypeName() + + ' ' + pDevice->driverName() + + ' ' + pPort->portName()); + } + + // Those items shall have a proper pixmap... + QPixmap pmDevice; + switch (pDevice->deviceType()) { + case qsamplerDevice::Audio: + pmDevice = QPixmap::fromMimeSource("audio2.png"); + break; + case qsamplerDevice::Midi: + pmDevice = QPixmap::fromMimeSource("midi2.png"); + break; + case qsamplerDevice::None: + break; + } + + // Fill the routing table... + QTable::insertRows(0, routing.count()); + int iRow = 0; + qsamplerChannelRoutingMap::ConstIterator iter; + for (iter = routing.begin(); iter != routing.end(); ++iter) { + QTable::setPixmap(iRow, 0, pmDevice); + QTable::setText(iRow, 0, pDevice->deviceTypeName() + + ' ' + QString::number(iter.key())); + QComboTableItem *pComboItem = new QComboTableItem(this, opts); + pComboItem->setCurrentItem(iter.data()); + QTable::setItem(iRow, 1, pComboItem); + ++iRow; + } + + // Adjust optimal column widths. + QTable::adjustColumn(0); + QTable::adjustColumn(1); + + QTable::setUpdatesEnabled(true); + QTable::updateContents(); +} + // end of qsamplerChannel.cpp