--- libgig/trunk/src/gig.h 2005/11/22 11:26:55 809 +++ libgig/trunk/src/gig.h 2006/10/24 22:24:45 929 @@ -2,7 +2,7 @@ * * * libgig - C++ cross-platform Gigasampler format file loader library * * * - * Copyright (C) 2003-2005 by Christian Schoenebeck * + * Copyright (C) 2003-2006 by Christian Schoenebeck * * * * * * This library is free software; you can redistribute it and/or modify * @@ -29,21 +29,27 @@ #if WORDS_BIGENDIAN # define LIST_TYPE_3PRG 0x33707267 # define LIST_TYPE_3EWL 0x3365776C +# define LIST_TYPE_3GRI 0x33677269 +# define LIST_TYPE_3GNL 0x33676E6C # define CHUNK_ID_SMPL 0x736D706C # define CHUNK_ID_3GIX 0x33676978 # define CHUNK_ID_3EWA 0x33657761 # define CHUNK_ID_3LNK 0x336C6E6B # define CHUNK_ID_3EWG 0x33657767 # define CHUNK_ID_EWAV 0x65776176 +# define CHUNK_ID_3GNM 0x33676E6D #else // little endian # define LIST_TYPE_3PRG 0x67727033 # define LIST_TYPE_3EWL 0x6C776533 +# define LIST_TYPE_3GRI 0x69726733 +# define LIST_TYPE_3GNL 0x6C6E6733 # define CHUNK_ID_SMPL 0x6C706D73 # define CHUNK_ID_3GIX 0x78696733 # define CHUNK_ID_3EWA 0x61776533 # define CHUNK_ID_3LNK 0x6B6E6C33 # define CHUNK_ID_3EWG 0x67776533 # define CHUNK_ID_EWAV 0x76617765 +# define CHUNK_ID_3GNM 0x6D6E6733 #endif // WORDS_BIGENDIAN /** Gigasampler specific classes and definitions */ @@ -130,7 +136,7 @@ /** Defines how the filter cutoff frequency is controlled by. */ typedef enum { vcf_cutoff_ctrl_none = 0x00, - vcf_cutoff_ctrl_none2 = 0x01, ///< The difference betwheen none and none2 is unknown + vcf_cutoff_ctrl_none2 = 0x01, ///< The difference between none and none2 is unknown vcf_cutoff_ctrl_modwheel = 0x81, ///< Modulation Wheel (MIDI Controller 1) vcf_cutoff_ctrl_effect1 = 0x8c, ///< Effect Controller 1 (Coarse, MIDI Controller 12) vcf_cutoff_ctrl_effect2 = 0x8d, ///< Effect Controller 2 (Coarse, MIDI Controller 13) @@ -240,8 +246,7 @@ * into the corresponding dimension bit number. */ typedef enum { - split_type_normal, ///< dimension value between 0-127, no custom range of zones - split_type_customvelocity, ///< a velocity dimension split with custom range definition for each zone (if a velocity dimension split has no custom defined zone ranges then it's also just of type split_type_normal) + split_type_normal, ///< dimension value between 0-127 split_type_bit ///< dimension values are already the sought bit number } split_type_t; @@ -251,10 +256,7 @@ uint8_t bits; ///< Number of "bits" (1 bit = 2 splits/zones, 2 bit = 4 splits/zones, 3 bit = 8 splits/zones,...). uint8_t zones; ///< Number of zones the dimension has. split_type_t split_type; ///< Intended for internal usage: will be used to convert a dimension value into the corresponding dimension bit number. - range_t* ranges; ///< Intended for internal usage: Points to the beginning of a range_t array which reflects the value ranges of each dimension zone (only if custom defined ranges are defined, is NULL otherwise). float zone_size; ///< Intended for internal usage: reflects the size of each zone (128/zones) for normal split types only, 0 otherwise. - - dimension_def_t& operator=(const dimension_def_t& arg); }; /** Defines which frequencies are filtered by the VCF. */ @@ -320,6 +322,7 @@ class Instrument; class Sample; class Region; + class Group; /** Encapsulates articulation information of a dimension region. * @@ -434,6 +437,7 @@ // overridden methods virtual void UpdateChunks(); protected: + uint8_t* VelocityTable; ///< For velocity dimensions with custom defined zone ranges only: used for fast converting from velocity MIDI value to dimension bit number. DimensionRegion(RIFF::List* _3ewl); ~DimensionRegion(); friend class Region; @@ -492,7 +496,7 @@ */ class Sample : public DLS::Sample { public: - uint16_t SampleGroup; + Group* pGroup; ///< pointer to the Group this sample belongs to, NULL otherwise uint32_t Manufacturer; ///< Specifies the MIDI Manufacturer's Association (MMA) Manufacturer code for the sampler intended to receive this file's waveform. If no particular manufacturer is to be specified, a value of 0 should be used. uint32_t Product; ///< Specifies the MIDI model ID defined by the manufacturer corresponding to the Manufacturer field. If no particular manufacturer's product is to be specified, a value of 0 should be used. uint32_t SamplePeriod; ///< Specifies the duration of time that passes during the playback of one sample in nanoseconds (normally equal to 1 / Samples Per Second, where Samples Per Second is the value found in the format chunk), don't bother to update this attribute, it won't be saved. @@ -527,7 +531,7 @@ unsigned long SetPos(unsigned long SampleCount, RIFF::stream_whence_t Whence = RIFF::stream_start); unsigned long GetPos(); unsigned long Read(void* pBuffer, unsigned long SampleCount, buffer_t* pExternalDecompressionBuffer = NULL); - unsigned long ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, buffer_t* pExternalDecompressionBuffer = NULL); + unsigned long ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState, DimensionRegion* pDimRgn, buffer_t* pExternalDecompressionBuffer = NULL); unsigned long Write(void* pBuffer, unsigned long SampleCount); virtual void UpdateChunks(); protected: @@ -579,9 +583,9 @@ class Region : public DLS::Region { public: unsigned int Dimensions; ///< Number of defined dimensions, do not alter! - dimension_def_t pDimensionDefinitions[8]; ///< Defines the five (gig2) or eight (gig3) possible dimensions (the dimension's controller and number of bits/splits). Use AddDimension() and DeleteDimension() to create a new dimension ot delete an existing one. + dimension_def_t pDimensionDefinitions[8]; ///< Defines the five (gig2) or eight (gig3) possible dimensions (the dimension's controller and number of bits/splits). Use AddDimension() and DeleteDimension() to create a new dimension or delete an existing one. uint32_t DimensionRegions; ///< Total number of DimensionRegions this Region contains, do not alter! - DimensionRegion* pDimensionRegions[256]; ///< Pointer array to the 32 (gig2) or 256 (gig3) possible dimension regions (reflects NULL for dimension regions not in use). Avoid to access the array directly and better use GetDimensionRegionByValue() instead, but of course in some cases it makes sense to use the array (e.g. iterating through all DimensionRegions). Use AddDimension() and DeleteDimension() to create a new dimension ot delete an existing one (which will create or delete the respective dimension region(s) automatically). + DimensionRegion* pDimensionRegions[256]; ///< Pointer array to the 32 (gig2) or 256 (gig3) possible dimension regions (reflects NULL for dimension regions not in use). Avoid to access the array directly and better use GetDimensionRegionByValue() instead, but of course in some cases it makes sense to use the array (e.g. iterating through all DimensionRegions). Use AddDimension() and DeleteDimension() to create a new dimension or delete an existing one (which will create or delete the respective dimension region(s) automatically). unsigned int Layers; ///< Amount of defined layers (1 - 32). A value of 1 actually means no layering, a value > 1 means there is Layer dimension. The same information can of course also be obtained by accessing pDimensionDefinitions. Do not alter this value! DimensionRegion* GetDimensionRegionByValue(const uint DimValues[8]); @@ -591,14 +595,9 @@ void DeleteDimension(dimension_def_t* pDimDef); virtual void UpdateChunks(); protected: - typedef std::list DimensionList; - - uint8_t VelocityTable[128]; ///< For velocity dimensions with custom defined zone ranges only: used for fast converting from velocity MIDI value to dimension bit number. - DimensionList DimensionDefinitions; - Region(Instrument* pInstrument, RIFF::List* rgnList); void LoadDimensionRegions(RIFF::List* rgn); - void UpdateVelocityTable(dimension_def_t* pDimDef); + void UpdateVelocityTable(); Sample* GetSampleFromWavePool(unsigned int WavePoolTableIndex, progress_t* pProgress = NULL); ~Region(); friend class Instrument; @@ -637,9 +636,7 @@ // own methods Region* GetRegion(unsigned int Key); protected: - Region** pRegions; ///< Pointer array to the regions Region* RegionKeyTable[128]; ///< fast lookup for the corresponding Region of a MIDI key - int RegionIndex; Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress = NULL); ~Instrument(); @@ -647,7 +644,30 @@ friend class File; }; - // TODO: <3gnm> chunk not added yet (just contains the names of the sample groups) + /** @brief Group of Gigasampler objects + * + * Groups help to organize a huge collection of Gigasampler objects. + * Groups are not concerned at all for the synthesis, but they help + * sound library developers when working on complex instruments with an + * instrument editor (as long as that instrument editor supports it ;-). + * + * At the moment, it seems as only samples can be grouped together in + * the Gigasampler format yet. If this is false in the meantime, please + * tell us ! + */ + class Group { + public: + String Name; ///< Stores the name of this Group. + protected: + Group(RIFF::File* file, RIFF::Chunk* ck3gnm); + virtual ~Group(); + virtual void UpdateChunks(); + friend class File; + private: + RIFF::File* pFile; + RIFF::Chunk* pNameChunk; + }; + /** Parses Gigasampler files and provides abstract access to the data. */ class File : protected DLS::File { public: @@ -667,28 +687,32 @@ File(RIFF::File* pRIFF); Sample* GetFirstSample(progress_t* pProgress = NULL); ///< Returns a pointer to the first Sample object of the file, NULL otherwise. Sample* GetNextSample(); ///< Returns a pointer to the next Sample object of the file, NULL otherwise. - Instrument* GetFirstInstrument(); ///< Returns a pointer to the first Instrument object of the file, NULL otherwise. Sample* AddSample(); void DeleteSample(Sample* pSample); + Instrument* GetFirstInstrument(); ///< Returns a pointer to the first Instrument object of the file, NULL otherwise. Instrument* GetNextInstrument(); ///< Returns a pointer to the next Instrument object of the file, NULL otherwise. Instrument* GetInstrument(uint index, progress_t* pProgress = NULL); Instrument* AddInstrument(); void DeleteInstrument(Instrument* pInstrument); - ~File(); + Group* GetFirstGroup(); ///< Returns a pointer to the first Group object of the file, NULL otherwise. + Group* GetNextGroup(); ///< Returns a pointer to the next Group object of the file, NULL otherwise. + Group* GetGroup(uint index); + Group* AddGroup(); + void DeleteGroup(Group* pGroup); + virtual ~File(); protected: - typedef std::list SampleList; - typedef std::list InstrumentList; - - SampleList* pSamples; - SampleList::iterator SamplesIterator; - InstrumentList* pInstruments; - InstrumentList::iterator InstrumentsIterator; - - void LoadSamples(progress_t* pProgress = NULL); - void LoadInstruments(progress_t* pProgress = NULL); + // overridden protected methods from DLS::File + virtual void LoadSamples(); + virtual void LoadInstruments(); + virtual void LoadGroups(); + // own protected methods + virtual void LoadSamples(progress_t* pProgress); + virtual void LoadInstruments(progress_t* pProgress); friend class Region; - - std::list ExtensionFiles; + friend class Sample; + private: + std::list* pGroups; + std::list::iterator GroupsIterator; }; /** Will be thrown whenever a gig specific error occurs while trying to access a Gigasampler File. */