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.Melody(
        [NO_EVENT, 1, NO_EVENT, NOTE_OFF, NO_EVENT, 2, 3, NOTE_OFF, NO_EVENT])
    chords = chords_lib.ChordProgression(
        [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.assertEqual(melody_sequence.ticks_per_quarter,
                     sequence.ticks_per_quarter)
    self.assertProtoEquals(melody_sequence.tempos, sequence.tempos)
    self.assertEqual(melody_sequence.total_time, sequence.total_time)
    self.assertProtoEquals(melody_sequence.notes, sequence.notes)
    self.assertProtoEquals(chords_sequence.text_annotations,
                           sequence.text_annotations)
 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]
   chord_events = ['C', 'Am', 'Dm', 'G', 'C', NO_CHORD]
   melody = melodies_lib.Melody(melody_events)
   chords = chords_lib.ChordProgression(chord_events)
   expected_melody = copy.deepcopy(melody)
   expected_chords = copy.deepcopy(chords)
   lead_sheet = lead_sheets_lib.LeadSheet(melody, chords)
   lead_sheet.squash(min_note=12 * 5, max_note=12 * 6, transpose_to_key=0)
   transpose_amount = expected_melody.squash(
       min_note=12 * 5, max_note=12 * 6, transpose_to_key=0)
   expected_chords.transpose(transpose_amount=transpose_amount)
   self.assertEqual(expected_melody, lead_sheet.melody)
   self.assertEqual(expected_chords, lead_sheet.chords)
 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]
   chord_events = [NO_CHORD, 'C', 'F', 'Dm', 'D', 'G']
   melody = melodies_lib.Melody(melody_events)
   chords = chords_lib.ChordProgression(chord_events)
   expected_melody = copy.deepcopy(melody)
   expected_chords = copy.deepcopy(chords)
   lead_sheet = lead_sheets_lib.LeadSheet(melody, chords)
   lead_sheet.transpose(transpose_amount=-5, min_note=12 * 5, max_note=12 * 7)
   expected_melody.transpose(
       transpose_amount=-5, min_note=12 * 5, max_note=12 * 7)
   expected_chords.transpose(transpose_amount=-5)
   self.assertEqual(expected_melody, lead_sheet.melody)
   self.assertEqual(expected_chords, lead_sheet.chords)
 def testSetLength(self):
   # Setting LeadSheet length should agree with setting length on melody and
   # chords separately.
   melody_events = [60]
   chord_events = ['C7']
   melody = melodies_lib.Melody(melody_events, start_step=9)
   chords = chords_lib.ChordProgression(chord_events, start_step=9)
   expected_melody = copy.deepcopy(melody)
   expected_chords = copy.deepcopy(chords)
   lead_sheet = lead_sheets_lib.LeadSheet(melody, chords)
   lead_sheet.set_length(5)
   expected_melody.set_length(5)
   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)
Example #5
0
 def testLeadSheetExtractor(self):
     note_sequence = common_testing_lib.parse_test_proto(
         music_pb2.NoteSequence, """
     time_signatures: {
       numerator: 4
       denominator: 4}
     tempos: {
       qpm: 60}""")
     music_testing_lib.add_track_to_sequence(note_sequence,
                                             0, [(12, 100, 2, 4),
                                                 (11, 1, 6, 7)])
     music_testing_lib.add_track_to_sequence(note_sequence,
                                             1, [(12, 127, 2, 4),
                                                 (14, 50, 6, 8)])
     music_testing_lib.add_chords_to_sequence(note_sequence, [('Cm7', 2),
                                                              ('F9', 4),
                                                              ('G7b9', 6)])
     quantized_sequence = sequences_lib.quantize_note_sequence(
         note_sequence, steps_per_quarter=1)
     expected_melody_events = [[
         NO_EVENT, NO_EVENT, 12, NO_EVENT, NOTE_OFF, NO_EVENT, 11
     ], [
         NO_EVENT, NO_EVENT, 12, NO_EVENT, NOTE_OFF, NO_EVENT, 14, NO_EVENT
     ]]
     expected_chord_events = [[
         NO_CHORD, NO_CHORD, 'Cm7', 'Cm7', 'F9', 'F9', 'G7b9'
     ], [NO_CHORD, NO_CHORD, 'Cm7', 'Cm7', 'F9', 'F9', 'G7b9', 'G7b9']]
     expected_lead_sheets = []
     for melody_events, chord_events in zip(expected_melody_events,
                                            expected_chord_events):
         melody = melodies_lib.Melody(melody_events,
                                      steps_per_quarter=1,
                                      steps_per_bar=4)
         chords = chords_lib.ChordProgression(chord_events,
                                              steps_per_quarter=1,
                                              steps_per_bar=4)
         lead_sheet = lead_sheets_lib.LeadSheet(melody, chords)
         expected_lead_sheets.append(lead_sheet)
     unit = lead_sheet_pipelines.LeadSheetExtractor(
         min_bars=1,
         min_unique_pitches=1,
         gap_bars=1,
         all_transpositions=False)
     self._unit_transform_test(unit, quantized_sequence,
                               expected_lead_sheets)
Example #6
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
     ]
     chord_events = ['C', 'Am', 'Dm', 'G', 'C', NO_CHORD]
     lead_sheet = lead_sheets_lib.LeadSheet()
     lead_sheet.from_event_list(zip(melody_events, chord_events))
     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)
Example #7
0
 def testSetLength(self):
     # Setting LeadSheet length should agree with setting length on melody and
     # chords separately.
     melody_events = [60]
     chord_events = ['C7']
     lead_sheet = lead_sheets_lib.LeadSheet()
     lead_sheet.from_event_list(zip(melody_events, chord_events),
                                start_step=9)
     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)
Example #8
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
     ]
     chord_events = [NO_CHORD, 'C', 'F', 'Dm', 'D', 'G']
     lead_sheet = lead_sheets_lib.LeadSheet()
     lead_sheet.from_event_list(zip(melody_events, chord_events))
     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)