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

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

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

revision 3991 by schoenebeck, Tue Aug 31 15:58:57 2021 UTC revision 3992 by schoenebeck, Thu Sep 2 15:15:43 2021 UTC
# Line 94  static void printUsage() { Line 94  static void printUsage() {
94      cout << endl;      cout << endl;
95      cout << "      Scan input sample (.wav) files, but exit before creating any .gig file." << endl;      cout << "      Scan input sample (.wav) files, but exit before creating any .gig file." << endl;
96      cout << endl;      cout << endl;
97        cout << "  --verbose" << endl;
98        cout << endl;
99        cout << "      Increase amount of info being shown." << endl;
100        cout << endl;
101      cout << "  --regex-name1 PATTERN" << endl;      cout << "  --regex-name1 PATTERN" << endl;
102      cout << endl;      cout << endl;
103      cout << "      Regular expression for overriding the NAME1 part of the input sample file name scheme." << endl;      cout << "      Regular expression for overriding the NAME1 part of the input sample file name scheme." << endl;
# Line 381  inline int getDimensionIndex(gig::Region Line 385  inline int getDimensionIndex(gig::Region
385      return -1;      return -1;
386  }  }
387    
388  static gig::Sample* createSample(gig::File* gig, WavInfo* wav) {  static gig::Sample* createSample(gig::File* gig, WavInfo* wav, bool bVerbose) {
389      gig::Sample* s = gig->AddSample();      gig::Sample* s = gig->AddSample();
390    
391      s->pInfo->Name      = wav->outputSampleName();      s->pInfo->Name      = wav->outputSampleName();
392      s->Channels         = wav->sfinfo.channels;      s->Channels         = wav->sfinfo.channels;
393      s->SamplesPerSecond = wav->sfinfo.samplerate;      s->SamplesPerSecond = wav->sfinfo.samplerate;
394        
395        if (bVerbose) {
396            cout << "Add Sample [" << gig->CountSamples() << "] '"
397                 << s->pInfo->Name << "' to gig file:" << endl;
398        }
399    
400      switch (wav->sfinfo.format & 0xff) {      switch (wav->sfinfo.format & 0xff) {
401          case SF_FORMAT_PCM_S8:          case SF_FORMAT_PCM_S8:
402          case SF_FORMAT_PCM_16:          case SF_FORMAT_PCM_16:
# Line 405  static gig::Sample* createSample(gig::Fi Line 414  static gig::Sample* createSample(gig::Fi
414      }      }
415    
416      s->FrameSize = s->Channels * s->BitDepth / 8;      s->FrameSize = s->Channels * s->BitDepth / 8;
417    
418        if (bVerbose) {
419            cout << "\t" << s->BitDepth << " Bits "
420                 << s->SamplesPerSecond << " Hz "
421                 << s->Channels << " Channels"
422                 << endl;
423        }
424    
425      if (wav->hasSfInst) {      if (wav->hasSfInst) {
426          s->MIDIUnityNote = wav->sfinst.basenote;          s->MIDIUnityNote = wav->sfinst.basenote;
427          s->FineTune      = wav->sfinst.detune;          s->FineTune      = wav->sfinst.detune;
428            if (bVerbose) {
429                cout << "\tRoot Note " << s->MIDIUnityNote
430                    << " [Source: .WAV Internal Content]" << endl;
431                cout << "\tFine Tune " << s->FineTune << endl;
432            }
433          if (wav->sfinst.loop_count && wav->sfinst.loops[0].mode != SF_LOOP_NONE) {          if (wav->sfinst.loop_count && wav->sfinst.loops[0].mode != SF_LOOP_NONE) {
434              s->Loops = 1;              s->Loops = 1;
435                if (bVerbose) cout << "\t";
436              switch (wav->sfinst.loops[0].mode) {              switch (wav->sfinst.loops[0].mode) {
437                  case SF_LOOP_FORWARD:                  case SF_LOOP_FORWARD:
438                      s->LoopType = gig::loop_type_normal;                      s->LoopType = gig::loop_type_normal;
439                        if (bVerbose) cout << "Normal ";
440                      break;                      break;
441                  case SF_LOOP_BACKWARD:                  case SF_LOOP_BACKWARD:
442                      s->LoopType = gig::loop_type_backward;                      s->LoopType = gig::loop_type_backward;
443                        if (bVerbose) cout << "Backward ";
444                      break;                      break;
445                  case SF_LOOP_ALTERNATING:                  case SF_LOOP_ALTERNATING:
446                      s->LoopType = gig::loop_type_bidirectional;                      s->LoopType = gig::loop_type_bidirectional;
447                        if (bVerbose) cout << "Pingpong ";
448                      break;                      break;
449              }              }
450              s->LoopStart = wav->sfinst.loops[0].start;              s->LoopStart = wav->sfinst.loops[0].start;
451              s->LoopEnd = wav->sfinst.loops[0].end;              s->LoopEnd = wav->sfinst.loops[0].end;
452              s->LoopPlayCount = wav->sfinst.loops[0].count;              s->LoopPlayCount = wav->sfinst.loops[0].count;
453              s->LoopSize = s->LoopEnd - s->LoopStart + 1;              s->LoopSize = s->LoopEnd - s->LoopStart + 1;
454                if (bVerbose) {
455                    cout << "Loop " << s->LoopPlayCount << " times from "
456                         << s->LoopStart << " to " << s->LoopEnd
457                         << " (Size " << s->LoopSize << ")" << endl;
458                }
459          }          }
460      } else {      } else {
461          s->MIDIUnityNote = wav->note;          s->MIDIUnityNote = wav->note;
462            cout << "\tRoot Note " << s->MIDIUnityNote << " [Source: .WAV Filename Schema]" << endl;
463      }      }
464    
465      // schedule for resize (will be performed when gig->Save() is called)      // schedule for resize (will be performed when gig->Save() is called)
# Line 440  int main(int argc, char *argv[]) { Line 472  int main(int argc, char *argv[]) {
472      bool bForce = false;      bool bForce = false;
473      bool bRecursive = false;      bool bRecursive = false;
474      bool bDryRun = false;      bool bDryRun = false;
475        bool bVerbose = false;
476      FilenameRegExPatterns patterns = {      FilenameRegExPatterns patterns = {
477          // name 1 (e.g. "BSTEIN18")          // name 1 (e.g. "BSTEIN18")
478          .name1 = "^([^-]+) - [^-]+ - [^-]+ - [^-]+ - [^.]+",          .name1 = "^([^-]+) - [^-]+ - [^-]+ - [^-]+ - [^.]+",
# Line 473  int main(int argc, char *argv[]) { Line 506  int main(int argc, char *argv[]) {
506              bRecursive = true;              bRecursive = true;
507          } else if (opt == "--dry-run") {          } else if (opt == "--dry-run") {
508              bDryRun = true;              bDryRun = true;
509            } else if (opt == "--verbose") {
510                bVerbose = true;
511          } else if (opt == "--regex-name1") {          } else if (opt == "--regex-name1") {
512              if (nextOpt.empty() || beginsWith(nextOpt, "-")) {              if (nextOpt.empty() || beginsWith(nextOpt, "-")) {
513                  cerr << "Missing argument for option '" << opt << "'" << endl;                  cerr << "Missing argument for option '" << opt << "'" << endl;
# Line 585  int main(int argc, char *argv[]) { Line 620  int main(int argc, char *argv[]) {
620      }      }
621      cout << "OK\n";      cout << "OK\n";
622    
     if (bDryRun)  
         return EXIT_SUCCESS;  
   
623      // create and assemble a new .gig file as output      // create and assemble a new .gig file as output
624      try {      try {
625          cout << "Creating new gig file and one new gig instrument ... " << flush;          cout << "Creating new gig file and one new gig instrument ... " << flush;
# Line 637  int main(int argc, char *argv[]) { Line 669  int main(int argc, char *argv[]) {
669              for (auto& itWav : wavRgn) {              for (auto& itWav : wavRgn) {
670                  const int velocity = itWav.first;                  const int velocity = itWav.first;
671                  WavInfo& wav = itWav.second;                  WavInfo& wav = itWav.second;
672                  gig::Sample* gigSample = createSample(&gig, &wav);                  gig::Sample* gigSample = createSample(&gig, &wav, bVerbose);
673                  queuedSamples[gigSample] = wav;                  queuedSamples[gigSample] = wav;
674    
675                  uint8_t iDimBits[8] = {};                  uint8_t iDimBits[8] = {};
# Line 688  int main(int argc, char *argv[]) { Line 720  int main(int argc, char *argv[]) {
720              }              }
721          }          }
722          cout << "OK\n";          cout << "OK\n";
723            
724            if (bDryRun)
725                return EXIT_SUCCESS;
726    
727          cout << "Saving initial gig file layout ... " << flush;          cout << "Saving initial gig file layout ... " << flush;
728          // save result to disk (as .gig file)          // save result to disk (as .gig file)
729          gig.Save(outFileName);          gig.Save(outFileName);

Legend:
Removed from v.3991  
changed lines
  Added in v.3992

  ViewVC Help
Powered by ViewVC