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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2598 - (show annotations) (download)
Fri Jun 6 12:38:54 2014 UTC (5 years, 11 months ago) by schoenebeck
File size: 2341 byte(s)
* ScriptVM (WIP): Built-in script function "play_note()" now returns the
  event ID of the triggered note.
* ScriptVM (WIP): Implemented built-in script int variable $EVENT_ID.
* ScriptVM (WIP): Implemented built-in script function "ignore_event()".
* ScriptVM (WIP): Implemented built-in script function
  "ignore_controller()" (accepts one and no argument).
* Bumped version (1.0.0.svn44).

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

  ViewVC Help
Powered by ViewVC