--- libgig/trunk/src/gig.cpp 2006/10/29 17:57:20 930 +++ libgig/trunk/src/gig.cpp 2007/03/06 18:33:30 1076 @@ -1,8 +1,8 @@ /*************************************************************************** * * - * libgig - C++ cross-platform Gigasampler format file loader library * + * libgig - C++ cross-platform Gigasampler format file access library * * * - * Copyright (C) 2003-2006 by Christian Schoenebeck * + * Copyright (C) 2003-2007 by Christian Schoenebeck * * * * * * This library is free software; you can redistribute it and/or modify * @@ -364,7 +364,7 @@ * Usually there is absolutely no need to call this method explicitly. * It will be called automatically when File::Save() was called. * - * @throws DLS::Exception if FormatTag != WAVE_FORMAT_PCM or no sample data + * @throws DLS::Exception if FormatTag != DLS_WAVE_FORMAT_PCM or no sample data * was provided yet * @throws gig::Exception if there is any invalid sample setting */ @@ -635,13 +635,13 @@ * enlarged samples before calling File::Save() as this might exceed the * current sample's boundary! * - * Also note: only WAVE_FORMAT_PCM is currently supported, that is - * FormatTag must be WAVE_FORMAT_PCM. Trying to resize samples with + * Also note: only DLS_WAVE_FORMAT_PCM is currently supported, that is + * FormatTag must be DLS_WAVE_FORMAT_PCM. Trying to resize samples with * other formats will fail! * * @param iNewSize - new sample wave data size in sample points (must be * greater than zero) - * @throws DLS::Excecption if FormatTag != WAVE_FORMAT_PCM + * @throws DLS::Excecption if FormatTag != DLS_WAVE_FORMAT_PCM * or if \a iNewSize is less than 1 * @throws gig::Exception if existing sample is compressed * @see DLS::Sample::GetSize(), DLS::Sample::FrameSize, @@ -1338,6 +1338,11 @@ if (lfo3ctrl & 0x40) // bit 6 VCFType = vcf_type_lowpassturbo; } + if (_3ewa->RemainingBytes() >= 8) { + _3ewa->Read(DimensionUpperLimits, 1, 8); + } else { + memset(DimensionUpperLimits, 0, 8); + } } else { // '3ewa' chunk does not exist yet // use default values LFO3Frequency = 1.0; @@ -1418,6 +1423,7 @@ VCFVelocityDynamicRange = 0x04; VCFVelocityCurve = curve_type_linear; VCFType = vcf_type_lowpass; + memset(DimensionUpperLimits, 0, 8); } pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve, @@ -1473,8 +1479,8 @@ // update '3ewa' chunk with DimensionRegion's current settings - const uint32_t unknown = _3ewa->GetSize(); // unknown, always chunk size ? - memcpy(&pData[0], &unknown, 4); + const uint32_t chunksize = _3ewa->GetSize(); + memcpy(&pData[0], &chunksize, 4); // unknown, always chunk size? const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); memcpy(&pData[4], &lfo3freq, 4); @@ -1729,6 +1735,10 @@ const uint8_t vcftype = (VCFType == vcf_type_lowpassturbo) ? vcf_type_lowpass : VCFType; memcpy(&pData[139], &vcftype, 1); + + if (chunksize >= 148) { + memcpy(&pData[140], DimensionUpperLimits, 8); + } } // get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet @@ -2110,8 +2120,10 @@ dimension == dimension_releasetrigger || dimension == dimension_keyboard || dimension == dimension_roundrobin || - dimension == dimension_random) ? split_type_bit - : split_type_normal; + dimension == dimension_random || + dimension == dimension_smartmidi || + dimension == dimension_roundrobinkeyboard) ? split_type_bit + : split_type_normal; pDimensionDefinitions[i].zone_size = (pDimensionDefinitions[i].split_type == split_type_normal) ? 128.0 / pDimensionDefinitions[i].zones : 0; @@ -2248,7 +2260,8 @@ int dim[8] = { 0 }; for (int i = 0 ; i < DimensionRegions ; i++) { - if (pDimensionRegions[i]->VelocityUpperLimit) { + if (pDimensionRegions[i]->DimensionUpperLimits[veldim] || + pDimensionRegions[i]->VelocityUpperLimit) { // create the velocity table uint8_t* table = pDimensionRegions[i]->VelocityTable; if (!table) { @@ -2257,10 +2270,18 @@ } int tableidx = 0; int velocityZone = 0; - for (int k = i ; k < end ; k += step) { - DimensionRegion *d = pDimensionRegions[k]; - for (; tableidx <= d->VelocityUpperLimit ; tableidx++) table[tableidx] = velocityZone; - velocityZone++; + if (pDimensionRegions[i]->DimensionUpperLimits[veldim]) { // gig3 + for (int k = i ; k < end ; k += step) { + DimensionRegion *d = pDimensionRegions[k]; + for (; tableidx <= d->DimensionUpperLimits[veldim] ; tableidx++) table[tableidx] = velocityZone; + velocityZone++; + } + } else { // gig2 + for (int k = i ; k < end ; k += step) { + DimensionRegion *d = pDimensionRegions[k]; + for (; tableidx <= d->VelocityUpperLimit ; tableidx++) table[tableidx] = velocityZone; + velocityZone++; + } } } else { if (pDimensionRegions[i]->VelocityTable) { @@ -2455,7 +2476,15 @@ } else { switch (pDimensionDefinitions[i].split_type) { case split_type_normal: - bits = uint8_t(DimValues[i] / pDimensionDefinitions[i].zone_size); + if (pDimensionRegions[0]->DimensionUpperLimits[i]) { + // gig3: all normal dimensions (not just the velocity dimension) have custom zone ranges + for (bits = 0 ; bits < pDimensionDefinitions[i].zones ; bits++) { + if (DimValues[i] <= pDimensionRegions[bits << bitpos]->DimensionUpperLimits[i]) break; + } + } else { + // gig2: evenly sized zones + bits = uint8_t(DimValues[i] / pDimensionDefinitions[i].zone_size); + } break; case split_type_bit: // the value is already the sought dimension bit number const uint8_t limiter_mask = (0xff << pDimensionDefinitions[i].bits) ^ 0xff; @@ -2469,7 +2498,7 @@ DimensionRegion* dimreg = pDimensionRegions[dimregidx]; if (veldim != -1) { // (dimreg is now the dimension region for the lowest velocity) - if (dimreg->VelocityUpperLimit) // custom defined zone ranges + if (dimreg->VelocityTable) // custom defined zone ranges bits = dimreg->VelocityTable[DimValues[veldim]]; else // normal split type bits = uint8_t(DimValues[veldim] / pDimensionDefinitions[veldim].zone_size);