Conditions
Every function from the function library can be applied conditionally. To do so, use the special cond
keyword. This keyword is available to every function. There are many types of conditions you can apply on your pattern and you can even create conditions manually. Conditions are working by providing them binary values:
1
represents truth:True
.0
represents false:False
.
The function above will turn the sequence into a palindrome but only on beats 1 and 3:
Pa >> d('(pal F A C E ::cond (beat 0 2))')
In the Sardine Pattern Language, everything is a function, including the logical constructs themselves (if
, while
). It means that you can also add conditions to your conditions, etc…
If condition
The if
condition is a binary condition: it will execute something if true, something else if false. In the following example, the function will play a clap for every pair bar (2, 4, etc.) and another sample on every odd bar.
Pa >> d('(if (every 2) cp sid')
The nif
function can be used to reverse the logic (not if).
While condition
The while
condition is an unary condition: it will execute something if true, nothing at all if false. In the following example, the function will sometimes play a clap:
Pa >> d('(while rand*5>2 cp)')
In that specific case, as a demonstration, we craft our own condition by using the greater-than (>
) operator.
In the semblance of if
and nif
, there is also a nwhile
condition to reverse the condition logic.
Special condition functions
Some functions from the library can be used to build more complex conditions in conjunction with if
or while
. Use them wisely:
Function name | Arguments | Description | Result |
beat | ... numbers | 1 or more beats numbers to match | Boolean |
phase | low high | Check if currently in-between range of phase (between 0.0 and 1.0) | Boolean |
every | ... bar_numbers | Similar to TidalCycles every function. Will be true every x bars. | Boolean |
proba | probability | Simple probability in % | Boolean |
modbar | choice faces | Simulation of a dice with n faces. | Boolean |
obar | None | Check if the current bar is odd | Boolean |
ebar | None | Check if the current bar is even | Boolean |
modbar | modulo | Modulo against current bar number | Boolean |
The beat
function is a great place to start. Let’s play a clap on the start of the bar:
Pa >> d('(if (beat 0) cp)')
Let's add another beat to the equation. It will now also play on the following beat of the bar:
Pa >> d('(if (beat 0 1) cp)')
You get it. Other functions work similarly. These functions are cool but you might have guessed already that you can craft your own functions yourself if you are clever enough :) If you think of some cool functions to add, I’ll be more than happy to include them into Sardine.