# Song class hierarchy

TSE3 has been designed in an object oriented fashion. Hence it takes an object oriented approach to it's song structure. This provides a lot of the powerful expressive features of the system.

The follows a class diagram of the song structure, which is explained below.

                  +--------+                      1+----------------+
                  |  Song  |---------------+-------|   TempoTrack   |
                  +--------+               |       +----------------+
                   |      |                |
                   |      |                |      1+----------------+
                  *|      |                +-------|  TimeSigTrack  |
            +---------+   |in PhraseList   |       +----------------+
            |  Track  |   |                |
            +---------+   |                |      1+----------------+
                 |        |                +-------|   FlagTrack    |
     time ordered|        +------+                 +----------------+
                *|              *|
            +----+----+     1+----------+
            |  Part   |------|  Phrase  |
            +---------+      +----------+

The Song is a description of a particular piece of music. It consists primarily of Tracks, Parts and Phrases. Tracks are the sections of a Song that play simultaneously. They correspond loosely to the different people in a band playing together. One Track can perhaps handle the melody whilst another handles the bassline and yet another the drum beat.

Phrases are (typically small) snatches of music. They are recorded by the user can stored in a PhraseList in the Song. Once a Phrase has been recorded it needs to be placed into a Track to make some sound during playback of the Song. This is achieved with a Part.

Parts represent the physical placement of a Phrase in a Track. Since you can have any number of Parts in different Tracks using the same Phrase, it is easy to edit the one Phrase and change how each Part sounds. There is no messy ghosting or memory expensive copying of data.

Both Tracks and Parts contain a number of parameters that can affect the MIDI data that they produce. For example, Parts contain a number of real time filters such as linear quantise and velocity window clipping. Both also have a set of MIDI controls (such as pan, volume, program etc) that can be sent at their start.

In addition to these Song components, there are additional tracks known as the Master Tracks. They are

The TempoTrack
  This defines any tempo changes that occur in the Song. The TempoTrack can be disabled preventing tempo changes from occurring during playback.
The TimeSig Track
  This defines any time signature changes that occur in the Song. A change in time signature does not effect the recorded data but does affect the metronome at playback. The TimeSigTrack can be disabled preventing time signature changes from occurring during playback.
The FlagTrack
  This is a track holding a number of general purpose markers. They do not affect playback in any way, but allow the user to mark certain positions to find it easier to navigate to them.
The Left and Right Markers
  The Song also contains two marker positions about which 'repeat' takes place, if enabled. When playback reaches the right marker it jumps to the position of the left one.

### More on Phrases

Phrases are not an editable type: once you have created a Phrase that MIDI data it contains will remain as it is until the Phrase is deleted.

To create a Phrase you use a PhraseEdit object. This is an editable type of Phrase, which once editing is completed can be used to create a Phrase.

These classes both inherit from a base MidiData class as shown below.

                  +------------+
                  |  MidiData  |
                  +------------+
                   ^          ^
                   |          |
         +----------+        +--------------+
         |  Phrase  |        |  PhraseEdit  |
         +----------+        +--------------+
         | Title    |
         +----------+

The effect of editing a Phrase is achieved by creating a new Phrase with the same name as an existing Phrase, making all Parts that use the old Phrase now use the new Phrase, deleting the old Phrase and putting the new Phrase into the PhraseList. This operation is provided in the Song class.