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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3564 - (hide annotations) (download)
Sat Aug 24 09:18:57 2019 UTC (4 years, 9 months ago) by schoenebeck
File size: 6138 byte(s)
NKSP: Bug fixes regarding new measurement units feature:

* Fix: Engine internal Fade of script synthesis parameters volume, pitch
  and pan were not rendered at all.

* Fix: Backward compatibility of built-in function arguments without a
  metric unit prefix was broken (resulted in incorrect value
  transformation).

* Fix: built-in script function change_play_pos() resolved wrong arguments.

* Bumped version (2.1.1.svn5).

1 schoenebeck 2596 /*
2 schoenebeck 3561 * Copyright (c) 2014-2019 Christian Schoenebeck
3 schoenebeck 2596 *
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 "common.h"
11 schoenebeck 2598 #include <iostream>
12 schoenebeck 2885 #include "editor/SourceToken.h"
13 schoenebeck 2596
14     namespace LinuxSampler {
15    
16 schoenebeck 3561 ///////////////////////////////////////////////////////////////////////
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 schoenebeck 2596 VMIntExpr* VMExpr::asInt() const {
52     return const_cast<VMIntExpr*>( dynamic_cast<const VMIntExpr*>(this) );
53     }
54    
55     VMStringExpr* VMExpr::asString() const {
56     return const_cast<VMStringExpr*>( dynamic_cast<const VMStringExpr*>(this) );
57     }
58    
59 schoenebeck 2619 VMIntArrayExpr* VMExpr::asIntArray() const {
60     return const_cast<VMIntArrayExpr*>( dynamic_cast<const VMIntArrayExpr*>(this) );
61     }
62    
63 schoenebeck 2945 bool VMExpr::isModifyable() const {
64     const VMVariable* var = dynamic_cast<const VMVariable*>(this);
65     return (!var) ? false : var->isAssignable();
66     }
67    
68 schoenebeck 3561 bool VMFunction::acceptsArgUnitType(vmint iArg, StdUnit_t type) const {
69     return type == VM_NO_UNIT;
70     }
71    
72 schoenebeck 3564 bool VMFunction::acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const {
73 schoenebeck 3561 return false;
74     }
75    
76     bool VMFunction::acceptsArgFinal(vmint iArg) const {
77     return false;
78     }
79    
80 schoenebeck 2598 void VMFunction::wrnMsg(const String& txt) {
81     std::cout << "[ScriptVM] " << txt << std::endl;
82     }
83    
84     void VMFunction::errMsg(const String& txt) {
85     std::cerr << "[ScriptVM] " << txt << std::endl;
86     }
87 schoenebeck 3561
88     ///////////////////////////////////////////////////////////////////////
89     // class 'VMIntExpr'
90    
91     vmint VMIntExpr::evalInt(MetricPrefix_t prefix) {
92     vmfloat f = (vmfloat) evalInt();
93     vmfloat factor = unitFactor() / _unitFactor(prefix);
94     return (vmint) f * factor;
95     }
96    
97     vmint VMIntExpr::evalInt(MetricPrefix_t prefix1, MetricPrefix_t prefix2) {
98     vmfloat f = (vmfloat) evalInt();
99     vmfloat factor = unitFactor() /
100     ( _unitFactor(prefix1) * _unitFactor(prefix2) );
101     return (vmint) f * factor;
102     }
103 schoenebeck 2885
104     ///////////////////////////////////////////////////////////////////////
105     // class 'VMSourceToken'
106 schoenebeck 2598
107 schoenebeck 2885 VMSourceToken::VMSourceToken() : m_token(NULL) {
108     }
109    
110     VMSourceToken::VMSourceToken(SourceToken* ct) : m_token(ct) {
111     }
112    
113     VMSourceToken::VMSourceToken(const VMSourceToken& other) {
114     if (other.m_token) {
115     m_token = new SourceToken;
116     *m_token = *other.m_token;
117     } else m_token = NULL;
118     }
119    
120     VMSourceToken::~VMSourceToken() {
121     if (m_token) {
122     delete m_token;
123     m_token = NULL;
124     }
125     }
126    
127     VMSourceToken& VMSourceToken::operator=(const VMSourceToken& other) {
128     if (m_token) delete m_token;
129     if (other.m_token) {
130     m_token = new SourceToken;
131     *m_token = *other.m_token;
132     } else m_token = NULL;
133     return *this;
134     }
135    
136     String VMSourceToken::text() const {
137     return (m_token) ? m_token->text() : "";
138     }
139    
140     int VMSourceToken::firstLine() const {
141     return (m_token) ? m_token->firstLine() : 0;
142     }
143    
144     int VMSourceToken::firstColumn() const {
145     return (m_token) ? m_token->firstColumn() : 0;
146     }
147    
148     bool VMSourceToken::isEOF() const {
149     return (m_token) ? m_token->isEOF() : true;
150     }
151    
152     bool VMSourceToken::isNewLine() const {
153     return (m_token) ? m_token->isNewLine() : false;
154     }
155    
156     bool VMSourceToken::isKeyword() const {
157     return (m_token) ? m_token->isKeyword() : false;
158     }
159    
160     bool VMSourceToken::isVariableName() const {
161     return (m_token) ? m_token->isVariableName() : false;
162     }
163    
164     bool VMSourceToken::isIdentifier() const {
165     return (m_token) ? m_token->isIdentifier() : false;
166     }
167    
168     bool VMSourceToken::isNumberLiteral() const {
169     return (m_token) ? m_token->isNumberLiteral() : false;
170     }
171    
172     bool VMSourceToken::isStringLiteral() const {
173     return (m_token) ? m_token->isStringLiteral() : false;
174     }
175    
176     bool VMSourceToken::isComment() const {
177     return (m_token) ? m_token->isComment() : false;
178     }
179    
180     bool VMSourceToken::isPreprocessor() const {
181     return (m_token) ? m_token->isPreprocessor() : false;
182     }
183    
184 schoenebeck 3562 bool VMSourceToken::isMetricPrefix() const {
185     return (m_token) ? m_token->isMetricPrefix() : false;
186     }
187    
188     bool VMSourceToken::isStdUnit() const {
189     return (m_token) ? m_token->isStdUnit() : false;
190     }
191    
192 schoenebeck 2885 bool VMSourceToken::isOther() const {
193     return (m_token) ? m_token->isOther() : true;
194     }
195    
196     bool VMSourceToken::isIntegerVariable() const {
197     return (m_token) ? m_token->isIntegerVariable() : false;
198     }
199    
200     bool VMSourceToken::isStringVariable() const {
201     return (m_token) ? m_token->isStringVariable() : false;
202     }
203    
204     bool VMSourceToken::isArrayVariable() const {
205     return (m_token) ? m_token->isArrayVariable() : false;
206     }
207    
208     bool VMSourceToken::isEventHandlerName() const {
209     return (m_token) ? m_token->isEventHandlerName() : false;
210     }
211    
212 schoenebeck 2596 } // namespace LinuxSampler

  ViewVC Help
Powered by ViewVC