music21.style¶
The style module represents information about the style of a Note, Accidental, etc. such that precise positioning information, layout, size, etc. can be specified.
BezierStyle¶
-
class
music21.style.BezierStyle¶ From the MusicXML Definition.
BezierStyle bases
BezierStyle read/write properties
Read/write properties inherited from Style:
Style¶
-
class
music21.style.Style¶ A style object is a lightweight object that keeps track of information about the look of an object.
>>> st = style.Style() >>> st.units 'tenths' >>> st.absoluteX is None True
>>> st.absoluteX = 20.4 >>> st.absoluteX 20.4
Style read/write properties
-
Style.absoluteY¶ Get or set the vertical position, where 0 is the top line of the staff and units are in 10ths of a staff space.
Other legal positions are ‘above’ and ‘below’ which are synonyms for 10 and -70 respectively (for 5-line staves; other staves are not yet implemented)
>>> te = style.Style() >>> te.absoluteY = 10 >>> te.absoluteY 10
>>> te.absoluteY = 'below' >>> te.absoluteY -70
-
Style.enclosure¶ Get or set the enclosure. Valid names are rectangle, square, oval, circle, bracket, triangle, diamond, or None.
>>> tst = style.TextStyle() >>> tst.enclosure = None >>> tst.enclosure = 'rectangle' >>> tst.enclosure 'rectangle'
StyleMixin¶
-
class
music21.style.StyleMixin¶ Mixin for any class that wants to support style and editorial, since several non-music21 objects, such as Lyrics and Accidentals will support Style.
Not used by Music21Objects because of the added trouble in copying etc. so there is code duplication with base.Music21Object
StyleMixin bases
StyleMixin read-only properties
-
StyleMixin.hasEditorialInformation¶ Returns True if there is a
Editorialobject already associated with this object, False otherwise.Calling .style on an object will always create a new Style object, so even though a new Style object isn’t too expensive to create, this property helps to prevent creating new Styles more than necessary.
>>> acc = pitch.Accidental('#') >>> acc.hasEditorialInformation False >>> acc.editorial <music21.editorial.Editorial {} > >>> acc.hasEditorialInformation True
-
StyleMixin.hasStyleInformation¶ Returns True if there is a
Styleobject already associated with this object, False otherwise.Calling .style on an object will always create a new Style object, so even though a new Style object isn’t too expensive to create, this property helps to prevent creating new Styles more than necessary.
>>> lObj = note.Lyric('hello') >>> lObj.hasStyleInformation False >>> lObj.style <music21.style.TextStyle object at 0x10b0a2080> >>> lObj.hasStyleInformation True
StyleMixin read/write properties
-
StyleMixin.editorial¶ a
Editorialobject that stores editorial information (comments, footnotes, harmonic information, ficta).Created automatically as needed:
>>> acc = pitch.Accidental() >>> acc.editorial <music21.editorial.Editorial {} > >>> acc.editorial.ficta = pitch.Accidental('sharp') >>> acc.editorial.ficta <accidental sharp> >>> acc.editorial <music21.editorial.Editorial {'ficta': <accidental sharp>} >
-
StyleMixin.style¶ Returns (or Creates and then Returns) the Style object associated with this object, or sets a new style object. Different classes might use different Style objects because they might have different style needs (such as text formatting or bezier positioning)
Eventually will also query the groups to see if they have any styles associated with them.
>>> acc = pitch.Accidental() >>> st = acc.style >>> st <music21.style.TextStyle object at 0x10ba96208> >>> st.absoluteX = 20.0 >>> st.absoluteX 20.0 >>> acc.style = style.TextStyle() >>> acc.style.absoluteX is None True
TextStyle¶
-
class
music21.style.TextStyle¶ A Style object that also includes text formatting.
TextStyle bases
TextStyle read/write properties
-
TextStyle.alignHorizontal¶ Get or set the horizontal alignment. Valid values are left, right, center
>>> te = style.TextStyle() >>> te.alignHorizontal = 'right' >>> te.alignHorizontal 'right'
-
TextStyle.alignVertical¶ Get or set the vertical align. Valid values are top, middle, bottom, and baseline
>>> te = style.TextStyle() >>> te.alignVertical = 'top' >>> te.alignVertical 'top'
-
TextStyle.fontFamily¶ Returns a list of font family names associated with the style, or sets the font family name list.
If a single string is passed then it is converted to a list.
>>> ts = style.TextStyle() >>> ff = ts.fontFamily >>> ff [] >>> ff.append('Times') >>> ts.fontFamily ['Times'] >>> ts.fontFamily.append('Garamond') >>> ts.fontFamily ['Times', 'Garamond'] >>> ts.fontFamily = 'Helvetica, sans-serif' >>> ts.fontFamily ['Helvetica', 'sans-serif']
-
TextStyle.fontSize¶ Get or set the size. Best, an int or float, but also a css font size
>>> tst = style.TextStyle() >>> tst.fontSize = 20 >>> tst.fontSize 20
-
TextStyle.fontStyle¶ Get or set the style, as normal, italic, bold, and bolditalic.
>>> tst = style.TextStyle() >>> tst.fontStyle = 'bold' >>> tst.fontStyle 'bold'
-
TextStyle.fontWeight¶ Get or set the weight, as normal, or bold.
>>> tst = style.TextStyle() >>> tst.fontWeight = 'bold' >>> tst.fontWeight 'bold'
-
TextStyle.justify¶ Get or set the justification. Valid values are left, center, right, and full (the last not supported by MusicXML)
>>> tst = style.TextStyle() >>> tst.justify = 'center' >>> tst.justify 'center'
-
TextStyle.letterSpacing¶ Get or set the letter spacing.
>>> tst = style.TextStyle() >>> tst.letterSpacing = 20 >>> tst.letterSpacing 20.0 >>> tst.letterSpacing = 'normal'
Read/write properties inherited from Style: