scamp.spelling.SpellingPolicy¶
-
class
scamp.spelling.
SpellingPolicy
(step_alteration_pairs: Sequence[Tuple[int, int]] = 0, 0, 0, 1, 1, 0, 2, - 1, 2, 0, 3, 0, 3, 1, 4, 0, 5, - 1, 5, 0, 6, - 1, 6, 0)[source]¶ Bases:
expenvelope.json_serializer.SavesToJSON
,scamp.utilities.NoteProperty
Object that translates pitches or pitch classes to the actual spelling used in a score
- Parameters
step_alteration_pairs – a list of 12 (step, alteration) tuples showing how to spell each pitch class. The step corresponds to the letter-name of the note, and the alteration to its accidental. So (3, -1) represents an E-flat.
- Variables
step_alteration_pairs – list of 12 (step, alteration) tuples showing how to spell each pitch class.
Methods
all_flats
([including_white_keys])Constructs a flats-only SpellingPolicy
all_sharps
([including_white_keys])Constructs a sharps-only SpellingPolicy
from_circle_of_fifths_position
(…[, …])Constructs a spelling policy by transposing a template around the circles of fifths
from_string
(string_initializer)Constructs a SpellingPolicy from several possible input string formats
interpret
(obj)Interpret an object of unknown type as a SpellingPolicy
resolve_abjad_pitch
(midi_num)Convert a given MIDI pitch to an abjad NamedPitch according to this SpellingPolicy
resolve_music_xml_pitch
(midi_num)Convert a given MIDI pitch to an abjad pymusicxml Pitch object according to this SpellingPolicy
resolve_name_octave_and_alteration
(midi_num)For a given pitch, determine its name, octave and alteration under this SpellingPolicy.
Inherited Methods
Returns a copy of this object by serializing to and from JSON.
Dump this object as a JSON string.
json_loads
(s)Load this object from a JSON string.
load_from_json
(file_path)Load this object from a JSON file with the given path.
save_to_json
(file_path)Save this object to a JSON file using the given path.
-
classmethod
all_sharps
(including_white_keys: bool = False) → scamp.spelling.SpellingPolicy[source]¶ Constructs a sharps-only SpellingPolicy
- Parameters
including_white_keys – if True, even white keys like D will be spelled as C-double-sharp
-
classmethod
all_flats
(including_white_keys: bool = False) → scamp.spelling.SpellingPolicy[source]¶ Constructs a flats-only SpellingPolicy
- Parameters
including_white_keys – if True, even white keys like D will be spelled as E-double-flat
-
classmethod
from_circle_of_fifths_position
(num_sharps_or_flats: int, avoid_double_accidentals: bool = False, template: Sequence[Tuple[int, int]] = 0, 0, 0, 1, 1, 0, 2, - 1, 2, 0, 3, 0, 3, 1, 4, 0, 5, - 1, 5, 0, 6, - 1, 6, 0) → scamp.spelling.SpellingPolicy[source]¶ Constructs a spelling policy by transposing a template around the circles of fifths
- Parameters
num_sharps_or_flats – how many steps sharp or flat to transpose around the circle of fifths. For instance, if set to 4, our tonic is E, and if set to -3, our tonic is Eb
avoid_double_accidentals – if true, replaces double sharps and flats with simpler spelling
template – by default, uses sharp-2, flat-3, sharp-4, flat-6, and flat-7
-
classmethod
from_string
(string_initializer: str) → scamp.spelling.SpellingPolicy[source]¶ Constructs a SpellingPolicy from several possible input string formats
- Parameters
string_initializer – one of the following: - a key center (case insensitive), such as “C#” or “f” or “Gb” - a key center followed by a mode, such as “g minor” or “Bb locrian”. Most modes to not alter the way spelling is done, but certain modes like phrygian and locrian do. - “flat”/”b” or “sharp”/”#”, indicating that any note, even a white key, is to be expressed with the specified accidental. Most useful for spelling known individual notes - “flats”/”sharps” indicating that black keys will be spelled with the specified accidental, but white keys will remain unaltered. (Turns out “flats” is equivalent to “Bb” and “sharps” is equivalent to “A”.)
-
classmethod
interpret
(obj: Union[SpellingPolicy, str, tuple]) → scamp.spelling.SpellingPolicy[source]¶ Interpret an object of unknown type as a SpellingPolicy
- Parameters
obj – an object to interpret as a SpellingPolicy; accepts SpellingPolicy, string, or tuple of alterations
- Returns
a SpellingPolicy
-
resolve_name_octave_and_alteration
(midi_num: int) → Tuple[str, int, int][source]¶ For a given pitch, determine its name, octave and alteration under this SpellingPolicy.
- Parameters
midi_num – a MIDI pitch value
- Returns
a tuple of (name, octave, alteration)
-
resolve_abjad_pitch
(midi_num: int) → abjad.NamedPitch[source]¶ Convert a given MIDI pitch to an abjad NamedPitch according to this SpellingPolicy
- Parameters
midi_num – a MIDI pitch value
-
resolve_music_xml_pitch
(midi_num: int) → pymusicxml.music_xml_objects.Pitch[source]¶ Convert a given MIDI pitch to an abjad pymusicxml Pitch object according to this SpellingPolicy
- Parameters
midi_num – a MIDI pitch value
-
duplicate
() → T¶ Returns a copy of this object by serializing to and from JSON.
-
json_dumps
() → str¶ Dump this object as a JSON string. This uses a custom encoder that recognizes and appropriately converts any attributes that are object inheriting from SavesToJSON.
-
classmethod
json_loads
(s: str) → T¶ Load this object from a JSON string. This uses a custom decoder that looks for a “_type” key in any object/dictionary being parsed and converts it to the class specified (assuming it a subclass of SavesToJSON).
- Parameters
s – a string representing this object in JSON format
-
classmethod
load_from_json
(file_path: str) → T¶ Load this object from a JSON file with the given path. This uses a custom decoder that looks for a “_type” key in any object/dictionary being parsed and converts it to the class specified (assuming it a subclass of SavesToJSON).
- Parameters
file_path – path for loading the file
-
save_to_json
(file_path: str) → None¶ Save this object to a JSON file using the given path. This uses a custom encoder that recognizes and appropriately converts any attributes that are object inheriting from SavesToJSON.
- Parameters
file_path – path for saving the file