/[svn]/linuxsampler/trunk/src/engines/common/AbstractInstrumentManager.h
ViewVC logotype

Annotation of /linuxsampler/trunk/src/engines/common/AbstractInstrumentManager.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 4017 - (hide annotations) (download) (as text)
Mon Jan 3 16:09:59 2022 UTC (2 years, 3 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 5745 byte(s)
AbstractInstrumentManager: add method GetInstrumentManagerThread()

This new method must not be added directly to its base class
'InstrumentManager', because the latter is exported to the public C++ API
while the 'InstrumentManagerThread' class however was intentionally not
exported to the public C++ API. Being able to access the (singleton)
InstrumentManagerThread object is useful though for the sampler internal
components like the individual sampler engine implementations, to avoid
redeclaring its methods in other classes like (Abstract)InstrumentManager,
hence adding this method to 'AbstractInstrumentManager' as the latter is
a private, sampler internal class as well.

1 schoenebeck 2611 /*
2 schoenebeck 4017 * Copyright (c) 2014-2022 Christian Schoenebeck
3 schoenebeck 2611 *
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 schoenebeck 4017 #include "../InstrumentManagerThread.h"
18 schoenebeck 2611
19     namespace LinuxSampler {
20    
21     typedef ResourceConsumer<VMParserContext> InstrumentScriptConsumer;
22    
23 schoenebeck 3971 /**
24     * Identifies uniquely a compiled script.
25     *
26     * Note: every engine channel now has its own compiled script object
27     * (a.k.a. VMParserContext). Originally a compiled script was shared by
28     * multiple engine channels. This was wrong: we cannot share compiled
29     * script instances among multiple engine channels (parts), for two
30     * reasons:
31     *
32     * 1. VMParserContext not only encompasses the compiled tree
33     * presentation of the requested script, but also global variables
34     * and we don't want those global variables to be modified by
35     * different sampler parts, as this would not be expected behaviour
36     * by instrument script authors.
37     *
38     * 2. If there is more than one sampler engine instance (e.g. if there
39     * are multiple audio output device instances) this would even crash,
40     * because each sampler engine instance has its own ScriptVM
41     * instance, and a (VM)ParserContext is always tied to exactly one
42     * ScriptVM instance.
43     *
44     * We would not be buying much by sharing compiled scripts anyway, as a
45     * script usually compiles in couple microseconds and RAM usage is also
46     * neglectable.
47     */
48 schoenebeck 3733 struct ScriptKey {
49     String code; ///< Script's source code.
50     std::map<String,String> patchVars; ///< Patch variables being overridden by instrument.
51 schoenebeck 3971 EngineChannel* engineChannel; ///< Unique owning engine channel on which the compiled script is/was loaded onto.
52 schoenebeck 3733 bool wildcardPatchVars; ///< Seldom use: Allows lookup for consumers of a specific script by ignoring all (overridden) patch variables.
53 schoenebeck 3971 bool wildcardEngineChannel; ///< Seldom use: Allows lookup for consumers of a specific script by ignoring on which engine channel it was loaded.
54 schoenebeck 3733
55     inline bool operator<(const ScriptKey& o) const {
56 schoenebeck 3971 if (wildcardPatchVars && wildcardEngineChannel)
57 schoenebeck 3733 return code < o.code;
58 schoenebeck 3971 else if (wildcardPatchVars)
59     return code < o.code || (code == o.code && engineChannel < o.engineChannel);
60     else if (wildcardEngineChannel)
61     return code < o.code || (code == o.code && patchVars < o.patchVars);
62 schoenebeck 3733 else
63 schoenebeck 3971 return code < o.code || (code == o.code && (patchVars < o.patchVars || (patchVars == o.patchVars && engineChannel < o.engineChannel)));
64 schoenebeck 3733 }
65    
66     inline bool operator>(const ScriptKey& o) const {
67 schoenebeck 3971 if (wildcardPatchVars && wildcardEngineChannel)
68 schoenebeck 3733 return code > o.code;
69 schoenebeck 3971 else if (wildcardPatchVars)
70     return code > o.code || (code == o.code && engineChannel > o.engineChannel);
71     else if (wildcardEngineChannel)
72     return code > o.code || (code == o.code && patchVars > o.patchVars);
73 schoenebeck 3733 else
74 schoenebeck 3971 return code > o.code || (code == o.code && (patchVars > o.patchVars || (patchVars == o.patchVars && engineChannel > o.engineChannel)));
75 schoenebeck 3733 }
76    
77     inline bool operator==(const ScriptKey& o) const {
78 schoenebeck 3971 if (wildcardPatchVars && wildcardEngineChannel)
79 schoenebeck 3733 return code == o.code;
80 schoenebeck 3971 else if (wildcardPatchVars)
81     return code == o.code && engineChannel == o.engineChannel;
82     else if (wildcardEngineChannel)
83     return code == o.code && patchVars == o.patchVars;
84 schoenebeck 3733 else
85 schoenebeck 3971 return code == o.code && patchVars == o.patchVars && engineChannel == o.engineChannel;
86 schoenebeck 3733 }
87    
88     inline bool operator!=(const ScriptKey& o) const {
89     return !(operator==(o));
90     }
91     };
92    
93 schoenebeck 2611 class AbstractInstrumentManager : public InstrumentManager {
94     public:
95     AbstractInstrumentManager() { }
96 schoenebeck 4017 InstrumentManagerThread* GetInstrumentManagerThread();
97 schoenebeck 2611 virtual ~AbstractInstrumentManager() { }
98    
99 schoenebeck 2902 /**
100     * Resource manager for loading and sharing the parsed (executable) VM
101     * presentation of real-time instrument scripts. The key used here, and
102     * associated with each script resource, is not as one might expect the
103     * script name or something equivalent, instead the key used is
104 schoenebeck 3733 * actually the entire script's source code text (and additionally
105     * potentially patched variables). The value (the actual resource) is of
106     * type @c VMParserContext, which is the parsed (executable) VM
107     * representation of the respective script.
108 schoenebeck 2902 */
109 schoenebeck 3733 class ScriptResourceManager : public ResourceManager<ScriptKey, VMParserContext> {
110 schoenebeck 2611 public:
111     ScriptResourceManager() {}
112     virtual ~ScriptResourceManager() {}
113     protected:
114     // implementation of derived abstract methods from 'ResourceManager'
115 schoenebeck 3733 virtual VMParserContext* Create(ScriptKey key, InstrumentScriptConsumer* pConsumer, void*& pArg);
116 schoenebeck 2611 virtual void Destroy(VMParserContext* pResource, void* pArg);
117     virtual void OnBorrow(VMParserContext* pResource, InstrumentScriptConsumer* pConsumer, void*& pArg) {} // ignore
118     } scripts;
119     };
120    
121     } // namespace LinuxSampler
122    
123     #endif // LS_ABSTRACTINSTRUMENTMANAGER_H

  ViewVC Help
Powered by ViewVC