--- qsampler/trunk/src/qsamplerChannel.cpp 2007/01/11 16:14:31 1022 +++ qsampler/trunk/src/qsamplerChannel.cpp 2007/11/01 17:49:27 1465 @@ -2,6 +2,7 @@ // /**************************************************************************** Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. + Copyright (C) 2007, Christian Schoenebeck This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License @@ -19,6 +20,7 @@ *****************************************************************************/ +#include "qsamplerUtilities.h" #include "qsamplerAbout.h" #include "qsamplerChannel.h" @@ -34,6 +36,7 @@ #define QSAMPLER_INSTRUMENT_MAX 100 +using namespace QSampler; //------------------------------------------------------------------------- // qsamplerChannel - Sampler channel structure. @@ -70,7 +73,7 @@ // Create a new sampler channel, if not already. bool qsamplerChannel::addChannel (void) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm* pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL) @@ -95,7 +98,7 @@ // Remove sampler channel. bool qsamplerChannel::removeChannel (void) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL) @@ -145,7 +148,7 @@ bool qsamplerChannel::loadEngine ( const QString& sEngineName ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -192,7 +195,7 @@ // Instrument file loader. bool qsamplerChannel::loadInstrument ( const QString& sInstrumentFile, int iInstrumentNr ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -202,7 +205,13 @@ if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr) return true; - if (::lscp_load_instrument_non_modal(pMainForm->client(), sInstrumentFile.latin1(), iInstrumentNr, m_iChannelID) != LSCP_OK) { + if ( + ::lscp_load_instrument_non_modal( + pMainForm->client(), + qsamplerUtilities::lscpEscapePath(sInstrumentFile).latin1(), + iInstrumentNr, m_iChannelID + ) != LSCP_OK + ) { appendMessagesClient("lscp_load_instrument"); return false; } @@ -238,7 +247,7 @@ bool qsamplerChannel::setMidiDriver ( const QString& sMidiDriver ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -266,7 +275,7 @@ bool qsamplerChannel::setMidiDevice ( int iMidiDevice ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -294,7 +303,7 @@ bool qsamplerChannel::setMidiPort ( int iMidiPort ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -322,7 +331,7 @@ bool qsamplerChannel::setMidiChannel ( int iMidiChannel ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -350,7 +359,7 @@ bool qsamplerChannel::setMidiMap ( int iMidiMap ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -378,7 +387,7 @@ bool qsamplerChannel::setAudioDevice ( int iAudioDevice ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -406,7 +415,7 @@ bool qsamplerChannel::setAudioDriver ( const QString& sAudioDriver ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -434,7 +443,7 @@ bool qsamplerChannel::setVolume ( float fVolume ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -462,7 +471,7 @@ bool qsamplerChannel::setChannelMute ( bool bMute ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -492,7 +501,7 @@ bool qsamplerChannel::setChannelSolo ( bool bSolo ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -522,7 +531,7 @@ bool qsamplerChannel::setAudioChannel ( int iAudioOut, int iAudioIn ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -564,7 +573,7 @@ // Update whole channel info state. bool qsamplerChannel::updateChannelInfo (void) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -580,9 +589,11 @@ #ifdef CONFIG_INSTRUMENT_NAME // We got all actual instrument datum... - m_sInstrumentFile = pChannelInfo->instrument_file; + m_sInstrumentFile = + qsamplerUtilities::lscpEscapedPathToPosix(pChannelInfo->instrument_file); m_iInstrumentNr = pChannelInfo->instrument_nr; - m_sInstrumentName = pChannelInfo->instrument_name; + m_sInstrumentName = + qsamplerUtilities::lscpEscapedTextToRaw(pChannelInfo->instrument_name); #else // First, check if intrument name has changed, // taking care that instrument name lookup might be expensive, @@ -656,7 +667,7 @@ // Reset channel method. bool qsamplerChannel::channelReset (void) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -673,10 +684,53 @@ } +// Spawn instrument editor method. +bool qsamplerChannel::editChannel (void) +{ +#ifdef CONFIG_EDIT_INSTRUMENT + + MainForm *pMainForm = MainForm::getInstance(); + if (pMainForm == NULL) + return false; + if (pMainForm->client() == NULL || m_iChannelID < 0) + return false; + + if (::lscp_edit_channel_instrument(pMainForm->client(), m_iChannelID) + != LSCP_OK) { + appendMessagesClient("lscp_edit_channel_instrument"); + appendMessagesError(QObject::tr( + "Could not launch an appropriate instrument editor " + "for the given instrument!\n" + "Make sure you have an appropriate " + "instrument editor like 'gigedit' installed\n" + "and that it placed its mandatory DLL file " + "into the sampler's plugin directory.") + ); + return false; + } + + appendMessages(QObject::tr("edit instrument.")); + + return true; + +#else + + appendMessagesError(QObject::tr( + "Sorry, QSampler was compiled for a version of liblscp " + "which lacks this feature.\n" + "You may want to update liblscp and recompile QSampler afterwards.") + ); + + return false; + +#endif +} + + // Channel setup dialog form. bool qsamplerChannel::channelSetup ( QWidget *pParent ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; @@ -684,7 +738,7 @@ appendMessages(QObject::tr("setup...")); - qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent); + ChannelForm *pChannelForm = new ChannelForm(pParent); if (pChannelForm) { pChannelForm->setup(this); bResult = pChannelForm->exec(); @@ -698,7 +752,7 @@ // Redirected messages output methods. void qsamplerChannel::appendMessages( const QString& s ) const { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm) pMainForm->appendMessages(channelName() + ' ' + s); } @@ -706,28 +760,28 @@ void qsamplerChannel::appendMessagesColor( const QString& s, const QString& c ) const { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm) pMainForm->appendMessagesColor(channelName() + ' ' + s, c); } void qsamplerChannel::appendMessagesText( const QString& s ) const { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm) pMainForm->appendMessagesText(channelName() + ' ' + s); } void qsamplerChannel::appendMessagesError( const QString& s ) const { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm) pMainForm->appendMessagesError(channelName() + "\n\n" + s); } void qsamplerChannel::appendMessagesClient( const QString& s ) const { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm) pMainForm->appendMessagesClient(channelName() + ' ' + s); } @@ -736,7 +790,7 @@ // Context menu event handler. void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm) pMainForm->contextMenuEvent(pEvent); } @@ -847,7 +901,7 @@ //------------------------------------------------------------------------- // qsamplerChannelRoutingTable - Channel routing table. // - +#if 0 // Constructor. qsamplerChannelRoutingTable::qsamplerChannelRoutingTable ( QWidget *pParent, const char *pszName ) @@ -900,14 +954,14 @@ } // Those items shall have a proper pixmap... - QPixmap pmChannel = QPixmap::fromMimeSource("qsamplerChannel.png"); + QPixmap pmChannel = QPixmap(":/icons/qsamplerChannel.png"); QPixmap pmDevice; switch (pDevice->deviceType()) { case qsamplerDevice::Audio: - pmDevice = QPixmap::fromMimeSource("audio2.png"); + pmDevice = QPixmap(":/icons/audio2.png"); break; case qsamplerDevice::Midi: - pmDevice = QPixmap::fromMimeSource("midi2.png"); + pmDevice = QPixmap(":/icons/midi2.png"); break; case qsamplerDevice::None: break; @@ -943,12 +997,106 @@ if (QTable::isEditing()) QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true); } +#endif + +ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) { +} + +int ChannelRoutingModel::rowCount(const QModelIndex& /*parent*/) const { + return routing.size(); +} + +int ChannelRoutingModel::columnCount(const QModelIndex& /*parent*/) const { + return 1; +} + +QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const { + if (!index.isValid()) + return QVariant(); + if (role != Qt::DisplayRole) + return QVariant(); + + ChannelRoutingItem item; + + // The common device port item list. + qsamplerDevicePortList& ports = pDevice->ports(); + qsamplerDevicePort* pPort; + for (pPort = ports.first(); pPort; pPort = ports.next()) { + item.options.append( + pDevice->deviceTypeName() + + ' ' + pDevice->driverName() + + ' ' + pPort->portName() + ); + } + + item.selection = routing[index.column()]; + + return QVariant::fromValue(item); +} + +QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const { + if (role != Qt::DisplayRole) return QVariant(); + + if (orientation == Qt::Horizontal) + return QObject::tr("Device Channel"); + + if (orientation == Qt::Vertical) + return QObject::tr("Sampler Channel Output ") + + QString(section); + + return QVariant(); +} + +void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice, + const qsamplerChannelRoutingMap& routing ) +{ + this->pDevice = pDevice; + this->routing = routing; +} + + + + +ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) { +} + +QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent, + const QStyleOptionViewItem &/* option */, + const QModelIndex& index) const +{ + ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value(); + + QComboBox* editor = new QComboBox(parent); + editor->addItems(item.options); + editor->setCurrentIndex(item.selection); + editor->installEventFilter(const_cast(this)); + return editor; +} + +void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { + ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value(); + QComboBox* comboBox = static_cast(editor); + comboBox->setCurrentIndex(item.selection); +} + +void ChannelRoutingDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { + QComboBox* comboBox = static_cast(editor); + model->setData(index, comboBox->currentIndex()); +} + +void ChannelRoutingDelegate::updateEditorGeometry(QWidget *editor, + const QStyleOptionViewItem &option, const QModelIndex &/* index */) const +{ + editor->setGeometry(option.rect); +} + //------------------------------------------------------------------------- // qsamplerChannelRoutingComboBox - Custom combo box for routing table. // +#if 0 // Constructor. qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox ( QTable *pTable, const QStringList& list, const QPixmap& pixmap ) @@ -995,5 +1143,7 @@ else QTableItem::setContentFromEditor(pWidget); } +#endif + // end of qsamplerChannel.cpp