pymusicxml.score_components.NonTraditionalKeySignature

class pymusicxml.score_components.NonTraditionalKeySignature(*step_alteration_tuples)[source]

Bases: KeySignature

A non-traditional key signature. See https://www.w3.org/2021/06/musicxml40/musicxml-reference/elements/key/.

Parameters:

step_alteration_tuples – a list of (step, alteration) or (step, alteration, accidental) tuples, each of which corresponds to a set of <key-step>, <key-alter>, and optionally <key-accidental> tags.

Methods

add_alteration(step, alteration[, accidental])

Add another altered step to this key signature.

render()

Renders this component to a tuple of ElementTree.Element.

step_alterations()

Map of step letter -> alteration (in half steps) implied by this key.

Inherited Methods

export_to_file(file_path[, pretty_print])

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

parse(interpretable_as_key_signature)

Parses several kinds of input into a TraditionalKeySignature or NonTraditionalKeySignature object.

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.

wrap_as_score()

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

Attributes

mode_fifth_alterations

add_alteration(step, alteration, accidental=None)[source]

Add another altered step to this key signature.

Parameters:
  • step – the step being altered, e.g. “B”

  • alteration – how much to alter it by, in half steps, e.g. -1 for a flat

  • accidental – which accidental to draw; inferred from the alteration if left as None. (See AccidentalType.)

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.)

step_alterations() → dict[source]

Map of step letter -> alteration (in half steps) implied by this key.

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

mode_fifth_alterations = {'aeolian': -3, 'dorian': -2, 'ionian': 0, 'locrian': -4, 'lydian': 1, 'major': 0, 'minor': -3, 'mixolydian': -1, 'phrygian': -4, None: 0}
static parse(interpretable_as_key_signature: KeySignature | int | str) → KeySignature

Parses several kinds of input into a TraditionalKeySignature or NonTraditionalKeySignature object.

Parameters:

interpretable_as_key_signature – either a KeySignature object, an integer representing the number of sharps (or flats if negative), or a string to be parsed into a key signature, such as “G major”, “F# lydian”, or “C#, Ab” (which produces a non-traditional key-signature), etc.

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.

wrap_as_score() → Score

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