def testExtractLeadSheetFragmentsNoChords(self):
   testing_lib.add_track_to_sequence(
       self.note_sequence, 0,
       [(12, 100, 2, 4), (11, 1, 6, 11)])
   testing_lib.add_track_to_sequence(
       self.note_sequence, 1,
       [(12, 127, 2, 4), (14, 50, 6, 8),
        (50, 100, 33, 37), (52, 100, 34, 37)])
   testing_lib.add_chords_to_sequence(
       self.note_sequence,
       [('C', 2), ('G7', 6), (NO_CHORD, 10)])
   quantized_sequence = sequences_lib.quantize_note_sequence(
       self.note_sequence, steps_per_quarter=1)
   lead_sheets, stats = lead_sheets_lib.extract_lead_sheet_fragments(
       quantized_sequence, min_bars=1, gap_bars=2, min_unique_pitches=2,
       ignore_polyphonic_notes=True, require_chords=True)
   melodies, _ = melodies_lib.extract_melodies(
       quantized_sequence, min_bars=1, gap_bars=2, min_unique_pitches=2,
       ignore_polyphonic_notes=True)
   chord_progressions, _ = chords_lib.extract_chords_for_melodies(
       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)
 def testExtractLeadSheetFragments(self):
   testing_lib.add_track_to_sequence(
       self.note_sequence, 0,
       [(12, 100, .5, 1), (11, 1, 1.5, 2.75)])
   testing_lib.add_track_to_sequence(
       self.note_sequence, 1,
       [(12, 127, .5, 1), (14, 50, 1.5, 2),
        (50, 100, 8.25, 9.25), (52, 100, 8.5, 9.25)])
   testing_lib.add_chords_to_sequence(
       self.note_sequence,
       [('C', .5), ('G7', 1.5), ('Cmaj7', 8.25)])
   quantized_sequence = sequences_lib.quantize_note_sequence(
       self.note_sequence, self.steps_per_quarter)
   lead_sheets, _ = lead_sheets_lib.extract_lead_sheet_fragments(
       quantized_sequence, min_bars=1, gap_bars=2, min_unique_pitches=2,
       ignore_polyphonic_notes=True, require_chords=True)
   melodies, _ = melodies_lib.extract_melodies(
       quantized_sequence, min_bars=1, gap_bars=2, min_unique_pitches=2,
       ignore_polyphonic_notes=True)
   chord_progressions, _ = chords_lib.extract_chords_for_melodies(
       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))
 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))
 def testExtractLeadSheetFragmentsCoincidentChords(self):
   testing_lib.add_track_to_sequence(
       self.note_sequence, 0,
       [(12, 100, 2, 4), (11, 1, 6, 11)])
   testing_lib.add_track_to_sequence(
       self.note_sequence, 1,
       [(12, 127, 2, 4), (14, 50, 6, 8),
        (50, 100, 33, 37), (52, 100, 34, 37)])
   testing_lib.add_chords_to_sequence(
       self.note_sequence,
       [('C', 2), ('G7', 6), ('Cmaj7', 33), ('F', 33)])
   quantized_sequence = sequences_lib.quantize_note_sequence(
       self.note_sequence, steps_per_quarter=1)
   lead_sheets, _ = lead_sheets_lib.extract_lead_sheet_fragments(
       quantized_sequence, min_bars=1, gap_bars=2, min_unique_pitches=2,
       ignore_polyphonic_notes=True, require_chords=True)
   melodies, _ = melodies_lib.extract_melodies(
       quantized_sequence, min_bars=1, gap_bars=2, min_unique_pitches=2,
       ignore_polyphonic_notes=True)
   chord_progressions, _ = chords_lib.extract_chords_for_melodies(
       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))
 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)
Exemple #6
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))
 def testExtractLeadSheetFragments(self):
   testing_lib.add_track_to_sequence(
       self.note_sequence, 0,
       [(12, 100, .5, 1), (11, 1, 1.5, 2.75)])
   testing_lib.add_track_to_sequence(
       self.note_sequence, 1,
       [(12, 127, .5, 1), (14, 50, 1.5, 2),
        (50, 100, 8.25, 9.25), (52, 100, 8.5, 9.25)])
   testing_lib.add_chords_to_sequence(
       self.note_sequence,
       [('C', .5), ('G7', 1.5), ('Cmaj7', 8.25)])
   quantized_sequence = sequences_lib.quantize_note_sequence(
       self.note_sequence, self.steps_per_quarter)
   lead_sheets, _ = lead_sheets_lib.extract_lead_sheet_fragments(
       quantized_sequence, min_bars=1, gap_bars=2, min_unique_pitches=2,
       ignore_polyphonic_notes=True, require_chords=True)
   melodies, _ = melodies_lib.extract_melodies(
       quantized_sequence, min_bars=1, gap_bars=2, min_unique_pitches=2,
       ignore_polyphonic_notes=True)
   chord_progressions, _ = chords_lib.extract_chords_for_melodies(
       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))
Exemple #8
0
 def transform(self, quantized_sequence):
   try:
     lead_sheets, stats = lead_sheets_lib.extract_lead_sheet_fragments(
         quantized_sequence,
         min_bars=self._min_bars,
         max_steps_truncate=self._max_steps,
         min_unique_pitches=self._min_unique_pitches,
         gap_bars=self._gap_bars,
         ignore_polyphonic_notes=self._ignore_polyphonic_notes,
         filter_drums=self._filter_drums,
         require_chords=self._require_chords,
         all_transpositions=self._all_transpositions)
   except events_lib.NonIntegerStepsPerBarException as detail:
     tf.logging.warning('Skipped sequence: %s', detail)
     lead_sheets = []
     stats = [statistics.Counter('non_integer_steps_per_bar', 1)]
   self._set_stats(stats)
   return lead_sheets
 def transform(self, quantized_sequence):
   try:
     lead_sheets, stats = lead_sheets_lib.extract_lead_sheet_fragments(
         quantized_sequence,
         min_bars=self._min_bars,
         max_steps_truncate=self._max_steps,
         min_unique_pitches=self._min_unique_pitches,
         gap_bars=self._gap_bars,
         ignore_polyphonic_notes=self._ignore_polyphonic_notes,
         filter_drums=self._filter_drums,
         require_chords=self._require_chords,
         all_transpositions=self._all_transpositions)
   except events_lib.NonIntegerStepsPerBarError as detail:
     tf.logging.warning('Skipped sequence: %s', detail)
     lead_sheets = []
     stats = [statistics.Counter('non_integer_steps_per_bar', 1)]
   except chord_symbols_lib.ChordSymbolError as detail:
     tf.logging.warning('Skipped sequence: %s', detail)
     lead_sheets = []
     stats = [statistics.Counter('chord_symbol_exception', 1)]
   self._set_stats(stats)
   return lead_sheets