Example #1
0
def test_github_issue_8_sloppy_midi():
    prog = ChordProgression.from_midi_file(
        os.path.join(os.path.dirname(__file__), "test_data", "issue_8.mid"))
    assert prog == ChordProgression([
        Chord(
            name="A#min",
            root=Note("A#", 3),
            intervals=Intervals(name="min", semitones=[0, 3, 7]),
        ),
        Chord(
            name="D#",
            root=Note("D#", 4),
            intervals=Intervals(name="", semitones=[0, 4, 7]),
        ),
        Chord(
            name="D#min",
            root=Note("D#", 4),
            intervals=Intervals(name="min", semitones=[0, 3, 7]),
        ),
        Chord(
            name="A#min/G#",
            root=Note("G#", 3),
            intervals=Intervals(name="min/b7", semitones=[0, 5, 9, 14]),
        ),
    ])
Example #2
0
def test_github_issue_61_slash_chord_with_octave():
    """https://github.com/jonathangjertsen/jchord/issues/61#issuecomment-777625321"""
    chord = Chord.from_name("5C/E")
    assert chord == Chord(
        name="C/E",
        root=Note("C", 5),
        intervals=Intervals(name="major", semitones=[-8, 0, 4, 7]),
    )
    assert chord.bass == Note("E", 4)
Example #3
0
def test_github_issue_61_progression():
    """https://github.com/jonathangjertsen/jchord/issues/61#issuecomment-777575298"""
    prog = ChordProgression.from_string("4F -- 3Am -- 4Dm7 -- 4F --")
    assert prog == ChordProgression([
        Chord(
            name="F",
            root=Note("F", 4),
            intervals=Intervals(name="major", semitones=[0, 4, 7]),
        ),
        Chord(
            name="F",
            root=Note("F", 4),
            intervals=Intervals(name="major", semitones=[0, 4, 7]),
        ),
        Chord(
            name="Am",
            root=Note("A", 3),
            intervals=Intervals(name="m", semitones=[0, 3, 7]),
        ),
        Chord(
            name="Am",
            root=Note("A", 3),
            intervals=Intervals(name="m", semitones=[0, 3, 7]),
        ),
        Chord(
            name="Dm7",
            root=Note("D", 4),
            intervals=Intervals(name="m7", semitones=[0, 3, 7, 10]),
        ),
        Chord(
            name="Dm7",
            root=Note("D", 4),
            intervals=Intervals(name="m7", semitones=[0, 3, 7, 10]),
        ),
        Chord(
            name="F",
            root=Note("F", 4),
            intervals=Intervals(name="major", semitones=[0, 4, 7]),
        ),
        Chord(
            name="F",
            root=Note("F", 4),
            intervals=Intervals(name="major", semitones=[0, 4, 7]),
        ),
    ])
Example #4
0
def test_chord_from_degrees(deg_in, semi_out):
    assert Intervals.from_degrees(deg_in).semitones == semi_out
Example #5
0
def test_semitones_to_chord_options(semitones, options, selected):
    computed_options = semitones_to_name_options(semitones)
    assert set(computed_options) >= set(options)
    assert Intervals.from_semitones(semitones).name == selected
Example #6
0
def test_chord_from_invalid_name(name_in):
    with pytest.raises(InvalidChord):
        Intervals.from_name(name_in)
Example #7
0
def test_chord_add_root(name_in, octave):
    name_then_root = Intervals.from_name(name_in).with_root(Note("A#", octave))
    name_and_root = Chord.from_name(f"{octave}A#{name_in}")
    assert name_then_root == name_and_root
Example #8
0
def test_chord_repr(name_in, repr_out):
    assert repr(Intervals.from_name(name_in)) == repr_out
    assert Intervals.from_name(name_in) == eval(repr_out)
Example #9
0
def test_chord_from_name_intervals(name_in, int_out):
    assert Intervals.from_name(name_in).interval_sequence() == int_out
Example #10
0
def test_chord_from_semitones(semi_in, semi_out):
    assert Intervals.from_semitones(semi_in).semitones == semi_out
Example #11
0
def test_chord_name_roundtrip(name_in, name_out):
    assert (
        Intervals.from_semitones(Intervals.from_name(name_in).semitones).name
        == name_out
    )
Example #12
0
def test_chord_from_name_modifications(name_in, modifications):
    assert Intervals.from_name(name_in).modifications == modifications