1 |
/* |
2 |
* Copyright (c) 2014-2020 Christian Schoenebeck |
3 |
* |
4 |
* http://www.linuxsampler.org |
5 |
* |
6 |
* This file is part of LinuxSampler and released under the same terms. |
7 |
* See README file for details. |
8 |
*/ |
9 |
|
10 |
#ifndef LS_ABSTRACTINSTRUMENTMANAGER_H |
11 |
#define LS_ABSTRACTINSTRUMENTMANAGER_H |
12 |
|
13 |
#include "../InstrumentManager.h" |
14 |
#include "../../common/ResourceManager.h" |
15 |
#include "../../common/global_private.h" |
16 |
#include "InstrumentScriptVM.h" |
17 |
|
18 |
namespace LinuxSampler { |
19 |
|
20 |
typedef ResourceConsumer<VMParserContext> InstrumentScriptConsumer; |
21 |
|
22 |
/// Identifies uniquely a compiled script. |
23 |
struct ScriptKey { |
24 |
String code; ///< Script's source code. |
25 |
std::map<String,String> patchVars; ///< Patch variables being overridden by instrument. |
26 |
bool wildcardPatchVars; ///< Seldom use: Allows lookup for consumers of a specific script by ignoring all (overridden) patch variables. |
27 |
|
28 |
inline bool operator<(const ScriptKey& o) const { |
29 |
if (wildcardPatchVars) |
30 |
return code < o.code; |
31 |
else |
32 |
return code < o.code || (code == o.code && patchVars < o.patchVars); |
33 |
} |
34 |
|
35 |
inline bool operator>(const ScriptKey& o) const { |
36 |
if (wildcardPatchVars) |
37 |
return code > o.code; |
38 |
else |
39 |
return code > o.code || (code == o.code && patchVars > o.patchVars); |
40 |
} |
41 |
|
42 |
inline bool operator==(const ScriptKey& o) const { |
43 |
if (wildcardPatchVars) |
44 |
return code == o.code; |
45 |
else |
46 |
return code == o.code && patchVars == o.patchVars; |
47 |
} |
48 |
|
49 |
inline bool operator!=(const ScriptKey& o) const { |
50 |
return !(operator==(o)); |
51 |
} |
52 |
}; |
53 |
|
54 |
class AbstractInstrumentManager : public InstrumentManager { |
55 |
public: |
56 |
AbstractInstrumentManager() { } |
57 |
virtual ~AbstractInstrumentManager() { } |
58 |
|
59 |
/** |
60 |
* Resource manager for loading and sharing the parsed (executable) VM |
61 |
* presentation of real-time instrument scripts. The key used here, and |
62 |
* associated with each script resource, is not as one might expect the |
63 |
* script name or something equivalent, instead the key used is |
64 |
* actually the entire script's source code text (and additionally |
65 |
* potentially patched variables). The value (the actual resource) is of |
66 |
* type @c VMParserContext, which is the parsed (executable) VM |
67 |
* representation of the respective script. |
68 |
*/ |
69 |
class ScriptResourceManager : public ResourceManager<ScriptKey, VMParserContext> { |
70 |
public: |
71 |
ScriptResourceManager() {} |
72 |
virtual ~ScriptResourceManager() {} |
73 |
protected: |
74 |
// implementation of derived abstract methods from 'ResourceManager' |
75 |
virtual VMParserContext* Create(ScriptKey key, InstrumentScriptConsumer* pConsumer, void*& pArg); |
76 |
virtual void Destroy(VMParserContext* pResource, void* pArg); |
77 |
virtual void OnBorrow(VMParserContext* pResource, InstrumentScriptConsumer* pConsumer, void*& pArg) {} // ignore |
78 |
} scripts; |
79 |
}; |
80 |
|
81 |
} // namespace LinuxSampler |
82 |
|
83 |
#endif // LS_ABSTRACTINSTRUMENTMANAGER_H |