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.-
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.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.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
-
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()
-