--- qsampler/trunk/src/qsamplerChannel.cpp 2005/02/11 15:36:06 371 +++ qsampler/trunk/src/qsamplerChannel.cpp 2005/02/24 12:10:54 409 @@ -45,8 +45,8 @@ m_pMainForm = pMainForm; m_iChannelID = iChannelID; -// m_sEngineName = QObject::tr("(No engine)"); -// m_sInstrumentName = QObject::tr("(No instrument)"); +// m_sEngineName = noEngineName(); +// m_sInstrumentName = noInstrumentName(); // m_sInstrumentFile = m_sInstrumentName; m_iInstrumentNr = -1; m_iInstrumentStatus = -1; @@ -97,9 +97,9 @@ m_iChannelID = ::lscp_add_channel(client()); if (m_iChannelID < 0) { appendMessagesClient("lscp_add_channel"); - appendMessagesError(QObject::tr("Could not create the new channel.\n\nSorry.")); + appendMessagesError(QObject::tr("Could not add channel.\n\nSorry.")); } // Otherwise it's created... - else appendMessages(QObject::tr("Channel %1 created.").arg(m_iChannelID)); + else appendMessages(QObject::tr("added.")); } // Return whether we're a valid channel... @@ -120,7 +120,7 @@ appendMessagesError(QObject::tr("Could not remove channel.\n\nSorry.")); } else { // Otherwise it's removed. - appendMessages(QObject::tr("Channel %1 removed.").arg(m_iChannelID)); + appendMessages(QObject::tr("removed.")); m_iChannelID = -1; } } @@ -159,23 +159,20 @@ { if (client() == NULL || m_iChannelID < 0) 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; } + appendMessages(QObject::tr("Engine: %1.").arg(sEngineName)); m_sEngineName = sEngineName; return true; } -// Instrument name accessor. -QString& qsamplerChannel::instrumentName (void) -{ - return m_sInstrumentName; -} - // Instrument filename accessor. QString& qsamplerChannel::instrumentFile (void) { @@ -188,6 +185,12 @@ return m_iInstrumentNr; } +// Instrument name accessor. +QString& qsamplerChannel::instrumentName (void) +{ + return m_sInstrumentName; +} + // Instrument status accessor. int qsamplerChannel::instrumentStatus (void) { @@ -199,18 +202,36 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (!isInstrumentFile(sInstrumentFile)) + return false; + if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr) + return true; if (::lscp_load_instrument_non_modal(client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { appendMessagesClient("lscp_load_instrument"); return false; } - m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true); + appendMessages(QObject::tr("Instrument: \"%1\" (%2).") + .arg(sInstrumentFile).arg(iInstrumentNr)); + + return setInstrument(sInstrumentFile, iInstrumentNr); +} + + +// Special instrument file/name/number settler. +bool qsamplerChannel::setInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) +{ m_sInstrumentFile = sInstrumentFile; m_iInstrumentNr = iInstrumentNr; +#ifdef CONFIG_INSTRUMENT_NAME + m_sInstrumentName = QString::null; // We'll get it, maybe later, on channel_info... +#else + m_sInstrumentName = getInstrumentName(sInstrumentFile, iInstrumentNr, true); +#endif m_iInstrumentStatus = 0; - return true; + return true; } @@ -224,12 +245,16 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver) + return true; if (::lscp_set_channel_midi_type(client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { appendMessagesClient("lscp_set_channel_midi_type"); return false; } + appendMessages(QObject::tr("MIDI driver: %1.").arg(sMidiDriver)); + m_sMidiDriver = sMidiDriver; return true; } @@ -245,12 +270,16 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_iMidiDevice == iMidiDevice) + return true; if (::lscp_set_channel_midi_device(client(), m_iChannelID, iMidiDevice) != LSCP_OK) { appendMessagesClient("lscp_set_channel_midi_device"); return false; } + appendMessages(QObject::tr("MIDI device: %1.").arg(iMidiDevice)); + m_iMidiDevice = iMidiDevice; return true; } @@ -266,12 +295,16 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_iMidiPort == iMidiPort) + return true; if (::lscp_set_channel_midi_port(client(), m_iChannelID, iMidiPort) != LSCP_OK) { appendMessagesClient("lscp_set_channel_midi_port"); return false; } + appendMessages(QObject::tr("MIDI port: %1.").arg(iMidiPort)); + m_iMidiPort = iMidiPort; return true; } @@ -287,12 +320,16 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_iMidiChannel == iMidiChannel) + return true; if (::lscp_set_channel_midi_channel(client(), m_iChannelID, iMidiChannel) != LSCP_OK) { appendMessagesClient("lscp_set_channel_midi_channel"); return false; } + appendMessages(QObject::tr("MIDI channel: %1.").arg(iMidiChannel)); + m_iMidiChannel = iMidiChannel; return true; } @@ -308,12 +345,16 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_iAudioDevice == iAudioDevice) + return true; if (::lscp_set_channel_audio_device(client(), m_iChannelID, iAudioDevice) != LSCP_OK) { appendMessagesClient("lscp_set_channel_audio_device"); return false; } + appendMessages(QObject::tr("Audio device: %1.").arg(iAudioDevice)); + m_iAudioDevice = iAudioDevice; return true; } @@ -329,12 +370,16 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver) + return true; if (::lscp_set_channel_audio_type(client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { appendMessagesClient("lscp_set_channel_audio_type"); return false; } + appendMessages(QObject::tr("Audio driver: %1.").arg(sAudioDriver)); + m_sAudioDriver = sAudioDriver; return true; } @@ -350,12 +395,16 @@ { if (client() == NULL || m_iChannelID < 0) return false; + if (m_iInstrumentStatus == 100 && m_fVolume == fVolume) + return true; if (::lscp_set_channel_volume(client(), m_iChannelID, fVolume) != LSCP_OK) { appendMessagesClient("lscp_set_channel_volume"); return false; } + appendMessages(QObject::tr("Volume: %1.").arg(fVolume)); + m_fVolume = fVolume; return true; } @@ -364,8 +413,10 @@ // Istrument name remapper. void qsamplerChannel::updateInstrumentName (void) { +#ifndef CONFIG_INSTRUMENT_NAME m_sInstrumentName = getInstrumentName(m_sInstrumentFile, m_iInstrumentNr, (options() && options()->bInstrumentNames)); +#endif } @@ -383,6 +434,12 @@ return false; } +#ifdef CONFIG_INSTRUMENT_NAME + // We got all actual instrument datum... + m_sInstrumentFile = pChannelInfo->instrument_file; + m_iInstrumentNr = pChannelInfo->instrument_nr; + m_sInstrumentName = pChannelInfo->instrument_name; +#else // First, check if intrument name has changed, // taking care that instrument name lookup might be expensive, // so we better make it only once and when really needed... @@ -392,6 +449,7 @@ m_iInstrumentNr = pChannelInfo->instrument_nr; updateInstrumentName(); } +#endif // Cache in other channel information. m_sEngineName = pChannelInfo->engine_name; m_iInstrumentStatus = pChannelInfo->instrument_status; @@ -413,7 +471,7 @@ // Reset channel method. -bool qsamplerChannel::resetChannel (void) +bool qsamplerChannel::channelReset (void) { if (client() == NULL || m_iChannelID < 0) return false; @@ -423,7 +481,8 @@ return false; } - appendMessages(QObject::tr("Channel %1 reset.").arg(m_iChannelID)); + appendMessages(QObject::tr("reset.")); + return true; } @@ -433,6 +492,8 @@ { bool bResult = false; + appendMessages(QObject::tr("setup...")); + qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent); if (pChannelForm) { pChannelForm->setup(this); @@ -447,34 +508,59 @@ // Redirected messages output methods. void qsamplerChannel::appendMessages( const QString& s ) { - if (m_pMainForm) m_pMainForm->appendMessages(s); + if (m_pMainForm) + m_pMainForm->appendMessages(channelName() + ' ' + s); } void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c ) { - if (m_pMainForm) m_pMainForm->appendMessagesColor(s, c); + if (m_pMainForm) + m_pMainForm->appendMessagesColor(channelName() + ' ' + s, c); } void qsamplerChannel::appendMessagesText( const QString& s ) { - if (m_pMainForm) m_pMainForm->appendMessagesText(s); + if (m_pMainForm) + m_pMainForm->appendMessagesText(channelName() + ' ' + s); } void qsamplerChannel::appendMessagesError( const QString& s ) { - if (m_pMainForm) m_pMainForm->appendMessagesError(s); + if (m_pMainForm) + m_pMainForm->appendMessagesError(channelName() + "\n\n" + s); } void qsamplerChannel::appendMessagesClient( const QString& s ) { - if (m_pMainForm) m_pMainForm->appendMessagesClient(s); + if (m_pMainForm) + m_pMainForm->appendMessagesClient(channelName() + ' ' + s); } // Context menu event handler. void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) { - if (m_pMainForm) m_pMainForm->contextMenuEvent(pEvent); + if (m_pMainForm) + m_pMainForm->contextMenuEvent(pEvent); +} + + +// FIXME: Check whether a given file is an instrument file. +bool qsamplerChannel::isInstrumentFile ( const QString& sInstrumentFile ) +{ + bool bResult = false; + + QFile file(sInstrumentFile); + if (file.open(IO_ReadOnly)) { + char achHeader[16]; + if (file.readBlock(achHeader, 16)) { + bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0 + && ::memcmp(&achHeader[8], "DLS LIST", 8) == 0); + } + file.close(); + } + + return bResult; } @@ -482,11 +568,10 @@ QStringList qsamplerChannel::getInstrumentList( const QString& sInstrumentFile, bool bInstrumentNames ) { - QFileInfo fileinfo(sInstrumentFile); - QString sInstrumentName = fileinfo.fileName(); + QString sInstrumentName = QFileInfo(sInstrumentFile).fileName(); QStringList instlist; - if (fileinfo.exists()) { + if (isInstrumentFile(sInstrumentFile)) { #ifdef CONFIG_LIBGIG if (bInstrumentNames) { RIFF::File *pRiff = new RIFF::File(sInstrumentFile); @@ -504,7 +589,7 @@ for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); } - else instlist.append(sInstrumentName); + else instlist.append(noInstrumentName()); return instlist; } @@ -514,10 +599,10 @@ QString qsamplerChannel::getInstrumentName( const QString& sInstrumentFile, int iInstrumentNr, bool bInstrumentNames ) { - QFileInfo fileinfo(sInstrumentFile); - QString sInstrumentName = fileinfo.fileName(); + QString sInstrumentName; - if (fileinfo.exists()) { + if (isInstrumentFile(sInstrumentFile)) { + sInstrumentName = QFileInfo(sInstrumentFile).fileName(); #ifdef CONFIG_LIBGIG if (bInstrumentNames) { RIFF::File *pRiff = new RIFF::File(sInstrumentFile); @@ -539,9 +624,22 @@ #endif sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; } + else sInstrumentName = noInstrumentName(); return sInstrumentName; } +// Common invalid name-helpers. +QString qsamplerChannel::noEngineName (void) +{ + return QObject::tr("(No engine)"); +} + +QString qsamplerChannel::noInstrumentName (void) +{ + return QObject::tr("(No instrument)"); +} + + // end of qsamplerChannel.cpp