예제 #1
0
 def testExtractChordsForMelodiesCoincidentChords(self):
     self.quantized_sequence.steps_per_quarter = 1
     testing_lib.add_quantized_track(self.quantized_sequence, 0,
                                     [(12, 100, 2, 4), (11, 1, 6, 11)])
     testing_lib.add_quantized_track(self.quantized_sequence, 1,
                                     [(12, 127, 2, 4), (14, 50, 6, 8),
                                      (50, 100, 33, 37), (52, 100, 34, 37)])
     testing_lib.add_quantized_chords(self.quantized_sequence,
                                      [('C', 2), ('G7', 6), ('E13', 8),
                                       ('Cmaj7', 8)])
     melodies, _ = melodies_lib.extract_melodies(
         self.quantized_sequence,
         min_bars=1,
         gap_bars=2,
         min_unique_pitches=2,
         ignore_polyphonic_notes=True)
     chord_progressions, stats = chords_lib.extract_chords_for_melodies(
         self.quantized_sequence, melodies)
     expected = [[NO_CHORD, NO_CHORD, 'C', 'C', 'C', 'C', 'G7', 'G7'],
                 ['Cmaj7', 'Cmaj7', 'Cmaj7', 'Cmaj7', 'Cmaj7']]
     stats_dict = dict([(stat.name, stat) for stat in stats])
     self.assertIsNone(chord_progressions[0])
     self.assertEqual(expected,
                      [list(chords) for chords in chord_progressions[1:]])
     self.assertEqual(stats_dict['coincident_chords'].count, 1)
예제 #2
0
 def testExtractLeadSheetFragments(self):
     self.quantized_sequence.steps_per_quarter = 1
     testing_lib.add_quantized_track(self.quantized_sequence, 0,
                                     [(12, 100, 2, 4), (11, 1, 6, 11)])
     testing_lib.add_quantized_track(self.quantized_sequence, 1,
                                     [(12, 127, 2, 4), (14, 50, 6, 8),
                                      (50, 100, 33, 37), (52, 100, 34, 37)])
     testing_lib.add_quantized_chords(self.quantized_sequence,
                                      [('C', 2), ('G7', 6), ('Cmaj7', 33)])
     lead_sheets, _ = lead_sheets_lib.extract_lead_sheet_fragments(
         self.quantized_sequence,
         min_bars=1,
         gap_bars=2,
         min_unique_pitches=2,
         ignore_polyphonic_notes=True,
         require_chords=True)
     melodies, _ = melodies_lib.extract_melodies(
         self.quantized_sequence,
         min_bars=1,
         gap_bars=2,
         min_unique_pitches=2,
         ignore_polyphonic_notes=True)
     chord_progressions, _ = chords_lib.extract_chords_for_melodies(
         self.quantized_sequence, melodies)
     self.assertEqual(list(melodies),
                      list(lead_sheet.melody for lead_sheet in lead_sheets))
     self.assertEqual(list(chord_progressions),
                      list(lead_sheet.chords for lead_sheet in lead_sheets))
예제 #3
0
 def testExtractLeadSheetFragmentsNoChords(self):
     self.quantized_sequence.steps_per_quarter = 1
     testing_lib.add_quantized_track(self.quantized_sequence, 0,
                                     [(12, 100, 2, 4), (11, 1, 6, 11)])
     testing_lib.add_quantized_track(self.quantized_sequence, 1,
                                     [(12, 127, 2, 4), (14, 50, 6, 8),
                                      (50, 100, 33, 37), (52, 100, 34, 37)])
     testing_lib.add_quantized_chords(self.quantized_sequence,
                                      [('C', 2), ('G7', 6), (NO_CHORD, 10)])
     lead_sheets, stats = lead_sheets_lib.extract_lead_sheet_fragments(
         self.quantized_sequence,
         min_bars=1,
         gap_bars=2,
         min_unique_pitches=2,
         ignore_polyphonic_notes=True,
         require_chords=True)
     melodies, _ = melodies_lib.extract_melodies(
         self.quantized_sequence,
         min_bars=1,
         gap_bars=2,
         min_unique_pitches=2,
         ignore_polyphonic_notes=True)
     chord_progressions, _ = chords_lib.extract_chords_for_melodies(
         self.quantized_sequence, melodies)
     stats_dict = dict([(stat.name, stat) for stat in stats])
     # Last lead sheet should be rejected for having no chords.
     self.assertEqual(list(melodies[:2]),
                      list(lead_sheet.melody for lead_sheet in lead_sheets))
     self.assertEqual(list(chord_progressions[:2]),
                      list(lead_sheet.chords for lead_sheet in lead_sheets))
     self.assertEqual(stats_dict['empty_chord_progressions'].count, 1)
