/[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 2012 by iliev, Fri Oct 23 17:53:17 2009 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 - 2009 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/Pool.h"
 #include "../../common/LinuxSamplerException.h"  
32  #include "../../common/ResourceManager.h"  #include "../../common/ResourceManager.h"
33    #include "../InstrumentManagerBase.h"
34  #include "../../drivers/audio/AudioOutputDevice.h"  #include "../../drivers/audio/AudioOutputDevice.h"
35  #include "../../lib/fileloader/libgig/gig.h"  #include "../InstrumentManager.h"
36    #include "../../common/ArrayList.h"
 // preload 64k samples = 128kB of data in RAM for 16 bit mono samples  
 #define NUM_RAM_PRELOAD_SAMPLES 32768  
37    
38  //namespace libgig = gig;  //namespace libgig = gig;
39    
# Line 46  namespace LinuxSampler { namespace gig { Line 43  namespace LinuxSampler { namespace gig {
43    
44  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig
45    
46  #include "Engine.h"  #include "../../plugins/InstrumentEditor.h"
47    
48  namespace LinuxSampler { namespace gig {  namespace LinuxSampler { namespace gig {
   
     // just symbol prototyping  
49      class Engine;      class Engine;
50        class EngineChannel;
51    
52      /**      /** @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  
53       *       *
54       * Manager to share gig instruments between multiple Gigasampler       * Manager to share gig instruments between multiple Gigasampler
55       * engines. The engines Borrow() instruments when they need them and       * engine channels. The engine channels Borrow() instruments when they
56       * HandBack() when they don't need them anymore. The       * need them and HandBack() when they don't need them anymore. The
57       * InstrumentResourceManager loads the corresponding gig file and gig       * InstrumentResourceManager loads the corresponding gig file and gig
58       * 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
59       * it just returns the same resource, if an gig instrument / file is not       * channel, then it just returns the same resource, if an gig
60       * 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
61         * memory.
62       */       */
63      class InstrumentResourceManager : public ResourceManager<instrument_id_t, ::gig::Instrument> {      class InstrumentResourceManager : public InstrumentManagerBase< ::gig::File, ::gig::Instrument, ::gig::DimensionRegion, ::gig::Sample>, public InstrumentEditorListener {
64                  public:          public:
65                          virtual ~InstrumentResourceManager() {}              InstrumentResourceManager() : Gigs(this) {}
66                virtual ~InstrumentResourceManager() {}
67                static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress);
68    
69                // implementation of derived abstract methods from 'InstrumentManager'
70                virtual std::vector<instrument_id_t> Instruments();
71                virtual String GetInstrumentName(instrument_id_t ID);
72                virtual String GetInstrumentDataStructureName(instrument_id_t ID);
73                virtual String GetInstrumentDataStructureVersion(instrument_id_t ID);
74                virtual InstrumentEditor* LaunchInstrumentEditor(instrument_id_t ID, void* pUserData = NULL) throw (InstrumentManagerException);
75                virtual std::vector<instrument_id_t> GetInstrumentFileContent(String File) throw (InstrumentManagerException);
76                virtual instrument_info_t GetInstrumentInfo(instrument_id_t ID) throw (InstrumentManagerException);
77    
78                // implementation of derived abstract methods from 'InstrumentEditorListener'
79                virtual void OnInstrumentEditorQuit(InstrumentEditor* pSender);
80                virtual void OnSamplesToBeRemoved(std::set<void*> Samples, InstrumentEditor* pSender);
81                virtual void OnSamplesRemoved(InstrumentEditor* pSender);
82                virtual void OnDataStructureToBeChanged(void* pStruct, String sStructType, InstrumentEditor* pSender);
83                virtual void OnDataStructureChanged(void* pStruct, String sStructType, InstrumentEditor* pSender);
84                virtual void OnSampleReferenceChanged(void* pOldSample, void* pNewSample, InstrumentEditor* pSender);
85    
86    #if 0 // currently unused :
87                void TrySendNoteOnToEditors(uint8_t Key, uint8_t Velocity, ::gig::Instrument* pInstrument);
88                void TrySendNoteOffToEditors(uint8_t Key, uint8_t Velocity, ::gig::Instrument* pInstrument);
89    #endif // unused
90    
91          protected:          protected:
92                // implementation of derived abstract methods from 'ResourceManager'
93              virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg);              virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg);
94              virtual void               Destroy(::gig::Instrument* pResource, void* pArg);              virtual void               Destroy(::gig::Instrument* pResource, void* pArg);
95              virtual void               OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg);              virtual void               OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg);
96                virtual void               CacheInitialSamples(::gig::Sample* pSample, AbstractEngine* pEngine);
97                virtual void               CacheInitialSamples(::gig::Sample* pSample, EngineChannel* pEngineChannel);
98                virtual void               DeleteRegionIfNotUsed(::gig::DimensionRegion* pRegion, region_info_t* pRegInfo);
99                virtual void               DeleteSampleIfNotUsed(::gig::Sample* pSample, region_info_t* pRegInfo);
100          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  
             };  
   
101              typedef ResourceConsumer< ::gig::File> GigConsumer;              typedef ResourceConsumer< ::gig::File> GigConsumer;
102    
103              class GigResourceManager : public ResourceManager<String, ::gig::File> {              class GigResourceManager : public ResourceManager<String, ::gig::File> {
104                  protected:                  protected:
105                        // implementation of derived abstract methods from 'ResourceManager'
106                      virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg);                      virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg);
107                      virtual void         Destroy(::gig::File* pResource, void* pArg);                      virtual void         Destroy(::gig::File* pResource, void* pArg);
108                      virtual void         OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore                      virtual void         OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore
109                                  public:                  public:
110                                          virtual ~GigResourceManager() {}                      GigResourceManager(InstrumentResourceManager* parent) : parent(parent) {}
111                        virtual ~GigResourceManager() {}
112                    private:
113                        InstrumentResourceManager* parent;
114              } Gigs;              } Gigs;
115    
116              void CacheInitialSamples(::gig::Sample* pSample, gig::Engine* pEngine);              void UncacheInitialSamples(::gig::Sample* pSample);
117      };              std::vector< ::gig::Instrument*> GetInstrumentsCurrentlyUsedOf(::gig::File* pFile, bool bLock);
118                std::set<EngineChannel*> GetEngineChannelsUsing(::gig::Instrument* pInstrument, bool bLock);
119      /**              std::set<Engine*> GetEnginesUsing(::gig::Instrument* pInstrument, bool bLock);
120       * Will be thrown by the InstrumentResourceManager on errors.              std::set<Engine*> GetEnginesUsing(::gig::File* pFile, bool bLock);
121       */              bool SampleReferencedByInstrument(::gig::Sample* pSample, ::gig::Instrument* pInstrument);
122      class InstrumentResourceManagerException : public LinuxSamplerException {              void SuspendEnginesUsing(::gig::Instrument* pInstrument);
123          public:              void SuspendEnginesUsing(::gig::File* pFile);
124              InstrumentResourceManagerException(String msg) : LinuxSamplerException(msg) {}              void ResumeAllEngines();
125    
126                Mutex InstrumentEditorProxiesMutex; ///< protects the 'InstrumentEditorProxies' map
127                ArrayList<InstrumentConsumer*> InstrumentEditorProxies; ///< here we store the objects that react on instrument specific notifications on behalf of the respective instrument editor
128                std::set<Engine*> suspendedEngines; ///< all engines currently completely suspended
129                Mutex             suspendedEnginesMutex; ///< protects 'suspendedEngines' set
130      };      };
131    
132  }} // namespace LinuxSampler::gig  }} // namespace LinuxSampler::gig

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

  ViewVC Help
Powered by ViewVC