(min_pitch, max_pitch, kv)
return key, ns.SerializeToString()
Filter notes with out-of-range pitch from NoteSequence protos.
Filter notes with out-of-range pitch from NoteSequence protos.
Filter notes with out - of - range pitch from NoteSequence protos .
def filter_invalid_notes(min_pitch, max_pitch, kv):
  """Filter notes with out-of-range pitch from NoteSequence protos."""
  key, ns_str = kv
  ns = note_seq.NoteSequence.FromString(ns_str)
  valid_notes = [note for note in ns.notes
                 if min_pitch <= note.pitch <= max_pitch]
  if len(valid_notes) < len(ns.notes):
    del ns.notes[:]
    ns.notes.extend(valid_notes)
    Metrics.counter('filter_invalid_notes', 'out_of_range_pitch').inc()
  return key, ns.SerializeToString()
def filter_invalid_notes ( min_pitch , max_pitch , kv ) : key , ns_str = kv ns = note_seq . NoteSequence . FromString ( ns_str ) valid_notes = [ note for note in ns . notes if min_pitch <= note . pitch <= max_pitch ] if len ( valid_notes ) < len ( ns . notes ) : del ns . notes [ : ] ns . notes . extend ( valid_notes ) Metrics . counter ( 'filter_invalid_notes' , 'out_of_range_pitch' ) . inc ( ) return key , ns . SerializeToString ( )