/[svn]/linuxsampler/trunk/src/engines/common/InstrumentScriptVMDynVars.h
ViewVC logotype

Contents of /linuxsampler/trunk/src/engines/common/InstrumentScriptVMDynVars.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3581 - (show annotations) (download) (as text)
Fri Aug 30 11:40:25 2019 UTC (4 years, 7 months ago) by schoenebeck
File MIME type: text/x-c++hdr
File size: 3017 byte(s)
NKSP: Allow more wider support of standard measuring units & 'final'ness.

* Raised compiler requirement to be C++14 compliant (due to severe
  restrictions regarding C-style aggregate initializer lists in C++11
  which are now massively used throughout the code base).

* NKSP VM API: Allow units and 'final'ness to be returned as result from
  built-in functions (added methods VMFunction::returnUnitType() and
  VMFunction::returnsFinal() for that purpose which must be implemented by
  built-in function implementations).

* NKSP language: Allow metric unit prefixes of numeric scalar and array
  variables to be changed freely at runtime (unlike unit types like Hz etc.
  which are still sticky parse-time features of variables which cannot be
  changed at runtime for the intentional sake of determinism).

* NKSP language: 'final' values are prohibited for array variables for now
  (attempt causes a parsers error).

* NKSP language: expressions with unit types (e.g. Hz) are prohibited for
  conditions of runtime control structures like if(), while(), select()
  (attempt causes a parser error).

* NKSP VM API: Allow built-in functions to perform their own, individual
  parse time checks of arguments going to be passed to the function at
  runtime (added method VMFunction::checkArgs() for that purpose).

* NKSP language: raise parser warning if only one operand of binary
  operators (like logical 'or' comparison) contain a 'final' value (because
  it would always yield in a 'final' result in such cases).

