1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2008 Christian Schoenebeck * |
7 |
* Copyright (C) 2009 - 2012 Christian Schoenebeck and Grigor Iliev * |
8 |
* * |
9 |
* This program is free software; you can redistribute it and/or modify * |
10 |
* it under the terms of the GNU General Public License as published by * |
11 |
* the Free Software Foundation; either version 2 of the License, or * |
12 |
* (at your option) any later version. * |
13 |
* * |
14 |
* This program is distributed in the hope that it will be useful, * |
15 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
17 |
* GNU General Public License for more details. * |
18 |
* * |
19 |
* You should have received a copy of the GNU General Public License * |
20 |
* along with this program; if not, write to the Free Software * |
21 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, * |
22 |
* MA 02111-1307 USA * |
23 |
***************************************************************************/ |
24 |
|
25 |
#ifndef __LS_SFZ_INSTRUMENTRESOURCEMANAGER_H__ |
26 |
#define __LS_SFZ_INSTRUMENTRESOURCEMANAGER_H__ |
27 |
|
28 |
#include "../../common/global.h" |
29 |
|
30 |
#include "sfz.h" |
31 |
|
32 |
#include "../../common/global.h" |
33 |
#include "../../common/Pool.h" |
34 |
#include "../../common/ResourceManager.h" |
35 |
#include "../../drivers/audio/AudioOutputDevice.h" |
36 |
#include "../InstrumentManagerBase.h" |
37 |
#include "../common/Sample.h" |
38 |
#include "../../common/ArrayList.h" |
39 |
|
40 |
namespace LinuxSampler { namespace sfz { |
41 |
|
42 |
typedef ResourceConsumer< ::sfz::Instrument> InstrumentConsumer; |
43 |
|
44 |
}} // namespace LinuxSampler::sfz |
45 |
|
46 |
#include "../../plugins/InstrumentEditor.h" |
47 |
|
48 |
namespace LinuxSampler { namespace sfz { |
49 |
class Engine; |
50 |
class EngineChannel; |
51 |
|
52 |
/** @brief sfz instrument manager |
53 |
* |
54 |
* Manager to share sfz instruments between multiple sfz |
55 |
* engine channels. The engine channels Borrow() instruments when they |
56 |
* need them and HandBack() when they don't need them anymore. The |
57 |
* InstrumentResourceManager loads the corresponding sfz file and sfz |
58 |
* instrument if needed, if it's already in use by another engine |
59 |
* channel, then it just returns the same resource, if a sfz |
60 |
* instrument / file is not needed anymore, then it will be freed from |
61 |
* memory. |
62 |
*/ |
63 |
class InstrumentResourceManager : public InstrumentManagerBase< ::sfz::File, ::sfz::Instrument, ::sfz::Region, Sample> { |
64 |
public: |
65 |
InstrumentResourceManager() : Sfzs(this) {} |
66 |
virtual ~InstrumentResourceManager() {} |
67 |
|
68 |
// implementation of derived abstract methods from 'InstrumentManager' |
69 |
virtual String GetInstrumentName(instrument_id_t ID); |
70 |
virtual std::vector<instrument_id_t> GetInstrumentFileContent(String File) throw (InstrumentManagerException); |
71 |
virtual instrument_info_t GetInstrumentInfo(instrument_id_t ID) throw (InstrumentManagerException); |
72 |
|
73 |
::sfz::SampleManager* GetSampleManager() { return &Sfzs.sampleManager; } |
74 |
|
75 |
protected: |
76 |
// implementation of derived abstract methods from 'ResourceManager' |
77 |
virtual ::sfz::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg); |
78 |
virtual void Destroy(::sfz::Instrument* pResource, void* pArg); |
79 |
virtual void DeleteRegionIfNotUsed(::sfz::Region* pRegion, region_info_t* pRegInfo); |
80 |
virtual void DeleteSampleIfNotUsed(Sample* pSample, region_info_t* pRegInfo); |
81 |
private: |
82 |
typedef ResourceConsumer< ::sfz::File> SfzConsumer; |
83 |
|
84 |
class SfzResourceManager : public ResourceManager<String, ::sfz::File> { |
85 |
protected: |
86 |
// implementation of derived abstract methods from 'ResourceManager' |
87 |
virtual ::sfz::File* Create(String Key, SfzConsumer* pConsumer, void*& pArg); |
88 |
virtual void Destroy(::sfz::File* pResource, void* pArg); |
89 |
virtual void OnBorrow(::sfz::File* pResource, SfzConsumer* pConsumer, void*& pArg) {} // ignore |
90 |
public: |
91 |
SfzResourceManager(InstrumentResourceManager* parent) : parent(parent) {} |
92 |
virtual ~SfzResourceManager() {} |
93 |
friend class InstrumentResourceManager; |
94 |
private: |
95 |
InstrumentResourceManager* parent; |
96 |
::sfz::SampleManager sampleManager; |
97 |
} Sfzs; |
98 |
}; |
99 |
|
100 |
}} // namespace LinuxSampler::sfz |
101 |
|
102 |
#endif // __LS_SFZ_INSTRUMENTRESOURCEMANAGER_H__ |