Exemplo n.º 1
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.QuantizedSequence.TimeSignature(
       numerator=7, denominator=8)
   testing_lib.add_quantized_track_to_sequence(
       left_hand, 0,
       [(12, 100, 0, 40), (11, 100, 1, 2)])
   testing_lib.add_quantized_track_to_sequence(
       left_hand, 2,
       [(55, 100, 4, 6), (15, 120, 4, 10)])
   testing_lib.add_quantized_track_to_sequence(
       left_hand, 3,
       [(1, 10, 0, 6), (2, 50, 20, 21), (0, 101, 17, 21)])
   testing_lib.add_quantized_chords_to_sequence(
       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.QuantizedSequence.TimeSignature(
       numerator=7, denominator=8)
   testing_lib.add_quantized_track_to_sequence(
       right_hand, 0,
       [(11, 100, 1, 2), (12, 100, 0, 40)])
   testing_lib.add_quantized_track_to_sequence(
       right_hand, 2,
       [(14, 120, 4, 10), (55, 100, 4, 6)])
   testing_lib.add_quantized_track_to_sequence(
       right_hand, 3,
       [(0, 101, 17, 21), (2, 50, 20, 21), (1, 10, 0, 6)])
   testing_lib.add_quantized_chords_to_sequence(
       right_hand, [('G9', 2), ('C7', 1)])
   self.assertNotEqual(left_hand, right_hand)
Exemplo n.º 2
0
 def testExtractChordsForMelodiesCoincidentChords(self):
     self.quantized_sequence.steps_per_quarter = 1
     testing_lib.add_quantized_track_to_sequence(self.quantized_sequence, 0,
                                                 [(12, 100, 2, 4),
                                                  (11, 1, 6, 11)])
     testing_lib.add_quantized_track_to_sequence(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_to_sequence(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)
 def testExtractLeadSheetFragmentsNoChords(self):
   self.quantized_sequence.steps_per_quarter = 1
   testing_lib.add_quantized_track_to_sequence(
       self.quantized_sequence, 0,
       [(12, 100, 2, 4), (11, 1, 6, 11)])
   testing_lib.add_quantized_track_to_sequence(
       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_to_sequence(
       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)
Exemplo n.º 4
0
 def testExtractChordsForMelodies(self):
     self.quantized_sequence.steps_per_quarter = 1
     testing_lib.add_quantized_track_to_sequence(self.quantized_sequence, 0,
                                                 [(12, 100, 2, 4),
                                                  (11, 1, 6, 11)])
     testing_lib.add_quantized_track_to_sequence(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_to_sequence(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])
 def testExtractLeadSheetFragmentsCoincidentChords(self):
   self.quantized_sequence.steps_per_quarter = 1
   testing_lib.add_quantized_track_to_sequence(
       self.quantized_sequence, 0,
       [(12, 100, 2, 4), (11, 1, 6, 11)])
   testing_lib.add_quantized_track_to_sequence(
       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_to_sequence(
       self.quantized_sequence,
       [('C', 2), ('G7', 6), ('Cmaj7', 33), ('F', 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)
   # Last lead sheet should be rejected for coincident 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))
Exemplo n.º 6
0
 def testFromQuantizedSequenceWithCoincidentChords(self):
   testing_lib.add_quantized_chords_to_sequence(
       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.º 7
0
 def testFromQuantizedSequenceWithinSingleChord(self):
   testing_lib.add_quantized_chords_to_sequence(
       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.º 8
0
 def testFromQuantizedSequenceWithinSingleChord(self):
   testing_lib.add_quantized_chords_to_sequence(
       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.º 9
0
 def testFromQuantizedSequenceWithCoincidentChords(self):
   testing_lib.add_quantized_chords_to_sequence(
       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.º 10
0
 def testExtractChords(self):
   self.quantized_sequence.steps_per_quarter = 1
   testing_lib.add_quantized_chords_to_sequence(
       self.quantized_sequence, [('C', 2), ('G7', 6), ('F', 8)])
   self.quantized_sequence.total_steps = 10
   chord_progressions, _ = chords_lib.extract_chords(self.quantized_sequence)
   expected = [[NO_CHORD, NO_CHORD, 'C', 'C', 'C', 'C', 'G7', 'G7', 'F', 'F']]
   self.assertEqual(expected, [list(chords) for chords in chord_progressions])
Exemplo n.º 11
0
 def testExtractChordsAllTranspositions(self):
   self.quantized_sequence.steps_per_quarter = 1
   testing_lib.add_quantized_chords_to_sequence(
       self.quantized_sequence, [('C', 1)])
   self.quantized_sequence.total_steps = 2
   chord_progressions, _ = chords_lib.extract_chords(self.quantized_sequence,
                                                     all_transpositions=True)
   expected = zip([NO_CHORD] * 12, ['G-', 'G', 'A-', 'A', 'B-', 'B',
                                    'C', 'D-', 'D', 'E-', 'E', 'F'])
   self.assertEqual(expected, [tuple(chords) for chords in chord_progressions])
Exemplo n.º 12
0
 def testFromQuantizedSequence(self):
   testing_lib.add_quantized_chords_to_sequence(
       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.º 13
0
 def testFromQuantizedSequence(self):
   testing_lib.add_quantized_chords_to_sequence(
       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.º 14
0
 def testChordsExtractor(self):
     quantized_sequence = sequences_lib.QuantizedSequence()
     quantized_sequence.steps_per_quarter = 1
     testing_lib.add_quantized_chords_to_sequence(quantized_sequence,
                                                  [('C', 2), ('Am', 4),
                                                   ('F', 5)])
     quantized_sequence.total_steps = 8
     expected_events = [[NO_CHORD, NO_CHORD, 'C', 'C', 'Am', 'F', 'F', 'F']]
     expected_chord_progressions = []
     for events_list in expected_events:
         chords = chords_lib.ChordProgression(events_list,
                                              steps_per_quarter=1,
                                              steps_per_bar=4)
         expected_chord_progressions.append(chords)
     unit = pipelines_common.ChordsExtractor(all_transpositions=False)
     self._unit_transform_test(unit, quantized_sequence,
                               expected_chord_progressions)
Exemplo n.º 15
0
 def testFromNoteSequence(self):
   testing_lib.add_track_to_sequence(
       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_to_sequence(
       self.note_sequence,
       [('B7', 0.22), ('Em9', 4.0)])
   testing_lib.add_quantized_track_to_sequence(
       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_to_sequence(
       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)
Exemplo n.º 16
0
 def testExtractChordsForMelodies(self):
   self.quantized_sequence.steps_per_quarter = 1
   testing_lib.add_quantized_track_to_sequence(
       self.quantized_sequence, 0,
       [(12, 100, 2, 4), (11, 1, 6, 11)])
   testing_lib.add_quantized_track_to_sequence(
       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_to_sequence(
       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])
Exemplo n.º 17
0
 def testExtractChordsForMelodiesCoincidentChords(self):
   self.quantized_sequence.steps_per_quarter = 1
   testing_lib.add_quantized_track_to_sequence(
       self.quantized_sequence, 0,
       [(12, 100, 2, 4), (11, 1, 6, 11)])
   testing_lib.add_quantized_track_to_sequence(
       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_to_sequence(
       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)