tag¶
Classes
Tag. |
- class abjad.tag.Tag(string='')[source]¶
Tag.
>>> abjad.Tag("YELLOW") Tag(string='YELLOW')
>>> abjad.Tag("YELLOW:RED") Tag(string='YELLOW:RED')
Raises exception on duplicate words in tag:
>>> abjad.Tag("YELLOW:RED:RED") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 4, in __init__ File "/Users/trevor/abjad/abjad/tag.py", line 49, in __post_init__ self.words() File "/Users/trevor/abjad/abjad/tag.py", line 196, in words raise Exception(f"duplicate words in tag: {self.string!r}") Exception: duplicate words in tag: 'YELLOW:RED:RED'
Raises exception on multiple only-edition tags:
>>> abjad.Tag("+SEGMENT:+PARTS") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 4, in __init__ File "/Users/trevor/abjad/abjad/tag.py", line 49, in __post_init__ self.words() File "/Users/trevor/abjad/abjad/tag.py", line 205, in words raise Exception(f"at most one only-edition tag: {only_edition_tags!r}.") Exception: at most one only-edition tag: ['+SEGMENT', '+PARTS'].
Raises exception on mixed only-edition / not-edition tags:
>>> abjad.Tag("+SEGMENT:-PARTS") Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 4, in __init__ File "/Users/trevor/abjad/abjad/tag.py", line 49, in __post_init__ self.words() File "/Users/trevor/abjad/abjad/tag.py", line 209, in words raise Exception(message) Exception: only-edition and not-edition forbidden in same tag: ['+SEGMENT'] / ['-PARTS']
Attributes Summary
Implement delattr(self, name).
Return self==value.
Return self>=value.
Return self>value.
Return hash(self).
Return self<=value.
Return self<value.
Return repr(self).
Implement setattr(self, name, value).
Appends
word
to tag.Gets edition tags in tag.
Inverts edition tags in tag.
Gets not-edition tags in tag.
Gets only-edition tag in tag.
Gets words.
Special methods
- overridden __delattr__(name)¶
Implement delattr(self, name).
- overridden __eq__(other)¶
Return self==value.
- overridden __ge__(other)¶
Return self>=value.
- overridden __gt__(other)¶
Return self>value.
- overridden __hash__()¶
Return hash(self).
- overridden __le__(other)¶
Return self<=value.
- overridden __lt__(other)¶
Return self<value.
- overridden __repr__()¶
Return repr(self).
- overridden __setattr__(name, value)¶
Implement setattr(self, name, value).
Methods
- append(word)[source]¶
Appends
word
to tag.>>> abjad.Tag("-PARTS").append(abjad.Tag("DEFAULT_CLEF")) Tag(string='-PARTS:DEFAULT_CLEF')
- Return type:
- editions()[source]¶
Gets edition tags in tag.
>>> abjad.Tag("FOO").editions() []
>>> abjad.Tag("+SEGMENT").only_edition() Tag(string='+SEGMENT')
>>> abjad.Tag("+SEGMENT:FOO").only_edition() Tag(string='+SEGMENT')
>>> abjad.Tag("-SEGMENT").editions() [Tag(string='-SEGMENT')]
>>> abjad.Tag("-SEGMENT:FOO").editions() [Tag(string='-SEGMENT')]
>>> abjad.Tag("-SEGMENT:-PARTS").editions() [Tag(string='-SEGMENT'), Tag(string='-PARTS')]
- invert_edition_tags()[source]¶
Inverts edition tags in tag.
>>> abjad.Tag("FOO").invert_edition_tags() Tag(string='FOO')
>>> abjad.Tag("FOO:-PARTS").invert_edition_tags() Tag(string='FOO:+PARTS')
>>> abjad.Tag("FOO:+PARTS").invert_edition_tags() Tag(string='FOO:-PARTS')
- Return type:
- not_editions()[source]¶
Gets not-edition tags in tag.
>>> abjad.Tag("FOO").not_editions() []
>>> abjad.Tag("-SEGMENT").not_editions() [Tag(string='-SEGMENT')]
>>> abjad.Tag("-SEGMENT:FOO").not_editions() [Tag(string='-SEGMENT')]
>>> abjad.Tag("-SEGMENT:-PARTS").not_editions() [Tag(string='-SEGMENT'), Tag(string='-PARTS')]
Functions
Activates |
|
Deactivates |
|
Double tags |
|
Left shifts tags in |
|
Removes all tags from |
- abjad.tag.activate(text, tag)[source]¶
Activates
tag
intext
.Writes (deactivated) tag with
"%@%"
prefix into LilyPond input:>>> staff = abjad.Staff("c'4 d' e' f'") >>> markup = abjad.Markup(r"\markup { \with-color #red Allegro }") >>> abjad.attach( ... markup, ... staff[0], ... deactivate=True, ... tag=abjad.Tag("RED_MARKUP"), ... )
>>> text = abjad.lilypond(staff, tags=True) >>> text = abjad.tag.left_shift_tags(text) >>> print(text) \new Staff { c'4 %! RED_MARKUP %@% - \markup { \with-color #red Allegro } d'4 e'4 f'4 }
>>> abjad.show(staff)
Activates tag:
>>> text, count, skipped = abjad.activate(text, abjad.Tag("RED_MARKUP")) >>> print(text) \new Staff { c'4 %! RED_MARKUP - \markup { \with-color #red Allegro } %@% d'4 e'4 f'4 }
>>> lines = [_.strip("\n") for _ in text.split("\n")] >>> string = "\n".join(lines) >>> lilypond_file = abjad.LilyPondFile([string]) >>> abjad.show(lilypond_file)
Deactivates tag again:
>>> text, count, skipped = abjad.deactivate(text, abjad.Tag("RED_MARKUP")) >>> print(text) \new Staff { c'4 %! RED_MARKUP %@% - \markup { \with-color #red Allegro } d'4 e'4 f'4 }
>>> lines = [_.strip("\n") for _ in text.split("\n")] >>> string = "\n".join(lines) >>> lilypond_file = abjad.LilyPondFile([string]) >>> abjad.show(lilypond_file)
Activates tag again:
>>> text, count, skipped = abjad.activate(text, abjad.Tag("RED_MARKUP")) >>> print(text) \new Staff { c'4 %! RED_MARKUP - \markup { \with-color #red Allegro } %@% d'4 e'4 f'4 }
>>> lines = [_.strip("\n") for _ in text.split("\n")] >>> string = "\n".join(lines) >>> lilypond_file = abjad.LilyPondFile([string]) >>> abjad.show(lilypond_file)
Tags can toggle indefinitely.
Returns (text, count, skipped) triple.
Count gives number of activated tags.
Skipped gives number of skipped tags.
- abjad.tag.deactivate(text, tag, prepend_empty_chord=False)[source]¶
Deactivates
tag
intext
.Writes (active) tag into LilyPond input:
>>> staff = abjad.Staff("c'4 d' e' f'") >>> string = r"\markup { \with-color #red Allegro }" >>> markup = abjad.Markup(string) >>> abjad.attach( ... markup, ... staff[0], ... tag=abjad.Tag("RED_MARKUP"), ... )
>>> text = abjad.lilypond(staff, tags=True) >>> text = abjad.tag.left_shift_tags(text) >>> print(text) \new Staff { c'4 %! RED_MARKUP - \markup { \with-color #red Allegro } d'4 e'4 f'4 }
>>> abjad.show(staff)
Deactivates tag:
>>> text = abjad.lilypond(staff, tags=True) >>> text, count, skipped = abjad.deactivate(text, abjad.Tag("RED_MARKUP")) >>> print(text) \new Staff { c'4 %! RED_MARKUP %%% - \markup { \with-color #red Allegro } d'4 e'4 f'4 }
>>> lines = [_.strip("\n") for _ in text.split("\n")] >>> string = "\n".join(lines) >>> lilypond_file = abjad.LilyPondFile([string]) >>> abjad.show(lilypond_file)
Activates tag again:
>>> text, count, skipped = abjad.activate(text, abjad.Tag("RED_MARKUP")) >>> print(text) \new Staff { c'4 %! RED_MARKUP - \markup { \with-color #red Allegro } d'4 e'4 f'4 }
>>> lines = [_.strip("\n") for _ in text.split("\n")] >>> string = "\n".join(lines) >>> lilypond_file = abjad.LilyPondFile([string]) >>> abjad.show(lilypond_file)
Deactivates tag again:
>>> text, count, skipped = abjad.deactivate(text, abjad.Tag("RED_MARKUP")) >>> print(text) \new Staff { c'4 %! RED_MARKUP %%% - \markup { \with-color #red Allegro } d'4 e'4 f'4 }
>>> lines = [_.strip("\n") for _ in text.split("\n")] >>> string = "\n".join(lines) >>> lilypond_file = abjad.LilyPondFile([string]) >>> abjad.show(lilypond_file)
Tags can toggle indefinitely.