Skip to content

Commit 9ffa14b

Browse files
committed
give warning if repeated tendency has not completed a cycle
1 parent 4f2beaf commit 9ffa14b

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

tests/tendencies/test_repeat.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,3 +166,12 @@ def test_filled(repeat_waveform):
166166
assert tendencies[2].base == 2
167167
assert tendencies[2].amplitude == -1
168168
assert tendencies[2].frequency == 0.25
169+
170+
171+
def test_too_short(repeat_waveform):
172+
"""Check for warning in annotations if repeated waveform has not completed a
173+
single repetition."""
174+
repeat_waveform["user_duration"] = 2
175+
repeat_tendency = RepeatTendency(**repeat_waveform)
176+
assert repeat_tendency.annotations
177+
assert repeat_tendency.annotations[0]["type"] == "warning"

waveform_editor/tendencies/repeat.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,21 @@ def __init__(self, **kwargs):
1818

1919
self.waveform = Waveform(waveform=waveform, is_repeated=True)
2020
if not self.waveform.tendencies:
21-
error_msg = "There are no tendencies in the repeated waveform."
21+
error_msg = "There are no tendencies in the repeated waveform.\n"
2222
self.annotations.add(self.line_number, error_msg)
2323
return
2424

2525
if self.waveform.tendencies[0].start != 0:
26-
error_msg = "The starting point of the first repeated must be set to 0."
26+
error_msg = "The starting point of the first repeated must be set to 0.\n"
2727
self.annotations.add(self.line_number, error_msg)
2828

29+
if self.duration < self.waveform.tendencies[-1].end:
30+
error_msg = (
31+
"The repeated tendency has not completed a single repetition.\n"
32+
"Perhaps increase the duration of the repeated tendency?\n"
33+
)
34+
self.annotations.add(self.line_number, error_msg, is_warning=True)
35+
2936
# Link the last tendency to the first tendency in the repeated waveform
3037
# We must lock the start to 0, otherwise it will take the start value of the
3138
# previous tendency.

0 commit comments

Comments
 (0)