- java.lang.Object
-
- org.praxislive.code.CodeDelegate
-
- org.praxislive.code.DefaultCodeDelegate
-
- Direct Known Subclasses:
AudioCodeDelegate,CoreCodeDelegate,P2DCodeDelegate,P3DCodeDelegate,TFCodeDelegate,VideoCodeDelegate
public class DefaultCodeDelegate extends CodeDelegate
Default base for code delegates providing a variety of functions.
-
-
Constructor Summary
Constructors Constructor Description DefaultCodeDelegate()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description doubleabs(double n)Calculate the absolute value of the given value.doubleacos(double value)Returns the arc cosine of a value.PArrayarray(String s)Parse the given String into aPArray.PArrayarray(Property p)Attempt to extract aPArrayfrom the given Property.PArrayarray(Value v)Convert the given Value into aPArray.voidarrayCopy(Object src, int srcPosition, Object dst, int dstPosition, int length)Copies an array (or part of an array) to another array.voidarrayCopy(Object src, Object dst)Copies an array to another array.voidarrayCopy(Object src, Object dst, int length)Copies an array (or part of an array) to another array.doubleasin(double value)Returns the arc sine of a value.doubleatan(double value)Returns the arc tangent of a value.doubleatan2(double y, double x)Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).booleanb(String s)Parse the given String into a boolean according to the parsing rules ofPBoolean.booleanb(Property p)Extract the Property's current value as a boolean.booleanb(Value v)Convert the provided Value into a boolean according to the parsing rules ofPBoolean.doubleconstrain(double amt, double low, double high)Constrain a value between the range of the given low and high values.intconstrain(int amt, int low, int high)Constrain a value between the range of the given low and high values.doublecos(double angle)Returns the trigonometric cosine of an angle.doubled(String s)Parse the provided String into a double, or zero if invalid.doubled(Property p)Extract a double from the Property's current Value, or zero if the value cannot be coerced.doubled(Value v)Convert the provided Value into a double, or zero if the Value cannot be coerced.doubledegrees(double radians)Converts an angle in radians to an angle in degrees.doubledist(double x1, double y1, double x2, double y2)Calculates the distance between two points.doubledist(double x1, double y1, double z1, double x2, double y2, double z2)Calculates the distance between two points.doubleexp(double a)Calculate Euler's number raised to the power of the given value.<T> Optional<T>find(Class<T> type)Search for an instance of the given type.LookupgetLookup()Return a Lookup for finding instances of features.inti(String s)Parse the provided String into an int, or zero if invalid.inti(Property p)Extract an int from the Property's current Value, or zero if the value cannot be coerced.inti(Value v)Convert the provided Value into an int, or zero if the Value cannot be coerced.booleanisLoggable(LogLevel level)Check whether the messages at the given log level are being sent.doublelerp(double start, double stop, double amt)Calculates a number between two numbers at a specific increment.doublelog(double a)Calculate the natural logarithm if the given value.voidlog(LogLevel level, Class<? extends Exception> type, String msg)Send a log message with associated Exception type.voidlog(LogLevel level, Exception ex)Send a log message with associated Exception type.voidlog(LogLevel level, Exception ex, String msg)Send a log message with associated Exception.voidlog(LogLevel level, String msg)Send a log message.doublemap(double value, double start1, double stop1, double start2, double stop2)Re-map (scale) an input value from one range to another.doublemax(double... values)Calculate the maximum value in the provided array.doublemax(double a, double b)Calculate the maximum of two values.doublemax(double a, double b, double c)Calculate the maximum of three values.intmax(int... values)Calculate the maximum value in the provided array.intmax(int a, int b)Calculate the maximum of two values.intmax(int a, int b, int c)Calculate the maximum of three values.longmillis()The current time in milliseconds since the root was started.doublemin(double... values)Calculate the minimum value in the provided array.doublemin(double a, double b)Calculate the minimum of two values.doublemin(double a, double b, double c)Calculate the minimum of three values.intmin(int... values)Calculate the minimum value in the provided array.intmin(int a, int b)Calculate the minimum of two values.intmin(int a, int b, int c)Calculate the minimum of three values.doublenoise(double x)Computes the Perlin noise function value at point x.doublenoise(double x, double y)Computes the Perlin noise function value at the point x, y.doublenoise(double x, double y, double z)Computes the Perlin noise function value at x, y, z.voidnoiseDetail(int lod)voidnoiseDetail(int lod, double falloff)voidnoiseSeed(long what)doublenorm(double value, double start, double stop)Normalizes a number from another range into a value between 0 and 1.doublepow(double a, double b)Calculate the value of the first argument raised to the power of the second argument.doubleradians(double degrees)Converts an angle in degrees to an angle in radians.doublerandom(double max)Return a random number between zero and max (exclusive)doublerandom(double min, double max)Return a random number between min (inclusive) and max (exclusive)doublerandomOf(double... values)Return a random element from an array of values.intrandomOf(int... values)Return a random element from an array of values.StringrandomOf(String... values)Return a random element from an array of values.intround(double amt)Round a value to the nearest integer.Strings(Property p)Extract the Property's current value into a String representation.Strings(Value v)Convert the provided Value into a String representation.ComponentAddressself()Get this component's address.ControlAddressself(String control)Get the address of a control on this component.doublesin(double angle)Returns the trigonometric sine of an angledoublesq(double a)Calculate the square of the given value.doublesqrt(double a)Calculate the square root of the given value.doubletan(double angle)Returns the trigonometric tangent of an angle.voidtell(ControlAddress destination, double value)Send a message to a Control.voidtell(ControlAddress destination, String value)Send a message to a Control.voidtell(ControlAddress destination, Value value)Send a message to a Control.voidtellIn(double seconds, ControlAddress destination, double value)Send a message to a Control in the given number of seconds or fractions of second from now.voidtellIn(double seconds, ControlAddress destination, String value)Send a message to a Control in the given number of seconds or fractions of second from now.voidtellIn(double seconds, ControlAddress destination, Value value)Send a message to a Control in the given number of seconds or fractions of second from now.longtime()The current clocktime in nanoseconds.voidtransmit(String componentID, String portID, double value)Send a value to a port on another component.voidtransmit(String componentID, String portID, String value)Send a value to a port on another component.voidtransmit(String componentID, String portID, Value value)Send a value to a port on another component.
-
-
-
Field Detail
-
RND
protected final Random RND
-
-
Method Detail
-
log
public final void log(LogLevel level, String msg)
Send a log message.- Parameters:
level-msg-
-
log
public final void log(LogLevel level, Exception ex)
Send a log message with associated Exception type.- Parameters:
level-ex-
-
log
public final void log(LogLevel level, Exception ex, String msg)
Send a log message with associated Exception.- Parameters:
level-ex-msg-
-
log
public final void log(LogLevel level, Class<? extends Exception> type, String msg)
Send a log message with associated Exception type.- Parameters:
level-type-msg-
-
isLoggable
public final boolean isLoggable(LogLevel level)
Check whether the messages at the given log level are being sent.- Parameters:
level-- Returns:
-
transmit
public final void transmit(String componentID, String portID, String value)
Send a value to a port on another component. The other component must have the same parent.- Parameters:
componentID- ID of the other componentportID- ID of the port on the other componentvalue-
-
transmit
public final void transmit(String componentID, String portID, Value value)
Send a value to a port on another component. The other component must have the same parent.- Parameters:
componentID- ID of the other componentportID- ID of the port on the other componentvalue-
-
transmit
public final void transmit(String componentID, String portID, double value)
Send a value to a port on another component. The other component must have the same parent.- Parameters:
componentID- ID of the other componentportID- ID of the port on the other componentvalue-
-
tell
public final void tell(ControlAddress destination, String value)
Send a message to a Control.- Parameters:
destination- address of controlvalue- message value
-
tell
public final void tell(ControlAddress destination, double value)
Send a message to a Control.- Parameters:
destination- address of controlvalue- message value
-
tell
public final void tell(ControlAddress destination, Value value)
Send a message to a Control.- Parameters:
destination- address of controlvalue- message value
-
tellIn
public final void tellIn(double seconds, ControlAddress destination, String value)Send a message to a Control in the given number of seconds or fractions of second from now.- Parameters:
seconds- from nowdestination- address of controlvalue- message value
-
tellIn
public final void tellIn(double seconds, ControlAddress destination, double value)Send a message to a Control in the given number of seconds or fractions of second from now.- Parameters:
seconds- from nowdestination- address of controlvalue- message value
-
tellIn
public final void tellIn(double seconds, ControlAddress destination, Value value)Send a message to a Control in the given number of seconds or fractions of second from now.- Parameters:
seconds- from nowdestination- address of controlvalue- message value
-
self
public final ComponentAddress self()
Get this component's address.- Returns:
- address of self
-
self
public final ControlAddress self(String control)
Get the address of a control on this component.- Parameters:
control- id of control- Returns:
- address of control
-
getLookup
public Lookup getLookup()
Return a Lookup for finding instances of features.- Returns:
- Lookup context
-
find
public <T> Optional<T> find(Class<T> type)
Search for an instance of the given type.- Type Parameters:
T-- Parameters:
type- class to search for- Returns:
- Optional wrapping the result if found, or empty if not
-
time
public final long time()
The current clocktime in nanoseconds. May only be used relatively to itself, and may be negative.- Returns:
-
millis
public final long millis()
The current time in milliseconds since the root was started.- Returns:
-
d
public final double d(Property p)
Extract a double from the Property's current Value, or zero if the value cannot be coerced.- Parameters:
p-- Returns:
-
d
public final double d(Value v)
Convert the provided Value into a double, or zero if the Value cannot be coerced.- Parameters:
v-- Returns:
-
d
public final double d(String s)
Parse the provided String into a double, or zero if invalid.- Parameters:
s-- Returns:
-
i
public final int i(Property p)
Extract an int from the Property's current Value, or zero if the value cannot be coerced.- Parameters:
p-- Returns:
-
i
public final int i(Value v)
Convert the provided Value into an int, or zero if the Value cannot be coerced.- Parameters:
v-- Returns:
-
i
public final int i(String s)
Parse the provided String into an int, or zero if invalid.- Parameters:
s-- Returns:
-
b
public final boolean b(Property p)
Extract the Property's current value as a boolean. If the value cannot be coerced, returns false.- Parameters:
p-- Returns:
-
b
public final boolean b(Value v)
Convert the provided Value into a boolean according to the parsing rules ofPBoolean. If the Value cannot be coerced, returns false.- Parameters:
v-- Returns:
-
b
public final boolean b(String s)
Parse the given String into a boolean according to the parsing rules ofPBoolean. If the String is invalid, returns false.- Parameters:
s-- Returns:
-
s
public final String s(Property p)
Extract the Property's current value into a String representation.- Parameters:
p-- Returns:
-
s
public final String s(Value v)
Convert the provided Value into a String representation.- Parameters:
v-- Returns:
-
array
public final PArray array(Property p)
Attempt to extract aPArrayfrom the given Property. An empty PArray will be returned if the property's value is not a PArray and cannot be coerced.- Parameters:
p-- Returns:
- See Also:
array(org.praxislive.core.types.Value)
-
array
public final PArray array(Value v)
Convert the given Value into aPArray. If the Value is already a PArray it will be returned, otherwise an attempt will be made to coerce it. If the Value cannot be converted, an empty PArray will be returned.- Parameters:
s-- Returns:
-
array
public final PArray array(String s)
Parse the given String into aPArray. If the String is not a valid representation of an array, returns an empty PArray.- Parameters:
s-- Returns:
-
random
public final double random(double max)
Return a random number between zero and max (exclusive)- Parameters:
max- the upper bound of the range- Returns:
-
random
public final double random(double min, double max)Return a random number between min (inclusive) and max (exclusive)- Parameters:
min- the lower bound of the rangemax- the upper bound of the range- Returns:
-
randomOf
public final double randomOf(double... values)
Return a random element from an array of values.- Parameters:
values- list of values, may not be empty- Returns:
- random element
-
randomOf
public final int randomOf(int... values)
Return a random element from an array of values.- Parameters:
values- list of values, may not be empty- Returns:
- random element
-
randomOf
public final String randomOf(String... values)
Return a random element from an array of values.- Parameters:
values- list of values, may not be empty- Returns:
- random element
-
abs
public final double abs(double n)
Calculate the absolute value of the given value. If the value is positive, the value is returned. If the value is negative, the negation of the value is returned.- Parameters:
n-- Returns:
-
sq
public final double sq(double a)
Calculate the square of the given value.- Parameters:
a-- Returns:
-
sqrt
public final double sqrt(double a)
Calculate the square root of the given value.- Parameters:
a-- Returns:
- See Also:
Math.sqrt(double)
-
log
public final double log(double a)
Calculate the natural logarithm if the given value.- Parameters:
a-- Returns:
- See Also:
Math.log(double)
-
exp
public final double exp(double a)
Calculate Euler's number raised to the power of the given value.- Parameters:
a-- Returns:
- See Also:
Math.exp(double)
-
pow
public final double pow(double a, double b)Calculate the value of the first argument raised to the power of the second argument.- Parameters:
a- the baseb- the exponent- Returns:
- the value ab
- See Also:
Math.pow(double, double)
-
max
public final int max(int a, int b)Calculate the maximum of two values.- Parameters:
a-b-- Returns:
-
max
public final int max(int a, int b, int c)Calculate the maximum of three values.- Parameters:
a-b-c-- Returns:
-
max
public final int max(int... values)
Calculate the maximum value in the provided array.- Parameters:
values- value list - must not be empty- Returns:
- maximum value
-
max
public final double max(double a, double b)Calculate the maximum of two values.- Parameters:
a-b-- Returns:
-
max
public final double max(double a, double b, double c)Calculate the maximum of three values.- Parameters:
a-b-c-- Returns:
-
max
public final double max(double... values)
Calculate the maximum value in the provided array.- Parameters:
values- value list - must not be empty- Returns:
- maximum value
-
min
public final int min(int a, int b)Calculate the minimum of two values.- Parameters:
a-b-- Returns:
-
min
public final int min(int a, int b, int c)Calculate the minimum of three values.- Parameters:
a-b-c-- Returns:
-
min
public final int min(int... values)
Calculate the minimum value in the provided array.- Parameters:
values- value list - must not be empty- Returns:
- minimum value
-
min
public final double min(double a, double b)Calculate the minimum of two values.- Parameters:
a-b-- Returns:
-
min
public final double min(double a, double b, double c)Calculate the minimum of three values.- Parameters:
a-b-c-- Returns:
-
min
public final double min(double... values)
Calculate the minimum value in the provided array.- Parameters:
values- value list - must not be empty- Returns:
- minimum value
-
constrain
public final int constrain(int amt, int low, int high)Constrain a value between the range of the given low and high values.- Parameters:
amt- input valuelow- lowest allowed valuehigh- highest allowed value- Returns:
- constrained value
-
constrain
public final double constrain(double amt, double low, double high)Constrain a value between the range of the given low and high values.- Parameters:
amt- input valuelow- lowest allowed valuehigh- highest allowed value- Returns:
- constrained value
-
round
public final int round(double amt)
Round a value to the nearest integer.- Parameters:
amt- input value- Returns:
- rounded value
-
degrees
public final double degrees(double radians)
Converts an angle in radians to an angle in degrees.- Parameters:
radians-- Returns:
- See Also:
Math.toDegrees(double)
-
radians
public final double radians(double degrees)
Converts an angle in degrees to an angle in radians.- Parameters:
degrees-- Returns:
- See Also:
Math.toRadians(double)
-
sin
public final double sin(double angle)
Returns the trigonometric sine of an angle- Parameters:
angle-- Returns:
- See Also:
Math.sin(double)
-
cos
public final double cos(double angle)
Returns the trigonometric cosine of an angle.- Parameters:
angle-- Returns:
- See Also:
Math.cos(double)
-
tan
public final double tan(double angle)
Returns the trigonometric tangent of an angle.- Parameters:
angle-- Returns:
- See Also:
Math.tan(double)
-
asin
public final double asin(double value)
Returns the arc sine of a value.- Parameters:
value-- Returns:
- See Also:
Math.asin(double)
-
acos
public final double acos(double value)
Returns the arc cosine of a value.- Parameters:
value-- Returns:
- See Also:
Math.acos(double)
-
atan
public final double atan(double value)
Returns the arc tangent of a value.- Parameters:
value-- Returns:
- See Also:
Math.atan(double)
-
atan2
public final double atan2(double y, double x)Returns the angle theta from the conversion of rectangular coordinates (x, y) to polar coordinates (r, theta).- Parameters:
y-x-- Returns:
- See Also:
Math.atan2(double, double)
-
map
public final double map(double value, double start1, double stop1, double start2, double stop2)Re-map (scale) an input value from one range to another. Numbers outside the range are not clamped.- Parameters:
value- the value to be convertedstart1- lower bound of the value's current rangestop1- upper bound of the value's current rangestart2- lower bound of the value's target rangestop2- upper bound of the value's target range- Returns:
-
dist
public final double dist(double x1, double y1, double x2, double y2)Calculates the distance between two points.- Parameters:
x1- x-coordinate of the first pointy1- y-coordinate of the first pointx2- x-coordinate of the second pointy2- y-coordinate of the second point- Returns:
-
dist
public final double dist(double x1, double y1, double z1, double x2, double y2, double z2)Calculates the distance between two points.- Parameters:
x1- x-coordinate of the first pointy1- y-coordinate of the first pointz1- z-coordinate of the first pointx2- x-coordinate of the second pointy2- y-coordinate of the second pointz2- z-coordinate of the second point- Returns:
-
lerp
public final double lerp(double start, double stop, double amt)Calculates a number between two numbers at a specific increment. The amt parameter is the amount to interpolate between the two values where 0.0 equal to the first point, 0.1 is very near the first point, 0.5 is half-way in between, etc. The lerp function is convenient for creating motion along a straight path and for drawing dotted lines.- Parameters:
start- first valuestop- second valueamt- between 0.0 and 1.0- Returns:
-
norm
public final double norm(double value, double start, double stop)Normalizes a number from another range into a value between 0 and 1.Identical to map(value, low, high, 0, 1);
Numbers outside the range are not clamped to 0 and 1, because out-of-range values are often intentional and useful.
- Parameters:
value- the incoming value to be convertedstart- lower bound of the value's current rangestop- upper bound of the value's current range- Returns:
-
noise
public final double noise(double x)
Computes the Perlin noise function value at point x.- Parameters:
x-- Returns:
-
noise
public final double noise(double x, double y)Computes the Perlin noise function value at the point x, y.- Parameters:
x-y-- Returns:
-
noise
public final double noise(double x, double y, double z)Computes the Perlin noise function value at x, y, z.- Parameters:
x-z-y-- Returns:
-
noiseDetail
public final void noiseDetail(int lod)
- Parameters:
lod-
-
noiseDetail
public final void noiseDetail(int lod, double falloff)- Parameters:
lod-falloff-
-
noiseSeed
public final void noiseSeed(long what)
- Parameters:
what-
-
arrayCopy
public final void arrayCopy(Object src, int srcPosition, Object dst, int dstPosition, int length)
Copies an array (or part of an array) to another array. The src array is copied to the dst array, beginning at the position specified by srcPos and into the position specified by dstPos. The number of elements to copy is determined by length.- Parameters:
src-srcPosition-dst-dstPosition-length-
-
arrayCopy
public final void arrayCopy(Object src, Object dst, int length)
Copies an array (or part of an array) to another array. The src array is copied to the dst array. The number of elements to copy is determined by length.- Parameters:
src-dst-length-
-
-