.. _moduleTimespansCore:

music21.timespans.core
======================

.. WARNING: DO NOT EDIT THIS FILE:
   AUTOMATICALLY GENERATED.
   PLEASE EDIT THE .py FILE DIRECTLY.

.. automodule:: music21.timespans.core

AVLNode
-------

.. autoclass:: music21.timespans.core.AVLNode

.. rubric:: :class:`~music21.timespans.core.AVLNode` bases

- :class:`~music21.common.objects.SlottedObject`

.. rubric:: :class:`~music21.timespans.core.AVLNode` methods

.. automethod:: music21.timespans.core.AVLNode.debug

.. automethod:: music21.timespans.core.AVLNode.moveAttributes

.. automethod:: music21.timespans.core.AVLNode.rebalance

.. automethod:: music21.timespans.core.AVLNode.rotateLeftLeft

.. automethod:: music21.timespans.core.AVLNode.rotateLeftRight

.. automethod:: music21.timespans.core.AVLNode.rotateRightLeft

.. automethod:: music21.timespans.core.AVLNode.rotateRightRight

.. automethod:: music21.timespans.core.AVLNode.update

.. rubric:: :class:`~music21.timespans.core.AVLNode` instance variables

.. attribute:: AVLNode.balance

	
	Returns the current state of the difference in heights of the
	two subtrees rooted on this node.
	
	This attribute is used to help balance the AVL tree.
	
	>>> score = timespans.makeExampleScore()
	>>> tree = timespans.streamToTimespanTree(score, flatten=True,
	...                    classList=(note.Note, chord.Chord))
	>>> print(tree.debug())
	<Node: Start:3.0 Indices:(0:5:6:12) Length:{1}>
	L: <Node: Start:1.0 Indices:(0:2:3:5) Length:{1}>
	L: <Node: Start:0.0 Indices:(0:0:2:2) Length:{2}>
	R: <Node: Start:2.0 Indices:(3:3:5:5) Length:{2}>
	R: <Node: Start:5.0 Indices:(6:8:9:12) Length:{1}>
	L: <Node: Start:4.0 Indices:(6:6:8:8) Length:{2}>
	R: <Node: Start:6.0 Indices:(9:9:11:12) Length:{2}>
	R: <Node: Start:7.0 Indices:(11:11:12:12) Length:{1}>
	
	
	This tree has one more depth on the right than on the left
	
	>>> tree.rootNode.balance
	1
	
	
	The leftChild of the rootNote is perfectly balanced, while the rightChild is off by
	one (acceptable).
	
	>>> tree.rootNode.leftChild.balance
	0
	>>> tree.rootNode.rightChild.balance
	1
	
	
	The rightChild's children are also (acceptably) unbalanced:
	
	>>> tree.rootNode.rightChild.leftChild.balance
	0
	>>> tree.rootNode.rightChild.rightChild.balance
	1
	
	You should never see a balance other than 1, -1, or 0.  If you do then
	something has gone wrong.
	

.. attribute:: AVLNode.height

	
	The height of the subtree rooted on this node.
	
	This property is used to help balance the AVL tree.
	
	>>> score = timespans.makeExampleScore()
	>>> tree = timespans.streamToTimespanTree(score, flatten=True,
	...              classList=(note.Note, chord.Chord))
	>>> print(tree.debug())
	<Node: Start:3.0 Indices:(0:5:6:12) Length:{1}>
	L: <Node: Start:1.0 Indices:(0:2:3:5) Length:{1}>
	L: <Node: Start:0.0 Indices:(0:0:2:2) Length:{2}>
	R: <Node: Start:2.0 Indices:(3:3:5:5) Length:{2}>
	R: <Node: Start:5.0 Indices:(6:8:9:12) Length:{1}>
	L: <Node: Start:4.0 Indices:(6:6:8:8) Length:{2}>
	R: <Node: Start:6.0 Indices:(9:9:11:12) Length:{2}>
	R: <Node: Start:7.0 Indices:(11:11:12:12) Length:{1}>
	
	>>> tree.rootNode.height
	3
	
	>>> tree.rootNode.rightChild.height
	2
	
	>>> tree.rootNode.rightChild.rightChild.height
	1
	
	>>> tree.rootNode.rightChild.rightChild.rightChild.height
	0
	
	Once you hit a height of zero, then the next child on either size should be None
	
	>>> print(tree.rootNode.rightChild.rightChild.rightChild.rightChild)
	None
	

