The Playable interface

Each component that comprises a Song can produce some sort of stream of MIDI data that needs to be scheduled to a timed output. To simplify this process they implement the Playable interface. This makes the Song structure use a form of the composite design pattern (GoF book).

The Playable meerly defines one method, creating for the client a PlayableIterator that can iterate over the MIDI data in the output stream. This is a form of the iterator design pattern.

Each different kind of Playable object provides it's own implementation of the PlayableIterator interface that knows how to generate the MIDI events.

The user can ignore the individual song components Playable interface, and meerly use the Song's PlayableIterator that will in turn use the Playable iterators of all sub components to create a MIDI data stream for the whole song.


+------------\     +------------+      creates +--------------------+
| Interface  |_\   |  Playable  |--------------|  PlayableIterator  |
|              |   +------------+              +--------------------+
+------------- +         ^                               ^
                         |                               |
+------------\           |                               |
|   Example  |_\   +------------+              +--------------------+
| Implemenation |  |    Song    |              |    SongIterator    |
+---------------+  +------------+              +--------------------+

See also

Midi.h for descriptions of the TSE representation of MIDI data.
© Pete Goodliffe, 2000