Skip to content

Phrase

A Phrase object contains a sequence of Note objects. These notes are played sequentially (i.e., one after the other). If a gap is desired between two notes, then a REST note 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).

Creating a Phrase

You can create a Phrase using the following functions:

phrase = Phrase()
phrase = Phrase(startTime)
Parameter Type Default Description
startTime int or float None A start time (0.0 is the beginning of the piece, 1.0 is a quarter note into the piece, etc.)

For example,

phrase = Phrase(5.0)

Functions

Once a Phrase phrase has been created, the following functions are available:

Function Description
phrase.addNote(note) Add a note to the end of the phrase.
phrase.addNote(pitch, duration) Add a new note with pitch and duration to the end of the phrase.
phrase.addNoteList(listOfPitches, listOfDurations) Add many notes to the end of the phrase at once.
phrase.addChord(listOfPitches, duration) Add a chord (several pitches sounded together) to the end of the phrase.

You can also set the instrument, tempo, dynamic, panning, and title of the phrase.

Function Description
phrase.getInstrument() Return the phrase's instrument.
phrase.setInstrument(instrument) Set the phrase's instrument.
phrase.getTempo() Return the phrase's tempo.
phrase.setTempo(tempo) Set the phrase's tempo.
phrase.setDynamic(dynamic) Set how loud every note in the phrase is.
phrase.setPan(pan) Set the stereo position of every note in the phrase.
phrase.getTitle() Return the phrase's title.
phrase.setTitle(title) Set the phrase's title.

NOTE: You may set the instrument on a single phrase. If you intend to add the phrase to a Part, then set the instrument at the Part level. (If you do both, you may get unexpected results.)

Finally, here are some additional Phrase functions:

Function Description
phrase.copy() Return a copy of the phrase.
phrase.empty() Remove every note from the phrase.
phrase.getSize() Return how many notes are in the phrase.
phrase.getNote(index) Return the note at a given position, without changing the phrase.
phrase.getNoteList() Return the phrase's notes.
phrase.getNoteStartTime(index) Return when the note at a given position starts.
phrase.getStartTime() Return when the phrase starts.
phrase.setStartTime(startTime) Set when the phrase starts.
phrase.getEndTime() Return when the phrase ends.
phrase.removeNote(index) Remove the note at a given position from the phrase.
phrase.getHighestPitch() Return the pitch of the highest note in the phrase.
phrase.getLowestPitch() Return the pitch of the lowest note in the phrase.
phrase.getLongestDuration() Return the duration of the longest note in the phrase.
phrase.getShortestDuration() Return the duration of the shortest note in the phrase.