Phrase

Phrases contain a sequence of Notes.  These Notes are played sequentially (i.e., one after the other).  If a gap is desired between two notes, then a Rest should be introduced.  Phrases may also contain chords (i.e., sets of concurrent notes).

Phrases have start times.  If no start time is specified, then the phrase starts at the end of the previous phrase (or at the beginning of the piece, if this is the first phrase).

The music library provides several functions to create musical phrases.  It also provides several others to retrieve or modify existing phrases.

Here are functions used to create phrases.  Each of these functions creates a new Phrase object, so you need to store it in a variable (or other memory location) to be able to use it later.

Function Description
Phrase() Creates an empty phrase. This phrase starts at the end of the previous phrase (or at the beginning of the piece, if this is the first phrase).
Phrase(startTime) Creates an empty phrase starting at specified time (e.g., 0.0 is beginning of piece, 1.0 is a quarter note into the piece, etc.).
Phrase(note) Creates a phrase containing the specified note.

Below are functions used to retrieve and modify attributes of existing phrases.  It is assumed that a phrase has already been created, for example, as follows:

 

Function Description
phr.addNote(note) Appends the given note to the phrase.
phr.addNote(pitch, duration) Appends a new note of given pitch (0-127) and duration (a float) to the phrase.
phr.addNoteList(listOfPitches, listOfDurations,
listOfDynamics,
listOfPanoramics,
listOfLengths)
Appends the notes specified in terms of pitches (a list), durations (a list), dynamics (a list), panning values (a list), and lengths (a list) to the phrase. The lists are parallel.  Dynamic, panoramic, and length lists are optional. Whereas duration determines the printed (notation) value of a note, the length of a note determines how long the note actually sounds.
phr.addChord(listOfPitches, duration, dynamic, panoramic, length) Appends a chord containing the specified pitches (a list) and having the specified duration (a float), dynamic (0 – 127), panoramic (0.0 – 1.0), and length (a float).  Dynamic, panoramic, and length values are optional. Whereas duration determines the printed (notation) value of a note, the length of a note determines how long the note actually sounds.
phr.getEndTime() Returns the phrase’s end time (a float).
phr.getNoteList() Returns the phrase’s notes (a list).
phr.getSize() Returns the number of notes in phrase phr.
phr.getStartTime() Returns the phrase’s start time (a float).
phr.setStartTime(startTime) Sets the phrase’s startTime (a float).
phr.getVolume() Returns the phrase’s volume (0 – 127).
phr.setVolume(volume) Set the volume (0 – 127) of the phrase.
phr.copy() Returns a new phrase with the same notes and attributes as phrase phr.  This is used to create a copy to be modified, while the original phrase is not affected.
phr.empty() Removes all notes from phrase phr.