1 |
// qsamplerChannel.cpp |
// qsamplerChannel.cpp |
2 |
// |
// |
3 |
/**************************************************************************** |
/**************************************************************************** |
4 |
Copyright (C) 2004-2012, 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 |
|
#ifdef CONFIG_LIBGIG_SF_H |
36 |
|
#include "SF.h" |
37 |
|
#endif |
38 |
#endif |
#endif |
39 |
|
|
40 |
namespace QSampler { |
namespace QSampler { |
41 |
|
|
42 |
#define QSAMPLER_INSTRUMENT_MAX 100 |
#define QSAMPLER_INSTRUMENT_MAX 128 |
43 |
|
|
44 |
#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21)) |
#define UNICODE_RIGHT_ARROW QChar(char(0x92), char(0x21)) |
45 |
|
|
825 |
} |
} |
826 |
|
|
827 |
|
|
828 |
|
// FIXME: Check whether a given file is an instrument file (SF2 only). |
829 |
|
bool Channel::isSf2InstrumentFile ( const QString& sInstrumentFile ) |
830 |
|
{ |
831 |
|
bool bResult = false; |
832 |
|
|
833 |
|
QFile file(sInstrumentFile); |
834 |
|
if (file.open(QIODevice::ReadOnly)) { |
835 |
|
char achHeader[12]; |
836 |
|
if (file.read(achHeader, 12) > 0) { |
837 |
|
bResult = (::memcmp(&achHeader[0], "RIFF", 4) == 0 |
838 |
|
&& ::memcmp(&achHeader[8], "sfbk", 4) == 0); |
839 |
|
} |
840 |
|
file.close(); |
841 |
|
} |
842 |
|
|
843 |
|
return bResult; |
844 |
|
} |
845 |
|
|
846 |
|
|
847 |
// Retrieve the instrument list of a instrument file (.gig). |
// Retrieve the instrument list of a instrument file (.gig). |
848 |
QStringList Channel::getInstrumentList( const QString& sInstrumentFile, |
QStringList Channel::getInstrumentList ( |
849 |
bool bInstrumentNames ) |
const QString& sInstrumentFile, bool bInstrumentNames ) |
850 |
{ |
{ |
851 |
QStringList instlist; |
QStringList instlist; |
852 |
|
|
853 |
if (isDlsInstrumentFile(sInstrumentFile)) { |
const QFileInfo fi(sInstrumentFile); |
854 |
#ifdef CONFIG_LIBGIG |
if (!fi.exists()) { |
855 |
if (bInstrumentNames) { |
instlist.append(noInstrumentName()); |
856 |
|
return instlist; |
857 |
|
} |
858 |
|
|
859 |
|
#ifdef CONFIG_LIBGIG |
860 |
|
if (bInstrumentNames) { |
861 |
|
if (isDlsInstrumentFile(sInstrumentFile)) { |
862 |
RIFF::File *pRiff |
RIFF::File *pRiff |
863 |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
864 |
gig::File *pGig = new gig::File(pRiff); |
gig::File *pGig = new gig::File(pRiff); |
865 |
#if HAVE_LIBGIG_SETAUTOLOAD |
#ifdef CONFIG_LIBGIG_SETAUTOLOAD |
866 |
// prevent sleepy response time on large .gig files |
// prevent sleepy response time on large .gig files |
867 |
pGig->SetAutoLoad(false); |
pGig->SetAutoLoad(false); |
868 |
#endif |
#endif |
874 |
delete pGig; |
delete pGig; |
875 |
delete pRiff; |
delete pRiff; |
876 |
} |
} |
877 |
|
#ifdef CONFIG_LIBGIG_SF2 |
878 |
|
else |
879 |
|
if (isSf2InstrumentFile(sInstrumentFile)) { |
880 |
|
RIFF::File *pRiff |
881 |
|
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
882 |
|
sf2::File *pSf2 = new sf2::File(pRiff); |
883 |
|
const int iPresetCount = pSf2->GetPresetCount(); |
884 |
|
for (int iIndex = 0; iIndex < iPresetCount; ++iIndex) { |
885 |
|
sf2::Preset *pPreset = pSf2->GetPreset(iIndex); |
886 |
|
if (pPreset) { |
887 |
|
instlist.append(pPreset->Name.c_str()); |
888 |
|
} else { |
889 |
|
instlist.append(fi.fileName() |
890 |
|
+ " [" + QString::number(iIndex) + "]"); |
891 |
|
} |
892 |
|
} |
893 |
|
delete pSf2; |
894 |
|
delete pRiff; |
895 |
|
} |
896 |
#endif |
#endif |
897 |
} |
} |
898 |
|
#endif |
899 |
|
|
900 |
if (instlist.isEmpty()) { |
if (instlist.isEmpty()) { |
901 |
QFileInfo fi(sInstrumentFile); |
for (int iIndex = 0; iIndex < QSAMPLER_INSTRUMENT_MAX; ++iIndex) { |
902 |
if (fi.exists()) { |
instlist.append(fi.fileName() |
903 |
QString sInstrumentName = fi.fileName(); |
+ " [" + QString::number(iIndex) + "]"); |
|
int iInstrumentNr = 0; |
|
|
while (iInstrumentNr < QSAMPLER_INSTRUMENT_MAX) { |
|
|
instlist.append(sInstrumentName |
|
|
+ " [" + QString::number(++iInstrumentNr) + "]"); |
|
|
} |
|
904 |
} |
} |
|
else instlist.append(noInstrumentName()); |
|
905 |
} |
} |
906 |
|
|
907 |
return instlist; |
return instlist; |
909 |
|
|
910 |
|
|
911 |
// 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. |
912 |
QString Channel::getInstrumentName( const QString& sInstrumentFile, |
QString Channel::getInstrumentName ( |
913 |
int iInstrumentNr, bool bInstrumentNames ) |
const QString& sInstrumentFile, int iInstrumentNr, bool bInstrumentNames ) |
914 |
{ |
{ |
915 |
|
const QFileInfo fi(sInstrumentFile); |
916 |
|
if (!fi.exists()) |
917 |
|
return noInstrumentName(); |
918 |
|
|
919 |
QString sInstrumentName; |
QString sInstrumentName; |
920 |
|
|
921 |
if (isDlsInstrumentFile(sInstrumentFile)) { |
#ifdef CONFIG_LIBGIG |
922 |
#ifdef CONFIG_LIBGIG |
if (bInstrumentNames) { |
923 |
if (bInstrumentNames) { |
if (isDlsInstrumentFile(sInstrumentFile)) { |
924 |
RIFF::File *pRiff |
RIFF::File *pRiff |
925 |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
926 |
gig::File *pGig = new gig::File(pRiff); |
gig::File *pGig = new gig::File(pRiff); |
927 |
#if HAVE_LIBGIG_SETAUTOLOAD |
#ifdef CONFIG_LIBGIG_SETAUTOLOAD |
928 |
// prevent sleepy response time on large .gig files |
// prevent sleepy response time on large .gig files |
929 |
pGig->SetAutoLoad(false); |
pGig->SetAutoLoad(false); |
930 |
#endif |
#endif |
941 |
delete pGig; |
delete pGig; |
942 |
delete pRiff; |
delete pRiff; |
943 |
} |
} |
944 |
|
#ifdef CONFIG_LIBGIG_SF2 |
945 |
|
else |
946 |
|
if (isSf2InstrumentFile(sInstrumentFile)) { |
947 |
|
RIFF::File *pRiff |
948 |
|
= new RIFF::File(sInstrumentFile.toUtf8().constData()); |
949 |
|
sf2::File *pSf2 = new sf2::File(pRiff); |
950 |
|
sf2::Preset *pPreset = pSf2->GetPreset(iInstrumentNr); |
951 |
|
if (pPreset) |
952 |
|
sInstrumentName = pPreset->Name.c_str(); |
953 |
|
delete pSf2; |
954 |
|
delete pRiff; |
955 |
|
} |
956 |
#endif |
#endif |
957 |
} |
} |
958 |
|
#endif |
959 |
|
|
960 |
if (sInstrumentName.isEmpty()) { |
if (sInstrumentName.isEmpty()) { |
961 |
QFileInfo fi(sInstrumentFile); |
sInstrumentName = fi.fileName(); |
962 |
if (fi.exists()) { |
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
|
sInstrumentName = fi.fileName(); |
|
|
sInstrumentName += " [" + QString::number(iInstrumentNr) + "]"; |
|
|
} |
|
|
else sInstrumentName = noInstrumentName(); |
|
963 |
} |
} |
964 |
|
|
965 |
return sInstrumentName; |
return sInstrumentName; |