Skip to content

Commit

Permalink
Merge pull request #2 from josiah-wolf-oberholtzer/abjad-2.21
Browse files Browse the repository at this point in the history
Update for Abjad 2.21
  • Loading branch information
josiah-wolf-oberholtzer committed Aug 10, 2017
2 parents 6eeb9b6 + 56330f8 commit dd69003
Show file tree
Hide file tree
Showing 99 changed files with 2,806 additions and 3,056 deletions.
5 changes: 2 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ sudo: false

env:
global:
- LILYPOND_VERSION=2.19.44
- LILYPOND_VERSION=2.19.65

python:
- 3.5
Expand All @@ -22,8 +22,7 @@ install:
- pip install -e .

script:
- coverage run -a `which ajv` doctest ./consort
- coverage run -a `which py.test` -rf ./consort
- coverage run -a `which py.test`

after_success:
coveralls
Expand Down
9 changes: 9 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import abjad
import consort
import pytest


@pytest.fixture(autouse=True)
def add_libraries(doctest_namespace):
doctest_namespace['abjad'] = abjad
doctest_namespace['consort'] = consort
2 changes: 1 addition & 1 deletion consort/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
__version_info__ = (0, 1)
__version_info__ = (0, 2)
__version__ = '.'.join(str(x) for x in __version_info__)
19 changes: 8 additions & 11 deletions consort/tools/AbsolutePitchHandler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- encoding: utf-8 -*-
from __future__ import print_function
from consort.tools.PitchHandler import PitchHandler


