/[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 406 by persson, Wed Feb 23 19:11:07 2005 UTC revision 728 by persson, Tue Jul 26 11:13:53 2005 UTC
# Line 25  Line 25 
25    
26  #include <iostream>  #include <iostream>
27    
28  namespace gig { namespace {  namespace gig {
29    
30    // *************** progress_t ***************
31    // *
32    
33        progress_t::progress_t() {
34            callback    = NULL;
35            custom      = NULL;
36            __range_min = 0.0f;
37            __range_max = 1.0f;
38        }
39    
40        // private helper function to convert progress of a subprocess into the global progress
41        static void __notify_progress(progress_t* pProgress, float subprogress) {
42            if (pProgress && pProgress->callback) {
43                const float totalrange    = pProgress->__range_max - pProgress->__range_min;
44                const float totalprogress = pProgress->__range_min + subprogress * totalrange;
45                pProgress->factor         = totalprogress;
46                pProgress->callback(pProgress); // now actually notify about the progress
47            }
48        }
49    
50        // private helper function to divide a progress into subprogresses
51        static void __divide_progress(progress_t* pParentProgress, progress_t* pSubProgress, float totalTasks, float currentTask) {
52            if (pParentProgress && pParentProgress->callback) {
53                const float totalrange    = pParentProgress->__range_max - pParentProgress->__range_min;
54                pSubProgress->callback    = pParentProgress->callback;
55                pSubProgress->custom      = pParentProgress->custom;
56                pSubProgress->__range_min = pParentProgress->__range_min + totalrange * currentTask / totalTasks;
57                pSubProgress->__range_max = pSubProgress->__range_min + totalrange / totalTasks;
58            }
59        }
60    
61    
62  // *************** Internal functions for sample decopmression ***************  // *************** Internal functions for sample decopmression ***************
63  // *  // *
64    
65    namespace {
66    
67      inline int get12lo(const unsigned char* pSrc)      inline int get12lo(const unsigned char* pSrc)
68      {      {
69          const int x = pSrc[0] | (pSrc[1] & 0x0f) << 8;          const int x = pSrc[0] | (pSrc[1] & 0x0f) << 8;
# Line 94  namespace gig { namespace { Line 128  namespace gig { namespace {
128      void Decompress24(int compressionmode, const unsigned char* params,      void Decompress24(int compressionmode, const unsigned char* params,
129                        int dstStep, const unsigned char* pSrc, int16_t* pDst,                        int dstStep, const unsigned char* pSrc, int16_t* pDst,
130                        unsigned long currentframeoffset,                        unsigned long currentframeoffset,
131                        unsigned long copysamples)                        unsigned long copysamples, int truncatedBits)
132      {      {
133          // Note: The 24 bits are truncated to 16 bits for now.          // Note: The 24 bits are truncated to 16 bits for now.
134    
135          // Note: The calculation of the initial value of y is strange          int y, dy, ddy, dddy;
136          // and not 100% correct. What should the first two parameters          const int shift = 8 - truncatedBits;
137          // really be used for? Why are they two? The correct value for  
138          // y seems to lie somewhere between the values of the first  #define GET_PARAMS(params)                      \
139          // two parameters.          y    = get24(params);                   \
140          //          dy   = y - get24((params) + 3);         \
141          // Strange thing #2: The formula in SKIP_ONE gives values for          ddy  = get24((params) + 6);             \
142          // y that are twice as high as they should be. That's why          dddy = get24((params) + 9)
         // COPY_ONE shifts 9 steps instead of 8, and also why y is  
         // initialized with a sum instead of a mean value.  
   
         int y, dy, ddy;  
   
 #define GET_PARAMS(params)                              \  
         y = (get24(params) + get24((params) + 3));      \  
         dy  = get24((params) + 6);                      \  
         ddy = get24((params) + 9)  
143    
144  #define SKIP_ONE(x)                             \  #define SKIP_ONE(x)                             \
145          ddy -= (x);                             \          dddy -= (x);                            \
146          dy -= ddy;                              \          ddy  -= dddy;                           \
147          y -= dy          dy   =  -dy - ddy;                      \
148            y    += dy
149    
150  #define COPY_ONE(x)                             \  #define COPY_ONE(x)                             \
151          SKIP_ONE(x);                            \          SKIP_ONE(x);                            \
152          *pDst = y >> 9;                         \          *pDst = y >> shift;                     \
153          pDst += dstStep          pDst += dstStep
154    
155          switch (compressionmode) {          switch (compressionmode) {
156              case 2: // 24 bit uncompressed              case 2: // 24 bit uncompressed
157                  pSrc += currentframeoffset * 3;                  pSrc += currentframeoffset * 3;
158                  while (copysamples) {                  while (copysamples) {
159                      *pDst = get24(pSrc) >> 8;                      *pDst = get24(pSrc) >> shift;
160                      pDst += dstStep;                      pDst += dstStep;
161                      pSrc += 3;                      pSrc += 3;
162                      copysamples--;                      copysamples--;
# Line 206  namespace gig { namespace { Line 232  namespace gig { namespace {
232      unsigned int Sample::Instances = 0;      unsigned int Sample::Instances = 0;
233      buffer_t     Sample::InternalDecompressionBuffer;      buffer_t     Sample::InternalDecompressionBuffer;
234    
235      Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) {      Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) {
236          Instances++;          Instances++;
237            FileNo = fileNo;
238    
239          RIFF::Chunk* _3gix = waveList->GetSubChunk(CHUNK_ID_3GIX);          RIFF::Chunk* _3gix = waveList->GetSubChunk(CHUNK_ID_3GIX);
240          if (!_3gix) throw gig::Exception("Mandatory chunks in <wave> list chunk not found.");          if (!_3gix) throw gig::Exception("Mandatory chunks in <wave> list chunk not found.");
# Line 239  namespace gig { namespace { Line 266  namespace gig { namespace {
266    
267          if (BitDepth > 24) throw gig::Exception("Only samples up to 24 bit supported");          if (BitDepth > 24) throw gig::Exception("Only samples up to 24 bit supported");
268    
269          Compressed = (waveList->GetSubChunk(CHUNK_ID_EWAV));          RIFF::Chunk* ewav = waveList->GetSubChunk(CHUNK_ID_EWAV);
270            Compressed        = ewav;
271            Dithered          = false;
272            TruncatedBits     = 0;
273          if (Compressed) {          if (Compressed) {
274                uint32_t version = ewav->ReadInt32();
275                if (version == 3 && BitDepth == 24) {
276                    Dithered = ewav->ReadInt32();
277                    ewav->SetPos(Channels == 2 ? 84 : 64);
278                    TruncatedBits = ewav->ReadInt32();
279                }
280              ScanCompressedSample();              ScanCompressedSample();
281          }          }
282    
# Line 249  namespace gig { namespace { Line 285  namespace gig { namespace {
285              InternalDecompressionBuffer.pStart = new unsigned char[INITIAL_SAMPLE_BUFFER_SIZE];              InternalDecompressionBuffer.pStart = new unsigned char[INITIAL_SAMPLE_BUFFER_SIZE];
286              InternalDecompressionBuffer.Size   = INITIAL_SAMPLE_BUFFER_SIZE;              InternalDecompressionBuffer.Size   = INITIAL_SAMPLE_BUFFER_SIZE;
287          }          }
288          FrameOffset = 0; // just for streaming compressed samples          FrameOffset = 0; // just for streaming compressed samples
289    
290          LoopSize = LoopEnd - LoopStart;          LoopSize = LoopEnd - LoopStart;
291      }      }
# Line 846  namespace gig { namespace { Line 882  namespace gig { namespace {
882                              const unsigned char* const param_r = pSrc;                              const unsigned char* const param_r = pSrc;
883                              if (mode_r != 2) pSrc += 12;                              if (mode_r != 2) pSrc += 12;
884    
885                              Decompress24(mode_l, param_l, 2, pSrc, pDst, skipsamples, copysamples);                              Decompress24(mode_l, param_l, 2, pSrc, pDst,
886                                             skipsamples, copysamples, TruncatedBits);
887                              Decompress24(mode_r, param_r, 2, pSrc + rightChannelOffset, pDst + 1,                              Decompress24(mode_r, param_r, 2, pSrc + rightChannelOffset, pDst + 1,
888                                           skipsamples, copysamples);                                           skipsamples, copysamples, TruncatedBits);
889                              pDst += copysamples << 1;                              pDst += copysamples << 1;
890                          }                          }
891                          else { // Mono                          else { // Mono
892                              Decompress24(mode_l, param_l, 1, pSrc, pDst, skipsamples, copysamples);                              Decompress24(mode_l, param_l, 1, pSrc, pDst,
893                                             skipsamples, copysamples, TruncatedBits);
894                              pDst += copysamples;                              pDst += copysamples;
895                          }                          }
896                      }                      }
# Line 1096  namespace gig { namespace { Line 1134  namespace gig { namespace {
1134          VCFEnabled = vcfcutoff & 0x80; // bit 7          VCFEnabled = vcfcutoff & 0x80; // bit 7
1135          VCFCutoff  = vcfcutoff & 0x7f; // lower 7 bits          VCFCutoff  = vcfcutoff & 0x7f; // lower 7 bits
1136          VCFCutoffController = static_cast<vcf_cutoff_ctrl_t>(_3ewa->ReadUint8());          VCFCutoffController = static_cast<vcf_cutoff_ctrl_t>(_3ewa->ReadUint8());
1137          VCFVelocityScale = _3ewa->ReadUint8();          uint8_t vcfvelscale = _3ewa->ReadUint8();
1138            VCFCutoffControllerInvert = vcfvelscale & 0x80; // bit 7
1139            VCFVelocityScale = vcfvelscale & 0x7f; // lower 7 bits
1140          _3ewa->ReadInt8(); // unknown          _3ewa->ReadInt8(); // unknown
1141          uint8_t vcfresonance = _3ewa->ReadUint8();          uint8_t vcfresonance = _3ewa->ReadUint8();
1142          VCFResonance = vcfresonance & 0x7f; // lower 7 bits          VCFResonance = vcfresonance & 0x7f; // lower 7 bits
# Line 1113  namespace gig { namespace { Line 1153  namespace gig { namespace {
1153                  VCFType = vcf_type_lowpassturbo;                  VCFType = vcf_type_lowpassturbo;
1154          }          }
1155    
1156          // get the corresponding velocity->volume table from the table map or create & calculate that table if it doesn't exist yet          pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve,
1157          uint32_t tableKey = (VelocityResponseCurve<<16) | (VelocityResponseDepth<<8) | VelocityResponseCurveScaling;                                                       VelocityResponseDepth,
1158                                                         VelocityResponseCurveScaling);
1159    
1160            curve_type_t curveType = ReleaseVelocityResponseCurve;
1161            uint8_t depth = ReleaseVelocityResponseDepth;
1162    
1163            // this models a strange behaviour or bug in GSt: two of the
1164            // velocity response curves for release time are not used even
1165            // if specified, instead another curve is chosen.
1166            if ((curveType == curve_type_nonlinear && depth == 0) ||
1167                (curveType == curve_type_special   && depth == 4)) {
1168                curveType = curve_type_nonlinear;
1169                depth = 3;
1170            }
1171            pVelocityReleaseTable = GetVelocityTable(curveType, depth, 0);
1172    
1173            curveType = VCFVelocityCurve;
1174            depth = VCFVelocityDynamicRange;
1175    
1176            // even stranger GSt: two of the velocity response curves for
1177            // filter cutoff are not used, instead another special curve
1178            // is chosen. This curve is not used anywhere else.
1179            if ((curveType == curve_type_nonlinear && depth == 0) ||
1180                (curveType == curve_type_special   && depth == 4)) {
1181                curveType = curve_type_special;
1182                depth = 5;
1183            }
1184            pVelocityCutoffTable = GetVelocityTable(curveType, depth,
1185                                                    VCFCutoffController == vcf_cutoff_ctrl_none ? VCFVelocityScale : 0);
1186    
1187            SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360));
1188        }
1189    
1190        // get the corresponding velocity table from the table map or create & calculate that table if it doesn't exist yet
1191        double* DimensionRegion::GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling)
1192        {
1193            double* table;
1194            uint32_t tableKey = (curveType<<16) | (depth<<8) | scaling;
1195          if (pVelocityTables->count(tableKey)) { // if key exists          if (pVelocityTables->count(tableKey)) { // if key exists
1196              pVelocityAttenuationTable = (*pVelocityTables)[tableKey];              table = (*pVelocityTables)[tableKey];
1197          }          }
1198          else {          else {
1199              pVelocityAttenuationTable =              table = CreateVelocityTable(curveType, depth, scaling);
1200                  CreateVelocityTable(VelocityResponseCurve,              (*pVelocityTables)[tableKey] = table; // put the new table into the tables map
                                     VelocityResponseDepth,  
                                     VelocityResponseCurveScaling);  
             (*pVelocityTables)[tableKey] = pVelocityAttenuationTable; // put the new table into the tables map  
1201          }          }
1202            return table;
         SampleAttenuation = pow(10.0, -Gain / (20.0 * 655360));  
