abjad.tweaks
|
Bundles |
|
Appends |
|
Bundled indicator. |
|
Tweak. |
- abjad.tweaks.bundle(indicator: Any, *tweaks: str | Tweak, comment: str | None = None, overwrite: bool = False, tag: Tag | None = None) Bundle [source]
Bundles
indicator
withtweaks
.Bundles indicator:
>>> staff = abjad.Staff("c'4 d' e' f'") >>> bundle = abjad.bundle( ... abjad.Articulation("."), ... r"- \tweak color #red", ... ) >>> abjad.attach(bundle, staff[0]) >>> abjad.show(staff)
Bundles existing bundle:
>>> staff = abjad.Staff("c'4 d' e' f'") >>> bundle = abjad.bundle(abjad.Articulation("."), r"- \tweak color #red") >>> bundle = abjad.bundle(bundle, r"- \tweak font-size 3") >>> abjad.attach(bundle, staff[0]) >>> abjad.show(staff)
Raises exception on duplicate attribute:
>>> bundle = abjad.bundle( ... abjad.Articulation("."), ... r"- \tweak color #blue", ... r"- \tweak color #red", ... ) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/trevor/Repositories/Projects/abjad/source/abjad/tweaks.py", line 323, in bundle raise Exception(message) Exception: duplicate 'color' attribute: Tweak(string='- \\tweak color #blue', i=None, tag=None) Tweak(string='- \\tweak color #red', i=None, tag=None)
Unless
overwrite=True
:>>> bundle = abjad.bundle( ... abjad.Articulation("."), ... r"- \tweak color #blue", ... r"- \tweak color #red", ... overwrite=True, ... ) >>> for _ in bundle.tweaks: ... _ ... Tweak(string='- \\tweak color #red', i=None, tag=None)
Also raises exception on duplicate attribute:
>>> bundle = abjad.bundle( ... abjad.Articulation("."), ... r"- \tweak color #blue", ... ) >>> bundle = abjad.bundle( ... bundle, ... r"- \tweak color #red", ... ) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/Users/trevor/Repositories/Projects/abjad/source/abjad/tweaks.py", line 337, in bundle raise Exception(message) Exception: duplicate 'color' attribute: OLD: Tweak(string='- \\tweak color #blue', i=None, tag=None) NEW: Tweak(string='- \\tweak color #red', i=None, tag=None)
Unless
overwrite=True
:>>> bundle = abjad.bundle( ... abjad.Articulation("."), ... r"- \tweak color #blue", ... ) >>> bundle = abjad.bundle( ... bundle, ... r"- \tweak color #red", ... overwrite=True, ... ) >>> for _ in bundle.tweaks: ... _ ... Tweak(string='- \\tweak color #red', i=None, tag=None)
- abjad.tweaks.tweak(indicator: Any, *tweaks: str | Tweak, overwrite: bool = False, tag: Tag | None = None) None [source]
Appends
tweaks
toindicator
.
- class abjad.tweaks.Bundle(indicator: Any, tweaks: tuple[Tweak, ...] = (), comment: str | None = None)[source]
Bundled indicator.
Raises exception on duplicate attributes:
>>> abjad.Bundle( ... indicator=abjad.Articulation("."), ... tweaks=( ... abjad.Tweak(r"- \tweak color #blue"), ... abjad.Tweak(r"- \tweak color #red"), ... ), ... ) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<string>", line 6, in __init__ File "/Users/trevor/Repositories/Projects/abjad/source/abjad/tweaks.py", line 106, in __post_init__ raise Exception(f"duplicate {attribute!r} attribute.") Exception: duplicate 'color' attribute.
get_attribute
(attribute)Gets tweak with
attribute
.remove
(tweak)Removes
tweak
from bundle and returns new bundle.- get_attribute(attribute: str) Tweak | None [source]
Gets tweak with
attribute
.>>> markup = abjad.Markup(r"\markup Allegro") >>> bundle = abjad.bundle( ... markup, ... r"- \tweak color #red", ... r"- \tweak font-size 3", ... ) >>> bundle.get_attribute("color") Tweak(string='- \\tweak color #red', i=None, tag=None)
>>> bundle.get_attribute("style") is None True
- remove(tweak: Tweak) Bundle [source]
Removes
tweak
from bundle and returns new bundle.>>> markup = abjad.Markup(r"\markup Allegro") >>> bundle_1 = abjad.bundle(markup, r"- \tweak color #red") >>> tweak = bundle_1.get_attribute("color")
>>> bundle_2 = bundle_1.remove(tweak) >>> bundle_2 Bundle(indicator=Markup(string='\\markup Allegro'), tweaks=(), comment=None)
>>> bundle_3 = abjad.bundle(bundle_2, r"- \tweak color #blue") >>> bundle_3.tweaks (Tweak(string='- \\tweak color #blue', i=None, tag=None),)