(sequence, truncate_secs)
return truncated_seq
Truncates a NoteSequence to the given length.
Truncates a NoteSequence to the given length.
Truncates a NoteSequence to the given length .
def truncate_note_sequence(sequence, truncate_secs):
  """Truncates a NoteSequence to the given length."""
  sus_sequence = sequences_lib.apply_sustain_control_changes(sequence)

  truncated_seq = music_pb2.NoteSequence()

  for note in sus_sequence.notes:
    start_time = note.start_time
    end_time = note.end_time

    if start_time > truncate_secs:
      continue

    if end_time > truncate_secs:
      end_time = truncate_secs

    modified_note = truncated_seq.notes.add()
    modified_note.MergeFrom(note)
    modified_note.start_time = start_time
    modified_note.end_time = end_time
  if truncated_seq.notes:
    truncated_seq.total_time = truncated_seq.notes[-1].end_time
  return truncated_seq
def truncate_note_sequence ( sequence , truncate_secs ) : sus_sequence = sequences_lib . apply_sustain_control_changes ( sequence ) truncated_seq = music_pb2 . NoteSequence ( ) for note in sus_sequence . notes : start_time = note . start_time end_time = note . end_time if start_time > truncate_secs : continue if end_time > truncate_secs : end_time = truncate_secs modified_note = truncated_seq . notes . add ( ) modified_note . MergeFrom ( note ) modified_note . start_time = start_time modified_note . end_time = end_time if truncated_seq . notes : truncated_seq . total_time = truncated_seq . notes [ - 1 ] . end_time return truncated_seq