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

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

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

revision 3277 by schoenebeck, Mon Jun 5 18:40:18 2017 UTC revision 3573 by schoenebeck, Tue Aug 27 21:36:53 2019 UTC
# Line 1  Line 1 
1  /*  /*
2   * Copyright (c) 2014-2017 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  // This header defines data types shared between the VM core implementation  // This header defines data types shared between the VM core implementation
11  // (inside the current source directory) and other parts of the sampler  // (inside the current source directory) and other parts of the sampler
12  // (located at other source directories).  // (located at other source directories). It also acts as public API of the
13    // Real-Time script engine for other applications.
14    
15  #ifndef LS_INSTR_SCRIPT_PARSER_COMMON_H  #ifndef LS_INSTR_SCRIPT_PARSER_COMMON_H
16  #define LS_INSTR_SCRIPT_PARSER_COMMON_H  #define LS_INSTR_SCRIPT_PARSER_COMMON_H
# Line 22  Line 23 
23  namespace LinuxSampler {  namespace LinuxSampler {
24    
25      /**      /**
26         * Native data type used by the script engine both internally, as well as
27         * for all integer data types used by scripts (i.e. for all $foo variables
28         * in NKSP scripts). Note that this is different from the original KSP which
29         * is limited to 32 bit for integer variables in KSP scripts.
30         */
31        typedef int64_t vmint;
32    
33        /**
34         * Native data type used internally by the script engine for all unsigned
35         * integer types. This type is currently not exposed to scripts.
36         */
37        typedef uint64_t vmuint;
38    
39        /**
40         * Native data type used by the script engine both internally for floating
41         * point data, as well as for all @c real data types used by scripts (i.e.
42         * for all ~foo variables in NKSP scripts).
43         */
44        typedef float vmfloat;
45    
46        /**
47       * Identifies the type of a noteworthy issue identified by the script       * Identifies the type of a noteworthy issue identified by the script
48       * parser. That's either a parser error or parser warning.       * parser. That's either a parser error or parser warning.
49       */       */
# Line 43  namespace LinuxSampler { Line 65  namespace LinuxSampler {
65          INT_ARR_EXPR, ///< integer array expression          INT_ARR_EXPR, ///< integer array expression
66          STRING_EXPR, ///< string expression          STRING_EXPR, ///< string expression
67          STRING_ARR_EXPR, ///< string array expression          STRING_ARR_EXPR, ///< string array expression
68            REAL_EXPR, ///< floating point (scalar) expression
69            REAL_ARR_EXPR, ///< floating point array expression
70      };      };
71    
72      /** @brief Result flags of a script statement or script function call.      /** @brief Result flags of a script statement or script function call.
# Line 80  namespace LinuxSampler { Line 104  namespace LinuxSampler {
104       *       *
105       * Identifies one of the possible event handler callback types defined by       * Identifies one of the possible event handler callback types defined by
106       * the NKSP script language.       * the NKSP script language.
107         *
108         * IMPORTANT: this type is forced to be emitted as int32_t type ATM, because
109         * that's the native size expected by the built-in instrument script
110         * variable bindings (see occurrences of VMInt32RelPtr and DECLARE_VMINT
111         * respectively. A native type mismatch between the two could lead to
112         * undefined behavior! Background: By definition the C/C++ compiler is free
113         * to choose a bit size for individual enums which it might find
114         * appropriate, which is usually decided by the compiler according to the
115         * biggest enum constant value defined (in practice it is usually 32 bit).
116       */       */
117      enum VMEventHandlerType_t {      enum VMEventHandlerType_t : int32_t {
118          VM_EVENT_HANDLER_INIT, ///< Initilization event handler, that is script's "on init ... end on" code block.          VM_EVENT_HANDLER_INIT, ///< Initilization event handler, that is script's "on init ... end on" code block.
119          VM_EVENT_HANDLER_NOTE, ///< Note event handler, that is script's "on note ... end on" code block.          VM_EVENT_HANDLER_NOTE, ///< Note event handler, that is script's "on note ... end on" code block.
120          VM_EVENT_HANDLER_RELEASE, ///< Release event handler, that is script's "on release ... end on" code block.          VM_EVENT_HANDLER_RELEASE, ///< Release event handler, that is script's "on release ... end on" code block.
121          VM_EVENT_HANDLER_CONTROLLER, ///< Controller event handler, that is script's "on controller ... end on" code block.          VM_EVENT_HANDLER_CONTROLLER, ///< Controller event handler, that is script's "on controller ... end on" code block.
122      };      };
123    
124        /**
125         * All metric unit prefixes (actually just scale factors) supported by this
126         * script engine.
127         */
128        enum MetricPrefix_t {
129            VM_NO_PREFIX = 0, ///< = 1
130            VM_KILO,          ///< = 10^3, short 'k'
131            VM_HECTO,         ///< = 10^2, short 'h'
132            VM_DECA,          ///< = 10, short 'da'
133            VM_DECI,          ///< = 10^-1, short 'd'
134            VM_CENTI,         ///< = 10^-2, short 'c' (this is also used for tuning "cents")
135            VM_MILLI,         ///< = 10^-3, short 'm'
136            VM_MICRO,         ///< = 10^-6, short 'u'
137        };
138    
139        /**
140         * All measurement unit types supported by this script engine.
141         *
142         * @e Note: there is no standard unit "cents" here (for pitch/tuning), use
143         * @c VM_CENTI for the latter instad. That's because the commonly cited
144         * "cents" unit is actually no measurement unit type but rather a metric
145         * unit prefix.
146         *
147         * @see MetricPrefix_t
148         */
149        enum StdUnit_t {
150            VM_NO_UNIT = 0, ///< No unit used, the number is just an abstract number.
151            VM_SECOND,      ///< Measuring time.
152            VM_HERTZ,       ///< Measuring frequency.
153            VM_BEL,         ///< Measuring relation between two energy levels (in logarithmic scale). Since we are using it for accoustics, we are always referring to A-weighted Bels (i.e. dBA).
154        };
155    
156      // just symbol prototyping      // just symbol prototyping
157      class VMIntExpr;      class VMIntExpr;
158        class VMRealExpr;
159      class VMStringExpr;      class VMStringExpr;
160        class VMScalarNumberExpr;
161      class VMIntArrayExpr;      class VMIntArrayExpr;
162        class VMRealArrayExpr;
163      class VMStringArrayExpr;      class VMStringArrayExpr;
164        class VMParserContext;
165    
166        /** @brief Virtual machine measuring unit.
167         *
168         * Abstract base class representing standard measurement units throughout
169         * the script engine. These might be i.e. "dB" (deci Bel) for loudness,
170         * "Hz" (Hertz) for frequencies or "s" for "seconds".
171         *
172         * Originally the script engine only supported abstract integer values for
173         * controlling any synthesis parameter or built-in function argument or
174         * variable. Under certain situations it makes sense though for an
175         * instrument script author to provide values in real, standard measurement
176         * units, for example setting the frequency of some LFO directly to "20Hz".
177         * Hence support for standard units in scripts was added as an extension to
178         * the NKSP script engine.
179         */
180        class VMUnit {
181        public:
182            /**
183             * Returns the metric prefix of this unit. A metric prefix essentially
184             * is just a mathematical scale factor that should be applied to the
185             * number associated with the measurement unit. Usually a unit either
186             * has exactly none or one prefix, but note that there might also be
187             * units with more than one prefix, for example mdB (mili deci bel)
188             * is used sometimes which has two prefixes. This is an exception though
189             * and more than two prefixes is currently not supported by the script
190             * engine.
191             *
192             * Start iterating over the prefixes of this unit by passing @c 0 as
193             * argument to this method. The prefixes are terminated with return
194             * value VM_NO_PREFIX being always the last element.
195             *
196             * @param i - index of prefix
197             * @returns prefix of requested index or VM_NO_PREFIX otherwise
198             * @see unitFactor()
199             */
200            virtual MetricPrefix_t unitPrefix(vmuint i) const = 0;
201    
202            /**
203             * Conveniently returns the final mathematical factor that should be
204             * multiplied against the number associated with this unit. This factor
205             * results from the sequence of metric prefixes of this unit.
206             *
207             * @see unitPrefix()
208             */
209            vmfloat unitFactor() const;
210    
211            /**
212             * This is the actual fundamental measuring unit base type of this unit,
213             * which might be either Hertz, second or Bel.
214             *
215             * @returns standard unit type identifier or VM_NO_UNIT if no unit used
216             */
217            virtual StdUnit_t unitType() const = 0;
218    
219            /**
220             * Returns the actual mathematical factor represented by the passed
221             * @a prefix argument.
222             */
223            static vmfloat unitFactor(MetricPrefix_t prefix);
224    
225            /**
226             * Returns the actual mathematical factor represented by the passed
227             * two @a prefix1 and @a prefix2 arguments.
228             */
229            static vmfloat unitFactor(MetricPrefix_t prefix1, MetricPrefix_t prefix2);
230        };
231    
232      /** @brief Virtual machine expression      /** @brief Virtual machine expression
233       *       *
# Line 125  namespace LinuxSampler { Line 260  namespace LinuxSampler {
260           * if this expression is i.e. actually a string expression like "12",           * if this expression is i.e. actually a string expression like "12",
261           * calling asInt() will @b not cast that numerical string expression to           * calling asInt() will @b not cast that numerical string expression to
262           * an integer expression 12 for you, instead this method will simply           * an integer expression 12 for you, instead this method will simply
263           * return NULL!           * return NULL! Same applies if this expression is actually a real
264             * number expression: asInt() would return NULL in that case as well.
265           *           *
266           * @see exprType()           * @see exprType(), asReal(), asScalarNumberExpr()
267           */           */
268          VMIntExpr* asInt() const;          VMIntExpr* asInt() const;
269    
270          /**          /**
271             * In case this expression is a real number (floating point) expression,
272             * then this method returns a casted pointer to that VMRealExpr object.
273             * It returns NULL if this expression is not a real number expression.
274             *
275             * @b Note: type casting performed by this method is strict! That means
276             * if this expression is i.e. actually a string expression like "12",
277             * calling asReal() will @b not cast that numerical string expression to
278             * a real number expression 12.0 for you, instead this method will
279             * simply return NULL! Same applies if this expression is actually an
280             * integer expression: asReal() would return NULL in that case as well.
281             *
282             * @see exprType(), asInt(), asScalarNumberExpr()
283             */
284            VMRealExpr* asReal() const;
285    
286            /**
287             * In case this expression is a scalar number expression, that is either
288             * an integer (scalar) expression or a real number (floating point
289             * scalar) expression, then this method returns a casted pointer to that
290             * VMScalarNumberExpr base class object. It returns NULL if this
291             * expression is neither an integer (scalar), nor a real number (scalar)
292             * expression.
293             *
294             * Since the methods asInt() and asReal() are very strict, this method
295             * is provided as convenience access in case only very general
296             * information (e.g. which standard measurement unit is being used or
297             * whether final operator being effective to this expression) is
298             * intended to be retrieved of this scalar number expression independent
299             * from whether this expression is actually an integer or a real number
300             * expression.
301             *
302             * @see exprType(), asInt(), asReal()
303             */
304            VMScalarNumberExpr* asScalarNumberExpr() const;
305    
306            /**
307           * In case this expression is a string expression, then this method           * In case this expression is a string expression, then this method
308           * returns a casted pointer to that VMStringExpr object. It returns NULL           * returns a casted pointer to that VMStringExpr object. It returns NULL
309           * if this expression is not a string expression.           * if this expression is not a string expression.
# Line 152  namespace LinuxSampler { Line 324  namespace LinuxSampler {
324           * returns NULL if this expression is not an integer array expression.           * returns NULL if this expression is not an integer array expression.
325           *           *
326           * @b Note: type casting performed by this method is strict! That means           * @b Note: type casting performed by this method is strict! That means
327           * if this expression is i.e. an integer expression or a string           * if this expression is i.e. an integer scalar expression, a real
328           * expression, calling asIntArray() will @b not cast those scalar           * number expression or a string expression, calling asIntArray() will
329           * expressions to an array expression for you, instead this method will           * @b not cast those expressions to an integer array expression for you,
330           * simply return NULL!           * instead this method will simply return NULL!
331           *           *
332           * @b Note: this method is currently, and in contrast to its other           * @b Note: this method is currently, and in contrast to its other
333           * counter parts, declared as virtual method. Some deriving classes are           * counter parts, declared as virtual method. Some deriving classes are
# Line 170  namespace LinuxSampler { Line 342  namespace LinuxSampler {
342          virtual VMIntArrayExpr* asIntArray() const;          virtual VMIntArrayExpr* asIntArray() const;
343    
344          /**          /**
345             * In case this expression is a real number (floating point) array
346             * expression, then this method returns a casted pointer to that
347             * VMRealArrayExpr object. It returns NULL if this expression is not a
348             * real number array expression.
349             *
350             * @b Note: type casting performed by this method is strict! That means
351             * if this expression is i.e. a real number scalar expression, an
352             * integer expression or a string expression, calling asRealArray() will
353             * @b not cast those scalar expressions to a real number array
354             * expression for you, instead this method will simply return NULL!
355             *
356             * @b Note: this method is currently, and in contrast to its other
357             * counter parts, declared as virtual method. Some deriving classes are
358             * currently using this to override this default implementation in order
359             * to implement an "evaluate now as real number array" behavior. This
360             * has efficiency reasons, however this also currently makes this part
361             * of the API less clean and should thus be addressed in future with
362             * appropriate changes to the API.
363             *
364             * @see exprType()
365             */
366            virtual VMRealArrayExpr* asRealArray() const;
367    
368            /**
369           * Returns true in case this expression can be considered to be a           * Returns true in case this expression can be considered to be a
370           * constant expression. A constant expression will retain the same           * constant expression. A constant expression will retain the same
371           * value throughout the entire life time of a script and the           * value throughout the entire life time of a script and the
# Line 200  namespace LinuxSampler { Line 396  namespace LinuxSampler {
396          bool isModifyable() const;          bool isModifyable() const;
397      };      };
398    
399        /** @brief Virtual machine scalar number expression
400         *
401         * This is the abstract base class for integer (scalar) expressions and
402         * real number (floating point scalar) expressions of scripts.
403         */
404        class VMScalarNumberExpr : virtual public VMExpr, virtual public VMUnit {
405        public:
406            /**
407             * Returns @c true if the value of this expression should be applied
408             * as final value to the respective destination synthesis chain
409             * parameter.
410             *
411             * This property is somewhat special and dedicated for the purpose of
412             * this expression's (integer or real number) value to be applied as
413             * parameter to the synthesis chain of the sampler (i.e. for altering a
414             * filter cutoff frequency). Now historically and by default all values
415             * of scripts are applied relatively to the sampler's synthesis chain,
416             * that is the synthesis parameter value of a script is multiplied
417             * against other sources for the same synthesis parameter (i.e. an LFO
418             * or a dedicated MIDI controller either hard wired in the engine or
419             * defined by the instrument patch). So by default the resulting actual
420             * final synthesis parameter is a combination of all these sources. This
421             * has the advantage that it creates a very living and dynamic overall
422             * sound.
423             *
424             * However sometimes there are requirements by script authors where this
425             * is not what you want. Therefore the NKSP script engine added a
426             * language extension by prefixing a value in scripts with a @c !
427             * character the value will be defined as being the "final" value of the
428             * destination synthesis parameter, so that causes this value to be
429             * applied exclusively, and the values of all other sources are thus
430             * entirely ignored by the sampler's synthesis core as long as this
431             * value is assigned by the script engine as "final" value for the
432             * requested synthesis parameter.
433             */
434            virtual bool isFinal() const = 0;
435        };
436    
437      /** @brief Virtual machine integer expression      /** @brief Virtual machine integer expression
438       *       *
439       * This is the abstract base class for all expressions inside scripts which       * This is the abstract base class for all expressions inside scripts which
# Line 207  namespace LinuxSampler { Line 441  namespace LinuxSampler {
441       * abstract method evalInt() to return the actual integer result value of       * abstract method evalInt() to return the actual integer result value of
442       * the expression.       * the expression.
443       */       */
444      class VMIntExpr : virtual public VMExpr {      class VMIntExpr : virtual public VMScalarNumberExpr {
445      public:      public:
446          /**          /**
447           * Returns the result of this expression as integer (scalar) value.           * Returns the result of this expression as integer (scalar) value.
448           * This abstract method must be implemented by deriving classes.           * This abstract method must be implemented by deriving classes.
449           */           */
450          virtual int evalInt() = 0;          virtual vmint evalInt() = 0;
451    
452            /**
453             * Returns the result of this expression as integer (scalar) value and
454             * thus behaves similar to the previous method, however this overridden
455             * method automatically takes unit prefixes into account and returns a
456             * value corresponding to the expected given unit @a prefix.
457             *
458             * @param prefix - default measurement unit prefix expected by caller
459             */
460            vmint evalInt(MetricPrefix_t prefix);
461    
462            /**
463             * This method behaves like the previous method, just that it takes
464             * a default measurement prefix with two elements (i.e. "milli cents"
465             * for tuning).
466             */
467            vmint evalInt(MetricPrefix_t prefix1, MetricPrefix_t prefix2);
468    
469          /**          /**
470           * Returns always INT_EXPR for instances of this class.           * Returns always INT_EXPR for instances of this class.
# Line 221  namespace LinuxSampler { Line 472  namespace LinuxSampler {
472          ExprType_t exprType() const OVERRIDE { return INT_EXPR; }          ExprType_t exprType() const OVERRIDE { return INT_EXPR; }
473      };      };
474    
475        /** @brief Virtual machine real number (floating point scalar) expression
476         *
477         * This is the abstract base class for all expressions inside scripts which
478         * evaluate to a real number (floating point scalar) value. Deriving classes
479         * implement the abstract method evalReal() to return the actual floating
480         * point result value of the expression.
481         */
482        class VMRealExpr : virtual public VMScalarNumberExpr {
483        public:
484            /**
485             * Returns the result of this expression as real number (floating point
486             * scalar) value. This abstract method must be implemented by deriving
487             * classes.
488             */
489            virtual vmfloat evalReal() = 0;
490    
491            /**
492             * Returns the result of this expression as real number (floating point
493             * scalar) value and thus behaves similar to the previous method,
494             * however this overridden method automatically takes unit prefixes into
495             * account and returns a value corresponding to the expected given unit
496             * @a prefix.
497             *
498             * @param prefix - default measurement unit prefix expected by caller
499             */
500            vmfloat evalReal(MetricPrefix_t prefix);
501    
502            /**
503             * This method behaves like the previous method, just that it takes
504             * a default measurement prefix with two elements (i.e. "milli cents"
505             * for tuning).
506             */
507            vmfloat evalReal(MetricPrefix_t prefix1, MetricPrefix_t prefix2);
508    
509            /**
510             * Returns always REAL_EXPR for instances of this class.
511             */
512            ExprType_t exprType() const OVERRIDE { return REAL_EXPR; }
513        };
514    
515      /** @brief Virtual machine string expression      /** @brief Virtual machine string expression
516       *       *
517       * This is the abstract base class for all expressions inside scripts which       * This is the abstract base class for all expressions inside scripts which
# Line 255  namespace LinuxSampler { Line 546  namespace LinuxSampler {
546           * Returns amount of elements in this array. This abstract method must           * Returns amount of elements in this array. This abstract method must
547           * be implemented by deriving classes.           * be implemented by deriving classes.
548           */           */
549          virtual int arraySize() const = 0;          virtual vmint arraySize() const = 0;
550      };      };
551    
552      /** @brief Virtual Machine Integer Array Expression      /** @brief Virtual Machine Integer Array Expression
# Line 273  namespace LinuxSampler { Line 564  namespace LinuxSampler {
564           *           *
565           * @param i - array element index (must be between 0 .. arraySize() - 1)           * @param i - array element index (must be between 0 .. arraySize() - 1)
566           */           */
567          virtual int evalIntElement(uint i) = 0;          virtual vmint evalIntElement(vmuint i) = 0;
568    
569          /**          /**
570           * Changes the current value of an element (given by array element           * Changes the current value of an element (given by array element
# Line 282  namespace LinuxSampler { Line 573  namespace LinuxSampler {
573           * @param i - array element index (must be between 0 .. arraySize() - 1)           * @param i - array element index (must be between 0 .. arraySize() - 1)
574           * @param value - new integer scalar value to be assigned to that array element           * @param value - new integer scalar value to be assigned to that array element
575           */           */
576          virtual void assignIntElement(uint i, int value) = 0;          virtual void assignIntElement(vmuint i, vmint value) = 0;
577    
578          /**          /**
579           * Returns always INT_ARR_EXPR for instances of this class.           * Returns always INT_ARR_EXPR for instances of this class.
# Line 290  namespace LinuxSampler { Line 581  namespace LinuxSampler {
581          ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }          ExprType_t exprType() const OVERRIDE { return INT_ARR_EXPR; }
582      };      };
583    
584        /** @brief Virtual Machine Real Number Array Expression
585         *
586         * This is the abstract base class for all expressions inside scripts which
587         * evaluate to an array of real numbers (floating point values). Deriving
588         * classes implement the abstract methods arraySize(), evalRealElement() and
589         * assignRealElement() to access the array's individual real numbers.
590         */
591        class VMRealArrayExpr : virtual public VMArrayExpr {
592        public:
593            /**
594             * Returns the (scalar) real mumber (floating point value) of the array
595             * element given by element index @a i.
596             *
597             * @param i - array element index (must be between 0 .. arraySize() - 1)
598             */
599            virtual vmfloat evalRealElement(vmuint i) = 0;
600    
601            /**
602             * Changes the current value of an element (given by array element
603             * index @a i) of this real number array.
604             *
605             * @param i - array element index (must be between 0 .. arraySize() - 1)
606             * @param value - new real number value to be assigned to that array element
607             */
608            virtual void assignRealElement(vmuint i, vmfloat value) = 0;
609    
610            /**
611             * Returns always REAL_ARR_EXPR for instances of this class.
612             */
613            ExprType_t exprType() const OVERRIDE { return REAL_ARR_EXPR; }
614        };
615    
616      /** @brief Arguments (parameters) for being passed to a built-in script function.      /** @brief Arguments (parameters) for being passed to a built-in script function.
617       *       *
618       * An argument or a set of arguments passed to a script function are       * An argument or a set of arguments passed to a script function are
# Line 304  namespace LinuxSampler { Line 627  namespace LinuxSampler {
627           * Returns the amount of arguments going to be passed to the script           * Returns the amount of arguments going to be passed to the script
628           * function.           * function.
629           */           */
630          virtual int argsCount() const = 0;          virtual vmint argsCount() const = 0;
631    
632          /**          /**
633           * Returns the respective argument (requested by argument index @a i) of           * Returns the respective argument (requested by argument index @a i) of
# Line 314  namespace LinuxSampler { Line 637  namespace LinuxSampler {
637           *           *
638           * @param i - function argument index (indexed from left to right)           * @param i - function argument index (indexed from left to right)
639           */           */
640          virtual VMExpr* arg(int i) = 0;          virtual VMExpr* arg(vmint i) = 0;
641      };      };
642    
643      /** @brief Result value returned from a call to a built-in script function.      /** @brief Result value returned from a call to a built-in script function.
# Line 378  namespace LinuxSampler { Line 701  namespace LinuxSampler {
701           * script is calling this function with less arguments, the script           * script is calling this function with less arguments, the script
702           * parser will throw a parser error.           * parser will throw a parser error.
703           */           */
704          virtual int minRequiredArgs() const = 0;          virtual vmint minRequiredArgs() const = 0;
705    
706          /**          /**
707           * Maximum amount of function arguments this functions accepts. If a           * Maximum amount of function arguments this functions accepts. If a
708           * script is calling this function with more arguments, the script           * script is calling this function with more arguments, the script
709           * parser will throw a parser error.           * parser will throw a parser error.
710           */           */
711          virtual int maxAllowedArgs() const = 0;          virtual vmint maxAllowedArgs() const = 0;
712    
713          /**          /**
714           * Script data type of the function's @c iArg 'th function argument.           * Script data type of the function's @c iArg 'th function argument.
# Line 401  namespace LinuxSampler { Line 724  namespace LinuxSampler {
724           * @param iArg - index of the function argument in question           * @param iArg - index of the function argument in question
725           *               (must be between 0 .. maxAllowedArgs() - 1)           *               (must be between 0 .. maxAllowedArgs() - 1)
726           */           */
727          virtual ExprType_t argType(int iArg) const = 0;          virtual ExprType_t argType(vmint iArg) const = 0;
728    
729          /**          /**
730           * This method is called by the parser to check whether arguments           * This method is called by the parser to check whether arguments
# Line 419  namespace LinuxSampler { Line 742  namespace LinuxSampler {
742           * @return true if the given data type would be accepted for the           * @return true if the given data type would be accepted for the
743           *         respective function argument by the function           *         respective function argument by the function
744           */           */
745          virtual bool acceptsArgType(int iArg, ExprType_t type) const = 0;          virtual bool acceptsArgType(vmint iArg, ExprType_t type) const = 0;
746    
747            /**
748             * This method is called by the parser to check whether arguments
749             * passed in scripts to this function are accepted by this function. If
750             * a script calls this function with an argument's measuremnt unit type
751             * not accepted by this function, the parser will throw a parser error.
752             *
753             * This default implementation of this method does not accept any
754             * measurement unit. Deriving subclasses would override this method
755             * implementation in case they do accept any measurement unit for its
756             * function arguments.
757             *
758             * @param iArg - index of the function argument in question
759             *               (must be between 0 .. maxAllowedArgs() - 1)
760             * @param type - standard measurement unit data type used for this
761             *               function argument by currently parsed script
762             * @return true if the given standard measurement unit type would be
763             *         accepted for the respective function argument by the function
764             */
765            virtual bool acceptsArgUnitType(vmint iArg, StdUnit_t type) const;
766    
767            /**
768             * This method is called by the parser to check whether arguments
769             * passed in scripts to this function are accepted by this function. If
770             * a script calls this function with a metric unit prefix and metric
771             * prefixes are not accepted for that argument by this function, then
772             * the parser will throw a parser error.
773             *
774             * This default implementation of this method does not accept any
775             * metric prefix. Deriving subclasses would override this method
776             * implementation in case they do accept any metric prefix for its
777             * function arguments.
778             *
779             * @param iArg - index of the function argument in question
780             *               (must be between 0 .. maxAllowedArgs() - 1)
781             * @param type - standard measurement unit data type used for that
782             *               function argument by currently parsed script
783             *
784             * @return true if a metric prefix would be accepted for the respective
785             *         function argument by this function
786             *
787             * @see MetricPrefix_t
788             */
789            virtual bool acceptsArgUnitPrefix(vmint iArg, StdUnit_t type) const;
790    
791            /**
792             * This method is called by the parser to check whether arguments
793             * passed in scripts to this function are accepted by this function. If
794             * a script calls this function with an argument that is declared to be
795             * a "final" value and this is not accepted by this function, the parser
796             * will throw a parser error.
797             *
798             * This default implementation of this method does not accept a "final"
799             * value. Deriving subclasses would override this method implementation
800             * in case they do accept a "final" value for its function arguments.
801             *
802             * @param iArg - index of the function argument in question
803             *               (must be between 0 .. maxAllowedArgs() - 1)
804             * @return true if a "final" value would be accepted for the respective
805             *         function argument by the function
806             *
807             * @see VMIntExpr::isFinal()
808             */
809            virtual bool acceptsArgFinal(vmint iArg) const;
810    
811          /**          /**
812           * This method is called by the parser to check whether some arguments           * This method is called by the parser to check whether some arguments
# Line 434  namespace LinuxSampler { Line 821  namespace LinuxSampler {
821           * @param iArg - index of the function argument in question           * @param iArg - index of the function argument in question
822           *               (must be between 0 .. maxAllowedArgs() - 1)           *               (must be between 0 .. maxAllowedArgs() - 1)
823           */           */
824          virtual bool modifiesArg(int iArg) const = 0;          virtual bool modifiesArg(vmint iArg) const = 0;
825    
826          /**          /**
827           * Implements the actual function execution. This exec() method is           * Implements the actual function execution. This exec() method is
# Line 468  namespace LinuxSampler { Line 855  namespace LinuxSampler {
855    
856      /** @brief Virtual machine relative pointer.      /** @brief Virtual machine relative pointer.
857       *       *
858       * POD base of VMIntRelPtr and VMInt8RelPtr structures. Not intended to be       * POD base of VMInt64RelPtr, VMInt32RelPtr and VMInt8RelPtr structures. Not
859       * used directly. Use VMIntRelPtr or VMInt8RelPtr instead.       * intended to be used directly. Use VMInt64RelPtr, VMInt32RelPtr,
860         * VMInt8RelPtr instead.
861       *       *
862       * @see VMIntRelPtr, VMInt8RelPtr       * @see VMInt64RelPtr, VMInt32RelPtr, VMInt8RelPtr
863       */       */
864      struct VMRelPtr {      struct VMRelPtr {
865          void** base; ///< Base pointer.          void** base; ///< Base pointer.
866          int offset;  ///< Offset (in bytes) relative to base pointer.          vmint offset;  ///< Offset (in bytes) relative to base pointer.
867          bool readonly; ///< Whether the pointed data may be modified or just be read.          bool readonly; ///< Whether the pointed data may be modified or just be read.
868      };      };
869    
870      /** @brief Pointer to built-in VM integer variable (of C/C++ type int).      /** @brief Pointer to built-in VM integer variable (interface class).
871         *
872         * This class acts as an abstract interface to all built-in integer script
873         * variables, independent of their actual native size (i.e. some built-in
874         * script variables are internally using a native int size of 64 bit or 32
875         * bit or 8 bit). The virtual machine is using this interface class instead
876         * of its implementing descendants (VMInt64RelPtr, VMInt32RelPtr,
877         * VMInt8RelPtr) in order for the virtual machine for not being required to
878         * handle each of them differently.
879         */
880        struct VMIntPtr {
881            virtual vmint evalInt() = 0;
882            virtual void assign(vmint i) = 0;
883            virtual bool isAssignable() const = 0;
884        };
885    
886        /** @brief Pointer to built-in VM integer variable (of C/C++ type int64_t).
887         *
888         * Used for defining built-in 64 bit integer script variables.
889         *
890         * @b CAUTION: You may only use this class for pointing to C/C++ variables
891         * of type "int64_t" (thus being exactly 64 bit in size). If the C/C++ int
892         * variable you want to reference is only 32 bit in size then you @b must
893         * use VMInt32RelPtr instead! Respectively for a referenced native variable
894         * with only 8 bit in size you @b must use VMInt8RelPtr instead!
895         *
896         * For efficiency reasons the actual native C/C++ int variable is referenced
897         * by two components here. The actual native int C/C++ variable in memory
898         * is dereferenced at VM run-time by taking the @c base pointer dereference
899         * and adding @c offset bytes. This has the advantage that for a large
900         * number of built-in int variables, only one (or few) base pointer need
901         * to be re-assigned before running a script, instead of updating each
902         * built-in variable each time before a script is executed.
903         *
904         * Refer to DECLARE_VMINT() for example code.
905         *
906         * @see VMInt32RelPtr, VMInt8RelPtr, DECLARE_VMINT()
907         */
908        struct VMInt64RelPtr : VMRelPtr, VMIntPtr {
909            VMInt64RelPtr() {
910                base   = NULL;
911                offset = 0;
912                readonly = false;
913            }
914            VMInt64RelPtr(const VMRelPtr& data) {
915                base   = data.base;
916                offset = data.offset;
917                readonly = false;
918            }
919            vmint evalInt() OVERRIDE {
920                return (vmint)*(int64_t*)&(*(uint8_t**)base)[offset];
921            }
922            void assign(vmint i) OVERRIDE {
923                *(int64_t*)&(*(uint8_t**)base)[offset] = (int64_t)i;
924            }
925            bool isAssignable() const OVERRIDE { return !readonly; }
926        };
927    
928        /** @brief Pointer to built-in VM integer variable (of C/C++ type int32_t).
929       *       *
930       * Used for defining built-in 32 bit integer script variables.       * Used for defining built-in 32 bit integer script variables.
931       *       *
932       * @b CAUTION: You may only use this class for pointing to C/C++ variables       * @b CAUTION: You may only use this class for pointing to C/C++ variables
933       * of type "int" (which on most systems is 32 bit in size). If the C/C++ int       * of type "int32_t" (thus being exactly 32 bit in size). If the C/C++ int
934       * variable you want to reference is only 8 bit in size, then you @b must       * variable you want to reference is 64 bit in size then you @b must use
935       * use VMInt8RelPtr instead!       * VMInt64RelPtr instead! Respectively for a referenced native variable with
936         * only 8 bit in size you @b must use VMInt8RelPtr instead!
937       *       *
938       * For efficiency reasons the actual native C/C++ int variable is referenced       * For efficiency reasons the actual native C/C++ int variable is referenced
939       * by two components here. The actual native int C/C++ variable in memory       * by two components here. The actual native int C/C++ variable in memory
# Line 498  namespace LinuxSampler { Line 945  namespace LinuxSampler {
945       *       *
946       * Refer to DECLARE_VMINT() for example code.       * Refer to DECLARE_VMINT() for example code.
947       *       *
948       * @see VMInt8RelPtr, DECLARE_VMINT()       * @see VMInt64RelPtr, VMInt8RelPtr, DECLARE_VMINT()
949       */       */
950      struct VMIntRelPtr : VMRelPtr {      struct VMInt32RelPtr : VMRelPtr, VMIntPtr {
951          VMIntRelPtr() {          VMInt32RelPtr() {
952              base   = NULL;              base   = NULL;
953              offset = 0;              offset = 0;
954              readonly = false;              readonly = false;
955          }          }
956          VMIntRelPtr(const VMRelPtr& data) {          VMInt32RelPtr(const VMRelPtr& data) {
957              base   = data.base;              base   = data.base;
958              offset = data.offset;              offset = data.offset;
959              readonly = false;              readonly = false;
960          }          }
961          virtual int evalInt() { return *(int*)&(*(uint8_t**)base)[offset]; }          vmint evalInt() OVERRIDE {
962          virtual void assign(int i) { *(int*)&(*(uint8_t**)base)[offset] = i; }              return (vmint)*(int32_t*)&(*(uint8_t**)base)[offset];
963            }
964            void assign(vmint i) OVERRIDE {
965                *(int32_t*)&(*(uint8_t**)base)[offset] = (int32_t)i;
966            }
967            bool isAssignable() const OVERRIDE { return !readonly; }
968      };      };
969    
970      /** @brief Pointer to built-in VM integer variable (of C/C++ type int8_t).      /** @brief Pointer to built-in VM integer variable (of C/C++ type int8_t).
# Line 521  namespace LinuxSampler { Line 973  namespace LinuxSampler {
973       *       *
974       * @b CAUTION: You may only use this class for pointing to C/C++ variables       * @b CAUTION: You may only use this class for pointing to C/C++ variables
975       * of type "int8_t" (8 bit integer). If the C/C++ int variable you want to       * of type "int8_t" (8 bit integer). If the C/C++ int variable you want to
976       * reference is an "int" type (which is 32 bit on most systems), then you       * reference is not exactly 8 bit in size then you @b must respectively use
977       * @b must use VMIntRelPtr instead!       * either VMInt32RelPtr for native 32 bit variables or VMInt64RelPtrl for
978         * native 64 bit variables instead!
979       *       *
980       * For efficiency reasons the actual native C/C++ int variable is referenced       * For efficiency reasons the actual native C/C++ int variable is referenced
981       * by two components here. The actual native int C/C++ variable in memory       * by two components here. The actual native int C/C++ variable in memory
# Line 534  namespace LinuxSampler { Line 987  namespace LinuxSampler {
987       *       *
988       * Refer to DECLARE_VMINT() for example code.       * Refer to DECLARE_VMINT() for example code.
989       *       *
990       * @see VMIntRelPtr, DECLARE_VMINT()       * @see VMIntRel32Ptr, VMIntRel64Ptr, DECLARE_VMINT()
991       */       */
992      struct VMInt8RelPtr : VMIntRelPtr {      struct VMInt8RelPtr : VMRelPtr, VMIntPtr {
993          VMInt8RelPtr() : VMIntRelPtr() {}          VMInt8RelPtr() {
994          VMInt8RelPtr(const VMRelPtr& data) : VMIntRelPtr(data) {}              base   = NULL;
995          virtual int evalInt() OVERRIDE {              offset = 0;
996              return *(uint8_t*)&(*(uint8_t**)base)[offset];              readonly = false;
997            }
998            VMInt8RelPtr(const VMRelPtr& data) {
999                base   = data.base;
1000                offset = data.offset;
1001                readonly = false;
1002            }
1003            vmint evalInt() OVERRIDE {
1004                return (vmint)*(uint8_t*)&(*(uint8_t**)base)[offset];
1005          }          }
1006          virtual void assign(int i) OVERRIDE {          void assign(vmint i) OVERRIDE {
1007              *(uint8_t*)&(*(uint8_t**)base)[offset] = i;              *(uint8_t*)&(*(uint8_t**)base)[offset] = (uint8_t)i;
1008          }          }
1009            bool isAssignable() const OVERRIDE { return !readonly; }
1010      };      };
1011    
1012        /** @brief Pointer to built-in VM integer variable (of C/C++ type vmint).
1013         *
1014         * Use this typedef if the native variable to be pointed to is using the
1015         * typedef vmint. If the native C/C++ variable to be pointed to is using
1016         * another C/C++ type then better use one of VMInt64RelPtr or VMInt32RelPtr
1017         * instead.
1018         */
1019        typedef VMInt64RelPtr VMIntRelPtr;
1020    
1021      #if HAVE_CXX_EMBEDDED_PRAGMA_DIAGNOSTICS      #if HAVE_CXX_EMBEDDED_PRAGMA_DIAGNOSTICS
1022      # define COMPILER_DISABLE_OFFSETOF_WARNING                    \      # define COMPILER_DISABLE_OFFSETOF_WARNING                    \
1023          _Pragma("GCC diagnostic push")                            \          _Pragma("GCC diagnostic push")                            \
# Line 559  namespace LinuxSampler { Line 1030  namespace LinuxSampler {
1030      #endif      #endif
1031    
1032      /**      /**
1033       * Convenience macro for initializing VMIntRelPtr and VMInt8RelPtr       * Convenience macro for initializing VMInt64RelPtr, VMInt32RelPtr and
1034       * structures. Usage example:       * VMInt8RelPtr structures. Usage example:
1035       * @code       * @code
1036       * struct Foo {       * struct Foo {
1037       *   uint8_t a; // native representation of a built-in integer script variable       *   uint8_t a; // native representation of a built-in integer script variable
1038       *   int b; // native representation of another built-in integer script variable       *   int64_t b; // native representation of another built-in integer script variable
1039       *   int c; // native representation of another built-in integer script variable       *   int64_t c; // native representation of another built-in integer script variable
1040       *   uint8_t d; // native representation of another built-in integer script variable       *   uint8_t d; // native representation of another built-in integer script variable
1041       * };       * };
1042       *       *
# Line 576  namespace LinuxSampler { Line 1047  namespace LinuxSampler {
1047       * Foo* pFoo;       * Foo* pFoo;
1048       *       *
1049       * VMInt8RelPtr varA = DECLARE_VMINT(pFoo, class Foo, a);       * VMInt8RelPtr varA = DECLARE_VMINT(pFoo, class Foo, a);
1050       * VMIntRelPtr  varB = DECLARE_VMINT(pFoo, class Foo, b);       * VMInt64RelPtr varB = DECLARE_VMINT(pFoo, class Foo, b);
1051       * VMIntRelPtr  varC = DECLARE_VMINT(pFoo, class Foo, c);       * VMInt64RelPtr varC = DECLARE_VMINT(pFoo, class Foo, c);
1052       * VMInt8RelPtr varD = DECLARE_VMINT(pFoo, class Foo, d);       * VMInt8RelPtr varD = DECLARE_VMINT(pFoo, class Foo, d);
1053       *       *
1054       * pFoo = &foo1;       * pFoo = &foo1;
# Line 612  namespace LinuxSampler { Line 1083  namespace LinuxSampler {
1083      )                                                             \      )                                                             \
1084    
1085      /**      /**
1086       * Same as DECLARE_VMINT(), but this one defines the VMIntRelPtr and       * Same as DECLARE_VMINT(), but this one defines the VMInt64RelPtr,
1087       * VMInt8RelPtr structures to be of read-only type. That means the script       * VMInt32RelPtr and VMInt8RelPtr structures to be of read-only type.
1088       * parser will abort any script at parser time if the script is trying to       * That means the script parser will abort any script at parser time if the
1089       * modify such a read-only built-in variable.       * script is trying to modify such a read-only built-in variable.
1090       *       *
1091       * @b NOTE: this is only intended for built-in read-only variables that       * @b NOTE: this is only intended for built-in read-only variables that
1092       * may change during runtime! If your built-in variable's data is rather       * may change during runtime! If your built-in variable's data is rather
# Line 638  namespace LinuxSampler { Line 1109  namespace LinuxSampler {
1109      /** @brief Built-in VM 8 bit integer array variable.      /** @brief Built-in VM 8 bit integer array variable.
1110       *       *
1111       * Used for defining built-in integer array script variables (8 bit per       * Used for defining built-in integer array script variables (8 bit per
1112       * array element). Currently there is no support for any other kind of array       * array element). Currently there is no support for any other kind of
1113       * type. So all integer arrays of scripts use 8 bit data types.       * built-in array type. So all built-in integer arrays accessed by scripts
1114         * use 8 bit data types.
1115       */       */
1116      struct VMInt8Array {      struct VMInt8Array {
1117          int8_t* data;          int8_t* data;
1118          int size;          vmint size;
1119          bool readonly; ///< Whether the array data may be modified or just be read.          bool readonly; ///< Whether the array data may be modified or just be read.
1120    
1121          VMInt8Array() : data(NULL), size(0), readonly(false) {}          VMInt8Array() : data(NULL), size(0), readonly(false) {}
# Line 651  namespace LinuxSampler { Line 1123  namespace LinuxSampler {
1123    
1124      /** @brief Virtual machine script variable.      /** @brief Virtual machine script variable.
1125       *       *
1126       * Common interface for all variables accessed in scripts.       * Common interface for all variables accessed in scripts, independent of
1127         * their precise data type.
1128       */       */
1129      class VMVariable : virtual public VMExpr {      class VMVariable : virtual public VMExpr {
1130      public:      public:
# Line 672  namespace LinuxSampler { Line 1145  namespace LinuxSampler {
1145           */           */
1146          virtual void assignExpr(VMExpr* expr) = 0;          virtual void assignExpr(VMExpr* expr) = 0;
1147      };      };
1148        
1149      /** @brief Dynamically executed variable (abstract base class).      /** @brief Dynamically executed variable (abstract base class).
1150       *       *
1151       * Interface for the implementation of a dynamically generated content of       * Interface for the implementation of a dynamically generated content of
# Line 746  namespace LinuxSampler { Line 1219  namespace LinuxSampler {
1219       */       */
1220      class VMDynIntVar : virtual public VMDynVar, virtual public VMIntExpr {      class VMDynIntVar : virtual public VMDynVar, virtual public VMIntExpr {
1221      public:      public:
1222            MetricPrefix_t unitPrefix(vmuint i) const OVERRIDE { return VM_NO_PREFIX; }
1223            StdUnit_t unitType() const OVERRIDE { return VM_NO_UNIT; }
1224            bool isFinal() const OVERRIDE { return false; }
1225      };      };
1226    
1227      /** @brief Dynamically executed variable (of string data type).      /** @brief Dynamically executed variable (of string data type).
# Line 786  namespace LinuxSampler { Line 1262  namespace LinuxSampler {
1262          virtual VMFunction* functionByName(const String& name) = 0;          virtual VMFunction* functionByName(const String& name) = 0;
1263    
1264          /**          /**
1265             * Returns @c true if the passed built-in function is disabled and
1266             * should be ignored by the parser. This method is called by the
1267             * parser on preprocessor level for each built-in function call within
1268             * a script. Accordingly if this method returns @c true, then the
1269             * respective function call is completely filtered out on preprocessor
1270             * level, so that built-in function won't make into the result virtual
1271             * machine representation, nor would expressions of arguments passed to
1272             * that built-in function call be evaluated, nor would any check
1273             * regarding correct usage of the built-in function be performed.
1274             * In other words: a disabled function call ends up as a comment block.
1275             *
1276             * @param fn - built-in function to be checked
1277             * @param ctx - parser context at the position where the built-in
1278             *              function call is located within the script
1279             */
1280            virtual bool isFunctionDisabled(VMFunction* fn, VMParserContext* ctx) = 0;
1281    
1282            /**
1283           * Returns a variable name indexed map of all built-in script variables           * Returns a variable name indexed map of all built-in script variables
1284           * which point to native "int" scalar (usually 32 bit) variables.           * which point to native "int" scalar (usually 32 bit) variables.
1285           */           */
1286          virtual std::map<String,VMIntRelPtr*> builtInIntVariables() = 0;          virtual std::map<String,VMIntPtr*> builtInIntVariables() = 0;
1287    
1288          /**          /**
1289           * Returns a variable name indexed map of all built-in script integer           * Returns a variable name indexed map of all built-in script integer
# Line 801  namespace LinuxSampler { Line 1295  namespace LinuxSampler {
1295           * Returns a variable name indexed map of all built-in constant script           * Returns a variable name indexed map of all built-in constant script
1296           * variables, which never change their value at runtime.           * variables, which never change their value at runtime.
1297           */           */
1298          virtual std::map<String,int> builtInConstIntVariables() = 0;          virtual std::map<String,vmint> builtInConstIntVariables() = 0;
1299    
1300          /**          /**
1301           * Returns a variable name indexed map of all built-in dynamic variables,           * Returns a variable name indexed map of all built-in dynamic variables,
# Line 850  namespace LinuxSampler { Line 1344  namespace LinuxSampler {
1344           *           *
1345           * @see ScriptVM::exec()           * @see ScriptVM::exec()
1346           */           */
1347          virtual int suspensionTimeMicroseconds() const = 0;          virtual vmint suspensionTimeMicroseconds() const = 0;
1348    
1349          /**          /**
1350           * Causes all polyphonic variables to be reset to zero values. A           * Causes all polyphonic variables to be reset to zero values. A
# Line 879  namespace LinuxSampler { Line 1373  namespace LinuxSampler {
1373           * instance.           * instance.
1374           */           */
1375          virtual void signalAbort() = 0;          virtual void signalAbort() = 0;
1376    
1377            /**
1378             * Copies the current entire execution state from this object to the
1379             * given object. So this can be used to "fork" a new script thread which
1380             * then may run independently with its own polyphonic data for instance.
1381             */
1382            virtual void forkTo(VMExecContext* ectx) const = 0;
1383    
1384            /**
1385             * In case the script called the built-in exit() function and passed a
1386             * value as argument to the exit() function, then this method returns
1387             * the value that had been passed as argument to the exit() function.
1388             * Otherwise if the exit() function has not been called by the script
1389             * or no argument had been passed to the exit() function, then this
1390             * method returns NULL instead.
1391             *
1392             * Currently this is only used for automated test cases against the
1393             * script engine, which return some kind of value in the individual
1394             * test case scripts to check their behaviour in automated way. There
1395             * is no purpose for this mechanism in production use. Accordingly this
1396             * exit result value is @b always completely ignored by the sampler
1397             * engines.
1398             *
1399             * Officially the built-in exit() function does not expect any arguments
1400             * to be passed to its function call, and by default this feature is
1401             * hence disabled and will yield in a parser error unless
1402             * ScriptVM::setExitResultEnabled() was explicitly set.
1403             *
1404             * @see ScriptVM::setExitResultEnabled()
1405             */
1406            virtual VMExpr* exitResult() = 0;
1407      };      };
1408    
1409      /** @brief Script callback for a certain event.      /** @brief Script callback for a certain event.
# Line 910  namespace LinuxSampler { Line 1435  namespace LinuxSampler {
1435      };      };
1436    
1437      /**      /**
1438         * Reflects the precise position and span of a specific code block within
1439         * a script. This is currently only used for the locations of commented
1440         * code blocks due to preprocessor statements, and for parser errors and
1441         * parser warnings.
1442         *
1443         * @see ParserIssue for code locations of parser errors and parser warnings
1444         *
1445         * @see VMParserContext::preprocessorComments() for locations of code which
1446         *      have been filtered out by preprocessor statements
1447         */
1448        struct CodeBlock {
1449            int firstLine; ///< The first line number of this code block within the script (indexed with 1 being the very first line).
1450            int lastLine; ///< The last line number of this code block within the script.
1451            int firstColumn; ///< The first column of this code block within the script (indexed with 1 being the very first column).
1452            int lastColumn; ///< The last column of this code block within the script.
1453        };
1454    
1455        /**
1456       * Encapsulates a noteworty parser issue. This encompasses the type of the       * Encapsulates a noteworty parser issue. This encompasses the type of the
1457       * issue (either a parser error or parser warning), a human readable       * issue (either a parser error or parser warning), a human readable
1458       * explanation text of the error or warning and the location of the       * explanation text of the error or warning and the location of the
# Line 917  namespace LinuxSampler { Line 1460  namespace LinuxSampler {
1460       *       *
1461       * @see VMSourceToken for processing syntax highlighting instead.       * @see VMSourceToken for processing syntax highlighting instead.
1462       */       */
1463      struct ParserIssue {      struct ParserIssue : CodeBlock {
1464          String txt; ///< Human readable explanation text of the parser issue.          String txt; ///< Human readable explanation text of the parser issue.
         int firstLine; ///< The first line number within the script where this issue was encountered (indexed with 1 being the very first line).  
         int lastLine; ///< The last line number within the script where this issue was encountered.  
         int firstColumn; ///< The first column within the script where this issue was encountered (indexed with 1 being the very first column).  
         int lastColumn; ///< The last column within the script where this issue was encountered.  
1465          ParserIssueType_t type; ///< Whether this issue is either a parser error or just a parser warning.          ParserIssueType_t type; ///< Whether this issue is either a parser error or just a parser warning.
1466    
1467          /**          /**
# Line 962  namespace LinuxSampler { Line 1501  namespace LinuxSampler {
1501              case EMPTY_EXPR: return "empty";              case EMPTY_EXPR: return "empty";
1502              case INT_EXPR: return "integer";              case INT_EXPR: return "integer";
1503              case INT_ARR_EXPR: return "integer array";              case INT_ARR_EXPR: return "integer array";
1504                case REAL_EXPR: return "real number";
1505                case REAL_ARR_EXPR: return "real number array";
1506              case STRING_EXPR: return "string";              case STRING_EXPR: return "string";
1507              case STRING_ARR_EXPR: return "string array";              case STRING_ARR_EXPR: return "string array";
1508          }          }
1509          return "invalid";          return "invalid";
1510      }      }
1511    
1512        /**
1513         * Convenience function used for retrieving the data type of a script
1514         * variable name being passed to this function.
1515         *
1516         * @param name - some script variable name (e.g. "$foo")
1517         * @return variable's data type (e.g. INT_EXPR for example above)
1518         */
1519        inline ExprType_t exprTypeOfVarName(const String& name) {
1520            if (name.empty()) return (ExprType_t) -1;
1521            const char prefix = name[0];
1522            switch (prefix) {
1523                case '$': return INT_EXPR;
1524                case '%': return INT_ARR_EXPR;
1525                case '~': return REAL_EXPR;
1526                case '?': return REAL_ARR_EXPR;
1527                case '@': return STRING_EXPR;
1528                case '!': return STRING_ARR_EXPR;
1529            }
1530            return (ExprType_t) -1;
1531        }
1532    
1533        /**
1534         * Returns @c true in case the passed data type is some array data type.
1535         */
1536        inline bool isArray(const ExprType_t& type) {
1537            return type == INT_ARR_EXPR || type == REAL_ARR_EXPR ||
1538                   type == STRING_ARR_EXPR;
1539        }
1540    
1541        /**
1542         * Returns @c true in case the passed data type is some scalar number type
1543         * (i.e. not an array and not a string).
1544         */
1545        inline bool isScalarNumber(const ExprType_t& type) {
1546            return type == INT_EXPR || type == REAL_EXPR;
1547        }
1548    
1549        /**
1550         * Convenience function used for converting an StdUnit_t constant to a
1551         * string, i.e. for generating error message by the parser.
1552         */
1553        inline String unitTypeStr(const StdUnit_t& type) {
1554            switch (type) {
1555                case VM_NO_UNIT: return "none";
1556                case VM_SECOND: return "seconds";
1557                case VM_HERTZ: return "Hz";
1558                case VM_BEL: return "Bel";
1559            }
1560            return "invalid";
1561        }
1562    
1563      /** @brief Virtual machine representation of a script.      /** @brief Virtual machine representation of a script.
1564       *       *
1565       * An instance of this abstract base class represents a parsed script,       * An instance of this abstract base class represents a parsed script,
# Line 1002  namespace LinuxSampler { Line 1594  namespace LinuxSampler {
1594          virtual std::vector<ParserIssue> warnings() const = 0;          virtual std::vector<ParserIssue> warnings() const = 0;
1595    
1596          /**          /**
1597             * Returns all code blocks of the script which were filtered out by the
1598             * preprocessor.
1599             */
1600            virtual std::vector<CodeBlock> preprocessorComments() const = 0;
1601    
1602            /**
1603           * Returns the translated virtual machine representation of an event           * Returns the translated virtual machine representation of an event
1604           * handler block (i.e. "on note ... end on" code block) within the           * handler block (i.e. "on note ... end on" code block) within the
1605           * parsed script. This translated representation of the event handler           * parsed script. This translated representation of the event handler
# Line 1061  namespace LinuxSampler { Line 1659  namespace LinuxSampler {
1659          bool isStringLiteral() const; ///< Returns true in case this source token represents a string literal (i.e. "Some text").          bool isStringLiteral() const; ///< Returns true in case this source token represents a string literal (i.e. "Some text").
1660          bool isComment() const; ///< Returns true in case this source token represents a source code comment.          bool isComment() const; ///< Returns true in case this source token represents a source code comment.
1661          bool isPreprocessor() const; ///< Returns true in case this source token represents a preprocessor statement.          bool isPreprocessor() const; ///< Returns true in case this source token represents a preprocessor statement.
1662            bool isMetricPrefix() const;
1663            bool isStdUnit() const;
1664          bool isOther() const; ///< Returns true in case this source token represents anything else not covered by the token types mentioned above.          bool isOther() const; ///< Returns true in case this source token represents anything else not covered by the token types mentioned above.
1665    
1666          // extended types          // extended types
1667          bool isIntegerVariable() const; ///< Returns true in case this source token represents an integer variable name (i.e. "$someIntVariable").          bool isIntegerVariable() const; ///< Returns true in case this source token represents an integer variable name (i.e. "$someIntVariable").
1668            bool isRealVariable() const; ///< Returns true in case this source token represents a floating point variable name (i.e. "~someRealVariable").
1669          bool isStringVariable() const; ///< Returns true in case this source token represents an string variable name (i.e. "\@someStringVariable").          bool isStringVariable() const; ///< Returns true in case this source token represents an string variable name (i.e. "\@someStringVariable").
1670          bool isArrayVariable() const; ///< Returns true in case this source token represents an array variable name (i.e. "%someArryVariable").          bool isIntArrayVariable() const; ///< Returns true in case this source token represents an integer array variable name (i.e. "%someArrayVariable").
1671            bool isRealArrayVariable() const; ///< Returns true in case this source token represents a real number array variable name (i.e. "?someArrayVariable").
1672            bool isArrayVariable() const DEPRECATED_API; ///< Returns true in case this source token represents an @b integer array variable name (i.e. "%someArrayVariable"). @deprecated This method will be removed, use isIntArrayVariable() instead.
1673          bool isEventHandlerName() const; ///< Returns true in case this source token represents an event handler name (i.e. "note", "release", "controller").          bool isEventHandlerName() const; ///< Returns true in case this source token represents an event handler name (i.e. "note", "release", "controller").
1674    
1675          VMSourceToken& operator=(const VMSourceToken& other);          VMSourceToken& operator=(const VMSourceToken& other);

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

  ViewVC Help
Powered by ViewVC