예제 #4
0
 def testNotEq(self):
     left_hand = sequences_lib.QuantizedSequence()
     left_hand.bpm = 123.0
     left_hand.steps_per_beat = 7
     left_hand.time_signature = sequences_lib.TimeSignature(7, 8)
     testing_lib.add_quantized_track(left_hand, 0, [(12, 100, 0, 40),
                                                    (11, 100, 1, 2)])
     testing_lib.add_quantized_track(left_hand, 2, [(55, 100, 4, 6),
                                                    (15, 120, 4, 10)])
     testing_lib.add_quantized_track(left_hand, 3, [(1, 10, 0, 6),
                                                    (2, 50, 20, 21),
                                                    (0, 101, 17, 21)])
     testing_lib.add_quantized_chords(left_hand, [('Cmaj7', 1), ('G9', 2)])
     right_hand = sequences_lib.QuantizedSequence()
     right_hand.bpm = 123.0
     right_hand.steps_per_beat = 7
     right_hand.time_signature = sequences_lib.TimeSignature(7, 8)
     testing_lib.add_quantized_track(right_hand, 0, [(11, 100, 1, 2),
                                                     (12, 100, 0, 40)])
     testing_lib.add_quantized_track(right_hand, 2, [(14, 120, 4, 10),
                                                     (55, 100, 4, 6)])
     testing_lib.add_quantized_track(right_hand, 3, [(0, 101, 17, 21),
                                                     (2, 50, 20, 21),
                                                     (1, 10, 0, 6)])
     testing_lib.add_quantized_chords(right_hand, [('G9', 2), ('C7', 1)])
     self.assertNotEqual(left_hand, right_hand)
예제 #5
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)
예제 #6
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))
예제 #7
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))
예제 #8
0
 def testFromNoteSequence(self):
     testing_lib.add_track(self.note_sequence, 0, [(12, 100, 0.01, 10.0),
                                                   (11, 55, 0.22, 0.50),
                                                   (40, 45, 2.50, 3.50),
                                                   (55, 120, 4.0, 4.01),
                                                   (52, 99, 4.75, 5.0)])
     testing_lib.add_chords(self.note_sequence, [('B7', 0.22),
                                                 ('Em9', 4.0)])
     testing_lib.add_quantized_track(self.expected_quantized_sequence, 0,
                                     [(12, 100, 0, 40), (11, 55, 1, 2),
                                      (40, 45, 10, 14), (55, 120, 16, 17),
                                      (52, 99, 19, 20)])
     testing_lib.add_quantized_chords(self.expected_quantized_sequence,
                                      [('B7', 1), ('Em9', 16)])
     quantized = sequences_lib.QuantizedSequence()
     quantized.from_note_sequence(self.note_sequence,
                                  self.steps_per_quarter)
     self.assertEqual(self.expected_quantized_sequence, quantized)
예제 #9
0
 def testExtractChordsForMelodies(self):
     self.quantized_sequence.steps_per_quarter = 1
     testing_lib.add_quantized_track(self.quantized_sequence, 0,
                                     [(12, 100, 2, 4), (11, 1, 6, 11)])
     testing_lib.add_quantized_track(self.quantized_sequence, 1,
                                     [(12, 127, 2, 4), (14, 50, 6, 8),
                                      (50, 100, 33, 37), (52, 100, 34, 37)])
     testing_lib.add_quantized_chords(self.quantized_sequence,
                                      [('C', 2), ('G7', 6), ('Cmaj7', 33)])
     melodies, _ = melodies_lib.extract_melodies(
         self.quantized_sequence,
         min_bars=1,
         gap_bars=2,
         min_unique_pitches=2,
         ignore_polyphonic_notes=True)
     chord_progressions, _ = chords_lib.extract_chords_for_melodies(
         self.quantized_sequence, melodies)
     expected = [[
         NO_CHORD, NO_CHORD, 'C', 'C', 'C', 'C', 'G7', 'G7', 'G7', 'G7',
         'G7'
     ], [NO_CHORD, NO_CHORD, 'C', 'C', 'C', 'C', 'G7', 'G7'],
                 ['G7', 'Cmaj7', 'Cmaj7', 'Cmaj7', 'Cmaj7']]
     self.assertEqual(expected,
                      [list(chords) for chords in chord_progressions])