code: def segment_notes(
      binarize_f,
      pick_f0_f,
      pick_amps_f,
      controls,
      frame_rate=DDSP_DEFAULT_FRAME_RATE,
  ):
      """A function to split a controls dict into discrete notes.
  
      Args:
        binarize_f: Returns a binary vector that is True when a note is on.
        pick_f0_f: Returns a single f0 for a vector of f0s of a single note.
        pick_amps_f: Returns a single amplitude for a vector of amplidutes of a
          single note.
        controls: The controls as returned from model inference.
        frame_rate: Frame rate for the notes found.
  
      Returns:
        NoteSequence object with discretized note information.
  
      """
  
      sequence = note_seq.NoteSequence()
  
      def construct_note(curr_ind, duration):
          note_start = curr_ind - duration
          f0 = pick_f0_f(controls, start=note_start, stop=curr_ind)
          amplitude = pick_amps_f(
              controls, start=note_start, stop=curr_ind
          )  # pylint:disable=unused-variable
          note = sequence.notes.add()
          note.pitch = np.round(ddsp.core.hz_to_midi(f0)).astype(
              np.int32
          )
          note.start_time = note_start / frame_rate
          note.end_time = (note_start + duration) / frame_rate
          # TODO(rigeljs): convert amplitude to velocity and add to note.
          note.velocity = 127
  
      binary_sample = binarize_f(controls)
      has_been_on = 0
  
      for i, sample_i in enumerate(np.nditer(binary_sample)):
          if sample_i:
              has_been_on += 1
          elif has_been_on > 0:
              construct_note(i, has_been_on)
              has_been_on = 0
      if has_been_on > 0:
          construct_note(len(binary_sample), has_been_on)
  
      sequence.total_time = len(binary_sample) / frame_rate
  
      return sequence
  
file_path: ddsp/ddsp/training/heuristics.py
imports: import ddsp
  import gin
  import note_seq
  import numpy
  import tensorflow.compat.v2
label_desc: Use image node_id 5 for calling a global function with example usage: segment_notes(binarize_f, pick_f0_f, pick_amps_f, controls, frame_rate) and returns: sequence