--- libgig/trunk/src/gig.h 2005/02/10 19:16:31 365 +++ libgig/trunk/src/gig.h 2005/07/26 11:13:53 728 @@ -2,8 +2,8 @@ * * * libgig - C++ cross-platform Gigasampler format file loader library * * * - * Copyright (C) 2003, 2004 by Christian Schoenebeck * - * * + * Copyright (C) 2003-2005 by Christian Schoenebeck * + * * * * * This library is free software; you can redistribute it and/or modify * * it under the terms of the GNU General Public License as published by * @@ -80,6 +80,11 @@ void* pStart; ///< Points to the beginning of the buffer. unsigned long Size; ///< Size of the actual data in the buffer in bytes. unsigned long NullExtensionSize; ///< The buffer might be bigger than the actual data, if that's the case that unused space at the end of the buffer is filled with NULLs and NullExtensionSize reflects that unused buffer space in bytes. Those NULL extensions are mandatory for differential algorithms that have to take the following data words into account, thus have to access past the buffer's boundary. If you don't know what I'm talking about, just forget this variable. :) + buffer_t() { + pStart = NULL; + Size = 0; + NullExtensionSize = 0; + } }; /** Standard types of sample loops. */ @@ -220,6 +225,8 @@ dimension_channelaftertouch = 0x83, ///< Channel Key Pressure dimension_releasetrigger = 0x84, ///< Special dimension for triggering samples on releasing a key. dimension_keyboard = 0x85, ///< Dimension for keyswitching + dimension_roundrobin = 0x86, ///< Different samples triggered each time a note is played, dimension regions selected in sequence + dimension_random = 0x87, ///< Different samples triggered each time a note is played, random order dimension_modwheel = 0x01, ///< Modulation Wheel (MIDI Controller 1) dimension_breath = 0x02, ///< Breath Controller (Coarse, MIDI Controller 2) dimension_foot = 0x04, ///< Foot Pedal (Coarse, MIDI Controller 4) @@ -302,6 +309,27 @@ unsigned long loop_cycles_left; ///< How many times the loop has still to be passed, this value will be decremented with each loop cycle. }; + /** + * @brief Used for indicating the progress of a certain task. + * + * The function pointer argument has to be supplied with a valid + * function of the given signature which will then be called on + * progress changes. An equivalent progress_t structure will be passed + * back as argument to the callback function on each progress change. + * The factor field of the supplied progress_t structure will then + * reflect the current progress as value between 0.0 and 1.0. You might + * want to use the custom field for data needed in your callback + * function. + */ + struct progress_t { + void (*callback)(progress_t*); ///< Callback function pointer which has to be assigned to a function for progress notification. + float factor; ///< Reflects current progress as value between 0.0 and 1.0. + void* custom; ///< This pointer can be used for arbitrary data. + float __range_min; ///< Only for internal usage, do not modify! + float __range_max; ///< Only for internal usage, do not modify! + progress_t(); + }; + // just symbol prototyping class File; class Instrument; @@ -375,9 +403,10 @@ bool VCFEnabled; ///< If filter should be used. vcf_type_t VCFType; ///< Defines the general filter characteristic (lowpass, highpass, bandpass, etc.). vcf_cutoff_ctrl_t VCFCutoffController; ///< Specifies which external controller has influence on the filter cutoff frequency. + bool VCFCutoffControllerInvert; ///< Inverts values coming from the defined cutoff controller uint8_t VCFCutoff; ///< Max. cutoff frequency. curve_type_t VCFVelocityCurve; ///< Defines a transformation curve for the incoming velocity values, affecting the VCF. - uint8_t VCFVelocityScale; ///< (0-127) Amount velocity controls VCF cutoff frequency (only if no other VCF cutoff controller is defined). + uint8_t VCFVelocityScale; ///< (0-127) Amount velocity controls VCF cutoff frequency (only if no other VCF cutoff controller is defined, otherwise this is the minimum cutoff). uint8_t VCFVelocityDynamicRange; ///< 0x04 = lowest, 0x00 = highest uint8_t VCFResonance; ///< Firm internal filter resonance weight. bool VCFResonanceDynamic; ///< If true: Increases the resonance Q according to changes of controllers that actually control the VCF cutoff frequency (EG2, ext. VCF MIDI controller). @@ -404,6 +433,8 @@ bool SustainDefeat; ///< If true: Sustain pedal will not hold a note. bool MSDecode; ///< Gigastudio flag: defines if Mid Side Recordings should be decoded. uint16_t SampleStartOffset; ///< Number of samples the sample start should be moved (0 - 2000). + double SampleAttenuation; ///< Sample volume (calculated from DLS::Sampler::Gain) + // derived attributes from DLS::Sampler DLS::Sampler::UnityNote; DLS::Sampler::FineTune; @@ -413,6 +444,9 @@ // Methods double GetVelocityAttenuation(uint8_t MIDIKeyVelocity); + double GetVelocityRelease(uint8_t MIDIKeyVelocity); + double GetVelocityCutoff(uint8_t MIDIKeyVelocity); + protected: DimensionRegion(RIFF::List* _3ewl); ~DimensionRegion(); @@ -451,8 +485,11 @@ static uint Instances; ///< Number of DimensionRegion instances. static VelocityTableMap* pVelocityTables; ///< Contains the tables corresponding to the various velocity parameters (VelocityResponseCurve and VelocityResponseDepth). double* pVelocityAttenuationTable; ///< Points to the velocity table corresponding to the velocity parameters of this DimensionRegion. + double* pVelocityReleaseTable; ///< Points to the velocity table corresponding to the release velocity parameters of this DimensionRegion + double* pVelocityCutoffTable; ///< Points to the velocity table corresponding to the filter velocity parameters of this DimensionRegion leverage_ctrl_t DecodeLeverageController(_lev_ctrl_t EncodedController); + double* GetVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling); double* CreateVelocityTable(curve_type_t curveType, uint8_t depth, uint8_t scaling); }; @@ -476,6 +513,8 @@ uint32_t LoopFraction; ///< The fractional value specifies a fraction of a sample at which to loop (only if Loops > 0). This allows a loop to be fine tuned at a resolution greater than one sample. A value of 0 means no fraction, a value of 0x80000000 means 1/2 of a sample length. 0xFFFFFFFF is the smallest fraction of a sample that can be represented. uint32_t LoopPlayCount; ///< Number of times the loop should be played (only if Loops > 0, a value of 0 = infinite). bool Compressed; ///< If the sample wave is compressed (probably just interesting for instrument and sample editors, as this library already handles the decompression in it's sample access methods anyway). + uint32_t TruncatedBits; ///< For 24-bit compressed samples only: number of bits truncated during compression (0, 4 or 6) + bool Dithered; ///< For 24-bit compressed samples only: if dithering was used during compression with bit reduction // own methods buffer_t LoadSampleData(); @@ -483,16 +522,18 @@ buffer_t LoadSampleDataWithNullSamplesExtension(uint NullSamplesCount); buffer_t LoadSampleDataWithNullSamplesExtension(unsigned long SampleCount, uint NullSamplesCount); buffer_t GetCache(); + // own static methods + static buffer_t CreateDecompressionBuffer(unsigned long MaxReadSize); + static void DestroyDecompressionBuffer(buffer_t& DecompressionBuffer); // overridden methods void ReleaseSampleData(); 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); - unsigned long ReadAndLoop(void* pBuffer, unsigned long SampleCount, playback_state_t* pPlaybackState); + 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); protected: static unsigned int Instances; ///< Number of instances of class Sample. - static unsigned long DecompressionBufferSize; ///< Current size of the decompression buffer. - static unsigned char* pDecompressionBuffer; ///< Small buffer used for decompression only. + static buffer_t InternalDecompressionBuffer; ///< Buffer used for decompression as well as for truncation of 24 Bit -> 16 Bit samples. unsigned long FrameOffset; ///< Current offset (sample points) in current sample frame (for decompression only). unsigned long* FrameTable; ///< For positioning within compressed samples only: stores the offset values for each frame. unsigned long SamplePos; ///< For compressed samples only: stores the current position (in sample points). @@ -500,8 +541,9 @@ unsigned long WorstCaseFrameSize; ///< For compressed samples only: size (in bytes) of the largest possible sample frame. unsigned long SamplesPerFrame; ///< For compressed samples only: number of samples in a full sample frame. buffer_t RAMCache; ///< Buffers samples (already uncompressed) in RAM. + unsigned long FileNo; ///< File number (> 0 when sample is stored in an extension file, 0 when it's in the gig) - Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset); + Sample(File* pFile, RIFF::List* waveList, unsigned long WavePoolOffset, unsigned long fileNo = 0); ~Sample(); /** * Swaps the order of the data words in the given memory area @@ -579,6 +621,12 @@ // frame return (Channels == 2 ? size << 1 : size) + WorstCaseFrameSize; } + + // Worst case amount of sample points that can be read with the + // given decompression buffer. + inline unsigned long WorstCaseMaxSamples(buffer_t* pDecompressionBuffer) { + return (unsigned long) ((float)pDecompressionBuffer->Size / (float)WorstCaseFrameSize * (float)SamplesPerFrame); + } private: void ScanCompressedSample(); friend class File; @@ -603,7 +651,7 @@ Region(Instrument* pInstrument, RIFF::List* rgnList); void LoadDimensionRegions(RIFF::List* rgn); - Sample* GetSampleFromWavePool(unsigned int WavePoolTableIndex); + Sample* GetSampleFromWavePool(unsigned int WavePoolTableIndex, progress_t* pProgress = NULL); ~Region(); friend class Instrument; }; @@ -642,7 +690,7 @@ Region* RegionKeyTable[128]; ///< fast lookup for the corresponding Region of a MIDI key int RegionIndex; - Instrument(File* pFile, RIFF::List* insList); + Instrument(File* pFile, RIFF::List* insList, progress_t* pProgress = NULL); ~Instrument(); friend class File; }; @@ -662,11 +710,11 @@ DLS::Resource::GetParent; // overridden methods File(RIFF::File* pRIFF); - Sample* GetFirstSample(); ///< Returns a pointer to the first Sample object of the file, NULL otherwise. + 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. Instrument* GetNextInstrument(); ///< Returns a pointer to the next Instrument object of the file, NULL otherwise. - Instrument* GetInstrument(uint index); + Instrument* GetInstrument(uint index, progress_t* pProgress = NULL); ~File(); protected: typedef std::list SampleList; @@ -677,9 +725,11 @@ InstrumentList* pInstruments; InstrumentList::iterator InstrumentsIterator; - void LoadSamples(); - void LoadInstruments(); + void LoadSamples(progress_t* pProgress = NULL); + void LoadInstruments(progress_t* pProgress = NULL); friend class Region; + + std::list ExtensionFiles; }; /** Will be thrown whenever a gig specific error occurs while trying to access a Gigasampler File. */ @@ -689,6 +739,9 @@ void PrintMessage(); }; + String libraryName(); + String libraryVersion(); + } // namespace gig #endif // __GIG_H__