/[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 1384 by schoenebeck, Fri Oct 5 11:26:53 2007 UTC revision 1627 by persson, Sun Jan 6 10:53:53 2008 UTC
# Line 366  namespace { Line 366  namespace {
366       *                         is located, 0 otherwise       *                         is located, 0 otherwise
367       */       */
368      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) {
369          static const DLS::Info::FixedStringLength fixedStringLengths[] = {          static const DLS::Info::string_length_t fixedStringLengths[] = {
370              { CHUNK_ID_INAM, 64 },              { CHUNK_ID_INAM, 64 },
371              { 0, 0 }              { 0, 0 }
372          };          };
373          pInfo->FixedStringLengths = fixedStringLengths;          pInfo->SetFixedStringLengths(fixedStringLengths);
374          Instances++;          Instances++;
375          FileNo = fileNo;          FileNo = fileNo;
376    
# Line 2372  namespace { Line 2372  namespace {
2372    
2373          // Actual Loading          // Actual Loading
2374    
2375            if (!file->GetAutoLoad()) return;
2376    
2377          LoadDimensionRegions(rgnList);          LoadDimensionRegions(rgnList);
2378    
2379          RIFF::Chunk* _3lnk = rgnList->GetSubChunk(CHUNK_ID_3LNK);          RIFF::Chunk* _3lnk = rgnList->GetSubChunk(CHUNK_ID_3LNK);
# Line 2415  namespace { Line 2417  namespace {
2417              else              else
2418                  _3lnk->SetPos(44);                  _3lnk->SetPos(44);
2419    
2420              // load sample references              // load sample references (if auto loading is enabled)
2421              for (uint i = 0; i < DimensionRegions; i++) {              if (file->GetAutoLoad()) {
2422                  uint32_t wavepoolindex = _3lnk->ReadUint32();                  for (uint i = 0; i < DimensionRegions; i++) {
2423                  if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex);                      uint32_t wavepoolindex = _3lnk->ReadUint32();
2424                        if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex);
2425                    }
2426                    GetSample(); // load global region sample reference
2427              }              }
             GetSample(); // load global region sample reference  
