(note_sequence)
return inactive_ranges
Returns ranges where no notes are active in the note_sequence.
Returns ranges where no notes are active in the note_sequence.
Returns ranges where no notes are active in the note_sequence .
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.)
    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
def find_inactive_ranges ( 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. ) 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