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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1525 - (hide annotations) (download) (as text)
Sun Nov 25 17:47:46 2007 UTC (16 years, 4 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 8435 byte(s)
* LSCP: added new LSCP commands: "GET FILE INSTRUMENTS <file>",
  "LIST FILE INSTRUMENTS <file>" and
  "GET FILE INSTRUMENT INFO <file> <index>" for retrieving informations
  about an arbitrary instrument file on the system where the sampler is
  running on (LSCP specs yet to be updated!)
* bumped version to 0.5.0.1cvs
* bumped LSCP compliance to LSCP version 1.3

1 schoenebeck 53 /***************************************************************************
2     * *
3     * LinuxSampler - modular, streaming capable sampler *
4     * *
5 schoenebeck 56 * Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck *
6 schoenebeck 1212 * Copyright (C) 2005 - 2007 Christian Schoenebeck *
7 schoenebeck 53 * *
8     * 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 *
10     * the Free Software Foundation; either version 2 of the License, or *
11     * (at your option) any later version. *
12     * *
13     * This program is distributed in the hope that it will be useful, *
14     * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16     * GNU General Public License for more details. *
17     * *
18     * You should have received a copy of the GNU General Public License *
19     * along with this program; if not, write to the Free Software *
20     * Foundation, Inc., 59 Temple Place, Suite 330, Boston, *
21     * MA 02111-1307 USA *
22     ***************************************************************************/
23    
24     #ifndef __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__
25     #define __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__
26    
27     #include "../../common/global.h"
28    
29 schoenebeck 505 #include <gig.h>
30    
31 schoenebeck 53 #include "../../common/global.h"
32     #include "../../common/ResourceManager.h"
33 schoenebeck 203 #include "../../drivers/audio/AudioOutputDevice.h"
34 schoenebeck 947 #include "../InstrumentManager.h"
35 schoenebeck 53
36     //namespace libgig = gig;
37    
38     namespace LinuxSampler { namespace gig {
39    
40     typedef ResourceConsumer< ::gig::Instrument> InstrumentConsumer;
41    
42     }} // namespace LinuxSampler::gig
43    
44 schoenebeck 411 #include "EngineChannel.h"
45 schoenebeck 53 #include "Engine.h"
46 schoenebeck 1375 #include "../../plugins/InstrumentEditor.h"
47 schoenebeck 53
48     namespace LinuxSampler { namespace gig {
49    
50     // just symbol prototyping
51 schoenebeck 411 class EngineChannel;
52 schoenebeck 1321 class Engine;
53 schoenebeck 53
54 schoenebeck 947 /** @brief Gig instrument manager
55 schoenebeck 53 *
56     * Manager to share gig instruments between multiple Gigasampler
57 schoenebeck 411 * engine channels. The engine channels Borrow() instruments when they
58     * need them and HandBack() when they don't need them anymore. The
59 schoenebeck 53 * InstrumentResourceManager loads the corresponding gig file and gig
60 schoenebeck 411 * instrument if needed, if it's already in use by another engine
61     * channel, then it just returns the same resource, if an gig
62 schoenebeck 947 * instrument / file is not needed anymore, then it will be freed from
63     * memory.
64 schoenebeck 53 */
65 schoenebeck 1212 class InstrumentResourceManager : public InstrumentManager, public ResourceManager<InstrumentManager::instrument_id_t, ::gig::Instrument>, public InstrumentEditorListener {
66 schoenebeck 411 public:
67 persson 1038 InstrumentResourceManager() : Gigs(this) {}
68 schoenebeck 411 virtual ~InstrumentResourceManager() {}
69 schoenebeck 517 static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress);
70 schoenebeck 947
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 schoenebeck 1321 virtual String GetInstrumentDataStructureName(instrument_id_t ID);
77     virtual String GetInstrumentDataStructureVersion(instrument_id_t ID);
78 schoenebeck 1212 virtual void LaunchInstrumentEditor(instrument_id_t ID) throw (InstrumentManagerException);
79 schoenebeck 1525 virtual std::vector<instrument_id_t> GetInstrumentFileContent(String File) throw (InstrumentManagerException);
80     virtual instrument_info_t GetInstrumentInfo(instrument_id_t ID) throw (InstrumentManagerException);
81 persson 1038
82 schoenebeck 1321 // implementation of derived abstract methods from 'InstrumentEditorListener'
83 schoenebeck 1212 virtual void OnInstrumentEditorQuit(InstrumentEditor* pSender);
84 schoenebeck 1321 virtual void OnSamplesToBeRemoved(std::set<void*> Samples, InstrumentEditor* pSender);
85     virtual void OnSamplesRemoved(InstrumentEditor* pSender);
86     virtual void OnDataStructureToBeChanged(void* pStruct, String sStructType, InstrumentEditor* pSender);
87     virtual void OnDataStructureChanged(void* pStruct, String sStructType, InstrumentEditor* pSender);
88     virtual void OnSampleReferenceChanged(void* pOldSample, void* pNewSample, InstrumentEditor* pSender);
89 schoenebeck 1212
90 persson 1038 void HandBackInstrument(::gig::Instrument* pResource, InstrumentConsumer* pConsumer,
91     ::gig::DimensionRegion** dimRegionsInUse);
92     void HandBackDimReg(::gig::DimensionRegion* pDimReg);
93    
94 schoenebeck 53 protected:
95 schoenebeck 1321 // implementation of derived abstract methods from 'ResourceManager'
96 schoenebeck 53 virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg);
97     virtual void Destroy(::gig::Instrument* pResource, void* pArg);
98     virtual void OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg);
99     private:
100     typedef ResourceConsumer< ::gig::File> GigConsumer;
101    
102     class GigResourceManager : public ResourceManager<String, ::gig::File> {
103     protected:
104 schoenebeck 1321 // implementation of derived abstract methods from 'ResourceManager'
105 schoenebeck 53 virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg);
106     virtual void Destroy(::gig::File* pResource, void* pArg);
107     virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore
108 schoenebeck 411 public:
109 persson 1038 GigResourceManager(InstrumentResourceManager* parent) : parent(parent) {}
110 schoenebeck 411 virtual ~GigResourceManager() {}
111 persson 1038 private:
112     InstrumentResourceManager* parent;
113 schoenebeck 53 } Gigs;
114    
115 schoenebeck 411 void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel);
116 schoenebeck 1321 void CacheInitialSamples(::gig::Sample* pSample, gig::Engine* pEngine);
117     void UncacheInitialSamples(::gig::Sample* pSample);
118     std::vector< ::gig::Instrument*> GetInstrumentsCurrentlyUsedOf(::gig::File* pFile, bool bLock);
119     std::set<gig::Engine*> GetEnginesUsing(::gig::Instrument* pFile, bool bLock);
120     std::set<gig::Engine*> GetEnginesUsing(::gig::File* pFile, bool bLock);
121     bool SampleReferencedByInstrument(::gig::Sample* pSample, ::gig::Instrument* pInstrument);
122     void SuspendEnginesUsing(::gig::Instrument* pInstrument);
123     void SuspendEnginesUsing(::gig::File* pFile);
124     void ResumeAllEngines();
125 persson 1038
126     struct dimreg_info_t {
127     int refCount;
128     ::gig::File* file;
129     ::RIFF::File* riff;
130     };
131     Mutex DimRegInfoMutex; ///< protects the DimRegInfo and SampleRefCount maps from concurrent access by the instrument loader and disk threads
132     std::map< ::gig::DimensionRegion*, dimreg_info_t> DimRegInfo; ///< contains dimension regions that are still in use but belong to released instrument
133     std::map< ::gig::Sample*, int> SampleRefCount; ///< contains samples that are still in use but belong to a released instrument
134 schoenebeck 53
135 schoenebeck 1212 Mutex InstrumentEditorProxiesMutex; ///< protects the 'InstrumentEditorProxies' map
136     std::map<InstrumentEditor*, InstrumentConsumer*> InstrumentEditorProxies; ///< here we store the objects that react on instrument specific notifications on behalf of the respective instrument editor
137 schoenebeck 1321 std::set<Engine*> suspendedEngines; ///< all engines currently completely suspended
138     Mutex suspendedEnginesMutex; ///< protects 'suspendedEngines' set
139 schoenebeck 53 };
140    
141     }} // namespace LinuxSampler::gig
142    
143     #endif // __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__

  ViewVC Help
Powered by ViewVC