/[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 386 by letz, Thu Feb 17 10:45:30 2005 UTC revision 1375 by schoenebeck, Wed Oct 3 18:41:09 2007 UTC
# Line 3  Line 3 
3   *   LinuxSampler - modular, streaming capable sampler                     *   *   LinuxSampler - modular, streaming capable sampler                     *
4   *                                                                         *   *                                                                         *
5   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *   *   Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck   *
6     *   Copyright (C) 2005 - 2007 Christian Schoenebeck                       *
7   *                                                                         *   *                                                                         *
8   *   This program is free software; you can redistribute it and/or modify  *   *   This program is free software; you can redistribute it and/or modify  *
9   *   it under the terms of the GNU General Public License as published by  *   *   it under the terms of the GNU General Public License as published by  *
# Line 25  Line 26 
26    
27  #include "../../common/global.h"  #include "../../common/global.h"
28    
29  #if DEBUG_HEADERS  #include <gig.h>
 # warning InstrumentResourceManager.h included  
 #endif // DEBUG_HEADERS  
30    
31  #include "../../common/global.h"  #include "../../common/global.h"
 #include "../../common/LinuxSamplerException.h"  
32  #include "../../common/ResourceManager.h"  #include "../../common/ResourceManager.h"
33  #include "../../drivers/audio/AudioOutputDevice.h"  #include "../../drivers/audio/AudioOutputDevice.h"
34  #include "../../lib/fileloader/libgig/gig.h"  #include "../InstrumentManager.h"
   
 // preload 64k samples = 128kB of data in RAM for 16 bit mono samples  
 #define NUM_RAM_PRELOAD_SAMPLES 32768  
35    
36  //namespace libgig = gig;  //namespace libgig = gig;
37    
# Line 46  namespace LinuxSampler { namespace gig { Line 41  namespace LinuxSampler { namespace gig {
41    
42  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig
43    
44    #include "EngineChannel.h"
45  #include "Engine.h"  #include "Engine.h"
46    #include "../../plugins/InstrumentEditor.h"
47    
48  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
49    
50      // just symbol prototyping      // just symbol prototyping
51        class EngineChannel;
52      class Engine;      class Engine;
53    
54      /**      /** @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  
55       *       *
56       * Manager to share gig instruments between multiple Gigasampler       * Manager to share gig instruments between multiple Gigasampler
57       * engines. The engines Borrow() instruments when they need them and       * engine channels. The engine channels Borrow() instruments when they
58       * HandBack() when they don't need them anymore. The       * need them and HandBack() when they don't need them anymore. The
59       * InstrumentResourceManager loads the corresponding gig file and gig       * InstrumentResourceManager loads the corresponding gig file and gig
60       * instrument if needed, if it's already in use by another engine, then       * instrument if needed, if it's already in use by another engine
61       * it just returns the same resource, if an gig instrument / file is not       * channel, then it just returns the same resource, if an gig
62       * in use by any engine anymore, then it will be freed from memory.       * instrument / file is not needed anymore, then it will be freed from
63         * memory.
64       */       */
65      class InstrumentResourceManager : public ResourceManager<instrument_id_t, ::gig::Instrument> {      class InstrumentResourceManager : public InstrumentManager, public ResourceManager<InstrumentManager::instrument_id_t, ::gig::Instrument>, public InstrumentEditorListener {
66                  public:          public:
67                          virtual ~InstrumentResourceManager() {}              InstrumentResourceManager() : Gigs(this) {}
68                virtual ~InstrumentResourceManager() {}
69                static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress);
70    
71                // implementation of derived abstract methods from 'InstrumentManager'
72                virtual std::vector<instrument_id_t> Instruments();
73                virtual InstrumentManager::mode_t GetMode(const instrument_id_t& ID);
74                virtual void SetMode(const instrument_id_t& ID, InstrumentManager::mode_t Mode);
75                virtual String GetInstrumentName(instrument_id_t ID);
76                virtual String GetInstrumentDataStructureName(instrument_id_t ID);
77                virtual String GetInstrumentDataStructureVersion(instrument_id_t ID);
78                virtual void LaunchInstrumentEditor(instrument_id_t ID) throw (InstrumentManagerException);
79    
80                // implementation of derived abstract methods from 'InstrumentEditorListener'
81                virtual void OnInstrumentEditorQuit(InstrumentEditor* pSender);
82                virtual void OnSamplesToBeRemoved(std::set<void*> Samples, InstrumentEditor* pSender);
83                virtual void OnSamplesRemoved(InstrumentEditor* pSender);
84                virtual void OnDataStructureToBeChanged(void* pStruct, String sStructType, InstrumentEditor* pSender);
85                virtual void OnDataStructureChanged(void* pStruct, String sStructType, InstrumentEditor* pSender);
86                virtual void OnSampleReferenceChanged(void* pOldSample, void* pNewSample, InstrumentEditor* pSender);
87    
88                void HandBackInstrument(::gig::Instrument* pResource, InstrumentConsumer* pConsumer,
89                                        ::gig::DimensionRegion** dimRegionsInUse);
90                void HandBackDimReg(::gig::DimensionRegion* pDimReg);
91    
92          protected:          protected:
93                // implementation of derived abstract methods from 'ResourceManager'
94              virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg);              virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg);
95              virtual void               Destroy(::gig::Instrument* pResource, void* pArg);              virtual void               Destroy(::gig::Instrument* pResource, void* pArg);
96              virtual void               OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg);              virtual void               OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg);
97          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  
             };  
   
