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

Diff of /linuxsampler/trunk/src/scriptvm/common.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 2598 by schoenebeck, Fri Jun 6 12:38:54 2014 UTC revision 3573 by schoenebeck, Tue Aug 27 21:36:53 2019 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014 Christian Schoenebeck   * Copyright (c) 2014-2019 Christian Schoenebeck
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 9  Line 9 
9    
10  #include "common.h"  #include "common.h"
11  #include <iostream>  #include <iostream>
12    #include "editor/SourceToken.h"
13    
14  namespace LinuxSampler {  namespace LinuxSampler {
15    
16        ///////////////////////////////////////////////////////////////////////
17        // class 'VMUnit'
18    
19        static vmfloat _unitFactor(MetricPrefix_t prefix) {
20            switch (prefix) {
21                case VM_NO_PREFIX:  return 1.f;
22                case VM_KILO:       return 1000.f;
23                case VM_HECTO:      return 100.f;
24                case VM_DECA:       return 10.f;
25                case VM_DECI:       return 0.1f;
26                case VM_CENTI:      return 0.01f;
27                case VM_MILLI:      return 0.001f;
28                case VM_MICRO:      return 0.000001f;
29            }
30            return 1.f;
31        }
32    
33        vmfloat VMUnit::unitFactor(MetricPrefix_t prefix) {
34            return _unitFactor(prefix);
35        }
36    
37        vmfloat VMUnit::unitFactor(MetricPrefix_t prefix1, MetricPrefix_t prefix2) {
38            return _unitFactor(prefix1) * _unitFactor(prefix2);
39        }
40    
41        vmfloat VMUnit::unitFactor() const {
42            vmfloat f = 1.f;
43            for (vmuint i = 0; unitPrefix(i); ++i)
44                f *= _unitFactor(unitPrefix(i));
45            return f;
46        }
47    
48        ///////////////////////////////////////////////////////////////////////
49        // class 'VMExpr'
50    
51      VMIntExpr* VMExpr::asInt() const {      VMIntExpr* VMExpr::asInt() const {
52          return const_cast<VMIntExpr*>( dynamic_cast<const VMIntExpr*>(this) );          return const_cast<VMIntExpr*>( dynamic_cast<const VMIntExpr*>(this) );
53      }      }
54    
55        VMRealExpr* VMExpr::asReal() const {
56            return const_cast<VMRealExpr*>( dynamic_cast<const VMRealExpr*>(this) );
57        }
58    
59        VMScalarNumberExpr* VMExpr::asScalarNumberExpr() const {
60            return const_cast<VMScalarNumberExpr*>(
61                dynamic_cast<const VMScalarNumberExpr*>(this)
62            );
63        }
64    
65      VMStringExpr* VMExpr::asString() const {      VMStringExpr* VMExpr::asString() const {
66          return const_cast<VMStringExpr*>( dynamic_cast<const VMStringExpr*>(this) );          return const_cast<VMStringExpr*>( dynamic_cast<const VMStringExpr*>(this) );
67      }      }
68    
69        VMIntArrayExpr* VMExpr::asIntArray() const {
70            return const_cast<VMIntArrayExpr*>( dynamic_cast<const VMIntArrayExpr*>(this) );
71        }
72    
73        VMRealArrayExpr* VMExpr::asRealArray() const {
74            return const_cast<VMRealArrayExpr*>(
75                dynamic_cast<const VMRealArrayExpr*>(this)
76            );
77        }
78    
79        bool VMExpr::isModifyable() const {
80            const VMVariable* var = dynamic_cast<const VMVariable*>(this);
81            return (!var) ? false : var->isAssignable();
82        }
83    
84        bool VMFunction::acceptsArgUnitType(vmint iArg, StdUnit_t type) const {
85            return type == VM_NO_UNIT;
86        }
87    
88        bool VMFunction::acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const {
89            return false;
90        }
91    
92        bool VMFunction::acceptsArgFinal(vmint iArg) const {
93            return false;
94        }
95    
96      void VMFunction::wrnMsg(const String& txt) {      void VMFunction::wrnMsg(const String& txt) {
97          std::cout << "[ScriptVM] " << txt << std::endl;          std::cout << "[ScriptVM] " << txt << std::endl;
98      }      }
# Line 28  namespace LinuxSampler { Line 101  namespace LinuxSampler {
101          std::cerr << "[ScriptVM] " << txt << std::endl;          std::cerr << "[ScriptVM] " << txt << std::endl;
102      }      }
103    
104        ///////////////////////////////////////////////////////////////////////
105        // class 'VMIntExpr'
106    
107        vmint VMIntExpr::evalInt(MetricPrefix_t prefix) {
108            vmfloat f = (vmfloat) evalInt();
109            vmfloat factor = unitFactor() / _unitFactor(prefix);
110            return (vmint) f * factor;
111        }
112    
113        vmint VMIntExpr::evalInt(MetricPrefix_t prefix1, MetricPrefix_t prefix2) {
114            vmfloat f = (vmfloat) evalInt();
115            vmfloat factor = unitFactor() /
116                                ( _unitFactor(prefix1) * _unitFactor(prefix2) );
117            return (vmint) f * factor;
118        }
119    
120        ///////////////////////////////////////////////////////////////////////
121        // class 'VMRealExpr'
122    
123        vmfloat VMRealExpr::evalReal(MetricPrefix_t prefix) {
124            vmfloat f = evalReal();
125            vmfloat factor = unitFactor() / _unitFactor(prefix);
126            return f * factor;
127        }
128    
129        vmfloat VMRealExpr::evalReal(MetricPrefix_t prefix1, MetricPrefix_t prefix2) {
130            vmfloat f = evalReal();
131            vmfloat factor = unitFactor() /
132                                ( _unitFactor(prefix1) * _unitFactor(prefix2) );
133            return f * factor;
134        }
135    
136        ///////////////////////////////////////////////////////////////////////
137        // class 'VMSourceToken'
138    
139        VMSourceToken::VMSourceToken() : m_token(NULL) {
140        }
141    
142        VMSourceToken::VMSourceToken(SourceToken* ct) : m_token(ct) {
143        }
144    
145        VMSourceToken::VMSourceToken(const VMSourceToken& other) {
146            if (other.m_token) {
147                m_token = new SourceToken;
148                *m_token = *other.m_token;
149            } else m_token = NULL;
150        }
151    
152        VMSourceToken::~VMSourceToken() {
153            if (m_token) {
154                delete m_token;
155                m_token = NULL;
156            }
157        }
158    
159        VMSourceToken& VMSourceToken::operator=(const VMSourceToken& other) {
160            if (m_token) delete m_token;
161            if (other.m_token) {
162                m_token = new SourceToken;
163                *m_token = *other.m_token;
164            } else m_token = NULL;
165            return *this;
166        }
167    
168        String VMSourceToken::text() const {
169            return (m_token) ? m_token->text() : "";
170        }
171    
172        int VMSourceToken::firstLine() const {
173            return (m_token) ? m_token->firstLine() : 0;
174        }
175    
176        int VMSourceToken::firstColumn() const {
177            return (m_token) ? m_token->firstColumn() : 0;
178        }
179    
180        bool VMSourceToken::isEOF() const {
181            return (m_token) ? m_token->isEOF() : true;
182        }
183    
184        bool VMSourceToken::isNewLine() const {
185            return (m_token) ? m_token->isNewLine() : false;
186        }
187    
188        bool VMSourceToken::isKeyword() const {
189            return (m_token) ? m_token->isKeyword() : false;
190        }
191    
192        bool VMSourceToken::isVariableName() const {
193            return (m_token) ? m_token->isVariableName() : false;
194        }
195    
196        bool VMSourceToken::isIdentifier() const {
197            return (m_token) ? m_token->isIdentifier() : false;
198        }
199    
200        bool VMSourceToken::isNumberLiteral() const {
201            return (m_token) ? m_token->isNumberLiteral() : false;
202        }
203    
204        bool VMSourceToken::isStringLiteral() const {
205            return (m_token) ? m_token->isStringLiteral() : false;
206        }
207    
208        bool VMSourceToken::isComment() const {
209            return (m_token) ? m_token->isComment() : false;
210        }
211    
212        bool VMSourceToken::isPreprocessor() const {
213            return (m_token) ? m_token->isPreprocessor() : false;
214        }
215    
216        bool VMSourceToken::isMetricPrefix() const {
217            return (m_token) ? m_token->isMetricPrefix() : false;
218        }
219    
220        bool VMSourceToken::isStdUnit() const {
221            return (m_token) ? m_token->isStdUnit() : false;
222        }
223    
224        bool VMSourceToken::isOther() const {
225            return (m_token) ? m_token->isOther() : true;
226        }
227    
228        bool VMSourceToken::isIntegerVariable() const {
229            return (m_token) ? m_token->isIntegerVariable() : false;
230        }
231    
232        bool VMSourceToken::isRealVariable() const {
233            return (m_token) ? m_token->isRealVariable() : false;
234        }
235    
236        bool VMSourceToken::isStringVariable() const {
237            return (m_token) ? m_token->isStringVariable() : false;
238        }
239    
240        bool VMSourceToken::isIntArrayVariable() const {
241            return (m_token) ? m_token->isIntegerArrayVariable() : false;
242        }
243    
244        bool VMSourceToken::isRealArrayVariable() const {
245            return (m_token) ? m_token->isRealArrayVariable() : false;
246        }
247    
248        bool VMSourceToken::isArrayVariable() const { // deprecated API: will be removed !
249            return isIntArrayVariable();
250        }
251    
252        bool VMSourceToken::isEventHandlerName() const {
253            return (m_token) ? m_token->isEventHandlerName() : false;
254        }
255    
256  } // namespace LinuxSampler  } // namespace LinuxSampler

Legend:
Removed from v.2598  
changed lines
  Added in v.3573

  ViewVC Help
Powered by ViewVC