def generate(sequence: NoteSequence, name: str, bundle_filename: str, config_name: str, generation_start_time: float, generation_end_time: float): # TODO generate a new sequence using the sequence generator pass sequence = ss.trim_note_sequence(sequence, generation_start_time, generation_end_time) return sequence
def generate(sequence: NoteSequence, name: str, bundle_filename: str, config_name: str, generation_start_time: float, generation_end_time: float): generator_options = generator_pb2.GeneratorOptions() generator_options.args['temperature'].float_value = 1 generator_options.generate_sections.add(start_time=generation_start_time, end_time=generation_end_time) sequence_generator = get_sequence_generator(name, bundle_filename, config_name) sequence = sequence_generator.generate(sequence, generator_options) sequence = ss.trim_note_sequence(sequence, generation_start_time, generation_end_time) return sequence
def testTrimNoteSequence(self): sequence = copy.copy(self.note_sequence) testing_lib.add_track_to_sequence( 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)]) expected_subsequence = copy.copy(self.note_sequence) testing_lib.add_track_to_sequence( expected_subsequence, 0, [(40, 45, 2.50, 3.50), (55, 120, 4.0, 4.01)]) expected_subsequence.total_time = 4.75 subsequence = sequences_lib.trim_note_sequence(sequence, 2.5, 4.75) self.assertProtoEquals(expected_subsequence, subsequence)
def run(self): # TODO sequence = self._primer_sequence player = self._midi_hub.start_playback(sequence, allow_updates=True) # TODO seconds_per_step = 60.0 / self._qpm / self._sequence_generator.steps_per_quarter num_steps_per_bar = self._sequence_generator.steps_per_quarter * 2 seconds_per_bar = num_steps_per_bar * seconds_per_step seconds_per_loop = self._bar_per_loop * seconds_per_bar # TODO MOVE plotter = Plotter(max_bar=16, live_reload=True) pretty_midi = pm.PrettyMIDI() pretty_midi.instruments.append(pm.Instrument(0)) pretty_midi.instruments[0].append(pm.Note(100, 36, 0, 1)) # TODO wall_start_time = time.time() # TODO for bar_count in range(0, sys.maxsize): # TODO cursor_time = bar_count * seconds_per_loop # TODO sequence_adjusted = music_pb2.NoteSequence() sequence_adjusted.CopyFrom(sequence) sequence_adjusted = adjust_sequence_times(sequence_adjusted, wall_start_time) player.update_sequence(sequence_adjusted, start_time=cursor_time) # TODO MOVE TO UTILS pretty_sequence = mm.midi_io.note_sequence_to_pretty_midi(sequence) for instrument in pretty_sequence.instruments: for note in instrument.notes: pretty_midi.instruments[0].notes.append(note) plotter.show(pretty_midi, self._output_file) # TODO loop_start_time = cursor_time loop_end_time = loop_start_time + seconds_per_loop generation_start_time = loop_end_time generation_end_time = generation_start_time + seconds_per_loop generator_options = generator_pb2.GeneratorOptions() generator_options.args['temperature'].float_value = 1 generator_options.generate_sections.add( start_time=generation_start_time, end_time=generation_end_time) # TODO if bar_count % self._num_loops == 0: print("GENERATING") sequence = self._sequence_generator.generate( sequence, generator_options) sequence = sequences_lib.trim_note_sequence( sequence, generation_start_time, generation_end_time) else: print("LOOPING") sequence = sequences_lib.trim_note_sequence( sequence, loop_start_time, loop_end_time) sequence = sequences_lib.shift_sequence_times( sequence, seconds_per_loop) # TODO 1 wake up per bar sleep_time = seconds_per_loop - ( (time.time() - wall_start_time) % seconds_per_loop) time.sleep(sleep_time)
def loop(sequence: NoteSequence, loop_start_time: float, loop_end_time: float, seconds_per_loop: float): sequence = ss.trim_note_sequence(sequence, loop_start_time, loop_end_time) sequence = ss.shift_sequence_times(sequence, seconds_per_loop) return sequence