Exercises in this lecture  previous -- Keyboard shortcut: 'p'  next -- Keyboard shortcut: 'n'  Go to the slide, where this exercise belongs -- Keyboard shortcut: 'u'  

Exercise 1.14
A music language in Scheme ****


Design a simple and small Lisp (Scheme) language for music. In this assignment, music is basically modelled in terms of notes and pauses. A note is characterized by a pitch value, a duration, and an instrument. A pause is characterized by a duration. A pitch value is an integer between 0 and 127 (where 60 is middle C). Durations are integers; 960 time units correspond roughly to a second. Instruments are represented as symbols, where the following are supported: Piano, Organ, Guitar, Violin, Flute, Trumpet, Helicopter eller Telephone.

Notes and pauses can be composed sequentially and in parallel. Conceptually, a MusicElement is either a Note, a Pause, a SequentialMusicElement or a ParallelMusicElement. A SequentialMusicElement represents a collection of MusicElements which are played in a strict sequence (one after the other). A ParallelMusicElement represents a collection of MusicElements which are played together (all starting at the same time). Please notice the recursive nature of this modelling: A SequentialMusicElement or a ParallelMusicElement consist of parts, which themselves may be of type SequentialMusicElement and/or ParallelMusicElement. Notes and pauses terminate the recursion. This model of music is a composite (design pattern), and it can be illustrated as in the following class hierarcy:

You are asked to program the following functionality:

Finally, your program must include an example of a simple canon song, and you must include the generated MIDI file in your submission.

The constructor function note-abs-time-with-duration takes the following parameters:

   (note-abs-time-with-duration abs-time channel note-number velocity duration)

where

The procedure transform-to-midi-file! transforms a list of note-abs-time-with-duration forms to a playable MIDI file. The procedure has the following signature:

   (transform-to-midi-file-and-write-to-file! low-level-event-list filename)

where

The low-level transformation functionality, which supports this exercise, can be downloadet from the course website in a number of different variants (depending on your Scheme platform).

Alternatively, a playable MIDI file can be generated by a web service from a list of note-abs-time-with-duration forms, provided that you use this simple implementation of the constructor function:

  ; Construct the low-level internal representation of a note (with note-number)
  ; bound to a particular absolute time (in time ticks), and with a given duration
  ; (in time ticks). The channel parameter encodes the instrument used.
  ; The velocity represents the strengths of the node.
  (define (note-abs-time-with-duration abs-time channel note-number velocity duration)
    (cons 'note-abs-time-with-duration (list abs-time channel note-number velocity duration)))

In case of inaccuracies in the formulation of this exercise, please state the conditions under which you have created you solution.


There is no solution to this exercise