Skip to content

Commit

Permalink
force_new option for segment creation
Browse files Browse the repository at this point in the history
  • Loading branch information
sildater committed Jan 10, 2025
1 parent 598af13 commit 8f07f95
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions partitura/score.py
Original file line number Diff line number Diff line change
Expand Up @@ -4427,7 +4427,7 @@ def __init__(self, id, to, await_to, force_seq=False, type="default", info=""):
self.info = info


def add_segments(part):
def add_segments(part, force_new = False):
"""
Add segment objects to a part based on repetition and capo/fine/coda/segno directions.
Expand All @@ -4436,9 +4436,14 @@ def add_segments(part):
part: part
A score part
"""
if len([seg for seg in part.iter_all(Segment)]) > 0:
existing_segments = [seg for seg in part.iter_all(Segment)]
if len(existing_segments) > 0:
# only add segments if no segments exist
pass
if force_new:
for seg in existing_segments:
part.remove(seg)
else:
pass
else:
boundaries = defaultdict(dict)
destinations = defaultdict(list)
Expand Down Expand Up @@ -5004,7 +5009,7 @@ def get_paths(part, no_repeats=False, all_repeats=False, ignore_leap_info=True):
segments = get_segments(part)
paths = list()
unfold_paths(
Path(["A"], segments, no_repeats=no_repeats, all_repeats=all_repeats),
Path([chr(65)], segments, no_repeats=no_repeats, all_repeats=all_repeats),
paths,
ignore_leap_info=ignore_leap_info,
)
Expand Down

0 comments on commit 8f07f95

Please sign in to comment.