Skip to content

Part

A Part object contains a set of Phrase objects to be played by a particular instrument. These phrase objects are played in parallel (i.e., simultaneously), and thus may overlap (according to their start times and durations). Even if the particular instrument does not allow for polyphony (e.g., a flute), a part using this instrument can have different simultaneous melodies. In other words, a part can be thought of as a group of several instruments of the same type (e.g., flutes), each playing a different melody (a phrase).

There are 128 different instruments to pick from.

Parts may be assigned to one of sixteen MIDI channels (0 – 15) available on a standard computer’s audio system. Each MIDI channel is capable of playing any of the 128 different instruments possible, but only one at a time. So, it is important to keep parts using different instruments in different MIDI channels. If two parts are using the same instrument, they may be assigned to the same MIDI channel.

MIDI channel 9 is reserved for percussion sounds. Regardless of a part’s selected instrument, if that part is assigned to MIDI channel 9, its notes will generate percussion sounds, based on the notes’ pitches.

Creating a Part

You can create a Part using the following functions:

Part()
Part(instrument)
Part(instrument, channel)
Part(title, instrument, channel)
Part(phrase)
Parameter Type Default Description
instrument int None A MIDI instrument.
channel int 0 A MIDI channel (0-15).
title str '' A title for the Part.
phrase Phrase None The first Phrase to add to the Part.

For example,

part = Part("An example flute part", FLUTE, 0)

This creates a Part part with a descriptive title, using instrument FLUTE (see instrument constants for a complete list of instruments), and assigned to MIDI channel 0 of the computer’s audio system. Again, you should assign parts with different instruments to different MIDI channels (0-8, and 10-15). Remember that MIDI channel 9 is dedicated to percussive sounds, as explained above.

Functions

Once a Part part has been created, the following functions are available:

Function Description
part.addPhrase(phrase) Add a phrase to the part.
part.addPhraseList(phraseList) Add several phrases to the part at once.

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

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

Finally, here are some additional Part functions:

Function Description
part.copy() Return a copy of the part.
part.empty() Remove every phrase from the part.
part.getSize() Return how many phrases are in the part.
part.getPhraseList() Return the part's phrases.
part.getStartTime() Return when the part starts.
part.getEndTime() Return when the part ends.
part.getChannel() Return the part's MIDI channel.
part.setChannel(channel) Set the part's MIDI channel.