Skip to content

Commit

Permalink
Merge pull request #274 from CPJKU/non_constant_features
Browse files Browse the repository at this point in the history
update note feature extraction for dynamic features
  • Loading branch information
manoskary authored Jun 15, 2023
2 parents d0cdd22 + bebdaac commit b1dc071
Showing 1 changed file with 5 additions and 31 deletions.
36 changes: 5 additions & 31 deletions partitura/musicanalysis/note_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,13 +758,8 @@ def feature_function_activation(direction):
if isinstance(
direction, (score.DynamicLoudnessDirection, score.DynamicTempoDirection)
):
# a dynamic direction will be encoded as a ramp from d.start.t to
# d.end.t, and then a step from d.end.t to the start of the next
# constant direction.

# There are two potential issues:

# Issue 1. d.end is None (e.g. just a ritardando without dashes). In this case
# a dynamic direction will be encoded as a ramp from d.start.t to d.end.t
# if d.end is None (e.g. just a ritardando without dashes)
if direction.end:
direction_end = direction.end.t
else:
Expand All @@ -774,31 +769,10 @@ def feature_function_activation(direction):
direction_end = measure.start.t
else:
# no measure, unlikely, but not impossible.
direction_end = direction.start.t

if isinstance(direction, score.TempoDirection):
next_dir = next(
direction.start.iter_next(score.ConstantTempoDirection), None
)
if isinstance(direction, score.ArticulationDirection):
next_dir = next(
direction.start.iter_next(score.ConstantArticulationDirection), None
)
else:
next_dir = next(
direction.start.iter_next(score.ConstantLoudnessDirection), None
)
direction_end = direction.start.t + 1

if next_dir:
# TODO: what do we do when next_dir is too far away?
sustained_end = next_dir.start.t
else:
# Issue 2. there is no next constant direction. In that case the
# feature function will be a ramp with a quarter note ramp
sustained_end = direction_end + direction.start.quarter

x = [direction.start.t, direction_end - epsilon, sustained_end - epsilon]
y = [0, 1, 1]
x = [direction.start.t, direction_end , direction_end + epsilon]
y = [0, 1, 0]

elif isinstance(
direction,
Expand Down

0 comments on commit b1dc071

Please sign in to comment.