/[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 3112 by schoenebeck, Wed Feb 15 13:21:31 2017 UTC revision 3324 by schoenebeck, Fri Jul 21 13:05:39 2017 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-2016 by Christian Schoenebeck                      *   *   Copyright (C) 2003-2017 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 24  Line 24 
24  #include "gig.h"  #include "gig.h"
25    
26  #include "helper.h"  #include "helper.h"
27    #include "Serialization.h"
28    
29  #include <algorithm>  #include <algorithm>
30  #include <math.h>  #include <math.h>
# Line 55  Line 56 
56  #define GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(x)    ((x & 0x03) << 3)  #define GIG_EG_CTR_DECAY_INFLUENCE_ENCODE(x)    ((x & 0x03) << 3)
57  #define GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(x)  ((x & 0x03) << 5)  #define GIG_EG_CTR_RELEASE_INFLUENCE_ENCODE(x)  ((x & 0x03) << 5)
58    
59    #define SRLZ(member) \
60        archive->serializeMember(*this, member, #member);
61    
62  namespace gig {  namespace gig {
63    
64  // *************** Internal functions for sample decompression ***************  // *************** Internal functions for sample decompression ***************
# Line 269  namespace { Line 273  namespace {
273       * steps.       * steps.
274       *       *
275       * Once the whole data was processed by __calculateCRC(), one should       * Once the whole data was processed by __calculateCRC(), one should
276       * call __encodeCRC() to get the final CRC result.       * call __finalizeCRC() to get the final CRC result.
277       *       *
278       * @param buf     - pointer to data the CRC shall be calculated of       * @param buf     - pointer to data the CRC shall be calculated of
279       * @param bufSize - size of the data to be processed       * @param bufSize - size of the data to be processed
# Line 286  namespace { Line 290  namespace {
290       *       *
291       * @param crc - variable previously passed to __calculateCRC()       * @param crc - variable previously passed to __calculateCRC()
292       */       */
293      inline static uint32_t __encodeCRC(const uint32_t& crc) {      inline static void __finalizeCRC(uint32_t& crc) {
294          return crc ^ 0xffffffff;          crc ^= 0xffffffff;
295      }      }
296    
297    
# Line 315  namespace { Line 319  namespace {
319    
320    
321    
322    // *************** leverage_ctrl_t ***************
323    // *
324    
325        void leverage_ctrl_t::serialize(Serialization::Archive* archive) {
326            SRLZ(type);
327            SRLZ(controller_number);
328        }
329    
330    
331    
332    // *************** crossfade_t ***************
333    // *
334    
335        void crossfade_t::serialize(Serialization::Archive* archive) {
336            SRLZ(in_start);
337            SRLZ(in_end);
338            SRLZ(out_start);
339            SRLZ(out_end);
340        }
341    
342    
343    
344    // *************** eg_opt_t ***************
345    // *
346    
347        eg_opt_t::eg_opt_t() {
348            AttackCancel     = true;
349            AttackHoldCancel = true;
350            Decay1Cancel     = true;
351            Decay2Cancel     = true;
352            ReleaseCancel    = true;
353        }
354    
355        void eg_opt_t::serialize(Serialization::Archive* archive) {
356            SRLZ(AttackCancel);
357            SRLZ(AttackHoldCancel);
358            SRLZ(Decay1Cancel);
359            SRLZ(Decay2Cancel);
360            SRLZ(ReleaseCancel);
361        }
362    
363    
364    
365  // *************** Sample ***************  // *************** Sample ***************
366  // *  // *
367    
# Line 1294  namespace { Line 1341  namespace {
1341          // if this is the last write, update the checksum chunk in the          // if this is the last write, update the checksum chunk in the
1342          // file          // file
1343          if (pCkData->GetPos() == pCkData->GetSize()) {          if (pCkData->GetPos() == pCkData->GetSize()) {
1344                __finalizeCRC(crc);
1345              File* pFile = static_cast<File*>(GetParent());              File* pFile = static_cast<File*>(GetParent());
1346              pFile->SetSampleChecksum(this, __encodeCRC(crc));              pFile->SetSampleChecksum(this, crc);
1347          }          }
1348          return res;          return res;
1349      }      }
# Line 1416  namespace { Line 1464  namespace {
1464              if (nRead <= 0) break;              if (nRead <= 0) break;
1465              __calculateCRC(&buffer[0], nRead * FrameSize, crc);              __calculateCRC(&buffer[0], nRead * FrameSize, crc);
1466          }          }
1467          __encodeCRC(crc);          __finalizeCRC(crc);
1468          return crc;          return crc;
1469      }      }
1470    
# Line 1684  namespace { Line 1732  namespace {
1732              VCFType                         = vcf_type_lowpass;              VCFType                         = vcf_type_lowpass;
1733              memset(DimensionUpperLimits, 127, 8);              memset(DimensionUpperLimits, 127, 8);
1734          }          }
1735            // format extension for EG behavior options, these will *NOT* work with
1736            // Gigasampler/GigaStudio !
1737            RIFF::Chunk* lsde = _3ewl->GetSubChunk(CHUNK_ID_LSDE);
1738            if (lsde) {
1739                unsigned char byte = lsde->ReadUint8();
1740                EGOptions.AttackCancel     = byte & 1;
1741                EGOptions.AttackHoldCancel = byte & (1 << 1);
1742                EGOptions.Decay1Cancel     = byte & (1 << 2);
1743                EGOptions.Decay2Cancel     = byte & (1 << 3);
1744                EGOptions.ReleaseCancel    = byte & (1 << 4);
1745            }
1746    
1747          pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve,          pVelocityAttenuationTable = GetVelocityTable(VelocityResponseCurve,
1748                                                       VelocityResponseDepth,                                                       VelocityResponseDepth,
# Line 1789  namespace { Line 1848  namespace {
1848          }          }
1849      }      }
1850    
1851        void DimensionRegion::serialize(Serialization::Archive* archive) {
1852            // in case this class will become backward incompatible one day,
1853            // then set a version and minimum version for this class like:
1854            //archive->setVersion(*this, 2);
1855            //archive->setMinVersion(*this, 1);
1856    
1857            SRLZ(VelocityUpperLimit);
1858            SRLZ(EG1PreAttack);
1859            SRLZ(EG1Attack);
1860            SRLZ(EG1Decay1);
1861            SRLZ(EG1Decay2);
1862            SRLZ(EG1InfiniteSustain);
1863            SRLZ(EG1Sustain);
1864            SRLZ(EG1Release);
1865            SRLZ(EG1Hold);
1866            SRLZ(EG1Controller);
1867            SRLZ(EG1ControllerInvert);
1868            SRLZ(EG1ControllerAttackInfluence);
1869            SRLZ(EG1ControllerDecayInfluence);
1870            SRLZ(EG1ControllerReleaseInfluence);
1871            SRLZ(LFO1Frequency);
1872            SRLZ(LFO1InternalDepth);
1873            SRLZ(LFO1ControlDepth);
1874            SRLZ(LFO1Controller);
1875            SRLZ(LFO1FlipPhase);
1876            SRLZ(LFO1Sync);
1877            SRLZ(EG2PreAttack);
1878            SRLZ(EG2Attack);
1879            SRLZ(EG2Decay1);
1880            SRLZ(EG2Decay2);
1881            SRLZ(EG2InfiniteSustain);
1882            SRLZ(EG2Sustain);
1883            SRLZ(EG2Release);
1884            SRLZ(EG2Controller);
1885            SRLZ(EG2ControllerInvert);
1886            SRLZ(EG2ControllerAttackInfluence);
1887            SRLZ(EG2ControllerDecayInfluence);
1888            SRLZ(EG2ControllerReleaseInfluence);
1889            SRLZ(LFO2Frequency);
1890            SRLZ(LFO2InternalDepth);
1891            SRLZ(LFO2ControlDepth);
1892            SRLZ(LFO2Controller);
1893            SRLZ(LFO2FlipPhase);
1894            SRLZ(LFO2Sync);
1895            SRLZ(EG3Attack);
1896            SRLZ(EG3Depth);
1897            SRLZ(LFO3Frequency);
1898            SRLZ(LFO3InternalDepth);
1899            SRLZ(LFO3ControlDepth);
1900            SRLZ(LFO3Controller);
1901            SRLZ(LFO3Sync);
1902            SRLZ(VCFEnabled);
1903            SRLZ(VCFType);
1904            SRLZ(VCFCutoffController);
1905            SRLZ(VCFCutoffControllerInvert);
1906            SRLZ(VCFCutoff);
1907            SRLZ(VCFVelocityCurve);
1908            SRLZ(VCFVelocityScale);
1909            SRLZ(VCFVelocityDynamicRange);
1910            SRLZ(VCFResonance);
1911            SRLZ(VCFResonanceDynamic);
1912            SRLZ(VCFResonanceController);
1913            SRLZ(VCFKeyboardTracking);
1914            SRLZ(VCFKeyboardTrackingBreakpoint);
1915            SRLZ(VelocityResponseCurve);
1916            SRLZ(VelocityResponseDepth);
1917            SRLZ(VelocityResponseCurveScaling);
1918            SRLZ(ReleaseVelocityResponseCurve);
1919            SRLZ(ReleaseVelocityResponseDepth);
1920            SRLZ(ReleaseTriggerDecay);
1921            SRLZ(Crossfade);
1922            SRLZ(PitchTrack);
1923            SRLZ(DimensionBypass);
1924            SRLZ(Pan);
1925            SRLZ(SelfMask);
1926            SRLZ(AttenuationController);
1927            SRLZ(InvertAttenuationController);
1928            SRLZ(AttenuationControllerThreshold);
1929            SRLZ(ChannelOffset);
1930            SRLZ(SustainDefeat);
1931            SRLZ(MSDecode);
1932            //SRLZ(SampleStartOffset);
1933            SRLZ(SampleAttenuation);
1934            SRLZ(EGOptions);
1935    
1936            // derived attributes from DLS::Sampler
1937            SRLZ(FineTune);
1938            SRLZ(Gain);
1939        }
1940    
1941      /**      /**
1942       * Updates the respective member variable and updates @c SampleAttenuation       * Updates the respective member variable and updates @c SampleAttenuation
1943       * which depends on this value.       * which depends on this value.
# Line 2089  namespace { Line 2238  namespace {
2238          if (chunksize >= 148) {          if (chunksize >= 148) {
2239              memcpy(&pData[140], DimensionUpperLimits, 8);              memcpy(&pData[140], DimensionUpperLimits, 8);
2240          }          }
2241    
2242            // format extension for EG behavior options, these will *NOT* work with
2243            // Gigasampler/GigaStudio !
2244            RIFF::Chunk* lsde = pParentList->GetSubChunk(CHUNK_ID_LSDE);
2245            if (!lsde) {
2246                // only add this "LSDE" chunk if the EG options do not match the
2247                // default EG behavior
2248                eg_opt_t defaultOpt;
2249                if (memcmp(&EGOptions, &defaultOpt, sizeof(eg_opt_t))) {
2250                    lsde = pParentList->AddSubChunk(CHUNK_ID_LSDE, 1);
2251                    // move LSDE chunk to the end of parent list
2252                    pParentList->MoveSubChunk(lsde, (RIFF::Chunk*)NULL);
2253                }
2254            }
2255            if (lsde) {
2256                unsigned char* pByte = (unsigned char*) lsde->LoadChunkData();
2257                *pByte =
2258                    (EGOptions.AttackCancel     ? 1 : 0) |
2259                    (EGOptions.AttackHoldCancel ? (1<<1) : 0) |
2260                    (EGOptions.Decay1Cancel     ? (1<<2) : 0) |
2261                    (EGOptions.Decay2Cancel     ? (1<<3) : 0) |
2262                    (EGOptions.ReleaseCancel    ? (1<<4) : 0);
2263            }
2264      }      }
2265    
2266      double* DimensionRegion::GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth) {      double* DimensionRegion::GetReleaseVelocityTable(curve_type_t releaseVelocityResponseCurve, uint8_t releaseVelocityResponseDepth) {
# Line 2503  namespace { Line 2675  namespace {
2675    
2676              // unknown controller type              // unknown controller type
2677              default:              default:
2678                  throw gig::Exception("Unknown leverage controller type.");                  decodedcontroller.type = leverage_ctrl_t::type_none;
2679                    decodedcontroller.controller_number = 0;
2680                    printf("Warning: Unknown leverage controller type (0x%x).\n", EncodedController);
2681                    break;
2682          }          }
2683          return decodedcontroller;          return decodedcontroller;
2684      }      }
# Line 4246  namespace { Line 4421  namespace {
4421          // recalculate CRC32 check sum          // recalculate CRC32 check sum
4422          __resetCRC(crc);          __resetCRC(crc);
4423          __calculateCRC(&data[0], data.size(), crc);          __calculateCRC(&data[0], data.size(), crc);
4424          __encodeCRC(crc);          __finalizeCRC(crc);
4425          // make sure chunk exists and has the required size          // make sure chunk exists and has the required size
4426          const file_offset_t chunkSize = (file_offset_t) 7*sizeof(int32_t) + Name.size() + data.size();          const file_offset_t chunkSize = (file_offset_t) 7*sizeof(int32_t) + Name.size() + data.size();
4427          if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize);          if (!pChunk) pChunk = pGroup->pList->AddSubChunk(CHUNK_ID_SCRI, chunkSize);
# Line 4297  namespace { Line 4472  namespace {
4472          return pGroup;          return pGroup;
4473      }      }
4474    
4475        /**
4476         * Make a (semi) deep copy of the Script object given by @a orig
4477         * and assign it to this object. Note: the ScriptGroup this Script
4478         * object belongs to remains untouched by this call.
4479         *
4480         * @param orig - original Script object to be copied from
4481         */
4482        void Script::CopyAssign(const Script* orig) {
4483            Name        = orig->Name;
4484            Compression = orig->Compression;
4485            Encoding    = orig->Encoding;
4486            Language    = orig->Language;
4487            Bypass      = orig->Bypass;
4488            data        = orig->data;
4489        }
4490    
4491      void Script::RemoveAllScriptReferences() {      void Script::RemoveAllScriptReferences() {
4492          File* pFile = pGroup->pFile;          File* pFile = pGroup->pFile;
4493          for (int i = 0; pFile->GetInstrument(i); ++i) {          for (int i = 0; pFile->GetInstrument(i); ++i) {
# Line 5612  namespace { Line 5803  namespace {
5803              mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s);              mGroups[pFile->GetSample(i)->GetGroup()]->AddSample(s);
5804              mSamples[pFile->GetSample(i)] = s;              mSamples[pFile->GetSample(i)] = s;
5805          }          }
5806            
5807            // clone script groups and their scripts
5808            for (int iGroup = 0; pFile->GetScriptGroup(iGroup); ++iGroup) {
5809                ScriptGroup* sg = pFile->GetScriptGroup(iGroup);
5810                ScriptGroup* dg = AddScriptGroup();
5811                dg->Name = "COPY" + ToString(iCallCount) + "_" + sg->Name;
5812                for (int iScript = 0; sg->GetScript(iScript); ++iScript) {
5813                    Script* ss = sg->GetScript(iScript);
5814                    Script* ds = dg->AddScript();
5815                    ds->CopyAssign(ss);
5816                }
5817            }
5818    
5819          //BUG: For some reason this method only works with this additional          //BUG: For some reason this method only works with this additional
5820          //     Save() call in between here.          //     Save() call in between here.
5821          //          //
# Line 6329  namespace { Line 6532  namespace {
6532  // *************** Exception ***************  // *************** Exception ***************
6533  // *  // *
6534    
6535      Exception::Exception(String Message) : DLS::Exception(Message) {      Exception::Exception() : DLS::Exception() {
6536        }
6537    
6538        Exception::Exception(String format, ...) : DLS::Exception() {
6539            va_list arg;
6540            va_start(arg, format);
6541            Message = assemble(format, arg);
6542            va_end(arg);
6543        }
6544    
6545        Exception::Exception(String format, va_list arg) : DLS::Exception() {
6546            Message = assemble(format, arg);
6547      }      }
6548    
6549      void Exception::PrintMessage() {      void Exception::PrintMessage() {

Legend:
Removed from v.3112  
changed lines
  Added in v.3324

  ViewVC Help
Powered by ViewVC