98              typedef ResourceConsumer< ::gig::File> GigConsumer;              typedef ResourceConsumer< ::gig::File> GigConsumer;
99    
100              class GigResourceManager : public ResourceManager<String, ::gig::File> {              class GigResourceManager : public ResourceManager<String, ::gig::File> {
101                  protected:                  protected:
102                        // implementation of derived abstract methods from 'ResourceManager'
103                      virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg);                      virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg);
104                      virtual void         Destroy(::gig::File* pResource, void* pArg);                      virtual void         Destroy(::gig::File* pResource, void* pArg);
105                      virtual void         OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore                      virtual void         OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore
106                                  public:                  public:
107                                          virtual ~GigResourceManager() {}                      GigResourceManager(InstrumentResourceManager* parent) : parent(parent) {}
108                        virtual ~GigResourceManager() {}
109                    private:
110                        InstrumentResourceManager* parent;
111              } Gigs;              } Gigs;
112    
113                void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel);
114              void CacheInitialSamples(::gig::Sample* pSample, gig::Engine* pEngine);              void CacheInitialSamples(::gig::Sample* pSample, gig::Engine* pEngine);
115      };              void UncacheInitialSamples(::gig::Sample* pSample);
116                std::vector< ::gig::Instrument*> GetInstrumentsCurrentlyUsedOf(::gig::File* pFile, bool bLock);
117      /**              std::set<gig::Engine*> GetEnginesUsing(::gig::Instrument* pFile, bool bLock);
118       * Will be thrown by the InstrumentResourceManager on errors.              std::set<gig::Engine*> GetEnginesUsing(::gig::File* pFile, bool bLock);
119       */              bool SampleReferencedByInstrument(::gig::Sample* pSample, ::gig::Instrument* pInstrument);
120      class InstrumentResourceManagerException : public LinuxSamplerException {              void SuspendEnginesUsing(::gig::Instrument* pInstrument);
121          public:              void SuspendEnginesUsing(::gig::File* pFile);
122              InstrumentResourceManagerException(String msg) : LinuxSamplerException(msg) {}              void ResumeAllEngines();
123    
124                struct dimreg_info_t {
125                    int           refCount;
126                    ::gig::File*  file;
127                    ::RIFF::File* riff;
128                };
129                Mutex DimRegInfoMutex; ///< protects the DimRegInfo and SampleRefCount maps from concurrent access by the instrument loader and disk threads
130                std::map< ::gig::DimensionRegion*, dimreg_info_t> DimRegInfo; ///< contains dimension regions that are still in use but belong to released instrument
131                std::map< ::gig::Sample*, int> SampleRefCount; ///< contains samples that are still in use but belong to a released instrument
132    
133                Mutex InstrumentEditorProxiesMutex; ///< protects the 'InstrumentEditorProxies' map
134                std::map<InstrumentEditor*, InstrumentConsumer*> InstrumentEditorProxies; ///< here we store the objects that react on instrument specific notifications on behalf of the respective instrument editor
135                std::set<Engine*> suspendedEngines; ///< all engines currently completely suspended
136                Mutex             suspendedEnginesMutex; ///< protects 'suspendedEngines' set
137      };      };
138    
139  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

Legend:
Removed from v.386  
changed lines
  Added in v.1375

  ViewVC Help
Powered by ViewVC