Exemplo n.º 1
0
 def testTransposeUnknownChordSymbol(self):
     # Attempt to transpose ChordProgression with unknown chord symbol.
     events = ['Cm', 'G7', 'P#13', 'F']
     chords = chords_lib.ChordProgression()
     chords.from_event_list(events)
     with self.assertRaises(chord_symbols_lib.ChordSymbolException):
         chords.transpose(transpose_amount=-4)
Exemplo n.º 2
0
 def testFromQuantizedSequenceWithNoChords(self):
     chords = chords_lib.ChordProgression()
     chords.from_quantized_sequence(self.quantized_sequence,
                                    start_step=0,
                                    end_step=16)
     expected = [NO_CHORD] * 16
     self.assertEqual(expected, list(chords))
Exemplo n.º 3
0
    def testToSequence(self):
        # Sequence produced from lead sheet should contain notes from melody
        # sequence and chords from chord sequence as text annotations.
        melody = melodies_lib.MonophonicMelody()
        melody.from_event_list([
            NO_EVENT, 1, NO_EVENT, NOTE_OFF, NO_EVENT, 2, 3, NOTE_OFF, NO_EVENT
        ])
        chords = chords_lib.ChordProgression()
        chords.from_event_list(
            [NO_CHORD, 'A', 'A', 'C#m', 'C#m', 'D', 'B', 'B', 'B'])
        lead_sheet = lead_sheets_lib.LeadSheet(melody, chords)
        sequence = lead_sheet.to_sequence(velocity=10,
                                          instrument=1,
                                          sequence_start_time=2,
                                          qpm=60.0)

        melody_sequence = melody.to_sequence(velocity=10,
                                             instrument=1,
                                             sequence_start_time=2,
                                             qpm=60.0)
        chords_sequence = chords.to_sequence(sequence_start_time=2, qpm=60.0)
        self.assertEquals(melody_sequence.ticks_per_quarter,
                          sequence.ticks_per_quarter)
        self.assertProtoEquals(melody_sequence.tempos, sequence.tempos)
        self.assertEquals(melody_sequence.total_time, sequence.total_time)
        self.assertProtoEquals(melody_sequence.notes, sequence.notes)
        self.assertProtoEquals(chords_sequence.text_annotations,
                               sequence.text_annotations)
Exemplo n.º 4
0
 def testFromQuantizedSequenceWithCoincidentChords(self):
     testing_lib.add_quantized_chords(self.quantized_sequence,
                                      [('Am', 4), ('D7', 8), ('G13', 12),
                                       ('Csus', 12)])
     chords = chords_lib.ChordProgression()
     with self.assertRaises(chords_lib.CoincidentChordsException):
         chords.from_quantized_sequence(self.quantized_sequence,
                                        start_step=0,
                                        end_step=16)
Exemplo n.º 5
0
 def testFromQuantizedSequenceWithinSingleChord(self):
     testing_lib.add_quantized_chords(self.quantized_sequence, [('F', 0),
                                                                ('Gm', 8)])
     chords = chords_lib.ChordProgression()
     chords.from_quantized_sequence(self.quantized_sequence,
                                    start_step=4,
                                    end_step=6)
     expected = ['F'] * 2
     self.assertEqual(expected, list(chords))
Exemplo n.º 6
0
    def testAppendEvent(self):
        chords = chords_lib.ChordProgression()

        chords.append_event(NO_CHORD)
        self.assertListEqual([NO_CHORD], list(chords))
        self.assertEqual(0, chords.start_step)
        self.assertEqual(1, chords.end_step)

        chords.append_event('A-')
        self.assertListEqual([NO_CHORD, 'A-'], list(chords))
        self.assertEqual(0, chords.start_step)
        self.assertEqual(2, chords.end_step)
Exemplo n.º 7
0
 def testSetLength(self):
     # Setting LeadSheet length should agree with setting length on melody and
     # chords separately.
     melody_events = [60]
     melody = melodies_lib.MonophonicMelody()
     melody.from_event_list(melody_events, start_step=9)
     chord_events = ['C7']
     chords = chords_lib.ChordProgression()
     chords.from_event_list(chord_events, start_step=9)
     lead_sheet = lead_sheets_lib.LeadSheet(melody, chords)
     lead_sheet.set_length(5)
     expected_melody = melodies_lib.MonophonicMelody()
     expected_melody.from_event_list(melody_events[:], start_step=9)
     expected_melody.set_length(5)
     expected_chords = chords_lib.ChordProgression()
     expected_chords.from_event_list(chord_events[:], start_step=9)
     expected_chords.set_length(5)
     self.assertEquals(expected_melody, lead_sheet.melody)
     self.assertEquals(expected_chords, lead_sheet.chords)
     self.assertEquals(9, lead_sheet.start_step)
     self.assertEquals(14, lead_sheet.end_step)
