/[svn]/gigedit/trunk/src/gigedit/CombineInstrumentsDialog.cpp
ViewVC logotype

Diff of /gigedit/trunk/src/gigedit/CombineInstrumentsDialog.cpp

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

revision 2553 by schoenebeck, Wed May 14 19:57:56 2014 UTC revision 2558 by schoenebeck, Sat May 17 23:55:30 2014 UTC
# Line 11  Line 11 
11  #define DEBUG_COMBINE_INSTRUMENTS 0  #define DEBUG_COMBINE_INSTRUMENTS 0
12    
13  #include "global.h"  #include "global.h"
14    #include "compat.h"
15    
16  #include <set>  #include <set>
17  #include <iostream>  #include <iostream>
# Line 21  Line 22 
22  #include <glibmm/ustring.h>  #include <glibmm/ustring.h>
23  #include <gtkmm/stock.h>  #include <gtkmm/stock.h>
24  #include <gtkmm/messagedialog.h>  #include <gtkmm/messagedialog.h>
25    #include <gtkmm/label.h>
26    
27  Glib::ustring gig_to_utf8(const gig::String& gig_string);  Glib::ustring gig_to_utf8(const gig::String& gig_string);
28    Glib::ustring dimTypeAsString(gig::dimension_t d);
29    
30    typedef std::vector< std::pair<gig::Instrument*, gig::Region*> > OrderedRegionGroup;
31  typedef std::map<gig::Instrument*, gig::Region*> RegionGroup;  typedef std::map<gig::Instrument*, gig::Region*> RegionGroup;
32  typedef std::map<DLS::range_t,RegionGroup> RegionGroups;  typedef std::map<DLS::range_t,RegionGroup> RegionGroups;
33    
# Line 168  static RegionGroup getAllRegionsWhichOve Line 172  static RegionGroup getAllRegionsWhichOve
172  /** @brief Identify required regions.  /** @brief Identify required regions.
173   *   *
174   * Takes a list of @a instruments as argument (which are planned to be combined   * Takes a list of @a instruments as argument (which are planned to be combined
175   * as layers in one single new instrument) and fulfills the following tasks:   * as separate dimension zones of a certain dimension into one single new
176     * instrument) and fulfills the following tasks:
177   *   *
178   * - 1. Identification of total amount of regions required to create a new   * - 1. Identification of total amount of regions required to create a new
179   *      instrument to become a layered version of the given instruments.   *      instrument to become a combined version of the given instruments.
180   * - 2. Precise key range of each of those identified required regions to be   * - 2. Precise key range of each of those identified required regions to be
181   *      created in that new instrument.   *      created in that new instrument.
182   * - 3. Grouping the original source regions of the given original instruments   * - 3. Grouping the original source regions of the given original instruments
# Line 293  static void fillDimValues(uint* values/* Line 298  static void fillDimValues(uint* values/*
298          #endif          #endif
299      }      }
300      #if DEBUG_COMBINE_INSTRUMENTS      #if DEBUG_COMBINE_INSTRUMENTS
301      printf("\n");      printf("}\n");
302      #endif      #endif
303  }  }
304    
# Line 400  struct CopyAssignSchedEntry { Line 405  struct CopyAssignSchedEntry {
405  };  };
406  typedef std::vector<CopyAssignSchedEntry> CopyAssignSchedule;  typedef std::vector<CopyAssignSchedEntry> CopyAssignSchedule;
407    
408  /** @brief Copy all DimensionRegions from source Region to target Region.  /** @brief Schedule copying DimensionRegions from source Region to target Region.
409   *   *
410   * Copies the entire articulation informations (including sample reference of   * Schedules copying the entire articulation informations (including sample
411   * course) from all individual DimensionRegions of source Region @a inRgn to   * reference) from all individual DimensionRegions of source Region @a inRgn to
412   * target Region @a outRgn. There are no dimension regions created during this   * target Region @a outRgn. It is expected that the required dimensions (thus
413   * task. It is expected that the required dimensions (thus the required   * the required dimension regions) were already created before calling this
414   * dimension regions) were already created before calling this function.   * function.
415   *   *
416   * To be precise, it does the task above only for the layer selected by   * To be precise, it does the task above only for the dimension zones defined by
417   * @a iSrcLayer and @a iDstLayer. All dimensions regions of other layers that   * the three arguments @a mainDim, @a iSrcMainBit, @a iDstMainBit, which reflect
418   * may exist, will not be copied by one single call of this function. So if   * a selection which dimension zones shall be copied. All other dimension zones
419   * there is a layer dimension, this function needs to be called several times.   * will not be scheduled to be copied by a single call of this function. So this
420     * function needs to be called several time in case all dimension regions shall
421     * be copied of the entire region (@a inRgn, @a outRgn).
422   *   *
423   * @param outRgn - where the dimension regions shall be copied to   * @param outRgn - where the dimension regions shall be copied to
424   * @param inRgn - all dimension regions that shall be copied from   * @param inRgn - all dimension regions that shall be copied from
425   * @param dims - precise dimension definitions of target region   * @param dims - precise dimension definitions of target region
426   * @param iDstLayer - layer index of destination region where the dimension   * @param mainDim - this dimension type, in combination with @a iSrcMainBit and
427   *                    regions shall be copied to   *                  @a iDstMainBit defines a selection which dimension region
428   * @param iSrcLayer - layer index of the source region where the dimension   *                  zones shall be copied by this call of this function
429   *                    regions shall be copied from   * @param iDstMainBit - destination bit of @a mainDim
430     * @param iSrcMainBit - source bit of @a mainDim
431     * @param schedule - list of all DimensionRegion copy operations which is filled
432     *                   during the nested loops / recursions of this function call
433   * @param dimCase - just for internal purpose (function recursion), don't pass   * @param dimCase - just for internal purpose (function recursion), don't pass
434   *                  anything here, this function will call itself recursively   *                  anything here, this function will call itself recursively
435   *                  will fill this container with concrete dimension values for   *                  will fill this container with concrete dimension values for
436   *                  selecting the precise dimension regions during its task   *                  selecting the precise dimension regions during its task
  * @param schedule - just for internal purpose (function recursion), don't pass  
                      anything here: list of all DimensionRegion copy operations  
  *                   which is filled during the nested loops / recursions of  
  *                   this function call, they will be peformed after all  
  *                   function recursions have been completed  
437   */   */
438  static void copyDimensionRegions(gig::Region* outRgn, gig::Region* inRgn, Dimensions dims, int iDstLayer, int iSrcLayer, DimensionCase dimCase = DimensionCase(), CopyAssignSchedule* schedule = NULL) {  static void scheduleCopyDimensionRegions(gig::Region* outRgn, gig::Region* inRgn,
439      const bool isHighestLevelOfRecursion = !schedule;                                   Dimensions dims, gig::dimension_t mainDim,
440                                     int iDstMainBit, int iSrcMainBit,
441      if (isHighestLevelOfRecursion)                                   CopyAssignSchedule* schedule,
442          schedule = new CopyAssignSchedule;                                   DimensionCase dimCase = DimensionCase())
443    {
444      if (dims.empty()) { // reached deepest level of function recursion ...      if (dims.empty()) { // reached deepest level of function recursion ...
445          CopyAssignSchedEntry e;          CopyAssignSchedEntry e;
446    
# Line 444  static void copyDimensionRegions(gig::Re Line 449  static void copyDimensionRegions(gig::Re
449          uint dstDimValues[8] = {};          uint dstDimValues[8] = {};
450          DimensionCase srcDimCase = dimCase;          DimensionCase srcDimCase = dimCase;
451          DimensionCase dstDimCase = dimCase;          DimensionCase dstDimCase = dimCase;
452          srcDimCase[gig::dimension_layer] = iSrcLayer;          srcDimCase[mainDim] = iSrcMainBit;
453          dstDimCase[gig::dimension_layer] = iDstLayer;          dstDimCase[mainDim] = iDstMainBit;
454    
455          #if DEBUG_COMBINE_INSTRUMENTS          #if DEBUG_COMBINE_INSTRUMENTS
456          printf("-------------------------------\n");          printf("-------------------------------\n");
457            printf("iDstMainBit=%d iSrcMainBit=%d\n", iDstMainBit, iSrcMainBit);
458          #endif          #endif
459    
460          // first select source & target dimension region with an arbitrary          // first select source & target dimension region with an arbitrary
# Line 467  static void copyDimensionRegions(gig::Re Line 473  static void copyDimensionRegions(gig::Re
473          gig::DimensionRegion* srcDimRgn = inRgn->GetDimensionRegionByValue(srcDimValues);          gig::DimensionRegion* srcDimRgn = inRgn->GetDimensionRegionByValue(srcDimValues);
474          gig::DimensionRegion* dstDimRgn = outRgn->GetDimensionRegionByValue(dstDimValues);          gig::DimensionRegion* dstDimRgn = outRgn->GetDimensionRegionByValue(dstDimValues);
475          #if DEBUG_COMBINE_INSTRUMENTS          #if DEBUG_COMBINE_INSTRUMENTS
476          printf("iDstLayer=%d iSrcLayer=%d\n", iDstLayer, iSrcLayer);          printf("iDstMainBit=%d iSrcMainBit=%d\n", iDstMainBit, iSrcMainBit);
477          printf("srcDimRgn=%lx dstDimRgn=%lx\n", (uint64_t)srcDimRgn, (uint64_t)dstDimRgn);          printf("srcDimRgn=%lx dstDimRgn=%lx\n", (uint64_t)srcDimRgn, (uint64_t)dstDimRgn);
478          printf("srcSample='%s' dstSample='%s'\n",          printf("srcSample='%s' dstSample='%s'\n",
479                 (!srcDimRgn->pSample ? "NULL" : srcDimRgn->pSample->pInfo->Name.c_str()),                 (!srcDimRgn->pSample ? "NULL" : srcDimRgn->pSample->pInfo->Name.c_str()),
# Line 486  static void copyDimensionRegions(gig::Re Line 492  static void copyDimensionRegions(gig::Re
492              // re-select target dimension region (with correct velocity zone)              // re-select target dimension region (with correct velocity zone)
493              DimensionZones dstZones = preciseDimensionZonesFor(gig::dimension_velocity, dstDimRgn);              DimensionZones dstZones = preciseDimensionZonesFor(gig::dimension_velocity, dstDimRgn);
494              assert(dstZones.size() > 1);              assert(dstZones.size() > 1);
495              int iZoneIndex = dstDimCase[gig::dimension_velocity];              const int iDstZoneIndex =
496              e.velocityZone = iZoneIndex;                  (mainDim == gig::dimension_velocity)
497                        ? iDstMainBit : dstDimCase[gig::dimension_velocity]; // (mainDim == gig::dimension_velocity) exception case probably unnecessary here
498                e.velocityZone = iDstZoneIndex;
499              #if DEBUG_COMBINE_INSTRUMENTS              #if DEBUG_COMBINE_INSTRUMENTS
500              printf("dst velocity zone: %d/%d\n", iZoneIndex, (int)dstZones.size());              printf("dst velocity zone: %d/%d\n", iDstZoneIndex, (int)dstZones.size());
501              #endif              #endif
502              assert(uint(iZoneIndex) < dstZones.size());              assert(uint(iDstZoneIndex) < dstZones.size());
503              dstDimCase[gig::dimension_velocity] = dstZones[iZoneIndex].low; // arbitrary value between low and high              dstDimCase[gig::dimension_velocity] = dstZones[iDstZoneIndex].low; // arbitrary value between low and high
504              #if DEBUG_COMBINE_INSTRUMENTS              #if DEBUG_COMBINE_INSTRUMENTS
505              printf("dst velocity value = %d\n", dstDimCase[gig::dimension_velocity]);              printf("dst velocity value = %d\n", dstDimCase[gig::dimension_velocity]);
506              printf("dst refilled "); fflush(stdout);              printf("dst refilled "); fflush(stdout);
# Line 501  static void copyDimensionRegions(gig::Re Line 509  static void copyDimensionRegions(gig::Re
509              dstDimRgn = outRgn->GetDimensionRegionByValue(dstDimValues);              dstDimRgn = outRgn->GetDimensionRegionByValue(dstDimValues);
510              #if DEBUG_COMBINE_INSTRUMENTS              #if DEBUG_COMBINE_INSTRUMENTS
511              printf("reselected dstDimRgn=%lx\n", (uint64_t)dstDimRgn);              printf("reselected dstDimRgn=%lx\n", (uint64_t)dstDimRgn);
512              printf("dstSample='%s'\n",              printf("dstSample='%s'%s\n",
513                  (!dstDimRgn->pSample ? "NULL" : dstDimRgn->pSample->pInfo->Name.c_str())                  (!dstDimRgn->pSample ? "NULL" : dstDimRgn->pSample->pInfo->Name.c_str()),
514                    (dstDimRgn->pSample ? " <--- ERROR ERROR ERROR !!!!!!!!! " : "")
515              );              );
516              #endif              #endif
517    
# Line 515  static void copyDimensionRegions(gig::Re Line 524  static void copyDimensionRegions(gig::Re
524                  if (srcZones.size() <= 1) {                  if (srcZones.size() <= 1) {
525                      addWarning("Input region has a velocity dimension with only ONE zone!");                      addWarning("Input region has a velocity dimension with only ONE zone!");
526                  }                  }
527                  if (uint(iZoneIndex) >= srcZones.size())                  int iSrcZoneIndex =
528                      iZoneIndex  = srcZones.size() - 1;                      (mainDim == gig::dimension_velocity)
529                  srcDimCase[gig::dimension_velocity] = srcZones[iZoneIndex].low; // same zone as used above for target dimension region (no matter what the precise zone ranges are)                          ? iSrcMainBit : iDstZoneIndex;
530                    if (uint(iSrcZoneIndex) >= srcZones.size())
531                        iSrcZoneIndex = srcZones.size() - 1;
532                    srcDimCase[gig::dimension_velocity] = srcZones[iSrcZoneIndex].low; // same zone as used above for target dimension region (no matter what the precise zone ranges are)
533                  #if DEBUG_COMBINE_INSTRUMENTS                  #if DEBUG_COMBINE_INSTRUMENTS
534                  printf("src refilled "); fflush(stdout);                  printf("src refilled "); fflush(stdout);
535                  #endif                  #endif
# Line 532  static void copyDimensionRegions(gig::Re Line 544  static void copyDimensionRegions(gig::Re
544              }              }
545          }          }
546    
547          // Schedule copy opertion of source -> target DimensionRegion for the          // Schedule copy operation of source -> target DimensionRegion for the
548          // time after all nested loops have been traversed. We have to postpone          // time after all nested loops have been traversed. We have to postpone
549          // the actual copy operations this way, because otherwise it would          // the actual copy operations this way, because otherwise it would
550          // overwrite informations inside the destination DimensionRegion object          // overwrite informations inside the destination DimensionRegion object
# Line 563  static void copyDimensionRegions(gig::Re Line 575  static void copyDimensionRegions(gig::Re
575          dimCase[type] = (def->split_type == gig::split_type_bit) ? iZone : zoneRange.low;          dimCase[type] = (def->split_type == gig::split_type_bit) ? iZone : zoneRange.low;
576    
577          // recurse until 'dims' is exhausted (and dimCase filled up with concrete value)          // recurse until 'dims' is exhausted (and dimCase filled up with concrete value)
578          copyDimensionRegions(outRgn, inRgn, dims, iDstLayer, iSrcLayer, dimCase, schedule);          scheduleCopyDimensionRegions(outRgn, inRgn, dims, mainDim, iDstMainBit, iSrcMainBit, schedule, dimCase);
579      }      }
580    }
581    
582      // if current function call is the (very first) entry point ...  static OrderedRegionGroup sortRegionGroup(const RegionGroup& group, const std::vector<gig::Instrument*>& instruments) {
583      if (isHighestLevelOfRecursion) {      OrderedRegionGroup result;
584          // ... then perform all scheduled DimensionRegion copy operations      for (std::vector<gig::Instrument*>::const_iterator it = instruments.begin();
585          for (uint i = 0; i < schedule->size(); ++i) {           it != instruments.end(); ++it)
586              CopyAssignSchedEntry& e = (*schedule)[i];      {
587            RegionGroup::const_iterator itRgn = group.find(*it);
588              // backup the target DimensionRegion's current dimension zones upper          if (itRgn == group.end()) continue;
589              // limits (because the target DimensionRegion's upper limits are          result.push_back(
590              // already defined correctly since calling AddDimension(), and the              std::pair<gig::Instrument*, gig::Region*>(
591              // CopyAssign() call next, will overwrite those upper limits                  itRgn->first, itRgn->second
592              // unfortunately              )
593              DimensionRegionUpperLimits dstUpperLimits = getDimensionRegionUpperLimits(e.dst);          );
             DimensionRegionUpperLimits srcUpperLimits = getDimensionRegionUpperLimits(e.src);  
   
             // now actually copy over the current DimensionRegion  
             const gig::Region* const origRgn = e.dst->GetParent(); // just for sanity check below  
             e.dst->CopyAssign(e.src);  
             assert(origRgn == e.dst->GetParent()); // if gigedit is crashing here, then you must update libgig (to at least SVN r2547, v3.3.0.svn10)  
   
             // restore all original dimension zone upper limits except of the  
             // velocity dimension, because the velocity dimension zone sizes are  
             // allowed to differ for individual DimensionRegions in gig v3  
             // format  
             if (srcUpperLimits.count(gig::dimension_velocity)) {  
                 if (!dstUpperLimits.count(gig::dimension_velocity)) {  
                     addWarning("Source instrument seems to have a velocity dimension whereas new target instrument doesn't!");  
                 } else {  
                     dstUpperLimits[gig::dimension_velocity] =  
                         (e.velocityZone >= e.totalSrcVelocityZones)  
                             ? 127 : srcUpperLimits[gig::dimension_velocity];  
                 }  
             }  
             restoreDimensionRegionUpperLimits(e.dst, dstUpperLimits);  
         }  
         delete schedule;  
