/[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 3446 by schoenebeck, Sun Dec 23 21:47:26 2018 UTC revision 3474 by schoenebeck, Wed Feb 20 16:04:19 2019 UTC
# Line 2  Line 2 
2   *                                                                         *   *                                                                         *
3   *   libgig - C++ cross-platform Gigasampler format file access library    *   *   libgig - C++ cross-platform Gigasampler format file access library    *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003-2018 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2019 by Christian Schoenebeck                      *
6   *                              <cuse@users.sourceforge.net>               *   *                              <cuse@users.sourceforge.net>               *
7   *                                                                         *   *                                                                         *
8   *   This library is free software; you can redistribute it and/or modify  *   *   This library is free software; you can redistribute it and/or modify  *
# Line 5702  namespace { Line 5702  namespace {
5702          int iSampleIndex  = 0;          int iSampleIndex  = 0;
5703          int iTotalSamples = WavePoolCount;          int iTotalSamples = WavePoolCount;
5704    
5705          // check if samples should be loaded from extension files          // just for assembling path of optional extension files to be read
5706          // (only for old gig files < 2 GB)          const std::string folder = parentPath(pRIFF->GetFileName());
5707          int lastFileNo = 0;          const std::string baseName = pathWithoutExtension(pRIFF->GetFileName());
5708          if (!file->IsNew() && !(file->GetCurrentFileSize() >> 31)) {  
5709              for (int i = 0 ; i < WavePoolCount ; i++) {          // the main gig file and the extension files (.gx01, ... , .gx98) may
5710                  if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i];          // contain wave data (wave pool)
5711              }          std::vector<RIFF::File*> poolFiles;
5712          }          poolFiles.push_back(pRIFF);
5713          String name(pRIFF->GetFileName());  
5714          int nameLen = (int) name.length();          // get info about all extension files
5715          char suffix[6];          RIFF::Chunk* ckXfil = pRIFF->GetSubChunk(CHUNK_ID_XFIL);
5716          if (nameLen > 4 && name.substr(nameLen - 4) == ".gig") nameLen -= 4;          if (ckXfil) { // there are extension files (.gx01, ... , .gx98) ...
5717                const uint32_t n = ckXfil->ReadInt32();
5718          for (int fileNo = 0 ; ; ) {              for (int i = 0; i < n; i++) {
5719                    // read the filename and load the extension file
5720                    std::string name;
5721                    ckXfil->ReadString(name, 128);
5722                    std::string path = concatPath(folder, name);
5723                    RIFF::File* pExtFile = new RIFF::File(path);
5724                    // check that the dlsids match
5725                    RIFF::Chunk* ckDLSID = pExtFile->GetSubChunk(CHUNK_ID_DLID);
5726                    if (ckDLSID) {
5727                        ::DLS::dlsid_t idExpected;
5728                        idExpected.ulData1 = ckXfil->ReadInt32();
5729                        idExpected.usData2 = ckXfil->ReadInt16();
5730                        idExpected.usData3 = ckXfil->ReadInt16();
5731                        ckXfil->Read(idExpected.abData, 8, 1);
5732                        ::DLS::dlsid_t idFound;
5733                        ckDLSID->Read(&idFound.ulData1, 1, 4);
5734                        ckDLSID->Read(&idFound.usData2, 1, 2);
5735                        ckDLSID->Read(&idFound.usData3, 1, 2);
5736                        ckDLSID->Read(idFound.abData, 8, 1);
5737                        if (memcmp(&idExpected, &idFound, 16) != 0)
5738                            throw gig::Exception("dlsid mismatch for extension file: %s", path.c_str());
5739                    }
5740                    poolFiles.push_back(pExtFile);
5741                    ExtensionFiles.push_back(pExtFile);
5742                }
5743            }
5744    
5745            // check if a .gx99 (GigaPulse) file exists
5746            RIFF::Chunk* ckDoxf = pRIFF->GetSubChunk(CHUNK_ID_DOXF);
5747            if (ckDoxf) { // there is a .gx99 (GigaPulse) file ...
5748                std::string path = baseName + ".gx99";
5749                RIFF::File* pExtFile = new RIFF::File(path);
5750    
5751                // skip unused int and filename
5752                ckDoxf->SetPos(132, RIFF::stream_whence_t::stream_curpos);
5753    
5754                // check that the dlsids match
5755                RIFF::Chunk* ckDLSID = pExtFile->GetSubChunk(CHUNK_ID_DLID);
5756                if (ckDLSID) {
5757                    ::DLS::dlsid_t idExpected;
5758                    idExpected.ulData1 = ckDoxf->ReadInt32();
5759                    idExpected.usData2 = ckDoxf->ReadInt16();
5760                    idExpected.usData3 = ckDoxf->ReadInt16();
5761                    ckDoxf->Read(idExpected.abData, 8, 1);
5762                    ::DLS::dlsid_t idFound;
5763                    ckDLSID->Read(&idFound.ulData1, 1, 4);
5764                    ckDLSID->Read(&idFound.usData2, 1, 2);
5765                    ckDLSID->Read(&idFound.usData3, 1, 2);
5766                    ckDLSID->Read(idFound.abData, 8, 1);
5767                    if (memcmp(&idExpected, &idFound, 16) != 0)
5768                        throw gig::Exception("dlsid mismatch for GigaPulse file: %s", path.c_str());
5769                }
5770                poolFiles.push_back(pExtFile);
5771                ExtensionFiles.push_back(pExtFile);
5772            }
5773    
5774            // load samples from extension files (if required)
5775            for (int i = 0; i < poolFiles.size(); i++) {
5776                RIFF::File* file = poolFiles[i];
5777              RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL);              RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL);
5778              if (wvpl) {              if (wvpl) {
5779                  file_offset_t wvplFileOffset = wvpl->GetFilePos();                  file_offset_t wvplFileOffset = wvpl->GetFilePos();
# Line 5727  namespace { Line 5785  namespace {
5785                          __notify_progress(pProgress, subprogress);                          __notify_progress(pProgress, subprogress);
5786    
5787                          file_offset_t waveFileOffset = wave->GetFilePos();                          file_offset_t waveFileOffset = wave->GetFilePos();
5788                          pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo, iSampleIndex));                          pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, i, iSampleIndex));
5789    
5790                          iSampleIndex++;                          iSampleIndex++;
5791                      }                      }
5792                      wave = wvpl->GetNextSubList();                      wave = wvpl->GetNextSubList();
5793                  }                  }
5794                }
                 if (fileNo == lastFileNo) break;  
   
                 // open extension file (*.gx01, *.gx02, ...)  
                 fileNo++;  
                 sprintf(suffix, ".gx%02d", fileNo);  
                 name.replace(nameLen, 5, suffix);  
                 file = new RIFF::File(name);  
                 ExtensionFiles.push_back(file);  
             } else break;  
5795          }          }
5796    
5797          __notify_progress(pProgress, 1.0); // notify done          __notify_progress(pProgress, 1.0); // notify done

Legend:
Removed from v.3446  
changed lines
  Added in v.3474

  ViewVC Help
Powered by ViewVC