Making A MIDI Based Piano Using Scheme and Impromptu

As part of the tutorial in week 3 of KKB210, Computational Arts 1, we were introduced to the Scheme programming language through the Impromptu environment.

We were looking at creating audio based on the Apple Sound Bank Synthesizer using the MIDI specifications.

As an introduction to this topic we started off simply by writing the code to play a single note on a piano.

To start with, we clear everything from the au graph.

; Make sure that everything is disconnected

Next we define the piano and create a basic au graph that connects the piano library to the output.

; setup simple au graph
; piano -> output
(define piano (au:make-node "aumu" "dls " "appl"))
(au:connect-node piano 0 *au:output-node* 0)

Now we tell it to play a note. It is formatted as follows:

(play-note time instrument pitch volume duration)

Time is of course, when the note is to be played and duration is how long for. In the example below, we have defined that the note will be played immediately, it will be from the piano library we defined earlier, the pitch is set at 60 with a volume of 80, and it is held for 1 second. To add more notes, simply copy the line and paste it before or after and change the parameters to meet your needs.

; play note on piano
(play-note (now) piano 60 80 (* 1.0 *second*))

The following are not required. The first line just prints out information about the device in the log view.

The second line opens the Apple Sound Bank Synthesizer properties and parameters which allow you to adjust settings such as the tuning, volume, reverb volume, audio streaming, render quality, and CPU load restriction.

(au:print-audiounits "aumu")
(au:open-view piano)

Now this is all well and good, but how do you make it play?

The easiest way is to press Option > E on your keyboard to tell it to evaluate. Alternatively you can press the evaluate button in the top right of the Impromptu editor. Now, this won’t evaluate the entire program, you will have to do each line individually starting from the beginning. So in some cases, it may be best to evaluate as you are going.

Click near the start of a line and ensure that the entire line and anything on seperate lines that are within the series of commands are highlighted and then hit evaluate.

Work your way through and once you reach play-note, it should play the note with the parameters that you specified.

If you try to evaluate the note first, it won’t play. This is because the MIDI library hasn’t been connected yet.

If you have put in multiple notes than you will have noticed that you have to evaluate each note whenever you want to hear it. This is a pain and it will be addressed in my next post where we will be making a drum machine in Impromptu.

Tags: , , , , , ,

One Response to “Making A MIDI Based Piano Using Scheme and Impromptu”

  1. […] on from the MIDI-based piano idea that I outlined earlier, today we will be going through writing a drum machione in Impromptu […]

Leave a Reply