/[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 2885 by schoenebeck, Fri Apr 22 15:37:45 2016 UTC revision 3564 by schoenebeck, Sat Aug 24 09:18:57 2019 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014-2016 Christian Schoenebeck   * Copyright (c) 2014-2019 Christian Schoenebeck
3   *   *
4   * http://www.linuxsampler.org   * http://www.linuxsampler.org
5   *   *
# Line 13  Line 13 
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      }      }
# Line 25  namespace LinuxSampler { Line 60  namespace LinuxSampler {
60          return const_cast<VMIntArrayExpr*>( dynamic_cast<const VMIntArrayExpr*>(this) );          return const_cast<VMIntArrayExpr*>( dynamic_cast<const VMIntArrayExpr*>(this) );
61      }      }
62    
63        bool VMExpr::isModifyable() const {
64            const VMVariable* var = dynamic_cast<const VMVariable*>(this);
65            return (!var) ? false : var->isAssignable();
66        }
67    
68        bool VMFunction::acceptsArgUnitType(vmint iArg, StdUnit_t type) const {
69            return type == VM_NO_UNIT;
70        }
71    
72        bool VMFunction::acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const {
73            return false;
74        }
75    
76        bool VMFunction::acceptsArgFinal(vmint iArg) const {
77            return false;
78        }
79    
80      void VMFunction::wrnMsg(const String& txt) {      void VMFunction::wrnMsg(const String& txt) {
81          std::cout << "[ScriptVM] " << txt << std::endl;          std::cout << "[ScriptVM] " << txt << std::endl;
82      }      }
# Line 32  namespace LinuxSampler { Line 84  namespace LinuxSampler {
84      void VMFunction::errMsg(const String& txt) {      void VMFunction::errMsg(const String& txt) {
85          std::cerr << "[ScriptVM] " << txt << std::endl;          std::cerr << "[ScriptVM] " << txt << std::endl;
86      }      }
87    
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            
104      ///////////////////////////////////////////////////////////////////////      ///////////////////////////////////////////////////////////////////////
105      // class 'VMSourceToken'      // class 'VMSourceToken'
# Line 113  namespace LinuxSampler { Line 181  namespace LinuxSampler {
181          return (m_token) ? m_token->isPreprocessor() : false;          return (m_token) ? m_token->isPreprocessor() : false;
182      }      }
183    
184        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      bool VMSourceToken::isOther() const {      bool VMSourceToken::isOther() const {
193          return (m_token) ? m_token->isOther() : true;          return (m_token) ? m_token->isOther() : true;
194      }      }

Legend:
Removed from v.2885  
changed lines
  Added in v.3564

  ViewVC Help
Powered by ViewVC