Class Trigger

java.lang.Object
org.praxislive.code.userapi.Trigger
Direct Known Subclasses:
TriggerControl

public abstract class Trigger extends Object
A field type for triggers (actions) - see @T. The Trigger type provides a Linkable.Int for listening for triggers, and maintains a count of each time the trigger has been called (useful for sequencing). It is also possible to connect Runnable functions to be called on each trigger.

A field of this type can also be used with the Inject annotation. This is primarily for use with Trigger.Timer for scheduling trigger events when direct external triggering is not required.

  • Constructor Details

    • Trigger

      protected Trigger()
  • Method Details

    • attach

      protected void attach(CodeContext<?> context, Trigger previous)
    • clearLinks

      public Trigger clearLinks()
      Clear all Linkables from this Trigger.
      Returns:
      this
    • link

      public Trigger link(Runnable runnable)
      Run the provided Runnable each time this Trigger is triggered. This method is shorthand for on().link(i -> runnable.run());.
      Parameters:
      runnable - function to run on trigger
      Returns:
      this
    • on

      public Linkable.Int on()
      Returns a new Linkable.Int for listening to each trigger. The int passed to the created linkable will be the same as index, incrementing each time, wrapping at maxIndex.
      Returns:
      new Linkable.Int for reacting to triggers
    • index

      public Trigger index(int idx)
      Set the current index. Must not be negative.
      Parameters:
      idx - new index
      Returns:
      this
    • maxIndex

      public Trigger maxIndex(int max)
      Set the maximum index, at which the index will wrap back to zero.
      Parameters:
      max - maximum index
      Returns:
      this
    • index

      public int index()
      Get the current index.
      Returns:
      current index
    • maxIndex

      public int maxIndex()
      Get the current maximum index.
      Returns:
      maximum index
    • timer

      public Trigger.Timer timer()
      Access the Trigger.Timer for this trigger to schedule one-off or repeat triggering.
      Returns:
      timer for this trigger
    • isScheduled

      public boolean isScheduled()
      Check whether this trigger has a scheduled timer.
      Returns:
      scheduled timer
    • trigger

      public Trigger trigger()
      Manually trigger this Trigger. Useful for chaining this trigger to other sources of input. Otherwise behaves as if externally called, incrementing index and calling linkables.
      Returns:
      this
    • trigger

      protected void trigger(long time)
    • hasLinks

      protected boolean hasLinks()
    • triggerLinks

      protected void triggerLinks()
    • incrementIndex

      protected void incrementIndex()
    • reset

      protected void reset()