1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 - 2009 Christian Schoenebeck * |
7 |
* Copyright (C) 2009 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_SF2_INSTRUMENTRESOURCEMANAGER_H__ |
26 |
#define __LS_SF2_INSTRUMENTRESOURCEMANAGER_H__ |
27 |
|
28 |
#include "../../common/global.h" |
29 |
|
30 |
#include <SF.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/ArrayList.h" |
38 |
|
39 |
namespace LinuxSampler { namespace sf2 { |
40 |
|
41 |
typedef ResourceConsumer< ::sf2::Preset> InstrumentConsumer; |
42 |
|
43 |
}} // namespace LinuxSampler::sf2 |
44 |
|
45 |
#include "../../plugins/InstrumentEditor.h" |
46 |
|
47 |
namespace LinuxSampler { namespace sf2 { |
48 |
class Engine; |
49 |
class EngineChannel; |
50 |
|
51 |
/** @brief sf2 instrument manager |
52 |
* |
53 |
* Manager to share sf2 instruments between multiple sf2 |
54 |
* engine channels. The engine channels Borrow() instruments when they |
55 |
* need them and HandBack() when they don't need them anymore. The |
56 |
* InstrumentResourceManager loads the corresponding sf2 file and sf2 |
57 |
* instrument if needed, if it's already in use by another engine |
58 |
* channel, then it just returns the same resource, if a sf2 |
59 |
* instrument / file is not needed anymore, then it will be freed from |
60 |
* memory. |
61 |
*/ |
62 |
class InstrumentResourceManager : public InstrumentManagerDefaultImpl< ::sf2::File, ::sf2::Preset, ::sf2::Region, ::sf2::Sample> { |
63 |
public: |
64 |
InstrumentResourceManager() : Sf2s(this) {} |
65 |
virtual ~InstrumentResourceManager() {} |
66 |
|
67 |
// implementation of derived abstract methods from 'InstrumentManager' |
68 |
virtual std::vector<instrument_id_t> Instruments(); |
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 |
protected: |
74 |
// implementation of derived abstract methods from 'ResourceManager' |
75 |
virtual ::sf2::Preset* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg); |
76 |
virtual void Destroy(::sf2::Preset* pResource, void* pArg); |
77 |
virtual void OnBorrow(::sf2::Preset* pResource, InstrumentConsumer* pConsumer, void*& pArg); |
78 |
virtual void DeleteRegionIfNotUsed(::sf2::Region* pRegion, region_info_t* pRegInfo); |
79 |
virtual void DeleteSampleIfNotUsed(::sf2::Sample* pSample, region_info_t* pRegInfo); |
80 |
private: |
81 |
typedef ResourceConsumer< ::sf2::File> Sf2Consumer; |
82 |
|
83 |
class Sf2ResourceManager : public ResourceManager<String, ::sf2::File> { |
84 |
protected: |
85 |
// implementation of derived abstract methods from 'ResourceManager' |
86 |
virtual ::sf2::File* Create(String Key, Sf2Consumer* pConsumer, void*& pArg); |
87 |
virtual void Destroy(::sf2::File* pResource, void* pArg); |
88 |
virtual void OnBorrow(::sf2::File* pResource, Sf2Consumer* pConsumer, void*& pArg) {} // ignore |
89 |
public: |
90 |
Sf2ResourceManager(InstrumentResourceManager* parent) : parent(parent) {} |
91 |
virtual ~Sf2ResourceManager() {} |
92 |
friend class InstrumentResourceManager; |
93 |
private: |
94 |
InstrumentResourceManager* parent; |
95 |
} Sf2s; |
96 |
|
97 |
int GetSfInstrumentCount(::sf2::File* pFile); |
98 |
::sf2::Preset* GetSfInstrument(::sf2::File* pFile, int idx); |
99 |
}; |
100 |
|
101 |
}} // namespace LinuxSampler::sf2 |
102 |
|
103 |
#endif // __LS_SF2_INSTRUMENTRESOURCEMANAGER_H__ |