/[svn]/linuxsampler/trunk/src/scriptvm/CoreVMFunctions.cpp
ViewVC logotype

Annotation of /linuxsampler/trunk/src/scriptvm/CoreVMFunctions.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2596 - (hide annotations) (download)
Thu Jun 5 19:39:12 2014 UTC (9 years, 10 months ago) by schoenebeck
File size: 2254 byte(s)
* ScriptVM (WIP): Implemented execution of script event
  handlers "note" and "release".
* ScriptVM (WIP): Implemented built-in script function
  "play_note()" (only two of the max. four function
  arguments are currently implemented yet though).
* ScriptVM (WIP): Fixed incorrect handling of
  suspended scripts.
* Bumped version (1.0.0.svn43).

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     #include "CoreVMFunctions.h"
11    
12     #include <iostream>
13     #include "tree.h"
14     #include "ScriptVM.h"
15    
16     namespace LinuxSampler {
17    
18     VMFnResult* VMEmptyResultFunction::errorResult() {
19     result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED);
20     return &result;
21     }
22    
23 schoenebeck 2596 void VMEmptyResultFunction::wrnMsg(const String& txt) {
24     std::cout << "[ScriptVM] " << txt << std::endl;
25     }
26    
27     void VMEmptyResultFunction::errMsg(const String& txt) {
28     std::cerr << "[ScriptVM] " << txt << std::endl;
29     }
30    
31 schoenebeck 2581 VMFnResult* VMEmptyResultFunction::successResult() {
32     result.flags = STMT_SUCCESS;
33     return &result;
34     }
35    
36     VMFnResult* VMStringResultFunction::errorResult(const String& s) {
37     result.flags = StmtFlags_t(STMT_ABORT_SIGNALLED | STMT_ERROR_OCCURRED);
38     result.value = s;
39     return &result;
40     }
41    
42     VMFnResult* VMStringResultFunction::successResult(const String& s) {
43     result.flags = STMT_SUCCESS;
44     result.value = s;
45     return &result;
46     }
47    
48     bool CoreVMFunction_message::acceptsArgType(int iArg, ExprType_t type) const {
49     return type == INT_EXPR || type == STRING_EXPR;
50     }
51    
52     VMFnResult* CoreVMFunction_message::exec(VMFnArgs* args) {
53     if (!args->argsCount()) return errorResult();
54    
55     VMStringExpr* strExpr = dynamic_cast<VMStringExpr*>(args->arg(0));
56     if (strExpr) {
57     std::cout << "[ScriptVM] " << strExpr->evalStr() << "\n";
58     return successResult();
59     }
60    
61     VMIntExpr* intExpr = dynamic_cast<VMIntExpr*>(args->arg(0));
62     if (intExpr) {
63     std::cout << "[ScriptVM] " << intExpr->evalInt() << "\n";
64     return successResult();
65     }
66    
67     return errorResult();
68     }
69    
70     VMFnResult* CoreVMFunction_exit::exec(VMFnArgs* args) {
71     this->result.flags = STMT_ABORT_SIGNALLED;
72     return &result;
73     }
74    
75     VMFnResult* CoreVMFunction_wait::exec(VMFnArgs* args) {
76     ExecContext* ctx = dynamic_cast<ExecContext*>(vm->currentVMExecContext());
77     VMIntExpr* expr = dynamic_cast<VMIntExpr*>(args->arg(0));
78     ctx->suspendMicroseconds = expr->evalInt();
79     this->result.flags = STMT_SUSPEND_SIGNALLED;
80     return &result;
81     }
82    
83     } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC