1 |
/* |
/* |
2 |
* Copyright (c) 2014-2020 Christian Schoenebeck |
* Copyright (c) 2014-2021 Christian Schoenebeck |
3 |
* |
* |
4 |
* http://www.linuxsampler.org |
* http://www.linuxsampler.org |
5 |
* |
* |
19 |
|
|
20 |
typedef ResourceConsumer<VMParserContext> InstrumentScriptConsumer; |
typedef ResourceConsumer<VMParserContext> InstrumentScriptConsumer; |
21 |
|
|
22 |
/// Identifies uniquely a compiled script. |
/** |
23 |
|
* Identifies uniquely a compiled script. |
24 |
|
* |
25 |
|
* Note: every engine channel now has its own compiled script object |
26 |
|
* (a.k.a. VMParserContext). Originally a compiled script was shared by |
27 |
|
* multiple engine channels. This was wrong: we cannot share compiled |
28 |
|
* script instances among multiple engine channels (parts), for two |
29 |
|
* reasons: |
30 |
|
* |
31 |
|
* 1. VMParserContext not only encompasses the compiled tree |
32 |
|
* presentation of the requested script, but also global variables |
33 |
|
* and we don't want those global variables to be modified by |
34 |
|
* different sampler parts, as this would not be expected behaviour |
35 |
|
* by instrument script authors. |
36 |
|
* |
37 |
|
* 2. If there is more than one sampler engine instance (e.g. if there |
38 |
|
* are multiple audio output device instances) this would even crash, |
39 |
|
* because each sampler engine instance has its own ScriptVM |
40 |
|
* instance, and a (VM)ParserContext is always tied to exactly one |
41 |
|
* ScriptVM instance. |
42 |
|
* |
43 |
|
* We would not be buying much by sharing compiled scripts anyway, as a |
44 |
|
* script usually compiles in couple microseconds and RAM usage is also |
45 |
|
* neglectable. |
46 |
|
*/ |
47 |
struct ScriptKey { |
struct ScriptKey { |
48 |
String code; ///< Script's source code. |
String code; ///< Script's source code. |
49 |
std::map<String,String> patchVars; ///< Patch variables being overridden by instrument. |
std::map<String,String> patchVars; ///< Patch variables being overridden by instrument. |
50 |
|
EngineChannel* engineChannel; ///< Unique owning engine channel on which the compiled script is/was loaded onto. |
51 |
bool wildcardPatchVars; ///< Seldom use: Allows lookup for consumers of a specific script by ignoring all (overridden) patch variables. |
bool wildcardPatchVars; ///< Seldom use: Allows lookup for consumers of a specific script by ignoring all (overridden) patch variables. |
52 |
|
bool wildcardEngineChannel; ///< Seldom use: Allows lookup for consumers of a specific script by ignoring on which engine channel it was loaded. |
53 |
|
|
54 |
inline bool operator<(const ScriptKey& o) const { |
inline bool operator<(const ScriptKey& o) const { |
55 |
if (wildcardPatchVars) |
if (wildcardPatchVars && wildcardEngineChannel) |
56 |
return code < o.code; |
return code < o.code; |
57 |
else |
else if (wildcardPatchVars) |
58 |
|
return code < o.code || (code == o.code && engineChannel < o.engineChannel); |
59 |
|
else if (wildcardEngineChannel) |
60 |
return code < o.code || (code == o.code && patchVars < o.patchVars); |
return code < o.code || (code == o.code && patchVars < o.patchVars); |
61 |
|
else |
62 |
|
return code < o.code || (code == o.code && (patchVars < o.patchVars || (patchVars == o.patchVars && engineChannel < o.engineChannel))); |
63 |
} |
} |
64 |
|
|
65 |
inline bool operator>(const ScriptKey& o) const { |
inline bool operator>(const ScriptKey& o) const { |
66 |
if (wildcardPatchVars) |
if (wildcardPatchVars && wildcardEngineChannel) |
67 |
return code > o.code; |
return code > o.code; |
68 |
else |
else if (wildcardPatchVars) |
69 |
|
return code > o.code || (code == o.code && engineChannel > o.engineChannel); |
70 |
|
else if (wildcardEngineChannel) |
71 |
return code > o.code || (code == o.code && patchVars > o.patchVars); |
return code > o.code || (code == o.code && patchVars > o.patchVars); |
72 |
|
else |
73 |
|
return code > o.code || (code == o.code && (patchVars > o.patchVars || (patchVars == o.patchVars && engineChannel > o.engineChannel))); |
74 |
} |
} |
75 |
|
|
76 |
inline bool operator==(const ScriptKey& o) const { |
inline bool operator==(const ScriptKey& o) const { |
77 |
if (wildcardPatchVars) |
if (wildcardPatchVars && wildcardEngineChannel) |
78 |
return code == o.code; |
return code == o.code; |
79 |
else |
else if (wildcardPatchVars) |
80 |
|
return code == o.code && engineChannel == o.engineChannel; |
81 |
|
else if (wildcardEngineChannel) |
82 |
return code == o.code && patchVars == o.patchVars; |
return code == o.code && patchVars == o.patchVars; |
83 |
|
else |
84 |
|
return code == o.code && patchVars == o.patchVars && engineChannel == o.engineChannel; |
85 |
} |
} |
86 |
|
|
87 |
inline bool operator!=(const ScriptKey& o) const { |
inline bool operator!=(const ScriptKey& o) const { |