Recherche Google
OpenMusic 6 – User ManualAdvanced Visual Programming > Evaluation Modes > Lambda Mode > Lambda Function / Test Argument
previous pagenext page

Using a Lambda Function as a Test Argument

Some functions have a test argument that defines conditions to manipulate another argument. This test argument can be replaced by a lambda function.

Example : Removing Octaves from a List

We need to remove octaves from a list of pitches in midicents, but there is no such function in OM.

The Remove-Dup Function

The remove-dup function tests if two items in a list are equal and removes duplicates.

  • The first argument of "remove-dup" must be a list

  • Its second argument must be a test function.

  • By default, this test is 'eql : values that are equal to another value in the list will be removed.

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.

Using the Modulo Om// Function as a Test Argument for Remove-Dup

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.

Modulo
  • 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

Using the Test Argument in a Lambda Patch

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.

Remove-dup can now remove all values whose modulo is equal to the modulo of another value.
Remove-dup can now remove all values whose modulo is equal to the modulo of another value.
previous pagenext page
About...(c) Ircam - Centre PompidouMade with Scenari