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-2007 by Christian Schoenebeck * |
* Copyright (C) 2003-2013 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 * |
25 |
|
|
26 |
#include "helper.h" |
#include "helper.h" |
27 |
|
|
28 |
|
#include <algorithm> |
29 |
#include <math.h> |
#include <math.h> |
30 |
#include <iostream> |
#include <iostream> |
31 |
|
|
256 |
|
|
257 |
|
|
258 |
|
|
259 |
|
// *************** Internal CRC-32 (Cyclic Redundancy Check) functions *************** |
260 |
|
// * |
261 |
|
|
262 |
|
static uint32_t* __initCRCTable() { |
263 |
|
static uint32_t res[256]; |
264 |
|
|
265 |
|
for (int i = 0 ; i < 256 ; i++) { |
266 |
|
uint32_t c = i; |
267 |
|
for (int j = 0 ; j < 8 ; j++) { |
268 |
|
c = (c & 1) ? 0xedb88320 ^ (c >> 1) : c >> 1; |
269 |
|
} |
270 |
|
res[i] = c; |
271 |
|
} |
272 |
|
return res; |
273 |
|
} |
274 |
|
|
275 |
|
static const uint32_t* __CRCTable = __initCRCTable(); |
276 |
|
|
277 |
|
/** |
278 |
|
* Initialize a CRC variable. |
279 |
|
* |
280 |
|
* @param crc - variable to be initialized |
281 |
|
*/ |
282 |
|
inline static void __resetCRC(uint32_t& crc) { |
283 |
|
crc = 0xffffffff; |
284 |
|
} |
285 |
|
|
286 |
|
/** |
287 |
|
* Used to calculate checksums of the sample data in a gig file. The |
288 |
|
* checksums are stored in the 3crc chunk of the gig file and |
289 |
|
* automatically updated when a sample is written with Sample::Write(). |
290 |
|
* |
291 |
|
* One should call __resetCRC() to initialize the CRC variable to be |
292 |
|
* used before calling this function the first time. |
293 |
|
* |
294 |
|
* After initializing the CRC variable one can call this function |
295 |
|
* arbitrary times, i.e. to split the overall CRC calculation into |
296 |
|
* steps. |
297 |
|
* |
298 |
|
* Once the whole data was processed by __calculateCRC(), one should |
299 |
|
* call __encodeCRC() to get the final CRC result. |
300 |
|
* |
301 |
|
* @param buf - pointer to data the CRC shall be calculated of |
302 |
|
* @param bufSize - size of the data to be processed |
303 |
|
* @param crc - variable the CRC sum shall be stored to |
304 |
|
*/ |
305 |
|
static void __calculateCRC(unsigned char* buf, int bufSize, uint32_t& crc) { |
306 |
|
for (int i = 0 ; i < bufSize ; i++) { |
307 |
|
crc = __CRCTable[(crc ^ buf[i]) & 0xff] ^ (crc >> 8); |
308 |
|
} |
309 |
|
} |
310 |
|
|
311 |
|
/** |
312 |
|
* Returns the final CRC result. |
313 |
|
* |
314 |
|
* @param crc - variable previously passed to __calculateCRC() |
315 |
|
*/ |
316 |
|
inline static uint32_t __encodeCRC(const uint32_t& crc) { |
317 |
|
return crc ^ 0xffffffff; |
318 |
|
} |
319 |
|
|
320 |
|
|
321 |
|
|
322 |
// *************** Other Internal functions *************** |
// *************** Other Internal functions *************** |
323 |
// * |
// * |
324 |
|
|
342 |
|
|
343 |
|
|
344 |
|
|
|
// *************** CRC *************** |
|
|
// * |
|
|
|
|
|
const uint32_t* CRC::table(initTable()); |
|
|
|
|
|
uint32_t* CRC::initTable() { |
|
|
uint32_t* res = new uint32_t[256]; |
|
|
|
|
|
for (int i = 0 ; i < 256 ; i++) { |
|
|
uint32_t c = i; |
|
|
for (int j = 0 ; j < 8 ; j++) { |
|
|
c = (c & 1) ? 0xedb88320 ^ (c >> 1) : c >> 1; |
|
|
} |
|
|
res[i] = c; |
|
|
} |
|
|
return res; |
|
|
} |
|
|
|
|
|
|
|
|
|
|
345 |
// *************** Sample *************** |
// *************** Sample *************** |
346 |
// * |
// * |
347 |
|
|
367 |
* is located, 0 otherwise |
* is located, 0 otherwise |
368 |
*/ |
*/ |
369 |
Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { |
370 |
static const DLS::Info::FixedStringLength fixedStringLengths[] = { |
static const DLS::Info::string_length_t fixedStringLengths[] = { |
371 |
{ CHUNK_ID_INAM, 64 }, |
{ CHUNK_ID_INAM, 64 }, |
372 |
{ 0, 0 } |
{ 0, 0 } |
373 |
}; |
}; |
374 |
pInfo->FixedStringLengths = fixedStringLengths; |
pInfo->SetFixedStringLengths(fixedStringLengths); |
375 |
Instances++; |
Instances++; |
376 |
FileNo = fileNo; |
FileNo = fileNo; |
377 |
|
|
378 |
|
__resetCRC(crc); |
379 |
|
|
380 |
pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX); |
381 |
if (pCk3gix) { |
if (pCk3gix) { |
382 |
uint16_t iSampleGroup = pCk3gix->ReadInt16(); |
uint16_t iSampleGroup = pCk3gix->ReadInt16(); |
677 |
if (SampleCount > this->SamplesTotal) SampleCount = this->SamplesTotal; |
if (SampleCount > this->SamplesTotal) SampleCount = this->SamplesTotal; |
678 |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
679 |
unsigned long allocationsize = (SampleCount + NullSamplesCount) * this->FrameSize; |
unsigned long allocationsize = (SampleCount + NullSamplesCount) * this->FrameSize; |
680 |
|
SetPos(0); // reset read position to begin of sample |
681 |
RAMCache.pStart = new int8_t[allocationsize]; |
RAMCache.pStart = new int8_t[allocationsize]; |
682 |
RAMCache.Size = Read(RAMCache.pStart, SampleCount) * this->FrameSize; |
RAMCache.Size = Read(RAMCache.pStart, SampleCount) * this->FrameSize; |
683 |
RAMCache.NullExtensionSize = allocationsize - RAMCache.Size; |
RAMCache.NullExtensionSize = allocationsize - RAMCache.Size; |
715 |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
716 |
RAMCache.pStart = NULL; |
RAMCache.pStart = NULL; |
717 |
RAMCache.Size = 0; |
RAMCache.Size = 0; |
718 |
|
RAMCache.NullExtensionSize = 0; |
719 |
} |
} |
720 |
|
|
721 |
/** @brief Resize sample. |
/** @brief Resize sample. |
910 |
} |
} |
911 |
|
|
912 |
// reverse the sample frames for backward playback |
// reverse the sample frames for backward playback |
913 |
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
if (totalreadsamples > swapareastart) //FIXME: this if() is just a crash workaround for now (#102), but totalreadsamples <= swapareastart should never be the case, so there's probably still a bug above! |
914 |
|
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
915 |
} |
} |
916 |
} while (samplestoread && readsamples); |
} while (samplestoread && readsamples); |
917 |
break; |
break; |
1217 |
// if this is the first write in this sample, reset the |
// if this is the first write in this sample, reset the |
1218 |
// checksum calculator |
// checksum calculator |
1219 |
if (pCkData->GetPos() == 0) { |
if (pCkData->GetPos() == 0) { |
1220 |
crc.reset(); |
__resetCRC(crc); |
1221 |
} |
} |
1222 |
if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small"); |
if (GetSize() < SampleCount) throw Exception("Could not write sample data, current sample size to small"); |
1223 |
unsigned long res; |
unsigned long res; |
1227 |
res = Channels == 2 ? pCkData->Write(pBuffer, SampleCount << 1, 2) >> 1 |
res = Channels == 2 ? pCkData->Write(pBuffer, SampleCount << 1, 2) >> 1 |
1228 |
: pCkData->Write(pBuffer, SampleCount, 2); |
: pCkData->Write(pBuffer, SampleCount, 2); |
1229 |
} |
} |
1230 |
crc.update((unsigned char *)pBuffer, SampleCount * FrameSize); |
__calculateCRC((unsigned char *)pBuffer, SampleCount * FrameSize, crc); |
1231 |
|
|
1232 |
// if this is the last write, update the checksum chunk in the |
// if this is the last write, update the checksum chunk in the |
1233 |
// file |
// file |
1234 |
if (pCkData->GetPos() == pCkData->GetSize()) { |
if (pCkData->GetPos() == pCkData->GetSize()) { |
1235 |
File* pFile = static_cast<File*>(GetParent()); |
File* pFile = static_cast<File*>(GetParent()); |
1236 |
pFile->SetSampleChecksum(this, crc.getValue()); |
pFile->SetSampleChecksum(this, __encodeCRC(crc)); |
1237 |
} |
} |
1238 |
return res; |
return res; |
1239 |
} |
} |
1433 |
: vcf_res_ctrl_none; |
: vcf_res_ctrl_none; |
1434 |
uint16_t eg3depth = _3ewa->ReadUint16(); |
uint16_t eg3depth = _3ewa->ReadUint16(); |
1435 |
EG3Depth = (eg3depth <= 1200) ? eg3depth /* positives */ |
EG3Depth = (eg3depth <= 1200) ? eg3depth /* positives */ |
1436 |
: (-1) * (int16_t) ((eg3depth ^ 0xffff) + 1); /* binary complementary for negatives */ |
: (-1) * (int16_t) ((eg3depth ^ 0xfff) + 1); /* binary complementary for negatives */ |
1437 |
_3ewa->ReadInt16(); // unknown |
_3ewa->ReadInt16(); // unknown |
1438 |
ChannelOffset = _3ewa->ReadUint8() / 4; |
ChannelOffset = _3ewa->ReadUint8() / 4; |
1439 |
uint8_t regoptions = _3ewa->ReadUint8(); |
uint8_t regoptions = _3ewa->ReadUint8(); |
1561 |
VelocityResponseDepth, |
VelocityResponseDepth, |
1562 |
VelocityResponseCurveScaling); |
VelocityResponseCurveScaling); |
1563 |
|
|
1564 |
curve_type_t curveType = ReleaseVelocityResponseCurve; |
pVelocityReleaseTable = GetReleaseVelocityTable( |
1565 |
uint8_t depth = ReleaseVelocityResponseDepth; |
ReleaseVelocityResponseCurve, |
1566 |
|
ReleaseVelocityResponseDepth |
1567 |
// this models a strange behaviour or bug in GSt: two of the |
); |
1568 |
// velocity response curves for release time are not used even |
|
1569 |
// if specified, instead another curve is chosen. |
pVelocityCutoffTable = GetCutoffVelocityTable(VCFVelocityCurve, |
1570 |
if ((curveType == curve_type_nonlinear && depth == 0) || |
VCFVelocityDynamicRange, |
1571 |
(curveType == curve_type_special && depth == 4)) { |
VCFVelocityScale, |
1572 |
curveType = curve_type_nonlinear; |
VCFCutoffController); |
|
depth = 3; |
|
|
} |
|
|
pVelocityReleaseTable = GetVelocityTable(curveType, depth, 0); |
|
|
|
|
|
curveType = VCFVelocityCurve; |
|
|
depth = VCFVelocityDynamicRange; |
|
|
|
|
|
// even stranger GSt: two of the velocity response curves for |
|
|
// filter cutoff are not used, instead another special curve |
|
|
// is chosen. This curve is not used anywhere else. |
|
|
if ((curveType == curve_type_nonlinear && depth == 0) || |
|
|
(curveType == curve_type_special && depth == 4)) { |
|
|
curveType = curve_type_special; |
|
|
depth = 5; |
|
|
} |
|
|
pVelocityCutoffTable = GetVelocityTable(curveType, depth, |
|
|
VCFCutoffController <= vcf_cutoff_ctrl_none2 ? VCFVelocityScale : 0); |
|
1573 |
|
|
1574 |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
1575 |
VelocityTable = 0; |
VelocityTable = 0; |
1581 |
*/ |
*/ |
1582 |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src) : DLS::Sampler(_3ewl) { |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src) : DLS::Sampler(_3ewl) { |
1583 |
Instances++; |
Instances++; |
1584 |
|
//NOTE: I think we cannot call CopyAssign() here (in a constructor) as long as its a virtual method |
1585 |
*this = src; // default memberwise shallow copy of all parameters |
*this = src; // default memberwise shallow copy of all parameters |
1586 |
pParentList = _3ewl; // restore the chunk pointer |
pParentList = _3ewl; // restore the chunk pointer |
1587 |
|
|
1597 |
pSampleLoops[k] = src.pSampleLoops[k]; |
pSampleLoops[k] = src.pSampleLoops[k]; |
1598 |
} |
} |
1599 |
} |
} |
1600 |
|
|
1601 |
|
/** |
1602 |
|
* Make a (semi) deep copy of the DimensionRegion object given by @a orig |
1603 |
|
* and assign it to this object. |
1604 |
|
* |
1605 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
1606 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
1607 |
|
* |
1608 |
|
* @param orig - original DimensionRegion object to be copied from |
1609 |
|
*/ |
1610 |
|
void DimensionRegion::CopyAssign(const DimensionRegion* orig) { |
1611 |
|
// delete all allocated data first |
1612 |
|
if (VelocityTable) delete [] VelocityTable; |
1613 |
|
if (pSampleLoops) delete [] pSampleLoops; |
1614 |
|
|
1615 |
|
// backup parent list pointer |
1616 |
|
RIFF::List* p = pParentList; |
1617 |
|
|
1618 |
|
//NOTE: copy code copied from assignment constructor above, see comment there as well |
1619 |
|
|
1620 |
|
*this = *orig; // default memberwise shallow copy of all parameters |
1621 |
|
pParentList = p; // restore the chunk pointer |
1622 |
|
|
1623 |
|
// deep copy of owned structures |
1624 |
|
if (orig->VelocityTable) { |
1625 |
|
VelocityTable = new uint8_t[128]; |
1626 |
|
for (int k = 0 ; k < 128 ; k++) |
1627 |
|
VelocityTable[k] = orig->VelocityTable[k]; |
1628 |
|
} |
1629 |
|
if (orig->pSampleLoops) { |
1630 |
|
pSampleLoops = new DLS::sample_loop_t[orig->SampleLoops]; |
1631 |
|
for (int k = 0 ; k < orig->SampleLoops ; k++) |
1632 |
|
pSampleLoops[k] = orig->pSampleLoops[k]; |
1633 |
|
} |
1634 |
|
} |
1635 |
|
|
1636 |
|
/** |
1637 |
|
* Updates the respective member variable and updates @c SampleAttenuation |
1638 |
|
* which depends on this value. |
1639 |
|
*/ |
1640 |
|
void DimensionRegion::SetGain(int32_t gain) { |
1641 |
|
DLS::Sampler::SetGain(gain); |
1642 |
|
SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360)); |
1643 |
|
} |
1644 |
|
|
1645 |
/** |
/** |
1646 |
* Apply dimension region settings to the respective RIFF chunks. You |
* Apply dimension region settings to the respective RIFF chunks. You |
1873 |
} |
} |
1874 |
|
|
1875 |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
1876 |
: uint16_t(((-EG3Depth) - 1) ^ 0xffff); /* binary complementary for negatives */ |
: uint16_t(((-EG3Depth) - 1) ^ 0xfff); /* binary complementary for negatives */ |
1877 |
pData[116] = eg3depth; |
store16(&pData[116], eg3depth); |
1878 |
|
|
1879 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1880 |
|
|
1921 |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
1922 |
pData[137] = vcfbreakpoint; |
pData[137] = vcfbreakpoint; |
1923 |
|
|
1924 |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 | |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 + |
1925 |
VCFVelocityCurve * 5; |
VCFVelocityCurve * 5; |
1926 |
pData[138] = vcfvelocity; |
pData[138] = vcfvelocity; |
1927 |
|
|
1933 |
} |
} |
1934 |
} |
} |
1935 |
|
|
1936 |
|
double* DimensionRegion::GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth) { |
1937 |
|
curve_type_t curveType = releaseVelocityResponseCurve; |
1938 |
|
uint8_t depth = releaseVelocityResponseDepth; |
1939 |
|
// this models a strange behaviour or bug in GSt: two of the |
1940 |
|
// velocity response curves for release time are not used even |
1941 |
|
// if specified, instead another curve is chosen. |
1942 |
|
if ((curveType == curve_type_nonlinear && depth == 0) || |
1943 |
|
(curveType == curve_type_special && depth == 4)) { |
1944 |
|
curveType = curve_type_nonlinear; |
1945 |
|
depth = 3; |
1946 |
|
} |
1947 |
|
return GetVelocityTable(curveType, depth, 0); |
1948 |
|
} |
1949 |
|
|
1950 |
|
double* DimensionRegion::GetCutoffVelocityTable(curve_type_t vcfVelocityCurve, |
1951 |
|
uint8_t vcfVelocityDynamicRange, |
1952 |
|
uint8_t vcfVelocityScale, |
1953 |
|
vcf_cutoff_ctrl_t vcfCutoffController) |
1954 |
|
{ |
1955 |
|
curve_type_t curveType = vcfVelocityCurve; |
1956 |
|
uint8_t depth = vcfVelocityDynamicRange; |
1957 |
|
// even stranger GSt: two of the velocity response curves for |
1958 |
|
// filter cutoff are not used, instead another special curve |
1959 |
|
// is chosen. This curve is not used anywhere else. |
1960 |
|
if ((curveType == curve_type_nonlinear && depth == 0) || |
1961 |
|
(curveType == curve_type_special && depth == 4)) { |
1962 |
|
curveType = curve_type_special; |
1963 |
|
depth = 5; |
1964 |
|
} |
1965 |
|
return GetVelocityTable(curveType, depth, |
1966 |
|
(vcfCutoffController <= vcf_cutoff_ctrl_none2) |
1967 |
|
? vcfVelocityScale : 0); |
1968 |
|
} |
1969 |
|
|
1970 |
// get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet |
// get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet |
1971 |
double* DimensionRegion::GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) |
double* DimensionRegion::GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) |
1972 |
{ |
{ |
2239 |
return pVelocityCutoffTable[MIDIKeyVelocity]; |
return pVelocityCutoffTable[MIDIKeyVelocity]; |
2240 |
} |
} |
2241 |
|
|
2242 |
|
/** |
2243 |
|
* Updates the respective member variable and the lookup table / cache |
2244 |
|
* that depends on this value. |
2245 |
|
*/ |
2246 |
|
void DimensionRegion::SetVelocityResponseCurve(curve_type_t curve) { |
2247 |
|
pVelocityAttenuationTable = |
2248 |
|
GetVelocityTable( |
2249 |
|
curve, VelocityResponseDepth, VelocityResponseCurveScaling |
2250 |
|
); |
2251 |
|
VelocityResponseCurve = curve; |
2252 |
|
} |
2253 |
|
|
2254 |
|
/** |
2255 |
|
* Updates the respective member variable and the lookup table / cache |
2256 |
|
* that depends on this value. |
2257 |
|
*/ |
2258 |
|
void DimensionRegion::SetVelocityResponseDepth(uint8_t depth) { |
2259 |
|
pVelocityAttenuationTable = |
2260 |
|
GetVelocityTable( |
2261 |
|
VelocityResponseCurve, depth, VelocityResponseCurveScaling |
2262 |
|
); |
2263 |
|
VelocityResponseDepth = depth; |
2264 |
|
} |
2265 |
|
|
2266 |
|
/** |
2267 |
|
* Updates the respective member variable and the lookup table / cache |
2268 |
|
* that depends on this value. |
2269 |
|
*/ |
2270 |
|
void DimensionRegion::SetVelocityResponseCurveScaling(uint8_t scaling) { |
2271 |
|
pVelocityAttenuationTable = |
2272 |
|
GetVelocityTable( |
2273 |
|
VelocityResponseCurve, VelocityResponseDepth, scaling |
2274 |
|
); |
2275 |
|
VelocityResponseCurveScaling = scaling; |
2276 |
|
} |
2277 |
|
|
2278 |
|
/** |
2279 |
|
* Updates the respective member variable and the lookup table / cache |
2280 |
|
* that depends on this value. |
2281 |
|
*/ |
2282 |
|
void DimensionRegion::SetReleaseVelocityResponseCurve(curve_type_t curve) { |
2283 |
|
pVelocityReleaseTable = GetReleaseVelocityTable(curve, ReleaseVelocityResponseDepth); |
2284 |
|
ReleaseVelocityResponseCurve = curve; |
2285 |
|
} |
2286 |
|
|
2287 |
|
/** |
2288 |
|
* Updates the respective member variable and the lookup table / cache |
2289 |
|
* that depends on this value. |
2290 |
|
*/ |
2291 |
|
void DimensionRegion::SetReleaseVelocityResponseDepth(uint8_t depth) { |
2292 |
|
pVelocityReleaseTable = GetReleaseVelocityTable(ReleaseVelocityResponseCurve, depth); |
2293 |
|
ReleaseVelocityResponseDepth = depth; |
2294 |
|
} |
2295 |
|
|
2296 |
|
/** |
2297 |
|
* Updates the respective member variable and the lookup table / cache |
2298 |
|
* that depends on this value. |
2299 |
|
*/ |
2300 |
|
void DimensionRegion::SetVCFCutoffController(vcf_cutoff_ctrl_t controller) { |
2301 |
|
pVelocityCutoffTable = GetCutoffVelocityTable(VCFVelocityCurve, VCFVelocityDynamicRange, VCFVelocityScale, controller); |
2302 |
|
VCFCutoffController = controller; |
2303 |
|
} |
2304 |
|
|
2305 |
|
/** |
2306 |
|
* Updates the respective member variable and the lookup table / cache |
2307 |
|
* that depends on this value. |
2308 |
|
*/ |
2309 |
|
void DimensionRegion::SetVCFVelocityCurve(curve_type_t curve) { |
2310 |
|
pVelocityCutoffTable = GetCutoffVelocityTable(curve, VCFVelocityDynamicRange, VCFVelocityScale, VCFCutoffController); |
2311 |
|
VCFVelocityCurve = curve; |
2312 |
|
} |
2313 |
|
|
2314 |
|
/** |
2315 |
|
* Updates the respective member variable and the lookup table / cache |
2316 |
|
* that depends on this value. |
2317 |
|
*/ |
2318 |
|
void DimensionRegion::SetVCFVelocityDynamicRange(uint8_t range) { |
2319 |
|
pVelocityCutoffTable = GetCutoffVelocityTable(VCFVelocityCurve, range, VCFVelocityScale, VCFCutoffController); |
2320 |
|
VCFVelocityDynamicRange = range; |
2321 |
|
} |
2322 |
|
|
2323 |
|
/** |
2324 |
|
* Updates the respective member variable and the lookup table / cache |
2325 |
|
* that depends on this value. |
2326 |
|
*/ |
2327 |
|
void DimensionRegion::SetVCFVelocityScale(uint8_t scaling) { |
2328 |
|
pVelocityCutoffTable = GetCutoffVelocityTable(VCFVelocityCurve, VCFVelocityDynamicRange, scaling, VCFCutoffController); |
2329 |
|
VCFVelocityScale = scaling; |
2330 |
|
} |
2331 |
|
|
2332 |
double* DimensionRegion::CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) { |
double* DimensionRegion::CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) { |
2333 |
|
|
2334 |
// line-segment approximations of the 15 velocity curves |
// line-segment approximations of the 15 velocity curves |
2412 |
|
|
2413 |
// Actual Loading |
// Actual Loading |
2414 |
|
|
2415 |
|
if (!file->GetAutoLoad()) return; |
2416 |
|
|
2417 |
LoadDimensionRegions(rgnList); |
LoadDimensionRegions(rgnList); |
2418 |
|
|
2419 |
RIFF::Chunk* _3lnk = rgnList->GetSubChunk(CHUNK_ID_3LNK); |
RIFF::Chunk* _3lnk = rgnList->GetSubChunk(CHUNK_ID_3LNK); |
2457 |
else |
else |
2458 |
_3lnk->SetPos(44); |
_3lnk->SetPos(44); |
2459 |
|
|
2460 |
// load sample references |
// load sample references (if auto loading is enabled) |
2461 |
for (uint i = 0; i < DimensionRegions; i++) { |
if (file->GetAutoLoad()) { |
2462 |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
for (uint i = 0; i < DimensionRegions; i++) { |
2463 |
if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
uint32_t wavepoolindex = _3lnk->ReadUint32(); |
2464 |
|
if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex); |
2465 |
|
} |
2466 |
|
GetSample(); // load global region sample reference |
2467 |
} |
} |
|
GetSample(); // load global region sample reference |
|
2468 |
} else { |
} else { |
2469 |
DimensionRegions = 0; |
DimensionRegions = 0; |
2470 |
for (int i = 0 ; i < 8 ; i++) { |
for (int i = 0 ; i < 8 ; i++) { |
2574 |
} |
} |
2575 |
} |
} |
2576 |
|
|
2577 |
|
void Region::SetKeyRange(uint16_t Low, uint16_t High) { |
2578 |
|
// update KeyRange struct and make sure regions are in correct order |
2579 |
|
DLS::Region::SetKeyRange(Low, High); |
2580 |
|
// update Region key table for fast lookup |
2581 |
|
((gig::Instrument*)GetParent())->UpdateRegionKeyTable(); |
2582 |
|
} |
2583 |
|
|
2584 |
void Region::UpdateVelocityTable() { |
void Region::UpdateVelocityTable() { |
2585 |
// get velocity dimension's index |
// get velocity dimension's index |
2586 |
int veldim = -1; |
int veldim = -1; |
2961 |
} |
} |
2962 |
return NULL; |
return NULL; |
2963 |
} |
} |
2964 |
|
|
2965 |
|
/** |
2966 |
|
* Make a (semi) deep copy of the Region object given by @a orig |
2967 |
|
* and assign it to this object. |
2968 |
|
* |
2969 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
2970 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
2971 |
|
* |
2972 |
|
* @param orig - original Region object to be copied from |
2973 |
|
*/ |
2974 |
|
void Region::CopyAssign(const Region* orig) { |
2975 |
|
// handle base classes |
2976 |
|
DLS::Region::CopyAssign(orig); |
2977 |
|
|
2978 |
|
// handle own member variables |
2979 |
|
for (int i = Dimensions - 1; i >= 0; --i) { |
2980 |
|
DeleteDimension(&pDimensionDefinitions[i]); |
2981 |
|
} |
2982 |
|
Layers = 0; // just to be sure |
2983 |
|
for (int i = 0; i < orig->Dimensions; i++) { |
2984 |
|
// we need to copy the dim definition here, to avoid the compiler |
2985 |
|
// complaining about const-ness issue |
2986 |
|
dimension_def_t def = orig->pDimensionDefinitions[i]; |
2987 |
|
AddDimension(&def); |
2988 |
|
} |
2989 |
|
for (int i = 0; i < 256; i++) { |
2990 |
|
if (pDimensionRegions[i] && orig->pDimensionRegions[i]) { |
2991 |
|
pDimensionRegions[i]->CopyAssign( |
2992 |
|
orig->pDimensionRegions[i] |
2993 |
|
); |
2994 |
|
} |
2995 |
|
} |
2996 |
|
Layers = orig->Layers; |
2997 |
|
} |
2998 |
|
|
2999 |
|
|
3000 |
|
// *************** MidiRule *************** |
3001 |
|
// * |
3002 |
|
|
3003 |
|
MidiRuleCtrlTrigger::MidiRuleCtrlTrigger(RIFF::Chunk* _3ewg) { |
3004 |
|
_3ewg->SetPos(36); |
3005 |
|
Triggers = _3ewg->ReadUint8(); |
3006 |
|
_3ewg->SetPos(40); |
3007 |
|
ControllerNumber = _3ewg->ReadUint8(); |
3008 |
|
_3ewg->SetPos(46); |
3009 |
|
for (int i = 0 ; i < Triggers ; i++) { |
3010 |
|
pTriggers[i].TriggerPoint = _3ewg->ReadUint8(); |
3011 |
|
pTriggers[i].Descending = _3ewg->ReadUint8(); |
3012 |
|
pTriggers[i].VelSensitivity = _3ewg->ReadUint8(); |
3013 |
|
pTriggers[i].Key = _3ewg->ReadUint8(); |
3014 |
|
pTriggers[i].NoteOff = _3ewg->ReadUint8(); |
3015 |
|
pTriggers[i].Velocity = _3ewg->ReadUint8(); |
3016 |
|
pTriggers[i].OverridePedal = _3ewg->ReadUint8(); |
3017 |
|
_3ewg->ReadUint8(); |
3018 |
|
} |
3019 |
|
} |
3020 |
|
|
3021 |
|
MidiRuleCtrlTrigger::MidiRuleCtrlTrigger() : |
3022 |
|
ControllerNumber(0), |
3023 |
|
Triggers(0) { |
3024 |
|
} |
3025 |
|
|
3026 |
|
void MidiRuleCtrlTrigger::UpdateChunks(uint8_t* pData) const { |
3027 |
|
pData[32] = 4; |
3028 |
|
pData[33] = 16; |
3029 |
|
pData[36] = Triggers; |
3030 |
|
pData[40] = ControllerNumber; |
3031 |
|
for (int i = 0 ; i < Triggers ; i++) { |
3032 |
|
pData[46 + i * 8] = pTriggers[i].TriggerPoint; |
3033 |
|
pData[47 + i * 8] = pTriggers[i].Descending; |
3034 |
|
pData[48 + i * 8] = pTriggers[i].VelSensitivity; |
3035 |
|
pData[49 + i * 8] = pTriggers[i].Key; |
3036 |
|
pData[50 + i * 8] = pTriggers[i].NoteOff; |
3037 |
|
pData[51 + i * 8] = pTriggers[i].Velocity; |
3038 |
|
pData[52 + i * 8] = pTriggers[i].OverridePedal; |
3039 |
|
} |
3040 |
|
} |
3041 |
|
|
3042 |
|
MidiRuleLegato::MidiRuleLegato(RIFF::Chunk* _3ewg) { |
3043 |
|
_3ewg->SetPos(36); |
3044 |
|
LegatoSamples = _3ewg->ReadUint8(); // always 12 |
3045 |
|
_3ewg->SetPos(40); |
3046 |
|
BypassUseController = _3ewg->ReadUint8(); |
3047 |
|
BypassKey = _3ewg->ReadUint8(); |
3048 |
|
BypassController = _3ewg->ReadUint8(); |
3049 |
|
ThresholdTime = _3ewg->ReadUint16(); |
3050 |
|
_3ewg->ReadInt16(); |
3051 |
|
ReleaseTime = _3ewg->ReadUint16(); |
3052 |
|
_3ewg->ReadInt16(); |
3053 |
|
KeyRange.low = _3ewg->ReadUint8(); |
3054 |
|
KeyRange.high = _3ewg->ReadUint8(); |
3055 |
|
_3ewg->SetPos(64); |
3056 |
|
ReleaseTriggerKey = _3ewg->ReadUint8(); |
3057 |
|
AltSustain1Key = _3ewg->ReadUint8(); |
3058 |
|
AltSustain2Key = _3ewg->ReadUint8(); |
3059 |
|
} |
3060 |
|
|
3061 |
|
MidiRuleLegato::MidiRuleLegato() : |
3062 |
|
LegatoSamples(12), |
3063 |
|
BypassUseController(false), |
3064 |
|
BypassKey(0), |
3065 |
|
BypassController(1), |
3066 |
|
ThresholdTime(20), |
3067 |
|
ReleaseTime(20), |
3068 |
|
ReleaseTriggerKey(0), |
3069 |
|
AltSustain1Key(0), |
3070 |
|
AltSustain2Key(0) |
3071 |
|
{ |
3072 |
|
KeyRange.low = KeyRange.high = 0; |
3073 |
|
} |
3074 |
|
|
3075 |
|
void MidiRuleLegato::UpdateChunks(uint8_t* pData) const { |
3076 |
|
pData[32] = 0; |
3077 |
|
pData[33] = 16; |
3078 |
|
pData[36] = LegatoSamples; |
3079 |
|
pData[40] = BypassUseController; |
3080 |
|
pData[41] = BypassKey; |
3081 |
|
pData[42] = BypassController; |
3082 |
|
store16(&pData[43], ThresholdTime); |
3083 |
|
store16(&pData[47], ReleaseTime); |
3084 |
|
pData[51] = KeyRange.low; |
3085 |
|
pData[52] = KeyRange.high; |
3086 |
|
pData[64] = ReleaseTriggerKey; |
3087 |
|
pData[65] = AltSustain1Key; |
3088 |
|
pData[66] = AltSustain2Key; |
3089 |
|
} |
3090 |
|
|
3091 |
|
MidiRuleAlternator::MidiRuleAlternator(RIFF::Chunk* _3ewg) { |
3092 |
|
_3ewg->SetPos(36); |
3093 |
|
Articulations = _3ewg->ReadUint8(); |
3094 |
|
int flags = _3ewg->ReadUint8(); |
3095 |
|
Polyphonic = flags & 8; |
3096 |
|
Chained = flags & 4; |
3097 |
|
Selector = (flags & 2) ? selector_controller : |
3098 |
|
(flags & 1) ? selector_key_switch : selector_none; |
3099 |
|
Patterns = _3ewg->ReadUint8(); |
3100 |
|
_3ewg->ReadUint8(); // chosen row |
3101 |
|
_3ewg->ReadUint8(); // unknown |
3102 |
|
_3ewg->ReadUint8(); // unknown |
3103 |
|
_3ewg->ReadUint8(); // unknown |
3104 |
|
KeySwitchRange.low = _3ewg->ReadUint8(); |
3105 |
|
KeySwitchRange.high = _3ewg->ReadUint8(); |
3106 |
|
Controller = _3ewg->ReadUint8(); |
3107 |
|
PlayRange.low = _3ewg->ReadUint8(); |
3108 |
|
PlayRange.high = _3ewg->ReadUint8(); |
3109 |
|
|
3110 |
|
int n = std::min(int(Articulations), 32); |
3111 |
|
for (int i = 0 ; i < n ; i++) { |
3112 |
|
_3ewg->ReadString(pArticulations[i], 32); |
3113 |
|
} |
3114 |
|
_3ewg->SetPos(1072); |
3115 |
|
n = std::min(int(Patterns), 32); |
3116 |
|
for (int i = 0 ; i < n ; i++) { |
3117 |
|
_3ewg->ReadString(pPatterns[i].Name, 16); |
3118 |
|
pPatterns[i].Size = _3ewg->ReadUint8(); |
3119 |
|
_3ewg->Read(&pPatterns[i][0], 1, 32); |
3120 |
|
} |
3121 |
|
} |
3122 |
|
|
3123 |
|
MidiRuleAlternator::MidiRuleAlternator() : |
3124 |
|
Articulations(0), |
3125 |
|
Patterns(0), |
3126 |
|
Selector(selector_none), |
3127 |
|
Controller(0), |
3128 |
|
Polyphonic(false), |
3129 |
|
Chained(false) |
3130 |
|
{ |
3131 |
|
PlayRange.low = PlayRange.high = 0; |
3132 |
|
KeySwitchRange.low = KeySwitchRange.high = 0; |
3133 |
|
} |
3134 |
|
|
3135 |
|
void MidiRuleAlternator::UpdateChunks(uint8_t* pData) const { |
3136 |
|
pData[32] = 3; |
3137 |
|
pData[33] = 16; |
3138 |
|
pData[36] = Articulations; |
3139 |
|
pData[37] = (Polyphonic ? 8 : 0) | (Chained ? 4 : 0) | |
3140 |
|
(Selector == selector_controller ? 2 : |
3141 |
|
(Selector == selector_key_switch ? 1 : 0)); |
3142 |
|
pData[38] = Patterns; |
3143 |
|
|
3144 |
|
pData[43] = KeySwitchRange.low; |
3145 |
|
pData[44] = KeySwitchRange.high; |
3146 |
|
pData[45] = Controller; |
3147 |
|
pData[46] = PlayRange.low; |
3148 |
|
pData[47] = PlayRange.high; |
3149 |
|
|
3150 |
|
char* str = reinterpret_cast<char*>(pData); |
3151 |
|
int pos = 48; |
3152 |
|
int n = std::min(int(Articulations), 32); |
3153 |
|
for (int i = 0 ; i < n ; i++, pos += 32) { |
3154 |
|
strncpy(&str[pos], pArticulations[i].c_str(), 32); |
3155 |
|
} |
3156 |
|
|
3157 |
|
pos = 1072; |
3158 |
|
n = std::min(int(Patterns), 32); |
3159 |
|
for (int i = 0 ; i < n ; i++, pos += 49) { |
3160 |
|
strncpy(&str[pos], pPatterns[i].Name.c_str(), 16); |
3161 |
|
pData[pos + 16] = pPatterns[i].Size; |
3162 |
|
memcpy(&pData[pos + 16], &(pPatterns[i][0]), 32); |
3163 |
|
} |
3164 |
|
} |
3165 |
|
|
3166 |
// *************** Instrument *************** |
// *************** Instrument *************** |
3167 |
// * |
// * |
3168 |
|
|
3169 |
Instrument::Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress) : DLS::Instrument((DLS::File*)pFile, insList) { |
Instrument::Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress) : DLS::Instrument((DLS::File*)pFile, insList) { |
3170 |
static const DLS::Info::FixedStringLength fixedStringLengths[] = { |
static const DLS::Info::string_length_t fixedStringLengths[] = { |
3171 |
{ CHUNK_ID_INAM, 64 }, |
{ CHUNK_ID_INAM, 64 }, |
3172 |
{ CHUNK_ID_ISFT, 12 }, |
{ CHUNK_ID_ISFT, 12 }, |
3173 |
{ 0, 0 } |
{ 0, 0 } |
3174 |
}; |
}; |
3175 |
pInfo->FixedStringLengths = fixedStringLengths; |
pInfo->SetFixedStringLengths(fixedStringLengths); |
3176 |
|
|
3177 |
// Initialization |
// Initialization |
3178 |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
3183 |
PianoReleaseMode = false; |
PianoReleaseMode = false; |
3184 |
DimensionKeyRange.low = 0; |
DimensionKeyRange.low = 0; |
3185 |
DimensionKeyRange.high = 0; |
DimensionKeyRange.high = 0; |
3186 |
|
pMidiRules = new MidiRule*[3]; |
3187 |
|
pMidiRules[0] = NULL; |
3188 |
|
|
3189 |
// Loading |
// Loading |
3190 |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); |
3199 |
PianoReleaseMode = dimkeystart & 0x01; |
PianoReleaseMode = dimkeystart & 0x01; |
3200 |
DimensionKeyRange.low = dimkeystart >> 1; |
DimensionKeyRange.low = dimkeystart >> 1; |
3201 |
DimensionKeyRange.high = _3ewg->ReadUint8(); |
DimensionKeyRange.high = _3ewg->ReadUint8(); |
3202 |
|
|
3203 |
|
if (_3ewg->GetSize() > 32) { |
3204 |
|
// read MIDI rules |
3205 |
|
int i = 0; |
3206 |
|
_3ewg->SetPos(32); |
3207 |
|
uint8_t id1 = _3ewg->ReadUint8(); |
3208 |
|
uint8_t id2 = _3ewg->ReadUint8(); |
3209 |
|
|
3210 |
|
if (id2 == 16) { |
3211 |
|
if (id1 == 4) { |
3212 |
|
pMidiRules[i++] = new MidiRuleCtrlTrigger(_3ewg); |
3213 |
|
} else if (id1 == 0) { |
3214 |
|
pMidiRules[i++] = new MidiRuleLegato(_3ewg); |
3215 |
|
} else if (id1 == 3) { |
3216 |
|
pMidiRules[i++] = new MidiRuleAlternator(_3ewg); |
3217 |
|
} else { |
3218 |
|
pMidiRules[i++] = new MidiRuleUnknown; |
3219 |
|
} |
3220 |
|
} |
3221 |
|
else if (id1 != 0 || id2 != 0) { |
3222 |
|
pMidiRules[i++] = new MidiRuleUnknown; |
3223 |
|
} |
3224 |
|
//TODO: all the other types of rules |
3225 |
|
|
3226 |
|
pMidiRules[i] = NULL; |
3227 |
|
} |
3228 |
} |
} |
3229 |
} |
} |
3230 |
|
|
3231 |
if (!pRegions) pRegions = new RegionList; |
if (pFile->GetAutoLoad()) { |
3232 |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
if (!pRegions) pRegions = new RegionList; |
3233 |
if (lrgn) { |
RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN); |
3234 |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
if (lrgn) { |
3235 |
while (rgn) { |
RIFF::List* rgn = lrgn->GetFirstSubList(); |
3236 |
if (rgn->GetListType() == LIST_TYPE_RGN) { |
while (rgn) { |
3237 |
__notify_progress(pProgress, (float) pRegions->size() / (float) Regions); |
if (rgn->GetListType() == LIST_TYPE_RGN) { |
3238 |
pRegions->push_back(new Region(this, rgn)); |
__notify_progress(pProgress, (float) pRegions->size() / (float) Regions); |
3239 |
|
pRegions->push_back(new Region(this, rgn)); |
3240 |
|
} |
3241 |
|
rgn = lrgn->GetNextSubList(); |
3242 |
} |
} |
3243 |
rgn = lrgn->GetNextSubList(); |
// Creating Region Key Table for fast lookup |
3244 |
|
UpdateRegionKeyTable(); |
3245 |
} |
} |
|
// Creating Region Key Table for fast lookup |
|
|
UpdateRegionKeyTable(); |
|
3246 |
} |
} |
3247 |
|
|
3248 |
__notify_progress(pProgress, 1.0f); // notify done |
__notify_progress(pProgress, 1.0f); // notify done |
3249 |
} |
} |
3250 |
|
|
3251 |
void Instrument::UpdateRegionKeyTable() { |
void Instrument::UpdateRegionKeyTable() { |
3252 |
|
for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; |
3253 |
RegionList::iterator iter = pRegions->begin(); |
RegionList::iterator iter = pRegions->begin(); |
3254 |
RegionList::iterator end = pRegions->end(); |
RegionList::iterator end = pRegions->end(); |
3255 |
for (; iter != end; ++iter) { |
for (; iter != end; ++iter) { |
3261 |
} |
} |
3262 |
|
|
3263 |
Instrument::~Instrument() { |
Instrument::~Instrument() { |
3264 |
|
for (int i = 0 ; pMidiRules[i] ; i++) { |
3265 |
|
delete pMidiRules[i]; |
3266 |
|
} |
3267 |
|
delete[] pMidiRules; |
3268 |
} |
} |
3269 |
|
|
3270 |
/** |
/** |
3311 |
DimensionKeyRange.low << 1; |
DimensionKeyRange.low << 1; |
3312 |
pData[10] = dimkeystart; |
pData[10] = dimkeystart; |
3313 |
pData[11] = DimensionKeyRange.high; |
pData[11] = DimensionKeyRange.high; |
3314 |
|
|
3315 |
|
if (pMidiRules[0] == 0 && _3ewg->GetSize() >= 34) { |
3316 |
|
pData[32] = 0; |
3317 |
|
pData[33] = 0; |
3318 |
|
} else { |
3319 |
|
for (int i = 0 ; pMidiRules[i] ; i++) { |
3320 |
|
pMidiRules[i]->UpdateChunks(pData); |
3321 |
|
} |
3322 |
|
} |
3323 |
} |
} |
3324 |
|
|
3325 |
/** |
/** |
3330 |
* there is no Region defined for the given \a Key |
* there is no Region defined for the given \a Key |
3331 |
*/ |
*/ |
3332 |
Region* Instrument::GetRegion(unsigned int Key) { |
Region* Instrument::GetRegion(unsigned int Key) { |
3333 |
if (!pRegions || !pRegions->size() || Key > 127) return NULL; |
if (!pRegions || pRegions->empty() || Key > 127) return NULL; |
3334 |
return RegionKeyTable[Key]; |
return RegionKeyTable[Key]; |
3335 |
|
|
3336 |
/*for (int i = 0; i < Regions; i++) { |
/*for (int i = 0; i < Regions; i++) { |
3388 |
UpdateRegionKeyTable(); |
UpdateRegionKeyTable(); |
3389 |
} |
} |
3390 |
|
|
3391 |
|
/** |
3392 |
|
* Returns a MIDI rule of the instrument. |
3393 |
|
* |
3394 |
|
* The list of MIDI rules, at least in gig v3, always contains at |
3395 |
|
* most two rules. The second rule can only be the DEF filter |
3396 |
|
* (which currently isn't supported by libgig). |
3397 |
|
* |
3398 |
|
* @param i - MIDI rule number |
3399 |
|
* @returns pointer address to MIDI rule number i or NULL if there is none |
3400 |
|
*/ |
3401 |
|
MidiRule* Instrument::GetMidiRule(int i) { |
3402 |
|
return pMidiRules[i]; |
3403 |
|
} |
3404 |
|
|
3405 |
|
/** |
3406 |
|
* Adds the "controller trigger" MIDI rule to the instrument. |
3407 |
|
* |
3408 |
|
* @returns the new MIDI rule |
3409 |
|
*/ |
3410 |
|
MidiRuleCtrlTrigger* Instrument::AddMidiRuleCtrlTrigger() { |
3411 |
|
delete pMidiRules[0]; |
3412 |
|
MidiRuleCtrlTrigger* r = new MidiRuleCtrlTrigger; |
3413 |
|
pMidiRules[0] = r; |
3414 |
|
pMidiRules[1] = 0; |
3415 |
|
return r; |
3416 |
|
} |
3417 |
|
|
3418 |
|
/** |
3419 |
|
* Adds the legato MIDI rule to the instrument. |
3420 |
|
* |
3421 |
|
* @returns the new MIDI rule |
3422 |
|
*/ |
3423 |
|
MidiRuleLegato* Instrument::AddMidiRuleLegato() { |
3424 |
|
delete pMidiRules[0]; |
3425 |
|
MidiRuleLegato* r = new MidiRuleLegato; |
3426 |
|
pMidiRules[0] = r; |
3427 |
|
pMidiRules[1] = 0; |
3428 |
|
return r; |
3429 |
|
} |
3430 |
|
|
3431 |
|
/** |
3432 |
|
* Adds the alternator MIDI rule to the instrument. |
3433 |
|
* |
3434 |
|
* @returns the new MIDI rule |
3435 |
|
*/ |
3436 |
|
MidiRuleAlternator* Instrument::AddMidiRuleAlternator() { |
3437 |
|
delete pMidiRules[0]; |
3438 |
|
MidiRuleAlternator* r = new MidiRuleAlternator; |
3439 |
|
pMidiRules[0] = r; |
3440 |
|
pMidiRules[1] = 0; |
3441 |
|
return r; |
3442 |
|
} |
3443 |
|
|
3444 |
|
/** |
3445 |
|
* Deletes a MIDI rule from the instrument. |
3446 |
|
* |
3447 |
|
* @param i - MIDI rule number |
3448 |
|
*/ |
3449 |
|
void Instrument::DeleteMidiRule(int i) { |
3450 |
|
delete pMidiRules[i]; |
3451 |
|
pMidiRules[i] = 0; |
3452 |
|
} |
3453 |
|
|
3454 |
|
/** |
3455 |
|
* Make a (semi) deep copy of the Instrument object given by @a orig |
3456 |
|
* and assign it to this object. |
3457 |
|
* |
3458 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
3459 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
3460 |
|
* |
3461 |
|
* @param orig - original Instrument object to be copied from |
3462 |
|
*/ |
3463 |
|
void Instrument::CopyAssign(const Instrument* orig) { |
3464 |
|
// handle base class |
3465 |
|
// (without copying DLS region stuff) |
3466 |
|
DLS::Instrument::CopyAssignCore(orig); |
3467 |
|
|
3468 |
|
// handle own member variables |
3469 |
|
Attenuation = orig->Attenuation; |
3470 |
|
EffectSend = orig->EffectSend; |
3471 |
|
FineTune = orig->FineTune; |
3472 |
|
PitchbendRange = orig->PitchbendRange; |
3473 |
|
PianoReleaseMode = orig->PianoReleaseMode; |
3474 |
|
DimensionKeyRange = orig->DimensionKeyRange; |
3475 |
|
|
3476 |
|
// free old midi rules |
3477 |
|
for (int i = 0 ; pMidiRules[i] ; i++) { |
3478 |
|
delete pMidiRules[i]; |
3479 |
|
} |
3480 |
|
//TODO: MIDI rule copying |
3481 |
|
pMidiRules[0] = NULL; |
3482 |
|
|
3483 |
|
// delete all old regions |
3484 |
|
while (Regions) DeleteRegion(GetFirstRegion()); |
3485 |
|
// create new regions and copy them from original |
3486 |
|
{ |
3487 |
|
RegionList::const_iterator it = orig->pRegions->begin(); |
3488 |
|
for (int i = 0; i < orig->Regions; ++i, ++it) { |
3489 |
|
Region* dstRgn = AddRegion(); |
3490 |
|
//NOTE: Region does semi-deep copy ! |
3491 |
|
dstRgn->CopyAssign( |
3492 |
|
static_cast<gig::Region*>(*it) |
3493 |
|
); |
3494 |
|
} |
3495 |
|
} |
3496 |
|
|
3497 |
|
UpdateRegionKeyTable(); |
3498 |
|
} |
3499 |
|
|
3500 |
|
|
3501 |
// *************** Group *************** |
// *************** Group *************** |
3621 |
// *************** File *************** |
// *************** File *************** |
3622 |
// * |
// * |
3623 |
|
|
3624 |
// File version 2.0, 1998-06-28 |
/// Reflects Gigasampler file format version 2.0 (1998-06-28). |
3625 |
const DLS::version_t File::VERSION_2 = { |
const DLS::version_t File::VERSION_2 = { |
3626 |
0, 2, 19980628 & 0xffff, 19980628 >> 16 |
0, 2, 19980628 & 0xffff, 19980628 >> 16 |
3627 |
}; |
}; |
3628 |
|
|
3629 |
// File version 3.0, 2003-03-31 |
/// Reflects Gigasampler file format version 3.0 (2003-03-31). |
3630 |
const DLS::version_t File::VERSION_3 = { |
const DLS::version_t File::VERSION_3 = { |
3631 |
0, 3, 20030331 & 0xffff, 20030331 >> 16 |
0, 3, 20030331 & 0xffff, 20030331 >> 16 |
3632 |
}; |
}; |
3633 |
|
|
3634 |
const DLS::Info::FixedStringLength File::FixedStringLengths[] = { |
static const DLS::Info::string_length_t _FileFixedStringLengths[] = { |
3635 |
{ CHUNK_ID_IARL, 256 }, |
{ CHUNK_ID_IARL, 256 }, |
3636 |
{ CHUNK_ID_IART, 128 }, |
{ CHUNK_ID_IART, 128 }, |
3637 |
{ CHUNK_ID_ICMS, 128 }, |
{ CHUNK_ID_ICMS, 128 }, |
3653 |
}; |
}; |
3654 |
|
|
3655 |
File::File() : DLS::File() { |
File::File() : DLS::File() { |
3656 |
|
bAutoLoad = true; |
3657 |
*pVersion = VERSION_3; |
*pVersion = VERSION_3; |
3658 |
pGroups = NULL; |
pGroups = NULL; |
3659 |
pInfo->FixedStringLengths = FixedStringLengths; |
pInfo->SetFixedStringLengths(_FileFixedStringLengths); |
3660 |
pInfo->ArchivalLocation = String(256, ' '); |
pInfo->ArchivalLocation = String(256, ' '); |
3661 |
|
|
3662 |
// add some mandatory chunks to get the file chunks in right |
// add some mandatory chunks to get the file chunks in right |
3669 |
} |
} |
3670 |
|
|
3671 |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { |
3672 |
|
bAutoLoad = true; |
3673 |
pGroups = NULL; |
pGroups = NULL; |
3674 |
pInfo->FixedStringLengths = FixedStringLengths; |
pInfo->SetFixedStringLengths(_FileFixedStringLengths); |
3675 |
} |
} |
3676 |
|
|
3677 |
File::~File() { |
File::~File() { |
3739 |
pSamples->erase(iter); |
pSamples->erase(iter); |
3740 |
delete pSample; |
delete pSample; |
3741 |
|
|
3742 |
|
SampleList::iterator tmp = SamplesIterator; |
3743 |
// remove all references to the sample |
// remove all references to the sample |
3744 |
for (Instrument* instrument = GetFirstInstrument() ; instrument ; |
for (Instrument* instrument = GetFirstInstrument() ; instrument ; |
3745 |
instrument = GetNextInstrument()) { |
instrument = GetNextInstrument()) { |
3754 |
} |
} |
3755 |
} |
} |
3756 |
} |
} |
3757 |
|
SamplesIterator = tmp; // restore iterator |
3758 |
} |
} |
3759 |
|
|
3760 |
void File::LoadSamples() { |
void File::LoadSamples() { |
3845 |
progress_t subprogress; |
progress_t subprogress; |
3846 |
__divide_progress(pProgress, &subprogress, 3.0f, 0.0f); // randomly schedule 33% for this subtask |
__divide_progress(pProgress, &subprogress, 3.0f, 0.0f); // randomly schedule 33% for this subtask |
3847 |
__notify_progress(&subprogress, 0.0f); |
__notify_progress(&subprogress, 0.0f); |
3848 |
GetFirstSample(&subprogress); // now force all samples to be loaded |
if (GetAutoLoad()) |
3849 |
|
GetFirstSample(&subprogress); // now force all samples to be loaded |
3850 |
__notify_progress(&subprogress, 1.0f); |
__notify_progress(&subprogress, 1.0f); |
3851 |
|
|
3852 |
// instrument loading subtask |
// instrument loading subtask |
3895 |
pInstruments->push_back(pInstrument); |
pInstruments->push_back(pInstrument); |
3896 |
return pInstrument; |
return pInstrument; |
3897 |
} |
} |
3898 |
|
|
3899 |
|
/** @brief Add a duplicate of an existing instrument. |
3900 |
|
* |
3901 |
|
* Duplicates the instrument definition given by @a orig and adds it |
3902 |
|
* to this file. This allows in an instrument editor application to |
3903 |
|
* easily create variations of an instrument, which will be stored in |
3904 |
|
* the same .gig file, sharing i.e. the same samples. |
3905 |
|
* |
3906 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
3907 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
3908 |
|
* |
3909 |
|
* You have to call Save() to make this persistent to the file. |
3910 |
|
* |
3911 |
|
* @param orig - original instrument to be copied |
3912 |
|
* @returns duplicated copy of the given instrument |
3913 |
|
*/ |
3914 |
|
Instrument* File::AddDuplicateInstrument(const Instrument* orig) { |
3915 |
|
Instrument* instr = AddInstrument(); |
3916 |
|
instr->CopyAssign(orig); |
3917 |
|
return instr; |
3918 |
|
} |
3919 |
|
|
3920 |
/** @brief Delete an instrument. |
/** @brief Delete an instrument. |
3921 |
* |
* |
4128 |
|
|
4129 |
// update group's chunks |
// update group's chunks |
4130 |
if (pGroups) { |
if (pGroups) { |
4131 |
std::list<Group*>::iterator iter = pGroups->begin(); |
// make sure '3gri' and '3gnl' list chunks exist |
4132 |
std::list<Group*>::iterator end = pGroups->end(); |
// (before updating the Group chunks) |
4133 |
for (; iter != end; ++iter) { |
RIFF::List* _3gri = pRIFF->GetSubList(LIST_TYPE_3GRI); |
4134 |
(*iter)->UpdateChunks(); |
if (!_3gri) { |
4135 |
|
_3gri = pRIFF->AddSubList(LIST_TYPE_3GRI); |
4136 |
|
pRIFF->MoveSubChunk(_3gri, pRIFF->GetSubChunk(CHUNK_ID_PTBL)); |
4137 |
} |
} |
4138 |
|
RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); |
4139 |
|
if (!_3gnl) _3gnl = _3gri->AddSubList(LIST_TYPE_3GNL); |
4140 |
|
|
4141 |
// v3: make sure the file has 128 3gnm chunks |
// v3: make sure the file has 128 3gnm chunks |
4142 |
|
// (before updating the Group chunks) |
4143 |
if (pVersion && pVersion->major == 3) { |
if (pVersion && pVersion->major == 3) { |
|
RIFF::List* _3gnl = pRIFF->GetSubList(LIST_TYPE_3GRI)->GetSubList(LIST_TYPE_3GNL); |
|
4144 |
RIFF::Chunk* _3gnm = _3gnl->GetFirstSubChunk(); |
RIFF::Chunk* _3gnm = _3gnl->GetFirstSubChunk(); |
4145 |
for (int i = 0 ; i < 128 ; i++) { |
for (int i = 0 ; i < 128 ; i++) { |
4146 |
if (i >= pGroups->size()) ::SaveString(CHUNK_ID_3GNM, _3gnm, _3gnl, "", "", true, 64); |
if (i >= pGroups->size()) ::SaveString(CHUNK_ID_3GNM, _3gnm, _3gnl, "", "", true, 64); |
4147 |
if (_3gnm) _3gnm = _3gnl->GetNextSubChunk(); |
if (_3gnm) _3gnm = _3gnl->GetNextSubChunk(); |
4148 |
} |
} |
4149 |
} |
} |
4150 |
|
|
4151 |
|
std::list<Group*>::iterator iter = pGroups->begin(); |
4152 |
|
std::list<Group*>::iterator end = pGroups->end(); |
4153 |
|
for (; iter != end; ++iter) { |
4154 |
|
(*iter)->UpdateChunks(); |
4155 |
|
} |
4156 |
} |
} |
4157 |
|
|
4158 |
// update einf chunk |
// update einf chunk |
4284 |
} |
} |
4285 |
} |
} |
4286 |
|
|
4287 |
|
/** |
4288 |
|
* Enable / disable automatic loading. By default this properyt is |
4289 |
|
* enabled and all informations are loaded automatically. However |
4290 |
|
* loading all Regions, DimensionRegions and especially samples might |
4291 |
|
* take a long time for large .gig files, and sometimes one might only |
4292 |
|
* be interested in retrieving very superficial informations like the |
4293 |
|
* amount of instruments and their names. In this case one might disable |
4294 |
|
* automatic loading to avoid very slow response times. |
4295 |
|
* |
4296 |
|
* @e CAUTION: by disabling this property many pointers (i.e. sample |
4297 |
|
* references) and informations will have invalid or even undefined |
4298 |
|
* data! This feature is currently only intended for retrieving very |
4299 |
|
* superficial informations in a very fast way. Don't use it to retrieve |
4300 |
|
* details like synthesis informations or even to modify .gig files! |
4301 |
|
*/ |
4302 |
|
void File::SetAutoLoad(bool b) { |
4303 |
|
bAutoLoad = b; |
4304 |
|
} |
4305 |
|
|
4306 |
|
/** |
4307 |
|
* Returns whether automatic loading is enabled. |
4308 |
|
* @see SetAutoLoad() |
4309 |
|
*/ |
4310 |
|
bool File::GetAutoLoad() { |
4311 |
|
return bAutoLoad; |
4312 |
|
} |
4313 |
|
|
4314 |
|
|
4315 |
|
|
4316 |
// *************** Exception *************** |
// *************** Exception *************** |