Pattern Matching with Optima Lisp Library – Part 3

Written by on June 29, 2016 in LISP, Music, Programming with 0 Comments

In the previous two posts on this topic, I explained some of the basic pattern matching facilities of Optima library. There are many more advanced features in the library and I will try to discuss them in future posts. In today’s post, I will outline a straightforward application of the library for processing scores in Opusmodus.

In the post, I showed how we can build a simple framework in Opusmodus to read and transform MIDI files. Let us look at the same problem, but this time using Optima’s pattern matching capabilities.

The function convert-midifile-to-score takes as argument a MIDI file and returns its score representation. This representation is a list having the format:

(def-score <score-name> <title-section> <instrument section> … <instrument section>)

The <title-section> and <instrument section> are examples of property lists in Optima, so we can use the matching mechanisms available in that context.

For convenience, I have defined a function called process-score that takes a score object as well as two handler functions as arguments and works on the score.

Take a look at the two handler functions to see how Optima’s match function is used to de-structure the respective elements for further processing. In the handler for instrument section, for example, you can see how I modify the :volume parameter.

Optima Example

Optima Example

Optima opens up many interesting possibilities. Try to experiment.

You can download the code here. The example MIDI file is available here.

Tags: , ,

Subscribe

If you enjoyed this article, subscribe now to receive more just like it.

Subscribe via RSS Feed

Leave a Reply

Your email address will not be published.

Top