Skip to content

Commit

Permalink
Track: Allow re-scheduling count; schedule endlessly if max_event_cou…
Browse files Browse the repository at this point in the history
…nt is 0
  • Loading branch information
ideoforms committed Sep 19, 2024
1 parent 0bb0fde commit c1f9a24
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions isobar/timelines/track.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def start(self,
interpolate: Optional[str] = None) -> None:
"""
Begin executing the events on this track.
Resets the track's time counter to zero.
Args:
events: A dict, a PDict, or a Pattern that generates dicts.
Expand All @@ -114,7 +113,13 @@ def start(self,
self.event_stream = events

self.is_started = True
self.current_time = 0.0

# Previously, this reset the counter to zero, but when re-scheduling a track that has
# note-offs awaiting, this caused the existing notes to extend in duration.
# Arguably it is more coherent to reset the time and adjust the note-off scheduling
# accordingly, so may need to re-visit this.
# self.current_time = 0.0

self.next_event_time = self.current_time
if interpolate is not None:
self.interpolate = interpolate
Expand All @@ -123,7 +128,8 @@ def update(self,
events: Union[dict, Pattern],
quantize: Optional[float] = None,
delay: Optional[float] = None,
interpolate: Optional[str] = None):
interpolate: Optional[str] = None,
count: Optional[int] = None):
"""
Update the events that this Track produces.
Expand All @@ -133,13 +139,16 @@ def update(self,
quantize == 1 means that the update should happen on the next beat boundary.
delay: Optional float specifying delay time applied to quantization
interpolate: Optional interpolation mode
count: Optional max_event_count
"""
if quantize is None:
quantize = self.timeline.defaults.quantize
if delay is None:
delay = self.timeline.defaults.delay
if self.output_device is not None and self.output_device.added_latency_seconds > 0.0:
delay += self.timeline.seconds_to_beats(self.output_device.added_latency_seconds)
if count is not None:
self.max_event_count = count

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

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

#------------------------------------------------------------------------
Expand Down

0 comments on commit c1f9a24

Please sign in to comment.