/[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 2581 - (show annotations) (download)
Fri May 30 12:48:05 2014 UTC (5 years, 5 months ago) by schoenebeck
File size: 3509 byte(s)
* (WIP) Implemented parser and VM for upcoming new real-time instrument
  script support. It needs yet to be integrated into the sampler's
  sampler engines. You can toy around for now with the command line tool
  "ls_instr_script" and i.e. examples showing the core language features
  under src/scriptvm/examples/.
* Bumped version (1.0.0.svn41).

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 script;
34 script.loadScript(&std::cin);
35
36 std::vector<ParserIssue> errors = script.errors();
37 std::vector<ParserIssue> warnings = script.warnings();
38 std::vector<ParserIssue> issues = script.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 script.dumpParsedScript();
60 printf("[End of parsed VM tree]\n");
61
62 if (!errors.empty()) return -1;
63
64 if (!script.eventHandler(0)) {
65 printf("No event handler exists. So nothing to execute.\n");
66 return 0;
67 }
68
69 printf("Preparing execution of script.\n");
70 VMExecContext* ctx = script.createExecContext();
71 for (int i = 0; script.eventHandler(i); ++i) {
72 VMEventHandler* handler = script.eventHandler(i);
73 printf("[Running event handler '%s']\n", handler->eventHandlerName().c_str());
74 VMExecStatus_t result = script.exec(handler, ctx);
75 CFmt fmt;
76 if (result & VM_EXEC_ERROR) {
77 fmt.red();
78 printf("[Event handler '%s' finished with ERROR status]\n", handler->eventHandlerName().c_str());
79 } else if (result & VM_EXEC_SUSPENDED) {
80 fmt.yellow();
81 printf("[Event handler '%s' returned with SUSPENDED status: %d microseconds]\n",
82 handler->eventHandlerName().c_str(), ctx->suspensionTimeMicroseconds());
83 } else if (!(result & VM_EXEC_RUNNING)) {
84 fmt.green();
85 printf("[Event handler '%s' finished with SUCCESS status]\n", handler->eventHandlerName().c_str());
86 } else if (result & VM_EXEC_RUNNING) {
87 fmt.cyan();
88 printf("[Event handler '%s' finished with RUNNING status]\n", handler->eventHandlerName().c_str());
89 } else {
90 fmt.red();
91 printf("[Event handler '%s' finished with UNKNOWN status]\n", handler->eventHandlerName().c_str());
92 }
93 }
94 if (ctx) delete ctx;
95
96 return 0;
97 }

  ViewVC Help
Powered by ViewVC