Пример #1
0
 def augment(self, ns):
     stretch_factor = gauss(1.0, 0.5)
     velocity_factor = gauss(1.0, 0.2)
     transpose = randrange(-5, 7)
     ns = stretch_note_sequence(ns, stretch_factor)
     for note in ns.notes:
         note.velocity = max(1,
                             min(127, int(note.velocity * velocity_factor)))
     return transpose_note_sequence(ns, transpose, in_place=True)[0]
Пример #2
0
    def testStretchPipeline(self):
        note_sequence = common_testing_lib.parse_test_proto(
            music_pb2.NoteSequence, """
        time_signatures: {
          time: 1.0
          numerator: 4
          denominator: 4}
        tempos: {
          qpm: 60}""")
        testing_lib.add_track_to_sequence(note_sequence, 0,
                                          [(11, 55, 0.22, 0.50),
                                           (40, 45, 2.50, 3.50),
                                           (55, 120, 4.0, 4.01)])

        expected_sequences = [
            sequences_lib.stretch_note_sequence(note_sequence, 0.5),
            sequences_lib.stretch_note_sequence(note_sequence, 1.0),
            sequences_lib.stretch_note_sequence(note_sequence, 1.5)
        ]

        unit = note_sequence_pipelines.StretchPipeline(
            stretch_factors=[0.5, 1.0, 1.5])
        self._unit_transform_test(unit, note_sequence, expected_sequences)
Пример #3
0
 def augment_note_sequence(ns, stretch_factor, transpose_amount):
   """Augment a NoteSequence by time stretch and pitch transposition."""
   augmented_ns = sequences_lib.stretch_note_sequence(
       ns, stretch_factor, in_place=False)
   try:
     _, num_deleted_notes = sequences_lib.transpose_note_sequence(
         augmented_ns, transpose_amount,
         min_allowed_pitch=MIN_PITCH, max_allowed_pitch=MAX_PITCH,
         in_place=True)
   except chord_symbols_lib.ChordSymbolError:
     raise datagen_beam.DataAugmentationError(
         'Transposition of chord symbol(s) failed.')
   if num_deleted_notes:
     raise datagen_beam.DataAugmentationError(
         'Transposition caused out-of-range pitch(es).')
   return augmented_ns
Пример #4
0
 def transform(self, note_sequence):
     return [
         sequences_lib.stretch_note_sequence(note_sequence, stretch_factor)
         for stretch_factor in self._stretch_factors
     ]
Пример #5
0
 def transform(self, input_object):
   note_sequence = input_object
   return [sequences_lib.stretch_note_sequence(note_sequence, stretch_factor)
           for stretch_factor in self._stretch_factors]