Expand All @@ -8,25 +6,24 @@ class AbsolutePitchHandler(PitchHandler):
::
>>> import consort
>>> pitch_handler = consort.AbsolutePitchHandler(
... pitch_specifier="c' d' e' f'",
... )
>>> print(format(pitch_handler))
consort.tools.AbsolutePitchHandler(
pitch_specifier=consort.tools.PitchSpecifier(
pitch_segments=(
pitchtools.PitchSegment(
abjad.PitchSegment(
(
pitchtools.NamedPitch("c'"),
pitchtools.NamedPitch("d'"),
pitchtools.NamedPitch("e'"),
pitchtools.NamedPitch("f'"),
abjad.NamedPitch("c'"),
abjad.NamedPitch("d'"),
abjad.NamedPitch("e'"),
abjad.NamedPitch("f'"),
),
item_class=pitchtools.NamedPitch,
item_class=abjad.NamedPitch,
),
),
ratio=mathtools.Ratio((1,)),
ratio=abjad.Ratio((1,)),
),
)
Expand Down Expand Up @@ -86,4 +83,4 @@ def _get_pitch(
while pitch == previous_pitch:
seed += 1
pitch = pitch_choices[seed]
return pitch
return pitch
5 changes: 2 additions & 3 deletions consort/tools/AfterGraceSelectorCallback.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# -*- encoding: utf-8 -*-
from abjad import inspect_
import abjad
from abjad.tools import abctools
from abjad.tools import selectiontools

Expand All @@ -19,7 +18,7 @@ def __call__(self, expr, rotation=None, start_offset=None):
subresult = []
for x in subexpr:
subresult.append(x)
if inspect_(x).get_grace_containers('after'):
if abjad.inspect(x).get_after_grace_container():
subresult = selectiontools.Selection(subresult)
result.append(subresult)
subresult = []
Expand Down
78 changes: 36 additions & 42 deletions consort/tools/AttachmentExpression.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
# -*- encoding: utf-8 -*-
from __future__ import print_function
import abjad
import collections
import copy
try:
import funcsigs
except ImportError:
import inspect as funcsigs
from abjad import attach
from abjad import new
from abjad.tools import datastructuretools
from abjad.tools import scoretools
from abjad.tools import selectortools
from abjad.tools import sequencetools
from abjad.tools import spannertools
from consort.tools.HashCachingObject import HashCachingObject


Expand All @@ -23,27 +16,26 @@ class AttachmentExpression(HashCachingObject):
::
>>> import consort
>>> attachment_expression = consort.AttachmentExpression(
... attachments=(indicatortools.Articulation('>'),),
... selector=selectortools.Selector().by_leaf().by_run(Note)[0],
... attachments=(abjad.Articulation('>'),),
... selector=abjad.Selector().by_leaf().by_run(abjad.Note)[0],
... )
>>> print(format(attachment_expression))
consort.tools.AttachmentExpression(
attachments=datastructuretools.TypedList(
attachments=abjad.TypedList(
[
indicatortools.Articulation('>'),
abjad.Articulation('>'),
]
),
selector=selectortools.Selector(
selector=abjad.Selector(
callbacks=(
selectortools.PrototypeSelectorCallback(
prototype=scoretools.Leaf,
abjad.PrototypeSelectorCallback(
prototype=abjad.Leaf,
),
selectortools.RunSelectorCallback(
prototype=scoretools.Note,
abjad.RunSelectorCallback(
prototype=abjad.Note,
),
selectortools.ItemSelectorCallback(
abjad.ItemSelectorCallback(
item=0,
apply_to_each=True,
),
Expand All @@ -60,37 +52,37 @@ class AttachmentExpression(HashCachingObject):
... hairpin_stop_token='niente',
... ),
... ),
... selector=selectortools.Selector().by_leaf().by_run(Note),
... selector=abjad.Selector().by_leaf().by_run(abjad.Note),
... )
::
>>> staff = Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8")
>>> staff = abjad.Staff("c'8 r8 d'8 e'8 r8 f'8 g'8 a'8")
>>> attachment_expression(staff)
>>> print(format(staff))
\new Staff {
c'8 \sfz
r8
\override Hairpin.circled-tip = ##t
d'8 \> \sfz
e'8 \!
\revert Hairpin.circled-tip
e'8 \!
r8
\override Hairpin.circled-tip = ##t
f'8 \> \sfz
g'8
a'8 \!
\revert Hairpin.circled-tip
a'8 \!
}
.. container:: example
::
>>> attachment_expression = consort.AttachmentExpression(
... attachments=spannertools.Slur(),
... attachments=abjad.Slur(),
... )
>>> staff = Staff("c'4 d'4 e'4 f'4")
>>> staff = abjad.Staff("c'4 d'4 e'4 f'4")
>>> attachment_expression(staff)
>>> print(format(staff))
\new Staff {
Expand All @@ -104,15 +96,15 @@ class AttachmentExpression(HashCachingObject):
::
>>> staff = Staff("c'4 d'4 e'4 f'4")
>>> staff = abjad.Staff("c'4 d'4 e'4 f'4")
>>> attachment_expression = consort.AttachmentExpression(
... attachments=[
... [
... indicatortools.Articulation('accent'),
... indicatortools.Articulation('staccato'),
... abjad.Articulation('accent'),
... abjad.Articulation('staccato'),
... ],
... ],
... selector=selectortools.Selector().by_logical_tie()[0]
... selector=abjad.Selector().by_logical_tie()[0]
... )
>>> attachment_expression(staff)
>>> print(format(staff))
Expand Down Expand Up @@ -151,16 +143,16 @@ def __init__(
if attachments is not None:
if not isinstance(attachments, collections.Sequence):
attachments = (attachments,)
attachments = datastructuretools.TypedList(attachments)
attachments = abjad.TypedList(attachments)
self._attachments = attachments
if selector is not None:
assert isinstance(selector, selectortools.Selector)
assert isinstance(selector, abjad.Selector)
self._selector = selector
if scope is not None:
if isinstance(scope, type):
assert issubclass(scope, scoretools.Component)
assert issubclass(scope, abjad.Component)
else:
assert isinstance(scope, (scoretools.Component, str))
assert isinstance(scope, (abjad.Component, str))
self._scope = scope
if is_annotation is not None:
is_annotation = bool(is_annotation)
Expand All @@ -182,7 +174,7 @@ def __call__(
):
selector = self.selector
if selector is None:
selector = selectortools.Selector()
selector = abjad.Selector()
selections = selector(music, rotation=rotation)
self._apply_attachments(
selections,
Expand All @@ -195,7 +187,7 @@ def __call__(
def _apply_attachments(self, selections, name=None, rotation=None):
if not self.attachments:
return
all_attachments = datastructuretools.CyclicTuple(self.attachments)
all_attachments = abjad.CyclicTuple(self.attachments)
if self.use_only_first_attachment:
attachments = all_attachments[rotation]
for i, selection in enumerate(selections, rotation):
Expand All @@ -209,11 +201,11 @@ def _apply_attachments(self, selections, name=None, rotation=None):
for attachment in attachments:
# print('\t' + repr(attachment))
# spanners
if isinstance(attachment, spannertools.Spanner):
if isinstance(attachment, abjad.Spanner):
attachment = copy.copy(attachment)
attach(attachment, selection, name=name)
elif isinstance(attachment, type) and \
issubclass(attachment, spannertools.Spanner):
issubclass(attachment, abjad.Spanner):
attachment = attachment()
attach(attachment, selection, name=name)
# expressions
Expand All @@ -229,7 +221,7 @@ def _apply_attachments(self, selections, name=None, rotation=None):
attachment(selection)
# indicators
else:
if isinstance(selection, scoretools.Leaf):
if isinstance(selection, abjad.Leaf):
selection = (selection,)
for component in selection:
attachment = copy.copy(attachment)
Expand All @@ -244,14 +236,16 @@ def _apply_attachments(self, selections, name=None, rotation=None):
### PUBLIC METHODS ###

def reverse(self):
attachments = sequencetools.Sequence(*self.attachments)
return new(self,
attachments = abjad.Sequence(*self.attachments)
return abjad.new(
self,
attachments=attachments.reverse(),
)

def rotate(self, n=0):
attachments = sequencetools.Sequence(*self.attachments)
return new(self,
attachments = abjad.Sequence(*self.attachments)
return abjad.new(
self,
attachments=attachments.rotate(n),
)

Expand Down
18 changes: 7 additions & 11 deletions consort/tools/AttachmentHandler.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
# -*- encoding: utf-8 -*-
from __future__ import print_function
import abjad
import collections
from abjad import inspect_
from abjad import inspect
from abjad import iterate
from abjad.tools import abctools
from abjad.tools import scoretools
from abjad.tools import selectortools
from abjad.tools import systemtools


Expand All @@ -14,7 +11,6 @@ class AttachmentHandler(abctools.AbjadValueObject):
::
>>> import consort
>>> attachment_handler = consort.AttachmentHandler()
>>> print(format(attachment_handler))
consort.tools.AttachmentHandler()
Expand Down Expand Up @@ -53,7 +49,7 @@ def __call__(
music,
seed=0,
):
assert isinstance(music, scoretools.Container)
assert isinstance(music, abjad.Container)
if not self.attachment_expressions:
return
items = self.attachment_expressions.items()
Expand All @@ -67,15 +63,15 @@ def __call__(
continue
selector = attachment_expression.selector
if selector is None:
selector = selectortools.Selector()
selector = abjad.Selector()
selectors.add(selector)
if selector not in selectors_to_expressions:
selectors_to_expressions[selector] = set()
selectors_to_expressions[selector].add(item)
if destructive_expressions:
for name, attachment_expression in sorted(destructive_expressions):
attachment_expression(music, name=name, rotation=seed)
selectors_to_selections = selectortools.Selector.run_selectors(
selectors_to_selections = abjad.Selector.run_selectors(
music, selectors, rotation=seed,
)
for selector in selectors:
Expand Down Expand Up @@ -106,11 +102,11 @@ def _process_session(segment_maker, verbose=None):
score = segment_maker.score
counter = collections.Counter()
template = ' decorating {}: {}'
for voice in iterate(score).by_class(scoretools.Voice):
for voice in iterate(score).by_class(abjad.Voice):
count = 0
for container in voice:
prototype = consort.MusicSpecifier
music_specifier = inspect_(container).get_effective(prototype)
music_specifier = abjad.inspect(container).get_effective(prototype)
maker = music_specifier.attachment_handler
if maker is None:
continue
Expand Down
Loading

0 comments on commit dd69003

Please sign in to comment.