pymusicxml.score_components.Clef
- class pymusicxml.score_components.Clef(sign: str, line: int, octaves_transposition: int = 0)[source]
Bases:
MusicXMLComponent
Class representing a musical clef
- Parameters:
sign – Whether it is a G, F, or C clef
line – Which line the clef is centered on
octaves_transposition – How many octaves up or down the clef transposes
Methods
from_string
(clef_string[, octaves_transposition])Constructs a clef from one of the standard names, e.g.
render
()Renders this component to a tuple of ElementTree.Element.
Wraps this component in a
Score
so that it can be exported and viewedInherited Methods
export_to_file
(file_path[, pretty_print])Exports this musical object (wrapped as a score) to the given file path.
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
Dictionary mapping standard clef names to tuple of (clef letter type, clef line)
- clef_name_to_letter_and_line = {'alto': ('C', 3), 'baritone': ('F', 3), 'bass': ('F', 4), 'mezzo-soprano': ('C', 2), 'soprano': ('C', 1), 'tenor': ('C', 4), 'treble': ('G', 2)}
Dictionary mapping standard clef names to tuple of (clef letter type, clef line)
- classmethod from_string(clef_string: str, octaves_transposition: int = 0)[source]
Constructs a clef from one of the standard names, e.g. treble, bass, alto
- Parameters:
clef_string – name of the clef
octaves_transposition – octaves of transposition up or down to be applied to the clef
- 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.)
- wrap_as_score() Score [source]
Wraps this component in a
Score
so that it can be exported and viewed
- 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
- 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.