mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-08 13:33:42 +08:00
fd4ca85d61
Provide alert playback and volume control with a native audio callback that does not depend on the Python GIL. Co-authored-by: Daniel Koepping <elkoled@gmail.com>
22 lines
997 B
Python
22 lines
997 B
Python
"""Bounded delivery of an already selected availability chime, independent of authority."""
|
|
MAX_DELIVERY_NS = 400_000_000
|
|
|
|
class AvailabilityWarningDelivery:
|
|
def __init__(self):
|
|
self.context = None
|
|
self.until_ns = 0
|
|
self.last_ns = 0
|
|
|
|
def observe(self, *, session, drive, now_ns, selected, requested_until_ns):
|
|
context = (session, drive) if session and drive > 0 else None
|
|
if context != self.context or now_ns < self.last_ns or context is None:
|
|
self.until_ns = 0
|
|
self.context, self.last_ns = context, now_ns
|
|
if context is not None and selected and now_ns <= requested_until_ns:
|
|
self.until_ns = max(self.until_ns, min(requested_until_ns, now_ns + MAX_DELIVERY_NS))
|
|
|
|
def pending(self, *, session, drive, now_ns, audible_none, priority, low_priority):
|
|
return (self.context is not None and self.context == (session, drive) and drive > 0 and
|
|
self.last_ns <= now_ns <= self.until_ns and
|
|
audible_none and priority <= low_priority)
|