Beispiel #1
0
 def from_root_and_semitones(cls, root: Note, semitones: List[int]) -> "Chord":
     chord = Intervals.from_semitones(semitones)
     if "/" in chord.name:
         chord_name, bass_degree = chord.name.split("/")
         new_root = (
             Note(root.name, 0).transpose(12 - degree_to_semitone(bass_degree)).name
         )
         name = f"{new_root}{chord_name}/{root.name}"
     else:
         name = root.name + chord.name
     return cls(name, root, chord)
Beispiel #2
0
    def from_root_and_semitones(cls, root: Note,
                                semitones: List[int]) -> "ChordWithRoot":
        """Creates a ChordWithRoot from a root `Note` and a list of semitones from the root.

        `semitones_to_chord_name_options` is used to guess a good name for the chord.
        """
        chord = Chord.from_semitones(None, semitones)
        if "/" in chord.name:
            chord_name, bass_degree = chord.name.split("/")
            new_root = (Note(
                root.name,
                0).transpose(12 - degree_to_semitone(bass_degree)).name)
            name = "{}{}/{}".format(new_root, chord_name, root.name)
        else:
            name = root.name + chord.name
        return cls(name, root, chord)
Beispiel #3
0
 def from_degrees(
     cls, degrees: List[str], name: Optional[str] = None
 ) -> "Intervals":
     return cls([degree_to_semitone(degree) for degree in degrees], name)
Beispiel #4
0
def test_degree_to_semitone_invalid_degree(degree):
    with pytest.raises(InvalidDegree):
        assert degree_to_semitone(degree)
Beispiel #5
0
def test_degree_to_semitone(degree, semitone):
    assert degree_to_semitone(degree) == semitone
Beispiel #6
0
    def from_degrees(cls, name: str, degrees: List[str]) -> "Chord":
        """Creates a Chord from a list of scale degrees.

        If `name` is `None`, `semitones_to_chord_name_options` is used to guess a good name for the chord.
        """
        return cls(name, [degree_to_semitone(degree) for degree in degrees])