.. attribute:: AVLNode.leftChild

	
	The left child of this node.
	
	After setting the left child you need to do a node update. with node.update()
	
	>>> score = timespans.makeExampleScore()
	>>> tree = timespans.streamToTimespanTree(score, flatten=True,
	...           classList=(note.Note, chord.Chord))
	>>> print(tree.rootNode.debug())
	<Node: Start:3.0 Indices:(0:5:6:12) Length:{1}>
	L: <Node: Start:1.0 Indices:(0:2:3:5) Length:{1}>
	L: <Node: Start:0.0 Indices:(0:0:2:2) Length:{2}>
	R: <Node: Start:2.0 Indices:(3:3:5:5) Length:{2}>
	R: <Node: Start:5.0 Indices:(6:8:9:12) Length:{1}>
	L: <Node: Start:4.0 Indices:(6:6:8:8) Length:{2}>
	R: <Node: Start:6.0 Indices:(9:9:11:12) Length:{2}>
	R: <Node: Start:7.0 Indices:(11:11:12:12) Length:{1}>
	
	>>> print(tree.rootNode.leftChild.debug())
	<Node: Start:1.0 Indices:(0:2:3:5) Length:{1}>
	L: <Node: Start:0.0 Indices:(0:0:2:2) Length:{2}>
	R: <Node: Start:2.0 Indices:(3:3:5:5) Length:{2}>
	

.. attribute:: AVLNode.position

	
	The position of this node.
	
	>>> score = timespans.makeExampleScore()
	>>> tree = timespans.streamToTimespanTree(score, flatten=True,
	...            classList=(note.Note, chord.Chord))
	>>> print(tree.rootNode.debug())
	<Node: Start:3.0 Indices:(0:5:6:12) Length:{1}>
	L: <Node: Start:1.0 Indices:(0:2:3:5) Length:{1}>
	L: <Node: Start:0.0 Indices:(0:0:2:2) Length:{2}>
	R: <Node: Start:2.0 Indices:(3:3:5:5) Length:{2}>
	R: <Node: Start:5.0 Indices:(6:8:9:12) Length:{1}>
	L: <Node: Start:4.0 Indices:(6:6:8:8) Length:{2}>
	R: <Node: Start:6.0 Indices:(9:9:11:12) Length:{2}>
	R: <Node: Start:7.0 Indices:(11:11:12:12) Length:{1}>
	
	>>> tree.rootNode.position
	3.0
	
	>>> tree.rootNode.leftChild.position
	1.0
	
	>>> tree.rootNode.rightChild.position
	5.0
	

.. attribute:: AVLNode.rightChild

	
	The right child of this node.
	
	After setting the right child you need to do a node update. with node.update()
	
	>>> score = timespans.makeExampleScore()
	>>> tree = timespans.streamToTimespanTree(score, flatten=True,
	...             classList=(note.Note, chord.Chord))
	>>> print(tree.rootNode.debug())
	<Node: Start:3.0 Indices:(0:5:6:12) Length:{1}>
	L: <Node: Start:1.0 Indices:(0:2:3:5) Length:{1}>
	L: <Node: Start:0.0 Indices:(0:0:2:2) Length:{2}>
	R: <Node: Start:2.0 Indices:(3:3:5:5) Length:{2}>
	R: <Node: Start:5.0 Indices:(6:8:9:12) Length:{1}>
	L: <Node: Start:4.0 Indices:(6:6:8:8) Length:{2}>
	R: <Node: Start:6.0 Indices:(9:9:11:12) Length:{2}>
	R: <Node: Start:7.0 Indices:(11:11:12:12) Length:{1}>
	
	>>> print(tree.rootNode.rightChild.debug())
	<Node: Start:5.0 Indices:(6:8:9:12) Length:{1}>
	L: <Node: Start:4.0 Indices:(6:6:8:8) Length:{2}>
	R: <Node: Start:6.0 Indices:(9:9:11:12) Length:{2}>
	R: <Node: Start:7.0 Indices:(11:11:12:12) Length:{1}>
	
	>>> print(tree.rootNode.rightChild.rightChild.debug())
	<Node: Start:6.0 Indices:(9:9:11:12) Length:{2}>
	R: <Node: Start:7.0 Indices:(11:11:12:12) Length:{1}>
	
	>>> print(tree.rootNode.rightChild.rightChild.rightChild.debug())
	<Node: Start:7.0 Indices:(11:11:12:12) Length:{1}>
	

AVLTree
-------

.. autoclass:: music21.timespans.core.AVLTree

.. rubric:: :class:`~music21.timespans.core.AVLTree` methods

.. automethod:: music21.timespans.core.AVLTree.debug

.. automethod:: music21.timespans.core.AVLTree.getNodeAfter

.. automethod:: music21.timespans.core.AVLTree.getNodeBefore

.. automethod:: music21.timespans.core.AVLTree.getNodeByPosition

.. automethod:: music21.timespans.core.AVLTree.getPositionAfter

.. automethod:: music21.timespans.core.AVLTree.getPositionBefore

.. automethod:: music21.timespans.core.AVLTree.insertAtPosition

.. automethod:: music21.timespans.core.AVLTree.removeNode
