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-2014 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 * |
454 |
} |
} |
455 |
|
|
456 |
/** |
/** |
457 |
|
* Make a (semi) deep copy of the Sample object given by @a orig (without |
458 |
|
* the actual waveform data) and assign it to this object. |
459 |
|
* |
460 |
|
* Discussion: copying .gig samples is a bit tricky. It requires three |
461 |
|
* steps: |
462 |
|
* 1. Copy sample's meta informations (done by CopyAssignMeta()) including |
463 |
|
* its new sample waveform data size. |
464 |
|
* 2. Saving the file (done by File::Save()) so that it gains correct size |
465 |
|
* and layout for writing the actual wave form data directly to disc |
466 |
|
* in next step. |
467 |
|
* 3. Copy the waveform data with disk streaming (done by CopyAssignWave()). |
468 |
|
* |
469 |
|
* @param orig - original Sample object to be copied from |
470 |
|
*/ |
471 |
|
void Sample::CopyAssignMeta(const Sample* orig) { |
472 |
|
// handle base classes |
473 |
|
DLS::Sample::CopyAssignCore(orig); |
474 |
|
|
475 |
|
// handle actual own attributes of this class |
476 |
|
Manufacturer = orig->Manufacturer; |
477 |
|
Product = orig->Product; |
478 |
|
SamplePeriod = orig->SamplePeriod; |
479 |
|
MIDIUnityNote = orig->MIDIUnityNote; |
480 |
|
FineTune = orig->FineTune; |
481 |
|
SMPTEFormat = orig->SMPTEFormat; |
482 |
|
SMPTEOffset = orig->SMPTEOffset; |
483 |
|
Loops = orig->Loops; |
484 |
|
LoopID = orig->LoopID; |
485 |
|
LoopType = orig->LoopType; |
486 |
|
LoopStart = orig->LoopStart; |
487 |
|
LoopEnd = orig->LoopEnd; |
488 |
|
LoopSize = orig->LoopSize; |
489 |
|
LoopFraction = orig->LoopFraction; |
490 |
|
LoopPlayCount = orig->LoopPlayCount; |
491 |
|
|
492 |
|
// schedule resizing this sample to the given sample's size |
493 |
|
Resize(orig->GetSize()); |
494 |
|
} |
495 |
|
|
496 |
|
/** |
497 |
|
* Should be called after CopyAssignMeta() and File::Save() sequence. |
498 |
|
* Read more about it in the discussion of CopyAssignMeta(). This method |
499 |
|
* copies the actual waveform data by disk streaming. |
500 |
|
* |
501 |
|
* @e CAUTION: this method is currently not thread safe! During this |
502 |
|
* operation the sample must not be used for other purposes by other |
503 |
|
* threads! |
504 |
|
* |
505 |
|
* @param orig - original Sample object to be copied from |
506 |
|
*/ |
507 |
|
void Sample::CopyAssignWave(const Sample* orig) { |
508 |
|
const int iReadAtOnce = 32*1024; |
509 |
|
char* buf = new char[iReadAtOnce * orig->FrameSize]; |
510 |
|
Sample* pOrig = (Sample*) orig; //HACK: remove constness for now |
511 |
|
unsigned long restorePos = pOrig->GetPos(); |
512 |
|
pOrig->SetPos(0); |
513 |
|
SetPos(0); |
514 |
|
for (unsigned long n = pOrig->Read(buf, iReadAtOnce); n; |
515 |
|
n = pOrig->Read(buf, iReadAtOnce)) |
516 |
|
{ |
517 |
|
Write(buf, n); |
518 |
|
} |
519 |
|
pOrig->SetPos(restorePos); |
520 |
|
delete [] buf; |
521 |
|
} |
522 |
|
|
523 |
|
/** |
524 |
* Apply sample and its settings to the respective RIFF chunks. You have |
* Apply sample and its settings to the respective RIFF chunks. You have |
525 |
* to call File::Save() to make changes persistent. |
* to call File::Save() to make changes persistent. |
526 |
* |
* |
581 |
// update '3gix' chunk |
// update '3gix' chunk |
582 |
pData = (uint8_t*) pCk3gix->LoadChunkData(); |
pData = (uint8_t*) pCk3gix->LoadChunkData(); |
583 |
store16(&pData[0], iSampleGroup); |
store16(&pData[0], iSampleGroup); |
584 |
|
|
585 |
|
// if the library user toggled the "Compressed" attribute from true to |
586 |
|
// false, then the EWAV chunk associated with compressed samples needs |
587 |
|
// to be deleted |
588 |
|
RIFF::Chunk* ewav = pWaveList->GetSubChunk(CHUNK_ID_EWAV); |
589 |
|
if (ewav && !Compressed) { |
590 |
|
pWaveList->DeleteSubChunk(ewav); |
591 |
|
} |
592 |
} |
} |
593 |
|
|
594 |
/// Scans compressed samples for mandatory informations (e.g. actual number of total sample points). |
/// Scans compressed samples for mandatory informations (e.g. actual number of total sample points). |
752 |
if (SampleCount > this->SamplesTotal) SampleCount = this->SamplesTotal; |
if (SampleCount > this->SamplesTotal) SampleCount = this->SamplesTotal; |
753 |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
754 |
unsigned long allocationsize = (SampleCount + NullSamplesCount) * this->FrameSize; |
unsigned long allocationsize = (SampleCount + NullSamplesCount) * this->FrameSize; |
755 |
|
SetPos(0); // reset read position to begin of sample |
756 |
RAMCache.pStart = new int8_t[allocationsize]; |
RAMCache.pStart = new int8_t[allocationsize]; |
757 |
RAMCache.Size = Read(RAMCache.pStart, SampleCount) * this->FrameSize; |
RAMCache.Size = Read(RAMCache.pStart, SampleCount) * this->FrameSize; |
758 |
RAMCache.NullExtensionSize = allocationsize - RAMCache.Size; |
RAMCache.NullExtensionSize = allocationsize - RAMCache.Size; |
790 |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
if (RAMCache.pStart) delete[] (int8_t*) RAMCache.pStart; |
791 |
RAMCache.pStart = NULL; |
RAMCache.pStart = NULL; |
792 |
RAMCache.Size = 0; |
RAMCache.Size = 0; |
793 |
|
RAMCache.NullExtensionSize = 0; |
794 |
} |
} |
795 |
|
|
796 |
/** @brief Resize sample. |
/** @brief Resize sample. |
883 |
/** |
/** |
884 |
* Returns the current position in the sample (in sample points). |
* Returns the current position in the sample (in sample points). |
885 |
*/ |
*/ |
886 |
unsigned long Sample::GetPos() { |
unsigned long Sample::GetPos() const { |
887 |
if (Compressed) return SamplePos; |
if (Compressed) return SamplePos; |
888 |
else return pCkData->GetPos() / FrameSize; |
else return pCkData->GetPos() / FrameSize; |
889 |
} |
} |
985 |
} |
} |
986 |
|
|
987 |
// reverse the sample frames for backward playback |
// reverse the sample frames for backward playback |
988 |
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! |
989 |
|
SwapMemoryArea(&pDst[swapareastart * this->FrameSize], (totalreadsamples - swapareastart) * this->FrameSize, this->FrameSize); |
990 |
} |
} |
991 |
} while (samplestoread && readsamples); |
} while (samplestoread && readsamples); |
992 |
break; |
break; |
1508 |
: vcf_res_ctrl_none; |
: vcf_res_ctrl_none; |
1509 |
uint16_t eg3depth = _3ewa->ReadUint16(); |
uint16_t eg3depth = _3ewa->ReadUint16(); |
1510 |
EG3Depth = (eg3depth <= 1200) ? eg3depth /* positives */ |
EG3Depth = (eg3depth <= 1200) ? eg3depth /* positives */ |
1511 |
: (-1) * (int16_t) ((eg3depth ^ 0xffff) + 1); /* binary complementary for negatives */ |
: (-1) * (int16_t) ((eg3depth ^ 0xfff) + 1); /* binary complementary for negatives */ |
1512 |
_3ewa->ReadInt16(); // unknown |
_3ewa->ReadInt16(); // unknown |
1513 |
ChannelOffset = _3ewa->ReadUint8() / 4; |
ChannelOffset = _3ewa->ReadUint8() / 4; |
1514 |
uint8_t regoptions = _3ewa->ReadUint8(); |
uint8_t regoptions = _3ewa->ReadUint8(); |
1656 |
*/ |
*/ |
1657 |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src) : DLS::Sampler(_3ewl) { |
DimensionRegion::DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src) : DLS::Sampler(_3ewl) { |
1658 |
Instances++; |
Instances++; |
1659 |
|
//NOTE: I think we cannot call CopyAssign() here (in a constructor) as long as its a virtual method |
1660 |
*this = src; // default memberwise shallow copy of all parameters |
*this = src; // default memberwise shallow copy of all parameters |
1661 |
pParentList = _3ewl; // restore the chunk pointer |
pParentList = _3ewl; // restore the chunk pointer |
1662 |
|
|
1672 |
pSampleLoops[k] = src.pSampleLoops[k]; |
pSampleLoops[k] = src.pSampleLoops[k]; |
1673 |
} |
} |
1674 |
} |
} |
1675 |
|
|
1676 |
|
/** |
1677 |
|
* Make a (semi) deep copy of the DimensionRegion object given by @a orig |
1678 |
|
* and assign it to this object. |
1679 |
|
* |
1680 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
1681 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
1682 |
|
* |
1683 |
|
* @param orig - original DimensionRegion object to be copied from |
1684 |
|
*/ |
1685 |
|
void DimensionRegion::CopyAssign(const DimensionRegion* orig) { |
1686 |
|
CopyAssign(orig, NULL); |
1687 |
|
} |
1688 |
|
|
1689 |
|
/** |
1690 |
|
* Make a (semi) deep copy of the DimensionRegion object given by @a orig |
1691 |
|
* and assign it to this object. |
1692 |
|
* |
1693 |
|
* @param orig - original DimensionRegion object to be copied from |
1694 |
|
* @param mSamples - crosslink map between the foreign file's samples and |
1695 |
|
* this file's samples |
1696 |
|
*/ |
1697 |
|
void DimensionRegion::CopyAssign(const DimensionRegion* orig, const std::map<Sample*,Sample*>* mSamples) { |
1698 |
|
// delete all allocated data first |
1699 |
|
if (VelocityTable) delete [] VelocityTable; |
1700 |
|
if (pSampleLoops) delete [] pSampleLoops; |
1701 |
|
|
1702 |
|
// backup parent list pointer |
1703 |
|
RIFF::List* p = pParentList; |
1704 |
|
|
1705 |
|
gig::Sample* pOriginalSample = pSample; |
1706 |
|
gig::Region* pOriginalRegion = pRegion; |
1707 |
|
|
1708 |
|
//NOTE: copy code copied from assignment constructor above, see comment there as well |
1709 |
|
|
1710 |
|
*this = *orig; // default memberwise shallow copy of all parameters |
1711 |
|
pParentList = p; // restore the chunk pointer |
1712 |
|
|
1713 |
|
// only take the raw sample reference & parent region reference if the |
1714 |
|
// two DimensionRegion objects are part of the same file |
1715 |
|
if (pOriginalRegion->GetParent()->GetParent() != orig->pRegion->GetParent()->GetParent()) { |
1716 |
|
pRegion = pOriginalRegion; |
1717 |
|
pSample = pOriginalSample; |
1718 |
|
} |
1719 |
|
|
1720 |
|
if (mSamples && mSamples->count(orig->pSample)) { |
1721 |
|
pSample = mSamples->find(orig->pSample)->second; |
1722 |
|
} |
1723 |
|
|
1724 |
|
// deep copy of owned structures |
1725 |
|
if (orig->VelocityTable) { |
1726 |
|
VelocityTable = new uint8_t[128]; |
1727 |
|
for (int k = 0 ; k < 128 ; k++) |
1728 |
|
VelocityTable[k] = orig->VelocityTable[k]; |
1729 |
|
} |
1730 |
|
if (orig->pSampleLoops) { |
1731 |
|
pSampleLoops = new DLS::sample_loop_t[orig->SampleLoops]; |
1732 |
|
for (int k = 0 ; k < orig->SampleLoops ; k++) |
1733 |
|
pSampleLoops[k] = orig->pSampleLoops[k]; |
1734 |
|
} |
1735 |
|
} |
1736 |
|
|
1737 |
/** |
/** |
1738 |
* Updates the respective member variable and updates @c SampleAttenuation |
* Updates the respective member variable and updates @c SampleAttenuation |
1974 |
} |
} |
1975 |
|
|
1976 |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth |
1977 |
: uint16_t(((-EG3Depth) - 1) ^ 0xffff); /* binary complementary for negatives */ |
: uint16_t(((-EG3Depth) - 1) ^ 0xfff); /* binary complementary for negatives */ |
1978 |
pData[116] = eg3depth; |
store16(&pData[116], eg3depth); |
1979 |
|
|
1980 |
// next 2 bytes unknown |
// next 2 bytes unknown |
1981 |
|
|
2022 |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
(VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */ |
2023 |
pData[137] = vcfbreakpoint; |
pData[137] = vcfbreakpoint; |
2024 |
|
|
2025 |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 | |
const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 + |
2026 |
VCFVelocityCurve * 5; |
VCFVelocityCurve * 5; |
2027 |
pData[138] = vcfvelocity; |
pData[138] = vcfvelocity; |
2028 |
|
|
2087 |
return pRegion; |
return pRegion; |
2088 |
} |
} |
2089 |
|
|
2090 |
|
// show error if some _lev_ctrl_* enum entry is not listed in the following function |
2091 |
|
// (commented out for now, because "diagnostic push" not supported prior GCC 4.6) |
2092 |
|
// TODO: uncomment and add a GCC version check (see also commented "#pragma GCC diagnostic pop" below) |
2093 |
|
//#pragma GCC diagnostic push |
2094 |
|
//#pragma GCC diagnostic error "-Wswitch" |
2095 |
|
|
2096 |
leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) { |
leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) { |
2097 |
leverage_ctrl_t decodedcontroller; |
leverage_ctrl_t decodedcontroller; |
2098 |
switch (EncodedController) { |
switch (EncodedController) { |
2204 |
decodedcontroller.controller_number = 95; |
decodedcontroller.controller_number = 95; |
2205 |
break; |
break; |
2206 |
|
|
2207 |
|
// format extension (these controllers are so far only supported by |
2208 |
|
// LinuxSampler & gigedit) they will *NOT* work with |
2209 |
|
// Gigasampler/GigaStudio ! |
2210 |
|
case _lev_ctrl_CC3_EXT: |
2211 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2212 |
|
decodedcontroller.controller_number = 3; |
2213 |
|
break; |
2214 |
|
case _lev_ctrl_CC6_EXT: |
2215 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2216 |
|
decodedcontroller.controller_number = 6; |
2217 |
|
break; |
2218 |
|
case _lev_ctrl_CC7_EXT: |
2219 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2220 |
|
decodedcontroller.controller_number = 7; |
2221 |
|
break; |
2222 |
|
case _lev_ctrl_CC8_EXT: |
2223 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2224 |
|
decodedcontroller.controller_number = 8; |
2225 |
|
break; |
2226 |
|
case _lev_ctrl_CC9_EXT: |
2227 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2228 |
|
decodedcontroller.controller_number = 9; |
2229 |
|
break; |
2230 |
|
case _lev_ctrl_CC10_EXT: |
2231 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2232 |
|
decodedcontroller.controller_number = 10; |
2233 |
|
break; |
2234 |
|
case _lev_ctrl_CC11_EXT: |
2235 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2236 |
|
decodedcontroller.controller_number = 11; |
2237 |
|
break; |
2238 |
|
case _lev_ctrl_CC14_EXT: |
2239 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2240 |
|
decodedcontroller.controller_number = 14; |
2241 |
|
break; |
2242 |
|
case _lev_ctrl_CC15_EXT: |
2243 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2244 |
|
decodedcontroller.controller_number = 15; |
2245 |
|
break; |
2246 |
|
case _lev_ctrl_CC20_EXT: |
2247 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2248 |
|
decodedcontroller.controller_number = 20; |
2249 |
|
break; |
2250 |
|
case _lev_ctrl_CC21_EXT: |
2251 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2252 |
|
decodedcontroller.controller_number = 21; |
2253 |
|
break; |
2254 |
|
case _lev_ctrl_CC22_EXT: |
2255 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2256 |
|
decodedcontroller.controller_number = 22; |
2257 |
|
break; |
2258 |
|
case _lev_ctrl_CC23_EXT: |
2259 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2260 |
|
decodedcontroller.controller_number = 23; |
2261 |
|
break; |
2262 |
|
case _lev_ctrl_CC24_EXT: |
2263 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2264 |
|
decodedcontroller.controller_number = 24; |
2265 |
|
break; |
2266 |
|
case _lev_ctrl_CC25_EXT: |
2267 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2268 |
|
decodedcontroller.controller_number = 25; |
2269 |
|
break; |
2270 |
|
case _lev_ctrl_CC26_EXT: |
2271 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2272 |
|
decodedcontroller.controller_number = 26; |
2273 |
|
break; |
2274 |
|
case _lev_ctrl_CC27_EXT: |
2275 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2276 |
|
decodedcontroller.controller_number = 27; |
2277 |
|
break; |
2278 |
|
case _lev_ctrl_CC28_EXT: |
2279 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2280 |
|
decodedcontroller.controller_number = 28; |
2281 |
|
break; |
2282 |
|
case _lev_ctrl_CC29_EXT: |
2283 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2284 |
|
decodedcontroller.controller_number = 29; |
2285 |
|
break; |
2286 |
|
case _lev_ctrl_CC30_EXT: |
2287 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2288 |
|
decodedcontroller.controller_number = 30; |
2289 |
|
break; |
2290 |
|
case _lev_ctrl_CC31_EXT: |
2291 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2292 |
|
decodedcontroller.controller_number = 31; |
2293 |
|
break; |
2294 |
|
case _lev_ctrl_CC68_EXT: |
2295 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2296 |
|
decodedcontroller.controller_number = 68; |
2297 |
|
break; |
2298 |
|
case _lev_ctrl_CC69_EXT: |
2299 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2300 |
|
decodedcontroller.controller_number = 69; |
2301 |
|
break; |
2302 |
|
case _lev_ctrl_CC70_EXT: |
2303 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2304 |
|
decodedcontroller.controller_number = 70; |
2305 |
|
break; |
2306 |
|
case _lev_ctrl_CC71_EXT: |
2307 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2308 |
|
decodedcontroller.controller_number = 71; |
2309 |
|
break; |
2310 |
|
case _lev_ctrl_CC72_EXT: |
2311 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2312 |
|
decodedcontroller.controller_number = 72; |
2313 |
|
break; |
2314 |
|
case _lev_ctrl_CC73_EXT: |
2315 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2316 |
|
decodedcontroller.controller_number = 73; |
2317 |
|
break; |
2318 |
|
case _lev_ctrl_CC74_EXT: |
2319 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2320 |
|
decodedcontroller.controller_number = 74; |
2321 |
|
break; |
2322 |
|
case _lev_ctrl_CC75_EXT: |
2323 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2324 |
|
decodedcontroller.controller_number = 75; |
2325 |
|
break; |
2326 |
|
case _lev_ctrl_CC76_EXT: |
2327 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2328 |
|
decodedcontroller.controller_number = 76; |
2329 |
|
break; |
2330 |
|
case _lev_ctrl_CC77_EXT: |
2331 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2332 |
|
decodedcontroller.controller_number = 77; |
2333 |
|
break; |
2334 |
|
case _lev_ctrl_CC78_EXT: |
2335 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2336 |
|
decodedcontroller.controller_number = 78; |
2337 |
|
break; |
2338 |
|
case _lev_ctrl_CC79_EXT: |
2339 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2340 |
|
decodedcontroller.controller_number = 79; |
2341 |
|
break; |
2342 |
|
case _lev_ctrl_CC84_EXT: |
2343 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2344 |
|
decodedcontroller.controller_number = 84; |
2345 |
|
break; |
2346 |
|
case _lev_ctrl_CC85_EXT: |
2347 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2348 |
|
decodedcontroller.controller_number = 85; |
2349 |
|
break; |
2350 |
|
case _lev_ctrl_CC86_EXT: |
2351 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2352 |
|
decodedcontroller.controller_number = 86; |
2353 |
|
break; |
2354 |
|
case _lev_ctrl_CC87_EXT: |
2355 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2356 |
|
decodedcontroller.controller_number = 87; |
2357 |
|
break; |
2358 |
|
case _lev_ctrl_CC89_EXT: |
2359 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2360 |
|
decodedcontroller.controller_number = 89; |
2361 |
|
break; |
2362 |
|
case _lev_ctrl_CC90_EXT: |
2363 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2364 |
|
decodedcontroller.controller_number = 90; |
2365 |
|
break; |
2366 |
|
case _lev_ctrl_CC96_EXT: |
2367 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2368 |
|
decodedcontroller.controller_number = 96; |
2369 |
|
break; |
2370 |
|
case _lev_ctrl_CC97_EXT: |
2371 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2372 |
|
decodedcontroller.controller_number = 97; |
2373 |
|
break; |
2374 |
|
case _lev_ctrl_CC102_EXT: |
2375 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2376 |
|
decodedcontroller.controller_number = 102; |
2377 |
|
break; |
2378 |
|
case _lev_ctrl_CC103_EXT: |
2379 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2380 |
|
decodedcontroller.controller_number = 103; |
2381 |
|
break; |
2382 |
|
case _lev_ctrl_CC104_EXT: |
2383 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2384 |
|
decodedcontroller.controller_number = 104; |
2385 |
|
break; |
2386 |
|
case _lev_ctrl_CC105_EXT: |
2387 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2388 |
|
decodedcontroller.controller_number = 105; |
2389 |
|
break; |
2390 |
|
case _lev_ctrl_CC106_EXT: |
2391 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2392 |
|
decodedcontroller.controller_number = 106; |
2393 |
|
break; |
2394 |
|
case _lev_ctrl_CC107_EXT: |
2395 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2396 |
|
decodedcontroller.controller_number = 107; |
2397 |
|
break; |
2398 |
|
case _lev_ctrl_CC108_EXT: |
2399 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2400 |
|
decodedcontroller.controller_number = 108; |
2401 |
|
break; |
2402 |
|
case _lev_ctrl_CC109_EXT: |
2403 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2404 |
|
decodedcontroller.controller_number = 109; |
2405 |
|
break; |
2406 |
|
case _lev_ctrl_CC110_EXT: |
2407 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2408 |
|
decodedcontroller.controller_number = 110; |
2409 |
|
break; |
2410 |
|
case _lev_ctrl_CC111_EXT: |
2411 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2412 |
|
decodedcontroller.controller_number = 111; |
2413 |
|
break; |
2414 |
|
case _lev_ctrl_CC112_EXT: |
2415 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2416 |
|
decodedcontroller.controller_number = 112; |
2417 |
|
break; |
2418 |
|
case _lev_ctrl_CC113_EXT: |
2419 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2420 |
|
decodedcontroller.controller_number = 113; |
2421 |
|
break; |
2422 |
|
case _lev_ctrl_CC114_EXT: |
2423 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2424 |
|
decodedcontroller.controller_number = 114; |
2425 |
|
break; |
2426 |
|
case _lev_ctrl_CC115_EXT: |
2427 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2428 |
|
decodedcontroller.controller_number = 115; |
2429 |
|
break; |
2430 |
|
case _lev_ctrl_CC116_EXT: |
2431 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2432 |
|
decodedcontroller.controller_number = 116; |
2433 |
|
break; |
2434 |
|
case _lev_ctrl_CC117_EXT: |
2435 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2436 |
|
decodedcontroller.controller_number = 117; |
2437 |
|
break; |
2438 |
|
case _lev_ctrl_CC118_EXT: |
2439 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2440 |
|
decodedcontroller.controller_number = 118; |
2441 |
|
break; |
2442 |
|
case _lev_ctrl_CC119_EXT: |
2443 |
|
decodedcontroller.type = leverage_ctrl_t::type_controlchange; |
2444 |
|
decodedcontroller.controller_number = 119; |
2445 |
|
break; |
2446 |
|
|
2447 |
// unknown controller type |
// unknown controller type |
2448 |
default: |
default: |
2449 |
throw gig::Exception("Unknown leverage controller type."); |
throw gig::Exception("Unknown leverage controller type."); |
2450 |
} |
} |
2451 |
return decodedcontroller; |
return decodedcontroller; |
2452 |
} |
} |
2453 |
|
|
2454 |
|
// see above (diagnostic push not supported prior GCC 4.6) |
2455 |
|
//#pragma GCC diagnostic pop |
2456 |
|
|
2457 |
DimensionRegion::_lev_ctrl_t DimensionRegion::EncodeLeverageController(leverage_ctrl_t DecodedController) { |
DimensionRegion::_lev_ctrl_t DimensionRegion::EncodeLeverageController(leverage_ctrl_t DecodedController) { |
2458 |
_lev_ctrl_t encodedcontroller; |
_lev_ctrl_t encodedcontroller; |
2540 |
case 95: |
case 95: |
2541 |
encodedcontroller = _lev_ctrl_effect5depth; |
encodedcontroller = _lev_ctrl_effect5depth; |
2542 |
break; |
break; |
2543 |
|
|
2544 |
|
// format extension (these controllers are so far only |
2545 |
|
// supported by LinuxSampler & gigedit) they will *NOT* |
2546 |
|
// work with Gigasampler/GigaStudio ! |
2547 |
|
case 3: |
2548 |
|
encodedcontroller = _lev_ctrl_CC3_EXT; |
2549 |
|
break; |
2550 |
|
case 6: |
2551 |
|
encodedcontroller = _lev_ctrl_CC6_EXT; |
2552 |
|
break; |
2553 |
|
case 7: |
2554 |
|
encodedcontroller = _lev_ctrl_CC7_EXT; |
2555 |
|
break; |
2556 |
|
case 8: |
2557 |
|
encodedcontroller = _lev_ctrl_CC8_EXT; |
2558 |
|
break; |
2559 |
|
case 9: |
2560 |
|
encodedcontroller = _lev_ctrl_CC9_EXT; |
2561 |
|
break; |
2562 |
|
case 10: |
2563 |
|
encodedcontroller = _lev_ctrl_CC10_EXT; |
2564 |
|
break; |
2565 |
|
case 11: |
2566 |
|
encodedcontroller = _lev_ctrl_CC11_EXT; |
2567 |
|
break; |
2568 |
|
case 14: |
2569 |
|
encodedcontroller = _lev_ctrl_CC14_EXT; |
2570 |
|
break; |
2571 |
|
case 15: |
2572 |
|
encodedcontroller = _lev_ctrl_CC15_EXT; |
2573 |
|
break; |
2574 |
|
case 20: |
2575 |
|
encodedcontroller = _lev_ctrl_CC20_EXT; |
2576 |
|
break; |
2577 |
|
case 21: |
2578 |
|
encodedcontroller = _lev_ctrl_CC21_EXT; |
2579 |
|
break; |
2580 |
|
case 22: |
2581 |
|
encodedcontroller = _lev_ctrl_CC22_EXT; |
2582 |
|
break; |
2583 |
|
case 23: |
2584 |
|
encodedcontroller = _lev_ctrl_CC23_EXT; |
2585 |
|
break; |
2586 |
|
case 24: |
2587 |
|
encodedcontroller = _lev_ctrl_CC24_EXT; |
2588 |
|
break; |
2589 |
|
case 25: |
2590 |
|
encodedcontroller = _lev_ctrl_CC25_EXT; |
2591 |
|
break; |
2592 |
|
case 26: |
2593 |
|
encodedcontroller = _lev_ctrl_CC26_EXT; |
2594 |
|
break; |
2595 |
|
case 27: |
2596 |
|
encodedcontroller = _lev_ctrl_CC27_EXT; |
2597 |
|
break; |
2598 |
|
case 28: |
2599 |
|
encodedcontroller = _lev_ctrl_CC28_EXT; |
2600 |
|
break; |
2601 |
|
case 29: |
2602 |
|
encodedcontroller = _lev_ctrl_CC29_EXT; |
2603 |
|
break; |
2604 |
|
case 30: |
2605 |
|
encodedcontroller = _lev_ctrl_CC30_EXT; |
2606 |
|
break; |
2607 |
|
case 31: |
2608 |
|
encodedcontroller = _lev_ctrl_CC31_EXT; |
2609 |
|
break; |
2610 |
|
case 68: |
2611 |
|
encodedcontroller = _lev_ctrl_CC68_EXT; |
2612 |
|
break; |
2613 |
|
case 69: |
2614 |
|
encodedcontroller = _lev_ctrl_CC69_EXT; |
2615 |
|
break; |
2616 |
|
case 70: |
2617 |
|
encodedcontroller = _lev_ctrl_CC70_EXT; |
2618 |
|
break; |
2619 |
|
case 71: |
2620 |
|
encodedcontroller = _lev_ctrl_CC71_EXT; |
2621 |
|
break; |
2622 |
|
case 72: |
2623 |
|
encodedcontroller = _lev_ctrl_CC72_EXT; |
2624 |
|
break; |
2625 |
|
case 73: |
2626 |
|
encodedcontroller = _lev_ctrl_CC73_EXT; |
2627 |
|
break; |
2628 |
|
case 74: |
2629 |
|
encodedcontroller = _lev_ctrl_CC74_EXT; |
2630 |
|
break; |
2631 |
|
case 75: |
2632 |
|
encodedcontroller = _lev_ctrl_CC75_EXT; |
2633 |
|
break; |
2634 |
|
case 76: |
2635 |
|
encodedcontroller = _lev_ctrl_CC76_EXT; |
2636 |
|
break; |
2637 |
|
case 77: |
2638 |
|
encodedcontroller = _lev_ctrl_CC77_EXT; |
2639 |
|
break; |
2640 |
|
case 78: |
2641 |
|
encodedcontroller = _lev_ctrl_CC78_EXT; |
2642 |
|
break; |
2643 |
|
case 79: |
2644 |
|
encodedcontroller = _lev_ctrl_CC79_EXT; |
2645 |
|
break; |
2646 |
|
case 84: |
2647 |
|
encodedcontroller = _lev_ctrl_CC84_EXT; |
2648 |
|
break; |
2649 |
|
case 85: |
2650 |
|
encodedcontroller = _lev_ctrl_CC85_EXT; |
2651 |
|
break; |
2652 |
|
case 86: |
2653 |
|
encodedcontroller = _lev_ctrl_CC86_EXT; |
2654 |
|
break; |
2655 |
|
case 87: |
2656 |
|
encodedcontroller = _lev_ctrl_CC87_EXT; |
2657 |
|
break; |
2658 |
|
case 89: |
2659 |
|
encodedcontroller = _lev_ctrl_CC89_EXT; |
2660 |
|
break; |
2661 |
|
case 90: |
2662 |
|
encodedcontroller = _lev_ctrl_CC90_EXT; |
2663 |
|
break; |
2664 |
|
case 96: |
2665 |
|
encodedcontroller = _lev_ctrl_CC96_EXT; |
2666 |
|
break; |
2667 |
|
case 97: |
2668 |
|
encodedcontroller = _lev_ctrl_CC97_EXT; |
2669 |
|
break; |
2670 |
|
case 102: |
2671 |
|
encodedcontroller = _lev_ctrl_CC102_EXT; |
2672 |
|
break; |
2673 |
|
case 103: |
2674 |
|
encodedcontroller = _lev_ctrl_CC103_EXT; |
2675 |
|
break; |
2676 |
|
case 104: |
2677 |
|
encodedcontroller = _lev_ctrl_CC104_EXT; |
2678 |
|
break; |
2679 |
|
case 105: |
2680 |
|
encodedcontroller = _lev_ctrl_CC105_EXT; |
2681 |
|
break; |
2682 |
|
case 106: |
2683 |
|
encodedcontroller = _lev_ctrl_CC106_EXT; |
2684 |
|
break; |
2685 |
|
case 107: |
2686 |
|
encodedcontroller = _lev_ctrl_CC107_EXT; |
2687 |
|
break; |
2688 |
|
case 108: |
2689 |
|
encodedcontroller = _lev_ctrl_CC108_EXT; |
2690 |
|
break; |
2691 |
|
case 109: |
2692 |
|
encodedcontroller = _lev_ctrl_CC109_EXT; |
2693 |
|
break; |
2694 |
|
case 110: |
2695 |
|
encodedcontroller = _lev_ctrl_CC110_EXT; |
2696 |
|
break; |
2697 |
|
case 111: |
2698 |
|
encodedcontroller = _lev_ctrl_CC111_EXT; |
2699 |
|
break; |
2700 |
|
case 112: |
2701 |
|
encodedcontroller = _lev_ctrl_CC112_EXT; |
2702 |
|
break; |
2703 |
|
case 113: |
2704 |
|
encodedcontroller = _lev_ctrl_CC113_EXT; |
2705 |
|
break; |
2706 |
|
case 114: |
2707 |
|
encodedcontroller = _lev_ctrl_CC114_EXT; |
2708 |
|
break; |
2709 |
|
case 115: |
2710 |
|
encodedcontroller = _lev_ctrl_CC115_EXT; |
2711 |
|
break; |
2712 |
|
case 116: |
2713 |
|
encodedcontroller = _lev_ctrl_CC116_EXT; |
2714 |
|
break; |
2715 |
|
case 117: |
2716 |
|
encodedcontroller = _lev_ctrl_CC117_EXT; |
2717 |
|
break; |
2718 |
|
case 118: |
2719 |
|
encodedcontroller = _lev_ctrl_CC118_EXT; |
2720 |
|
break; |
2721 |
|
case 119: |
2722 |
|
encodedcontroller = _lev_ctrl_CC119_EXT; |
2723 |
|
break; |
2724 |
|
|
2725 |
default: |
default: |
2726 |
throw gig::Exception("leverage controller number is not supported by the gig format"); |
throw gig::Exception("leverage controller number is not supported by the gig format"); |
2727 |
} |
} |
3493 |
} |
} |
3494 |
return NULL; |
return NULL; |
3495 |
} |
} |
3496 |
|
|
3497 |
|
/** |
3498 |
|
* Make a (semi) deep copy of the Region object given by @a orig |
3499 |
|
* and assign it to this object. |
3500 |
|
* |
3501 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
3502 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
3503 |
|
* |
3504 |
|
* @param orig - original Region object to be copied from |
3505 |
|
*/ |
3506 |
|
void Region::CopyAssign(const Region* orig) { |
3507 |
|
CopyAssign(orig, NULL); |
3508 |
|
} |
3509 |
|
|
3510 |
|
/** |
3511 |
|
* Make a (semi) deep copy of the Region object given by @a orig and |
3512 |
|
* assign it to this object |
3513 |
|
* |
3514 |
|
* @param mSamples - crosslink map between the foreign file's samples and |
3515 |
|
* this file's samples |
3516 |
|
*/ |
3517 |
|
void Region::CopyAssign(const Region* orig, const std::map<Sample*,Sample*>* mSamples) { |
3518 |
|
// handle base classes |
3519 |
|
DLS::Region::CopyAssign(orig); |
3520 |
|
|
3521 |
|
if (mSamples && mSamples->count((gig::Sample*)orig->pSample)) { |
3522 |
|
pSample = mSamples->find((gig::Sample*)orig->pSample)->second; |
3523 |
|
} |
3524 |
|
|
3525 |
|
// handle own member variables |
3526 |
|
for (int i = Dimensions - 1; i >= 0; --i) { |
3527 |
|
DeleteDimension(&pDimensionDefinitions[i]); |
3528 |
|
} |
3529 |
|
Layers = 0; // just to be sure |
3530 |
|
for (int i = 0; i < orig->Dimensions; i++) { |
3531 |
|
// we need to copy the dim definition here, to avoid the compiler |
3532 |
|
// complaining about const-ness issue |
3533 |
|
dimension_def_t def = orig->pDimensionDefinitions[i]; |
3534 |
|
AddDimension(&def); |
3535 |
|
} |
3536 |
|
for (int i = 0; i < 256; i++) { |
3537 |
|
if (pDimensionRegions[i] && orig->pDimensionRegions[i]) { |
3538 |
|
pDimensionRegions[i]->CopyAssign( |
3539 |
|
orig->pDimensionRegions[i], |
3540 |
|
mSamples |
3541 |
|
); |
3542 |
|
} |
3543 |
|
} |
3544 |
|
Layers = orig->Layers; |
3545 |
|
} |
3546 |
|
|
3547 |
|
|
3548 |
// *************** MidiRule *************** |
// *************** MidiRule *************** |
3549 |
// * |
// * |
3550 |
|
|
3551 |
MidiRuleCtrlTrigger::MidiRuleCtrlTrigger(RIFF::Chunk* _3ewg) { |
MidiRuleCtrlTrigger::MidiRuleCtrlTrigger(RIFF::Chunk* _3ewg) { |
3552 |
_3ewg->SetPos(36); |
_3ewg->SetPos(36); |
3553 |
Triggers = _3ewg->ReadUint8(); |
Triggers = _3ewg->ReadUint8(); |
3554 |
_3ewg->SetPos(40); |
_3ewg->SetPos(40); |
3555 |
ControllerNumber = _3ewg->ReadUint8(); |
ControllerNumber = _3ewg->ReadUint8(); |
3556 |
_3ewg->SetPos(46); |
_3ewg->SetPos(46); |
3557 |
for (int i = 0 ; i < Triggers ; i++) { |
for (int i = 0 ; i < Triggers ; i++) { |
3558 |
pTriggers[i].TriggerPoint = _3ewg->ReadUint8(); |
pTriggers[i].TriggerPoint = _3ewg->ReadUint8(); |
3559 |
pTriggers[i].Descending = _3ewg->ReadUint8(); |
pTriggers[i].Descending = _3ewg->ReadUint8(); |
3560 |
pTriggers[i].VelSensitivity = _3ewg->ReadUint8(); |
pTriggers[i].VelSensitivity = _3ewg->ReadUint8(); |
3561 |
pTriggers[i].Key = _3ewg->ReadUint8(); |
pTriggers[i].Key = _3ewg->ReadUint8(); |
3562 |
pTriggers[i].NoteOff = _3ewg->ReadUint8(); |
pTriggers[i].NoteOff = _3ewg->ReadUint8(); |
3563 |
pTriggers[i].Velocity = _3ewg->ReadUint8(); |
pTriggers[i].Velocity = _3ewg->ReadUint8(); |
3564 |
pTriggers[i].OverridePedal = _3ewg->ReadUint8(); |
pTriggers[i].OverridePedal = _3ewg->ReadUint8(); |
3565 |
_3ewg->ReadUint8(); |
_3ewg->ReadUint8(); |
3566 |
|
} |
3567 |
|
} |
3568 |
|
|
3569 |
|
MidiRuleCtrlTrigger::MidiRuleCtrlTrigger() : |
3570 |
|
ControllerNumber(0), |
3571 |
|
Triggers(0) { |
3572 |
|
} |
3573 |
|
|
3574 |
|
void MidiRuleCtrlTrigger::UpdateChunks(uint8_t* pData) const { |
3575 |
|
pData[32] = 4; |
3576 |
|
pData[33] = 16; |
3577 |
|
pData[36] = Triggers; |
3578 |
|
pData[40] = ControllerNumber; |
3579 |
|
for (int i = 0 ; i < Triggers ; i++) { |
3580 |
|
pData[46 + i * 8] = pTriggers[i].TriggerPoint; |
3581 |
|
pData[47 + i * 8] = pTriggers[i].Descending; |
3582 |
|
pData[48 + i * 8] = pTriggers[i].VelSensitivity; |
3583 |
|
pData[49 + i * 8] = pTriggers[i].Key; |
3584 |
|
pData[50 + i * 8] = pTriggers[i].NoteOff; |
3585 |
|
pData[51 + i * 8] = pTriggers[i].Velocity; |
3586 |
|
pData[52 + i * 8] = pTriggers[i].OverridePedal; |
3587 |
|
} |
3588 |
|
} |
3589 |
|
|
3590 |
|
MidiRuleLegato::MidiRuleLegato(RIFF::Chunk* _3ewg) { |
3591 |
|
_3ewg->SetPos(36); |
3592 |
|
LegatoSamples = _3ewg->ReadUint8(); // always 12 |
3593 |
|
_3ewg->SetPos(40); |
3594 |
|
BypassUseController = _3ewg->ReadUint8(); |
3595 |
|
BypassKey = _3ewg->ReadUint8(); |
3596 |
|
BypassController = _3ewg->ReadUint8(); |
3597 |
|
ThresholdTime = _3ewg->ReadUint16(); |
3598 |
|
_3ewg->ReadInt16(); |
3599 |
|
ReleaseTime = _3ewg->ReadUint16(); |
3600 |
|
_3ewg->ReadInt16(); |
3601 |
|
KeyRange.low = _3ewg->ReadUint8(); |
3602 |
|
KeyRange.high = _3ewg->ReadUint8(); |
3603 |
|
_3ewg->SetPos(64); |
3604 |
|
ReleaseTriggerKey = _3ewg->ReadUint8(); |
3605 |
|
AltSustain1Key = _3ewg->ReadUint8(); |
3606 |
|
AltSustain2Key = _3ewg->ReadUint8(); |
3607 |
|
} |
3608 |
|
|
3609 |
|
MidiRuleLegato::MidiRuleLegato() : |
3610 |
|
LegatoSamples(12), |
3611 |
|
BypassUseController(false), |
3612 |
|
BypassKey(0), |
3613 |
|
BypassController(1), |
3614 |
|
ThresholdTime(20), |
3615 |
|
ReleaseTime(20), |
3616 |
|
ReleaseTriggerKey(0), |
3617 |
|
AltSustain1Key(0), |
3618 |
|
AltSustain2Key(0) |
3619 |
|
{ |
3620 |
|
KeyRange.low = KeyRange.high = 0; |
3621 |
} |
} |
|
} |
|
3622 |
|
|
3623 |
|
void MidiRuleLegato::UpdateChunks(uint8_t* pData) const { |
3624 |
|
pData[32] = 0; |
3625 |
|
pData[33] = 16; |
3626 |
|
pData[36] = LegatoSamples; |
3627 |
|
pData[40] = BypassUseController; |
3628 |
|
pData[41] = BypassKey; |
3629 |
|
pData[42] = BypassController; |
3630 |
|
store16(&pData[43], ThresholdTime); |
3631 |
|
store16(&pData[47], ReleaseTime); |
3632 |
|
pData[51] = KeyRange.low; |
3633 |
|
pData[52] = KeyRange.high; |
3634 |
|
pData[64] = ReleaseTriggerKey; |
3635 |
|
pData[65] = AltSustain1Key; |
3636 |
|
pData[66] = AltSustain2Key; |
3637 |
|
} |
3638 |
|
|
3639 |
|
MidiRuleAlternator::MidiRuleAlternator(RIFF::Chunk* _3ewg) { |
3640 |
|
_3ewg->SetPos(36); |
3641 |
|
Articulations = _3ewg->ReadUint8(); |
3642 |
|
int flags = _3ewg->ReadUint8(); |
3643 |
|
Polyphonic = flags & 8; |
3644 |
|
Chained = flags & 4; |
3645 |
|
Selector = (flags & 2) ? selector_controller : |
3646 |
|
(flags & 1) ? selector_key_switch : selector_none; |
3647 |
|
Patterns = _3ewg->ReadUint8(); |
3648 |
|
_3ewg->ReadUint8(); // chosen row |
3649 |
|
_3ewg->ReadUint8(); // unknown |
3650 |
|
_3ewg->ReadUint8(); // unknown |
3651 |
|
_3ewg->ReadUint8(); // unknown |
3652 |
|
KeySwitchRange.low = _3ewg->ReadUint8(); |
3653 |
|
KeySwitchRange.high = _3ewg->ReadUint8(); |
3654 |
|
Controller = _3ewg->ReadUint8(); |
3655 |
|
PlayRange.low = _3ewg->ReadUint8(); |
3656 |
|
PlayRange.high = _3ewg->ReadUint8(); |
3657 |
|
|
3658 |
|
int n = std::min(int(Articulations), 32); |
3659 |
|
for (int i = 0 ; i < n ; i++) { |
3660 |
|
_3ewg->ReadString(pArticulations[i], 32); |
3661 |
|
} |
3662 |
|
_3ewg->SetPos(1072); |
3663 |
|
n = std::min(int(Patterns), 32); |
3664 |
|
for (int i = 0 ; i < n ; i++) { |
3665 |
|
_3ewg->ReadString(pPatterns[i].Name, 16); |
3666 |
|
pPatterns[i].Size = _3ewg->ReadUint8(); |
3667 |
|
_3ewg->Read(&pPatterns[i][0], 1, 32); |
3668 |
|
} |
3669 |
|
} |
3670 |
|
|
3671 |
|
MidiRuleAlternator::MidiRuleAlternator() : |
3672 |
|
Articulations(0), |
3673 |
|
Patterns(0), |
3674 |
|
Selector(selector_none), |
3675 |
|
Controller(0), |
3676 |
|
Polyphonic(false), |
3677 |
|
Chained(false) |
3678 |
|
{ |
3679 |
|
PlayRange.low = PlayRange.high = 0; |
3680 |
|
KeySwitchRange.low = KeySwitchRange.high = 0; |
3681 |
|
} |
3682 |
|
|
3683 |
|
void MidiRuleAlternator::UpdateChunks(uint8_t* pData) const { |
3684 |
|
pData[32] = 3; |
3685 |
|
pData[33] = 16; |
3686 |
|
pData[36] = Articulations; |
3687 |
|
pData[37] = (Polyphonic ? 8 : 0) | (Chained ? 4 : 0) | |
3688 |
|
(Selector == selector_controller ? 2 : |
3689 |
|
(Selector == selector_key_switch ? 1 : 0)); |
3690 |
|
pData[38] = Patterns; |
3691 |
|
|
3692 |
|
pData[43] = KeySwitchRange.low; |
3693 |
|
pData[44] = KeySwitchRange.high; |
3694 |
|
pData[45] = Controller; |
3695 |
|
pData[46] = PlayRange.low; |
3696 |
|
pData[47] = PlayRange.high; |
3697 |
|
|
3698 |
|
char* str = reinterpret_cast<char*>(pData); |
3699 |
|
int pos = 48; |
3700 |
|
int n = std::min(int(Articulations), 32); |
3701 |
|
for (int i = 0 ; i < n ; i++, pos += 32) { |
3702 |
|
strncpy(&str[pos], pArticulations[i].c_str(), 32); |
3703 |
|
} |
3704 |
|
|
3705 |
|
pos = 1072; |
3706 |
|
n = std::min(int(Patterns), 32); |
3707 |
|
for (int i = 0 ; i < n ; i++, pos += 49) { |
3708 |
|
strncpy(&str[pos], pPatterns[i].Name.c_str(), 16); |
3709 |
|
pData[pos + 16] = pPatterns[i].Size; |
3710 |
|
memcpy(&pData[pos + 16], &(pPatterns[i][0]), 32); |
3711 |
|
} |
3712 |
|
} |
3713 |
|
|
3714 |
// *************** Instrument *************** |
// *************** Instrument *************** |
3715 |
// * |
// * |
3755 |
uint8_t id1 = _3ewg->ReadUint8(); |
uint8_t id1 = _3ewg->ReadUint8(); |
3756 |
uint8_t id2 = _3ewg->ReadUint8(); |
uint8_t id2 = _3ewg->ReadUint8(); |
3757 |
|
|
3758 |
if (id1 == 4 && id2 == 16) { |
if (id2 == 16) { |
3759 |
pMidiRules[i++] = new MidiRuleCtrlTrigger(_3ewg); |
if (id1 == 4) { |
3760 |
|
pMidiRules[i++] = new MidiRuleCtrlTrigger(_3ewg); |
3761 |
|
} else if (id1 == 0) { |
3762 |
|
pMidiRules[i++] = new MidiRuleLegato(_3ewg); |
3763 |
|
} else if (id1 == 3) { |
3764 |
|
pMidiRules[i++] = new MidiRuleAlternator(_3ewg); |
3765 |
|
} else { |
3766 |
|
pMidiRules[i++] = new MidiRuleUnknown; |
3767 |
|
} |
3768 |
|
} |
3769 |
|
else if (id1 != 0 || id2 != 0) { |
3770 |
|
pMidiRules[i++] = new MidiRuleUnknown; |
3771 |
} |
} |
3772 |
//TODO: all the other types of rules |
//TODO: all the other types of rules |
3773 |
|
|
3809 |
} |
} |
3810 |
|
|
3811 |
Instrument::~Instrument() { |
Instrument::~Instrument() { |
3812 |
|
for (int i = 0 ; pMidiRules[i] ; i++) { |
3813 |
|
delete pMidiRules[i]; |
3814 |
|
} |
3815 |
delete[] pMidiRules; |
delete[] pMidiRules; |
3816 |
} |
} |
3817 |
|
|
3859 |
DimensionKeyRange.low << 1; |
DimensionKeyRange.low << 1; |
3860 |
pData[10] = dimkeystart; |
pData[10] = dimkeystart; |
3861 |
pData[11] = DimensionKeyRange.high; |
pData[11] = DimensionKeyRange.high; |
3862 |
|
|
3863 |
|
if (pMidiRules[0] == 0 && _3ewg->GetSize() >= 34) { |
3864 |
|
pData[32] = 0; |
3865 |
|
pData[33] = 0; |
3866 |
|
} else { |
3867 |
|
for (int i = 0 ; pMidiRules[i] ; i++) { |
3868 |
|
pMidiRules[i]->UpdateChunks(pData); |
3869 |
|
} |
3870 |
|
} |
3871 |
} |
} |
3872 |
|
|
3873 |
/** |
/** |
3950 |
return pMidiRules[i]; |
return pMidiRules[i]; |
3951 |
} |
} |
3952 |
|
|
3953 |
|
/** |
3954 |
|
* Adds the "controller trigger" MIDI rule to the instrument. |
3955 |
|
* |
3956 |
|
* @returns the new MIDI rule |
3957 |
|
*/ |
3958 |
|
MidiRuleCtrlTrigger* Instrument::AddMidiRuleCtrlTrigger() { |
3959 |
|
delete pMidiRules[0]; |
3960 |
|
MidiRuleCtrlTrigger* r = new MidiRuleCtrlTrigger; |
3961 |
|
pMidiRules[0] = r; |
3962 |
|
pMidiRules[1] = 0; |
3963 |
|
return r; |
3964 |
|
} |
3965 |
|
|
3966 |
|
/** |
3967 |
|
* Adds the legato MIDI rule to the instrument. |
3968 |
|
* |
3969 |
|
* @returns the new MIDI rule |
3970 |
|
*/ |
3971 |
|
MidiRuleLegato* Instrument::AddMidiRuleLegato() { |
3972 |
|
delete pMidiRules[0]; |
3973 |
|
MidiRuleLegato* r = new MidiRuleLegato; |
3974 |
|
pMidiRules[0] = r; |
3975 |
|
pMidiRules[1] = 0; |
3976 |
|
return r; |
3977 |
|
} |
3978 |
|
|
3979 |
|
/** |
3980 |
|
* Adds the alternator MIDI rule to the instrument. |
3981 |
|
* |
3982 |
|
* @returns the new MIDI rule |
3983 |
|
*/ |
3984 |
|
MidiRuleAlternator* Instrument::AddMidiRuleAlternator() { |
3985 |
|
delete pMidiRules[0]; |
3986 |
|
MidiRuleAlternator* r = new MidiRuleAlternator; |
3987 |
|
pMidiRules[0] = r; |
3988 |
|
pMidiRules[1] = 0; |
3989 |
|
return r; |
3990 |
|
} |
3991 |
|
|
3992 |
|
/** |
3993 |
|
* Deletes a MIDI rule from the instrument. |
3994 |
|
* |
3995 |
|
* @param i - MIDI rule number |
3996 |
|
*/ |
3997 |
|
void Instrument::DeleteMidiRule(int i) { |
3998 |
|
delete pMidiRules[i]; |
3999 |
|
pMidiRules[i] = 0; |
4000 |
|
} |
4001 |
|
|
4002 |
|
/** |
4003 |
|
* Make a (semi) deep copy of the Instrument object given by @a orig |
4004 |
|
* and assign it to this object. |
4005 |
|
* |
4006 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
4007 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
4008 |
|
* |
4009 |
|
* @param orig - original Instrument object to be copied from |
4010 |
|
*/ |
4011 |
|
void Instrument::CopyAssign(const Instrument* orig) { |
4012 |
|
CopyAssign(orig, NULL); |
4013 |
|
} |
4014 |
|
|
4015 |
|
/** |
4016 |
|
* Make a (semi) deep copy of the Instrument object given by @a orig |
4017 |
|
* and assign it to this object. |
4018 |
|
* |
4019 |
|
* @param orig - original Instrument object to be copied from |
4020 |
|
* @param mSamples - crosslink map between the foreign file's samples and |
4021 |
|
* this file's samples |
4022 |
|
*/ |
4023 |
|
void Instrument::CopyAssign(const Instrument* orig, const std::map<Sample*,Sample*>* mSamples) { |
4024 |
|
// handle base class |
4025 |
|
// (without copying DLS region stuff) |
4026 |
|
DLS::Instrument::CopyAssignCore(orig); |
4027 |
|
|
4028 |
|
// handle own member variables |
4029 |
|
Attenuation = orig->Attenuation; |
4030 |
|
EffectSend = orig->EffectSend; |
4031 |
|
FineTune = orig->FineTune; |
4032 |
|
PitchbendRange = orig->PitchbendRange; |
4033 |
|
PianoReleaseMode = orig->PianoReleaseMode; |
4034 |
|
DimensionKeyRange = orig->DimensionKeyRange; |
4035 |
|
|
4036 |
|
// free old midi rules |
4037 |
|
for (int i = 0 ; pMidiRules[i] ; i++) { |
4038 |
|
delete pMidiRules[i]; |
4039 |
|
} |
4040 |
|
//TODO: MIDI rule copying |
4041 |
|
pMidiRules[0] = NULL; |
4042 |
|
|
4043 |
|
// delete all old regions |
4044 |
|
while (Regions) DeleteRegion(GetFirstRegion()); |
4045 |
|
// create new regions and copy them from original |
4046 |
|
{ |
4047 |
|
RegionList::const_iterator it = orig->pRegions->begin(); |
4048 |
|
for (int i = 0; i < orig->Regions; ++i, ++it) { |
4049 |
|
Region* dstRgn = AddRegion(); |
4050 |
|
//NOTE: Region does semi-deep copy ! |
4051 |
|
dstRgn->CopyAssign( |
4052 |
|
static_cast<gig::Region*>(*it), |
4053 |
|
mSamples |
4054 |
|
); |
4055 |
|
} |
4056 |
|
} |
4057 |
|
|
4058 |
|
UpdateRegionKeyTable(); |
4059 |
|
} |
4060 |
|
|
4061 |
|
|
4062 |
// *************** Group *************** |
// *************** Group *************** |
4063 |
// * |
// * |
4259 |
SamplesIterator++; |
SamplesIterator++; |
4260 |
return static_cast<gig::Sample*>( (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL ); |
return static_cast<gig::Sample*>( (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL ); |
4261 |
} |
} |
4262 |
|
|
4263 |
|
/** |
4264 |
|
* Returns Sample object of @a index. |
4265 |
|
* |
4266 |
|
* @returns sample object or NULL if index is out of bounds |
4267 |
|
*/ |
4268 |
|
Sample* File::GetSample(uint index) { |
4269 |
|
if (!pSamples) LoadSamples(); |
4270 |
|
if (!pSamples) return NULL; |
4271 |
|
DLS::File::SampleList::iterator it = pSamples->begin(); |
4272 |
|
for (int i = 0; i < index; ++i) { |
4273 |
|
++it; |
4274 |
|
if (it == pSamples->end()) return NULL; |
4275 |
|
} |
4276 |
|
if (it == pSamples->end()) return NULL; |
4277 |
|
return static_cast<gig::Sample*>( *it ); |
4278 |
|
} |
4279 |
|
|
4280 |
/** @brief Add a new sample. |
/** @brief Add a new sample. |
4281 |
* |
* |
4473 |
pInstruments->push_back(pInstrument); |
pInstruments->push_back(pInstrument); |
4474 |
return pInstrument; |
return pInstrument; |
4475 |
} |
} |
4476 |
|
|
4477 |
|
/** @brief Add a duplicate of an existing instrument. |
4478 |
|
* |
4479 |
|
* Duplicates the instrument definition given by @a orig and adds it |
4480 |
|
* to this file. This allows in an instrument editor application to |
4481 |
|
* easily create variations of an instrument, which will be stored in |
4482 |
|
* the same .gig file, sharing i.e. the same samples. |
4483 |
|
* |
4484 |
|
* Note that all sample pointers referenced by @a orig are simply copied as |
4485 |
|
* memory address. Thus the respective samples are shared, not duplicated! |
4486 |
|
* |
4487 |
|
* You have to call Save() to make this persistent to the file. |
4488 |
|
* |
4489 |
|
* @param orig - original instrument to be copied |
4490 |
|
* @returns duplicated copy of the given instrument |
4491 |
|
*/ |
4492 |
|
Instrument* File::AddDuplicateInstrument(const Instrument* orig) { |
4493 |
|
Instrument* instr = AddInstrument(); |
4494 |
|
instr->CopyAssign(orig); |
4495 |
|
return instr; |
4496 |
|
} |
4497 |
|
|
4498 |
|
/** @brief Add content of another existing file. |
4499 |
|
* |
4500 |
|
* Duplicates the samples, groups and instruments of the original file |
4501 |
|
* given by @a pFile and adds them to @c this File. In case @c this File is |
4502 |
|
* a new one that you haven't saved before, then you have to call |
4503 |
|
* SetFileName() before calling AddContentOf(), because this method will |
4504 |
|
* automatically save this file during operation, which is required for |
4505 |
|
* writing the sample waveform data by disk streaming. |
4506 |
|
* |
4507 |
|
* @param pFile - original file whose's content shall be copied from |
4508 |
|
*/ |
4509 |
|
void File::AddContentOf(File* pFile) { |
4510 |
|
static int iCallCount = -1; |
4511 |
|
iCallCount++; |
4512 |
|
std::map<Group*,Group*> mGroups; |
4513 |
|
std::map<Sample*,Sample*> mSamples; |
4514 |
|
|
4515 |
|
// clone sample groups |
4516 |
|
for (int i = 0; pFile->GetGroup(i); ++i) { |
4517 |
|
Group* g = AddGroup(); |
4518 |
|
g->Name = |
4519 |
|
"COPY" + ToString(iCallCount) + "_" + pFile->GetGroup(i)->Name; |
4520 |
|
mGroups[pFile->GetGroup(i)] = g; |
4521 |
|
} |
4522 |
|
|
4523 |
|
// clone samples (not waveform data here yet) |
4524 |
|
for (int i = 0; pFile->GetSample(i); ++i) { |
4525 |
|
Sample* s = AddSample(); |
4526 |
|
s->CopyAssignMeta(pFile->GetSample(i)); |
4527 |
|
mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s); |
4528 |
|
mSamples[pFile->GetSample(i)] = s; |
4529 |
|
} |
4530 |
|
|
4531 |
|
//BUG: For some reason this method only works with this additional |
4532 |
|
// Save() call in between here. |
4533 |
|
// |
4534 |
|
// Important: The correct one of the 2 Save() methods has to be called |
4535 |
|
// here, depending on whether the file is completely new or has been |
4536 |
|
// saved to disk already, otherwise it will result in data corruption. |
4537 |
|
if (pRIFF->IsNew()) |
4538 |
|
Save(GetFileName()); |
4539 |
|
else |
4540 |
|
Save(); |
4541 |
|
|
4542 |
|
// clone instruments |
4543 |
|
// (passing the crosslink table here for the cloned samples) |
4544 |
|
for (int i = 0; pFile->GetInstrument(i); ++i) { |
4545 |
|
Instrument* instr = AddInstrument(); |
4546 |
|
instr->CopyAssign(pFile->GetInstrument(i), &mSamples); |
4547 |
|
} |
4548 |
|
|
4549 |
|
// Mandatory: file needs to be saved to disk at this point, so this |
4550 |
|
// file has the correct size and data layout for writing the samples' |
4551 |
|
// waveform data to disk. |
4552 |
|
Save(); |
4553 |
|
|
4554 |
|
// clone samples' waveform data |
4555 |
|
// (using direct read & write disk streaming) |
4556 |
|
for (int i = 0; pFile->GetSample(i); ++i) { |
4557 |
|
mSamples[pFile->GetSample(i)]->CopyAssignWave(pFile->GetSample(i)); |
4558 |
|
} |
4559 |
|
} |
4560 |
|
|
4561 |
/** @brief Delete an instrument. |
/** @brief Delete an instrument. |
4562 |
* |
* |
4659 |
return NULL; |
return NULL; |
4660 |
} |
} |
4661 |
|
|
4662 |
|
/** |
4663 |
|
* Returns the group with the given group name. |
4664 |
|
* |
4665 |
|
* Note: group names don't have to be unique in the gig format! So there |
4666 |
|
* can be multiple groups with the same name. This method will simply |
4667 |
|
* return the first group found with the given name. |
4668 |
|
* |
4669 |
|
* @param name - name of the sought group |
4670 |
|
* @returns sought group or NULL if there's no group with that name |
4671 |
|
*/ |
4672 |
|
Group* File::GetGroup(String name) { |
4673 |
|
if (!pGroups) LoadGroups(); |
4674 |
|
GroupsIterator = pGroups->begin(); |
4675 |
|
for (uint i = 0; GroupsIterator != pGroups->end(); ++GroupsIterator, ++i) |
4676 |
|
if ((*GroupsIterator)->Name == name) return *GroupsIterator; |
4677 |
|
return NULL; |
4678 |
|
} |
4679 |
|
|
4680 |
Group* File::AddGroup() { |
Group* File::AddGroup() { |
4681 |
if (!pGroups) LoadGroups(); |
if (!pGroups) LoadGroups(); |
4682 |
// there must always be at least one group |
// there must always be at least one group |
4787 |
|
|
4788 |
// update group's chunks |
// update group's chunks |
4789 |
if (pGroups) { |
if (pGroups) { |
4790 |
std::list<Group*>::iterator iter = pGroups->begin(); |
// make sure '3gri' and '3gnl' list chunks exist |
4791 |
std::list<Group*>::iterator end = pGroups->end(); |
// (before updating the Group chunks) |
4792 |
for (; iter != end; ++iter) { |
RIFF::List* _3gri = pRIFF->GetSubList(LIST_TYPE_3GRI); |
4793 |
(*iter)->UpdateChunks(); |
if (!_3gri) { |
4794 |
|
_3gri = pRIFF->AddSubList(LIST_TYPE_3GRI); |
4795 |
|
pRIFF->MoveSubChunk(_3gri, pRIFF->GetSubChunk(CHUNK_ID_PTBL)); |
4796 |
} |
} |
4797 |
|
RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); |
4798 |
|
if (!_3gnl) _3gnl = _3gri->AddSubList(LIST_TYPE_3GNL); |
4799 |
|
|
4800 |
// v3: make sure the file has 128 3gnm chunks |
// v3: make sure the file has 128 3gnm chunks |
4801 |
|
// (before updating the Group chunks) |
4802 |
if (pVersion && pVersion->major == 3) { |
if (pVersion && pVersion->major == 3) { |
|
RIFF::List* _3gnl = pRIFF->GetSubList(LIST_TYPE_3GRI)->GetSubList(LIST_TYPE_3GNL); |
|
4803 |
RIFF::Chunk* _3gnm = _3gnl->GetFirstSubChunk(); |
RIFF::Chunk* _3gnm = _3gnl->GetFirstSubChunk(); |
4804 |
for (int i = 0 ; i < 128 ; i++) { |
for (int i = 0 ; i < 128 ; i++) { |
4805 |
if (i >= pGroups->size()) ::SaveString(CHUNK_ID_3GNM, _3gnm, _3gnl, "", "", true, 64); |
if (i >= pGroups->size()) ::SaveString(CHUNK_ID_3GNM, _3gnm, _3gnl, "", "", true, 64); |
4806 |
if (_3gnm) _3gnm = _3gnl->GetNextSubChunk(); |
if (_3gnm) _3gnm = _3gnl->GetNextSubChunk(); |
4807 |
} |
} |
4808 |
} |
} |
4809 |
|
|
4810 |
|
std::list<Group*>::iterator iter = pGroups->begin(); |
4811 |
|
std::list<Group*>::iterator end = pGroups->end(); |
4812 |
|
for (; iter != end; ++iter) { |
4813 |
|
(*iter)->UpdateChunks(); |
4814 |
|
} |
4815 |
} |
} |
4816 |
|
|
4817 |
// update einf chunk |
// update einf chunk |