--- libgig/trunk/src/gig.cpp 2017/05/03 14:41:58 3138 +++ libgig/trunk/src/gig.cpp 2017/07/23 18:18:30 3327 @@ -24,6 +24,7 @@ #include "gig.h" #include "helper.h" +#include "Serialization.h" #include #include @@ -340,6 +341,27 @@ +// *************** eg_opt_t *************** +// * + + eg_opt_t::eg_opt_t() { + AttackCancel = true; + AttackHoldCancel = true; + Decay1Cancel = true; + Decay2Cancel = true; + ReleaseCancel = true; + } + + void eg_opt_t::serialize(Serialization::Archive* archive) { + SRLZ(AttackCancel); + SRLZ(AttackHoldCancel); + SRLZ(Decay1Cancel); + SRLZ(Decay2Cancel); + SRLZ(ReleaseCancel); + } + + + // *************** Sample *************** // * @@ -1710,6 +1732,20 @@ VCFType = vcf_type_lowpass; memset(DimensionUpperLimits, 127, 8); } + // format extension for EG behavior options, these will *NOT* work with + // Gigasampler/GigaStudio ! + RIFF::Chunk* lsde = _3ewl->GetSubChunk(CHUNK_ID_LSDE); + if (lsde) { + eg_opt_t* pEGOpts[2] = { &EG1Options, &EG2Options }; + for (int i = 0; i < 2; ++i) { + unsigned char byte = lsde->ReadUint8(); + pEGOpts[i]->AttackCancel = byte & 1; + pEGOpts[i]->AttackHoldCancel = byte & (1 << 1); + pEGOpts[i]->Decay1Cancel = byte & (1 << 2); + pEGOpts[i]->Decay2Cancel = byte & (1 << 3); + pEGOpts[i]->ReleaseCancel = byte & (1 << 4); + } + } pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, VelocityResponseDepth, @@ -1816,6 +1852,11 @@ } void DimensionRegion::serialize(Serialization::Archive* archive) { + // in case this class will become backward incompatible one day, + // then set a version and minimum version for this class like: + //archive->setVersion(*this, 2); + //archive->setMinVersion(*this, 1); + SRLZ(VelocityUpperLimit); SRLZ(EG1PreAttack); SRLZ(EG1Attack); @@ -1893,6 +1934,8 @@ SRLZ(MSDecode); //SRLZ(SampleStartOffset); SRLZ(SampleAttenuation); + SRLZ(EG1Options); + SRLZ(EG2Options); // derived attributes from DLS::Sampler SRLZ(FineTune); @@ -2199,6 +2242,34 @@ if (chunksize >= 148) { memcpy(&pData[140], DimensionUpperLimits, 8); } + + // format extension for EG behavior options, these will *NOT* work with + // Gigasampler/GigaStudio ! + RIFF::Chunk* lsde = pParentList->GetSubChunk(CHUNK_ID_LSDE); + if (!lsde) { + // only add this "LSDE" chunk if the EG options do not match the + // default EG behavior + eg_opt_t defaultOpt; + if (memcmp(&EG1Options, &defaultOpt, sizeof(eg_opt_t)) || + memcmp(&EG2Options, &defaultOpt, sizeof(eg_opt_t))) + { + lsde = pParentList->AddSubChunk(CHUNK_ID_LSDE, 2); + // move LSDE chunk to the end of parent list + pParentList->MoveSubChunk(lsde, (RIFF::Chunk*)NULL); + } + } + if (lsde) { + unsigned char* pData = (unsigned char*) lsde->LoadChunkData(); + eg_opt_t* pEGOpts[2] = { &EG1Options, &EG2Options }; + for (int i = 0; i < 2; ++i) { + pData[i] = + (pEGOpts[i]->AttackCancel ? 1 : 0) | + (pEGOpts[i]->AttackHoldCancel ? (1<<1) : 0) | + (pEGOpts[i]->Decay1Cancel ? (1<<2) : 0) | + (pEGOpts[i]->Decay2Cancel ? (1<<3) : 0) | + (pEGOpts[i]->ReleaseCancel ? (1<<4) : 0); + } + } } double* DimensionRegion::GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth) { @@ -2613,7 +2684,10 @@ // unknown controller type default: - throw gig::Exception("Unknown leverage controller type."); + decodedcontroller.type = leverage_ctrl_t::type_none; + decodedcontroller.controller_number = 0; + printf("Warning: Unknown leverage controller type (0x%x).\n", EncodedController); + break; } return decodedcontroller; } @@ -6467,7 +6541,18 @@ // *************** Exception *************** // * - Exception::Exception(String Message) : DLS::Exception(Message) { + Exception::Exception() : DLS::Exception() { + } + + Exception::Exception(String format, ...) : DLS::Exception() { + va_list arg; + va_start(arg, format); + Message = assemble(format, arg); + va_end(arg); + } + + Exception::Exception(String format, va_list arg) : DLS::Exception() { + Message = assemble(format, arg); } void Exception::PrintMessage() {