594      }      }
595        return result;
596  }  }
597    
598  /** @brief Combine given list of instruments to one instrument.  /** @brief Combine given list of instruments to one instrument.
599   *   *
600   * Takes a list of @a instruments as argument and combines them to one single   * Takes a list of @a instruments as argument and combines them to one single
601   * new @a output instrument. For this task, it will create a 'layer' dimension   * new @a output instrument. For this task, it will create a dimension of type
602   * in the new instrument and copies the source instruments to those layers.   * given by @a mainDimension in the new instrument and copies the source
603     * instruments to those dimension zones.
604   *   *
605   * @param instruments - (input) list of instruments that shall be combined,   * @param instruments - (input) list of instruments that shall be combined,
606   *                      they will only be read, so they will be left untouched   *                      they will only be read, so they will be left untouched
# Line 616  static void copyDimensionRegions(gig::Re Line 608  static void copyDimensionRegions(gig::Re
608   *              be created   *              be created
609   * @param output - (output) on success this pointer will be set to the new   * @param output - (output) on success this pointer will be set to the new
610   *                 instrument being created   *                 instrument being created
611     * @param mainDimension - the dimension that shall be used to combine the
612     *                        instruments
613   * @throw RIFF::Exception on any kinds of errors   * @throw RIFF::Exception on any kinds of errors
614   */   */
615  static void combineInstruments(std::vector<gig::Instrument*>& instruments, gig::File* gig, gig::Instrument*& output) {  static void combineInstruments(std::vector<gig::Instrument*>& instruments, gig::File* gig, gig::Instrument*& output, gig::dimension_t mainDimension) {
616      output = NULL;      output = NULL;
617    
618      // divide the individual regions to (probably even smaller) groups of      // divide the individual regions to (probably even smaller) groups of
# Line 655  static void combineInstruments(std::vect Line 649  static void combineInstruments(std::vect
649          printf("---> Start target region %d..%d\n", itGroup->first.low, itGroup->first.high);          printf("---> Start target region %d..%d\n", itGroup->first.low, itGroup->first.high);
650          #endif          #endif
651    
652          // detect the total amount of layers required to build up this combi          // detect the total amount of zones required for the given main
653          // for current key range          // dimension to build up this combi for current key range
654          int iTotalLayers = 0;          int iTotalZones = 0;
655          for (RegionGroup::iterator itRgn = itGroup->second.begin();          for (RegionGroup::iterator itRgn = itGroup->second.begin();
656               itRgn != itGroup->second.end(); ++itRgn)               itRgn != itGroup->second.end(); ++itRgn)
657          {          {
658              gig::Region* inRgn = itRgn->second;              gig::Region* inRgn = itRgn->second;
659              iTotalLayers += inRgn->Layers;              gig::dimension_def_t* def = inRgn->GetDimensionDefinition(mainDimension);
660                iTotalZones += (def) ? def->zones : 1;
661          }          }
662          #if DEBUG_COMBINE_INSTRUMENTS          #if DEBUG_COMBINE_INSTRUMENTS
663          printf("Required total layers: %d\n", iTotalLayers);          printf("Required total zones: %d\n", iTotalZones);
664          #endif          #endif
665            
666          // create all required dimensions for this output region          // create all required dimensions for this output region
667          // (except the layer dimension, which we create as next step)          // (except the main dimension used for separating the individual
668            // instruments, we create that particular dimension as next step)
669          Dimensions dims = getDimensionsForRegionGroup(itGroup->second);          Dimensions dims = getDimensionsForRegionGroup(itGroup->second);
670            // the given main dimension which is used to combine the instruments is
671            // created separately after the next code block, and the main dimension
672            // should not be part of dims here, because it also used for iterating
673            // all dimensions zones, which would lead to this dimensions being
674            // iterated twice
675            dims.erase(mainDimension);
676          {          {
677              std::vector<gig::dimension_t> skipTheseDimensions; // used to prevent a misbehavior (i.e. crash) of the combine algorithm in case one of the source instruments has a dimension with only one zone, which is not standard conform              std::vector<gig::dimension_t> skipTheseDimensions; // used to prevent a misbehavior (i.e. crash) of the combine algorithm in case one of the source instruments has a dimension with only one zone, which is not standard conform
678    
679              for (Dimensions::iterator itDim = dims.begin();              for (Dimensions::iterator itDim = dims.begin();
680                  itDim != dims.end(); ++itDim)                  itDim != dims.end(); ++itDim)
681              {              {
                 // layer dimension is created separately in the next code block  
                 // (outside of this loop)  
                 if (itDim->first == gig::dimension_layer) continue;  
   
682                  gig::dimension_def_t def;                  gig::dimension_def_t def;
683                  def.dimension = itDim->first; // dimension type                  def.dimension = itDim->first; // dimension type
684                  def.zones = itDim->second.size();                  def.zones = itDim->second.size();
# Line 711  static void combineInstruments(std::vect Line 709  static void combineInstruments(std::vect
709                  dims.erase(skipTheseDimensions[i]);                  dims.erase(skipTheseDimensions[i]);
710          }          }
711    
712          // create the layer dimension (if necessary for current key range)          // create the main dimension (if necessary for current key range)
713          if (iTotalLayers > 1) {          if (iTotalZones > 1) {
714              gig::dimension_def_t def;              gig::dimension_def_t def;
715              def.dimension = gig::dimension_layer; // dimension type              def.dimension = mainDimension; // dimension type
716              def.zones = iTotalLayers;              def.zones = iTotalZones;
717              def.bits = zoneCountToBits(def.zones);              def.bits = zoneCountToBits(def.zones);
718              #if DEBUG_COMBINE_INSTRUMENTS              #if DEBUG_COMBINE_INSTRUMENTS
719              std::cout << "Adding new (layer) dimension type=" << std::hex << (int)def.dimension << std::dec << ", zones=" << (int)def.zones << ", bits=" << (int)def.bits << " ... " << std::flush;              std::cout << "Adding new main combi dimension type=" << std::hex << (int)def.dimension << std::dec << ", zones=" << (int)def.zones << ", bits=" << (int)def.bits << " ... " << std::flush;
720              #endif              #endif
721              outRgn->AddDimension(&def);              outRgn->AddDimension(&def);
722              #if DEBUG_COMBINE_INSTRUMENTS              #if DEBUG_COMBINE_INSTRUMENTS
# Line 726  static void combineInstruments(std::vect Line 724  static void combineInstruments(std::vect
724              #endif              #endif
725          }          }
726    
727          // now copy the source dimension regions to the target dimension regions          // for the next task we need to have the current RegionGroup to be
728          int iDstLayer = 0;          // sorted by instrument in the same sequence as the 'instruments' vector
729          for (RegionGroup::iterator itRgn = itGroup->second.begin();          // argument passed to this function (because the std::map behind the
730               itRgn != itGroup->second.end(); ++itRgn) // iterate over 'vertical' / source regions ...          // 'RegionGroup' type sorts by memory address instead, and that would
731            // sometimes lead to the source instruments' region to be sorted into
732            // the wrong target layer)
733            OrderedRegionGroup currentGroup = sortRegionGroup(itGroup->second, instruments);
734    
735            // schedule copying the source dimension regions to the target dimension
736            // regions
737            CopyAssignSchedule schedule;
738            int iDstMainBit = 0;
739            for (OrderedRegionGroup::iterator itRgn = currentGroup.begin();
740                 itRgn != currentGroup.end(); ++itRgn) // iterate over 'vertical' / source regions ...
741          {          {
742              gig::Region* inRgn = itRgn->second;              gig::Region* inRgn = itRgn->second;
743              #if DEBUG_COMBINE_INSTRUMENTS              #if DEBUG_COMBINE_INSTRUMENTS
744              printf("[source region of '%s']\n", inRgn->GetParent()->pInfo->Name.c_str());              printf("[source region of '%s']\n", inRgn->GetParent()->pInfo->Name.c_str());
745              #endif              #endif
746              for (uint iSrcLayer = 0; iSrcLayer < inRgn->Layers; ++iSrcLayer, ++iDstLayer) {  
747                  copyDimensionRegions(outRgn, inRgn, dims, iDstLayer, iSrcLayer);              // determine how many main dimension zones this input region requires
748                gig::dimension_def_t* def = inRgn->GetDimensionDefinition(mainDimension);
749                const int inRgnMainZones = (def) ? def->zones : 1;
750    
751                for (uint iSrcMainBit = 0; iSrcMainBit < inRgnMainZones; ++iSrcMainBit, ++iDstMainBit) {
752                    scheduleCopyDimensionRegions(
753                        outRgn, inRgn, dims, mainDimension,
754                        iDstMainBit, iSrcMainBit, &schedule
755                    );
756                }
757            }
758    
759            // finally copy the scheduled source -> target dimension regions
760            for (uint i = 0; i < schedule.size(); ++i) {
761                CopyAssignSchedEntry& e = schedule[i];
762    
763                // backup the target DimensionRegion's current dimension zones upper
764                // limits (because the target DimensionRegion's upper limits are
765                // already defined correctly since calling AddDimension(), and the
766                // CopyAssign() call next, will overwrite those upper limits
767                // unfortunately
768                DimensionRegionUpperLimits dstUpperLimits = getDimensionRegionUpperLimits(e.dst);
769                DimensionRegionUpperLimits srcUpperLimits = getDimensionRegionUpperLimits(e.src);
770    
771                // now actually copy over the current DimensionRegion
772                const gig::Region* const origRgn = e.dst->GetParent(); // just for sanity check below
773                e.dst->CopyAssign(e.src);
774                assert(origRgn == e.dst->GetParent()); // if gigedit is crashing here, then you must update libgig (to at least SVN r2547, v3.3.0.svn10)
775    
776                // restore all original dimension zone upper limits except of the
777                // velocity dimension, because the velocity dimension zone sizes are
778                // allowed to differ for individual DimensionRegions in gig v3
779                // format
780                //
781                // if the main dinension is the 'velocity' dimension, then skip
782                // restoring the source's original velocity zone limits, because
783                // dealing with merging that is not implemented yet
784                // TODO: merge custom velocity splits if main dimension is the velocity dimension (for now equal sized velocity zones are used if mainDim is 'velocity')
785                if (srcUpperLimits.count(gig::dimension_velocity) && mainDimension != gig::dimension_velocity) {
786                    if (!dstUpperLimits.count(gig::dimension_velocity)) {
787                        addWarning("Source instrument seems to have a velocity dimension whereas new target instrument doesn't!");
788                    } else {
789                        dstUpperLimits[gig::dimension_velocity] =
790                            (e.velocityZone >= e.totalSrcVelocityZones)
791                                ? 127 : srcUpperLimits[gig::dimension_velocity];
792                    }
793              }              }
794                restoreDimensionRegionUpperLimits(e.dst, dstUpperLimits);
795          }          }
796      }      }
797    
# Line 752  CombineInstrumentsDialog::CombineInstrum Line 806  CombineInstrumentsDialog::CombineInstrum
806      : Gtk::Dialog(_("Combine Instruments"), parent, true),      : Gtk::Dialog(_("Combine Instruments"), parent, true),
807        m_gig(gig), m_fileWasChanged(false), m_newCombinedInstrument(NULL),        m_gig(gig), m_fileWasChanged(false), m_newCombinedInstrument(NULL),
808        m_cancelButton(Gtk::Stock::CANCEL), m_OKButton(Gtk::Stock::OK),        m_cancelButton(Gtk::Stock::CANCEL), m_OKButton(Gtk::Stock::OK),
809        m_descriptionLabel()        m_descriptionLabel(), m_tableDimCombo(2, 2), m_comboDimType(),
810          m_labelDimType(Glib::ustring(_("Combine by Dimension:")) + "  ", Gtk::ALIGN_RIGHT)
811  {  {
812      get_vbox()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK);      get_vbox()->pack_start(m_descriptionLabel, Gtk::PACK_SHRINK);
813        get_vbox()->pack_start(m_tableDimCombo, Gtk::PACK_SHRINK);
814      get_vbox()->pack_start(m_treeView);      get_vbox()->pack_start(m_treeView);
815      get_vbox()->pack_start(m_buttonBox, Gtk::PACK_SHRINK);      get_vbox()->pack_start(m_buttonBox, Gtk::PACK_SHRINK);
816    
# Line 762  CombineInstrumentsDialog::CombineInstrum Line 818  CombineInstrumentsDialog::CombineInstrum
818      description.set_line_wrap();      description.set_line_wrap();
819  #endif  #endif
820      m_descriptionLabel.set_text(_(      m_descriptionLabel.set_text(_(
821          "Select at least two instruments below that shall be combined  "          "Select at least two instruments below that shall be combined (as "
822          "as layers (using a \"Layer\" dimension) to a new instrument. The "          "separate dimension zones of the selected dimension type) as a new "
823          "original instruments remain untouched.")          "instrument. The original instruments remain untouched.\n\n"
824      );          "You may use this tool for example to combine solo instruments into "
825            "a combi sound arrangement by selecting the 'layer' dimension, or you "
826            "might combine similar sounding solo sounds into separate velocity "
827            "split layers by using the 'velocity' dimension, and so on."
828        ));
829    
830        // add dimension type combo box
831        {
832            int iLayerDimIndex = -1;
833            Glib::RefPtr<Gtk::ListStore> refComboModel = Gtk::ListStore::create(m_comboDimsModel);
834            for (int i = 0x01, iRow = 0; i < 0xff; i++) {
835                Glib::ustring sType =
836                    dimTypeAsString(static_cast<gig::dimension_t>(i));
837                if (sType.find("Unknown") != 0) {
838                    Gtk::TreeModel::Row row = *(refComboModel->append());
839                    row[m_comboDimsModel.m_type_id]   = i;
840                    row[m_comboDimsModel.m_type_name] = sType;
841                    if (i == gig::dimension_layer) iLayerDimIndex = iRow;
842                    iRow++;
843                }
844            }
845            m_comboDimType.set_model(refComboModel);
846            m_comboDimType.pack_start(m_comboDimsModel.m_type_id);
847            m_comboDimType.pack_start(m_comboDimsModel.m_type_name);
848            m_tableDimCombo.attach(m_labelDimType, 0, 1, 0, 1);
849            m_tableDimCombo.attach(m_comboDimType, 1, 2, 0, 1);
850            m_comboDimType.set_active(iLayerDimIndex); // preselect "layer" dimension
851        }
852    
853      m_refTreeModel = Gtk::ListStore::create(m_columns);      m_refTreeModel = Gtk::ListStore::create(m_columns);
854      m_treeView.set_model(m_refTreeModel);      m_treeView.set_model(m_refTreeModel);
# Line 853  void CombineInstrumentsDialog::combineSe Line 936  void CombineInstrumentsDialog::combineSe
936      g_warnings.clear();      g_warnings.clear();
937    
938      try {      try {
939          combineInstruments(instruments, m_gig, m_newCombinedInstrument);          // which main dimension was selected in the combo box?
940            gig::dimension_t mainDimension;
941            {
942                Gtk::TreeModel::iterator iterType = m_comboDimType.get_active();
943                if (!iterType) throw gig::Exception("No dimension selected");
944                Gtk::TreeModel::Row rowType = *iterType;
945                if (!rowType) throw gig::Exception("Something is wrong regarding dimension selection");
946                int iTypeID = rowType[m_comboDimsModel.m_type_id];
947                mainDimension = static_cast<gig::dimension_t>(iTypeID);
948            }
949    
950            // now start the actual cobination task ...
951            combineInstruments(instruments, m_gig, m_newCombinedInstrument, mainDimension);
952      } catch (RIFF::Exception e) {;      } catch (RIFF::Exception e) {;
953          Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);          Gtk::MessageDialog msg(*this, e.Message, false, Gtk::MESSAGE_ERROR);
954          msg.run();          msg.run();

Legend:
Removed from v.2553  
changed lines
  Added in v.2558

  ViewVC Help
Powered by ViewVC