1 |
// qsamplerChannel.cpp |
// qsamplerChannel.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2007, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2014, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, Christian Schoenebeck |
Copyright (C) 2007, 2008 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 |
32 |
|
|
33 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
34 |
#include "gig.h" |
#include "gig.h" |
35 |
|
#include "SF.h" |
36 |
#endif |
#endif |
37 |
|
|
38 |
namespace QSampler { |
namespace QSampler { |
39 |
|
|
40 |
#define QSAMPLER_INSTRUMENT_MAX 100 |
#define QSAMPLER_INSTRUMENT_MAX 128 |
41 |
|
|
42 |
#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21)) |
#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21)) |
43 |
|
|
205 |
return false; |
return false; |
206 |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
if (pMainForm->client() == NULL || m_iChannelID < 0) |
207 |
return false; |
return false; |
208 |
if (!isInstrumentFile(sInstrumentFile)) |
if (!QFileInfo(sInstrumentFile).exists()) |
209 |
return false; |
return false; |
210 |
if (m_iInstrumentStatus == 100 && m_sInstrumentFile == sInstrumentFile && m_iInstrumentNr == iInstrumentNr) |
if (m_iInstrumentStatus == 100 |
211 |
|
&& m_sInstrumentFile == sInstrumentFile |
212 |
|
&& m_iInstrumentNr == iInstrumentNr) |
213 |
return true; |
return true; |
214 |
|
|
215 |
if ( |
if (::lscp_load_instrument_non_modal( |
|
::lscp_load_instrument_non_modal( |
|
216 |
pMainForm->client(), |
pMainForm->client(), |
217 |
qsamplerUtilities::lscpEscapePath( |
qsamplerUtilities::lscpEscapePath( |
218 |
sInstrumentFile).toUtf8().constData(), |
sInstrumentFile).toUtf8().constData(), |
219 |
iInstrumentNr, m_iChannelID |
iInstrumentNr, m_iChannelID |
220 |
) != LSCP_OK |
) != LSCP_OK) { |
|
) { |
|
221 |
appendMessagesClient("lscp_load_instrument"); |
appendMessagesClient("lscp_load_instrument"); |
222 |
return false; |
return false; |
223 |
} |
} |
804 |
} |
} |
805 |
|
|
806 |
|
|
807 |
// FIXME: Check whether a given file is an instrument file. |
// FIXME: Check whether a given file is an instrument file (DLS only). |
808 |
bool Channel::isInstrumentFile ( const QString& sInstrumentFile ) |
bool Channel::isDlsInstrumentFile ( const QString& sInstrumentFile ) |
809 |
{ |
{ |
810 |
bool bResult = false; |
bool bResult = false; |
811 |
|
|
823 |
} |
} |
824 |
|
|
825 |
|
|
826 |
|
// FIXME: Check whether a given file is an instrument file (SF2 only). |
827 |
|
bool Channel::isSf2InstrumentFile ( const QString& sInstrumentFile ) |
828 |
|
{ |
829 |
|
bool bResult = false; |
830 |
|
|
831 |
|
QFile file(sInstrumentFile); |
832 |
|
if (file.open(QIODevice::ReadOnly)) { |
833 |
|
char achHeader[8]; |
834 |
|
if (file.read(achHeader, 8) > 0) { |
835 |
|
bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0 |
836 |
|
&& ::memcmp(&achHeader[4], "sfbk", 4) == 0); |
837 |
|
} |
838 |
|
file.close(); |
839 |
|
} |
840 |
|
|
841 |
|
return bResult; |
842 |
|
} |
843 |
|
|
844 |
|
|
845 |
// Retrieve the instrument list of a instrument file (.gig). |
// Retrieve the instrument list of a instrument file (.gig). |
846 |
QStringList Channel::getInstrumentList( const QString& sInstrumentFile, |
QStringList Channel::getInstrumentList( |
847 |
bool bInstrumentNames ) |
const QString& sInstrumentFile, bool bInstrumentNames ) |
848 |
{ |
{ |
|
QString sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
|
849 |
QStringList instlist; |
QStringList instlist; |
850 |
|
|
851 |
if (isInstrumentFile(sInstrumentFile)) { |
const QFileInfo fi(sInstrumentFile); |
852 |
|
if (!fi.exists()) { |
853 |
|
instlist.append(noInstrumentName()); |
854 |
|
return instlist; |
855 |
|
} |
856 |
|
|
857 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
858 |
if (bInstrumentNames) { |
if (bInstrumentNames) { |
859 |
|
if (isDlsInstrumentFile(sInstrumentFile)) { |
860 |
RIFF::File *pRiff |
RIFF::File *pRiff |
861 |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
862 |
gig::File *pGig = new gig::File(pRiff); |
gig::File *pGig = new gig::File(pRiff); |
863 |
#if HAVE_LIBGIG_SETAUTOLOAD |
#if HAVE_LIBGIG_SETAUTOLOAD |
864 |
// prevent sleepy response time on large .gig files |
// prevent sleepy response time on large .gig files |
865 |
pGig->SetAutoLoad(false); |
pGig->SetAutoLoad(false); |
866 |
#endif |
#endif |
867 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
868 |
while (pInstrument) { |
while (pInstrument) { |
869 |
instlist.append((pInstrument->pInfo)->Name.c_str()); |
instlist.append((pInstrument->pInfo)->Name.c_str()); |
873 |
delete pRiff; |
delete pRiff; |
874 |
} |
} |
875 |
else |
else |
876 |
|
if (isSf2InstrumentFile(sInstrumentFile)) { |
877 |
|
RIFF::File *pRiff |
878 |
|
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
879 |
|
sf2::File *pSf2 = new sf2::File(pRiff); |
880 |
|
const int iPresetCount = pSf2->GetPresetCount(); |
881 |
|
for (int iIndex = 0; iIndex < iPresetCount; ++iIndex) { |
882 |
|
sf2::Preset *pPreset = pSf2->GetPreset(iIndex); |
883 |
|
if (pPreset) { |
884 |
|
instlist.append(pPreset->Name.c_str()); |
885 |
|
} else { |
886 |
|
instlist.append(fi.fileName() |
887 |
|
+ " [" + QString::number(iIndex) + "]"); |
888 |
|
} |
889 |
|
} |
890 |
|
delete pSf2; |
891 |
|
delete pRiff; |
892 |
|
} |
893 |
|
} |
894 |
#endif |
#endif |
895 |
for (int iInstrumentNr = 0; iInstrumentNr < QSAMPLER_INSTRUMENT_MAX; iInstrumentNr++) |
|
896 |
instlist.append(sInstrumentName + " [" + QString::number(iInstrumentNr) + "]"); |
if (instlist.isEmpty()) { |
897 |
|
for (int iIndex = 0; iIndex < QSAMPLER_INSTRUMENT_MAX; ++iIndex) { |
898 |
|
instlist.append(fi.fileName() |
899 |
|
+ " [" + QString::number(iIndex) + "]"); |
900 |
|
} |
901 |
} |
} |
|
else instlist.append(noInstrumentName()); |
|
902 |
|
|
903 |
return instlist; |
return instlist; |
904 |
} |
} |
905 |
|
|
906 |
|
|
907 |
// Retrieve the spacific instrument name of a instrument file (.gig), given its index. |
// Retrieve the spacific instrument name of a instrument file (.gig), given its index. |
908 |
QString Channel::getInstrumentName( const QString& sInstrumentFile, |
QString Channel::getInstrumentName ( |
909 |
int iInstrumentNr, bool bInstrumentNames ) |
const QString& sInstrumentFile, int iInstrumentNr, bool bInstrumentNames ) |
910 |
{ |
{ |
911 |
|
const QFileInfo fi(sInstrumentFile); |
912 |
|
if (!fi.exists()) |
913 |
|
return noInstrumentName(); |
914 |
|
|
915 |
QString sInstrumentName; |
QString sInstrumentName; |
916 |
|
|
|
if (isInstrumentFile(sInstrumentFile)) { |
|
|
sInstrumentName = QFileInfo(sInstrumentFile).fileName(); |
|
917 |
#ifdef CONFIG_LIBGIG |
#ifdef CONFIG_LIBGIG |
918 |
if (bInstrumentNames) { |
if (bInstrumentNames) { |
919 |
|
if (isDlsInstrumentFile(sInstrumentFile)) { |
920 |
RIFF::File *pRiff |
RIFF::File *pRiff |
921 |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
922 |
gig::File *pGig = new gig::File(pRiff); |
gig::File *pGig = new gig::File(pRiff); |
923 |
#if HAVE_LIBGIG_SETAUTOLOAD |
#if HAVE_LIBGIG_SETAUTOLOAD |
924 |
// prevent sleepy response time on large .gig files |
// prevent sleepy response time on large .gig files |
925 |
pGig->SetAutoLoad(false); |
pGig->SetAutoLoad(false); |
926 |
#endif |
#endif |
927 |
int iIndex = 0; |
int iIndex = 0; |
928 |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
gig::Instrument *pInstrument = pGig->GetFirstInstrument(); |
929 |
while (pInstrument) { |
while (pInstrument) { |
938 |
delete pRiff; |
delete pRiff; |
939 |
} |
} |
940 |
else |
else |
941 |
|
if (isSf2InstrumentFile(sInstrumentFile)) { |
942 |
|
RIFF::File *pRiff |
943 |
|
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
944 |
|
sf2::File *pSf2 = new sf2::File(pRiff); |
945 |
|
sf2::Preset *pPreset = pSf2->GetPreset(iInstrumentNr); |
946 |
|
if (pPreset) |
947 |
|
sInstrumentName = pPreset->Name.c_str(); |
948 |
|
delete pSf2; |
949 |
|
delete pRiff; |
950 |
|
} |
951 |
|
} |
952 |
#endif |
#endif |
953 |
|
|
954 |
|
if (sInstrumentName.isEmpty()) { |
955 |
|
sInstrumentName = fi.fileName(); |
956 |
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
957 |
} |
} |
|
else sInstrumentName = noInstrumentName(); |
|
958 |
|
|
959 |
return sInstrumentName; |
return sInstrumentName; |
960 |
} |
} |
988 |
|
|
989 |
int ChannelRoutingModel::rowCount ( const QModelIndex& /*parent*/) const |
int ChannelRoutingModel::rowCount ( const QModelIndex& /*parent*/) const |
990 |
{ |
{ |
991 |
return m_routing.size(); |
return (m_pDevice) ? m_routing.size() : 0; |
992 |
} |
} |
993 |
|
|
994 |
|
|
1056 |
case Qt::Horizontal: |
case Qt::Horizontal: |
1057 |
return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel"); |
return UNICODE_RIGHT_ARROW + QObject::tr(" Device Channel"); |
1058 |
case Qt::Vertical: |
case Qt::Vertical: |
1059 |
return QObject::tr("Sampler Channel ") + |
return QObject::tr("Audio Channel ") + |
1060 |
QString::number(section) + " " + UNICODE_RIGHT_ARROW; |
QString::number(section) + " " + UNICODE_RIGHT_ARROW; |
1061 |
default: |
default: |
1062 |
return QVariant(); |
return QVariant(); |
1070 |
m_pDevice = pDevice; |
m_pDevice = pDevice; |
1071 |
m_routing = routing; |
m_routing = routing; |
1072 |
// inform the outer world (QTableView) that our data changed |
// inform the outer world (QTableView) that our data changed |
1073 |
|
#if QT_VERSION < 0x050000 |
1074 |
QAbstractTableModel::reset(); |
QAbstractTableModel::reset(); |
1075 |
|
#else |
1076 |
|
QAbstractTableModel::beginResetModel(); |
1077 |
|
QAbstractTableModel::endResetModel(); |
1078 |
|
#endif |
1079 |
} |
} |
1080 |
|
|
1081 |
|
|