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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 schoenebeck 2581 /*
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 schoenebeck 2588 ScriptVM vm;
34     VMParserContext* parserContext = vm.loadScript(&std::cin);
35 schoenebeck 2581
36 schoenebeck 2588 std::vector<ParserIssue> errors = parserContext->errors();
37     std::vector<ParserIssue> warnings = parserContext->warnings();
38     std::vector<ParserIssue> issues = parserContext->issues();
39 schoenebeck 2581 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 schoenebeck 2588 vm.dumpParsedScript(parserContext);
60 schoenebeck 2581 printf("[End of parsed VM tree]\n");
61    
62 schoenebeck 2588 if (!errors.empty()) {
63     if (parserContext) delete parserContext;
64     return -1;
65     }
66 schoenebeck 2581
67 schoenebeck 2588 if (!parserContext->eventHandler(0)) {
68 schoenebeck 2581 printf("No event handler exists. So nothing to execute.\n");
69 schoenebeck 2588 if (parserContext) delete parserContext;
70 schoenebeck 2581 return 0;
71     }
72    
73     printf("Preparing execution of script.\n");
74 schoenebeck 2588 VMExecContext* execContext = vm.createExecContext(parserContext);
75     for (int i = 0; parserContext->eventHandler(i); ++i) {
76     VMEventHandler* handler = parserContext->eventHandler(i);
77 schoenebeck 2581 printf("[Running event handler '%s']\n", handler->eventHandlerName().c_str());
78 schoenebeck 2588 VMExecStatus_t result = vm.exec(parserContext, execContext, handler);
79 schoenebeck 2581 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 schoenebeck 2588 handler->eventHandlerName().c_str(), execContext->suspensionTimeMicroseconds());
87 schoenebeck 2581 } 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 schoenebeck 2588 if (parserContext) delete parserContext;
99     if (execContext) delete execContext;
100 schoenebeck 2581
101     return 0;
102     }

  ViewVC Help
Powered by ViewVC