Friday, October 18, 2013

Lesson 29 - Sequencing sounds

She has started to play the violin and likes to sing, play, dance and compose her own songs. Today I added some music capabilities to Turtle Roy to see if we can combine music and programming in our sessions.

First we tried the new play function. The function accepts any frequency and plays it for 500 milliseconds. There are also some predefined notes (c,d,e,f,g,a,b) that can be played.

So we started with

    play c

Then, to compose a sequence of notes into a single action, we used the familiar s function, and this is her first composition on the computer:

    s [play a, play b, play c]

Simple stuff, but demonstrates how you can use the same constructs (functions, lists, sequencing action) to do different things, including speech, music and graphics.

That was enough for today for her. Not for me though. I wanted to introduce parallel execution and multiple sound channels, of course. So now you can

    par [play [c,d,e], play [e,f,g]]

This means she can compose polyphonic music using functional programming techniques. How about that?

It was also fun to discover that the verbs compose and sequence apply to both programming and music and mean closely the same thing. It also occurred to me that music notes are just programs. 

The composer is a programmer and the musicians are CPU cores.