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

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

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

revision 1184 by persson, Sun May 13 13:24:22 2007 UTC revision 1388 by persson, Sun Oct 7 11:10:02 2007 UTC
# Line 25  Line 25 
25    
26  #include <time.h>  #include <time.h>
27    
28    #ifdef __APPLE__
29    #include <CoreFoundation/CFUUID.h>
30    #elif defined(HAVE_UUID_UUID_H)
31    #include <uuid/uuid.h>
32    #endif
33    
34  #include "helper.h"  #include "helper.h"
35    
36  // macros to decode connection transforms  // macros to decode connection transforms
# Line 293  namespace DLS { Line 299  namespace DLS {
299              for (int i = 0 ; FixedStringLengths[i].length ; i++) {              for (int i = 0 ; FixedStringLengths[i].length ; i++) {
300                  if (FixedStringLengths[i].chunkId == ChunkID) {                  if (FixedStringLengths[i].chunkId == ChunkID) {
301                      size = FixedStringLengths[i].length;                      size = FixedStringLengths[i].length;
302                        break;
303                  }                  }
304              }              }
305          }          }
# Line 407  namespace DLS { Line 414  namespace DLS {
414       */       */
415      void Resource::UpdateChunks() {      void Resource::UpdateChunks() {
416          pInfo->UpdateChunks();          pInfo->UpdateChunks();
417          //TODO: save DLSID  
418            if (pDLSID) {
419                // make sure 'dlid' chunk exists
420                RIFF::Chunk* ckDLSID = pResourceList->GetSubChunk(CHUNK_ID_DLID);
421                if (!ckDLSID) ckDLSID = pResourceList->AddSubChunk(CHUNK_ID_DLID, 16);
422                uint8_t* pData = (uint8_t*)ckDLSID->LoadChunkData();
423                // update 'dlid' chunk
424                store32(&pData[0], pDLSID->ulData1);
425                store16(&pData[4], pDLSID->usData2);
426                store16(&pData[6], pDLSID->usData3);
427                memcpy(&pData[8], pDLSID->abData, 8);
428            }
429      }      }
430    
431        /**
432         * Generates a new DLSID for the resource.
433         */
434        void Resource::GenerateDLSID() {
435    #if defined(WIN32) || defined(__APPLE__) || defined(HAVE_UUID_GENERATE)
436    
437            if (!pDLSID) pDLSID = new dlsid_t;
438    
439    #ifdef WIN32
440    
441            UUID uuid;
442            UuidCreate(&uuid);
443            pDLSID->ulData1 = uuid.Data1;
444            pDLSID->usData2 = uuid.Data2;
445            pDLSID->usData3 = uuid.Data3;
446            memcpy(pDLSID->abData, uuid.Data4, 8);
447    
448    #elif defined(__APPLE__)
449    
450            CFUUIDRef uuidRef = CFUUIDCreate(NULL);
451            CFUUIDBytes uuid = CFUUIDGetUUIDBytes(uuidRef);
452            CFRelease(uuidRef);
453            pDLSID->ulData1 = uuid.byte0 | uuid.byte1 << 8 | uuid.byte2 << 16 | uuid.byte3 << 24;
454            pDLSID->usData2 = uuid.byte4 | uuid.byte5 << 8;
455            pDLSID->usData3 = uuid.byte6 | uuid.byte7 << 8;
456            pDLSID->abData[0] = uuid.byte8;
457            pDLSID->abData[1] = uuid.byte9;
458            pDLSID->abData[2] = uuid.byte10;
459            pDLSID->abData[3] = uuid.byte11;
460            pDLSID->abData[4] = uuid.byte12;
461            pDLSID->abData[5] = uuid.byte13;
462            pDLSID->abData[6] = uuid.byte14;
463            pDLSID->abData[7] = uuid.byte15;
464    #else
465            uuid_t uuid;
466            uuid_generate(uuid);
467            pDLSID->ulData1 = uuid[0] | uuid[1] << 8 | uuid[2] << 16 | uuid[3] << 24;
468            pDLSID->usData2 = uuid[4] | uuid[5] << 8;
469            pDLSID->usData3 = uuid[6] | uuid[7] << 8;
470            memcpy(pDLSID->abData, &uuid[8], 8);
471    #endif
472    #endif
473        }
474    
475    
476  // *************** Sampler ***************  // *************** Sampler ***************
# Line 426  namespace DLS { Line 487  namespace DLS {
487              SamplerOptions = wsmp->ReadUint32();              SamplerOptions = wsmp->ReadUint32();
488              SampleLoops    = wsmp->ReadUint32();              SampleLoops    = wsmp->ReadUint32();
489          } else { // 'wsmp' chunk missing          } else { // 'wsmp' chunk missing
490              uiHeaderSize   = 0;              uiHeaderSize   = 20;
491              UnityNote      = 64;              UnityNote      = 60;
492              FineTune       = 0; // +- 0 cents              FineTune       = 0; // +- 0 cents
493              Gain           = 0; // 0 dB              Gain           = 0; // 0 dB
494              SamplerOptions = F_WSMP_NO_COMPRESSION;              SamplerOptions = F_WSMP_NO_COMPRESSION;
# Line 451  namespace DLS { Line 512  namespace DLS {
512          if (pSampleLoops) delete[] pSampleLoops;          if (pSampleLoops) delete[] pSampleLoops;
513      }      }
514    
515        void Sampler::SetGain(int32_t gain) {
516            Gain = gain;
517        }
518    
519      /**      /**
520       * Apply all sample player options to the respective RIFF chunk. You       * Apply all sample player options to the respective RIFF chunk. You
521       * have to call File::Save() to make changes persistent.       * have to call File::Save() to make changes persistent.
# Line 458  namespace DLS { Line 523  namespace DLS {
523      void Sampler::UpdateChunks() {      void Sampler::UpdateChunks() {
524          // make sure 'wsmp' chunk exists          // make sure 'wsmp' chunk exists
525          RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP);          RIFF::Chunk* wsmp = pParentList->GetSubChunk(CHUNK_ID_WSMP);
526            int wsmpSize = uiHeaderSize + SampleLoops * 16;
527          if (!wsmp) {          if (!wsmp) {
528              uiHeaderSize = 20;              wsmp = pParentList->AddSubChunk(CHUNK_ID_WSMP, wsmpSize);
529              wsmp = pParentList->AddSubChunk(CHUNK_ID_WSMP, uiHeaderSize + SampleLoops * 16);          } else if (wsmp->GetSize() != wsmpSize) {
530                wsmp->Resize(wsmpSize);
531          }          }
532          uint8_t* pData = (uint8_t*) wsmp->LoadChunkData();          uint8_t* pData = (uint8_t*) wsmp->LoadChunkData();
533          // update headers size          // update headers size
# Line 488  namespace DLS { Line 555  namespace DLS {
555      /**      /**
556       * Adds a new sample loop with the provided loop definition.       * Adds a new sample loop with the provided loop definition.
557       *       *
558       * @param - points to a loop definition that is to be copied       * @param pLoopDef - points to a loop definition that is to be copied
559       */       */
560      void Sampler::AddSampleLoop(sample_loop_t* pLoopDef) {      void Sampler::AddSampleLoop(sample_loop_t* pLoopDef) {
561          sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops + 1];          sample_loop_t* pNewLoops = new sample_loop_t[SampleLoops + 1];
# Line 852  namespace DLS { Line 919  namespace DLS {
919      }      }
920    
921      /**      /**
922         * Modifies the key range of this Region and makes sure the respective
923         * chunks are in correct order.
924         *
925         * @param Low  - lower end of key range
926         * @param High - upper end of key range
927         */
928        void Region::SetKeyRange(uint16_t Low, uint16_t High) {
929            KeyRange.low  = Low;
930            KeyRange.high = High;
931    
932            // make sure regions are already loaded
933            Instrument* pInstrument = (Instrument*) GetParent();
934            if (!pInstrument->pRegions) pInstrument->LoadRegions();
935            if (!pInstrument->pRegions) return;
936    
937            // find the r which is the first one to the right of this region
938            // at its new position
939            Region* r = NULL;
940            Region* prev_region = NULL;
941            for (
942                Instrument::RegionList::iterator iter = pInstrument->pRegions->begin();
943                iter != pInstrument->pRegions->end(); iter++
944            ) {
945                if ((*iter)->KeyRange.low > this->KeyRange.low) {
946                    r = *iter;
947                    break;
948                }
949                prev_region = *iter;
950            }
951    
952            // place this region before r if it's not already there
953            if (prev_region != this) pInstrument->MoveRegion(this, r);
954        }
955    
956        /**
957       * Apply Region settings to the respective RIFF chunks. You have to       * Apply Region settings to the respective RIFF chunks. You have to
958       * call File::Save() to make changes persistent.       * call File::Save() to make changes persistent.
959       *       *
# Line 902  namespace DLS { Line 1004  namespace DLS {
1004                  }                  }
1005              }              }
1006          }          }
         if (index < 0) throw Exception("Could not save Region, could not find Region's sample");  
1007          WavePoolTableIndex = index;          WavePoolTableIndex = index;
1008          // update 'wlnk' chunk          // update 'wlnk' chunk
1009          store16(&pData[0], WaveLinkOptionFlags);          store16(&pData[0], WaveLinkOptionFlags);

Legend:
Removed from v.1184  
changed lines
  Added in v.1388

  ViewVC Help
Powered by ViewVC