1 |
schoenebeck |
2581 |
/* |
2 |
|
|
* Copyright (c) 2014 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_SCRIPTVM_H |
11 |
|
|
#define LS_SCRIPTVM_H |
12 |
|
|
|
13 |
|
|
#include <iostream> |
14 |
|
|
#include <vector> |
15 |
|
|
|
16 |
|
|
#include "../common/global.h" |
17 |
|
|
#include "common.h" |
18 |
|
|
#include "CoreVMFunctions.h" |
19 |
|
|
|
20 |
|
|
namespace LinuxSampler { |
21 |
|
|
|
22 |
|
|
class ParserContext; |
23 |
schoenebeck |
2588 |
class ExecContext; |
24 |
schoenebeck |
2581 |
|
25 |
schoenebeck |
2594 |
/** @brief Core virtual machine for real-time instrument scripts. |
26 |
|
|
* |
27 |
|
|
* This is the core of the virtual machine, used for running real-time |
28 |
|
|
* instrument scripts. The core encompasses the instrument script parser, |
29 |
|
|
* generalized virtual machine and very generic built-in script functions. |
30 |
|
|
* Thus this class only provides functionalities which are yet independent |
31 |
|
|
* of the actual purpose the virtual machine is going to be used for. |
32 |
|
|
* |
33 |
|
|
* The actual use case specific functionalites (i.e. MIDI processing) is |
34 |
|
|
* then implemented by VM classes which are derived from this generalized |
35 |
|
|
* ScriptVM class. |
36 |
|
|
* |
37 |
|
|
* This class is re-entrant safe, but not thread safe. So you can share one |
38 |
|
|
* instance of this class between multiple (native) threads, but you @b must |
39 |
|
|
* @b not execute methods of the same class instance simultaniously from |
40 |
|
|
* different (native) threads. If you want to execute scripts simultaniously |
41 |
|
|
* multi threaded, then create a separate ScriptVM instance for each |
42 |
|
|
* (native) thread. Also note that one VMParserContext instance is tied to |
43 |
|
|
* exactly one ScriptVM instance. So you @b must @b not create a |
44 |
|
|
* VMParserContext with one ScriptVM instance and run it with a different |
45 |
|
|
* ScriptVM instance! |
46 |
|
|
*/ |
47 |
schoenebeck |
2581 |
class ScriptVM : public VMFunctionProvider { |
48 |
|
|
public: |
49 |
|
|
ScriptVM(); |
50 |
|
|
virtual ~ScriptVM(); |
51 |
schoenebeck |
2588 |
VMParserContext* loadScript(const String& s); |
52 |
|
|
VMParserContext* loadScript(std::istream* is); |
53 |
|
|
void dumpParsedScript(VMParserContext* context); |
54 |
|
|
VMExecContext* createExecContext(VMParserContext* parserContext); |
55 |
|
|
VMExecStatus_t exec(VMParserContext* parserContext, VMExecContext* execContex, VMEventHandler* handler); |
56 |
schoenebeck |
2594 |
VMFunction* functionByName(const String& name) OVERRIDE; |
57 |
|
|
std::map<String,VMIntRelPtr*> builtInIntVariables() OVERRIDE; |
58 |
|
|
std::map<String,VMInt8Array*> builtInIntArrayVariables() OVERRIDE; |
59 |
|
|
std::map<String,int> builtInConstIntVariables() OVERRIDE; |
60 |
schoenebeck |
2588 |
|
61 |
|
|
VMParserContext* currentVMParserContext(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions) |
62 |
|
|
VMExecContext* currentVMExecContext(); //TODO: should be protected (only usable during exec() calls, intended only for VMFunctions) |
63 |
schoenebeck |
2581 |
protected: |
64 |
schoenebeck |
2588 |
ParserContext* m_parserContext; |
65 |
schoenebeck |
2581 |
CoreVMFunction_message fnMessage; |
66 |
|
|
CoreVMFunction_exit fnExit; |
67 |
|
|
CoreVMFunction_wait fnWait; |
68 |
|
|
}; |
69 |
|
|
|
70 |
|
|
} // namespace LinuxSampler |
71 |
|
|
|
72 |
|
|
#endif // LS_INSTRUMENTSCRIPTVM_H |