--- qsampler/trunk/src/qsamplerChannel.cpp 2007/11/19 03:29:57 1489 +++ qsampler/trunk/src/qsamplerChannel.cpp 2007/11/22 14:17:24 1510 @@ -20,15 +20,15 @@ *****************************************************************************/ -#include "qsamplerUtilities.h" #include "qsamplerAbout.h" #include "qsamplerChannel.h" +#include "qsamplerUtilities.h" #include "qsamplerMainForm.h" #include "qsamplerChannelForm.h" -#include -#include +#include +#include #ifdef CONFIG_LIBGIG #include "gig.h" @@ -36,6 +36,9 @@ #define QSAMPLER_INSTRUMENT_MAX 100 +#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21)) + + using namespace QSampler; //------------------------------------------------------------------------- @@ -59,7 +62,7 @@ m_iMidiMap = -1; m_sAudioDriver = "ALSA"; m_iAudioDevice = -1; - m_fVolume = 0.0; + m_fVolume = 0.0f; m_bMute = false; m_bSolo = false; } @@ -156,7 +159,8 @@ if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName) return true; - if (::lscp_load_engine(pMainForm->client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { + if (::lscp_load_engine(pMainForm->client(), + sEngineName.toUtf8().constData(), m_iChannelID) != LSCP_OK) { appendMessagesClient("lscp_load_engine"); return false; } @@ -208,7 +212,8 @@ if ( ::lscp_load_instrument_non_modal( pMainForm->client(), - qsamplerUtilities::lscpEscapePath(sInstrumentFile).latin1(), + qsamplerUtilities::lscpEscapePath( + sInstrumentFile).toUtf8().constData(), iInstrumentNr, m_iChannelID ) != LSCP_OK ) { @@ -255,7 +260,8 @@ if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver) return true; - if (::lscp_set_channel_midi_type(pMainForm->client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { + if (::lscp_set_channel_midi_type(pMainForm->client(), + m_iChannelID, sMidiDriver.toUtf8().constData()) != LSCP_OK) { appendMessagesClient("lscp_set_channel_midi_type"); return false; } @@ -423,7 +429,8 @@ if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver) return true; - if (::lscp_set_channel_audio_type(pMainForm->client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { + if (::lscp_set_channel_audio_type(pMainForm->client(), + m_iChannelID, sAudioDriver.toUtf8().constData()) != LSCP_OK) { appendMessagesClient("lscp_set_channel_audio_type"); return false; } @@ -802,9 +809,9 @@ bool bResult = false; QFile file(sInstrumentFile); - if (file.open(IO_ReadOnly)) { + if (file.open(QIODevice::ReadOnly)) { char achHeader[16]; - if (file.readBlock(achHeader, 16)) { + if (file.read(achHeader, 16) > 0) { bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0 && ::memcmp(&achHeader[8], "DLS LIST", 8) == 0); } @@ -825,7 +832,8 @@ if (isInstrumentFile(sInstrumentFile)) { #ifdef CONFIG_LIBGIG if (bInstrumentNames) { - RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); + RIFF::File *pRiff + = new RIFF::File(sInstrumentFile.toUtf8().constData()); gig::File *pGig = new gig::File(pRiff); gig::Instrument *pInstrument = pGig->GetFirstInstrument(); while (pInstrument) { @@ -856,8 +864,9 @@ sInstrumentName = QFileInfo(sInstrumentFile).fileName(); #ifdef CONFIG_LIBGIG if (bInstrumentNames) { - RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); - gig::File *pGig = new gig::File(pRiff); + RIFF::File *pRiff + = new RIFF::File(sInstrumentFile.toUtf8().constData()); + gig::File *pGig = new gig::File(pRiff); int iIndex = 0; gig::Instrument *pInstrument = pGig->GetFirstInstrument(); while (pInstrument) { @@ -901,79 +910,97 @@ // ChannelRoutingModel - data model for audio routing (used for QTableView) // -ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) { +ChannelRoutingModel::ChannelRoutingModel ( QObject *pParent ) + : QAbstractTableModel(pParent), m_pDevice(NULL) +{ } -int ChannelRoutingModel::rowCount(const QModelIndex& /*parent*/) const { - return routing.size(); + +int ChannelRoutingModel::rowCount ( const QModelIndex& /*parent*/) const +{ + return m_routing.size(); } -int ChannelRoutingModel::columnCount(const QModelIndex& /*parent*/) const { - return 1; + +int ChannelRoutingModel::columnCount ( const QModelIndex& /*parent*/) const +{ + return 1; } -Qt::ItemFlags ChannelRoutingModel::flags(const QModelIndex& /*index*/) const { - return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; + +Qt::ItemFlags ChannelRoutingModel::flags ( const QModelIndex& /*index*/) const +{ + return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; } -bool ChannelRoutingModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { - if (!index.isValid()) { - return false; - } - routing[index.row()] = value.toInt(); +bool ChannelRoutingModel::setData ( const QModelIndex& index, + const QVariant& value, int /*role*/) +{ + if (!index.isValid()) + return false; - emit dataChanged(index, index); - return true; -} + m_routing[index.row()] = value.toInt(); -QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const { - if (!index.isValid()) - return QVariant(); - if (role != Qt::DisplayRole) - return QVariant(); - if (index.column() != 0) - return QVariant(); + emit dataChanged(index, index); + return true; +} - 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() - ); - } +QVariant ChannelRoutingModel::data ( const QModelIndex &index, int role ) const +{ + if (!index.isValid()) + return QVariant(); + if (role != Qt::DisplayRole) + return QVariant(); + if (index.column() != 0) + return QVariant(); + + ChannelRoutingItem item; + + // The common device port item list. + qsamplerDevicePortList& ports = m_pDevice->ports(); + QListIterator iter(ports); + while (iter.hasNext()) { + qsamplerDevicePort *pPort = iter.next(); + item.options.append( + m_pDevice->deviceTypeName() + + ' ' + m_pDevice->driverName() + + ' ' + pPort->portName() + ); + } - item.selection = routing[index.row()]; + item.selection = m_routing[index.row()]; - return QVariant::fromValue(item); + return QVariant::fromValue(item); } -QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const { - if (role != Qt::DisplayRole) return QVariant(); - switch (orientation) { - case Qt::Horizontal: - return QObject::tr("-> Device Channel"); - case Qt::Vertical: - return QObject::tr("Sampler Channel ") + - QString::number(section) + " ->"; - default: - return QVariant(); - } +QVariant ChannelRoutingModel::headerData ( int section, + Qt::Orientation orientation, int role) const +{ + if (role != Qt::DisplayRole) + return QVariant(); + + switch (orientation) { + case Qt::Horizontal: + return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel"); + case Qt::Vertical: + return QObject::tr("Sampler Channel ") + + QString::number(section) + " " + UNICODE_RIGHT_ARROW; + default: + return QVariant(); + } } + void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice, const qsamplerChannelRoutingMap& routing ) { - this->pDevice = pDevice; - this->routing = routing; - // inform the outer world (QTableView) that our data changed - QAbstractTableModel::reset(); + m_pDevice = pDevice; + m_routing = routing; + // inform the outer world (QTableView) that our data changed + QAbstractTableModel::reset(); } @@ -981,46 +1008,55 @@ // ChannelRoutingDelegate - table cell renderer for audio routing // -ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) { +ChannelRoutingDelegate::ChannelRoutingDelegate ( QObject *pParent ) + : QItemDelegate(pParent) +{ } -QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent, - const QStyleOptionViewItem & option , - const QModelIndex& index) const + +QWidget* ChannelRoutingDelegate::createEditor ( QWidget *pParent, + const QStyleOptionViewItem & option, const QModelIndex& index ) const { - if (!index.isValid()) { - return NULL; - } + if (!index.isValid()) + return NULL; - if (index.column() != 0) { - return NULL; - } + if (index.column() != 0) + return NULL; - ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value(); + ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value(); - QComboBox* pComboBox = new QComboBox(parent); - pComboBox->addItems(item.options); - pComboBox->setCurrentIndex(item.selection); - pComboBox->setEnabled(true); - pComboBox->setGeometry(option.rect); - return pComboBox; + QComboBox* pComboBox = new QComboBox(pParent); + pComboBox->addItems(item.options); + pComboBox->setCurrentIndex(item.selection); + pComboBox->setEnabled(true); + pComboBox->setGeometry(option.rect); + return pComboBox; } -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::setEditorData ( QWidget *pEditor, + const QModelIndex &index) const +{ + ChannelRoutingItem item = index.model()->data(index, + Qt::DisplayRole).value (); + QComboBox* pComboBox = static_cast (pEditor); + pComboBox->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::setModelData ( QWidget* pEditor, + QAbstractItemModel *pModel, const QModelIndex& index ) const +{ + QComboBox *pComboBox = static_cast (pEditor); + pModel->setData(index, pComboBox->currentIndex()); } -void ChannelRoutingDelegate::updateEditorGeometry(QWidget *editor, - const QStyleOptionViewItem &option, const QModelIndex &/* index */) const + +void ChannelRoutingDelegate::updateEditorGeometry ( QWidget *pEditor, + const QStyleOptionViewItem& option, const QModelIndex &/* index */) const { - editor->setGeometry(option.rect); + pEditor->setGeometry(option.rect); } + // end of qsamplerChannel.cpp