Example #1
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"),
    ]
Example #2
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"),
    ]
Example #3
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"),
    ])
Example #4
0
    def from_midi_file(cls, filename: str) -> "ChordProgression":
        """Creates a `ChordProgression` from an MIDI file.

        There is no attempt at quantization at this time, so the notes must be played
        at the exact same time to be grouped together as chords.
        """
        notes = read_midi_file(filename)
        chords = group_notes_to_chords(notes)
        progression = []
        for time, chord in chords.items():
            progression.append(
                ChordWithRoot.from_midi([note.note for note in chord]))
        return cls(progression)
Example #5
0
def _string_to_progression(string: str) -> List[ChordWithRoot]:
    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(ChordWithRoot.from_name(name))
    return progression
Example #6
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"),
    }
Example #7
0
def test_single_chords():
    assert ChordProgression.from_string("Cm").chords() == {
        ChordWithRoot.from_name("Cm")
    }
Example #8
0
def test_single_progression():
    assert ChordProgression.from_string("Cm").progression == [
        ChordWithRoot.from_name("Cm")
    ]
Example #9
0
def test_chord_with_root(name_in, root_out, semi_out):
    assert ChordWithRoot.from_name(name_in).semitones == semi_out
    assert ChordWithRoot.from_name(name_in).root.name == root_out
Example #10
0
def test_chord_from_root_and_semitone(root, semitones, name):
    assert ChordWithRoot.from_root_and_semitones(Note(root, 4),
                                                 semitones).name == name
Example #11
0
def test_chord_repr(name_in):
    assert ChordWithRoot.from_name(name_in) == eval(
        repr(ChordWithRoot.from_name(name_in)))
Example #12
0
def test_chord_transpose(name_in, name_out, shift):
    assert ChordWithRoot.from_name(name_in).transpose(
        shift) == ChordWithRoot.from_name(name_out)
Example #13
0
def test_chord_note_to_midi(name_in, octave, midi):
    assert ChordWithRoot.from_name(name_in, octave).midi() == midi
Example #14
0
def test_chord_with_root_invalid_name(name_in):
    with pytest.raises(InvalidChord):
        assert ChordWithRoot.from_name(name_in)
Example #15
0
def test_chord_intervals(name_in, int_out):
    assert ChordWithRoot.from_name(name_in).intervals() == int_out
Example #16
0
def test_chord_from_midi(midi, name):
    assert ChordWithRoot.from_midi(midi).name == name
Example #17
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