1 |
// qsamplerChannel.cpp |
// qsamplerChannel.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2010, rncbc aka Rui Nuno Capela. All rights reserved. |
Copyright (C) 2004-2014, rncbc aka Rui Nuno Capela. All rights reserved. |
5 |
Copyright (C) 2007, 2008 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 |
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 |
|
|
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[12]; |
834 |
|
if (file.read(achHeader, 12) > 0) { |
835 |
|
bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0 |
836 |
|
&& ::memcmp(&achHeader[8], "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 |
{ |
{ |
849 |
QStringList instlist; |
QStringList instlist; |
850 |
|
|
851 |
if (isDlsInstrumentFile(sInstrumentFile)) { |
const QFileInfo fi(sInstrumentFile); |
852 |
#ifdef CONFIG_LIBGIG |
if (!fi.exists()) { |
853 |
if (bInstrumentNames) { |
instlist.append(noInstrumentName()); |
854 |
|
return instlist; |
855 |
|
} |
856 |
|
|
857 |
|
#ifdef CONFIG_LIBGIG |
858 |
|
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); |
872 |
delete pGig; |
delete pGig; |
873 |
delete pRiff; |
delete pRiff; |
874 |
} |
} |
875 |
#endif |
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 |
895 |
|
|
896 |
if (instlist.isEmpty()) { |
if (instlist.isEmpty()) { |
897 |
QFileInfo fi(sInstrumentFile); |
for (int iIndex = 0; iIndex < QSAMPLER_INSTRUMENT_MAX; ++iIndex) { |
898 |
if (fi.exists()) { |
instlist.append(fi.fileName() |
899 |
QString sInstrumentName = fi.fileName(); |
+ " [" + QString::number(iIndex) + "]"); |
|
int iInstrumentNr = 0; |
|
|
while (iInstrumentNr < QSAMPLER_INSTRUMENT_MAX) { |
|
|
instlist.append(sInstrumentName |
|
|
+ " [" + QString::number(++iInstrumentNr) + "]"); |
|
|
} |
|
900 |
} |
} |
|
else instlist.append(noInstrumentName()); |
|
901 |
} |
} |
902 |
|
|
903 |
return instlist; |
return instlist; |
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 |
|
|
917 |
if (isDlsInstrumentFile(sInstrumentFile)) { |
#ifdef CONFIG_LIBGIG |
918 |
#ifdef CONFIG_LIBGIG |
if (bInstrumentNames) { |
919 |
if (bInstrumentNames) { |
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); |
937 |
delete pGig; |
delete pGig; |
938 |
delete pRiff; |
delete pRiff; |
939 |
} |
} |
940 |
#endif |
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 |
953 |
|
|
954 |
if (sInstrumentName.isEmpty()) { |
if (sInstrumentName.isEmpty()) { |
955 |
QFileInfo fi(sInstrumentFile); |
sInstrumentName = fi.fileName(); |
956 |
if (fi.exists()) { |
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
|
sInstrumentName = fi.fileName(); |
|
|
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
|
|
} |
|
|
else sInstrumentName = noInstrumentName(); |
|
957 |
} |
} |
958 |
|
|
959 |
return sInstrumentName; |
return sInstrumentName; |
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 |
|
|