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 |
411 |
* Copyright (C) 2005 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 |
|
|
#if DEBUG_HEADERS |
30 |
|
|
# warning InstrumentResourceManager.h included |
31 |
|
|
#endif // DEBUG_HEADERS |
32 |
|
|
|
33 |
schoenebeck |
505 |
#include <gig.h> |
34 |
|
|
|
35 |
schoenebeck |
53 |
#include "../../common/global.h" |
36 |
|
|
#include "../../common/LinuxSamplerException.h" |
37 |
|
|
#include "../../common/ResourceManager.h" |
38 |
schoenebeck |
203 |
#include "../../drivers/audio/AudioOutputDevice.h" |
39 |
schoenebeck |
53 |
|
40 |
|
|
// preload 64k samples = 128kB of data in RAM for 16 bit mono samples |
41 |
|
|
#define NUM_RAM_PRELOAD_SAMPLES 32768 |
42 |
|
|
|
43 |
|
|
//namespace libgig = gig; |
44 |
|
|
|
45 |
|
|
namespace LinuxSampler { namespace gig { |
46 |
|
|
|
47 |
|
|
typedef ResourceConsumer< ::gig::Instrument> InstrumentConsumer; |
48 |
|
|
|
49 |
|
|
}} // namespace LinuxSampler::gig |
50 |
|
|
|
51 |
schoenebeck |
411 |
#include "EngineChannel.h" |
52 |
schoenebeck |
53 |
#include "Engine.h" |
53 |
|
|
|
54 |
|
|
namespace LinuxSampler { namespace gig { |
55 |
|
|
|
56 |
|
|
// just symbol prototyping |
57 |
schoenebeck |
411 |
class EngineChannel; |
58 |
schoenebeck |
53 |
|
59 |
|
|
/** |
60 |
|
|
* Explicitly identifies a Gigasampler instrument. |
61 |
|
|
*/ |
62 |
|
|
struct instrument_id_t { |
63 |
|
|
String FileName; ///< name of the file which contains the instrument |
64 |
|
|
uint iInstrument; ///< index of the instrument in the instrument file |
65 |
|
|
|
66 |
|
|
// 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 |
67 |
|
|
bool operator<(const instrument_id_t& o) const { |
68 |
|
|
return (iInstrument < o.iInstrument || (iInstrument == o.iInstrument && FileName < o.FileName)); |
69 |
|
|
} |
70 |
|
|
}; |
71 |
|
|
|
72 |
|
|
/** Gig instrument manager |
73 |
|
|
* |
74 |
|
|
* Manager to share gig instruments between multiple Gigasampler |
75 |
schoenebeck |
411 |
* engine channels. The engine channels Borrow() instruments when they |
76 |
|
|
* need them and HandBack() when they don't need them anymore. The |
77 |
schoenebeck |
53 |
* InstrumentResourceManager loads the corresponding gig file and gig |
78 |
schoenebeck |
411 |
* instrument if needed, if it's already in use by another engine |
79 |
|
|
* channel, then it just returns the same resource, if an gig |
80 |
|
|
* instrument / file is not in use by any engine channel anymore, then |
81 |
|
|
* it will be freed from memory. |
82 |
schoenebeck |
53 |
*/ |
83 |
|
|
class InstrumentResourceManager : public ResourceManager<instrument_id_t, ::gig::Instrument> { |
84 |
schoenebeck |
411 |
public: |
85 |
|
|
virtual ~InstrumentResourceManager() {} |
86 |
schoenebeck |
53 |
protected: |
87 |
|
|
virtual ::gig::Instrument* Create(instrument_id_t Key, InstrumentConsumer* pConsumer, void*& pArg); |
88 |
|
|
virtual void Destroy(::gig::Instrument* pResource, void* pArg); |
89 |
|
|
virtual void OnBorrow(::gig::Instrument* pResource, InstrumentConsumer* pConsumer, void*& pArg); |
90 |
|
|
private: |
91 |
|
|
struct instr_entry_t { |
92 |
|
|
::gig::File* pGig; |
93 |
|
|
uint iInstrument; |
94 |
|
|
uint MaxSamplesPerCycle; ///< if some engine requests an already allocated instrument with a higher value, we have to reallocate the instrument |
95 |
|
|
}; |
96 |
|
|
|
97 |
|
|
typedef ResourceConsumer< ::gig::File> GigConsumer; |
98 |
|
|
|
99 |
|
|
class GigResourceManager : public ResourceManager<String, ::gig::File> { |
100 |
|
|
protected: |
101 |
|
|
virtual ::gig::File* Create(String Key, GigConsumer* pConsumer, void*& pArg); |
102 |
|
|
virtual void Destroy(::gig::File* pResource, void* pArg); |
103 |
|
|
virtual void OnBorrow(::gig::File* pResource, GigConsumer* pConsumer, void*& pArg) {} // ignore |
104 |
schoenebeck |
411 |
public: |
105 |
|
|
virtual ~GigResourceManager() {} |
106 |
schoenebeck |
53 |
} Gigs; |
107 |
|
|
|
108 |
schoenebeck |
411 |
void CacheInitialSamples(::gig::Sample* pSample, gig::EngineChannel* pEngineChannel); |
109 |
schoenebeck |
53 |
}; |
110 |
|
|
|
111 |
|
|
/** |
112 |
|
|
* Will be thrown by the InstrumentResourceManager on errors. |
113 |
|
|
*/ |
114 |
|
|
class InstrumentResourceManagerException : public LinuxSamplerException { |
115 |
|
|
public: |
116 |
|
|
InstrumentResourceManagerException(String msg) : LinuxSamplerException(msg) {} |
117 |
|
|
}; |
118 |
|
|
|
119 |
|
|
}} // namespace LinuxSampler::gig |
120 |
|
|
|
121 |
|
|
#endif // __LS_GIG_INSTRUMENTRESOURCEMANAGER_H__ |