.. _usersGuide_46_streams3: .. WARNING: DO NOT EDIT THIS FILE: AUTOMATICALLY GENERATED. PLEASE EDIT THE .py FILE DIRECTLY. User's Guide, Chapter 46: Streams 3: Manipulation, inPlace, and deepcopy ======================================================================== Just getting started here... Replace all consecutive notes of a Stream with intervals while maintaining the hierarchy ---------------------------------------------------------------------------------------- .. code:: ipython3 from music21 import * import copy def intervalStream(inputStream): out = copy.deepcopy(inputStream) for n in out[note.Note]: nNext = n.next(note.GeneralNote) if nNext is None or not nNext.isNote: continue # Rests, Chords, etc. n.activeSite.replace(n, interval.Interval(n, nNext)) for other in out.recurse().getElementsNotOfClass([interval.Interval, stream.Stream]): other.activeSite.remove(other) # get rid of everything that is not an Interval or Stream return out .. code:: ipython3 b = corpus.parse('bwv66.6') ints = intervalStream(b.measures(0, 4)) ints.show('text') .. parsed-literal:: :class: ipython-result {0.0} {0.0} {0.0} {0.5} {1.0} {0.0} {1.0} {2.0} {3.0} {5.0} {0.0} {1.0} {2.0} {3.0} {9.0} {0.0} {0.5} {1.0} {2.0} {3.0} {13.0} {0.0} {1.0} {2.0} {3.0} {0.0} {0.0} {0.0} {1.0} {0.0} {1.0} {2.0} {3.0} {5.0} {0.0} {0.5} {1.0} {2.0} {3.0} {9.0} {0.0} {0.5} {1.0} {2.0} {3.0} {13.0} {0.0} {1.0} {2.0} {3.0} {0.0} {0.0} {0.0} {0.5} {1.0} {0.0} {1.0} {2.0} {3.0} {5.0} {0.0} {0.5} {1.0} {1.5} {2.0} {3.0} {9.0} {0.0} {0.5} {1.0} {1.5} {2.0} {3.0} {13.0} {0.0} {1.0} {2.0} {2.5} {3.0} {0.0} {0.0} {0.0} {0.5} {1.0} {0.0} {1.0} {2.0} {3.0} {5.0} {0.0} {0.5} {1.0} {2.0} {3.0} {9.0} {0.0} {0.5} {1.0} {2.0} {3.0} {13.0} {0.0} {0.5} {1.0} {1.5} {2.0} {2.5} {3.0}