java.lang.Object
org.praxislive.code.userapi.Trigger
- Direct Known Subclasses:
TriggerControl
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.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classA timer used for scheduling one-off or repeat invocations of aTrigger. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidattach(CodeContext<?> context, Trigger previous) Clear all Linkables from this Trigger.protected booleanhasLinks()protected voidintindex()Get the current index.index(int idx) Set the current index.booleanCheck whether this trigger has a scheduled timer.Run the provided Runnable each time this Trigger is triggered.intmaxIndex()Get the current maximum index.maxIndex(int max) Set the maximum index, at which the index will wrap back to zero.on()Returns a newLinkable.Intfor listening to each trigger.protected voidreset()timer()Access theTrigger.Timerfor this trigger to schedule one-off or repeat triggering.trigger()Manually trigger this Trigger.protected voidtrigger(long time) protected void
-
Constructor Details
-
Trigger
protected Trigger()
-
-
Method Details
-
attach
-
clearLinks
Clear all Linkables from this Trigger.- Returns:
- this
-
link
Run the provided Runnable each time this Trigger is triggered. This method is shorthand foron().link(i -> runnable.run());.- Parameters:
runnable- function to run on trigger- Returns:
- this
-
on
Returns a newLinkable.Intfor 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
Set the current index. Must not be negative.- Parameters:
idx- new index- Returns:
- this
-
maxIndex
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
Access theTrigger.Timerfor 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
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()
-