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

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

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

revision 2543 by schoenebeck, Sat May 10 02:06:58 2014 UTC revision 2546 by schoenebeck, Sat May 10 17:13:52 2014 UTC
# Line 324  static set<DLS::range_t> collectVelocity Line 324  static set<DLS::range_t> collectVelocity
324      return velocityRanges;      return velocityRanges;
325  }  }
326    
327    /**
328     * Ensure that the given list of ranges covers the full range between 0 .. 127.
329     *
330     * @param orig - (input) original set of ranges (read only)
331     * @param corrected - (output) corrected set of ranges (will be cleared and refilled)
332     * @return map that pairs respective original range with respective corrected range
333     */
334    static map<DLS::range_t,DLS::range_t> killGapsInRanges(const set<DLS::range_t>& orig, set<DLS::range_t>& corrected) {
335        map<DLS::range_t,DLS::range_t> result;
336        corrected.clear();
337        if (orig.empty()) return result;
338    
339        int iLow = 0;
340        int i = 0;
341        for (set<DLS::range_t>::const_iterator it = orig.begin(); it != orig.end(); ++it, ++i) {
342            DLS::range_t r = *it;
343            r.low = iLow;
344            iLow = r.high + 1;
345            if (i == orig.size() - 1) r.high = 127;
346            corrected.insert(r);
347            result[*it] = r;
348        }
349        return result;
350    }
351    
352    static void printRanges(const set<DLS::range_t>& ranges) {
353        cout << "{ ";
354        for (set<DLS::range_t>::const_iterator it = ranges.begin(); it != ranges.end(); ++it) {
355            if (it != ranges.begin()) cout << ", ";
356            cout << (int)it->low << ".." << (int)it->high;
357        }
358        cout << " }" << flush;
359    }
360    
361  static vector<Korg::KSFSample*>     ksfSamples;      // input .KSF files  static vector<Korg::KSFSample*>     ksfSamples;      // input .KSF files
362  static vector<Korg::KMPInstrument*> kmpInstruments;  // input .KMP files  static vector<Korg::KMPInstrument*> kmpInstruments;  // input .KMP files
363  static gig::File* g_gig = NULL;                      // output .gig file  static gig::File* g_gig = NULL;                      // output .gig file
# Line 597  int main(int argc, char *argv[]) { Line 631  int main(int argc, char *argv[]) {
631                              dim.dimension = gig::dimension_samplechannel;                              dim.dimension = gig::dimension_samplechannel;
632                              dim.bits  = 1; // 2^(1) = 2                              dim.bits  = 1; // 2^(1) = 2
633                              dim.zones = 2; // stereo = 2 audio channels = 2 split zones                              dim.zones = 2; // stereo = 2 audio channels = 2 split zones
634                                cout << "Adding stereo dimension." << endl;
635                              gigRegion->AddDimension(&dim);                              gigRegion->AddDimension(&dim);
636    
637                              iStereoDimensionIndex = getDimensionIndex(gigRegion, gig::dimension_samplechannel);                              iStereoDimensionIndex = getDimensionIndex(gigRegion, gig::dimension_samplechannel);
# Line 613  int main(int argc, char *argv[]) { Line 648  int main(int argc, char *argv[]) {
648                      DLS::range_t velRange = { 0 , 127 };                      DLS::range_t velRange = { 0 , 127 };
649                      bool isVelocitySplit = bInterpretNames && hasNumberRangeIndicator(kmpInstr->Name());                      bool isVelocitySplit = bInterpretNames && hasNumberRangeIndicator(kmpInstr->Name());
650                      if (isVelocitySplit) { // a velocity split is required for this region ...                      if (isVelocitySplit) { // a velocity split is required for this region ...
651                          // get the amount of velocity split zones for this                          // get the set of velocity split zones defined for
652                          // particular output instrument and key range                          // this particular output instrument and key range
653                          const set<DLS::range_t> velocitySplits = collectVelocitySplits(group, keyRange);                          set<DLS::range_t> origVelocitySplits = collectVelocitySplits(group, keyRange);
654                            // if there are any gaps, that is if the list of velocity
655                            // split ranges do not cover the full range completely
656                            // between 0 .. 127, then auto correct it by increasing
657                            // the split zones accordingly
658                            map<DLS::range_t,DLS::range_t> velocityCorrectionMap; // maps original defined velocity range (key) -> corrected velocity range (value)
659                            {
660                                set<DLS::range_t> correctedSplits;
661                                velocityCorrectionMap = killGapsInRanges(origVelocitySplits, correctedSplits);
662                                if (correctedSplits != origVelocitySplits) {
663                                    cout << "WARNING: Velocity splits did not cover the full range 0..127, auto adjusted it from " << flush;
664                                    printRanges(origVelocitySplits);
665                                    cout << " to " << flush;
666                                    printRanges(correctedSplits);
667                                    cout << endl;
668                                }
669                            }
670    
671                          // get the velocity range for current KORG region                          // get the velocity range for current KORG region
672                          {                          {
# Line 624  int main(int argc, char *argv[]) { Line 675  int main(int argc, char *argv[]) {
675                                  throw Korg::Exception("Internal error: parsing velocity range failed");                                  throw Korg::Exception("Internal error: parsing velocity range failed");
676                              velRange.low  = from;                              velRange.low  = from;
677                              velRange.high = to;                              velRange.high = to;
678                                if (velocityCorrectionMap.find(velRange) == velocityCorrectionMap.end())
679                                    throw Korg::Exception("Internal error: inconsistency in velocity split correction map");
680                                velRange = velocityCorrectionMap[velRange]; // corrected
681                          }                          }
682    
683                          // create velocity split dimension if it doesn't exist already ...                          // create velocity split dimension if it doesn't exist already ...
# Line 631  int main(int argc, char *argv[]) { Line 685  int main(int argc, char *argv[]) {
685                          if (iVelocityDimensionIndex < 0) {                          if (iVelocityDimensionIndex < 0) {
686                              gig::dimension_def_t dim;                              gig::dimension_def_t dim;
687                              dim.dimension = gig::dimension_velocity;                              dim.dimension = gig::dimension_velocity;
688                              dim.zones = velocitySplits.size();                              dim.zones = origVelocitySplits.size();
   
689                              // Find the number of bits required to hold the                              // Find the number of bits required to hold the
690                              // specified amount of zones.                              // specified amount of zones.
691                              int zoneBits = dim.zones - 1;                              int zoneBits = dim.zones - 1;
692                              for (dim.bits = 0; zoneBits > 1; dim.bits += 2, zoneBits >>= 2);                              for (dim.bits = 0; zoneBits > 1; dim.bits += 2, zoneBits >>= 2);
693                              dim.bits += zoneBits;                              dim.bits += zoneBits;
694                                cout << "Adding velocity dimension: zones=" << (int)dim.zones << ", bits=" << (int)dim.bits << endl;
695                              gigRegion->AddDimension(&dim);                              gigRegion->AddDimension(&dim);
696                                
697                              iVelocityDimensionIndex = getDimensionIndex(gigRegion, gig::dimension_velocity);                              iVelocityDimensionIndex = getDimensionIndex(gigRegion, gig::dimension_velocity);
698                          }                          }
699    
# Line 651  int main(int argc, char *argv[]) { Line 704  int main(int argc, char *argv[]) {
704                          int iVelocitySplitZone = -1;                          int iVelocitySplitZone = -1;
705                          {                          {
706                              int i = 0;                              int i = 0;
707                              for (set<DLS::range_t>::const_iterator itVelSplit = velocitySplits.begin();                              for (map<DLS::range_t,DLS::range_t>::const_iterator itVelSplit = velocityCorrectionMap.begin();
708                                   itVelSplit != velocitySplits.end(); ++itVelSplit, ++i)                                   itVelSplit != velocityCorrectionMap.end(); ++itVelSplit, ++i)
709                              {                              {
710                                  if (*itVelSplit == velRange) {                                  if (itVelSplit->second == velRange) { // already corrected before, thus second, not first
711                                      iVelocitySplitZone = i;                                      iVelocitySplitZone = i;
712                                      break;                                      break;
713                                  }                                  }

Legend:
Removed from v.2543  
changed lines
  Added in v.2546

  ViewVC Help
Powered by ViewVC