- 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.
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
Trigger()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
attach(CodeContext<?> context, Trigger previous)
Trigger
clearLinks()
Clear all Linkables from this Trigger.protected boolean
hasLinks()
protected void
incrementIndex()
int
index()
Get the current index.Trigger
index(int idx)
Set the current index.Trigger
link(Runnable runnable)
Run the provided Runnable each time this Trigger is triggered.int
maxIndex()
Get the current maximum index.Trigger
maxIndex(int max)
Set the maximum index, at which the index will wrap back to zero.Linkable.Int
on()
Returns a newLinkable.Int
for listening to each trigger.Trigger
trigger()
Manually trigger this Trigger.protected void
trigger(long time)
protected void
triggerLinks()
-
-
-
Method Detail
-
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 foron().link(i -> runnable.run());
.- Parameters:
runnable
- function to run on trigger- Returns:
- this
-
on
public Linkable.Int on()
Returns a newLinkable.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
-
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()
-
-