Exemplo n.º 1
0
def test_progression_to_midi():
    midi_filename = os.path.join(os.path.dirname(__file__), "test_data",
                                 "test_progression.midi")

    try:
        ChordProgression.from_string(
            """C Fm C G7 C E7 Am G G G G G""").to_midi(midi_filename)
    finally:
        os.remove(midi_filename)
Exemplo n.º 2
0
def test_song_to_string():
    intro = SongSection("Intro", ChordProgression.from_string("""C Fm G7"""))
    main = SongSection("Main",
                       ChordProgression.from_string("""C Fm C G7 C E7 Am G"""))
    song = Song([intro, main, main])
    assert (song.to_string() == """Intro
=====
C   Fm  G7

Main (x2)
=========
C   Fm  C   G7
C   E7  Am  G
""")
Exemplo n.º 3
0
def test_longer_progression():
    assert ChordProgression.from_string("C Fm C G7").progression == [
        ChordWithRoot.from_name("C"),
        ChordWithRoot.from_name("Fm"),
        ChordWithRoot.from_name("C"),
        ChordWithRoot.from_name("G7"),
    ]
Exemplo n.º 4
0
def test_repetition():
    assert ChordProgression.from_string("C -- Fm G7").progression == [
        ChordWithRoot.from_name("C"),
        ChordWithRoot.from_name("C"),
        ChordWithRoot.from_name("Fm"),
        ChordWithRoot.from_name("G7"),
    ]
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"),
    ]
Exemplo n.º 6
0
def test_progression_from_midi():
    midi_filename = os.path.join(os.path.dirname(__file__), "test_data",
                                 "test_progression.midi")

    original = ChordProgression.from_string("""C Fm C G7 C E7 Am G G G G G""")
    try:
        original.to_midi(midi_filename)
        assert ChordProgression.from_midi_file(midi_filename) == original
    finally:
        os.remove(midi_filename)
Exemplo n.º 7
0
def test_to_txt():
    txt_filename_in = os.path.join(os.path.dirname(__file__), "test_data",
                                   "test_progression.txt")
    txt_filename_out = os.path.join(os.path.dirname(__file__), "test_data",
                                    "test_progression_exported.txt")
    prog = ChordProgression.from_string("""C Fm C G7 C E7 Am G G G G G""")
    try:
        prog.to_txt(txt_filename_out)
        assert ChordProgression.from_txt(txt_filename_in) == prog
    finally:
        os.remove(txt_filename_out)
Exemplo n.º 8
0
def test_multiline():
    assert (ChordProgression.from_string("""C Fm C G7
               C E7 Am G""").progression == [
        ChordWithRoot.from_name("C"),
        ChordWithRoot.from_name("Fm"),
        ChordWithRoot.from_name("C"),
        ChordWithRoot.from_name("G7"),
        ChordWithRoot.from_name("C"),
        ChordWithRoot.from_name("E7"),
        ChordWithRoot.from_name("Am"),
        ChordWithRoot.from_name("G"),
    ])
Exemplo n.º 9
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]),
        ),
    ])
Exemplo n.º 10
0
def test_progression_midi():
    assert ChordProgression.from_string("""C Fm G7""").midi() == [
        [
            note_to_midi(("C", 4)),
            note_to_midi(("E", 4)),
            note_to_midi(("G", 4))
        ],
        [
            note_to_midi(("F", 4)),
            note_to_midi(("G#", 4)),
            note_to_midi(("C", 5))
        ],
        [
            note_to_midi(("G", 4)),
            note_to_midi(("B", 4)),
            note_to_midi(("D", 5)),
            note_to_midi(("F", 5)),
        ],
    ]
Exemplo n.º 11
0
def test_song_repr():
    intro = SongSection("Intro", ChordProgression.from_string("""C Fm G7"""))
    main = SongSection("Main",
                       ChordProgression.from_string("""C Fm C G7 C E7 Am G"""))
    song = Song([intro, main, main])
    assert song == eval(repr(song))
Exemplo n.º 12
0
def test_from_txt():
    txt_filename_in = os.path.join(os.path.dirname(__file__), "test_data",
                                   "test_progression.txt")
    assert ChordProgression.from_txt(
        txt_filename_in) == ChordProgression.from_string(
            """C Fm C G7 C E7 Am G G G G G""")
Exemplo n.º 13
0
def test_whitespace():
    assert ChordProgression.from_string(
        "C -- Fm G7") == ChordProgression.from_string("     C -- Fm G7    ")
Exemplo n.º 14
0
def test_repeat_nothing():
    with pytest.raises(InvalidProgression):
        assert ChordProgression.from_string("-- C Fm")
Exemplo n.º 15
0
def test_longer_chords():
    assert ChordProgression.from_string("C Fm C G7").chords() == {
        ChordWithRoot.from_name("C"),
        ChordWithRoot.from_name("Fm"),
        ChordWithRoot.from_name("G7"),
    }
Exemplo n.º 16
0
def test_single_chords():
    assert ChordProgression.from_string("Cm").chords() == {
        ChordWithRoot.from_name("Cm")
    }
Exemplo n.º 17
0
def test_empty_chords():
    assert ChordProgression.from_string("").chords() == set()
Exemplo n.º 18
0
from jchord.progressions import ChordProgression

ChordProgression.from_string(
    "Bmaj7 -- D7 -- Gmaj7 -- Bb7 -- -- -- Am7 D7").to_midi("example.midi",
                                                           tempo=100,
                                                           beats_per_chord=2,
                                                           instrument=4)
Exemplo n.º 19
0
from jchord.progressions import ChordProgression, MidiConversionSettings
from jchord.midi import Instrument
from jchord.midi_effects import Harmonizer

progression = ChordProgression.from_string("""Fn Gn En An""")

progression.to_midi(
    MidiConversionSettings(
        filename="harmonizer.midi",
        tempo=85,
        beats_per_chord=2,
        instrument=Instrument.VoiceOohs,
        effect=Harmonizer(scale=[0, 2, 4, 5, 7, 9, 11],
                          degrees=[1, 3, 5, 7],
                          root="C"),
    ))
Exemplo n.º 20
0
# fmt: off
from jchord.progressions import ChordProgression, MidiConversionSettings
from jchord.midi import Instrument
from jchord.midi_effects import (
    Chain,
    Doubler,
    Arpeggiator,
    Spreader,
    Transposer,
)

progression = ChordProgression.from_string("""
Dm    --  G          -- C      Cadd9   Fmaj7  --
Dm    --  E          -- Am     --      Am9    --
Dm7   --  G7         -- C      C7      Fmaj7  Fmaj7add6
Dm9   --  E7         -- Am     --      Amadd6 --
Esus4 E7  Am         --
Dm7   --  G          -- Cmaj9  Cmaj9/G Fmaj7  --
Dm    --  E          -- Amadd9 Am/G    Am/F#  Fmaj7
E7b9  --  Amadd6add9 -- --     --      Am     --
""")

progression.to_midi(
    MidiConversionSettings(
        filename="autumn_leaves_arpeggiated.midi",
        tempo=110,
        beats_per_chord=2,
        instrument=Instrument.VoiceOohs,
        effect=Chain(
            Doubler(12),
            Arpeggiator(
                rate=1 / 16,
Exemplo n.º 21
0
def test_empty_progression():
    assert ChordProgression.from_string("").progression == []
Exemplo n.º 22
0
def test_single_progression():
    assert ChordProgression.from_string("Cm").progression == [
        ChordWithRoot.from_name("Cm")
    ]