--- libgig/trunk/src/gig.cpp 2007/05/12 11:25:04 1179 +++ libgig/trunk/src/gig.cpp 2007/05/17 17:24:26 1195 @@ -303,7 +303,11 @@ * is located, 0 otherwise */ Sample::Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo) : DLS::Sample((DLS::File*) pFile, waveList, WavePoolOffset) { - pInfo->UseFixedLengthStrings = true; + static const DLS::Info::FixedStringLength fixedStringLengths[] = { + { CHUNK_ID_INAM, 64 }, + { 0, 0 } + }; + pInfo->FixedStringLengths = fixedStringLengths; Instances++; FileNo = fileNo; @@ -340,9 +344,11 @@ SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); MIDIUnityNote = 64; FineTune = 0; + SMPTEFormat = smpte_format_no_offset; SMPTEOffset = 0; Loops = 0; LoopID = 0; + LoopType = loop_type_normal; LoopStart = 0; LoopEnd = 0; LoopFraction = 0; @@ -398,7 +404,10 @@ // make sure 'smpl' chunk exists pCkSmpl = pWaveList->GetSubChunk(CHUNK_ID_SMPL); - if (!pCkSmpl) pCkSmpl = pWaveList->AddSubChunk(CHUNK_ID_SMPL, 60); + if (!pCkSmpl) { + pCkSmpl = pWaveList->AddSubChunk(CHUNK_ID_SMPL, 60); + memset(pCkSmpl->LoadChunkData(), 0, 60); + } // update 'smpl' chunk uint8_t* pData = (uint8_t*) pCkSmpl->LoadChunkData(); SamplePeriod = uint32_t(1000000000.0 / SamplesPerSecond + 0.5); @@ -1503,7 +1512,7 @@ // update '3ewa' chunk with DimensionRegion's current settings - const uint32_t chunksize = _3ewa->GetSize(); + const uint32_t chunksize = _3ewa->GetNewSize(); store32(&pData[0], chunksize); // unknown, always chunk size? const int32_t lfo3freq = (int32_t) GIG_EXP_ENCODE(LFO3Frequency); @@ -1987,6 +1996,7 @@ default: throw gig::Exception("leverage controller number is not supported by the gig format"); } + break; default: throw gig::Exception("Unknown leverage controller type."); } @@ -2104,8 +2114,6 @@ // * Region::Region(Instrument* pInstrument, RIFF::List* rgnList) : DLS::Region((DLS::Instrument*) pInstrument, rgnList) { - pInfo->UseFixedLengthStrings = true; - // Initialization Dimensions = 0; for (int i = 0; i < 256; i++) { @@ -2168,6 +2176,11 @@ GetSample(); // load global region sample reference } else { DimensionRegions = 0; + for (int i = 0 ; i < 8 ; i++) { + pDimensionDefinitions[i].dimension = dimension_none; + pDimensionDefinitions[i].bits = 0; + pDimensionDefinitions[i].zones = 0; + } } // make sure there is at least one dimension region @@ -2213,6 +2226,10 @@ if (!_3lnk) { const int _3lnkChunkSize = (pFile->pVersion && pFile->pVersion->major == 3) ? 1092 : 172; _3lnk = pCkRegion->AddSubChunk(CHUNK_ID_3LNK, _3lnkChunkSize); + memset(_3lnk->LoadChunkData(), 0, _3lnkChunkSize); + + // move 3prg to last position + pCkRegion->MoveSubChunk(pCkRegion->GetSubList(LIST_TYPE_3PRG), 0); } // update dimension definitions in '3lnk' chunk @@ -2379,7 +2396,8 @@ // create new dimension region(s) for this new dimension for (int i = 1 << iCurrentBits; i < 1 << iNewBits; i++) { //TODO: maybe we should copy existing dimension regions if possible instead of simply creating new ones with default values - RIFF::List* pNewDimRgnListChunk = pCkRegion->AddSubList(LIST_TYPE_3EWL); + RIFF::List* _3prg = pCkRegion->GetSubList(LIST_TYPE_3PRG); + RIFF::List* pNewDimRgnListChunk = _3prg->AddSubList(LIST_TYPE_3EWL); pDimensionRegions[i] = new DimensionRegion(pNewDimRgnListChunk); DimensionRegions++; } @@ -2592,10 +2610,22 @@ // * Instrument::Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress) : DLS::Instrument((DLS::File*)pFile, insList) { - pInfo->UseFixedLengthStrings = true; + static const DLS::Info::FixedStringLength fixedStringLengths[] = { + { CHUNK_ID_INAM, 64 }, + { CHUNK_ID_ISFT, 12 }, + { 0, 0 } + }; + pInfo->FixedStringLengths = fixedStringLengths; // Initialization for (int i = 0; i < 128; i++) RegionKeyTable[i] = NULL; + EffectSend = 0; + Attenuation = 0; + FineTune = 0; + PitchbendRange = 0; + PianoReleaseMode = false; + DimensionKeyRange.low = 0; + DimensionKeyRange.high = 0; // Loading RIFF::List* lart = insList->GetSubList(LIST_TYPE_LART); @@ -2783,9 +2813,12 @@ void Group::UpdateChunks() { // make sure <3gri> and <3gnl> list chunks exist RIFF::List* _3gri = pFile->pRIFF->GetSubList(LIST_TYPE_3GRI); - if (!_3gri) _3gri = pFile->pRIFF->AddSubList(LIST_TYPE_3GRI); + if (!_3gri) { + _3gri = pFile->pRIFF->AddSubList(LIST_TYPE_3GRI); + pFile->pRIFF->MoveSubChunk(_3gri, pFile->pRIFF->GetSubChunk(CHUNK_ID_PTBL)); + } RIFF::List* _3gnl = _3gri->GetSubList(LIST_TYPE_3GNL); - if (!_3gnl) _3gnl = pFile->pRIFF->AddSubList(LIST_TYPE_3GNL); + if (!_3gnl) _3gnl = _3gri->AddSubList(LIST_TYPE_3GNL); // now store the name of this group as <3gnm> chunk as subchunk of the <3gnl> list chunk ::SaveString(CHUNK_ID_3GNM, pNameChunk, _3gnl, Name, String("Unnamed Group"), true, 64); } @@ -2861,14 +2894,41 @@ // *************** File *************** // * + const DLS::Info::FixedStringLength File::FixedStringLengths[] = { + { CHUNK_ID_IARL, 256 }, + { CHUNK_ID_IART, 128 }, + { CHUNK_ID_ICMS, 128 }, + { CHUNK_ID_ICMT, 1024 }, + { CHUNK_ID_ICOP, 128 }, + { CHUNK_ID_ICRD, 128 }, + { CHUNK_ID_IENG, 128 }, + { CHUNK_ID_IGNR, 128 }, + { CHUNK_ID_IKEY, 128 }, + { CHUNK_ID_IMED, 128 }, + { CHUNK_ID_INAM, 128 }, + { CHUNK_ID_IPRD, 128 }, + { CHUNK_ID_ISBJ, 128 }, + { CHUNK_ID_ISFT, 128 }, + { CHUNK_ID_ISRC, 128 }, + { CHUNK_ID_ISRF, 128 }, + { CHUNK_ID_ITCH, 128 }, + { 0, 0 } + }; + File::File() : DLS::File() { pGroups = NULL; - pInfo->UseFixedLengthStrings = true; + pInfo->FixedStringLengths = FixedStringLengths; + pInfo->ArchivalLocation = String(256, ' '); + + // add some mandatory chunks to get the file chunks in right + // order (INFO chunk will be moved to first position later) + pRIFF->AddSubChunk(CHUNK_ID_VERS, 8); + pRIFF->AddSubChunk(CHUNK_ID_COLH, 4); } File::File(RIFF::File* pRIFF) : DLS::File(pRIFF) { pGroups = NULL; - pInfo->UseFixedLengthStrings = true; + pInfo->FixedStringLengths = FixedStringLengths; } File::~File() { @@ -2910,6 +2970,11 @@ // create new Sample object and its respective 'wave' list chunk RIFF::List* wave = wvpl->AddSubList(LIST_TYPE_WAVE); Sample* pSample = new Sample(this, wave, 0 /*arbitrary value, we update offsets when we save*/); + + // add mandatory chunks to get the chunks in right order + wave->AddSubChunk(CHUNK_ID_FMT, 16); + wave->AddSubList(LIST_TYPE_INFO); + pSamples->push_back(pSample); return pSample; } @@ -3052,7 +3117,17 @@ __ensureMandatoryChunksExist(); RIFF::List* lstInstruments = pRIFF->GetSubList(LIST_TYPE_LINS); RIFF::List* lstInstr = lstInstruments->AddSubList(LIST_TYPE_INS); + + // add mandatory chunks to get the chunks in right order + lstInstr->AddSubList(LIST_TYPE_INFO); + Instrument* pInstrument = new Instrument(this, lstInstr); + + lstInstr->AddSubChunk(CHUNK_ID_INSH, 12); + + // this string is needed for the gig to be loadable in GSt: + pInstrument->pInfo->Software = "Endless Wave"; + pInstruments->push_back(pInstrument); return pInstrument; } @@ -3220,9 +3295,21 @@ * @throws Exception - on errors */ void File::UpdateChunks() { + RIFF::Chunk* info = pRIFF->GetSubList(LIST_TYPE_INFO); + // first update base class's chunks DLS::File::UpdateChunks(); + if (!info) { + // INFO was added by Resource::UpdateChunks - make sure it + // is placed first in file + info = pRIFF->GetSubList(LIST_TYPE_INFO); + RIFF::Chunk* first = pRIFF->GetFirstSubChunk(); + if (first != info) { + pRIFF->MoveSubChunk(info, first); + } + } + // update group's chunks if (pGroups) { std::list::iterator iter = pGroups->begin();