/[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 1076 by persson, Tue Mar 6 18:33:30 2007 UTC revision 1158 by schoenebeck, Fri Apr 13 16:41:18 2007 UTC
# Line 254  namespace { Line 254  namespace {
254  }  }
255    
256    
257    
258    // *************** Other Internal functions  ***************
259    // *
260    
261        static split_type_t __resolveSplitType(dimension_t dimension) {
262            return (
263                dimension == dimension_layer ||
264                dimension == dimension_samplechannel ||
265                dimension == dimension_releasetrigger ||
266                dimension == dimension_keyboard ||
267                dimension == dimension_roundrobin ||
268                dimension == dimension_random ||
269                dimension == dimension_smartmidi ||
270                dimension == dimension_roundrobinkeyboard
271            ) ? split_type_bit : split_type_normal;
272        }
273    
274        static int __resolveZoneSize(dimension_def_t& dimension_definition) {
275            return (dimension_definition.split_type == split_type_normal)
276            ? int(128.0 / dimension_definition.zones) : 0;
277        }
278    
279    
280    
281  // *************** Sample ***************  // *************** Sample ***************
282  // *  // *
283    
# Line 2115  namespace { Line 2139  namespace {
2139                      pDimensionDefinitions[i].dimension = dimension;                      pDimensionDefinitions[i].dimension = dimension;
2140                      pDimensionDefinitions[i].bits      = bits;                      pDimensionDefinitions[i].bits      = bits;
2141                      pDimensionDefinitions[i].zones     = zones ? zones : 0x01 << bits; // = pow(2,bits)                      pDimensionDefinitions[i].zones     = zones ? zones : 0x01 << bits; // = pow(2,bits)
2142                      pDimensionDefinitions[i].split_type = (dimension == dimension_layer ||                      pDimensionDefinitions[i].split_type = __resolveSplitType(dimension);
2143                                                             dimension == dimension_samplechannel ||                      pDimensionDefinitions[i].zone_size  = __resolveZoneSize(pDimensionDefinitions[i]);
                                                            dimension == dimension_releasetrigger ||  
                                                            dimension == dimension_keyboard ||  
                                                            dimension == dimension_roundrobin ||  
                                                            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;  
2144                      Dimensions++;                      Dimensions++;
2145    
2146                      // if this is a layer dimension, remember the amount of layers                      // if this is a layer dimension, remember the amount of layers
# Line 2152  namespace { Line 2166  namespace {
2166                  if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex);                  if (file->pWavePoolTable) pDimensionRegions[i]->pSample = GetSampleFromWavePool(wavepoolindex);
2167              }              }
2168              GetSample(); // load global region sample reference              GetSample(); // load global region sample reference
2169            } else {
2170                DimensionRegions = 0;
2171          }          }
2172    
2173          // make sure there is at least one dimension region          // make sure there is at least one dimension region
# Line 2174  namespace { Line 2190  namespace {
2190       * @throws gig::Exception if samples cannot be dereferenced       * @throws gig::Exception if samples cannot be dereferenced
2191       */       */
2192      void Region::UpdateChunks() {      void Region::UpdateChunks() {
2193            // in the gig format we don't care about the Region's sample reference
2194            // but we still have to provide some existing one to not corrupt the
2195            // file, so to avoid the latter we simply always assign the sample of
2196            // the first dimension region of this region
2197            pSample = pDimensionRegions[0]->pSample;
2198    
2199          // first update base class's chunks          // first update base class's chunks
2200          DLS::Region::UpdateChunks();          DLS::Region::UpdateChunks();
2201    
# Line 2348  namespace { Line 2370  namespace {
2370          // assign definition of new dimension          // assign definition of new dimension
2371          pDimensionDefinitions[Dimensions] = *pDimDef;          pDimensionDefinitions[Dimensions] = *pDimDef;
2372    
2373            // auto correct certain dimension definition fields (where possible)
2374            pDimensionDefinitions[Dimensions].split_type  =
2375                __resolveSplitType(pDimensionDefinitions[Dimensions].dimension);
2376            pDimensionDefinitions[Dimensions].zone_size =
2377                __resolveZoneSize(pDimensionDefinitions[Dimensions]);
2378    
2379          // create new dimension region(s) for this new dimension          // create new dimension region(s) for this new dimension
2380          for (int i = 1 << iCurrentBits; i < 1 << iNewBits; i++) {          for (int i = 1 << iCurrentBits; i < 1 << iNewBits; i++) {
2381              //TODO: maybe we should copy existing dimension regions if possible instead of simply creating new ones with default values              //TODO: maybe we should copy existing dimension regions if possible instead of simply creating new ones with default values
# Line 2740  namespace { Line 2768  namespace {
2768      }      }
2769    
2770      Group::~Group() {      Group::~Group() {
2771            // remove the chunk associated with this group (if any)
2772            if (pNameChunk) pNameChunk->GetParent()->DeleteSubChunk(pNameChunk);
2773      }      }
2774    
2775      /** @brief Update chunks with current group settings.      /** @brief Update chunks with current group settings.
2776       *       *
2777       * Apply current Group field values to the respective. You have to call       * Apply current Group field values to the respective chunks. You have
2778       * File::Save() to make changes persistent.       * to call File::Save() to make changes persistent.
2779         *
2780         * Usually there is absolutely no need to call this method explicitly.
2781         * It will be called automatically when File::Save() was called.
2782       */       */
2783      void Group::UpdateChunks() {      void Group::UpdateChunks() {
2784          // make sure <3gri> and <3gnl> list chunks exist          // make sure <3gri> and <3gnl> list chunks exist
# Line 2893  namespace { Line 2926  namespace {
2926          if (!pSamples || !pSamples->size()) throw gig::Exception("Could not delete sample as there are no samples");          if (!pSamples || !pSamples->size()) throw gig::Exception("Could not delete sample as there are no samples");
2927          SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), (DLS::Sample*) pSample);          SampleList::iterator iter = find(pSamples->begin(), pSamples->end(), (DLS::Sample*) pSample);
2928          if (iter == pSamples->end()) throw gig::Exception("Could not delete sample, could not find given sample");          if (iter == pSamples->end()) throw gig::Exception("Could not delete sample, could not find given sample");
2929            if (SamplesIterator != pSamples->end() && *SamplesIterator == pSample) ++SamplesIterator; // avoid iterator invalidation
2930          pSamples->erase(iter);          pSamples->erase(iter);
2931          delete pSample;          delete pSample;
2932      }      }
# Line 2904  namespace { Line 2938  namespace {
2938      void File::LoadSamples(progress_t* pProgress) {      void File::LoadSamples(progress_t* pProgress) {
2939          // Groups must be loaded before samples, because samples will try          // Groups must be loaded before samples, because samples will try
2940          // to resolve the group they belong to          // to resolve the group they belong to
2941          LoadGroups();          if (!pGroups) LoadGroups();
2942    
2943          if (!pSamples) pSamples = new SampleList;          if (!pSamples) pSamples = new SampleList;
2944    
# Line 3029  namespace { Line 3063  namespace {
3063       * have to call Save() to make this persistent to the file.       * have to call Save() to make this persistent to the file.
3064       *       *
3065       * @param pInstrument - instrument to delete       * @param pInstrument - instrument to delete
3066       * @throws gig::Excption if given instrument could not be found       * @throws gig::Exception if given instrument could not be found
3067       */       */
3068      void File::DeleteInstrument(Instrument* pInstrument) {      void File::DeleteInstrument(Instrument* pInstrument) {
3069          if (!pInstruments) throw gig::Exception("Could not delete instrument as there are no instruments");          if (!pInstruments) throw gig::Exception("Could not delete instrument as there are no instruments");
# Line 3107  namespace { Line 3141  namespace {
3141          return pGroup;          return pGroup;
3142      }      }
3143    
3144        /** @brief Delete a group and its samples.
3145         *
3146         * This will delete the given Group object and all the samples that
3147         * belong to this group from the gig file. You have to call Save() to
3148         * make this persistent to the file.
3149         *
3150         * @param pGroup - group to delete
3151         * @throws gig::Exception if given group could not be found
3152         */
3153      void File::DeleteGroup(Group* pGroup) {      void File::DeleteGroup(Group* pGroup) {
3154          if (!pGroups) LoadGroups();          if (!pGroups) LoadGroups();
3155          std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup);          std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup);
3156          if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group");          if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group");
3157          if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!");          if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!");
3158            // delete all members of this group
3159            for (Sample* pSample = pGroup->GetFirstSample(); pSample; pSample = pGroup->GetNextSample()) {
3160                DeleteSample(pSample);
3161            }
3162            // now delete this group object
3163            pGroups->erase(iter);
3164            delete pGroup;
3165        }
3166    
3167        /** @brief Delete a group.
3168         *
3169         * This will delete the given Group object from the gig file. All the
3170         * samples that belong to this group will not be deleted, but instead
3171         * be moved to another group. You have to call Save() to make this
3172         * persistent to the file.
3173         *
3174         * @param pGroup - group to delete
3175         * @throws gig::Exception if given group could not be found
3176         */
3177        void File::DeleteGroupOnly(Group* pGroup) {
3178            if (!pGroups) LoadGroups();
3179            std::list<Group*>::iterator iter = find(pGroups->begin(), pGroups->end(), pGroup);
3180            if (iter == pGroups->end()) throw gig::Exception("Could not delete group, could not find given group");
3181            if (pGroups->size() == 1) throw gig::Exception("Cannot delete group, there must be at least one default group!");
3182          // move all members of this group to another group          // move all members of this group to another group
3183          pGroup->MoveAll();          pGroup->MoveAll();
3184          pGroups->erase(iter);          pGroups->erase(iter);
# Line 3142  namespace { Line 3209  namespace {
3209          }          }
3210      }      }
3211    
3212        /**
3213         * Apply all the gig file's current instruments, samples, groups and settings
3214         * to the respective RIFF chunks. You have to call Save() to make changes
3215         * persistent.
3216         *
3217         * Usually there is absolutely no need to call this method explicitly.
3218         * It will be called automatically when File::Save() was called.
3219         *
3220         * @throws Exception - on errors
3221         */
3222        void File::UpdateChunks() {
3223            // first update base class's chunks
3224            DLS::File::UpdateChunks();
3225    
3226            // update group's chunks
3227            if (pGroups) {
3228                std::list<Group*>::iterator iter = pGroups->begin();
3229                std::list<Group*>::iterator end  = pGroups->end();
3230                for (; iter != end; ++iter) {
3231                    (*iter)->UpdateChunks();
3232                }
3233            }
3234        }
3235    
3236    
3237    
3238  // *************** Exception ***************  // *************** Exception ***************

Legend:
Removed from v.1076  
changed lines
  Added in v.1158

  ViewVC Help
Powered by ViewVC