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]), ), ])
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)
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)
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)
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))
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 """)
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"), ]
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_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"), ]
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]), ), ])
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"), ])
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)), ], ]
def test_whitespace(): assert ChordProgression.from_string( "C -- Fm G7") == ChordProgression.from_string(" C -- Fm G7 ")
def test_repeat_nothing(): with pytest.raises(InvalidProgression): assert ChordProgression.from_string("-- C Fm")
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"), }
def test_single_chords(): assert ChordProgression.from_string("Cm").chords() == { ChordWithRoot.from_name("Cm") }
def test_empty_progression(): assert ChordProgression.from_string("").progression == []
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))
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"), ))
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)
def test_single_progression(): assert ChordProgression.from_string("Cm").progression == [ ChordWithRoot.from_name("Cm") ]
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""")
def test_empty_chords(): assert ChordProgression.from_string("").chords() == set()
# 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,