pymusicxml.score_components.Part

class pymusicxml.score_components.Part(part_name: str, measures: Optional[Sequence[Measure]] = None, part_id: int = 1, instrument_name: Optional[str] = None, midi_program_num: Optional[int] = None)[source]

Bases: MusicXMLComponent, MusicXMLContainer

Represents a musical part/staff.

Parameters:
  • part_name – name of this part

  • measures – list of measures contained in this part

  • part_id – unique identifier for the part (set automatically by the containing Score upon rendering)

  • instrument_name – used by notation programs to understand which sound to use; not rendered in score. Set automatically based on part name if left as None.

  • midi_program_num – the general midi program number for the instrument. Again, used by notation programs to pick an instrument sound. Set automatically based on part name if left as None.

Methods

iter_directions([direction_type])

Iterates through all directions, or all directions of a certain type, in this Part.

iter_leaves([which_voices])

Iterates through the Notes/Chords/Rests in this part, expanding out any measures, tuplets and beam groups.

iter_notations([notation_type])

Iterates through all notations, or all notations of a certain type, in this Part.

render()

Renders this component to a tuple of ElementTree.Element.

render_part_list_entry()

Renders the "score-part" tag for the top of the MusicXML score.

wrap_as_score()

Wraps this component in a Score so that it can be exported and viewed

Inherited Methods

append(value)

S.append(value) -- append value to the end of the sequence

clear()

count(value)

export_to_file(file_path[, pretty_print])

Exports this musical object (wrapped as a score) to the given file path.

extend(values)

S.extend(iterable) -- extend sequence by appending elements from the iterable

index(value, [start, [stop]])

Raises ValueError if the value is not present.

insert(i, o)

Insert the given object before the given index.

pop([index])

Raise IndexError if list is empty or index is out of range.

remove(value)

S.remove(value) -- remove first occurrence of value.

reverse()

S.reverse() -- reverse IN PLACE

to_xml([pretty_print])

Renders this component to MusicXML, adding a version tag, but not wrapping it up as a full score.

view_in_software(command)

Uses the given terminal command to create a score out of this musical object, and open it in music notation software.

Attributes

general_midi_preset_nums

measures

List of the measures in this Part.

general_midi_preset_nums = {'Accordion': 22, 'Acoustic Bass': 33, 'Acoustic Grand Piano': 1, 'Acoustic Guitar (nylon)': 25, 'Acoustic Guitar (steel)': 26, 'Agogo': 114, 'Alto Sax': 66, 'Applause': 127, 'Bag pipe': 110, 'Banjo': 106, 'Baritone Sax': 68, 'Bassoon': 71, 'Bells': 15, 'Bird Tweet': 124, 'Blown Bottle': 77, 'Brass Section': 62, 'Breath Noise': 122, 'Bright Acoustic Piano': 2, 'Celesta': 9, 'Cello': 43, 'Choir Aahs': 53, 'Church Organ': 20, 'Clarinet': 72, 'Clavinet': 8, 'Contrabass': 44, 'Distortion Guitar': 31, 'Drawbar Organ': 17, 'Dulcimer': 16, 'Electric Bass (finger)': 34, 'Electric Bass (pick)': 35, 'Electric Grand Piano': 3, 'Electric Guitar (clean)': 28, 'Electric Guitar (jazz)': 27, 'Electric Guitar (muted)': 29, 'Electric Piano 1': 5, 'Electric Piano 2': 6, 'English Horn': 70, 'FX 1 (rain)': 97, 'FX 2 (soundtrack)': 98, 'FX 3 (crystal)': 99, 'FX 4 (atmosphere)': 100, 'FX 5 (brightness)': 101, 'FX 6 (goblins)': 102, 'FX 7 (echoes)': 103, 'FX 8 (sci-fi)': 104, 'Fiddle': 111, 'Flute': 74, 'French Horn': 61, 'Fretless Bass': 36, 'Glockenspiel': 10, 'Guitar Fret Noise': 121, 'Guitar harmonics': 32, 'Gunshot': 128, 'Harmonica': 23, 'Harp': 47, 'Harpsichord': 7, 'Helicopter': 126, 'Honky-tonk Piano': 4, 'Horn': 61, 'Kalimba': 109, 'Koto': 108, 'Lead 1 (square)': 81, 'Lead 2 (sawtooth)': 82, 'Lead 3 (calliope)': 83, 'Lead 4 (chiff)': 84, 'Lead 5 (charang)': 85, 'Lead 6 (voice)': 86, 'Lead 7 (fifths)': 87, 'Lead 8 (bass + lead)': 88, 'Marimba': 13, 'Melodic Tom': 118, 'Music Box': 11, 'Muted Trumpet': 60, 'Oboe': 69, 'Ocarina': 80, 'Orchestra Hit': 56, 'Orchestral Harp': 47, 'Organ': 20, 'Overdriven Guitar': 30, 'Pad 1 (new age)': 89, 'Pad 2 (warm)': 90, 'Pad 3 (polysynth)': 91, 'Pad 4 (choir)': 92, 'Pad 5 (bowed)': 93, 'Pad 6 (metallic)': 94, 'Pad 7 (halo)': 95, 'Pad 8 (sweep)': 96, 'Pan Flute': 76, 'Percussive Organ': 18, 'Piano': 1, 'Piccolo': 73, 'Pizzicato Strings': 46, 'Recorder': 75, 'Reed Organ': 21, 'Reverse Cymbal': 120, 'Rock Organ': 19, 'Sax': 66, 'Seashore': 123, 'Shakuhachi': 78, 'Shamisen': 107, 'Shanai': 112, 'Sitar': 105, 'Slap Bass 1': 37, 'Slap Bass 2': 38, 'Soprano Sax': 65, 'Steel Drums': 115, 'String Ensemble 1': 49, 'String Ensemble 2': 50, 'Strings': 49, 'Synth Bass 1': 39, 'Synth Bass 2': 40, 'Synth Brass 1': 63, 'Synth Brass 2': 64, 'Synth Drum': 119, 'Synth Strings 1': 51, 'Synth Strings 2': 52, 'Synth Voice': 55, 'Taiko Drum': 117, 'Tango Accordion': 24, 'Telephone Ring': 125, 'Tenor Sax': 67, 'Timpani': 48, 'Tinkle Bell': 113, 'Tom': 118, 'Tremolo Strings': 45, 'Trombone': 58, 'Trumpet': 57, 'Tuba': 59, 'Tubular Bells': 15, 'Vibraphone': 12, 'Viola': 42, 'Violin': 41, 'Violoncello': 43, 'Voice Oohs': 54, 'Whistle': 79, 'Woodblock': 116, 'Xylophone': 14}
property measures: Sequence[Measure]

