/[svn]/libgig/trunk/src/gig.cpp
ViewVC logotype

Diff of /libgig/trunk/src/gig.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1292 by schoenebeck, Sat Aug 11 14:38:51 2007 UTC revision 1316 by schoenebeck, Fri Aug 31 19:09:13 2007 UTC
# Line 1262  namespace { Line 1262  namespace {
1262      uint                               DimensionRegion::Instances       = 0;      uint                               DimensionRegion::Instances       = 0;
1263      DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL;      DimensionRegion::VelocityTableMap* DimensionRegion::pVelocityTables = NULL;
1264    
1265      DimensionRegion::DimensionRegion(RIFF::List* _3ewl) : DLS::Sampler(_3ewl) {      DimensionRegion::DimensionRegion(Region* pParent, RIFF::List* _3ewl) : DLS::Sampler(_3ewl) {
1266          Instances++;          Instances++;
1267    
1268          pSample = NULL;          pSample = NULL;
1269            pRegion = pParent;
1270    
1271          if (_3ewl->GetSubChunk(CHUNK_ID_WSMP)) memcpy(&Crossfade, &SamplerOptions, 4);          if (_3ewl->GetSubChunk(CHUNK_ID_WSMP)) memcpy(&Crossfade, &SamplerOptions, 4);
1272          else memset(&Crossfade, 0, 4);          else memset(&Crossfade, 0, 4);
# Line 1542  namespace { Line 1543  namespace {
1543          VelocityTable = 0;          VelocityTable = 0;
1544      }      }
1545    
1546        /*
1547         * Constructs a DimensionRegion by copying all parameters from
1548         * another DimensionRegion
1549         */
1550        DimensionRegion::DimensionRegion(RIFF::List* _3ewl, const DimensionRegion& src) : DLS::Sampler(_3ewl) {
1551            Instances++;
1552            *this = src; // default memberwise shallow copy of all parameters
1553            pParentList = _3ewl; // restore the chunk pointer
1554    
1555            // deep copy of owned structures
1556            if (src.VelocityTable) {
1557                VelocityTable = new uint8_t[128];
1558                for (int k = 0 ; k < 128 ; k++)
1559                    VelocityTable[k] = src.VelocityTable[k];
1560            }
1561            if (src.pSampleLoops) {
1562                pSampleLoops = new DLS::sample_loop_t[src.SampleLoops];
1563                for (int k = 0 ; k < src.SampleLoops ; k++)
1564                    pSampleLoops[k] = src.pSampleLoops[k];
1565            }
1566        }
1567    
1568      /**      /**
1569       * Apply dimension region settings to the respective RIFF chunks. You       * Apply dimension region settings to the respective RIFF chunks. You
1570       * have to call File::Save() to make changes persistent.       * have to call File::Save() to make changes persistent.
# Line 1852  namespace { Line 1875  namespace {
1875          return table;          return table;
1876      }      }
1877    
1878        Region* DimensionRegion::GetParent() const {
1879            return pRegion;
1880        }
1881    
1882      leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) {      leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) {
1883          leverage_ctrl_t decodedcontroller;          leverage_ctrl_t decodedcontroller;
1884          switch (EncodedController) {          switch (EncodedController) {
# Line 2251  namespace { Line 2278  namespace {
2278              RIFF::List* _3prg = rgnList->GetSubList(LIST_TYPE_3PRG);              RIFF::List* _3prg = rgnList->GetSubList(LIST_TYPE_3PRG);
2279              if (!_3prg) _3prg = rgnList->AddSubList(LIST_TYPE_3PRG);              if (!_3prg) _3prg = rgnList->AddSubList(LIST_TYPE_3PRG);
2280              RIFF::List* _3ewl = _3prg->AddSubList(LIST_TYPE_3EWL);              RIFF::List* _3ewl = _3prg->AddSubList(LIST_TYPE_3EWL);
2281              pDimensionRegions[0] = new DimensionRegion(_3ewl);              pDimensionRegions[0] = new DimensionRegion(this, _3ewl);
2282              DimensionRegions = 1;              DimensionRegions = 1;
2283          }          }
2284      }      }
# Line 2346  namespace { Line 2373  namespace {
2373              RIFF::List* _3ewl = _3prg->GetFirstSubList();              RIFF::List* _3ewl = _3prg->GetFirstSubList();
2374              while (_3ewl) {              while (_3ewl) {
2375                  if (_3ewl->GetListType() == LIST_TYPE_3EWL) {                  if (_3ewl->GetListType() == LIST_TYPE_3EWL) {
2376                      pDimensionRegions[dimensionRegionNr] = new DimensionRegion(_3ewl);                      pDimensionRegions[dimensionRegionNr] = new DimensionRegion(this, _3ewl);
2377                      dimensionRegionNr++;                      dimensionRegionNr++;
2378                  }                  }
2379                  _3ewl = _3prg->GetNextSubList();                  _3ewl = _3prg->GetNextSubList();
# Line 2460  namespace { Line 2487  namespace {
2487              if (pDimensionDefinitions[i].dimension == pDimDef->dimension)              if (pDimensionDefinitions[i].dimension == pDimDef->dimension)
2488                  throw gig::Exception("Could not add new dimension, there is already a dimension of the same type");                  throw gig::Exception("Could not add new dimension, there is already a dimension of the same type");
2489    
2490            // pos is where the new dimension should be placed, normally
2491            // last in list, except for the samplechannel dimension which
2492            // has to be first in list
2493            int pos = pDimDef->dimension == dimension_samplechannel ? 0 : Dimensions;
2494            int bitpos = 0;
2495            for (int i = 0 ; i < pos ; i++)
2496                bitpos += pDimensionDefinitions[i].bits;
2497    
2498            // make room for the new dimension
2499            for (int i = Dimensions ; i > pos ; i--) pDimensionDefinitions[i] = pDimensionDefinitions[i - 1];
2500            for (int i = 0 ; i < (1 << iCurrentBits) ; i++) {
2501                for (int j = Dimensions ; j > pos ; j--) {
2502                    pDimensionRegions[i]->DimensionUpperLimits[j] =
2503                        pDimensionRegions[i]->DimensionUpperLimits[j - 1];
2504                }
2505            }
2506    
2507          // assign definition of new dimension          // assign definition of new dimension
2508          pDimensionDefinitions[Dimensions] = *pDimDef;          pDimensionDefinitions[pos] = *pDimDef;
2509    
2510          // auto correct certain dimension definition fields (where possible)          // auto correct certain dimension definition fields (where possible)
2511          pDimensionDefinitions[Dimensions].split_type  =          pDimensionDefinitions[pos].split_type  =
2512              __resolveSplitType(pDimensionDefinitions[Dimensions].dimension);              __resolveSplitType(pDimensionDefinitions[pos].dimension);
2513          pDimensionDefinitions[Dimensions].zone_size =          pDimensionDefinitions[pos].zone_size =
2514              __resolveZoneSize(pDimensionDefinitions[Dimensions]);              __resolveZoneSize(pDimensionDefinitions[pos]);
2515    
2516          // create new dimension region(s) for this new dimension          // create new dimension region(s) for this new dimension, and make
2517          for (int i = 1 << iCurrentBits; i < 1 << iNewBits; i++) {          // sure that the dimension regions are placed correctly in both the
2518              //TODO: maybe we should copy existing dimension regions if possible instead of simply creating new ones with default values          // RIFF list and the pDimensionRegions array
2519              RIFF::List* _3prg = pCkRegion->GetSubList(LIST_TYPE_3PRG);          RIFF::Chunk* moveTo = NULL;
2520              RIFF::List* pNewDimRgnListChunk = _3prg->AddSubList(LIST_TYPE_3EWL);          RIFF::List* _3prg = pCkRegion->GetSubList(LIST_TYPE_3PRG);
2521              pDimensionRegions[i] = new DimensionRegion(pNewDimRgnListChunk);          for (int i = (1 << iCurrentBits) - (1 << bitpos) ; i >= 0 ; i -= (1 << bitpos)) {
2522                for (int k = 0 ; k < (1 << bitpos) ; k++) {
2523              // copy the upper limits for the other dimensions                  pDimensionRegions[(i << pDimDef->bits) + k] = pDimensionRegions[i + k];
2524              memcpy(pDimensionRegions[i]->DimensionUpperLimits,              }
2525                     pDimensionRegions[i & ((1 << iCurrentBits) - 1)]->DimensionUpperLimits, 8);              for (int j = 1 ; j < (1 << pDimDef->bits) ; j++) {
2526                    for (int k = 0 ; k < (1 << bitpos) ; k++) {
2527                        RIFF::List* pNewDimRgnListChunk = _3prg->AddSubList(LIST_TYPE_3EWL);
2528                        if (moveTo) _3prg->MoveSubChunk(pNewDimRgnListChunk, moveTo);
2529                        // create a new dimension region and copy all parameter values from
2530                        // an existing dimension region
2531                        pDimensionRegions[(i << pDimDef->bits) + (j << bitpos) + k] =
2532                            new DimensionRegion(pNewDimRgnListChunk, *pDimensionRegions[i + k]);
2533    
2534              DimensionRegions++;                      DimensionRegions++;
2535                    }
2536                }
2537                moveTo = pDimensionRegions[i]->pParentList;
2538          }          }
2539    
2540          // initialize the upper limits for this dimension          // initialize the upper limits for this dimension
2541          for (int z = 0, j = 0 ; z < pDimDef->zones ; z++, j += 1 << iCurrentBits) {          int mask = (1 << bitpos) - 1;
2542            for (int z = 0 ; z < pDimDef->zones ; z++) {
2543              uint8_t upperLimit = uint8_t((z + 1) * 128.0 / pDimDef->zones - 1);              uint8_t upperLimit = uint8_t((z + 1) * 128.0 / pDimDef->zones - 1);
2544              for (int i = 0 ; i < 1 << iCurrentBits ; i++) {              for (int i = 0 ; i < 1 << iCurrentBits ; i++) {
2545                  pDimensionRegions[j + i]->DimensionUpperLimits[Dimensions] = upperLimit;                  pDimensionRegions[((i & ~mask) << pDimDef->bits) |
2546                                      (z << bitpos) |
2547                                      (i & mask)]->DimensionUpperLimits[pos] = upperLimit;
2548              }              }
2549          }          }
2550    

Legend:
Removed from v.1292  
changed lines
  Added in v.1316

  ViewVC Help
Powered by ViewVC