time
attribute__all__= ['TICK_RESOLUTION', 'Division', 'DivisionLike', 'Position', 'PositionLike', 'TickResolver', 'TimeCalculator', 'tick_to_pos', 'pos_to_tick', 'push_beat_events', 'pop_beat_events', 'resolve_tick', 'push_tick_resolver', 'pop_tick_resolver', 'div_to_tick', 'tick_to_div', 'resolve_division']func_require_int(name, value) -> intparamnamestrparamvalueobjectReturns
intfunc_assert_unique_beat_bars(events) -> Noneparameventslist[BeatEvent]Returns
Nonefunc_build_time_signatures(beat_events) -> list[_TimeSignature]parambeat_eventsIterable[BeatEvent]Returns
list[margrete_rpc.chart.time._TimeSignature]func_measure_length(ts) -> intparamts_TimeSignatureReturns
intfuncpush_beat_events(beat_events) -> contextvars.Token[Iterable[BeatEvent] | None]Install beat_events as the active beat events for position resolution.
While active, :func:tick_to_pos and :func:pos_to_tick use these events when none are passed
explicitly. :class:EditTransaction does this automatically for the duration of an
edit.
parambeat_eventsIterable[BeatEvent]The time-signature events to make active.
Returns
contextvars.TokenA token to pass to :func:pop_beat_events to restore the previous events.
funcpop_beat_events(token) -> NoneRestore the beat events active before the matching :func:push_beat_events.
paramtokencontextvars.Token[Iterable[BeatEvent] | None]Returns
Nonefunc_resolve_beat_events(beat_events) -> Iterable[BeatEvent]parambeat_eventsIterable[BeatEvent] | NoneReturns
collections.abc.Iterable[margrete_rpc.chart.events.BeatEvent]functick_to_pos(tick, *, beat_events=None) -> PositionConvert an absolute tick to a (bar, beat, offset) position.
paramtickintNon-negative absolute tick from the chart start.
parambeat_eventsIterable[BeatEvent] | None= NoneTime-signature events to resolve against; falls back to the active
events (see :func:push_beat_events), then to a default 4/4 signature.
Returns
margrete_rpc.chart.time.PositionThe (bar, beat, offset) position of tick.
funcpos_to_tick(bar, beat=0, offset=0, *, beat_events=None) -> intConvert a (bar, beat, offset) position to an absolute tick.
parambarintZero-based bar index.
parambeatint= 0Zero-based beat within the bar.
paramoffsetint= 0Tick offset within the beat.
parambeat_eventsIterable[BeatEvent] | None= NoneTime-signature events to resolve against; falls back to the active
events (see :func:push_beat_events), then to a default 4/4 signature.
Returns
intThe absolute tick from the chart start.
funcpush_tick_resolver(resolver) -> contextvars.Token[TickResolver | None]Install resolver as the active position->tick resolver.
While active, :func:resolve_tick uses it to turn :data:Position tuples into ticks.
:class:EditTransaction installs a resolver bound to the chart's beat events.
paramresolverTickResolverThe position-to-tick function to make active.
Returns
contextvars.TokenA token to pass to :func:pop_tick_resolver to restore the previous resolver.
funcpop_tick_resolver(token) -> NoneRestore the resolver active before the matching :func:push_tick_resolver.
paramtokencontextvars.Token[TickResolver | None]Returns
Nonefuncresolve_tick(value) -> intCoerce a tick-or-position argument to an absolute tick.
paramvalueint | PositionLikeAn int tick (returned unchanged) or a :data:PositionLike tuple, resolved via
the active tick resolver (see :func:push_tick_resolver) or, if none is set,
a default 4/4 signature.
Returns
intThe absolute tick.
funcdiv_to_tick(numerator, denominator) -> intConvert a numerator/denominator beat fraction to a tick count.
For example div_to_tick(1, 4) is the ticks in a quarter note and
div_to_tick(1, 1) equals TICK_RESOLUTION.
paramnumeratorintFraction numerator (number of divisions).
paramdenominatorintFraction denominator (1..TICK_RESOLUTION).
Returns
intThe duration in ticks.
functick_to_div(ticks) -> DivisionConvert a tick count to the reduced (numerator, denominator) beat fraction.
The inverse of :func:div_to_tick; e.g. one beat's worth of ticks yields (1, 1).
paramticksintNon-negative duration in ticks.
Returns
margrete_rpc.chart.time.DivisionThe reduced (numerator, denominator) beat fraction.
funcresolve_division(value) -> intCoerce a tick-count-or-fraction argument to an int tick count.
paramvalueint | DivisionLikeAn int tick count (returned unchanged) or a :data:DivisionLike
(numerator, denominator) beat fraction, converted via :func:div_to_tick.
Returns
intThe duration in ticks.