コード例 #1
0
def test_longer_progression():
    assert ChordProgression.from_string("C Fm C G7").progression == [
        Chord.from_name("C"),
        Chord.from_name("Fm"),
        Chord.from_name("C"),
        Chord.from_name("G7"),
    ]
コード例 #2
0
def test_explicit_octave():
    assert ChordProgression.from_string("4C -- +3Fm -2G7").progression == [
        Chord.from_name("+4C"),
        Chord.from_name("4C"),
        Chord.from_name("3Fm"),
        Chord.from_name("-2G7"),
    ]
コード例 #3
0
def test_repetition():
    assert ChordProgression.from_string("C -- Fm G7").progression == [
        Chord.from_name("C"),
        Chord.from_name("C"),
        Chord.from_name("Fm"),
        Chord.from_name("G7"),
    ]
コード例 #4
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)
コード例 #5
0
def test_multiline():
    assert ChordProgression.from_string("""C Fm C G7
               C E7 Am G""").progression == [
        Chord.from_name("C"),
        Chord.from_name("Fm"),
        Chord.from_name("C"),
        Chord.from_name("G7"),
        Chord.from_name("C"),
        Chord.from_name("E7"),
        Chord.from_name("Am"),
        Chord.from_name("G"),
    ]
コード例 #6
0
def make_midi_file(chord_names, beats_per_chord, out_file):
    chords = []
    for name in chord_names:
        try:
            chord = Chord.from_name(name)
        except InvalidChord:
            chord = ChordProgression.DUMMY_CHORD
        chords.append(chord)

    progression = ChordProgression(chords)
    progression.to_midi(
        MidiConversionSettings(filename=out_file,
                               instrument=11,
                               beats_per_chord=beats_per_chord))
コード例 #7
0
def _string_to_progression(string: str) -> List[Chord]:
    string = string.strip()

    if string == "":
        return []

    progression = []

    for name in string.split():
        name = name.strip()

        if name == REPETITION_SYMBOL:
            if not progression:
                raise InvalidProgression(
                    "Can't repeat before at least one chord has been added")

            progression.append(progression[-1])
        else:
            progression.append(Chord.from_name(name))
    return progression
コード例 #8
0
def test_chord_with_root(name_in, root_out, semi_out):
    assert Chord.from_name(name_in).semitones == semi_out
    assert Chord.from_name(name_in).root.name == root_out
コード例 #9
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
コード例 #10
0
def test_chord_from_degrees(name_in, semi_out):
    assert Chord.from_name(name_in).semitones == semi_out
コード例 #11
0
def test_chord_from_invalid_name(name_in):
    with pytest.raises(InvalidChord):
        Chord.from_name(name_in)
コード例 #12
0
def test_chord_with_root_repr(name_in):
    assert Chord.from_name(name_in) == eval(repr(Chord.from_name(name_in)))
コード例 #13
0
def test_chord_note_to_midi(name_in, midi):
    assert Chord.from_name(name_in).midi() == midi
コード例 #14
0
def test_longer_chords():
    assert ChordProgression.from_string("C Fm C G7").chords() == {
        Chord.from_name("C"),
        Chord.from_name("Fm"),
        Chord.from_name("G7"),
    }
コード例 #15
0
def test_single_chords():
    assert ChordProgression.from_string("Cm").chords() == {
        Chord.from_name("Cm")
    }
コード例 #16
0
def test_chord_with_root_intervals(name_in, int_out):
    assert Chord.from_name(name_in).interval_sequence() == int_out
コード例 #17
0
def test_chord_with_root_invalid_name(name_in):
    with pytest.raises(InvalidChord):
        assert Chord.from_name(name_in)
コード例 #18
0
def test_chord_intervals(name_in, int_out):
    assert Chord.from_name(name_in).intervals() == int_out
コード例 #19
0
def test_chord_transpose(name_in, name_out, shift):
    assert Chord.from_name(name_in).transpose(shift) == Chord.from_name(name_out)
コード例 #20
0
def test_chord_repr(name_in, repr_out):
    assert repr(Chord.from_name(name_in)) == repr_out
    assert Chord.from_name(name_in) == eval(repr_out)
コード例 #21
0
def test_chord_add_root(name_in, octave):
    name_then_root = Chord.from_name(name_in).with_root(Note("A#", octave))
    name_and_root = ChordWithRoot.from_name("A#" + name_in, octave=octave)
    print(name_and_root._keys())
    assert name_then_root == name_and_root
コード例 #22
0
def test_single_progression():
    assert ChordProgression.from_string("Cm").progression == [
        Chord.from_name("Cm")
    ]