/[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 902 by persson, Sat Jul 22 14:22:01 2006 UTC revision 929 by schoenebeck, Tue Oct 24 22:24:45 2006 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file loader library    *   *   libgig - C++ cross-platform Gigasampler format file loader library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003-2005 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2006 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  *
# Line 279  namespace { Line 279  namespace {
279       *                         is located, 0 otherwise       *                         is located, 0 otherwise
280       */       */
281      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) {
282            pInfo->UseFixedLengthStrings = true;
283          Instances++;          Instances++;
284          FileNo = fileNo;          FileNo = fileNo;
285    
286          pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX);          pCk3gix = waveList->GetSubChunk(CHUNK_ID_3GIX);
287          if (pCk3gix) {          if (pCk3gix) {
288              SampleGroup = pCk3gix->ReadInt16();              uint16_t iSampleGroup = pCk3gix->ReadInt16();
289                // caution: sample groups in .gig files are indexed (1..n) whereas Groups in libgig (0..n-1)
290                pGroup = pFile->GetGroup(iSampleGroup - 1);
291          } else { // '3gix' chunk missing          } else { // '3gix' chunk missing
292              // use default value(s)              // not assigned to a group by default
293              SampleGroup = 0;              pGroup = NULL;
294          }          }
295    
296          pCkSmpl = waveList->GetSubChunk(CHUNK_ID_SMPL);          pCkSmpl = waveList->GetSubChunk(CHUNK_ID_SMPL);
# Line 311  namespace { Line 314  namespace {
314              // use default values              // use default values
315              Manufacturer  = 0;              Manufacturer  = 0;
316              Product       = 0;              Product       = 0;
317              SamplePeriod  = 1 / SamplesPerSecond;              SamplePeriod  = uint32_t(1000000000.0 / SamplesPerSecond + 0.5);
318              MIDIUnityNote = 64;              MIDIUnityNote = 64;
319              FineTune      = 0;              FineTune      = 0;
320              SMPTEOffset   = 0;              SMPTEOffset   = 0;
# Line 375  namespace { Line 378  namespace {
378          if (!pCkSmpl) pCkSmpl = pWaveList->AddSubChunk(CHUNK_ID_SMPL, 60);          if (!pCkSmpl) pCkSmpl = pWaveList->AddSubChunk(CHUNK_ID_SMPL, 60);
379          // update 'smpl' chunk          // update 'smpl' chunk
380          uint8_t* pData = (uint8_t*) pCkSmpl->LoadChunkData();          uint8_t* pData = (uint8_t*) pCkSmpl->LoadChunkData();
381          SamplePeriod = 1 / SamplesPerSecond;          SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5);
382          memcpy(&pData[0], &Manufacturer, 4);          memcpy(&pData[0], &Manufacturer, 4);
383          memcpy(&pData[4], &Product, 4);          memcpy(&pData[4], &Product, 4);
384          memcpy(&pData[8], &SamplePeriod, 4);          memcpy(&pData[8], &SamplePeriod, 4);
# Line 397  namespace { Line 400  namespace {
400          // make sure '3gix' chunk exists          // make sure '3gix' chunk exists
401          pCk3gix = pWaveList->GetSubChunk(CHUNK_ID_3GIX);          pCk3gix = pWaveList->GetSubChunk(CHUNK_ID_3GIX);
402          if (!pCk3gix) pCk3gix = pWaveList->AddSubChunk(CHUNK_ID_3GIX, 4);          if (!pCk3gix) pCk3gix = pWaveList->AddSubChunk(CHUNK_ID_3GIX, 4);
403            // determine appropriate sample group index (to be stored in chunk)
404            uint16_t iSampleGroup = 0; // no sample group by default
405            File* pFile = static_cast<File*>(pParent);
406            if (pFile->pGroups) {
407                std::list<Group*>::iterator iter = pFile->pGroups->begin();
408                std::list<Group*>::iterator end  = pFile->pGroups->end();
409                // caution: sample groups in .gig files are indexed (1..n) whereas Groups in libgig (0..n-1)
410                for (int i = 1; iter != end; i++, iter++) {
411                    if (*iter == pGroup) {
412                        iSampleGroup = i;
413                        break; // found
414                    }
415                }
416            }
417          // update '3gix' chunk          // update '3gix' chunk
418          pData = (uint8_t*) pCk3gix->LoadChunkData();          pData = (uint8_t*) pCk3gix->LoadChunkData();
419          memcpy(&pData[0], &SampleGroup, 2);          memcpy(&pData[0], &iSampleGroup, 2);
420      }      }
421    
422      /// 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).
# Line 1166  namespace { Line 1183  namespace {
1183    
1184          RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA);          RIFF::Chunk* _3ewa = _3ewl->GetSubChunk(CHUNK_ID_3EWA);
1185          if (_3ewa) { // if '3ewa' chunk exists          if (_3ewa) { // if '3ewa' chunk exists
1186              _3ewa->ReadInt32(); // unknown, always 0x0000008C ?              _3ewa->ReadInt32(); // unknown, always == chunk size ?
1187              LFO3Frequency = (double) GIG_EXP_DECODE(_3ewa->ReadInt32());              LFO3Frequency = (double) GIG_EXP_DECODE(_3ewa->ReadInt32());
1188              EG3Attack     = (double) GIG_EXP_DECODE(_3ewa->ReadInt32());              EG3Attack     = (double) GIG_EXP_DECODE(_3ewa->ReadInt32());
1189              _3ewa->ReadInt16(); // unknown              _3ewa->ReadInt16(); // unknown
# Line 1446  namespace { Line 1463  namespace {
1463    
1464          // update '3ewa' chunk with DimensionRegion's current settings          // update '3ewa' chunk with DimensionRegion's current settings
1465    
1466          const uint32_t unknown = 0x0000008C; // unknown, always 0x0000008C ?          const uint32_t unknown = _3ewa->GetSize(); // unknown, always chunk size ?
1467          memcpy(&pData[0], &unknown, 4);          memcpy(&pData[0], &unknown, 4);
1468    
1469          const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency);          const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency);
1470          memcpy(&pData[4], &lfo3freq, 4);          memcpy(&pData[4], &lfo3freq, 4);
1471    
1472          const int32_t eg3attack = (int32_t) GIG_EXP_ENCODE(EG3Attack);          const int32_t eg3attack = (int32_t) GIG_EXP_ENCODE(EG3Attack);
1473          memcpy(&pData[4], &eg3attack, 4);          memcpy(&pData[8], &eg3attack, 4);
1474    
1475          // next 2 bytes unknown          // next 2 bytes unknown
1476    
1477          memcpy(&pData[10], &LFO1InternalDepth, 2);          memcpy(&pData[14], &LFO1InternalDepth, 2);
1478    
1479          // next 2 bytes unknown          // next 2 bytes unknown
1480    
1481          memcpy(&pData[14], &LFO3InternalDepth, 2);          memcpy(&pData[18], &LFO3InternalDepth, 2);
1482    
1483          // next 2 bytes unknown          // next 2 bytes unknown
1484    
1485          memcpy(&pData[18], &LFO1ControlDepth, 2);          memcpy(&pData[22], &LFO1ControlDepth, 2);
1486    
1487          // next 2 bytes unknown          // next 2 bytes unknown
1488    
1489          memcpy(&pData[22], &LFO3ControlDepth, 2);          memcpy(&pData[26], &LFO3ControlDepth, 2);
1490    
1491          const int32_t eg1attack = (int32_t) GIG_EXP_ENCODE(EG1Attack);          const int32_t eg1attack = (int32_t) GIG_EXP_ENCODE(EG1Attack);
1492          memcpy(&pData[24], &eg1attack, 4);          memcpy(&pData[28], &eg1attack, 4);
1493    
1494          const int32_t eg1decay1 = (int32_t) GIG_EXP_ENCODE(EG1Decay1);          const int32_t eg1decay1 = (int32_t) GIG_EXP_ENCODE(EG1Decay1);
1495          memcpy(&pData[28], &eg1decay1, 4);          memcpy(&pData[32], &eg1decay1, 4);
1496    
1497          // next 2 bytes unknown          // next 2 bytes unknown
1498    
1499          memcpy(&pData[34], &EG1Sustain, 2);          memcpy(&pData[38], &EG1Sustain, 2);
1500    
1501          const int32_t eg1release = (int32_t) GIG_EXP_ENCODE(EG1Release);          const int32_t eg1release = (int32_t) GIG_EXP_ENCODE(EG1Release);
1502          memcpy(&pData[36], &eg1release, 4);          memcpy(&pData[40], &eg1release, 4);
1503    
1504          const uint8_t eg1ctl = (uint8_t) EncodeLeverageController(EG1Controller);          const uint8_t eg1ctl = (uint8_t) EncodeLeverageController(EG1Controller);
1505          memcpy(&pData[40], &eg1ctl, 1);          memcpy(&pData[44], &eg1ctl, 1);
1506    
1507          const uint8_t eg1ctrloptions =          const uint8_t eg1ctrloptions =
1508              (EG1ControllerInvert) ? 0x01 : 0x00 |              (EG1ControllerInvert) ? 0x01 : 0x00 |
1509              GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG1ControllerAttackInfluence) |              GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG1ControllerAttackInfluence) |
1510              GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG1ControllerDecayInfluence) |              GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG1ControllerDecayInfluence) |
1511              GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG1ControllerReleaseInfluence);              GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG1ControllerReleaseInfluence);
1512          memcpy(&pData[41], &eg1ctrloptions, 1);          memcpy(&pData[45], &eg1ctrloptions, 1);
1513    
1514          const uint8_t eg2ctl = (uint8_t) EncodeLeverageController(EG2Controller);          const uint8_t eg2ctl = (uint8_t) EncodeLeverageController(EG2Controller);
1515          memcpy(&pData[42], &eg2ctl, 1);          memcpy(&pData[46], &eg2ctl, 1);
1516    
1517          const uint8_t eg2ctrloptions =          const uint8_t eg2ctrloptions =
1518              (EG2ControllerInvert) ? 0x01 : 0x00 |              (EG2ControllerInvert) ? 0x01 : 0x00 |
1519              GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG2ControllerAttackInfluence) |              GIG_EG_CTR_ATTACK_INFLUENCE_ENCODE(EG2ControllerAttackInfluence) |
1520              GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG2ControllerDecayInfluence) |              GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(EG2ControllerDecayInfluence) |
1521              GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG2ControllerReleaseInfluence);              GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(EG2ControllerReleaseInfluence);
1522          memcpy(&pData[43], &eg2ctrloptions, 1);          memcpy(&pData[47], &eg2ctrloptions, 1);
1523    
1524          const int32_t lfo1freq = (int32_t) GIG_EXP_ENCODE(LFO1Frequency);          const int32_t lfo1freq = (int32_t) GIG_EXP_ENCODE(LFO1Frequency);
1525          memcpy(&pData[44], &lfo1freq, 4);          memcpy(&pData[48], &lfo1freq, 4);
1526    
1527          const int32_t eg2attack = (int32_t) GIG_EXP_ENCODE(EG2Attack);          const int32_t eg2attack = (int32_t) GIG_EXP_ENCODE(EG2Attack);
1528          memcpy(&pData[48], &eg2attack, 4);          memcpy(&pData[52], &eg2attack, 4);
1529    
1530          const int32_t eg2decay1 = (int32_t) GIG_EXP_ENCODE(EG2Decay1);          const int32_t eg2decay1 = (int32_t) GIG_EXP_ENCODE(EG2Decay1);
1531          memcpy(&pData[52], &eg2decay1, 4);          memcpy(&pData[56], &eg2decay1, 4);
1532    
1533          // next 2 bytes unknown          // next 2 bytes unknown
1534    
1535          memcpy(&pData[58], &EG2Sustain, 2);          memcpy(&pData[62], &EG2Sustain, 2);
1536    
1537          const int32_t eg2release = (int32_t) GIG_EXP_ENCODE(EG2Release);          const int32_t eg2release = (int32_t) GIG_EXP_ENCODE(EG2Release);
1538          memcpy(&pData[60], &eg2release, 4);          memcpy(&pData[64], &eg2release, 4);
1539    
1540          // next 2 bytes unknown          // next 2 bytes unknown
1541    
1542          memcpy(&pData[66], &LFO2ControlDepth, 2);          memcpy(&pData[70], &LFO2ControlDepth, 2);
1543    
1544          const int32_t lfo2freq = (int32_t) GIG_EXP_ENCODE(LFO2Frequency);          const int32_t lfo2freq = (int32_t) GIG_EXP_ENCODE(LFO2Frequency);
1545          memcpy(&pData[68], &lfo2freq, 4);          memcpy(&pData[72], &lfo2freq, 4);
1546    
1547          // next 2 bytes unknown          // next 2 bytes unknown
1548    
1549          memcpy(&pData[72], &LFO2InternalDepth, 2);          memcpy(&pData[78], &LFO2InternalDepth, 2);
1550    
1551          const int32_t eg1decay2 = (int32_t) (EG1InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG1Decay2);          const int32_t eg1decay2 = (int32_t) (EG1InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG1Decay2);
1552          memcpy(&pData[74], &eg1decay2, 4);          memcpy(&pData[80], &eg1decay2, 4);
1553    
1554          // next 2 bytes unknown          // next 2 bytes unknown
1555    
1556          memcpy(&pData[80], &EG1PreAttack, 2);          memcpy(&pData[86], &EG1PreAttack, 2);
1557    
1558          const int32_t eg2decay2 = (int32_t) (EG2InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG2Decay2);          const int32_t eg2decay2 = (int32_t) (EG2InfiniteSustain) ? 0x7fffffff : (int32_t) GIG_EXP_ENCODE(EG2Decay2);
1559          memcpy(&pData[82], &eg2decay2, 4);          memcpy(&pData[88], &eg2decay2, 4);
1560    
1561          // next 2 bytes unknown          // next 2 bytes unknown
1562    
1563          memcpy(&pData[88], &EG2PreAttack, 2);          memcpy(&pData[94], &EG2PreAttack, 2);
1564    
1565          {          {
1566              if (VelocityResponseDepth > 4) throw Exception("VelocityResponseDepth must be between 0 and 4");              if (VelocityResponseDepth > 4) throw Exception("VelocityResponseDepth must be between 0 and 4");
# Line 1561  namespace { Line 1578  namespace {
1578                  default:                  default:
1579                      throw Exception("Could not update DimensionRegion's chunk, unknown VelocityResponseCurve selected");                      throw Exception("Could not update DimensionRegion's chunk, unknown VelocityResponseCurve selected");
1580              }              }
1581              memcpy(&pData[90], &velocityresponse, 1);              memcpy(&pData[96], &velocityresponse, 1);
1582          }          }
1583    
1584          {          {
# Line 1580  namespace { Line 1597  namespace {
1597                  default:                  default:
1598                      throw Exception("Could not update DimensionRegion's chunk, unknown ReleaseVelocityResponseCurve selected");                      throw Exception("Could not update DimensionRegion's chunk, unknown ReleaseVelocityResponseCurve selected");
1599              }              }
1600              memcpy(&pData[91], &releasevelocityresponse, 1);              memcpy(&pData[97], &releasevelocityresponse, 1);
1601          }          }
1602    
1603          memcpy(&pData[92], &VelocityResponseCurveScaling, 1);          memcpy(&pData[98], &VelocityResponseCurveScaling, 1);
1604    
1605          memcpy(&pData[93], &AttenuationControllerThreshold, 1);          memcpy(&pData[99], &AttenuationControllerThreshold, 1);
1606    
1607          // next 4 bytes unknown          // next 4 bytes unknown
1608    
1609          memcpy(&pData[98], &SampleStartOffset, 2);          memcpy(&pData[104], &SampleStartOffset, 2);
1610    
1611          // next 2 bytes unknown          // next 2 bytes unknown
1612    
# Line 1608  namespace { Line 1625  namespace {
1625                  default:                  default:
1626                      throw Exception("Could not update DimensionRegion's chunk, unknown DimensionBypass selected");                      throw Exception("Could not update DimensionRegion's chunk, unknown DimensionBypass selected");
1627              }              }
1628              memcpy(&pData[102], &pitchTrackDimensionBypass, 1);              memcpy(&pData[108], &pitchTrackDimensionBypass, 1);
1629          }          }
1630    
1631          const uint8_t pan = (Pan >= 0) ? Pan : ((-Pan) + 63); // signed 8 bit -> signed 7 bit          const uint8_t pan = (Pan >= 0) ? Pan : ((-Pan) + 63); // signed 8 bit -> signed 7 bit
1632          memcpy(&pData[103], &pan, 1);          memcpy(&pData[109], &pan, 1);
1633    
1634          const uint8_t selfmask = (SelfMask) ? 0x01 : 0x00;          const uint8_t selfmask = (SelfMask) ? 0x01 : 0x00;
1635          memcpy(&pData[104], &selfmask, 1);          memcpy(&pData[110], &selfmask, 1);
1636    
1637          // next byte unknown          // next byte unknown
1638    
# Line 1624  namespace { Line 1641  namespace {
1641              if (LFO3Sync) lfo3ctrl |= 0x20; // bit 5              if (LFO3Sync) lfo3ctrl |= 0x20; // bit 5
1642              if (InvertAttenuationController) lfo3ctrl |= 0x80; // bit 7              if (InvertAttenuationController) lfo3ctrl |= 0x80; // bit 7
1643              if (VCFType == vcf_type_lowpassturbo) lfo3ctrl |= 0x40; // bit 6              if (VCFType == vcf_type_lowpassturbo) lfo3ctrl |= 0x40; // bit 6
1644              memcpy(&pData[106], &lfo3ctrl, 1);              memcpy(&pData[112], &lfo3ctrl, 1);
1645          }          }
1646    
1647          const uint8_t attenctl = EncodeLeverageController(AttenuationController);          const uint8_t attenctl = EncodeLeverageController(AttenuationController);
1648          memcpy(&pData[107], &attenctl, 1);          memcpy(&pData[113], &attenctl, 1);
1649    
1650          {          {
1651              uint8_t lfo2ctrl = LFO2Controller & 0x07; // lower 3 bits              uint8_t lfo2ctrl = LFO2Controller & 0x07; // lower 3 bits
1652              if (LFO2FlipPhase) lfo2ctrl |= 0x80; // bit 7              if (LFO2FlipPhase) lfo2ctrl |= 0x80; // bit 7
1653              if (LFO2Sync)      lfo2ctrl |= 0x20; // bit 5              if (LFO2Sync)      lfo2ctrl |= 0x20; // bit 5
1654              if (VCFResonanceController != vcf_res_ctrl_none) lfo2ctrl |= 0x40; // bit 6              if (VCFResonanceController != vcf_res_ctrl_none) lfo2ctrl |= 0x40; // bit 6
1655              memcpy(&pData[108], &lfo2ctrl, 1);              memcpy(&pData[114], &lfo2ctrl, 1);
1656          }          }
1657    
1658          {          {
# Line 1644  namespace { Line 1661  namespace {
1661              if (LFO1Sync)      lfo1ctrl |= 0x40; // bit 6              if (LFO1Sync)      lfo1ctrl |= 0x40; // bit 6
1662              if (VCFResonanceController != vcf_res_ctrl_none)              if (VCFResonanceController != vcf_res_ctrl_none)
1663                  lfo1ctrl |= GIG_VCF_RESONANCE_CTRL_ENCODE(VCFResonanceController);                  lfo1ctrl |= GIG_VCF_RESONANCE_CTRL_ENCODE(VCFResonanceController);
1664              memcpy(&pData[109], &lfo1ctrl, 1);              memcpy(&pData[115], &lfo1ctrl, 1);
1665          }          }
1666    
1667          const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth          const uint16_t eg3depth = (EG3Depth >= 0) ? EG3Depth
1668                                                    : uint16_t(((-EG3Depth) - 1) ^ 0xffff); /* binary complementary for negatives */                                                    : uint16_t(((-EG3Depth) - 1) ^ 0xffff); /* binary complementary for negatives */
1669          memcpy(&pData[110], &eg3depth, 1);          memcpy(&pData[116], &eg3depth, 1);
1670    
1671          // next 2 bytes unknown          // next 2 bytes unknown
1672    
1673          const uint8_t channeloffset = ChannelOffset * 4;          const uint8_t channeloffset = ChannelOffset * 4;
1674          memcpy(&pData[113], &channeloffset, 1);          memcpy(&pData[120], &channeloffset, 1);
1675    
1676          {          {
1677              uint8_t regoptions = 0;              uint8_t regoptions = 0;
1678              if (MSDecode)      regoptions |= 0x01; // bit 0              if (MSDecode)      regoptions |= 0x01; // bit 0
1679              if (SustainDefeat) regoptions |= 0x02; // bit 1              if (SustainDefeat) regoptions |= 0x02; // bit 1
1680              memcpy(&pData[114], &regoptions, 1);              memcpy(&pData[121], &regoptions, 1);
1681          }          }
1682    
1683          // next 2 bytes unknown          // next 2 bytes unknown
1684    
1685          memcpy(&pData[117], &VelocityUpperLimit, 1);          memcpy(&pData[124], &VelocityUpperLimit, 1);
1686    
1687          // next 3 bytes unknown          // next 3 bytes unknown
1688    
1689          memcpy(&pData[121], &ReleaseTriggerDecay, 1);          memcpy(&pData[128], &ReleaseTriggerDecay, 1);
1690    
1691          // next 2 bytes unknown          // next 2 bytes unknown
1692    
1693          const uint8_t eg1hold = (EG1Hold) ? 0x80 : 0x00; // bit 7          const uint8_t eg1hold = (EG1Hold) ? 0x80 : 0x00; // bit 7
1694          memcpy(&pData[124], &eg1hold, 1);          memcpy(&pData[131], &eg1hold, 1);
1695    
1696          const uint8_t vcfcutoff = (VCFEnabled) ? 0x80 : 0x00 |  /* bit 7 */          const uint8_t vcfcutoff = (VCFEnabled) ? 0x80 : 0x00 |  /* bit 7 */
1697                                    (VCFCutoff)  ? 0x7f : 0x00;   /* lower 7 bits */                                    (VCFCutoff & 0x7f);   /* lower 7 bits */
1698          memcpy(&pData[125], &vcfcutoff, 1);          memcpy(&pData[132], &vcfcutoff, 1);
1699    
1700          memcpy(&pData[126], &VCFCutoffController, 1);          memcpy(&pData[133], &VCFCutoffController, 1);
1701    
1702          const uint8_t vcfvelscale = (VCFCutoffControllerInvert) ? 0x80 : 0x00 | /* bit 7 */          const uint8_t vcfvelscale = (VCFCutoffControllerInvert) ? 0x80 : 0x00 | /* bit 7 */
1703                                      (VCFVelocityScale) ? 0x7f : 0x00; /* lower 7 bits */                                      (VCFVelocityScale & 0x7f); /* lower 7 bits */
1704          memcpy(&pData[127], &vcfvelscale, 1);          memcpy(&pData[134], &vcfvelscale, 1);
1705    
1706          // next byte unknown          // next byte unknown
1707    
1708          const uint8_t vcfresonance = (VCFResonanceDynamic) ? 0x00 : 0x80 | /* bit 7 */          const uint8_t vcfresonance = (VCFResonanceDynamic) ? 0x00 : 0x80 | /* bit 7 */
1709                                       (VCFResonance) ? 0x7f : 0x00; /* lower 7 bits */                                       (VCFResonance & 0x7f); /* lower 7 bits */
1710          memcpy(&pData[129], &vcfresonance, 1);          memcpy(&pData[136], &vcfresonance, 1);
1711    
1712          const uint8_t vcfbreakpoint = (VCFKeyboardTracking) ? 0x80 : 0x00 | /* bit 7 */          const uint8_t vcfbreakpoint = (VCFKeyboardTracking) ? 0x80 : 0x00 | /* bit 7 */
1713                                        (VCFKeyboardTrackingBreakpoint) ? 0x7f : 0x00; /* lower 7 bits */                                        (VCFKeyboardTrackingBreakpoint & 0x7f); /* lower 7 bits */
1714          memcpy(&pData[130], &vcfbreakpoint, 1);          memcpy(&pData[137], &vcfbreakpoint, 1);
1715    
1716          const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 |          const uint8_t vcfvelocity = VCFVelocityDynamicRange % 5 |
1717                                      VCFVelocityCurve * 5;                                      VCFVelocityCurve * 5;
1718          memcpy(&pData[131], &vcfvelocity, 1);          memcpy(&pData[138], &vcfvelocity, 1);
1719    
1720          const uint8_t vcftype = (VCFType == vcf_type_lowpassturbo) ? vcf_type_lowpass : VCFType;          const uint8_t vcftype = (VCFType == vcf_type_lowpassturbo) ? vcf_type_lowpass : VCFType;
1721          memcpy(&pData[132], &vcftype, 1);          memcpy(&pData[139], &vcftype, 1);
1722      }      }
1723    
1724      // 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
# Line 2043  namespace { Line 2060  namespace {
2060  // *  // *
2061    
2062      Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : DLS::Region((DLS::Instrument*) pInstrument, rgnList) {      Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : DLS::Region((DLS::Instrument*) pInstrument, rgnList) {
2063            pInfo->UseFixedLengthStrings = true;
2064    
2065          // Initialization          // Initialization
2066          Dimensions = 0;          Dimensions = 0;
2067          for (int i = 0; i < 256; i++) {          for (int i = 0; i < 256; i++) {
# Line 2110  namespace { Line 2129  namespace {
2129                  uint32_t wavepoolindex = _3lnk->ReadUint32();                  uint32_t wavepoolindex = _3lnk->ReadUint32();
2130                  if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex);                  if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex);
2131              }              }
2132                GetSample(); // load global region sample reference
2133          }          }
2134    
2135          // make sure there is at least one dimension region          // make sure there is at least one dimension region
# Line 2153  namespace { Line 2173  namespace {
2173    
2174          // update dimension definitions in '3lnk' chunk          // update dimension definitions in '3lnk' chunk
2175          uint8_t* pData = (uint8_t*) _3lnk->LoadChunkData();          uint8_t* pData = (uint8_t*) _3lnk->LoadChunkData();
2176            memcpy(&pData[0], &DimensionRegions, 4);
2177          for (int i = 0; i < iMaxDimensions; i++) {          for (int i = 0; i < iMaxDimensions; i++) {
2178              pData[i * 8]     = (uint8_t) pDimensionDefinitions[i].dimension;              pData[4 + i * 8] = (uint8_t) pDimensionDefinitions[i].dimension;
2179              pData[i * 8 + 1] = pDimensionDefinitions[i].bits;              pData[5 + i * 8] = pDimensionDefinitions[i].bits;
2180              // next 2 bytes unknown              // next 2 bytes unknown
2181              pData[i * 8 + 4] = pDimensionDefinitions[i].zones;              pData[8 + i * 8] = pDimensionDefinitions[i].zones;
2182              // next 3 bytes unknown              // next 3 bytes unknown
2183          }          }
2184    
# Line 2492  namespace { Line 2513  namespace {
2513          Sample* sample = file->GetFirstSample(pProgress);          Sample* sample = file->GetFirstSample(pProgress);
2514          while (sample) {          while (sample) {
2515              if (sample->ulWavePoolOffset == soughtoffset &&              if (sample->ulWavePoolOffset == soughtoffset &&
2516                  sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(pSample = sample);                  sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(sample);
2517              sample = file->GetNextSample();              sample = file->GetNextSample();
2518          }          }
2519          return NULL;          return NULL;
# Line 2504  namespace { Line 2525  namespace {
2525  // *  // *
2526    
2527      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) {
2528            pInfo->UseFixedLengthStrings = true;
2529    
2530          // Initialization          // Initialization
2531          for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL;          for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL;
2532    
# Line 2662  namespace { Line 2685  namespace {
2685    
2686    
2687    
2688    // *************** Group ***************
2689    // *
2690    
2691        /** @brief Constructor.
2692         *
2693         * @param file   - pointer to the RIFF::File object of this .gig file
2694         * @param ck3gnm - pointer to 3gnm chunk associated with this group
2695         */
2696        Group::Group(RIFF::File* file, RIFF::Chunk* ck3gnm) {
2697            pFile      = file;
2698            pNameChunk = ck3gnm;
2699            ::LoadString(pNameChunk, Name);
2700        }
2701    
2702        Group::~Group() {
2703        }
2704    
2705        /** @brief Update chunks with current group settings.
2706         *
2707         * Apply current Group field values to the respective. You have to call
2708         * File::Save() to make changes persistent.
2709         */
2710        void Group::UpdateChunks() {
2711            // make sure <3gri> and <3gnl> list chunks exist
2712            RIFF::List* _3gri = pFile->GetSubList(LIST_TYPE_3GRI);
2713            if (!_3gri) _3gri = pFile->AddSubList(LIST_TYPE_3GRI);
2714            RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL);
2715            if (!_3gnl) _3gnl = pFile->AddSubList(LIST_TYPE_3GNL);
2716            // now store the name of this group as <3gnm> chunk as subchunk of the <3gnl> list chunk
2717            ::SaveString(CHUNK_ID_3GNM, pNameChunk, _3gnl, Name, String("Unnamed Group"), true, 64);
2718        }
2719    
2720    
2721    
2722  // *************** File ***************  // *************** File ***************
2723  // *  // *
2724    
2725      File::File() : DLS::File() {      File::File() : DLS::File() {
2726            pGroups = NULL;
2727            pInfo->UseFixedLengthStrings = true;
2728      }      }
2729    
2730      File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) {      File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) {
2731            pGroups = NULL;
2732            pInfo->UseFixedLengthStrings = true;
2733        }
2734    
2735        File::~File() {
2736            if (pGroups) {
2737                std::list<Group*>::iterator iter = pGroups->begin();
2738                std::list<Group*>::iterator end  = pGroups->end();
2739                while (iter != end) {
2740                    delete *iter;
2741                    ++iter;
2742                }
2743                delete pGroups;
2744            }
2745      }      }
2746    
2747      Sample* File::GetFirstSample(progress_t* pProgress) {      Sample* File::GetFirstSample(progress_t* pProgress) {
# Line 2886  namespace { Line 2959  namespace {
2959          }          }
2960      }      }
2961    
2962        Group* File::GetFirstGroup() {
2963            if (!pGroups) LoadGroups();
2964            if (!pGroups) return NULL;
2965            GroupsIterator = pGroups->begin();
2966            return (GroupsIterator == pGroups->end()) ? NULL : *GroupsIterator;
2967        }
2968    
2969        Group* File::GetNextGroup() {
2970            if (!pGroups) return NULL;
2971            ++GroupsIterator;
2972            return (GroupsIterator == pGroups->end()) ? NULL : *GroupsIterator;
2973        }
2974    
2975        /**
2976         * Returns the group with the given index.
2977         *
2978         * @param index - number of the sought group (0..n)
2979         * @returns sought group or NULL if there's no such group
2980         */
2981        Group* File::GetGroup(uint index) {
2982            if (!pGroups) LoadGroups();
2983            if (!pGroups) return NULL;
2984            GroupsIterator = pGroups->begin();
2985            for (uint i = 0; GroupsIterator != pGroups->end(); i++) {
2986                if (i == index) return *GroupsIterator;
2987                ++GroupsIterator;
2988            }
2989            return NULL;
2990        }
2991    
2992        Group* File::AddGroup() {
2993            if (!pGroups) LoadGroups();
2994            if (!pGroups) pGroups = new std::list<Group*>;
2995            __ensureMandatoryChunksExist();
2996            Group* pGroup = new Group(pRIFF, NULL);
2997            pGroups->push_back(pGroup);
2998            return pGroup;
2999        }
3000    
3001        void File::DeleteGroup(Group* pGroup) {
3002            if (!pGroups) throw gig::Exception("Could not delete group as there are no groups");
3003            std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup);
3004            if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group");
3005            pGroups->erase(iter);
3006            delete pGroup;
3007        }
3008    
3009        void File::LoadGroups() {
3010            if (!pGroups) pGroups = new std::list<Group*>;
3011            RIFF::List* lst3gri = pRIFF->GetSubList(LIST_TYPE_3GRI);
3012            if (!lst3gri) return;
3013            RIFF::List* lst3gnl = lst3gri->GetSubList(LIST_TYPE_3GNL);
3014            if (!lst3gnl) return;
3015            {
3016                RIFF::Chunk* ck = lst3gnl->GetFirstSubChunk();
3017                while (ck) {
3018                    if (ck->GetChunkID() == CHUNK_ID_3GNM) {
3019                        pGroups->push_back(new Group(pRIFF, ck));
3020                    }
3021                    ck = lst3gnl->GetNextSubChunk();
3022                }
3023            }
3024        }
3025    
3026    
3027    
3028  // *************** Exception ***************  // *************** Exception ***************

Legend:
Removed from v.902  
changed lines
  Added in v.929

  ViewVC Help
Powered by ViewVC