List of the measures in this Part.

iter_leaves(which_voices=None) Iterator[Note | Chord | Rest][source]

Iterates through the Notes/Chords/Rests in this part, expanding out any measures, tuplets and beam groups. The notes/chords/rests are ordered in time, and draw from the specified voices.

Parameters:

which_voices – List of voices to return notes from (numbered 0, 1, 2, 3). The default value of None returns notes from all voices.

iter_directions(direction_type=None) Iterator[Direction][source]

Iterates through all directions, or all directions of a certain type, in this Part.

Parameters:

direction_type – the type of direction to filter for, if any

iter_notations(notation_type=None) Iterator[Notation][source]

Iterates through all notations, or all notations of a certain type, in this Part.

Parameters:

notation_type – the type of notation to filter for, if any

render() Sequence[Element][source]

Renders this component to a tuple of ElementTree.Element. (The reason for making it a tuple is that musical objects like chords are represented by several notes side by side, with all but the first containing a </chord> tag.)

render_part_list_entry() Sequence[Element][source]

Renders the “score-part” tag for the top of the MusicXML score.

wrap_as_score() Score[source]

Wraps this component in a Score so that it can be exported and viewed

append(value)

S.append(value) – append value to the end of the sequence

clear() None -- remove all items from S
count(value) integer -- return number of occurrences of value
export_to_file(file_path: str, pretty_print: bool = True) None

Exports this musical object (wrapped as a score) to the given file path.

Parameters:
  • file_path – The path of the file we want to write to.

  • pretty_print – If True, breaks the MusicXML onto multiple lines, with indentation

extend(values)

S.extend(iterable) – extend sequence by appending elements from the iterable

index(value[, start[, stop]]) integer -- return first index of value.

Raises ValueError if the value is not present.

Supporting start and stop arguments is optional, but recommended.

insert(i, o) None

Insert the given object before the given index.

Parameters:
  • i – Index at which to insert

  • o – Object to insert

pop([index]) item -- remove and return item at index (default last).

Raise IndexError if list is empty or index is out of range.

remove(value)

S.remove(value) – remove first occurrence of value. Raise ValueError if the value is not present.

reverse()

S.reverse() – reverse IN PLACE

to_xml(pretty_print: bool = False) str

Renders this component to MusicXML, adding a version tag, but not wrapping it up as a full score.

Parameters:

pretty_print – If True, breaks the MusicXML onto multiple lines, with indentation

view_in_software(command: str) None

Uses the given terminal command to create a score out of this musical object, and open it in music notation software.

Parameters:

command – The terminal command corresponding to the software with which we want to open the score.