/[svn]/linuxsampler/trunk/src/ls_instr_script.cpp
ViewVC logotype

Contents of /linuxsampler/trunk/src/ls_instr_script.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2588 - (show annotations) (download)
Sun Jun 1 14:44:38 2014 UTC (9 years, 10 months ago) by schoenebeck
File size: 3810 byte(s)
* ScriptVM: refactoring and fixes.

1 /*
2 * Copyright (c) 2014 Christian Schoenebeck
3 *
4 * http://www.linuxsampler.org
5 *
6 * This program is part of LinuxSampler and released under the same terms.
7 * See README file for details.
8 */
9
10 #include "common/global.h"
11 #include "scriptvm/ScriptVM.h"
12 #include "shell/CFmt.h"
13
14 /*
15 This command line tool is currently merely for development and testing
16 purposes, regarding the real-time instrument script feature of the sampler.
17 You can use this command line application like this:
18
19 ls_instr_script < src/scriptvm/examples/helloworld.txt
20
21 Which will peform 3 things:
22
23 1. Parses the given instrument script and prints any parser errors or
24 warnings.
25 2. It dumps the parsed VM tree (only interesting for LS developers).
26 3. If there were not parser errors, it will run each event handler defined in
27 the script.
28 */
29
30 using namespace LinuxSampler;
31
32 int main() {
33 ScriptVM vm;
34 VMParserContext* parserContext = vm.loadScript(&std::cin);
35
36 std::vector<ParserIssue> errors = parserContext->errors();
37 std::vector<ParserIssue> warnings = parserContext->warnings();
38 std::vector<ParserIssue> issues = parserContext->issues();
39 if (warnings.empty() && errors.empty()) {
40 CFmt fmt; fmt.green();
41 printf("EOF. Script parse completed successfully (no errors, no warnings).\n");
42 } else if (!errors.empty()) {
43 CFmt fmt; fmt.red();
44 printf("EOF. Script parse completed with issues (%d errors, %d warnings):\n",
45 errors.size(), warnings.size());
46 } else {
47 CFmt fmt; fmt.yellow();
48 printf("EOF. Script parse completed with issues (%d errors, %d warnings):\n",
49 errors.size(), warnings.size());
50 }
51 for (int i = 0; i < issues.size(); ++i) {
52 CFmt fmt;
53 if (issues[i].isWrn()) fmt.yellow();
54 else if (issues[i].isErr()) fmt.red();
55 issues[i].dump();
56 }
57
58 printf("[Dumping parsed VM tree]\n");
59 vm.dumpParsedScript(parserContext);
60 printf("[End of parsed VM tree]\n");
61
62 if (!errors.empty()) {
63 if (parserContext) delete parserContext;
64 return -1;
65 }
66
67 if (!parserContext->eventHandler(0)) {
68 printf("No event handler exists. So nothing to execute.\n");
69 if (parserContext) delete parserContext;
70 return 0;
71 }
72
73 printf("Preparing execution of script.\n");
74 VMExecContext* execContext = vm.createExecContext(parserContext);
75 for (int i = 0; parserContext->eventHandler(i); ++i) {
76 VMEventHandler* handler = parserContext->eventHandler(i);
77 printf("[Running event handler '%s']\n", handler->eventHandlerName().c_str());
78 VMExecStatus_t result = vm.exec(parserContext, execContext, handler);
79 CFmt fmt;
80 if (result & VM_EXEC_ERROR) {
81 fmt.red();
82 printf("[Event handler '%s' finished with ERROR status]\n", handler->eventHandlerName().c_str());
83 } else if (result & VM_EXEC_SUSPENDED) {
84 fmt.yellow();
85 printf("[Event handler '%s' returned with SUSPENDED status: %d microseconds]\n",
86 handler->eventHandlerName().c_str(), execContext->suspensionTimeMicroseconds());
87 } else if (!(result & VM_EXEC_RUNNING)) {
88 fmt.green();
89 printf("[Event handler '%s' finished with SUCCESS status]\n", handler->eventHandlerName().c_str());
90 } else if (result & VM_EXEC_RUNNING) {
91 fmt.cyan();
92 printf("[Event handler '%s' finished with RUNNING status]\n", handler->eventHandlerName().c_str());
93 } else {
94 fmt.red();
95 printf("[Event handler '%s' finished with UNKNOWN status]\n", handler->eventHandlerName().c_str());
96 }
97 }
98 if (parserContext) delete parserContext;
99 if (execContext) delete execContext;
100
101 return 0;
102 }

  ViewVC Help
Powered by ViewVC