1203      }      }
1204    
1205      leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) {      leverage_ctrl_t DimensionRegion::DecodeLeverageController(_lev_ctrl_t EncodedController) {
# Line 1277  namespace gig { namespace { Line 1350  namespace gig { namespace {
1350          return pVelocityAttenuationTable[MIDIKeyVelocity];          return pVelocityAttenuationTable[MIDIKeyVelocity];
1351      }      }
1352    
1353        double DimensionRegion::GetVelocityRelease(uint8_t MIDIKeyVelocity) {
1354            return pVelocityReleaseTable[MIDIKeyVelocity];
1355        }
1356    
1357        double DimensionRegion::GetVelocityCutoff(uint8_t MIDIKeyVelocity) {
1358            return pVelocityCutoffTable[MIDIKeyVelocity];
1359        }
1360    
1361      double* DimensionRegion::CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) {      double* DimensionRegion::CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling) {
1362    
1363          // line-segment approximations of the 15 velocity curves          // line-segment approximations of the 15 velocity curves
# Line 1310  namespace gig { namespace { Line 1391  namespace gig { namespace {
1391          const int spe4[] = { 1, 4, 23, 5, 49, 13, 57, 17, 92, 57, 122, 127,          const int spe4[] = { 1, 4, 23, 5, 49, 13, 57, 17, 92, 57, 122, 127,
1392                               127, 127 };                               127, 127 };
1393    
1394            // this is only used by the VCF velocity curve
1395            const int spe5[] = { 1, 2, 30, 5, 60, 19, 77, 70, 83, 85, 88, 106,
1396                                 91, 127, 127, 127 };
1397    
1398          const int* const curves[] = { non0, non1, non2, non3, non4,          const int* const curves[] = { non0, non1, non2, non3, non4,
1399                                        lin0, lin1, lin2, lin3, lin4,                                        lin0, lin1, lin2, lin3, lin4,
1400                                        spe0, spe1, spe2, spe3, spe4 };                                        spe0, spe1, spe2, spe3, spe4, spe5 };
1401    
1402          double* const table = new double[128];          double* const table = new double[128];
1403    
# Line 1378  namespace gig { namespace { Line 1463  namespace gig { namespace {
1463                      pDimensionDefinitions[i].zones     = 0x01 << bits; // = pow(2,bits)                      pDimensionDefinitions[i].zones     = 0x01 << bits; // = pow(2,bits)
1464                      pDimensionDefinitions[i].split_type = (dimension == dimension_layer ||                      pDimensionDefinitions[i].split_type = (dimension == dimension_layer ||
1465                                                             dimension == dimension_samplechannel ||                                                             dimension == dimension_samplechannel ||
1466                                                             dimension == dimension_releasetrigger) ? split_type_bit                                                             dimension == dimension_releasetrigger ||
1467                                                                                                    : split_type_normal;                                                             dimension == dimension_roundrobin ||
1468                                                               dimension == dimension_random) ? split_type_bit
1469                                                                                              : split_type_normal;
1470                      pDimensionDefinitions[i].ranges = NULL; // it's not possible to check velocity dimensions for custom defined ranges at this point                      pDimensionDefinitions[i].ranges = NULL; // it's not possible to check velocity dimensions for custom defined ranges at this point
1471                      pDimensionDefinitions[i].zone_size  =                      pDimensionDefinitions[i].zone_size  =
1472                          (pDimensionDefinitions[i].split_type == split_type_normal) ? 128 / pDimensionDefinitions[i].zones                          (pDimensionDefinitions[i].split_type == split_type_normal) ? 128 / pDimensionDefinitions[i].zones
# Line 1535  namespace gig { namespace { Line 1622  namespace gig { namespace {
1622          else         return static_cast<gig::Sample*>(pSample = GetSampleFromWavePool(WavePoolTableIndex));          else         return static_cast<gig::Sample*>(pSample = GetSampleFromWavePool(WavePoolTableIndex));
1623      }      }
1624    
1625      Sample* Region::GetSampleFromWavePool(unsigned int WavePoolTableIndex) {      Sample* Region::GetSampleFromWavePool(unsigned int WavePoolTableIndex, progress_t* pProgress) {
1626          if ((int32_t)WavePoolTableIndex == -1) return NULL;          if ((int32_t)WavePoolTableIndex == -1) return NULL;
1627          File* file = (File*) GetParent()->GetParent();          File* file = (File*) GetParent()->GetParent();
1628          unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex];          unsigned long soughtoffset = file->pWavePoolTable[WavePoolTableIndex];
1629          Sample* sample = file->GetFirstSample();          unsigned long soughtfileno = file->pWavePoolTableHi[WavePoolTableIndex];
1630            Sample* sample = file->GetFirstSample(pProgress);
1631          while (sample) {          while (sample) {
1632              if (sample->ulWavePoolOffset == soughtoffset) return static_cast<gig::Sample*>(pSample = sample);              if (sample->ulWavePoolOffset == soughtoffset &&
1633                    sample->FileNo == soughtfileno) return static_cast<gig::Sample*>(pSample = sample);
1634              sample = file->GetNextSample();              sample = file->GetNextSample();
1635          }          }
1636          return NULL;          return NULL;
# Line 1552  namespace gig { namespace { Line 1641  namespace gig { namespace {
1641  // *************** Instrument ***************  // *************** Instrument ***************
1642  // *  // *
1643    
1644      Instrument::Instrument(File* pFile, RIFF::List* insList) : DLS::Instrument((DLS::File*)pFile, insList) {      Instrument::Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress) : DLS::Instrument((DLS::File*)pFile, insList) {
1645          // Initialization          // Initialization
1646          for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL;          for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL;
1647          RegionIndex = -1;          RegionIndex = -1;
# Line 1583  namespace gig { namespace { Line 1672  namespace gig { namespace {
1672          unsigned int iRegion = 0;          unsigned int iRegion = 0;
1673          while (rgn) {          while (rgn) {
1674              if (rgn->GetListType() == LIST_TYPE_RGN) {              if (rgn->GetListType() == LIST_TYPE_RGN) {
1675                    __notify_progress(pProgress, (float) iRegion / (float) Regions);
1676                  pRegions[iRegion] = new Region(this, rgn);                  pRegions[iRegion] = new Region(this, rgn);
1677                  iRegion++;                  iRegion++;
1678              }              }
# Line 1595  namespace gig { namespace { Line 1685  namespace gig { namespace {
1685                  RegionKeyTable[iKey] = pRegions[iReg];                  RegionKeyTable[iKey] = pRegions[iReg];
1686              }              }
1687          }          }
1688    
1689            __notify_progress(pProgress, 1.0f); // notify done
1690      }      }
1691    
1692      Instrument::~Instrument() {      Instrument::~Instrument() {
# Line 1681  namespace gig { namespace { Line 1773  namespace gig { namespace {
1773              pInstruments->clear();              pInstruments->clear();
1774              delete pInstruments;              delete pInstruments;
1775          }          }
1776            // free extension files
1777            for (std::list<RIFF::File*>::iterator i = ExtensionFiles.begin() ; i != ExtensionFiles.end() ; i++)
1778                delete *i;
1779      }      }
1780    
1781      Sample* File::GetFirstSample() {      Sample* File::GetFirstSample(progress_t* pProgress) {
1782          if (!pSamples) LoadSamples();          if (!pSamples) LoadSamples(pProgress);
1783          if (!pSamples) return NULL;          if (!pSamples) return NULL;
1784          SamplesIterator = pSamples->begin();          SamplesIterator = pSamples->begin();
1785          return static_cast<gig::Sample*>( (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL );          return static_cast<gig::Sample*>( (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL );
# Line 1696  namespace gig { namespace { Line 1791  namespace gig { namespace {
1791          return static_cast<gig::Sample*>( (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL );          return static_cast<gig::Sample*>( (SamplesIterator != pSamples->end()) ? *SamplesIterator : NULL );
1792      }      }
1793    
1794      void File::LoadSamples() {      void File::LoadSamples(progress_t* pProgress) {
1795          RIFF::List* wvpl = pRIFF->GetSubList(LIST_TYPE_WVPL);          RIFF::File* file = pRIFF;
1796          if (wvpl) {  
1797              unsigned long wvplFileOffset = wvpl->GetFilePos();          // just for progress calculation
1798              RIFF::List* wave = wvpl->GetFirstSubList();          int iSampleIndex  = 0;
1799              while (wave) {          int iTotalSamples = WavePoolCount;
1800                  if (wave->GetListType() == LIST_TYPE_WAVE) {  
1801                      if (!pSamples) pSamples = new SampleList;          // check if samples should be loaded from extension files
1802                      unsigned long waveFileOffset = wave->GetFilePos();          int lastFileNo = 0;
1803                      pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset));          for (int i = 0 ; i < WavePoolCount ; i++) {
1804                if (pWavePoolTableHi[i] > lastFileNo) lastFileNo = pWavePoolTableHi[i];
1805            }
1806            String name(pRIFF->Filename);
1807            int nameLen = pRIFF->Filename.length();
1808            char suffix[6];
1809            if (nameLen > 4 && pRIFF->Filename.substr(nameLen - 4) == ".gig") nameLen -= 4;
1810    
1811            for (int fileNo = 0 ; ; ) {
1812                RIFF::List* wvpl = file->GetSubList(LIST_TYPE_WVPL);
1813                if (wvpl) {
1814                    unsigned long wvplFileOffset = wvpl->GetFilePos();
1815                    RIFF::List* wave = wvpl->GetFirstSubList();
1816                    while (wave) {
1817                        if (wave->GetListType() == LIST_TYPE_WAVE) {
1818                            // notify current progress
1819                            const float subprogress = (float) iSampleIndex / (float) iTotalSamples;
1820                            __notify_progress(pProgress, subprogress);
1821    
1822                            if (!pSamples) pSamples = new SampleList;
1823                            unsigned long waveFileOffset = wave->GetFilePos();
1824                            pSamples->push_back(new Sample(this, wave, waveFileOffset - wvplFileOffset, fileNo));
1825    
1826                            iSampleIndex++;
1827                        }
1828                        wave = wvpl->GetNextSubList();
1829                  }                  }
1830                  wave = wvpl->GetNextSubList();  
1831                    if (fileNo == lastFileNo) break;
1832    
1833                    // open extension file (*.gx01, *.gx02, ...)
1834                    fileNo++;
1835                    sprintf(suffix, ".gx%02d", fileNo);
1836                    name.replace(nameLen, 5, suffix);
1837                    file = new RIFF::File(name);
1838                    ExtensionFiles.push_back(file);
1839              }              }
1840                else throw gig::Exception("Mandatory <wvpl> chunk not found.");
1841          }          }
1842          else throw gig::Exception("Mandatory <wvpl> chunk not found.");  
1843            __notify_progress(pProgress, 1.0); // notify done
1844      }      }
1845    
1846      Instrument* File::GetFirstInstrument() {      Instrument* File::GetFirstInstrument() {
# Line 1729  namespace gig { namespace { Line 1859  namespace gig { namespace {
1859      /**      /**
1860       * Returns the instrument with the given index.       * Returns the instrument with the given index.
1861       *       *
1862         * @param index     - number of the sought instrument (0..n)
1863         * @param pProgress - optional: callback function for progress notification
1864       * @returns  sought instrument or NULL if there's no such instrument       * @returns  sought instrument or NULL if there's no such instrument
1865       */       */
1866      Instrument* File::GetInstrument(uint index) {      Instrument* File::GetInstrument(uint index, progress_t* pProgress) {
1867          if (!pInstruments) LoadInstruments();          if (!pInstruments) {
1868                // TODO: hack - we simply load ALL samples here, it would have been done in the Region constructor anyway (ATM)
1869    
1870                // sample loading subtask
1871                progress_t subprogress;
1872                __divide_progress(pProgress, &subprogress, 3.0f, 0.0f); // randomly schedule 33% for this subtask
1873                __notify_progress(&subprogress, 0.0f);
1874                GetFirstSample(&subprogress); // now force all samples to be loaded
1875                __notify_progress(&subprogress, 1.0f);
1876    
1877                // instrument loading subtask
1878                if (pProgress && pProgress->callback) {
1879                    subprogress.__range_min = subprogress.__range_max;
1880                    subprogress.__range_max = pProgress->__range_max; // schedule remaining percentage for this subtask
1881                }
1882                __notify_progress(&subprogress, 0.0f);
1883                LoadInstruments(&subprogress);
1884                __notify_progress(&subprogress, 1.0f);
1885            }
1886          if (!pInstruments) return NULL;          if (!pInstruments) return NULL;
1887          InstrumentsIterator = pInstruments->begin();          InstrumentsIterator = pInstruments->begin();
1888          for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) {          for (uint i = 0; InstrumentsIterator != pInstruments->end(); i++) {
# Line 1742  namespace gig { namespace { Line 1892  namespace gig { namespace {
1892          return NULL;          return NULL;
1893      }      }
1894    
1895      void File::LoadInstruments() {      void File::LoadInstruments(progress_t* pProgress) {
1896          RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);          RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS);
1897          if (lstInstruments) {          if (lstInstruments) {
1898                int iInstrumentIndex = 0;
1899              RIFF::List* lstInstr = lstInstruments->GetFirstSubList();              RIFF::List* lstInstr = lstInstruments->GetFirstSubList();
1900              while (lstInstr) {              while (lstInstr) {
1901                  if (lstInstr->GetListType() == LIST_TYPE_INS) {                  if (lstInstr->GetListType() == LIST_TYPE_INS) {
1902                        // notify current progress
1903                        const float localProgress = (float) iInstrumentIndex / (float) Instruments;
1904                        __notify_progress(pProgress, localProgress);
1905    
1906                        // divide local progress into subprogress for loading current Instrument
1907                        progress_t subprogress;
1908                        __divide_progress(pProgress, &subprogress, Instruments, iInstrumentIndex);
1909    
1910                      if (!pInstruments) pInstruments = new InstrumentList;                      if (!pInstruments) pInstruments = new InstrumentList;
1911                      pInstruments->push_back(new Instrument(this, lstInstr));                      pInstruments->push_back(new Instrument(this, lstInstr, &subprogress));
1912    
1913                        iInstrumentIndex++;
1914                  }                  }
1915                  lstInstr = lstInstruments->GetNextSubList();                  lstInstr = lstInstruments->GetNextSubList();
1916              }              }
1917                __notify_progress(pProgress, 1.0); // notify done
1918          }          }
1919          else throw gig::Exception("Mandatory <lins> list chunk not found.");          else throw gig::Exception("Mandatory <lins> list chunk not found.");
1920      }      }
# Line 1769  namespace gig { namespace { Line 1931  namespace gig { namespace {
1931          std::cout << "gig::Exception: " << Message << std::endl;          std::cout << "gig::Exception: " << Message << std::endl;
1932      }      }
1933    
1934    
1935    // *************** functions ***************
1936    // *
1937    
1938        /**
1939         * Returns the name of this C++ library. This is usually "libgig" of
1940         * course. This call is equivalent to RIFF::libraryName() and
1941         * DLS::libraryName().
1942         */
1943        String libraryName() {
1944            return PACKAGE;
1945        }
1946    
1947        /**
1948         * Returns version of this C++ library. This call is equivalent to
1949         * RIFF::libraryVersion() and DLS::libraryVersion().
1950         */
1951        String libraryVersion() {
1952            return VERSION;
1953        }
1954    
1955  } // namespace gig  } // namespace gig

Legend:
Removed from v.406  
changed lines
  Added in v.728

  ViewVC Help
Powered by ViewVC