/[svn]/linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.h
ViewVC logotype

Diff of /linuxsampler/trunk/src/engines/gig/InstrumentResourceManager.h

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

revision 880 by schoenebeck, Tue Jun 27 22:57:37 2006 UTC revision 1038 by persson, Sat Feb 3 15:33:00 2007 UTC
# Line 32  Line 32 
32  #include "../../common/Exception.h"  #include "../../common/Exception.h"
33  #include "../../common/ResourceManager.h"  #include "../../common/ResourceManager.h"
34  #include "../../drivers/audio/AudioOutputDevice.h"  #include "../../drivers/audio/AudioOutputDevice.h"
35    #include "../InstrumentManager.h"
36    
37  //namespace libgig = gig;  //namespace libgig = gig;
38    
# Line 49  namespace LinuxSampler { namespace gig { Line 50  namespace LinuxSampler { namespace gig {
50      // just symbol prototyping      // just symbol prototyping
51      class EngineChannel;      class EngineChannel;
52    
53      /**      /** @brief Gig instrument manager
      * Explicitly identifies a Gigasampler instrument.  
      */  
     struct instrument_id_t {  
         String FileName;    ///< name of the file which contains the instrument  
         uint   iInstrument; ///< index of the instrument in the instrument file  
   
         // TODO: we should extend operator<() so it will be able to detect that file x and file y are actually the same files, e.g. because one of them is a symlink / share the same inode  
         bool operator<(const instrument_id_t& o) const {  
             return (iInstrument < o.iInstrument || (iInstrument == o.iInstrument && FileName < o.FileName));  
         }  
     };  
   
     /** Gig instrument manager  
54       *       *
55       * Manager to share gig instruments between multiple Gigasampler       * Manager to share gig instruments between multiple Gigasampler
56       * engine channels. The engine channels Borrow() instruments when they       * engine channels. The engine channels Borrow() instruments when they
# Line 70  namespace LinuxSampler { namespace gig { Line 58  namespace LinuxSampler { namespace gig {
58       * InstrumentResourceManager loads the corresponding gig file and gig       * InstrumentResourceManager loads the corresponding gig file and gig
59       * instrument if needed, if it's already in use by another engine       * instrument if needed, if it's already in use by another engine
60       * channel, then it just returns the same resource, if an gig       * channel, then it just returns the same resource, if an gig
61       * instrument / file is not in use by any engine channel anymore, then       * instrument / file is not needed anymore, then it will be freed from
62       * it will be freed from memory.       * memory.
63       */       */
64      class InstrumentResourceManager : public ResourceManager<instrument_id_t, ::gig::Instrument> {      class InstrumentResourceManager : public InstrumentManager, public ResourceManager<InstrumentManager::instrument_id_t, ::gig::Instrument> {
65          public:          public:
66                InstrumentResourceManager() : Gigs(this) {}
67              virtual ~InstrumentResourceManager() {}              virtual ~InstrumentResourceManager() {}
68              static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress);              static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress);
69    
70                // implementation of derived abstract methods from 'InstrumentManager'
71                virtual std::vector<instrument_id_t> Instruments();
72                virtual InstrumentManager::mode_t GetMode(const instrument_id_t& ID);
73                virtual void SetMode(const instrument_id_t& ID, InstrumentManager::mode_t Mode);
74                virtual String GetInstrumentName(instrument_id_t ID);
75    
76                void HandBackInstrument(::gig::Instrument* pResource, InstrumentConsumer* pConsumer,
77                                        ::gig::DimensionRegion** dimRegionsInUse);
78                void HandBackDimReg(::gig::DimensionRegion* pDimReg);
79    
80          protected:          protected:
81              virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg);              virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg);
82              virtual void               Destroy(::gig::Instrument* pResource, void* pArg);              virtual void               Destroy(::gig::Instrument* pResource, void* pArg);
83              virtual void               OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg);              virtual void               OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg);
84          private:          private:
             struct instr_entry_t {  
                 ::gig::File* pGig;  
                 uint         iInstrument;  
                 uint         MaxSamplesPerCycle; ///< if some engine requests an already allocated instrument with a higher value, we have to reallocate the instrument  
             };  
   
85              typedef ResourceConsumer< ::gig::File> GigConsumer;              typedef ResourceConsumer< ::gig::File> GigConsumer;
86    
87              class GigResourceManager : public ResourceManager<String, ::gig::File> {              class GigResourceManager : public ResourceManager<String, ::gig::File> {
# Line 96  namespace LinuxSampler { namespace gig { Line 90  namespace LinuxSampler { namespace gig {
90                      virtual void         Destroy(::gig::File* pResource, void* pArg);                      virtual void         Destroy(::gig::File* pResource, void* pArg);
91                      virtual void         OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore                      virtual void         OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore
92                  public:                  public:
93                        GigResourceManager(InstrumentResourceManager* parent) : parent(parent) {}
94                      virtual ~GigResourceManager() {}                      virtual ~GigResourceManager() {}
95                    private:
96                        InstrumentResourceManager* parent;
97              } Gigs;              } Gigs;
98    
99              void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel);              void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel);
100    
101                struct dimreg_info_t {
102                    int           refCount;
103                    ::gig::File*  file;
104                    ::RIFF::File* riff;
105                };
106                Mutex DimRegInfoMutex; ///< protects the DimRegInfo and SampleRefCount maps from concurrent access by the instrument loader and disk threads
107                std::map< ::gig::DimensionRegion*, dimreg_info_t> DimRegInfo; ///< contains dimension regions that are still in use but belong to released instrument
108                std::map< ::gig::Sample*, int> SampleRefCount; ///< contains samples that are still in use but belong to a released instrument
109      };      };
110    
111      /**      /**

Legend:
Removed from v.880  
changed lines
  Added in v.1038

  ViewVC Help
Powered by ViewVC