10 |
#include "common/global.h" |
#include "common/global.h" |
11 |
#include "scriptvm/ScriptVM.h" |
#include "scriptvm/ScriptVM.h" |
12 |
#include "shell/CFmt.h" |
#include "shell/CFmt.h" |
13 |
|
#include "engines/common/InstrumentScriptVM.h" |
14 |
|
#include "engines/gig/InstrumentScriptVM.h" |
15 |
|
#include <iostream> |
16 |
|
|
17 |
/* |
/* |
18 |
This command line tool is currently merely for development and testing |
This command line tool is currently merely for development and testing |
19 |
purposes, regarding the real-time instrument script feature of the sampler. |
purposes, regarding the real-time instrument script feature of the sampler. |
20 |
You can use this command line application like this: |
You can use this command line application like this: |
21 |
|
|
22 |
ls_instr_script < src/scriptvm/examples/helloworld.txt |
ls_instr_script core < src/scriptvm/examples/helloworld.txt |
23 |
|
|
24 |
Which will peform 3 things: |
Which will peform 3 things: |
25 |
|
|
31 |
*/ |
*/ |
32 |
|
|
33 |
using namespace LinuxSampler; |
using namespace LinuxSampler; |
34 |
|
using namespace std; |
35 |
|
|
36 |
int main() { |
static void printUsage() { |
37 |
ScriptVM vm; |
cout << "ls_instr_script - Parse real-time instrument script from stdin." << endl; |
38 |
VMParserContext* parserContext = vm.loadScript(&std::cin); |
cout << endl; |
39 |
|
cout << "Usage: ls_instr_script ENGINE" << endl; |
40 |
|
cout << endl; |
41 |
|
cout << " ENGINE\n"; |
42 |
|
cout << " Either \"core\", \"gig\", \"sf2\" or \"sfz\"." << endl; |
43 |
|
cout << endl; |
44 |
|
cout << "If you pass \"core\" as argument, only the core language built-in" << endl; |
45 |
|
cout << "variables and functions are available. However in this particular" << endl; |
46 |
|
cout << "mode the program will not just parse the given script, but also" << endl; |
47 |
|
cout << "execute the event handlers. All other arguments for ENGINE provide" << endl; |
48 |
|
cout << "the sampler engine / sampler format specific additional built-in" << endl; |
49 |
|
cout << "variables and functions, however they wil not be executed by this" << endl; |
50 |
|
cout << "program." << endl; |
51 |
|
cout << endl; |
52 |
|
} |
53 |
|
|
54 |
|
int main(int argc, char *argv[]) { |
55 |
|
if (argc < 2) { |
56 |
|
printUsage(); |
57 |
|
return -1; |
58 |
|
} |
59 |
|
String engine = argv[1]; |
60 |
|
bool runScript = false; |
61 |
|
|
62 |
|
ScriptVM* vm; |
63 |
|
if (engine == "core") { |
64 |
|
vm = new ScriptVM; |
65 |
|
runScript = true; |
66 |
|
} else if (engine == "sf2" || engine == "sfz") { |
67 |
|
vm = new InstrumentScriptVM; |
68 |
|
} else if (engine == "gig") { |
69 |
|
vm = new gig::InstrumentScriptVM; |
70 |
|
} else { |
71 |
|
std::cerr << "Unknown ENGINE '" << engine << "'\n\n"; |
72 |
|
printUsage(); |
73 |
|
return -1; |
74 |
|
} |
75 |
|
|
76 |
|
VMParserContext* parserContext = vm->loadScript(&std::cin); |
77 |
|
|
78 |
std::vector<ParserIssue> errors = parserContext->errors(); |
std::vector<ParserIssue> errors = parserContext->errors(); |
79 |
std::vector<ParserIssue> warnings = parserContext->warnings(); |
std::vector<ParserIssue> warnings = parserContext->warnings(); |
98 |
} |
} |
99 |
|
|
100 |
printf("[Dumping parsed VM tree]\n"); |
printf("[Dumping parsed VM tree]\n"); |
101 |
vm.dumpParsedScript(parserContext); |
vm->dumpParsedScript(parserContext); |
102 |
printf("[End of parsed VM tree]\n"); |
printf("[End of parsed VM tree]\n"); |
103 |
|
|
104 |
if (!errors.empty()) { |
if (!errors.empty()) { |
106 |
return -1; |
return -1; |
107 |
} |
} |
108 |
|
|
109 |
|
if (!runScript) { |
110 |
|
return 0; |
111 |
|
} |
112 |
|
|
113 |
if (!parserContext->eventHandler(0)) { |
if (!parserContext->eventHandler(0)) { |
114 |
printf("No event handler exists. So nothing to execute.\n"); |
printf("No event handler exists. So nothing to execute.\n"); |
115 |
if (parserContext) delete parserContext; |
if (parserContext) delete parserContext; |
117 |
} |
} |
118 |
|
|
119 |
printf("Preparing execution of script.\n"); |
printf("Preparing execution of script.\n"); |
120 |
VMExecContext* execContext = vm.createExecContext(parserContext); |
VMExecContext* execContext = vm->createExecContext(parserContext); |
121 |
for (int i = 0; parserContext->eventHandler(i); ++i) { |
for (int i = 0; parserContext->eventHandler(i); ++i) { |
122 |
VMEventHandler* handler = parserContext->eventHandler(i); |
VMEventHandler* handler = parserContext->eventHandler(i); |
123 |
printf("[Running event handler '%s']\n", handler->eventHandlerName().c_str()); |
printf("[Running event handler '%s']\n", handler->eventHandlerName().c_str()); |
124 |
VMExecStatus_t result = vm.exec(parserContext, execContext, handler); |
VMExecStatus_t result = vm->exec(parserContext, execContext, handler); |
125 |
CFmt fmt; |
CFmt fmt; |
126 |
if (result & VM_EXEC_ERROR) { |
if (result & VM_EXEC_ERROR) { |
127 |
fmt.red(); |
fmt.red(); |
141 |
printf("[Event handler '%s' finished with UNKNOWN status]\n", handler->eventHandlerName().c_str()); |
printf("[Event handler '%s' finished with UNKNOWN status]\n", handler->eventHandlerName().c_str()); |
142 |
} |
} |
143 |
} |
} |
144 |
|
|
145 |
if (parserContext) delete parserContext; |
if (parserContext) delete parserContext; |
146 |
if (execContext) delete execContext; |
if (execContext) delete execContext; |
147 |
|
if (vm) delete vm; |
148 |
|
|
149 |
return 0; |
return 0; |
150 |
} |
} |