Some functions have a test argument that defines conditions to manipulate another argument. This test argument can be replaced by a lambda function.
We need to remove octaves from a list of pitches in midicents, but there is no such function in OM.
The remove-dup function tests if two items in a list are equal and removes duplicates. | ![]() |
| ![]() |
The values of two pitches of an octave are not equal. Hence, the equality test used for removing items must be modified : the "test" argument of remove-dup must be replaced by a lambda function.
The following patch tests if the results of the division of pitches, modulo an octave, are equal, with the modulo function om//.
The first output of om// returns a quotient, its second output returns a rest : it is used for calculating the modulo of our values.
The = predicate tests if the rests of the same division performed upon two elements are equal. If so, the duplicate is removed.
Two values have the same modulo when their division by the same ratio produces the same rest .
The midicent value of an octava is 1200. Comparing the result of two values modulo 1200 allows to know if they have an octave relation. This means that an euclidean division by 1200 will return the same rest.
For instance : C4 is equal to 6000, C5 to 7200. F#4 is equal to 6400, F#5 to 7600.
C4 : (6000 / 1200) = 5, rest 0 C5 : (7200 / 1200) = 6, rest 0 |
F#4 : (6400 / 1200) = 5, rest 4 F#5 : (7600 / 1200) = 6, rest 4 |
The patch is now on "lambda" mode and connected as a test argument to remove-dup. It has two inlets, which specify that the lambda function takes two arguments.