* NKSP language: Allow comparison (=, #, <, >, <=, >=) of values with
  different metric unit prefixes, which will behave as expected (e.g.
  result of expression '1000us < 2ms' is true).

* NKSP language: Allow adding values with different metric unit prefixes
  (e.g. result of expression '100Hz + 5kHz' is '5100Hz').

* NKSP language: Allow subtracting values with different metric unit
  prefixes (e.g. result of expression '1ms - 20us' is '980us').

* NKSP language: Allow multiplying with any metric unit prefixes
  (e.g. result of expression '2k * 3ms' is '6s'), however multiplications
  with unit types on both sides (e.g. '2s * 2s') is still prohibited since
  we don't have any considerable practical use for a term like '4s^2'
  (hence any attempt multiplying two unit types still causes parser error).

* NKSP language: Allow dividing by any metric unit prefixes and allow
  division of same unit type on both sides (e.g. expression '8kHz / 1000Hz'
  yields in unit free result '8'). So this is now a way to cast units away
  e.g. for passing the result to other expressions, certain function calls
  or variables which are not accepting any units (or that specific unit).

* NKSP language: integer arrays and real number arrays can now be converted
  to strings (e.g. for dumping their content with message() calls for
  script debugging purposes).

* NKSP language: expressions and variables with units are now correctly
  casted to strings (e.g. with message() calls).

* NKSP language: comparing real numbers for equalness (e.g. '~foo = 3.1') or
  unequalness (e.g. '~foo # 3.1') is now less strict and takes the expected
  floating point tolerances into account.

* NKSP VM API: Added methods VMScalarNumberExpr::evalCastInt() and
  VMScalarNumberExpr::evalCastReal().

* NKSP VM API: Added base class 'VMNumberArrayExpr' for classes
  'VMIntArrayExpr' and 'VMRealArrayExpr'.

* NKSP VM API: replaced all unitPrefix() (parse time) methods by
  unitFactor() (runtime) methods.

* Built-in function "exit()" supports now returning units and 'final'ness
  exclusively for test cases.

* The following built-in functions support now units as well: "abs()",
  "random()", "inc()", "dec()", "in_range()", "min()", "max()",
  "real_to_int()", "int()", "int_to_real()" and "real()".

* Built-in functions "array_equal()", "search()" and "sort()" support now
  real number arrays (correctly) as well.

* Added individual parse time checks of arguments to be passed to built-in
  functions "random()", "inc()", "dec()", "in_range()", "min()", "max()",
  "array_equal()" and "search()" specific for their individual purposes.

* Test cases: Added massive amount of NKSP test cases for standard
  measuring units and 'final' operator usage cases.

* Test cases: Added NKSP test cases for (floating point tolerance aware)
  real number equalness / unequalness comparison.

* Bumped version (2.1.1.svn8).

1 /*
2 * Copyright (c) 2016 - 2019 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 #ifndef LS_INSTRSCRIPTVMDYNVARS_H
11 #define LS_INSTRSCRIPTVMDYNVARS_H
12
13 #include "../../common/global.h"
14 #include "../../scriptvm/CoreVMDynVars.h"
15 #include "Event.h"
16
17 namespace LinuxSampler {
18
19 class InstrumentScriptVM;
20
21 /**
22 * Implements the built-in $ENGINE_UPTIME script variable.
23 */
24 class InstrumentScriptVMDynVar_ENGINE_UPTIME FINAL : public VMDynIntVar {
25 public:
26 InstrumentScriptVMDynVar_ENGINE_UPTIME(InstrumentScriptVM* parent) : m_vm(parent) {}
27 bool isAssignable() const OVERRIDE { return false; }
28 vmint evalInt() OVERRIDE;
29 protected:
30 InstrumentScriptVM* m_vm;
31 };
32
33 /**
34 * Implements the built-in $NI_CALLBACK_ID script variable.
35 */
36 class InstrumentScriptVMDynVar_NI_CALLBACK_ID FINAL : public VMDynIntVar {
37 public:
38 InstrumentScriptVMDynVar_NI_CALLBACK_ID(InstrumentScriptVM* parent) : m_vm(parent) {}
39 bool isAssignable() const OVERRIDE { return false; }
40 vmint evalInt() OVERRIDE;
41 protected:
42 InstrumentScriptVM* m_vm;
43 };
44
45 /**
46 * Implements the built-in array %NKSP_CALLBACK_CHILD_ID[] script variable.
47 */
48 class InstrumentScriptVMDynVar_NKSP_CALLBACK_CHILD_ID FINAL : public VMDynIntArrayVar {
49 public:
50 InstrumentScriptVMDynVar_NKSP_CALLBACK_CHILD_ID(InstrumentScriptVM* parent);
51 VMIntArrayExpr* asIntArray() const OVERRIDE;
52 vmint arraySize() const OVERRIDE;
53 bool isAssignable() const OVERRIDE { return false; }
54 vmint evalIntElement(vmuint i) OVERRIDE;
55 void assignIntElement(vmuint i, vmint value) OVERRIDE {}
56 vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
57 void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {} // ignore assignment
58 protected:
59 InstrumentScriptVM* m_vm;
60 };
61
62 /**
63 * Implements the built-in %ALL_EVENTS script array variable.
64 */
65 class InstrumentScriptVMDynVar_ALL_EVENTS FINAL : public VMDynIntArrayVar {
66 public:
67 InstrumentScriptVMDynVar_ALL_EVENTS(InstrumentScriptVM* parent);
68 virtual ~InstrumentScriptVMDynVar_ALL_EVENTS();
69 VMIntArrayExpr* asIntArray() const OVERRIDE;
70 vmint arraySize() const OVERRIDE;
71 bool isAssignable() const OVERRIDE { return false; }
72 vmint evalIntElement(vmuint i) OVERRIDE;
73 void assignIntElement(vmuint i, vmint value) OVERRIDE {}
74 vmfloat unitFactorOfElement(vmuint i) const OVERRIDE { return VM_NO_FACTOR; }
75 void assignElementUnitFactor(vmuint i, vmfloat factor) OVERRIDE {} // ignore assignment
76 protected:
77 void updateNoteIDs();
78 private:
79 InstrumentScriptVM* m_vm;
80 note_id_t* m_ids;
81 vmuint m_numIDs;
82 };
83
84 } // namespace LinuxSampler
85
86 #endif // LS_INSTRSCRIPTVMDYNVARS_H

  ViewVC Help
Powered by ViewVC