Skip to content

Commit

Permalink
GraceHandler now generates spacer grace notes.
Browse files Browse the repository at this point in the history
  • Loading branch information
josiah-wolf-oberholtzer committed Dec 16, 2014
1 parent 0e5faf7 commit 5eeff0d
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
35 changes: 30 additions & 5 deletions consort/tools/GraceHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ def __init__(
def __call__(
self,
logical_tie,
maximum_grace_count=None,
seed=0,
):
assert isinstance(logical_tie, selectiontools.LogicalTie)
Expand All @@ -94,19 +95,39 @@ def __call__(
return
kind = 'after'
leaf_to_attach_to = previous_leaf
grace_notes = scoretools.make_notes([0], [(1, 16)] * grace_count)
assert len(grace_notes)
leaves = []
if maximum_grace_count:
skip_count = maximum_grace_count - grace_count
if 0 < skip_count:
skips = [scoretools.Skip((1, 16)) for _ in range(skip_count)]
leaves.extend(skips)
notes = scoretools.make_notes([0], [(1, 16)] * grace_count)
leaves.extend(notes)
assert len(leaves)
grace_container = scoretools.GraceContainer(
grace_notes,
leaves,
kind=kind,
)
override(grace_container).flag.stroke_style = \
schemetools.Scheme('grace', force_quotes=True)
override(grace_container).script.font_size = 0.5
attach(grace_container, leaf_to_attach_to)

### PRIVATE METHODS ###

@staticmethod
def _find_maximum_grace_count(segment_maker):
maximum_grace_count = 0
for music_setting in segment_maker._settings:
for music_specifier in music_setting.music_specifiers.values():
if music_specifier.grace_handler is None:
continue
counts = max(music_specifier.grace_handler.counts)
maximum_grace_count = max(maximum_grace_count, counts)
return maximum_grace_count

@staticmethod
def _process_session(segment_session):
def _process_session(segment_session, maximum_grace_count=None):
import consort
counter = collections.Counter()
attack_point_map = segment_session.attack_point_map
Expand All @@ -126,7 +147,11 @@ def _process_session(segment_session):
seed = music_specifier.seed or 0
counter[music_specifier] = seed
seed = counter[music_specifier]
grace_handler(logical_tie, seed=seed)
grace_handler(
logical_tie,
maximum_grace_count=maximum_grace_count,
seed=seed,
)
counter[music_specifier] += 1

### PUBLIC METHODS ###
Expand Down
7 changes: 6 additions & 1 deletion consort/tools/SegmentMaker.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,12 @@ def __call__(self):
enter_message='GraceHandler:',
exit_message='\ttotal:',
):
consort.GraceHandler._process_session(segment_session)
maximum_grace_count = \
consort.GraceHandler._find_maximum_grace_count(self)
consort.GraceHandler._process_session(
segment_session,
maximum_grace_count,
)
with systemtools.Timer(
enter_message='PitchHandler:',
exit_message='\ttotal:',
Expand Down
10 changes: 10 additions & 0 deletions consort/tools/test/test_GraceHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def test_GraceHandler_02():
{
\override Flag #'stroke-style = #"grace"
\override Script #'font-size = #0.5
s16
s16
c'16
\revert Flag #'stroke-style
\revert Script #'font-size
Expand All @@ -214,6 +216,7 @@ def test_GraceHandler_02():
{
\override Flag #'stroke-style = #"grace"
\override Script #'font-size = #0.5
s16
c'16
c'16
\revert Flag #'stroke-style
Expand Down Expand Up @@ -264,6 +267,8 @@ def test_GraceHandler_02():
{
\override Flag #'stroke-style = #"grace"
\override Script #'font-size = #0.5
s16
s16
c'16
\revert Flag #'stroke-style
\revert Script #'font-size
Expand All @@ -275,6 +280,7 @@ def test_GraceHandler_02():
{
\override Flag #'stroke-style = #"grace"
\override Script #'font-size = #0.5
s16
c'16
c'16
\revert Flag #'stroke-style
Expand Down Expand Up @@ -359,6 +365,8 @@ def test_GraceHandler_03():
{
\override Flag #'stroke-style = #"grace"
\override Script #'font-size = #0.5
s16
s16
c'16
c'16
\revert Flag #'stroke-style
Expand Down Expand Up @@ -414,6 +422,8 @@ def test_GraceHandler_03():
{
\override Flag #'stroke-style = #"grace"
\override Script #'font-size = #0.5
s16
s16
c'16
c'16
\revert Flag #'stroke-style
Expand Down

0 comments on commit 5eeff0d

Please sign in to comment.