Programming reference¶
This section details the programming language as used to program Cues. This (unnamed) programming language is developed specifically for the PolyPulse shares many similarities to languages such as C, C++ and JavaScript.
//
is used to add comments to code. All text placed after //
until the end of the line is ignored by the compiler and purely so that humans can write down notes on what code does.
Functions¶
To make things happen functions need to be called. A function call starts with the name of the function:
setPattern(1, 4, 0);
^^^^^^^^^^
|
function name
Then follows (
and the arguments of the function. Arguments are options / settings that influence what the function does:
setPattern(1, 4, 0);
^^^^^^^
|
function arguments
Functions can have multiple arguments and are separated by ,
. After the last argument comes the )
and then finally the line is ended using ;
.
Listed below is an overview of the built-in functions and how to add them to cue steps:
Function signature |
How to add |
---|---|
|
pattern+# |
|
note_list+# |
|
shift+cue+# → switchCue() |
|
shift+cue+# → startCue() |
|
motion+# |
|
pattern+note_list+morph+# |
|
shift + touchpad |
|
edit → insert function |
|
edit → insert function |
If functions are called with arguments that are outside of their specified range (see the table below), the values are silently clipped to stay within the range. For example: setPattern(7, 2, 1)
will result in track 5 being set to pattern 2.
Argument |
Minimum |
Maximum |
Notes |
---|---|---|---|
|
1 |
5 |
|
|
0 |
24 |
|
|
|||
|
|||
|
|||
|
0.0 |
1.0 |
The top left corner of the touchpad corresponds to x=0 y=0 |
|
|||
|
0 |
1 |
0 = false, 1 = true |
|
|||
|
0 |
100 |
Control flow¶
Code is executed from top to bottom. Control flow statements can be used to change what is executed and how many times. To add control flow statements to code press edit and select insert control flow.
if
statement¶
if
statements can be used to only execute a section of code if a condition is “true”. The condition can be a single function call but also more complex expressions.
if condition {
// place code here that is executed if condition is true
}
if
statements can also be placed inside other if
statements:
if conditionA {
// place code here that is executed if conditionA is true
if conditionB {
// place code here that is executed is conditionA and conditionB are true
}
// place more here code that is executed if conditionA is true
}
See also
What exactly is “true” and “false” is explained in True and false.
else
statement¶
A single else
statement can be used after an if
statement to add code that is only executed if the condition is “false”:
if condition {
// place code here that is executed if condition is true
} else {
// place code here that is executed if condition is false
}
while
loop¶
while
loops can be used to executed a section of code multiple times as long as a condition is met. The condition can be a single function call but also more complex expressions.
while condition {
// place code here that is executed continuously until the condition is not true anymore
}
Note
while
loops are a programming concept that is something different than the concept of loops in music. while
loops simply repeat a bit of code x amount of time and are not in any way related or connected to a cue’s loop parameter.
Types¶
There are two number types:
Integers (
int
) are numbers without decimals such as-4
,0
,27
and3062
.Floats (
float
) are numbers with decimals such as-20.459
,0.0
,0.56
,3.1415
.
Computer CPU’s handle calculations with integers and floats differently. When calculating 4 / 5
using integer math the CPU will say the answer is 0
while a human would say the answer is 0.8. If a computer however uses floating point math and calculates 4.0 / 5.0
it will say the answer is 0.800000011920928955078125
. Adding floats together can also result in small errors: 0.2 + 0.9
for example results in 1.10000002384185791015625
.
In practice the difference between floats and integers are not something you should worry about:
If division is done with an
int
and afloat
or with twoint
s it converts both values tofloat
and then calculates the result of the division with floating point math.If function arguments are given in a different type than expected by the function, the arguments are converted to the expected type.
True and false¶
In some programming languages there exists a “boolean” type which can either be true
or false
. The PolyPulse does not have a “boolean” type. When evaluating conditions in if
and while
statements the following rule is used:
an
int
with a value of0
is “false”any other
int
(such as1
) is “true”