Package eu.bandm.tscore.base
Class SyncEventsLong
java.lang.Object
eu.bandm.tscore.base.SyncEventsLong
Step through a strictly increasing sequence of
time points and process the tuple of events (from
a tuple of event sequences) which are "valid" at this particular timepoint.
In most cases these sequences are "voices" and valid events
are "sounding" events = those not playing a "pause" event,
which isrealized by a
Predicate
parameter.
The start timepoints of all events will be normalized to a long
value.
Requires an iterator for each voice which delivers the events in
strictly ascending order of their starting time points.
Each event is considered to last until the next event in the same
voice begins.
Usage:
- Create an instance of a specialized subclass, with
overwritten payload method
process(long)
. Each instance can only be used once. - Load the voices by
addVoice(Iterator, Predicate, Function)
. - Call
apply(Iterator)
with an argument which delivers (at least) all timepoints at which events start. - This code calls
process(long)
for each of these timepoints. This method must be overwritten by the payload code of the user. This can access the registerscurrentEvent
,startsHere
,previousEvent
, etc.
-
Field Summary
FieldsModifier and TypeFieldDescriptionCentral service access point: Output value of all time points when a processed event starts.protected boolean
Whether at least one event starts at the current time point.protected final int
Maximal number of loaded voices, as set when constructing.Events per voice which are currently valid whenprocess(long)
is called.Filter per voice to ignore event, and let its predecessor event still be valid.Iterator per voice which delivers the events ordered by strictly increasing start timepoints.protected int
Counts the number of loaded voices.Cache for the next event which will be copied to be the current event as soon as its starting point will be reached.protected final long[]
Cache for the next event's starting timepoint, normalized to long.Function per voice to calculate the normalized start timepoint.Predecessor event of the current event.protected final boolean[]
Whether the event in the voice with the given number starts exactly at the current timepoint. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddVoice
(Iterator<Event> iterator, @Opt Predicate<Event> ignoreEvent, Function<Event, Long> normalize) Central service access point: Add a voice to the lowest not yet assigned slot.void
Central service access point: Steps through all timepoints and all events and calls the overwritten payload methodprocess(long)
for all Events currently valid then.protected void
loadCache
(int i) Internal aux method for performance: Loads the next event from the iterator (identified by voice number) into the cache and calculates its normalized start timepoint.protected void
oneStep
(long currentNormalized) Internal aux function which finds all valid events at the current moment and then calls the user's payload methodprocess(long)
.abstract void
process
(long currentTp) Central service access point: The payload method overwritten by the user.
-
Field Details
-
countVoices
protected final int countVoicesMaximal number of loaded voices, as set when constructing. -
loaded
protected int loadedCounts the number of loaded voices. Can be read by the user's payload codeprocess(long)
. -
ignoreEvent
Filter per voice to ignore event, and let its predecessor event still be valid. -
normalize
Function per voice to calculate the normalized start timepoint. -
iterators
Iterator per voice which delivers the events ordered by strictly increasing start timepoints. -
currentEvent
Events per voice which are currently valid whenprocess(long)
is called. An array slot is null when the corresponding voice is not loaded or has reached its end. -
startsHere
protected final boolean[] startsHereWhether the event in the voice with the given number starts exactly at the current timepoint. Can be read by the user's payload codeprocess(long)
. -
nextEvent
Cache for the next event which will be copied to be the current event as soon as its starting point will be reached. Internal cache for perfomance only. -
previousEvent
Predecessor event of the current event. In general it is only sensible to read when the current event starts here. Can be read by the user's payload codeprocess(long)
. -
nextNormalized
protected final long[] nextNormalizedCache for the next event's starting timepoint, normalized to long. Internal cache for perfomance only. -
atLeastOneEventStartsHere
protected boolean atLeastOneEventStartsHereWhether at least one event starts at the current time point. Can be read by the user's payload codeprocess(long)
. -
allTps
Central service access point: Output value of all time points when a processed event starts.
-
-
Constructor Details
-
SyncEventsLong
public SyncEventsLong(int countVoices) Only constructor.- Parameters:
countVoices
- the maximal number of voices which can be added to this instance.
-
-
Method Details
-
addVoice
public SyncEventsLong addVoice(Iterator<Event> iterator, @Opt @Opt Predicate<Event> ignoreEvent, Function<Event, Long> normalize) Central service access point: Add a voice to the lowest not yet assigned slot.- Parameters:
iterator
- must step through the events of the voice in strictly ascending order of their start timepoints.ignoreEvent
- a predicate which filters out an event and instead lets its predecessor sill be valid.- Throws:
ArrayIndexOutOfBoundsException
- if called more thancountVoices
times.IllegalArgumentException
- if a non-opt argument is null.
-
loadCache
protected void loadCache(int i) Internal aux method for performance: Loads the next event from the iterator (identified by voice number) into the cache and calculates its normalized start timepoint. Events which pass the test inignoreEvent
are skipped. When the end is reached, null is stored and the maximum numeric value is memorized at its start value. -
apply
Central service access point: Steps through all timepoints and all events and calls the overwritten payload methodprocess(long)
for all Events currently valid then.- Parameters:
tps
- Iterator of all timepoints. Attention all starting points of all events must be contained in the set of delivered timepoints, otherwise the behaviour is unspecified.
-
oneStep
protected void oneStep(long currentNormalized) Internal aux function which finds all valid events at the current moment and then calls the user's payload methodprocess(long)
. Transfers all events from the cache tocurrentEvent
when they start at the reached time point. In this case the cache is filled with the next event and its normalized starting timepoint is calculated.- Parameters:
currentNormalized
- the time point to look at.
-
process
public abstract void process(long currentTp) Central service access point: The payload method overwritten by the user. It is called for the ascending timepoints as given explicitly toapply(Iterator)
. The code can readcurrentEvent
,startsHere
,atLeastOneEventStartsHere
, andpreviousEvent
.
-