Skip to content

Commit

Permalink
2021-10 update 2. (Abjad#1367)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: all abjad.Markup() must now initialize with literal=True.

    OLD: abjad.Markup("Allegro")
    NEW: abjad.Markup(r"\markup Allegro", literal=True)

    Markup now formats on a single line:

        >>> staff = abjad.Staff("c'4 d' e' f'")
        >>> markup = abjad.Markup(r'\bold Allegro')
        >>> abjad.attach(markup, staff[0])
        >>> string = abjad.lilypond(staff)

        OLD:

            >>> print(string)
            \new Staff
            {
                c'4
                - \markup {
                    \bold
                    Allegro
                    }
                d'4
                e'4
                f'4
            }

        NEW:

            >>> print(string)
            \new Staff
            {
                c'4
                - \markup { \bold Allegro }
                d'4
                e'4
                f'4
            }

    * Removed abjad.Markup.__add__(), __radd__()
    * Removed abjad.Markup.postscript()
    * Removed abjad.markups.abjad_metronome_mark()

REMOVED:

    * Removed abjad.OrderedDict; use dict() instead; Closes Abjad#1366.
  • Loading branch information
trevorbaca authored Oct 12, 2021
1 parent 9793fba commit 63520b2
Show file tree
Hide file tree
Showing 52 changed files with 1,498 additions and 2,426 deletions.
2 changes: 0 additions & 2 deletions abjad/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,6 @@
from .metricmodulation import MetricModulation
from .new import new
from .obgc import OnBeatGraceContainer, on_beat_grace_container
from .ordereddict import OrderedDict
from .overrides import (
IndexedTweakManager,
IndexedTweakManagers,
Expand Down Expand Up @@ -506,7 +505,6 @@
"Offset",
"OffsetCounter",
"OnBeatGraceContainer",
"OrderedDict",
"Ottava",
"OverrideInterface",
"PackageGitCommitToken",
Expand Down
22 changes: 13 additions & 9 deletions abjad/bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,9 +1082,13 @@ def detach(argument, target=None, by_id=False):
Consider the three document-specifier markups below:
>>> markup_1 = abjad.Markup('tutti', direction=abjad.Up)
>>> markup_2 = abjad.Markup('with the others', direction=abjad.Up)
>>> markup_3 = abjad.Markup('with the others', direction=abjad.Up)
>>> markup_1 = abjad.Markup(r'\markup tutti', direction=abjad.Up, literal=True)
>>> markup_2 = abjad.Markup(
... r'\markup { with the others }', direction=abjad.Up, literal=True,
... )
>>> markup_3 = abjad.Markup(
... r'\markup { with the others }', direction=abjad.Up, literal=True,
... )
Markups two and three compare equal:
Expand Down Expand Up @@ -1116,7 +1120,7 @@ def detach(argument, target=None, by_id=False):
{
c'4
%! +SCORE
^ \markup { tutti }
^ \markup tutti
%! +PARTS_VIOLIN_1
%@% ^ \markup { with the others }
%! +PARTS_VIOLIN_2
Expand All @@ -1133,7 +1137,7 @@ def detach(argument, target=None, by_id=False):
because detach tests for equality to input argument:
>>> abjad.detach(markup_2, staff[0])
(Markup(contents=['with the others'], direction=Up), Markup(contents=['with the others'], direction=Up))
(Markup(contents=['\\markup { with the others }'], direction=Up, literal=True), Markup(contents=['\\markup { with the others }'], direction=Up, literal=True))
>>> abjad.show(staff) # doctest: +SKIP
Expand All @@ -1143,7 +1147,7 @@ def detach(argument, target=None, by_id=False):
{
c'4
%! +SCORE
^ \markup { tutti }
^ \markup tutti
d'4
e'4
f'4
Expand Down Expand Up @@ -1173,7 +1177,7 @@ def detach(argument, target=None, by_id=False):
{
c'4
%! +SCORE
^ \markup { tutti }
^ \markup tutti
%! +PARTS_VIOLIN_1
%@% ^ \markup { with the others }
%! +PARTS_VIOLIN_2
Expand All @@ -1188,7 +1192,7 @@ def detach(argument, target=None, by_id=False):
us what we want:
>>> abjad.detach(markup_2, staff[0], by_id=True)
(Markup(contents=['with the others'], direction=Up),)
(Markup(contents=['\\markup { with the others }'], direction=Up, literal=True),)
>>> abjad.show(staff) # doctest: +SKIP
Expand All @@ -1198,7 +1202,7 @@ def detach(argument, target=None, by_id=False):
{
c'4
%! +SCORE
^ \markup { tutti }
^ \markup tutti
%! +PARTS_VIOLIN_2
%@% ^ \markup { with the others }
d'4
Expand Down
4 changes: 3 additions & 1 deletion abjad/contextmanagers.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,8 @@ class ForbidUpdate(ContextManager):
>>> string = abjad.lilypond(staff)
>>> print(string)
\new Staff {
\new Staff
{
<c' e'>8
<d' fs'>8
<d' fs'>2
Expand Down Expand Up @@ -449,6 +450,7 @@ class RedirectedStreams(ContextManager):
>>> string_io.close()
>>> print(result)
hello, world!
<BLANKLINE>
Redirected streams context manager is immutable.
"""
Expand Down
26 changes: 6 additions & 20 deletions abjad/deprecated.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ def add_final_markup(score, markup, extra_offset=None) -> None:
>>> score = abjad.Score([staff])
>>> place = "Bremen - Boston - LA."
>>> date = "July 2010 - May 2011."
>>> string = rf'\italic \right-column {{ "{place}" "{date}" }}'
>>> markup = abjad.Markup(string, direction=abjad.Down)
>>> string = rf'\markup \italic \right-column {{ "{place}" "{date}" }}'
>>> markup = abjad.Markup(string, direction=abjad.Down, literal=True)
>>> markup = abjad.deprecated.add_final_markup(
... score,
... markup,
Expand All @@ -101,14 +101,7 @@ def add_final_markup(score, markup, extra_offset=None) -> None:
e'4
\once \override TextScript.extra-offset = #'(0.5 . -2)
f'4
_ \markup {
\italic
\right-column
{
"Bremen - Boston - LA."
"July 2010 - May 2011."
}
}
_ \markup \italic \right-column { "Bremen - Boston - LA." "July 2010 - May 2011." }
}
>>
Expand All @@ -121,8 +114,8 @@ def add_final_markup(score, markup, extra_offset=None) -> None:
>>> score = abjad.Score([staff])
>>> place = "Bremen - Boston - LA."
>>> date = "July 2010 - May 2011."
>>> string = rf'\italic \right-column {{ "{place}" "{date}" }}'
>>> markup = abjad.Markup(string, direction=abjad.Down)
>>> string = rf'\markup \italic \right-column {{ "{place}" "{date}" }}'
>>> markup = abjad.Markup(string, direction=abjad.Down, literal=True)
>>> markup = abjad.deprecated.add_final_markup(
... score,
... markup,
Expand All @@ -144,14 +137,7 @@ def add_final_markup(score, markup, extra_offset=None) -> None:
f'4
\once \override MultiMeasureRestText.extra-offset = #'(14.5 . -2)
R1
_ \markup {
\italic
\right-column
{
"Bremen - Boston - LA."
"July 2010 - May 2011."
}
}
_ \markup \italic \right-column { "Bremen - Boston - LA." "July 2010 - May 2011." }
}
>>
Expand Down
11 changes: 3 additions & 8 deletions abjad/format.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import collections
import dataclasses
import importlib
import inspect
Expand Down Expand Up @@ -44,11 +43,7 @@ def _dispatch_formatting(argument, as_storage_format=True, is_indented=True):
return list(pieces)
elif isinstance(argument, (list, tuple)):
return _format_sequence(argument, as_storage_format, is_indented)
elif isinstance(argument, collections.OrderedDict):
return _format_ordered_mapping(argument, as_storage_format, is_indented)
elif hasattr(argument, "_collection") and isinstance(
argument._collection, collections.OrderedDict
):
elif hasattr(argument, "_collection") and isinstance(argument._collection, dict):
return _format_ordered_mapping(argument, as_storage_format, is_indented)
elif isinstance(argument, dict):
return _format_mapping(argument, as_storage_format, is_indented)
Expand Down Expand Up @@ -517,7 +512,7 @@ def get_template_dict(argument):
template_names.extend(signature_keyword_names)
template_names.extend(keyword_names)
template_names = sorted(set(template_names))
template_dict = collections.OrderedDict()
template_dict = dict()
for name in template_names:
template_dict[name] = _get(argument, name)
return template_dict
Expand All @@ -535,7 +530,7 @@ def storage(argument):
"""
Gets storage format of ``argument``.
"""
if isinstance(argument, dict) and not isinstance(argument, collections.OrderedDict):
if isinstance(argument, dict):
pieces = _dispatch_formatting(argument)
pieces[-1] = pieces[-1] + "\n"
pieces.append(")")
Expand Down
6 changes: 2 additions & 4 deletions abjad/get.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,10 +214,8 @@ def annotation_wrappers(argument):
name='cello',
short_name='vc.',
markup=abjad.Markup(
contents=['Cello'],
),
short_markup=abjad.Markup(
contents=['Vc.'],
contents=['\\markup Cello'],
literal=True,
),
allowable_clefs=('bass', 'tenor', 'treble'),
context='Staff',
Expand Down
23 changes: 13 additions & 10 deletions abjad/illustrators.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from . import deprecated, enums, get
from . import iterate as iterate_
from . import markups as _markups
from . import overrides
from . import score as _score
from . import selection as _selection
Expand All @@ -14,10 +15,8 @@
from .lilypondfile import Block, LilyPondFile
from .lilypondformat import lilypond
from .makers import NoteMaker
from .markups import Markup, Postscript
from .metricmodulation import MetricModulation
from .new import new
from .ordereddict import OrderedDict
from .pitch.PitchRange import PitchRange
from .pitch.pitches import NamedPitch
from .pitch.segments import PitchClassSegment, PitchSegment
Expand Down Expand Up @@ -45,7 +44,11 @@ def _illustrate_markup_maker(argument, **keywords):


def _illustrate_postscript(postscript):
markup = Markup.postscript(postscript)
if isinstance(postscript, _markups.Postscript):
postscript = str(postscript)
assert isinstance(postscript, str)
string = "\n".join([r"\markup", r"\postscript", '#"', postscript, '"'])
markup = _markups.Markup(string, literal=True)
return _illustrate_markup(markup)


Expand Down Expand Up @@ -158,7 +161,7 @@ def _illustrate_pitch_class_segment(
notes.append(note)
markup = None
if isinstance(figure_name, str):
figure_name = Markup(figure_name)
figure_name = _markups.Markup(rf"\markup {figure_name}", literal=True)
if figure_name is not None:
markup = figure_name
if markup is not None:
Expand Down Expand Up @@ -202,13 +205,13 @@ def _illustrate_timespan(timespan):
return _illustrate_markup_maker(timespans)


_class_to_method = OrderedDict(
_class_to_method = dict(
[
(_score.Component, _illustrate_component),
(Markup, _illustrate_markup),
(_markups.Markup, _illustrate_markup),
(MetricModulation, _illustrate_metric_modulation),
(_timespan.OffsetCounter, _illustrate_markup_maker),
(Postscript, _illustrate_postscript),
(_markups.Postscript, _illustrate_postscript),
(PitchRange, _illustrate_pitch_range),
(PitchClassSet, _illustrate_pitch_class_set),
(PitchSegment, _illustrate_pitch_segment),
Expand All @@ -230,14 +233,14 @@ def attach_markup_struts(lilypond_file):
"""
rhythmic_staff = lilypond_file[_score.Score][-1]
first_leaf = get.leaf(rhythmic_staff, 0)
markup = Markup(r"\markup I", direction=enums.Up, literal=True)
markup = _markups.Markup(r"\markup I", direction=enums.Up, literal=True)
attach(markup, first_leaf)
overrides.tweak(markup).staff_padding = 11
overrides.tweak(markup).transparent = "##t"
duration = get.duration(rhythmic_staff)
if Duration(6, 4) < duration:
last_leaf = get.leaf(rhythmic_staff, -1)
markup = Markup(r"\markup I", direction=enums.Up, literal=True)
markup = _markups.Markup(r"\markup I", direction=enums.Up, literal=True)
attach(markup, last_leaf)
overrides.tweak(markup).staff_padding = 18
overrides.tweak(markup).transparent = "##t"
Expand Down Expand Up @@ -389,7 +392,7 @@ def make_piano_score(leaves=None, lowest_treble_pitch="B3"):
score = _score.Score(name="Score")
score.append(staff_group)
for leaf in leaves:
markups = get.indicators(leaf, Markup)
markups = get.indicators(leaf, _markups.Markup)
written_duration = leaf.written_duration
if isinstance(leaf, _score.Note):
if leaf.written_pitch < lowest_treble_pitch:
Expand Down
4 changes: 2 additions & 2 deletions abjad/indicators/BarLine.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ def abbreviation(self) -> str:
>>> abjad.BarLine("text")
Traceback (most recent call last):
...
...
Exception: unknown bar line abbreviation: 'text'
Abbreviation must be one of these:
''
''
'|'
'.'
'||'
Expand Down
26 changes: 8 additions & 18 deletions abjad/indicators/BowContactPoint.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,29 +134,19 @@ def markup(self) -> Markup:
One quarter of the way from frog to point:
>>> indicator = abjad.BowContactPoint((1, 4))
>>> print(abjad.lilypond(indicator.markup))
\markup {
\center-align
\vcenter
\fraction
1
4
}
>>> string = abjad.lilypond(indicator.markup)
>>> print(string)
\markup \center-align \vcenter \fraction 1 4
>>> abjad.show(indicator.markup) # doctest: +SKIP
.. container:: example
Three fifths of the way from frog to point:
>>> indicator = abjad.BowContactPoint((3, 5))
>>> print(abjad.lilypond(indicator.markup))
\markup {
\center-align
\vcenter
\fraction
3
5
}
>>> string = abjad.lilypond(indicator.markup)
>>> print(string)
\markup \center-align \vcenter \fraction 3 5
>>> abjad.show(indicator.markup) # doctest: +SKIP
"""
Expand All @@ -165,8 +155,8 @@ def markup(self) -> Markup:
else:
contact_point = self.contact_point
fraction = fr"\fraction {contact_point.numerator} {contact_point.denominator}"
string = rf"\center-align \vcenter {fraction}"
markup = Markup(string)
string = rf"\markup \center-align \vcenter {fraction}"
markup = Markup(string, literal=True)
return markup

@property
Expand Down
Loading

0 comments on commit 63520b2

Please sign in to comment.