2 |
* * |
* * |
3 |
* libgig - C++ cross-platform Gigasampler format file access library * |
* libgig - C++ cross-platform Gigasampler format file access library * |
4 |
* * |
* * |
5 |
* Copyright (C) 2003-2014 by Christian Schoenebeck * |
* Copyright (C) 2003-2017 by Christian Schoenebeck * |
6 |
* <cuse@users.sourceforge.net> * |
* <cuse@users.sourceforge.net> * |
7 |
* * |
* * |
8 |
* This library is free software; you can redistribute it and/or modify * |
* This library is free software; you can redistribute it and/or modify * |
27 |
#include <string.h> |
#include <string.h> |
28 |
#include <string> |
#include <string> |
29 |
#include <sstream> |
#include <sstream> |
30 |
|
#include <algorithm> |
31 |
|
|
32 |
#if defined(WIN32) && !HAVE_CONFIG_H |
#if defined(WIN32) && !HAVE_CONFIG_H |
33 |
# include "../win32/libgig_private.h" // like config.h, automatically generated by Dev-C++ |
# include "../win32/libgig_private.h" // like config.h, automatically generated by Dev-C++ |
35 |
# define VERSION VER_STRING // VER_STRING defined in libgig_private.h |
# define VERSION VER_STRING // VER_STRING defined in libgig_private.h |
36 |
#endif // WIN32 |
#endif // WIN32 |
37 |
|
|
38 |
|
#if HAVE_CONFIG_H /*&& !HAVE_VASPRINTF*/ && defined(WIN32) |
39 |
|
# include <stdarg.h> |
40 |
|
int vasprintf(char** ret, const char* format, va_list arg); |
41 |
|
#endif |
42 |
|
|
43 |
#include "RIFF.h" |
#include "RIFF.h" |
44 |
|
|
45 |
// *************** Helper Functions ************** |
// *************** Helper Functions ************** |
51 |
return ss.str(); |
return ss.str(); |
52 |
} |
} |
53 |
|
|
54 |
|
inline std::string toLowerCase(std::string s) { |
55 |
|
std::transform(s.begin(), s.end(), s.begin(), ::tolower); |
56 |
|
return s; |
57 |
|
} |
58 |
|
|
59 |
inline long Min(long A, long B) { |
inline long Min(long A, long B) { |
60 |
return (A > B) ? B : A; |
return (A > B) ? B : A; |
61 |
} |
} |
206 |
inline void LoadString(RIFF::Chunk* ck, std::string& s) { |
inline void LoadString(RIFF::Chunk* ck, std::string& s) { |
207 |
if (ck) { |
if (ck) { |
208 |
const char* str = (char*)ck->LoadChunkData(); |
const char* str = (char*)ck->LoadChunkData(); |
209 |
int size = ck->GetSize(); |
int size = (int) ck->GetSize(); |
210 |
int len; |
int len; |
211 |
for (len = 0 ; len < size ; len++) |
for (len = 0 ; len < size ; len++) |
212 |
if (str[len] == '\0') break; |
if (str[len] == '\0') break; |
235 |
*/ |
*/ |
236 |
inline void SaveString(uint32_t ChunkID, RIFF::Chunk* ck, RIFF::List* lstINFO, const std::string& s, const std::string& sDefault, bool bUseFixedLengthStrings, int size) { |
inline void SaveString(uint32_t ChunkID, RIFF::Chunk* ck, RIFF::List* lstINFO, const std::string& s, const std::string& sDefault, bool bUseFixedLengthStrings, int size) { |
237 |
if (ck) { // if chunk exists already, use 's' as value |
if (ck) { // if chunk exists already, use 's' as value |
238 |
if (!bUseFixedLengthStrings) size = s.size() + 1; |
if (!bUseFixedLengthStrings) size = (int) s.size() + 1; |
239 |
ck->Resize(size); |
ck->Resize(size); |
240 |
char* pData = (char*) ck->LoadChunkData(); |
char* pData = (char*) ck->LoadChunkData(); |
241 |
strncpy(pData, s.c_str(), size); |
strncpy(pData, s.c_str(), size); |
242 |
} else if (s != "" || sDefault != "" || bUseFixedLengthStrings) { // create chunk |
} else if (s != "" || sDefault != "" || bUseFixedLengthStrings) { // create chunk |
243 |
const std::string& sToSave = (s != "") ? s : sDefault; |
const std::string& sToSave = (s != "") ? s : sDefault; |
244 |
if (!bUseFixedLengthStrings) size = sToSave.size() + 1; |
if (!bUseFixedLengthStrings) size = (int) sToSave.size() + 1; |
245 |
ck = lstINFO->AddSubChunk(ChunkID, size); |
ck = lstINFO->AddSubChunk(ChunkID, size); |
246 |
char* pData = (char*) ck->LoadChunkData(); |
char* pData = (char*) ck->LoadChunkData(); |
247 |
strncpy(pData, sToSave.c_str(), size); |
strncpy(pData, sToSave.c_str(), size); |