#QCON – Functional Programming, Music and Art

Last month, at QCON, I was in a great talk about functional programming languages (like Haskell) and their benefits to the Art world. The title of the talk was “How Functional Programmers can
Help, Inspire, or even Be Artists”. First of all I’d like to emphasize that all good programmers are artists, and as Richard Gabriel said 6 years ago, we programmers should be trained like artists. This is the major problem of our Computer Science Courses.

We all know artificial intelligence and computer tools are getting better and better. Right know we can easily produce things like this video:

In his talk, Prof. Paul Hudak also showed the examples of how we can do image animation using functional programming. The project he described was the Functional Reactive Animation (FRAN). All these things are not really new, but now that functional languages are returning to the main stream, those are the things that begin to appear. With tools like FRAN, an animation can be made as easy as this:

 growFlower u = buttonMonitor u `over`
stretch (grow u) flower

grow u = size
size = 1 + atRate rate u
rate = bSign u

Of course if you don’t know functional programming this is strange and difficult, but just think about an application which enlarges and shrinks an image when you press right or left mouse button. Think that this application can be written in those 6 code lines above.

Another application for functional programming is music. I recently acquired my MacBook last week I used Garage Band software for the first time. It is amazing what one can do with music software. I’ve already played with Fruit Loops Studio (my favorite), Sony SoundForge (great too) and who don’t remember one of the first DJ software called MixMan.

But the focus of Paul’s presentation wasn’t in using tools, but in how you can build wonderful tools with less lines of code, just because functional programming were made for this kind of application. He showed an example of his Haskore project, a nice way to compose music using the Haskell functional language. You specify the program in terms of WHAT to do, not HOW to do it.

The design goals of the Haskore project are:

  • Simplicity, expressiveness, generality and performance
  • Real-time sound synthesis
  • Transparency
  • Good for signal processing, algorithmic composition and interactive applications

A small example of how you can write a song using Haskore. Here is the language definition for notes:

type Octave = Int
type Dur = Rational
type Pitch = (PitchClass, Octave)
data PitchClass = Cff | Cf | C | Dff | Cs | Df | Css | D | Eff | Ds
data PitchClass = Cff | Cf | C | Dff | Cs | Df | Css | D | Eff | Ds
| Ef | Fff | Dss | E | Es | Ff | F | Gff | Ess | Fs | Gf | Fss | G
| Aff | Gs | Af | Gss | A | Bff | As | Bf | Ass | B | Bs | Bss
data Prim a = Note Dur a | Rest Dur

So, a prim(itive) can be defined as

  • a note with a Picth (class + octave) and a duration (expressed as a real number)
  • or a rest with a duration (silence)

For example:

Note (1/4) (C,4) :: Prim Pitch – it is a Middle C quarter note

The music is defined as a sequence of primitive notes, or notes played in parallel:

data Music a = Primitive (Prim a) –primitive note or rest
| Music a :+: Music a –sequential composition
| Music a :=: Music a –parallel composition
| Modify Control (Music a) –modifier

This is just a little example, the language is much more complete, you can even define performance and interpretation using the language.

Ok, all these geek things are great and we love it. But I still have some doubts about how the most rooted concepts of creativity can be applied to these computational tools. I mean, I love music and I feel it when I listen to it, I feel it when I play the guitar with my band. I really don’t know how this tools can contribute to produce human interaction. Of course one can go home and program a nice music using Haskore, or do a couple of clicks in Garage Band to produce a pre-factoried song. This is wonderful, people can produce things that they could not some time ago. But what about the old fashion music composition? Will people in future have to know something about the pentagram and how to write a sheet?

To fill a song I need to close my eyes. To compose something in my piano I just close my eyes and play what comes, don’t know from where. Is there any computer tool that I can use with closed eyes? Or am I wrong and closing eyes isn’t necessary?

Professor Paul ends his talk telling us about an computacional application for dance. It is like a pentagram like represantation of steps and body movements. All right! Now you can formally define a dance script and send it to a robot and he will do a nice job, dancing.

My final question is: what is the robot feeling while he is in his perfect dance defined by an algorithm?

1 Comment #QCON – Functional Programming, Music and Art

Leave a Reply

Your email address will not be published. Required fields are marked *