Skip to content

Commit

Permalink
Merge branch 'main' of github.com:Bubobubobubobubo/sardine
Browse files Browse the repository at this point in the history
  • Loading branch information
Bubobubobubobubo committed Jul 23, 2024
2 parents 1803600 + ca917e9 commit 69acb42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
4 changes: 2 additions & 2 deletions sardine_core/handlers/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ def get_new_period(self, pattern: PatternInformation) -> Number:
"""Get period value for the current cycle"""
for message in pattern.sender.pattern_reduce(
{"period": pattern.period},
self.iterator,
self.runner.iter,
pattern.divisor,
pattern.rate,
# use_divisor_to_skip=False,
Expand Down Expand Up @@ -206,7 +206,7 @@ def push(self, pattern: Optional[PatternInformation]):
return self.env.scheduler.stop_runner(self.runner)
elif not self.runner.is_running():
# Assume we are queuing the first state
self.iterator = 0
self.runner.iter = 0
self.runner.reset_states()

# Forcibly reset the interval shift back to 0 to make sure
Expand Down
14 changes: 10 additions & 4 deletions sardine_core/scheduler/async_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,11 @@ def defer_beats(self) -> float:
"""The number of beats to defer function calls."""
return float(self.scheduler.deferred)

@property
def defer_duration(self) -> float:
"""The amount of time to defer function calls."""
return self.defer_beats * self.clock.beat_duration

@property
def env(self) -> "FishBowl":
"""A shorthand for the scheduler's fish bowl."""
Expand Down Expand Up @@ -676,10 +681,11 @@ async def _run_once(self) -> None:
arriving_states: list[DeferredState] = []
while self.deferred_states:
entry = self.deferred_states[0]
entry_deadline = entry.deadline - self.defer_duration
if (
self.clock.time >= entry.deadline
self.clock.time >= entry_deadline
or state is not None
and deadline >= entry.deadline
and deadline >= entry_deadline
):
heapq.heappop(self.deferred_states)

Expand Down Expand Up @@ -709,7 +715,7 @@ async def _run_once(self) -> None:
# sleeping a full period.
deadline = self.deferred_states[0].deadline
# interrupted is true if we are past the deadline
interrupted = await self._sleep_until(deadline)
interrupted = await self._sleep_until(deadline - self.defer_duration)
return self._jump_start_iteration()

# NOTE: deadline will always be defined at this point
Expand Down Expand Up @@ -745,7 +751,7 @@ async def _call_func(self, func, args, kwargs):

if self.defer_beats:
delta = self.clock.time - self._expected_time
shift = self.defer_beats * self.clock.beat_duration - delta
shift = self.defer_duration - delta
self.time.shift += shift

return await maybe_coro(func, *args, **valid_kwargs)
Expand Down

0 comments on commit 69acb42

Please sign in to comment.