Exemplo n.º 8
0
 def testFromQuantizedSequence(self):
     testing_lib.add_quantized_chords(self.quantized_sequence,
                                      [('Am', 4), ('D7', 8), ('G13', 12),
                                       ('Csus', 14)])
     chords = chords_lib.ChordProgression()
     chords.from_quantized_sequence(self.quantized_sequence,
                                    start_step=0,
                                    end_step=16)
     expected = [
         NO_CHORD, NO_CHORD, NO_CHORD, NO_CHORD, 'Am', 'Am', 'Am', 'Am',
         'D7', 'D7', 'D7', 'D7', 'G13', 'G13', 'Csus', 'Csus'
     ]
     self.assertEqual(expected, list(chords))
Exemplo n.º 9
0
 def testSquash(self):
     # LeadSheet squash should agree with melody squash & chords transpose.
     melody_events = [
         12 * 5, NO_EVENT, 12 * 5 + 2, NOTE_OFF, 12 * 6 + 4, NO_EVENT
     ]
     melody = melodies_lib.MonophonicMelody()
     melody.from_event_list(melody_events)
     chord_events = ['C', 'Am', 'Dm', 'G', 'C', NO_CHORD]
     chords = chords_lib.ChordProgression()
     chords.from_event_list(chord_events)
     lead_sheet = lead_sheets_lib.LeadSheet(melody, chords)
     lead_sheet.squash(min_note=12 * 5, max_note=12 * 6, transpose_to_key=0)
     expected_melody = melodies_lib.MonophonicMelody()
     expected_melody.from_event_list(melody_events[:])
     transpose_amount = expected_melody.squash(min_note=12 * 5,
                                               max_note=12 * 6,
                                               transpose_to_key=0)
     expected_chords = chords_lib.ChordProgression()
     expected_chords.from_event_list(chord_events[:])
     expected_chords.transpose(transpose_amount=transpose_amount)
     self.assertEqual(expected_melody, lead_sheet.melody)
     self.assertEqual(expected_chords, lead_sheet.chords)
Exemplo n.º 10
0
    def testTranspose(self):
        # Transpose ChordProgression with basic triads.
        events = ['Cm', 'F', 'B-', 'E-']
        chords = chords_lib.ChordProgression()
        chords.from_event_list(events)
        chords.transpose(transpose_amount=7)
        expected = ['Gm', 'C', 'F', 'B-']
        self.assertEqual(expected, list(chords))

        # Transpose ChordProgression with more complex chords.
        events = ['Esus2', 'B13', 'A7/B', 'F#dim']
        chords = chords_lib.ChordProgression()
        chords.from_event_list(events)
        chords.transpose(transpose_amount=-2)
        expected = ['Dsus2', 'A13', 'G7/A', 'Edim']
        self.assertEqual(expected, list(chords))

        # Transpose ChordProgression containing NO_CHORD.
        events = ['C', 'B-', NO_CHORD, 'F', 'C']
        chords = chords_lib.ChordProgression()
        chords.from_event_list(events)
        chords.transpose(transpose_amount=4)
        expected = ['E', 'D', NO_CHORD, 'A', 'E']
        self.assertEqual(expected, list(chords))
Exemplo n.º 11
0
 def testTranspose(self):
     # LeadSheet transposition should agree with melody & chords transpositions.
     melody_events = [
         12 * 5 + 4, NO_EVENT, 12 * 5 + 5, NOTE_OFF, 12 * 6, NO_EVENT
     ]
     melody = melodies_lib.MonophonicMelody()
     melody.from_event_list(melody_events)
     chord_events = [NO_CHORD, 'C', 'F', 'Dm', 'D', 'G']
     chords = chords_lib.ChordProgression()
     chords.from_event_list(chord_events)
     lead_sheet = lead_sheets_lib.LeadSheet(melody, chords)
     lead_sheet.transpose(transpose_amount=-5,
                          min_note=12 * 5,
                          max_note=12 * 7)
     expected_melody = melodies_lib.MonophonicMelody()
     expected_melody.from_event_list(melody_events[:])
     expected_melody.transpose(transpose_amount=-5,
                               min_note=12 * 5,
                               max_note=12 * 7)
     expected_chords = chords_lib.ChordProgression()
     expected_chords.from_event_list(chord_events[:])
     expected_chords.transpose(transpose_amount=-5)
     self.assertEqual(expected_melody, lead_sheet.melody)
     self.assertEqual(expected_chords, lead_sheet.chords)
Exemplo n.º 12
0
    def testToSequence(self):
        chords = chords_lib.ChordProgression()
        chords.from_event_list(
            [NO_CHORD, 'C7', 'C7', 'C7', 'C7', 'Am7b5', 'F6', 'F6', NO_CHORD])
        sequence = chords.to_sequence(sequence_start_time=2, qpm=60.0)

        self.assertProtoEquals(
            'ticks_per_quarter: 96 '
            'tempos < qpm: 60.0 > '
            'text_annotations < '
            '  text: "C7" time: 2.25 annotation_type: CHORD_SYMBOL '
            '> '
            'text_annotations < '
            '  text: "Am7b5" time: 3.25 annotation_type: CHORD_SYMBOL '
            '> '
            'text_annotations < '
            '  text: "F6" time: 3.5 annotation_type: CHORD_SYMBOL '
            '> '
            'text_annotations < '
            '  text: "N.C." time: 4.0 annotation_type: CHORD_SYMBOL '
            '> ', sequence)