Previous topic

music21.counterpoint.species

Next topic

music21.documentation.library.cleaners

Table Of Contents

Table Of Contents

This Page

music21.derivation

This module defines objects for tracking the derivation of one Stream from another.

Derivation

class music21.derivation.Derivation(container=None)

A Derivation object keeps track of which Streams

>>> import copy
>>> s1 = stream.Stream()
>>> s2 = stream.Stream()
>>> d1 = derivation.Derivation(s1)
>>> d1.setAncestor(s2)
>>> d1.getAncestor() is s2
True
>>> d1.getContainer() is s1
True
>>> d2 = copy.deepcopy(d1)
>>> d2.getAncestor() is s2
True
>>> d1.setMethod('measure')
>>> d1.getMethod()
'measure'

Derivation bases

Derivation methods

Derivation.getAncestor()
Derivation.getContainer()
Derivation.getMethod()

Returns the string of the method that was used to generate this Stream. Note that it’s identical to the property derivationMethod on a Stream, so no need for any but the most advanced usages.

>>> s = stream.Stream()
>>> s.derivationMethod is s._derivation.getMethod()
True
>>> s.derivationMethod is None
True
>>> sNotes = s.notes
>>> sNotes.derivationMethod
'notes'
>>> sNotes._derivation.getMethod()
'notes'
Derivation.setAncestor(ancestor)
Derivation.setContainer(container)
Derivation.setMethod(method)

Sets a string identifying how the object was derived.

Some examples are ‘getElementsByClass’ etc.

>>> s = stream.Stream()
>>> s.append(clef.TrebleClef())
>>> s.append(note.Note())
>>> sNotes = s.notes
>>> sNotes._derivation
<music21.derivation.Derivation object at 0x...>
>>> derived = sNotes._derivation
>>> derived.getMethod()
'notes'
>>> derived.setMethod('blah')
>>> derived.getMethod()
'blah'
>>> sNotes.derivationMethod
'blah'
Derivation.unwrapWeakref()

Unwrap any and all weakrefs stored.

>>> s1 = stream.Stream()
>>> s2 = stream.Stream()
>>> d1 = derivation.Derivation(s1) # sets container
>>> d1.setAncestor(s2)
>>> common.isWeakref(d1._container)
True
>>> d1.unwrapWeakref()
>>> common.isWeakref(d1._container)
False
Derivation.wrapWeakref()

Wrap all stored objects with weakrefs.