1 |
/*************************************************************************** |
2 |
* * |
3 |
* LinuxSampler - modular, streaming capable sampler * |
4 |
* * |
5 |
* Copyright (C) 2003, 2004 by Benno Senoner and Christian Schoenebeck * |
6 |
* Copyright (C) 2005 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/LinuxSamplerException.h" |
33 |
#include "../../common/ResourceManager.h" |
34 |
#include "../../drivers/audio/AudioOutputDevice.h" |
35 |
|
36 |
//namespace libgig = gig; |
37 |
|
38 |
namespace LinuxSampler { namespace gig { |
39 |
|
40 |
typedef ResourceConsumer< ::gig::Instrument> InstrumentConsumer; |
41 |
|
42 |
}} // namespace LinuxSampler::gig |
43 |
|
44 |
#include "EngineChannel.h" |
45 |
#include "Engine.h" |
46 |
|
47 |
namespace LinuxSampler { namespace gig { |
48 |
|
49 |
// just symbol prototyping |
50 |
class EngineChannel; |
51 |
|
52 |
/** |
53 |
* Explicitly identifies a Gigasampler instrument. |
54 |
*/ |
55 |
struct instrument_id_t { |
56 |
String FileName; ///< name of the file which contains the instrument |
57 |
uint iInstrument; ///< index of the instrument in the instrument file |
58 |
|
59 |
// TODO: we should extend operator<() so it will be able to detect that file x and file y are actually the same files, e.g. because one of them is a symlink / share the same inode |
60 |
bool operator<(const instrument_id_t& o) const { |
61 |
return (iInstrument < o.iInstrument || (iInstrument == o.iInstrument && FileName < o.FileName)); |
62 |
} |
63 |
}; |
64 |
|
65 |
/** Gig instrument manager |
66 |
* |
67 |
* Manager to share gig instruments between multiple Gigasampler |
68 |
* engine channels. The engine channels Borrow() instruments when they |
69 |
* need them and HandBack() when they don't need them anymore. The |
70 |
* InstrumentResourceManager loads the corresponding gig file and gig |
71 |
* instrument if needed, if it's already in use by another engine |
72 |
* channel, then it just returns the same resource, if an gig |
73 |
* instrument / file is not in use by any engine channel anymore, then |
74 |
* it will be freed from memory. |
75 |
*/ |
76 |
class InstrumentResourceManager : public ResourceManager<instrument_id_t, ::gig::Instrument> { |
77 |
public: |
78 |
virtual ~InstrumentResourceManager() {} |
79 |
static void OnInstrumentLoadingProgress(::gig::progress_t* pProgress); |
80 |
protected: |
81 |
virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg); |
82 |
virtual void Destroy(::gig::Instrument* pResource, void* pArg); |
83 |
virtual void OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg); |
84 |
private: |
85 |
struct instr_entry_t { |
86 |
::gig::File* pGig; |
87 |
uint iInstrument; |
88 |
uint MaxSamplesPerCycle; ///< if some engine requests an already allocated instrument with a higher value, we have to reallocate the instrument |
89 |
}; |
90 |
|
91 |
typedef ResourceConsumer< ::gig::File> GigConsumer; |
92 |
|
93 |
class GigResourceManager : public ResourceManager<String, ::gig::File> { |
94 |
protected: |
95 |
virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg); |
96 |
virtual void Destroy(::gig::File* pResource, void* pArg); |
97 |
virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore |
98 |
public: |
99 |
virtual ~GigResourceManager() {} |
100 |
} Gigs; |
101 |
|
102 |
void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel); |
103 |
}; |
104 |
|
105 |
/** |
106 |
* Will be thrown by the InstrumentResourceManager on errors. |
107 |
*/ |
108 |
class InstrumentResourceManagerException : public LinuxSamplerException { |
109 |
public: |
110 |
InstrumentResourceManagerException(String msg) : LinuxSamplerException(msg) {} |
111 |
}; |
112 |
|
113 |
}} // namespace LinuxSampler::gig |
114 |
|
115 |
#endif // __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__ |