Data AcQuisition And Real-Time AnalysisScope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
Contact us about
Changes Script Expressions
Changes script commands can accept expressions in place of most values, such as those that appear as n in command formats. An expression is a chain of values connected by arithmetic and/or logical and/or bitwise binary operators.
Signed integer math is used when setting everything but oscillators and User Variables Ua through Uz, which use unsigned fixed-point math. You may mix signed integer and unsigned fixed-point values in expressions, and they will be converted as needed.
+ Add - Subtract * Multiply / Divide % Modulus (remainder after division) >> Right binary shift << Left binary shift | Absolute value (unary)
Note that when used in unsigned fixed-point calculations the modulus operator returns the remainder after a full fixed-point division, which may include a fractional portion. This is unlike the analogous operation in main Daqarta macros and most conventional programming languages.
Signed integer calculations support the use of a leading minus sign to indicate unary negation, as in UA=-UA.
Note that the abolute value operation is unary: It only applies to the following term. It can not be combined with unary negation. You can use UA=|UA, but you can't use UA=-|UA to negate the absolute value all in one command. Instead, use UA=0-|UA.
Note that there must be no spaces in the expression, and that parentheses are not allowed for grouping terms... you must plan the expression so that operations proceed in the order the terms appear, using a simple 2-level operator precedence. (See Operator Precedence, below.)
You may sometimes need to break a long expression into separate smaller expressions assigned to intermediate variables, then combine them in a final expression.
Expressions can include random values, oscillators, computer keyboard states, mouse position, Buffer note values, and User Variables on the right side. The right side may also include other MIDI variables like Instrument number, Note Delay, Lag, Arpeggio, Level, Pan, etc.
Expressions may use printable single characters, in quotes, as their equivalent ASCII values. For example, UA="B" sets the value of UA to 66, the ASCII value for B. This is especially handy when testing computer keyboard input.
Random values and oscillators may use expressions for their limits values (the 10 and 20 in parentheses in the above example), but those expressions must not include random values or oscillators directly. Instead, you can set User Variables with the desired random or oscillator values and then use the variables for the limits in the expression.
Buffer commands include parentheses, but you can still use expressions that include random values or oscillators for the individual terms.
The command that includes the expression must fit on one line. If the expression is long, you may want to break it into smaller sub-expressions that are assigned to User Variables, then combine those in the final command.
Expressions normally aren't used for Voice number, Buffer number, or Oscillator number, which are usually explicit constant values. To use an expression, surround it with carets as in I<UA+UB>=12. Note that such careted expressions must not contain other careted expressions.
Logical (True/False or Boolean) operators regard any integer value above zero as True, and any value of zero or less as False. The result of a logical operation is always True = 1 or False = 0.
For unsigned fixed-point calculations, any non-zero value is True, which is 1.0000.
&& Logical AND || Logical OR ## Logical XOR (Exclusive OR) ! Logical NOT (unary)
Bitwise binary operations are logical operations that act on all bits of integer or fixed-point values.
& Bitwise AND | Bitwise OR # Bitwise XOR (exclusive OR) ~ Bitwise NOT (unary)
Note that the | bitwise OR operator is the same symbol used for ELSE in Changes script IF statements. There is no ambiguity as long as you remember that in these scripts there must be no spaces between terms in an expression (unlike macros, which don't care), and that there must be a space before the ELSE operator.
MIDI Changes script operators have a simple 2-level order of priority or precedence when combined in expressions. High-level operations are performed as soon as they are encountered (moving left to right), then their results are combined with low-level operations.
For example, in A+B*C||D the B*C term is found first, then added to A, then logically ORed with D.
Once again, parentheses are not allowed for grouping terms... you must plan the expression so that operations proceed in the desired order, subject to this precedence. This may occasionally require breaking things into separate smaller expressions assigned to intermediate variables, then combined in a final expression.
Questions? Comments? Contact us!We respond to ALL inquiries, typically within 24 hrs.
Over 30 Years of Innovative Instrumentation
© Copyright 2007 - 2013 by Interstellar Research
All rights reserved