Class SyncEventsFloat

java.lang.Object
eu.bandm.tscore.base.SyncEventsFloat

public abstract class SyncEventsFloat extends Object
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 float 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:
  1. Create an instance of a specialized subclass, with overwritten payload method process(float). Each instance can only be used once.
  2. Load the voices by addVoice(Iterator, Predicate, Function).
  3. Call apply(Iterator) with an argument which delivers (at least) all timepoints at which events start.
  4. This code calls process(float) for each of these timepoints. This method must be overwritten by the payload code of the user. This can access the registers currentEvent, startsHere, previousEvent, etc.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected SortedSet<Float>
    Central 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.
    protected final @Opt Event[]
    Events per voice which are currently valid when process(float) is called.
    protected final @Opt Predicate<Event>[]
    Filter per voice to ignore event, and let its predecessor event still be valid.
    protected final Iterator<Event>[]
    Iterator per voice which delivers the events ordered by strictly increasing start timepoints.
    protected int
    Counts the number of loaded voices.
    protected final @Opt Event[]
    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 float[]
    Cache for the next event's starting timepoint, normalized to float.
    protected final Function<Event,Float>[]
    Function per voice to calculate the normalized start timepoint.
    protected final @Opt Event[]
    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
    Constructor
    Description
    SyncEventsFloat(int countVoices)
    Only constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    addVoice(Iterator<Event> iterator, @Opt Predicate<Event> ignoreEvent, Function<Event,Float> 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 method process(float) 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(float currentNormalized)
    Internal aux function which finds all valid events at the current moment and then calls the user's payload method process(float).
    abstract void
    process(float currentTp)
    Central service access point: The payload method overwritten by the user.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • countVoices

      protected final int countVoices
      Maximal number of loaded voices, as set when constructing.
    • loaded

      protected int loaded
      Counts the number of loaded voices. Can be read by the user's payload code process(float).
    • ignoreEvent

      @Opt protected final @Opt Predicate<Event>[] ignoreEvent
      Filter per voice to ignore event, and let its predecessor event still be valid.
    • normalize

      protected final Function<Event,Float>[] normalize
      Function per voice to calculate the normalized start timepoint.
    • iterators

      protected final Iterator<Event>[] iterators
      Iterator per voice which delivers the events ordered by strictly increasing start timepoints.
    • currentEvent

      @Opt protected final @Opt Event[] currentEvent
      Events per voice which are currently valid when process(float) is called. An array slot is null when the corresponding voice is not loaded or has reached its end.
    • startsHere

      protected final boolean[] startsHere
      Whether the event in the voice with the given number starts exactly at the current timepoint. Can be read by the user's payload code process(float).
    • nextEvent

      @Opt protected final @Opt Event[] 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

      @Opt protected final @Opt Event[] 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 code process(float).
    • nextNormalized

      protected final float[] nextNormalized
      Cache for the next event's starting timepoint, normalized to float. Internal cache for perfomance only.
    • atLeastOneEventStartsHere

      protected boolean atLeastOneEventStartsHere
      Whether at least one event starts at the current time point. Can be read by the user's payload code process(float).
    • allTps

      protected SortedSet<Float> allTps
      Central service access point: Output value of all time points when a processed event starts.
  • Constructor Details

    • SyncEventsFloat

      public SyncEventsFloat(int countVoices)
      Only constructor.
      Parameters:
      countVoices - the maximal number of voices which can be added to this instance.
  • Method Details

    • addVoice

      public SyncEventsFloat addVoice(Iterator<Event> iterator, @Opt @Opt Predicate<Event> ignoreEvent, Function<Event,Float> 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 than countVoices 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 in ignoreEvent are skipped. When the end is reached, null is stored and the maximum numeric value is memorized at its start value.
    • apply

      public void apply(Iterator<Float> tps)
      Central service access point: Steps through all timepoints and all events and calls the overwritten payload method process(float) 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(float currentNormalized)
      Internal aux function which finds all valid events at the current moment and then calls the user's payload method process(float). Transfers all events from the cache to currentEvent 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(float currentTp)
      Central service access point: The payload method overwritten by the user. It is called for the ascending timepoints as given explicitly to apply(Iterator). The code can read currentEvent, startsHere, atLeastOneEventStartsHere, and previousEvent.