code: def find_inactive_ranges(note_sequence):
      """Returns ranges where no notes are active in the note_sequence."""
      start_sequence = sorted(
          note_sequence.notes,
          key=lambda note: note.start_time,
          reverse=True,
      )
      end_sequence = sorted(
          note_sequence.notes,
          key=lambda note: note.end_time,
          reverse=True,
      )
  
      notes_active = 0
  
      time = start_sequence[-1].start_time
      inactive_ranges = []
      if time > 0:
          inactive_ranges.append(0.0)
          inactive_ranges.append(time)
      start_sequence.pop()
      notes_active += 1
      # Iterate through all note on events
      while start_sequence or end_sequence:
          if start_sequence and (
              start_sequence[-1].start_time < end_sequence[-1].end_time
          ):
              if notes_active == 0:
                  time = start_sequence[-1].start_time
                  inactive_ranges.append(time)
              notes_active += 1
              start_sequence.pop()
          else:
              notes_active -= 1
              if notes_active == 0:
                  time = end_sequence[-1].end_time
                  inactive_ranges.append(time)
              end_sequence.pop()
  
      # if the last note is the same time as the end, don't add it
      # remove the start instead of creating a sequence with 0 length
      if inactive_ranges[-1] < note_sequence.total_time:
          inactive_ranges.append(note_sequence.total_time)
      else:
          inactive_ranges.pop()
  
      assert len(inactive_ranges) % 2 == 0
  
      inactive_ranges = [
          (inactive_ranges[2 * i], inactive_ranges[2 * i + 1])
          for i in range(len(inactive_ranges) // 2)
      ]
      return inactive_ranges
  
file_path: magenta/magenta/models/onsets_frames_transcription/audio_label_data_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import bisect
  import math
  import librosa
  from note_seq import audio_io
  from note_seq import constants
  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 2 for calling a global function with example usage: find_inactive_ranges(note_sequence) and returns: inactive_ranges