Skip to content

Commit f71b58d

Browse files
committed
ensure values are updated after initialization
1 parent 44a33ba commit f71b58d

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

waveform_editor/tendencies/base.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ def __init__(self, **kwargs):
115115
self._handle_error(error)
116116

117117
self._handle_unknown_kwargs(unknown_kwargs)
118+
self.values_changed = True
118119

119120
def _handle_error(self, error):
120121
"""Handle exceptions raised by param assignment and add them as annotations.
@@ -179,18 +180,20 @@ def set_previous_tendency(self, prev_tendency):
179180
# If the tendency is the first tendency of a repeated tendency, it is linked to
180181
# the last tendency in the repeated tendency. In this case we can ignore this
181182
# error.
182-
if self.prev_tendency.end > self.start and not self.is_first_repeated:
183-
error_msg = (
184-
f"The end of the previous tendency ({self.prev_tendency.end})\nis "
185-
f"later than the start of the current tendency ({self.start}).\n"
186-
)
187-
self.annotations.add(self.line_number, error_msg)
188-
elif self.prev_tendency.end < self.start:
189-
error_msg = (
190-
"Previous tendency ends before the start of the current tendency.\n"
191-
"The values inbetween the tendencies will be linearly interpolated.\n"
192-
)
193-
self.annotations.add(self.line_number, error_msg, is_warning=True)
183+
if not np.isclose(self.prev_tendency.end, self.start):
184+
if self.prev_tendency.end > self.start and not self.is_first_repeated:
185+
error_msg = (
186+
f"The end of the previous tendency ({self.prev_tendency.end})\nis "
187+
f"later than the start of the current tendency ({self.start}).\n"
188+
)
189+
self.annotations.add(self.line_number, error_msg)
190+
elif self.prev_tendency.end < self.start:
191+
error_msg = (
192+
"Previous tendency ends before the start of the current tendency.\n"
193+
"The values inbetween the tendencies will be linearly interpolated."
194+
"\n"
195+
)
196+
self.annotations.add(self.line_number, error_msg, is_warning=True)
194197

195198
self.param.trigger("annotations")
196199

waveform_editor/tendencies/repeat.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ class RepeatTendency(BaseTendency):
1212

1313
def __init__(self, **kwargs):
1414
waveform = kwargs.pop("user_waveform", []) or []
15-
super().__init__(**kwargs)
16-
1715
from waveform_editor.waveform import Waveform
1816

1917
self.waveform = Waveform(waveform=waveform, is_repeated=True)
18+
super().__init__(**kwargs)
2019
if not self.waveform.tendencies:
2120
error_msg = "There are no tendencies in the repeated waveform.\n"
2221
self.annotations.add(self.line_number, error_msg)
@@ -68,7 +67,7 @@ def get_value(
6867
Tuple containing the time and its tendency values.
6968
"""
7069
if not self.waveform.tendencies:
71-
return np.array([]), np.array([])
70+
return np.array([0]), np.array([0])
7271
length = self.waveform.calc_length()
7372
if time is None:
7473
time, values = self.waveform.get_value()
@@ -103,6 +102,8 @@ def get_derivative(self, time: np.ndarray) -> np.ndarray:
103102
Returns:
104103
numpy array containing the derivatives
105104
"""
105+
if not self.waveform.tendencies:
106+
return np.array([0])
106107
length = self.waveform.calc_length()
107108
relative_times = (time - self.start) % length
108109
derivatives = self.waveform.get_derivative(relative_times)

0 commit comments

Comments
 (0)