1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005, 2006 Christian Schoenebeck * |
7 |
* * |
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 |
#include <gig.h> |
30 |
|
31 |
#include "../../common/global.h" |
32 |
#include "../../common/Exception.h" |
33 |
#include "../../common/ResourceManager.h" |
34 |
#include "../../drivers/audio/AudioOutputDevice.h" |
35 |
#include "../InstrumentManager.h" |
36 |
|
37 |
//namespace libgig = gig; |
38 |
|
39 |
namespace LinuxSampler { namespace gig { |
40 |
|
41 |
typedef ResourceConsumer< ::gig::Instrument> InstrumentConsumer; |
42 |
|
43 |
}} // namespace LinuxSampler::gig |
44 |
|
45 |
#include "EngineChannel.h" |
46 |
#include "Engine.h" |
47 |
|
48 |
namespace LinuxSampler { namespace gig { |
49 |
|
50 |
// just symbol prototyping |
51 |
class EngineChannel; |
52 |
|
53 |
/** @brief Gig instrument manager |
54 |
* |
55 |
* Manager to share gig instruments between multiple Gigasampler |
56 |
* engine channels. The engine channels Borrow() instruments when they |
57 |
* need them and HandBack() when they don't need them anymore. The |
58 |
* InstrumentResourceManager loads the corresponding gig file and gig |
59 |
* instrument if needed, if it's already in use by another engine |
60 |
* channel, then it just returns the same resource, if an gig |
61 |
* instrument / file is not needed anymore, then it will be freed from |
62 |
* memory. |
63 |
*/ |
64 |
class InstrumentResourceManager : public InstrumentManager, public ResourceManager<InstrumentManager::instrument_id_t, ::gig::Instrument> { |
65 |
public: |
66 |
virtual ~InstrumentResourceManager() {} |
67 |
static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress); |
68 |
|
69 |
// implementation of derived abstract methods from 'InstrumentManager' |
70 |
virtual std::vector<instrument_id_t> Instruments(); |
71 |
virtual InstrumentManager::mode_t GetMode(const instrument_id_t& ID); |
72 |
virtual void SetMode(const instrument_id_t& ID, InstrumentManager::mode_t Mode); |
73 |
virtual String GetInstrumentName(instrument_id_t ID); |
74 |
protected: |
75 |
virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg); |
76 |
virtual void Destroy(::gig::Instrument* pResource, void* pArg); |
77 |
virtual void OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg); |
78 |
private: |
79 |
typedef ResourceConsumer< ::gig::File> GigConsumer; |
80 |
|
81 |
class GigResourceManager : public ResourceManager<String, ::gig::File> { |
82 |
protected: |
83 |
virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg); |
84 |
virtual void Destroy(::gig::File* pResource, void* pArg); |
85 |
virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore |
86 |
public: |
87 |
virtual ~GigResourceManager() {} |
88 |
} Gigs; |
89 |
|
90 |
void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel); |
91 |
}; |
92 |
|
93 |
/** |
94 |
* Will be thrown by the InstrumentResourceManager on errors. |
95 |
*/ |
96 |
class InstrumentResourceManagerException : public Exception { |
97 |
public: |
98 |
InstrumentResourceManagerException(String msg) : Exception(msg) {} |
99 |
}; |
100 |
|
101 |
}} // namespace LinuxSampler::gig |
102 |
|
103 |
#endif // __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__ |