/[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 3120 - (hide annotations) (download) (as text)
Fri Apr 21 16:54:52 2017 UTC (7 years ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 8668 byte(s)
- Minor override fix.

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 3120 * Copyright (C) 2005 - 2017 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 3052 #if AC_APPLE_UNIVERSAL_BUILD
30     # include <libgig/gig.h>
31     #else
32     # include <gig.h>
33     #endif
34 schoenebeck 505
35 iliev 2012 #include "../../common/Pool.h"
36 schoenebeck 53 #include "../../common/ResourceManager.h"
37 iliev 2012 #include "../InstrumentManagerBase.h"
38 schoenebeck 203 #include "../../drivers/audio/AudioOutputDevice.h"
39 schoenebeck 947 #include "../InstrumentManager.h"
40 schoenebeck 1653 #include "../../common/ArrayList.h"
41 schoenebeck 53
42     //namespace libgig = gig;
43    
44     namespace LinuxSampler { namespace gig {
45    
46     typedef ResourceConsumer< ::gig::Instrument> InstrumentConsumer;
47    
48     }} // namespace LinuxSampler::gig
49    
50 schoenebeck 1375 #include "../../plugins/InstrumentEditor.h"
51 schoenebeck 53
52     namespace LinuxSampler { namespace gig {
53 schoenebeck 2687
54 iliev 2012 class Engine;
55 schoenebeck 411 class EngineChannel;
56 schoenebeck 53
57 schoenebeck 947 /** @brief Gig instrument manager
58 schoenebeck 53 *
59     * Manager to share gig instruments between multiple Gigasampler
60 schoenebeck 411 * engine channels. The engine channels Borrow() instruments when they
61     * need them and HandBack() when they don't need them anymore. The
62 schoenebeck 53 * InstrumentResourceManager loads the corresponding gig file and gig
63 schoenebeck 411 * instrument if needed, if it's already in use by another engine
64     * channel, then it just returns the same resource, if an gig
65 schoenebeck 947 * instrument / file is not needed anymore, then it will be freed from
66     * memory.
67 schoenebeck 53 */
68 iliev 2012 class InstrumentResourceManager : public InstrumentManagerBase< ::gig::File, ::gig::Instrument, ::gig::DimensionRegion, ::gig::Sample>, public InstrumentEditorListener {
69 schoenebeck 411 public:
70 persson 1038 InstrumentResourceManager() : Gigs(this) {}
71 schoenebeck 411 virtual ~InstrumentResourceManager() {}
72 schoenebeck 517 static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress);
73 schoenebeck 947
74     // implementation of derived abstract methods from 'InstrumentManager'
75 schoenebeck 3054 virtual String GetInstrumentName(instrument_id_t ID) OVERRIDE;
76     virtual String GetInstrumentDataStructureName(instrument_id_t ID) OVERRIDE;
77     virtual String GetInstrumentDataStructureVersion(instrument_id_t ID) OVERRIDE;
78 schoenebeck 2687 virtual InstrumentEditor* LaunchInstrumentEditor(LinuxSampler::EngineChannel* pEngineChannel, instrument_id_t ID, void* pUserData = NULL) throw (InstrumentManagerException) OVERRIDE;
79 schoenebeck 3054 virtual std::vector<instrument_id_t> GetInstrumentFileContent(String File) throw (InstrumentManagerException) OVERRIDE;
80     virtual instrument_info_t GetInstrumentInfo(instrument_id_t ID) throw (InstrumentManagerException) OVERRIDE;
81 persson 1038
82 schoenebeck 1321 // implementation of derived abstract methods from 'InstrumentEditorListener'
83 schoenebeck 3054 virtual void OnInstrumentEditorQuit(InstrumentEditor* pSender) OVERRIDE;
84     virtual void OnSamplesToBeRemoved(std::set<void*> Samples, InstrumentEditor* pSender) OVERRIDE;
85     virtual void OnSamplesRemoved(InstrumentEditor* pSender) OVERRIDE;
86     virtual void OnDataStructureToBeChanged(void* pStruct, String sStructType, InstrumentEditor* pSender) OVERRIDE;
87     virtual void OnDataStructureChanged(void* pStruct, String sStructType, InstrumentEditor* pSender) OVERRIDE;
88     virtual void OnSampleReferenceChanged(void* pOldSample, void* pNewSample, InstrumentEditor* pSender) OVERRIDE;
89 schoenebeck 1212
90 schoenebeck 1662 #if 0 // currently unused :
91 schoenebeck 1653 void TrySendNoteOnToEditors(uint8_t Key, uint8_t Velocity, ::gig::Instrument* pInstrument);
92     void TrySendNoteOffToEditors(uint8_t Key, uint8_t Velocity, ::gig::Instrument* pInstrument);
93 schoenebeck 1662 #endif // unused
94 schoenebeck 1653
95 schoenebeck 53 protected:
96 schoenebeck 1321 // implementation of derived abstract methods from 'ResourceManager'
97 schoenebeck 3054 virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg) OVERRIDE;
98     virtual void Destroy(::gig::Instrument* pResource, void* pArg) OVERRIDE;
99     virtual void DeleteRegionIfNotUsed(::gig::DimensionRegion* pRegion, region_info_t* pRegInfo) OVERRIDE;
100     virtual void DeleteSampleIfNotUsed(::gig::Sample* pSample, region_info_t* pRegInfo) OVERRIDE;
101 schoenebeck 53 private:
102 persson 2326 void CacheInitialSamples(::gig::Sample* pSample, AbstractEngine* pEngine);
103     void CacheInitialSamples(::gig::Sample* pSample, EngineChannel* pEngineChannel);
104     void CacheInitialSamples(::gig::Sample* pSample, uint maxSamplesPerCycle);
105    
106 schoenebeck 53 typedef ResourceConsumer< ::gig::File> GigConsumer;
107    
108     class GigResourceManager : public ResourceManager<String, ::gig::File> {
109     protected:
110 schoenebeck 1321 // implementation of derived abstract methods from 'ResourceManager'
111 schoenebeck 3120 virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg) OVERRIDE;
112     virtual void Destroy(::gig::File* pResource, void* pArg) OVERRIDE;
113     virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) OVERRIDE {} // ignore
114 schoenebeck 411 public:
115 persson 1038 GigResourceManager(InstrumentResourceManager* parent) : parent(parent) {}
116 schoenebeck 411 virtual ~GigResourceManager() {}
117 persson 1038 private:
118     InstrumentResourceManager* parent;
119 schoenebeck 53 } Gigs;
120    
121 schoenebeck 1321 void UncacheInitialSamples(::gig::Sample* pSample);
122     std::vector< ::gig::Instrument*> GetInstrumentsCurrentlyUsedOf(::gig::File* pFile, bool bLock);
123 schoenebeck 2902 std::set<EngineChannel*> GetEngineChannelsUsingScriptSourceCode(const String& code, bool bLock);
124 iliev 2012 std::set<EngineChannel*> GetEngineChannelsUsing(::gig::Instrument* pInstrument, bool bLock);
125     std::set<Engine*> GetEnginesUsing(::gig::Instrument* pInstrument, bool bLock);
126     std::set<Engine*> GetEnginesUsing(::gig::File* pFile, bool bLock);
127 schoenebeck 1321 bool SampleReferencedByInstrument(::gig::Sample* pSample, ::gig::Instrument* pInstrument);
128     void SuspendEnginesUsing(::gig::Instrument* pInstrument);
129     void SuspendEnginesUsing(::gig::File* pFile);
130     void ResumeAllEngines();
131 persson 1038
132 schoenebeck 1212 Mutex InstrumentEditorProxiesMutex; ///< protects the 'InstrumentEditorProxies' map
133 schoenebeck 1653 ArrayList<InstrumentConsumer*> InstrumentEditorProxies; ///< here we store the objects that react on instrument specific notifications on behalf of the respective instrument editor
134 schoenebeck 1321 std::set<Engine*> suspendedEngines; ///< all engines currently completely suspended
135     Mutex suspendedEnginesMutex; ///< protects 'suspendedEngines' set
136 schoenebeck 2902 std::map< ::gig::Script*,String> pendingScriptUpdates; ///< Used to prepare updates of instrument scripts (value of the map is the original source code of the script before it is modified).
137     Mutex pendingScriptUpdatesMutex; ///< Protectes 'pendingScriptUpdates'.
138 schoenebeck 53 };
139    
140     }} // namespace LinuxSampler::gig
141    
142     #endif // __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__

  ViewVC Help
Powered by ViewVC