Beispiel #1
0
    def to_roman(self, chord, scale_key):
        """Converts a `Chord` to `Roman`.

        Creates the `Roman` based on the `Chord` and a `Scale` or `Key`.

        Parameters
        ----------
        chord : Chord
            The `Chord` to be converted.
        scale_key : Scale or Key
            The `Scale` or `Key` to base the `Roman` on.

        Returns
        -------
        Roman
            The `Roman` of the `Chord`.

        Warns
        -----
        UserWarning
            If the `Chord` is a power or sus chord.

        Examples
        --------
        >>> KE = KeyEditor()
        >>> SE = ScaleEditor()
        >>> CE = ChordEditor()
        >>> CRC = ChordRomanConverter()
        >>> c_key = KE.create_key("C")
        >>> c_scale = SE.create_scale(c_key)
        >>> d = CE.create_diatonic(c_scale, 2)
        >>> CRC.to_roman(d, c_key)
        ii roman chord
        >>> f = CE.create_diatonic(c_scale, 4)
        >>> CRC.to_roman(f, c_scale)
        IV roman chord

        """
        if chord.quality.value in {"power", "sus2", "sus4"}:
            warnings.warn(
                "Warning: Power and sus chords are defaulted to major chords",
                UserWarning)
            chord = self._CE.change_chord(chord, quality="Maj", inplace=False)
        if isinstance(scale_key, Scale):
            scale_root = scale_key.key.root
        else:
            scale_root = scale_key.root
        scale = self._SE.create_scale(scale_root, "major")
        root = self._get_roman_root(chord, scale)
        quality = self._get_roman_quality(chord)
        inversion = self._get_roman_inversion(chord)
        return Roman(root, quality, inversion)
Beispiel #2
0
def test_notation():
    r = Roman("I", "M+", (6, 4))
    assert "IM+64" == str(r)
Beispiel #3
0
def test_equality_not_implemented():
    r = Roman("I", "", ())
    assert r != len
Beispiel #4
0
def test_equality_2():
    r = Roman("IV", "+", (6, ))
    assert "IV+6" == r
Beispiel #5
0
def test_equality():
    r = Roman("I", "+", (6, ))
    o = Roman("I", "+", (6, ))
    assert r == o
Beispiel #6
0
def test_repr():
    r = Roman("IV", "+", (6, ))
    assert "IV+6 roman chord" == repr(r)
Beispiel #7
0
def test_notation_3():
    r = Roman("IV", "+", (6, ))
    assert "IV+6" == str(r)
Beispiel #8
0
def test_notation_2():
    r = Roman("v", "\u00B0", ())
    assert "v\u00B0" == str(r)