28 |
|
|
29 |
#include "../common/Exception.h" |
#include "../common/Exception.h" |
30 |
#include "InstrumentsDb.h" |
#include "InstrumentsDb.h" |
31 |
|
#include "../engines/sfz/sfz.h" |
32 |
|
#if HAVE_SF2 |
33 |
|
# if AC_APPLE_UNIVERSAL_BUILD |
34 |
|
# include <libgig/SF.h> |
35 |
|
# else |
36 |
|
# include <SF.h> |
37 |
|
# endif |
38 |
|
#endif // HAVE_SF2 |
39 |
|
|
40 |
namespace LinuxSampler { |
namespace LinuxSampler { |
41 |
|
|
42 |
|
class GigFileInfo : public InstrumentFileInfo { |
43 |
|
public: |
44 |
|
GigFileInfo(String fileName) : InstrumentFileInfo(fileName) { |
45 |
|
m_gig = NULL; |
46 |
|
m_riff = NULL; |
47 |
|
try { |
48 |
|
m_riff = new RIFF::File(fileName); |
49 |
|
m_gig = new gig::File(m_riff); |
50 |
|
m_gig->SetAutoLoad(false); // avoid time consuming samples scanning |
51 |
|
} catch (RIFF::Exception e) { |
52 |
|
throw Exception(e.Message); |
53 |
|
} catch (...) { |
54 |
|
throw Exception("Unknown exception while accessing gig file"); |
55 |
|
} |
56 |
|
} |
57 |
|
|
58 |
|
virtual ~GigFileInfo() { |
59 |
|
if (m_gig) delete m_gig; |
60 |
|
if (m_riff) delete m_riff; |
61 |
|
} |
62 |
|
|
63 |
|
String formatName() OVERRIDE { |
64 |
|
return "GIG"; |
65 |
|
} |
66 |
|
|
67 |
|
String formatVersion() OVERRIDE { |
68 |
|
return (m_gig->pVersion) ? ToString(m_gig->pVersion->major) : ""; |
69 |
|
} |
70 |
|
|
71 |
|
optional<InstrumentInfo> getInstrumentInfo(int index, ScanProgress* pProgress) OVERRIDE { |
72 |
|
InstrumentInfo info; |
73 |
|
try { |
74 |
|
::gig::progress_t* progress = (pProgress) ? &pProgress->GigFileProgress : NULL; |
75 |
|
::gig::Instrument* pInstrument = m_gig->GetInstrument(index, progress); |
76 |
|
if (!pInstrument) |
77 |
|
return optional<InstrumentInfo>::nothing; |
78 |
|
|
79 |
|
info.instrumentName = pInstrument->pInfo->Name; |
80 |
|
info.product = (!pInstrument->pInfo->Product.empty()) ? pInstrument->pInfo->Product : m_gig->pInfo->Product; |
81 |
|
info.artists = (!pInstrument->pInfo->Artists.empty()) ? pInstrument->pInfo->Artists : m_gig->pInfo->Artists; |
82 |
|
info.keywords = (!pInstrument->pInfo->Keywords.empty()) ? pInstrument->pInfo->Keywords : m_gig->pInfo->Keywords; |
83 |
|
info.comments = (!pInstrument->pInfo->Comments.empty()) ? pInstrument->pInfo->Comments : m_gig->pInfo->Comments; |
84 |
|
info.isDrum = pInstrument->IsDrum; |
85 |
|
} catch (RIFF::Exception e) { |
86 |
|
throw Exception(e.Message); |
87 |
|
} catch (...) { |
88 |
|
throw Exception("Unknown exception while accessing gig file"); |
89 |
|
} |
90 |
|
return info; |
91 |
|
} |
92 |
|
private: |
93 |
|
::RIFF::File* m_riff; |
94 |
|
::gig::File* m_gig; |
95 |
|
}; |
96 |
|
|
97 |
|
class SFZFileInfo : public InstrumentFileInfo { |
98 |
|
public: |
99 |
|
SFZFileInfo(String fileName) : InstrumentFileInfo(fileName) { |
100 |
|
m_sfz = NULL; |
101 |
|
try { |
102 |
|
m_sfz = new ::sfz::File(fileName); |
103 |
|
} catch (sfz::Exception e) { |
104 |
|
throw Exception(e.Message()); |
105 |
|
} catch (...) { |
106 |
|
throw Exception("Unknown exception while accessing sfz file"); |
107 |
|
} |
108 |
|
} |
109 |
|
|
110 |
|
virtual ~SFZFileInfo() { |
111 |
|
if (m_sfz) delete m_sfz; |
112 |
|
} |
113 |
|
|
114 |
|
String formatName() OVERRIDE { |
115 |
|
return "SFZ"; |
116 |
|
} |
117 |
|
|
118 |
|
String formatVersion() OVERRIDE { |
119 |
|
return ""; |
120 |
|
} |
121 |
|
|
122 |
|
optional<InstrumentInfo> getInstrumentInfo(int index, ScanProgress* pProgress) OVERRIDE { |
123 |
|
if (index != 0) |
124 |
|
return optional<InstrumentInfo>::nothing; |
125 |
|
|
126 |
|
InstrumentInfo info; |
127 |
|
// yeah, lousy info, but SFZ does not provide any meta info unfortunately yet |
128 |
|
return info; |
129 |
|
} |
130 |
|
private: |
131 |
|
::sfz::File* m_sfz; |
132 |
|
}; |
133 |
|
|
134 |
|
#if HAVE_SF2 |
135 |
|
|
136 |
|
class Sf2FileInfo : public InstrumentFileInfo { |
137 |
|
public: |
138 |
|
Sf2FileInfo(String fileName) : InstrumentFileInfo(fileName) { |
139 |
|
m_sf2 = NULL; |
140 |
|
m_riff = NULL; |
141 |
|
try { |
142 |
|
m_riff = new RIFF::File(fileName); |
143 |
|
m_sf2 = new sf2::File(m_riff); |
144 |
|
} catch (RIFF::Exception e) { |
145 |
|
throw Exception(e.Message); |
146 |
|
} catch (...) { |
147 |
|
throw Exception("Unknown exception while accessing sf2 file"); |
148 |
|
} |
149 |
|
} |
150 |
|
|
151 |
|
virtual ~Sf2FileInfo() { |
152 |
|
if (m_sf2) delete m_sf2; |
153 |
|
if (m_riff) delete m_riff; |
154 |
|
} |
155 |
|
|
156 |
|
String formatName() OVERRIDE { |
157 |
|
return "SF2"; |
158 |
|
} |
159 |
|
|
160 |
|
String formatVersion() OVERRIDE { |
161 |
|
if (!m_sf2->pInfo || !m_sf2->pInfo->pVer) return ""; |
162 |
|
String major = ToString(m_sf2->pInfo->pVer->Major); |
163 |
|
//String minor = ToString(m_sf2->pInfo->pVer->Minor); |
164 |
|
//return major + "." + minor; |
165 |
|
return major; |
166 |
|
} |
167 |
|
|
168 |
|
optional<InstrumentInfo> getInstrumentInfo(int index, ScanProgress* pProgress) OVERRIDE { |
169 |
|
if (index >= m_sf2->GetPresetCount()) |
170 |
|
return optional<InstrumentInfo>::nothing; |
171 |
|
|
172 |
|
InstrumentInfo info; |
173 |
|
try { |
174 |
|
::sf2::Preset* preset = m_sf2->GetPreset(index); |
175 |
|
if (!preset) |
176 |
|
return optional<InstrumentInfo>::nothing; |
177 |
|
|
178 |
|
info.instrumentName = preset->Name; |
179 |
|
if (m_sf2->pInfo) { |
180 |
|
info.product = m_sf2->pInfo->Product; |
181 |
|
info.comments = m_sf2->pInfo->Comments; |
182 |
|
info.artists = m_sf2->pInfo->Engineers; |
183 |
|
} |
184 |
|
} catch (RIFF::Exception e) { |
185 |
|
throw Exception(e.Message); |
186 |
|
} catch (...) { |
187 |
|
throw Exception("Unknown exception while accessing gig file"); |
188 |
|
} |
189 |
|
return info; |
190 |
|
} |
191 |
|
private: |
192 |
|
::RIFF::File* m_riff; |
193 |
|
::sf2::File* m_sf2; |
194 |
|
}; |
195 |
|
|
196 |
|
#endif // #if HAVE_SF2 |
197 |
|
|
198 |
void DbInstrument::Copy(const DbInstrument& Instr) { |
void DbInstrument::Copy(const DbInstrument& Instr) { |
199 |
if (this == &Instr) return; |
if (this == &Instr) return; |
200 |
|
|
415 |
} |
} |
416 |
|
|
417 |
StringListPtr DirectoryFinder::GetDirectories() { |
StringListPtr DirectoryFinder::GetDirectories() { |
418 |
|
#if __cplusplus >= 201103L && !CONFIG_NO_CPP11STL |
419 |
|
return std::move(pDirectories); |
420 |
|
#else |
421 |
return pDirectories; |
return pDirectories; |
422 |
|
#endif |
423 |
} |
} |
424 |
|
|
425 |
void DirectoryFinder::ProcessDirectory(String Path, int DirId) { |
void DirectoryFinder::ProcessDirectory(String Path, int DirId) { |
532 |
} |
} |
533 |
|
|
534 |
StringListPtr InstrumentFinder::GetInstruments() { |
StringListPtr InstrumentFinder::GetInstruments() { |
535 |
|
#if __cplusplus >= 201103L && !CONFIG_NO_CPP11STL |
536 |
|
return std::move(pInstruments); |
537 |
|
#else |
538 |
return pInstruments; |
return pInstruments; |
539 |
|
#endif |
540 |
} |
} |
541 |
|
|
542 |
void DirectoryCounter::ProcessDirectory(String Path, int DirId) { |
void DirectoryCounter::ProcessDirectory(String Path, int DirId) { |
691 |
|
|
692 |
for (int i = 0; i < fileList->size(); i++) { |
for (int i = 0; i < fileList->size(); i++) { |
693 |
String s = fileList->at(i); |
String s = fileList->at(i); |
694 |
if (s.length() < 4) continue; |
if (InstrumentFileInfo::isSupportedFile(s)) count++; |
|
if(!strcasecmp(".gig", s.substr(s.length() - 4).c_str())) count++; |
|
695 |
} |
} |
696 |
} catch(Exception e) { |
} catch(Exception e) { |
697 |
e.PrintMessage(); |
e.PrintMessage(); |
786 |
|
|
787 |
void InstrumentFileCounter::FileEntry(std::string Path) { |
void InstrumentFileCounter::FileEntry(std::string Path) { |
788 |
dmsg(2,("InstrumentFileCounter: FileEntry(Path=%s)\n", Path.c_str())); |
dmsg(2,("InstrumentFileCounter: FileEntry(Path=%s)\n", Path.c_str())); |
789 |
if(Path.length() < 4) return; |
if (InstrumentFileInfo::isSupportedFile(Path)) FileCount++; |
|
if(!strcasecmp(".gig", Path.substr(Path.length() - 4).c_str())) FileCount++; |
|
790 |
}; |
}; |
791 |
|
|
792 |
|
|
793 |
|
InstrumentFileInfo* InstrumentFileInfo::getFileInfoFor(String filename) { |
794 |
|
if (filename.length() < 4) return NULL; |
795 |
|
String fileExtension = filename.substr(filename.length() - 4); |
796 |
|
if (!strcasecmp(".gig", fileExtension.c_str())) |
797 |
|
return new GigFileInfo(filename); |
798 |
|
if (!strcasecmp(".sfz", fileExtension.c_str())) |
799 |
|
return new SFZFileInfo(filename); |
800 |
|
#if HAVE_SF2 |
801 |
|
if (!strcasecmp(".sf2", fileExtension.c_str())) |
802 |
|
return new Sf2FileInfo(filename); |
803 |
|
#endif |
804 |
|
return NULL; |
805 |
|
} |
806 |
|
|
807 |
|
bool InstrumentFileInfo::isSupportedFile(String filename) { |
808 |
|
if (filename.length() < 4) return false; |
809 |
|
String fileExtension = filename.substr(filename.length() - 4); |
810 |
|
if (!strcasecmp(".gig", fileExtension.c_str())) return true; |
811 |
|
if (!strcasecmp(".sfz", fileExtension.c_str())) return true; |
812 |
|
#if HAVE_SF2 |
813 |
|
if (!strcasecmp(".sf2", fileExtension.c_str())) return true; |
814 |
|
#endif |
815 |
|
return false; |
816 |
|
} |
817 |
|
|
818 |
} // namespace LinuxSampler |
} // namespace LinuxSampler |