2428          } else {          } else {
2429              DimensionRegions = 0;              DimensionRegions = 0;
2430              for (int i = 0 ; i < 8 ; i++) {              for (int i = 0 ; i < 8 ; i++) {
# Line 2919  namespace { Line 2923  namespace {
2923      }      }
2924    
2925    
2926    // *************** MidiRule ***************
2927    // *
2928    
2929    MidiRuleCtrlTrigger::MidiRuleCtrlTrigger(RIFF::Chunk* _3ewg) {
2930        _3ewg->SetPos(36);
2931        Triggers = _3ewg->ReadUint8();
2932        _3ewg->SetPos(40);
2933        ControllerNumber = _3ewg->ReadUint8();
2934        _3ewg->SetPos(46);
2935        for (int i = 0 ; i < Triggers ; i++) {
2936            pTriggers[i].TriggerPoint = _3ewg->ReadUint8();
2937            pTriggers[i].Descending = _3ewg->ReadUint8();
2938            pTriggers[i].VelSensitivity = _3ewg->ReadUint8();
2939            pTriggers[i].Key = _3ewg->ReadUint8();
2940            pTriggers[i].NoteOff = _3ewg->ReadUint8();
2941            pTriggers[i].Velocity = _3ewg->ReadUint8();
2942            pTriggers[i].OverridePedal = _3ewg->ReadUint8();
2943            _3ewg->ReadUint8();
2944        }
2945    }
2946    
2947    
2948  // *************** Instrument ***************  // *************** Instrument ***************
2949  // *  // *
2950    
2951      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) {
2952          static const DLS::Info::FixedStringLength fixedStringLengths[] = {          static const DLS::Info::string_length_t fixedStringLengths[] = {
2953              { CHUNK_ID_INAM, 64 },              { CHUNK_ID_INAM, 64 },
2954              { CHUNK_ID_ISFT, 12 },              { CHUNK_ID_ISFT, 12 },
2955              { 0, 0 }              { 0, 0 }
2956          };          };
2957          pInfo->FixedStringLengths = fixedStringLengths;          pInfo->SetFixedStringLengths(fixedStringLengths);
2958    
2959          // Initialization          // Initialization
2960          for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL;          for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL;
# Line 2954  namespace { Line 2979  namespace {
2979                  PianoReleaseMode       = dimkeystart & 0x01;                  PianoReleaseMode       = dimkeystart & 0x01;
2980                  DimensionKeyRange.low  = dimkeystart >> 1;                  DimensionKeyRange.low  = dimkeystart >> 1;
2981                  DimensionKeyRange.high = _3ewg->ReadUint8();                  DimensionKeyRange.high = _3ewg->ReadUint8();
2982    
2983                    if (_3ewg->GetSize() > 32) {
2984                        // read MIDI rules
2985                        _3ewg->SetPos(32);
2986                        uint8_t id1 = _3ewg->ReadUint8();
2987                        uint8_t id2 = _3ewg->ReadUint8();
2988    
2989                        if (id1 == 4 && id2 == 16) {
2990                            MidiRules.push_back(new MidiRuleCtrlTrigger(_3ewg));
2991                        }
2992                        //TODO: all the other types of rules
2993                    }
2994              }              }
2995          }          }
2996    
2997          if (!pRegions) pRegions = new RegionList;          if (pFile->GetAutoLoad()) {
2998          RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN);              if (!pRegions) pRegions = new RegionList;
2999          if (lrgn) {              RIFF::List* lrgn = insList->GetSubList(LIST_TYPE_LRGN);
3000              RIFF::List* rgn = lrgn->GetFirstSubList();              if (lrgn) {
3001              while (rgn) {                  RIFF::List* rgn = lrgn->GetFirstSubList();
3002                  if (rgn->GetListType() == LIST_TYPE_RGN) {                  while (rgn) {
3003                      __notify_progress(pProgress, (float) pRegions->size() / (float) Regions);                      if (rgn->GetListType() == LIST_TYPE_RGN) {
3004                      pRegions->push_back(new Region(this, rgn));                          __notify_progress(pProgress, (float) pRegions->size() / (float) Regions);
3005                            pRegions->push_back(new Region(this, rgn));
3006                        }
3007                        rgn = lrgn->GetNextSubList();
3008                  }                  }
3009                  rgn = lrgn->GetNextSubList();                  // Creating Region Key Table for fast lookup
3010                    UpdateRegionKeyTable();
3011              }              }
             // Creating Region Key Table for fast lookup  
             UpdateRegionKeyTable();  
3012          }          }
3013    
3014          __notify_progress(pProgress, 1.0f); // notify done          __notify_progress(pProgress, 1.0f); // notify done
# Line 3102  namespace { Line 3141  namespace {
3141          UpdateRegionKeyTable();          UpdateRegionKeyTable();
3142      }      }
3143    
3144        /**
3145         * Returns the first MIDI rule of the instrument. You have to call
3146         * this method once before you use GetNextMidiRule().
3147         *
3148         * The list of MIDI rules, at least in gig v3, always contains at
3149         * most two rules. The second rule can only be the DEF filter
3150         * (which currently isn't supported by libgig).
3151         *
3152         * @returns  pointer address to first MIDI rule or NULL if there is none
3153         * @see      GetNextMidiRule()
3154         */
3155        MidiRule* Instrument::GetFirstMidiRule() {
3156            MidiRulesIterator = MidiRules.begin();
3157            return MidiRulesIterator != MidiRules.end() ? *MidiRulesIterator : NULL;
3158        }
3159    
3160        /**
3161         * Returns the next MIDI rule of the instrument. You have to call
3162         * GetFirstMidiRule() once before you can use this method. By
3163         * calling this method multiple times it iterates through the
3164         * available rules.
3165         *
3166         * @returns  pointer address to the next MIDI rule or NULL if end reached
3167         * @see      GetFirstMidiRule()
3168         */
3169        MidiRule* Instrument::GetNextMidiRule() {
3170            MidiRulesIterator++;
3171            return MidiRulesIterator != MidiRules.end() ? *MidiRulesIterator : NULL;
3172        }
3173    
3174    
3175  // *************** Group ***************  // *************** Group ***************
# Line 3237  namespace { Line 3305  namespace {
3305          0, 3, 20030331 & 0xffff, 20030331 >> 16          0, 3, 20030331 & 0xffff, 20030331 >> 16
3306      };      };
3307    
3308      const DLS::Info::FixedStringLength File::FixedStringLengths[] = {      static const DLS::Info::string_length_t _FileFixedStringLengths[] = {
3309          { CHUNK_ID_IARL, 256 },          { CHUNK_ID_IARL, 256 },
3310          { CHUNK_ID_IART, 128 },          { CHUNK_ID_IART, 128 },
3311          { CHUNK_ID_ICMS, 128 },          { CHUNK_ID_ICMS, 128 },
# Line 3259  namespace { Line 3327  namespace {
3327      };      };
3328    
3329      File::File() : DLS::File() {      File::File() : DLS::File() {
3330            bAutoLoad = true;
3331          *pVersion = VERSION_3;          *pVersion = VERSION_3;
3332          pGroups = NULL;          pGroups = NULL;
3333          pInfo->FixedStringLengths = FixedStringLengths;          pInfo->SetFixedStringLengths(_FileFixedStringLengths);
3334          pInfo->ArchivalLocation = String(256, ' ');          pInfo->ArchivalLocation = String(256, ' ');
3335    
3336          // add some mandatory chunks to get the file chunks in right          // add some mandatory chunks to get the file chunks in right
# Line 3274  namespace { Line 3343  namespace {
3343      }      }
3344    
3345      File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) {      File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) {
3346            bAutoLoad = true;
3347          pGroups = NULL;          pGroups = NULL;
3348          pInfo->FixedStringLengths = FixedStringLengths;          pInfo->SetFixedStringLengths(_FileFixedStringLengths);
3349      }      }
3350    
3351      File::~File() {      File::~File() {
# Line 3447  namespace { Line 3517  namespace {
3517              progress_t subprogress;              progress_t subprogress;
3518              __divide_progress(pProgress, &subprogress, 3.0f, 0.0f); // randomly schedule 33% for this subtask              __divide_progress(pProgress, &subprogress, 3.0f, 0.0f); // randomly schedule 33% for this subtask
3519              __notify_progress(&subprogress, 0.0f);              __notify_progress(&subprogress, 0.0f);
3520              GetFirstSample(&subprogress); // now force all samples to be loaded              if (GetAutoLoad())
3521                    GetFirstSample(&subprogress); // now force all samples to be loaded
3522              __notify_progress(&subprogress, 1.0f);              __notify_progress(&subprogress, 1.0f);
3523    
3524              // instrument loading subtask              // instrument loading subtask
# Line 3854  namespace { Line 3925  namespace {
3925          }          }
3926      }      }
3927    
3928        /**
3929         * Enable / disable automatic loading. By default this properyt is
3930         * enabled and all informations are loaded automatically. However
3931         * loading all Regions, DimensionRegions and especially samples might
3932         * take a long time for large .gig files, and sometimes one might only
3933         * be interested in retrieving very superficial informations like the
3934         * amount of instruments and their names. In this case one might disable
3935         * automatic loading to avoid very slow response times.
3936         *
3937         * @e CAUTION: by disabling this property many pointers (i.e. sample
3938         * references) and informations will have invalid or even undefined
3939         * data! This feature is currently only intended for retrieving very
3940         * superficial informations in a very fast way. Don't use it to retrieve
3941         * details like synthesis informations or even to modify .gig files!
3942         */
3943        void File::SetAutoLoad(bool b) {
3944            bAutoLoad = b;
3945        }
3946    
3947        /**
3948         * Returns whether automatic loading is enabled.
3949         * @see SetAutoLoad()
3950         */
3951        bool File::GetAutoLoad() {
3952            return bAutoLoad;
3953        }
3954    
3955    
3956    
3957  // *************** Exception ***************  // *************** Exception ***************

Legend:
Removed from v.1384  
changed lines
  Added in v.1627

  ViewVC Help
Powered by ViewVC