Spanner¶
- class maelzel.core.symbols.Spanner(kind='start', uuid='', linetype='solid', placement='', color='')[source]¶
Bases:
Symbol
A Spanner is a line/curve between two anchors (notes/chords/rests)
Spanners always come in pairs start/end.
Example
>>> from maelzel.core import * >>> from maelzel.core import symbols >>> chain = Chain(["C4:0.5", "D4:1", "E4:0.5"]) >>> slur = symbols.Slur() >>> chain[0].addSymbol(slur) >>> chain[2].addSymbol(slur.makeEndSpanner())
Or you can use the
.bind
method which is a shortcut:>>> symbols.Slur().bind(chain[0], chain[2])
Attributes Summary
Methods Summary
bind
(startobj, endobj)Bind a Spanner to two notes/chords
makeEndSpanner
([anchor])Creates the end spanner for an already existing start spanner
setAnchor
(obj)Set the anchor for this spanner.
setPartnerSpanner
(other)Set the given spanner as the partner spanner of self (and self as partner of other)
Attributes Documentation
- appliesToRests = True¶
- exclusive = False¶
Methods Documentation
- bind(startobj, endobj)[source]¶
Bind a Spanner to two notes/chords
- Parameters:
startobj (event.MEvent) – start anchor object
endobj (event.MEvent) – end anchor object
- Return type:
None
Example
>>> from maelzel.core import * >>> chain = Chain(["4E:1", "4F:1", "4G:1"]) # slur the first two notes of the chain, customizing the line-type >>> Slur(linetype='dashed').bind(chain[0], chain[1]) # The same can be achieved as: >>> chain[0].addSpanner(Slur(linetype='dashed'), chain[1])
- makeEndSpanner(anchor=None)[source]¶
Creates the end spanner for an already existing start spanner
start and end spanner share the same uuid and have a ref to each other, allowing each of the spanners to access their twin. As each spanner also holds a ref to their anchor, the anchored events can be made aware of each other.
- Parameters:
anchor (event.MEvent) – the event to which the end spanner is anchored to.
- Return type:
Self
- Returns:
the created spanner. This is a copy of the start spanner in every way with the only difference that
kind='end'
- setAnchor(obj)[source]¶
Set the anchor for this spanner.
This is called by :meth:
MusicObj.setSymbol
or by :meth:Spanner.bind
to set the anchor of this spanner. A User should not normally call this method- Parameters:
obj (event.MEvent) – the object this spanner is anchored to, either as start or end
- Return type:
None