code: 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
  
imports: import collections
  import functools
  import io
  import re
  import wave
  import zlib
  import librosa
  from magenta.models.onsets_frames_transcription import audio_transform
  from magenta.models.onsets_frames_transcription import constants
  from magenta.models.onsets_frames_transcription import drum_mappings
  from magenta.models.onsets_frames_transcription import melspec_input
  from note_seq import audio_io
  from note_seq import sequences_lib
  from note_seq.protobuf import music_pb2
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 16 for calling a global function with example usage: truncate_note_sequence(sequence, truncate_secs) and returns: truncated_seq