2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
|
Copyright (C) 2007, Christian Schoenebeck |
6 |
|
|
7 |
This program is free software; you can redistribute it and/or |
This program is free software; you can redistribute it and/or |
8 |
modify it under the terms of the GNU General Public License |
modify it under the terms of the GNU General Public License |
20 |
|
|
21 |
*****************************************************************************/ |
*****************************************************************************/ |
22 |
|
|
|
#include "qsamplerUtilities.h" |
|
23 |
#include "qsamplerAbout.h" |
#include "qsamplerAbout.h" |
24 |
#include "qsamplerChannel.h" |
#include "qsamplerChannel.h" |
25 |
|
#include "qsamplerUtilities.h" |
26 |
|
|
27 |
#include "qsamplerMainForm.h" |
#include "qsamplerMainForm.h" |
28 |
#include "qsamplerChannelForm.h" |
#include "qsamplerChannelForm.h" |
29 |
|
|
30 |
#include <qfileinfo.h> |
#include <QFileInfo> |
31 |
#include <qcombobox.h> |
#include <QComboBox> |
32 |
|
|
33 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
34 |
#include "gig.h" |
#include "gig.h" |
36 |
|
|
37 |
#define QSAMPLER_INSTRUMENT_MAX 100 |
#define QSAMPLER_INSTRUMENT_MAX 100 |
38 |
|
|
39 |
|
#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21)) |
40 |
|
|
41 |
|
|
42 |
using namespace QSampler; |
using namespace QSampler; |
43 |
|
|
44 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
159 |
if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName) |
if (m_iInstrumentStatus == 100 && m_sEngineName == sEngineName) |
160 |
return true; |
return true; |
161 |
|
|
162 |
if (::lscp_load_engine(pMainForm->client(), sEngineName.latin1(), m_iChannelID) != LSCP_OK) { |
if (::lscp_load_engine(pMainForm->client(), |
163 |
|
sEngineName.toUtf8().constData(), m_iChannelID) != LSCP_OK) { |
164 |
appendMessagesClient("lscp_load_engine"); |
appendMessagesClient("lscp_load_engine"); |
165 |
return false; |
return false; |
166 |
} |
} |
212 |
if ( |
if ( |
213 |
::lscp_load_instrument_non_modal( |
::lscp_load_instrument_non_modal( |
214 |
pMainForm->client(), |
pMainForm->client(), |
215 |
qsamplerUtilities::lscpEscapePath(sInstrumentFile).latin1(), |
qsamplerUtilities::lscpEscapePath( |
216 |
|
sInstrumentFile).toUtf8().constData(), |
217 |
iInstrumentNr, m_iChannelID |
iInstrumentNr, m_iChannelID |
218 |
) != LSCP_OK |
) != LSCP_OK |
219 |
) { |
) { |
260 |
if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver) |
if (m_iInstrumentStatus == 100 && m_sMidiDriver == sMidiDriver) |
261 |
return true; |
return true; |
262 |
|
|
263 |
if (::lscp_set_channel_midi_type(pMainForm->client(), m_iChannelID, sMidiDriver.latin1()) != LSCP_OK) { |
if (::lscp_set_channel_midi_type(pMainForm->client(), |
264 |
|
m_iChannelID, sMidiDriver.toUtf8().constData()) != LSCP_OK) { |
265 |
appendMessagesClient("lscp_set_channel_midi_type"); |
appendMessagesClient("lscp_set_channel_midi_type"); |
266 |
return false; |
return false; |
267 |
} |
} |
429 |
if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver) |
if (m_iInstrumentStatus == 100 && m_sAudioDriver == sAudioDriver) |
430 |
return true; |
return true; |
431 |
|
|
432 |
if (::lscp_set_channel_audio_type(pMainForm->client(), m_iChannelID, sAudioDriver.latin1()) != LSCP_OK) { |
if (::lscp_set_channel_audio_type(pMainForm->client(), |
433 |
|
m_iChannelID, sAudioDriver.toUtf8().constData()) != LSCP_OK) { |
434 |
appendMessagesClient("lscp_set_channel_audio_type"); |
appendMessagesClient("lscp_set_channel_audio_type"); |
435 |
return false; |
return false; |
436 |
} |
} |
809 |
bool bResult = false; |
bool bResult = false; |
810 |
|
|
811 |
QFile file(sInstrumentFile); |
QFile file(sInstrumentFile); |
812 |
if (file.open(IO_ReadOnly)) { |
if (file.open(QIODevice::ReadOnly)) { |
813 |
char achHeader[16]; |
char achHeader[16]; |
814 |
if (file.readBlock(achHeader, 16)) { |
if (file.read(achHeader, 16) > 0) { |
815 |
bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0 |
bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0 |
816 |
&& ::memcmp(&achHeader[8], "DLS LIST", 8) == 0); |
&& ::memcmp(&achHeader[8], "DLS LIST", 8) == 0); |
817 |
} |
} |
832 |
if (isInstrumentFile(sInstrumentFile)) { |
if (isInstrumentFile(sInstrumentFile)) { |
833 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
834 |
if (bInstrumentNames) { |
if (bInstrumentNames) { |
835 |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); |
RIFF::File *pRiff |
836 |
|
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
837 |
gig::File *pGig = new gig::File(pRiff); |
gig::File *pGig = new gig::File(pRiff); |
838 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
839 |
while (pInstrument) { |
while (pInstrument) { |
864 |
sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
865 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
866 |
if (bInstrumentNames) { |
if (bInstrumentNames) { |
867 |
RIFF::File *pRiff = new RIFF::File(sInstrumentFile.latin1()); |
RIFF::File *pRiff |
868 |
gig::File *pGig = new gig::File(pRiff); |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
869 |
|
gig::File *pGig = new gig::File(pRiff); |
870 |
int iIndex = 0; |
int iIndex = 0; |
871 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
872 |
while (pInstrument) { |
while (pInstrument) { |
906 |
} |
} |
907 |
|
|
908 |
|
|
|
|
|
909 |
//------------------------------------------------------------------------- |
//------------------------------------------------------------------------- |
910 |
// qsamplerChannelRoutingTable - Channel routing table. |
// ChannelRoutingModel - data model for audio routing (used for QTableView) |
911 |
// |
// |
|
#if 0 |
|
|
// 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::NoSelection); |
|
|
// 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 pmChannel = QPixmap(":/icons/qsamplerChannel.png"); |
|
|
QPixmap pmDevice; |
|
|
switch (pDevice->deviceType()) { |
|
|
case qsamplerDevice::Audio: |
|
|
pmDevice = QPixmap(":/icons/audio2.png"); |
|
|
break; |
|
|
case qsamplerDevice::Midi: |
|
|
pmDevice = QPixmap(":/icons/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, pmChannel); |
|
|
QTable::setText(iRow, 0, pDevice->deviceTypeName() |
|
|
+ ' ' + QString::number(iter.key())); |
|
|
qsamplerChannelRoutingComboBox *pComboItem = |
|
|
new qsamplerChannelRoutingComboBox(this, opts, pmDevice); |
|
|
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(); |
|
|
} |
|
|
|
|
|
|
|
|
// Commit any pending editing. |
|
|
void qsamplerChannelRoutingTable::flush (void) |
|
|
{ |
|
|
if (QTable::isEditing()) |
|
|
QTable::endEdit(QTable::currEditRow(), QTable::currEditCol(), true, true); |
|
|
} |
|
|
#endif |
|
912 |
|
|
913 |
ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) { |
ChannelRoutingModel::ChannelRoutingModel(QObject* parent) : QAbstractTableModel(parent), pDevice(NULL) { |
914 |
} |
} |
921 |
return 1; |
return 1; |
922 |
} |
} |
923 |
|
|
924 |
|
Qt::ItemFlags ChannelRoutingModel::flags(const QModelIndex& /*index*/) const { |
925 |
|
return Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled; |
926 |
|
} |
927 |
|
|
928 |
|
bool ChannelRoutingModel::setData(const QModelIndex& index, const QVariant& value, int /*role*/) { |
929 |
|
if (!index.isValid()) { |
930 |
|
return false; |
931 |
|
} |
932 |
|
|
933 |
|
routing[index.row()] = value.toInt(); |
934 |
|
|
935 |
|
emit dataChanged(index, index); |
936 |
|
return true; |
937 |
|
} |
938 |
|
|
939 |
QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const { |
QVariant ChannelRoutingModel::data(const QModelIndex &index, int role) const { |
940 |
if (!index.isValid()) |
if (!index.isValid()) |
941 |
return QVariant(); |
return QVariant(); |
942 |
if (role != Qt::DisplayRole) |
if (role != Qt::DisplayRole) |
943 |
return QVariant(); |
return QVariant(); |
944 |
|
if (index.column() != 0) |
945 |
|
return QVariant(); |
946 |
|
|
947 |
ChannelRoutingItem item; |
ChannelRoutingItem item; |
948 |
|
|
949 |
// The common device port item list. |
// The common device port item list. |
950 |
qsamplerDevicePortList& ports = pDevice->ports(); |
qsamplerDevicePortList& ports = pDevice->ports(); |
951 |
qsamplerDevicePort* pPort; |
QListIterator<qsamplerDevicePort *> iter(ports); |
952 |
for (pPort = ports.first(); pPort; pPort = ports.next()) { |
while (iter.hasNext()) { |
953 |
|
qsamplerDevicePort *pPort = iter.next(); |
954 |
item.options.append( |
item.options.append( |
955 |
pDevice->deviceTypeName() |
pDevice->deviceTypeName() |
956 |
+ ' ' + pDevice->driverName() |
+ ' ' + pDevice->driverName() |
958 |
); |
); |
959 |
} |
} |
960 |
|
|
961 |
item.selection = routing[index.column()]; |
item.selection = routing[index.row()]; |
962 |
|
|
963 |
return QVariant::fromValue(item); |
return QVariant::fromValue(item); |
964 |
} |
} |
966 |
QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const { |
QVariant ChannelRoutingModel::headerData(int section, Qt::Orientation orientation, int role) const { |
967 |
if (role != Qt::DisplayRole) return QVariant(); |
if (role != Qt::DisplayRole) return QVariant(); |
968 |
|
|
969 |
if (orientation == Qt::Horizontal) |
switch (orientation) { |
970 |
return QObject::tr("Device Channel"); |
case Qt::Horizontal: |
971 |
|
return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel"); |
972 |
if (orientation == Qt::Vertical) |
case Qt::Vertical: |
973 |
return QObject::tr("Sampler Channel Output ") + |
return QObject::tr("Sampler Channel ") + |
974 |
QString(section); |
QString::number(section) + " " + UNICODE_RIGHT_ARROW; |
975 |
|
default: |
976 |
return QVariant(); |
return QVariant(); |
977 |
|
} |
978 |
} |
} |
979 |
|
|
980 |
void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice, |
void ChannelRoutingModel::refresh ( qsamplerDevice *pDevice, |
982 |
{ |
{ |
983 |
this->pDevice = pDevice; |
this->pDevice = pDevice; |
984 |
this->routing = routing; |
this->routing = routing; |
985 |
|
// inform the outer world (QTableView) that our data changed |
986 |
|
QAbstractTableModel::reset(); |
987 |
} |
} |
988 |
|
|
989 |
|
|
990 |
|
//------------------------------------------------------------------------- |
991 |
|
// ChannelRoutingDelegate - table cell renderer for audio routing |
992 |
|
// |
993 |
|
|
994 |
ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) { |
ChannelRoutingDelegate::ChannelRoutingDelegate(QObject *parent) : QItemDelegate(parent) { |
995 |
} |
} |
996 |
|
|
997 |
QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent, |
QWidget* ChannelRoutingDelegate::createEditor(QWidget *parent, |
998 |
const QStyleOptionViewItem &/* option */, |
const QStyleOptionViewItem & option , |
999 |
const QModelIndex& index) const |
const QModelIndex& index) const |
1000 |
{ |
{ |
1001 |
|
if (!index.isValid()) { |
1002 |
|
return NULL; |
1003 |
|
} |
1004 |
|
|
1005 |
|
if (index.column() != 0) { |
1006 |
|
return NULL; |
1007 |
|
} |
1008 |
|
|
1009 |
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
ChannelRoutingItem item = index.model()->data(index, Qt::DisplayRole).value<ChannelRoutingItem>(); |
1010 |
|
|
1011 |
QComboBox* editor = new QComboBox(parent); |
QComboBox* pComboBox = new QComboBox(parent); |
1012 |
editor->addItems(item.options); |
pComboBox->addItems(item.options); |
1013 |
editor->setCurrentIndex(item.selection); |
pComboBox->setCurrentIndex(item.selection); |
1014 |
editor->installEventFilter(const_cast<ChannelRoutingDelegate*>(this)); |
pComboBox->setEnabled(true); |
1015 |
return editor; |
pComboBox->setGeometry(option.rect); |
1016 |
|
return pComboBox; |
1017 |
} |
} |
1018 |
|
|
1019 |
void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { |
void ChannelRoutingDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { |
1022 |
comboBox->setCurrentIndex(item.selection); |
comboBox->setCurrentIndex(item.selection); |
1023 |
} |
} |
1024 |
|
|
1025 |
void ChannelRoutingDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { |
void ChannelRoutingDelegate::setModelData(QWidget* editor, QAbstractItemModel* model, const QModelIndex& index) const { |
1026 |
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
QComboBox* comboBox = static_cast<QComboBox*>(editor); |
1027 |
model->setData(index, comboBox->currentIndex()); |
model->setData(index, comboBox->currentIndex()); |
1028 |
} |
} |
1033 |
editor->setGeometry(option.rect); |
editor->setGeometry(option.rect); |
1034 |
} |
} |
1035 |
|
|
1036 |
|
// end of qsamplerChannel.cpp |
|
|
|
|
//------------------------------------------------------------------------- |
|
|
// qsamplerChannelRoutingComboBox - Custom combo box for routing table. |
|
|
// |
|
|
|
|
|
#if 0 |
|
|
// Constructor. |
|
|
qsamplerChannelRoutingComboBox::qsamplerChannelRoutingComboBox ( |
|
|
QTable *pTable, const QStringList& list, const QPixmap& pixmap ) |
|
|
: QTableItem(pTable, QTableItem::WhenCurrent, QString::null, pixmap), |
|
|
m_list(list) |
|
|
{ |
|
|
m_iCurrentItem = 0; |
|
|
} |
|
|
|
|
|
// Public accessors. |
|
|
void qsamplerChannelRoutingComboBox::setCurrentItem ( int iCurrentItem ) |
|
|
{ |
|
|
m_iCurrentItem = iCurrentItem; |
|
|
|
|
|
QTableItem::setText(m_list[iCurrentItem]); |
|
|
} |
|
|
|
|
|
int qsamplerChannelRoutingComboBox::currentItem (void) const |
|
|
{ |
|
|
return m_iCurrentItem; |
|
|
} |
|
|
|
|
|
// Virtual implemetations. |
|
|
QWidget *qsamplerChannelRoutingComboBox::createEditor (void) const |
|
|
{ |
|
|
QComboBox *pComboBox = new QComboBox(QTableItem::table()->viewport()); |
|
|
QObject::connect(pComboBox, SIGNAL(activated(int)), |
|
|
QTableItem::table(), SLOT(doValueChanged())); |
|
|
for (QStringList::ConstIterator iter = m_list.begin(); |
|
|
iter != m_list.end(); iter++) { |
|
|
pComboBox->insertItem(QTableItem::pixmap(), *iter); |
|
|
} |
|
|
pComboBox->setCurrentItem(m_iCurrentItem); |
|
|
return pComboBox; |
|
|
} |
|
|
|
|
|
void qsamplerChannelRoutingComboBox::setContentFromEditor ( QWidget *pWidget ) |
|
|
{ |
|
|
if (pWidget->inherits("QComboBox")) { |
|
|
QComboBox *pComboBox = (QComboBox *) pWidget; |
|
|
m_iCurrentItem = pComboBox->currentItem(); |
|
|
QTableItem::setText(pComboBox->currentText()); |
|
|
} |
|
|
else QTableItem::setContentFromEditor(pWidget); |
|
|
} |
|
|
|
|
|
#endif |
|