code: def m21_to_stream(score, synth=ks_synth, beat=90, fdur=2., pad_dur=.5,
                    rate=lz.DEFAULT_SAMPLE_RATE):
    
    # Configuration
    s, Hz = lz.sHz(rate)
    step = 60. / beat * s
  
    # Creates a score from the music21 data
    score = reduce(operator.concat,
                   [[(pitch.frequency * Hz, # Note
                      note.offset * step, # Starting time
                      note.quarterLength * step, # Duration
                      Fermata in note.expressions) for pitch in note.pitches]
                                                   for note in score.flat.notes]
                  )
  
    # Mix all notes into song
    song = lz.Streamix()
    last_start = 0
    for freq, start, dur, has_fermata in score:
      delta = start - last_start
      if has_fermata:
        delta *= 2
      song.add(delta, synth(freq).limit(dur))
      last_start = start
  
    # Zero-padding and finishing
    song.add(dur + pad_dur * s, lz.Stream([]))
    return song
docs: Converts Music21 data to a Stream object.
  
    Parameters
    ----------
    score :
      A Music21 data, usually a music21.stream.Score instance.
    synth :
      A function that receives a frequency as input and should yield a Stream
      instance with the note being played.
    beat :
      The BPM (beats per minute) value to be used in playing.
    fdur :
      Relative duration of a fermata. For example, 1.0 ignores the fermata, and
      2.0 (default) doubles its duration.
    pad_dur :
      Duration in seconds, but not multiplied by ``s``, to be used as a
      zero-padding ending event (avoids clicks at the end when playing).
    rate :
      The sample rate, given in samples per second.