Skip to content

Commit c1f9a24

Browse files
committed
Track: Allow re-scheduling count; schedule endlessly if max_event_count is 0
1 parent 0bb0fde commit c1f9a24

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

isobar/timelines/track.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,6 @@ def start(self,
102102
interpolate: Optional[str] = None) -> None:
103103
"""
104104
Begin executing the events on this track.
105-
Resets the track's time counter to zero.
106105
107106
Args:
108107
events: A dict, a PDict, or a Pattern that generates dicts.
@@ -114,7 +113,13 @@ def start(self,
114113
self.event_stream = events
115114

116115
self.is_started = True
117-
self.current_time = 0.0
116+
117+
# Previously, this reset the counter to zero, but when re-scheduling a track that has
118+
# note-offs awaiting, this caused the existing notes to extend in duration.
119+
# Arguably it is more coherent to reset the time and adjust the note-off scheduling
120+
# accordingly, so may need to re-visit this.
121+
# self.current_time = 0.0
122+
118123
self.next_event_time = self.current_time
119124
if interpolate is not None:
120125
self.interpolate = interpolate
@@ -123,7 +128,8 @@ def update(self,
123128
events: Union[dict, Pattern],
124129
quantize: Optional[float] = None,
125130
delay: Optional[float] = None,
126-
interpolate: Optional[str] = None):
131+
interpolate: Optional[str] = None,
132+
count: Optional[int] = None):
127133
"""
128134
Update the events that this Track produces.
129135
@@ -133,13 +139,16 @@ def update(self,
133139
quantize == 1 means that the update should happen on the next beat boundary.
134140
delay: Optional float specifying delay time applied to quantization
135141
interpolate: Optional interpolation mode
142+
count: Optional max_event_count
136143
"""
137144
if quantize is None:
138145
quantize = self.timeline.defaults.quantize
139146
if delay is None:
140147
delay = self.timeline.defaults.delay
141148
if self.output_device is not None and self.output_device.added_latency_seconds > 0.0:
142149
delay += self.timeline.seconds_to_beats(self.output_device.added_latency_seconds)
150+
if count is not None:
151+
self.max_event_count = count
143152

144153
#--------------------------------------------------------------------------------
145154
# Don't assign to events immediately, because in the case of quantized
@@ -298,7 +307,8 @@ def get_next_event(self) -> Event:
298307
if self.event_stream is None:
299308
raise StopIteration
300309

301-
if self.max_event_count is not None and self.current_event_count >= self.max_event_count:
310+
# Allow for 0 to mean infinite events, for ease of use in live coding
311+
if self.max_event_count not in (None, 0) and self.current_event_count >= self.max_event_count:
302312
raise StopIteration
303313

304314
#------------------------------------------------------------------------

0 commit comments

Comments
 (0)