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 |
1868 |
* Copyright (C) 2005 - 2009 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 |
1653 |
#include "../../common/ArrayList.h" |
36 |
schoenebeck |
53 |
|
37 |
|
|
//namespace libgig = gig; |
38 |
|
|
|
39 |
|
|
namespace LinuxSampler { namespace gig { |
40 |
|
|
|
41 |
|
|
typedef ResourceConsumer< ::gig::Instrument> InstrumentConsumer; |
42 |
|
|
|
43 |
|
|
}} // namespace LinuxSampler::gig |
44 |
|
|
|
45 |
schoenebeck |
411 |
#include "EngineChannel.h" |
46 |
schoenebeck |
53 |
#include "Engine.h" |
47 |
schoenebeck |
1375 |
#include "../../plugins/InstrumentEditor.h" |
48 |
schoenebeck |
53 |
|
49 |
|
|
namespace LinuxSampler { namespace gig { |
50 |
|
|
|
51 |
|
|
// just symbol prototyping |
52 |
schoenebeck |
411 |
class EngineChannel; |
53 |
schoenebeck |
1321 |
class Engine; |
54 |
schoenebeck |
53 |
|
55 |
schoenebeck |
947 |
/** @brief Gig instrument manager |
56 |
schoenebeck |
53 |
* |
57 |
|
|
* Manager to share gig instruments between multiple Gigasampler |
58 |
schoenebeck |
411 |
* engine channels. The engine channels Borrow() instruments when they |
59 |
|
|
* need them and HandBack() when they don't need them anymore. The |
60 |
schoenebeck |
53 |
* InstrumentResourceManager loads the corresponding gig file and gig |
61 |
schoenebeck |
411 |
* instrument if needed, if it's already in use by another engine |
62 |
|
|
* channel, then it just returns the same resource, if an gig |
63 |
schoenebeck |
947 |
* instrument / file is not needed anymore, then it will be freed from |
64 |
|
|
* memory. |
65 |
schoenebeck |
53 |
*/ |
66 |
schoenebeck |
1212 |
class InstrumentResourceManager : public InstrumentManager, public ResourceManager<InstrumentManager::instrument_id_t, ::gig::Instrument>, public InstrumentEditorListener { |
67 |
schoenebeck |
411 |
public: |
68 |
persson |
1038 |
InstrumentResourceManager() : Gigs(this) {} |
69 |
schoenebeck |
411 |
virtual ~InstrumentResourceManager() {} |
70 |
schoenebeck |
517 |
static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress); |
71 |
schoenebeck |
947 |
|
72 |
|
|
// implementation of derived abstract methods from 'InstrumentManager' |
73 |
|
|
virtual std::vector<instrument_id_t> Instruments(); |
74 |
|
|
virtual InstrumentManager::mode_t GetMode(const instrument_id_t& ID); |
75 |
|
|
virtual void SetMode(const instrument_id_t& ID, InstrumentManager::mode_t Mode); |
76 |
|
|
virtual String GetInstrumentName(instrument_id_t ID); |
77 |
schoenebeck |
1321 |
virtual String GetInstrumentDataStructureName(instrument_id_t ID); |
78 |
|
|
virtual String GetInstrumentDataStructureVersion(instrument_id_t ID); |
79 |
schoenebeck |
1876 |
virtual InstrumentEditor* LaunchInstrumentEditor(instrument_id_t ID, void* pUserData = NULL) throw (InstrumentManagerException); |
80 |
schoenebeck |
1525 |
virtual std::vector<instrument_id_t> GetInstrumentFileContent(String File) throw (InstrumentManagerException); |
81 |
|
|
virtual instrument_info_t GetInstrumentInfo(instrument_id_t ID) throw (InstrumentManagerException); |
82 |
persson |
1038 |
|
83 |
schoenebeck |
1321 |
// implementation of derived abstract methods from 'InstrumentEditorListener' |
84 |
schoenebeck |
1212 |
virtual void OnInstrumentEditorQuit(InstrumentEditor* pSender); |
85 |
schoenebeck |
1321 |
virtual void OnSamplesToBeRemoved(std::set<void*> Samples, InstrumentEditor* pSender); |
86 |
|
|
virtual void OnSamplesRemoved(InstrumentEditor* pSender); |
87 |
|
|
virtual void OnDataStructureToBeChanged(void* pStruct, String sStructType, InstrumentEditor* pSender); |
88 |
|
|
virtual void OnDataStructureChanged(void* pStruct, String sStructType, InstrumentEditor* pSender); |
89 |
|
|
virtual void OnSampleReferenceChanged(void* pOldSample, void* pNewSample, InstrumentEditor* pSender); |
90 |
schoenebeck |
1212 |
|
91 |
persson |
1038 |
void HandBackInstrument(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, |
92 |
persson |
1646 |
RTList< ::gig::DimensionRegion*>* pDimRegionsInUse); |
93 |
persson |
1038 |
void HandBackDimReg(::gig::DimensionRegion* pDimReg); |
94 |
|
|
|
95 |
schoenebeck |
1662 |
#if 0 // currently unused : |
96 |
schoenebeck |
1653 |
void TrySendNoteOnToEditors(uint8_t Key, uint8_t Velocity, ::gig::Instrument* pInstrument); |
97 |
|
|
void TrySendNoteOffToEditors(uint8_t Key, uint8_t Velocity, ::gig::Instrument* pInstrument); |
98 |
schoenebeck |
1662 |
#endif // unused |
99 |
schoenebeck |
1653 |
|
100 |
schoenebeck |
53 |
protected: |
101 |
schoenebeck |
1321 |
// implementation of derived abstract methods from 'ResourceManager' |
102 |
schoenebeck |
53 |
virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg); |
103 |
|
|
virtual void Destroy(::gig::Instrument* pResource, void* pArg); |
104 |
|
|
virtual void OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg); |
105 |
|
|
private: |
106 |
|
|
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 |
53 |
virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg); |
112 |
|
|
virtual void Destroy(::gig::File* pResource, void* pArg); |
113 |
|
|
virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // 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 |
411 |
void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel); |
122 |
schoenebeck |
1321 |
void CacheInitialSamples(::gig::Sample* pSample, gig::Engine* pEngine); |
123 |
|
|
void UncacheInitialSamples(::gig::Sample* pSample); |
124 |
|
|
std::vector< ::gig::Instrument*> GetInstrumentsCurrentlyUsedOf(::gig::File* pFile, bool bLock); |
125 |
schoenebeck |
1659 |
std::set<gig::EngineChannel*> GetEngineChannelsUsing(::gig::Instrument* pInstrument, bool bLock); |
126 |
|
|
std::set<gig::Engine*> GetEnginesUsing(::gig::Instrument* pInstrument, bool bLock); |
127 |
schoenebeck |
1321 |
std::set<gig::Engine*> GetEnginesUsing(::gig::File* pFile, bool bLock); |
128 |
|
|
bool SampleReferencedByInstrument(::gig::Sample* pSample, ::gig::Instrument* pInstrument); |
129 |
|
|
void SuspendEnginesUsing(::gig::Instrument* pInstrument); |
130 |
|
|
void SuspendEnginesUsing(::gig::File* pFile); |
131 |
|
|
void ResumeAllEngines(); |
132 |
persson |
1038 |
|
133 |
|
|
struct dimreg_info_t { |
134 |
|
|
int refCount; |
135 |
|
|
::gig::File* file; |
136 |
|
|
::RIFF::File* riff; |
137 |
|
|
}; |
138 |
|
|
Mutex DimRegInfoMutex; ///< protects the DimRegInfo and SampleRefCount maps from concurrent access by the instrument loader and disk threads |
139 |
|
|
std::map< ::gig::DimensionRegion*, dimreg_info_t> DimRegInfo; ///< contains dimension regions that are still in use but belong to released instrument |
140 |
|
|
std::map< ::gig::Sample*, int> SampleRefCount; ///< contains samples that are still in use but belong to a released instrument |
141 |
schoenebeck |
53 |
|
142 |
schoenebeck |
1212 |
Mutex InstrumentEditorProxiesMutex; ///< protects the 'InstrumentEditorProxies' map |
143 |
schoenebeck |
1653 |
ArrayList<InstrumentConsumer*> InstrumentEditorProxies; ///< here we store the objects that react on instrument specific notifications on behalf of the respective instrument editor |
144 |
schoenebeck |
1321 |
std::set<Engine*> suspendedEngines; ///< all engines currently completely suspended |
145 |
|
|
Mutex suspendedEnginesMutex; ///< protects 'suspendedEngines' set |
146 |
schoenebeck |
53 |
}; |
147 |
|
|
|
148 |
|
|
}} // namespace LinuxSampler::gig |
149 |
|
|
|
150 |
|
|
#endif // __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__ |