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

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

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

libgig/trunk/src/korg2gig.cpp revision 2554 by schoenebeck, Wed May 14 20:07:10 2014 UTC libgig/trunk/src/tools/korg2gig.cpp revision 2836 by persson, Sun Aug 23 05:57:18 2015 UTC
# Line 1  Line 1 
1  /***************************************************************************  /***************************************************************************
2   *                                                                         *   *                                                                         *
3   *   Copyright (C) 2014 Christian Schoenebeck                              *   *   Copyright (C) 2014-2015 Christian Schoenebeck                         *
4   *                      <cuse@users.sourceforge.net>                       *   *                      <cuse@users.sourceforge.net>                       *
5   *                                                                         *   *                                                                         *
6   *   This program is part of libgig.                                       *   *   This program is part of libgig.                                       *
# Line 34  Line 34 
34  # include <unistd.h>  # include <unistd.h>
35  #endif  #endif
36    
37  #include "Korg.h"  #include "../Korg.h"
38  #include "gig.h"  #include "../gig.h"
39    
40  using namespace std;  using namespace std;
41    
# Line 63  static void printUsage() { Line 63  static void printUsage() {
63      cout << endl;      cout << endl;
64  }  }
65    
66    static bool beginsWith(const string& haystack, const string& needle) {
67        return haystack.substr(0, needle.size()) == needle;
68    }
69    
70  static bool endsWith(const string& haystack, const string& needle) {  static bool endsWith(const string& haystack, const string& needle) {
71      return haystack.substr(haystack.size() - needle.size(), needle.size()) == needle;      return haystack.substr(haystack.size() - needle.size(), needle.size()) == needle;
72  }  }
# Line 306  static set<DLS::range_t> collectVelocity Line 310  static set<DLS::range_t> collectVelocity
310      set<DLS::range_t> velocityRanges;      set<DLS::range_t> velocityRanges;
311      for (int i = 0; i < group.size(); ++i) {      for (int i = 0; i < group.size(); ++i) {
312          Korg::KMPInstrument* instr = group[i];          Korg::KMPInstrument* instr = group[i];
313          int iLowerKey = 0;          uint16_t iLowerKey = 0;
314          for (int k = 0; k < instr->GetRegionCount(); ++k) {          for (int k = 0; k < instr->GetRegionCount(); ++k) {
315              Korg::KMPRegion* rgn = instr->GetRegion(k);              Korg::KMPRegion* rgn = instr->GetRegion(k);
316              DLS::range_t keyRange2 = { iLowerKey, rgn->TopKey };              DLS::range_t keyRange2 = { iLowerKey, rgn->TopKey };
# Line 315  static set<DLS::range_t> collectVelocity Line 319  static set<DLS::range_t> collectVelocity
319                  int from, to;                  int from, to;
320                  string baseName = parseNumberRange(instr->Name(), from, to);                  string baseName = parseNumberRange(instr->Name(), from, to);
321                  if (baseName != instr->Name()) { // number range like "003-120" found in instrument name ...                  if (baseName != instr->Name()) { // number range like "003-120" found in instrument name ...
322                      DLS::range_t velRange = { from, to };                      DLS::range_t velRange = { uint16_t(from), uint16_t(to) };
323                      velocityRanges.insert(velRange);                      velocityRanges.insert(velRange);
324                  }                  }
325              }              }
# Line 446  static gig::Sample* findOrCreateGigSampl Line 450  static gig::Sample* findOrCreateGigSampl
450          gigSampleGroup->Name = baseName;          gigSampleGroup->Name = baseName;
451      }      }
452    
453        if (kmpRegion->SampleFileName == "SKIPPEDSAMPL" ||
454            (beginsWith(kmpRegion->SampleFileName, "INTERNAL") && !endsWith(kmpRegion->SampleFileName, ".KSF")))
455        {
456            return NULL;
457        }
458    
459      Korg::KSFSample* ksfSample = findKSFSampleWithFileName(kmpRegion->FullSampleFileName());      Korg::KSFSample* ksfSample = findKSFSampleWithFileName(kmpRegion->FullSampleFileName());
460      if (!ksfSample)      if (!ksfSample)
461          throw Korg::Exception("Internal error: Could not resolve KSFSample object");          throw Korg::Exception("Internal error: Could not resolve KSFSample object");
# Line 466  static void loadKorgFile(const string& f Line 476  static void loadKorgFile(const string& f
476    
477              for (int i = 0; i < instr->GetRegionCount(); ++i) {              for (int i = 0; i < instr->GetRegionCount(); ++i) {
478                  Korg::KMPRegion* rgn = instr->GetRegion(i);                  Korg::KMPRegion* rgn = instr->GetRegion(i);
479                    if (rgn->SampleFileName == "SKIPPEDSAMPL") {
480                        cout << "WARNING: 'SKIPPEDSAMPL' as sample reference found!\n";
481                        continue;
482                    } else if (beginsWith(rgn->SampleFileName, "INTERNAL") &&
483                               !endsWith(rgn->SampleFileName, ".KSF")) {
484                        cout << "WARNING: One of the KORG instrument's internal samples was referenced as sample!\n";
485                        continue;
486                    }
487                  // check if the sample referenced by this region was already                  // check if the sample referenced by this region was already
488                  // loaded, if not then load it ...                  // loaded, if not then load it ...
489                  if (!findKSFSampleWithFileName(rgn->FullSampleFileName()))                  if (!findKSFSampleWithFileName(rgn->FullSampleFileName()))
# Line 605  int main(int argc, char *argv[]) { Line 623  int main(int argc, char *argv[]) {
623                  Korg::KMPInstrument* kmpInstr = *itInstr;                  Korg::KMPInstrument* kmpInstr = *itInstr;
624                  cout << "    |---> KMP multi sample '" << kmpInstr->Name() << "'" << endl;                  cout << "    |---> KMP multi sample '" << kmpInstr->Name() << "'" << endl;
625    
626                  int iLowKey = 0;                  uint16_t iLowKey = 0;
627                  for (int k = 0; k < kmpInstr->GetRegionCount(); ++k) {                  for (int k = 0; k < kmpInstr->GetRegionCount(); ++k) {
628                      Korg::KMPRegion* kmpRegion = kmpInstr->GetRegion(k);                      Korg::KMPRegion* kmpRegion = kmpInstr->GetRegion(k);
629                      DLS::range_t keyRange = { iLowKey, kmpRegion->TopKey };                      DLS::range_t keyRange = { iLowKey, kmpRegion->TopKey };
# Line 739  int main(int argc, char *argv[]) { Line 757  int main(int argc, char *argv[]) {
757    
758                      // assign the respective gig sample to this dimension region                      // assign the respective gig sample to this dimension region
759                      gig::Sample* gigSample = findOrCreateGigSampleForKSFRegion(kmpRegion);                      gig::Sample* gigSample = findOrCreateGigSampleForKSFRegion(kmpRegion);
760                      dimRgn->pSample = gigSample; // might be NULL (if Korg sample had zero size)                      dimRgn->pSample = gigSample; // might be NULL (if Korg sample had zero size, or if the original instrument's internal samples were used)
761                      if (gigSample) {                      if (gigSample) {
762                          dimRgn->UnityNote = gigSample->MIDIUnityNote;                          dimRgn->UnityNote = gigSample->MIDIUnityNote;
763                          if (gigSample->Loops) {                          if (gigSample->Loops) {

Legend:
Removed from v.2554  
changed lines
  Added in v.2836

  ViewVC Help
Powered by ViewVC