--- qsampler/trunk/src/qsamplerChannel.cpp 2007/10/27 12:28:33 1460 +++ qsampler/trunk/src/qsamplerChannel.cpp 2007/10/28 23:30:36 1461 @@ -35,6 +35,7 @@ #define QSAMPLER_INSTRUMENT_MAX 100 +using namespace QSampler; //------------------------------------------------------------------------- // qsamplerChannel - Sampler channel structure. @@ -71,7 +72,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) @@ -96,7 +97,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) @@ -146,7 +147,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) @@ -193,7 +194,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) @@ -245,7 +246,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) @@ -273,7 +274,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) @@ -301,7 +302,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) @@ -329,7 +330,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) @@ -357,7 +358,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) @@ -385,7 +386,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) @@ -413,7 +414,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) @@ -441,7 +442,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) @@ -469,7 +470,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) @@ -499,7 +500,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) @@ -529,7 +530,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) @@ -571,7 +572,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) @@ -665,7 +666,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) @@ -687,7 +688,7 @@ { #ifdef CONFIG_EDIT_INSTRUMENT - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; if (pMainForm->client() == NULL || m_iChannelID < 0) @@ -728,7 +729,7 @@ // Channel setup dialog form. bool qsamplerChannel::channelSetup ( QWidget *pParent ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm == NULL) return false; @@ -736,7 +737,7 @@ appendMessages(QObject::tr("setup...")); - qsamplerChannelForm *pChannelForm = new qsamplerChannelForm(pParent); + ChannelForm *pChannelForm = new ChannelForm(pParent); if (pChannelForm) { pChannelForm->setup(this); bResult = pChannelForm->exec(); @@ -750,7 +751,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); } @@ -758,28 +759,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); } @@ -788,7 +789,7 @@ // Context menu event handler. void qsamplerChannel::contextMenuEvent( QContextMenuEvent *pEvent ) { - qsamplerMainForm *pMainForm = qsamplerMainForm::getInstance(); + MainForm *pMainForm = MainForm::getInstance(); if (pMainForm) pMainForm->contextMenuEvent(pEvent); } @@ -899,7 +900,7 @@ //------------------------------------------------------------------------- // qsamplerChannelRoutingTable - Channel routing table. // - +#if 0 // Constructor. qsamplerChannelRoutingTable::qsamplerChannelRoutingTable ( QWidget *pParent, const char *pszName ) @@ -995,12 +996,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 ) @@ -1047,5 +1142,4 @@ else QTableItem::setContentFromEditor(pWidget); } - -// end of qsamplerChannel.cpp +#endif