public class Pattern extends Object implements Cloneable
following(com.corajr.loom.Pattern)
, multiple mappings can be assigned.ConcretePattern
Modifier and Type | Class and Description |
---|---|
static class |
Pattern.MappingType
Constants for each possible mapping from floating-point values to output.
|
Constructor and Description |
---|
Pattern(Loom loom)
Constructor for an empty Pattern.
|
Pattern(Loom loom,
Collection<LEvent> events)
A pattern comprised of the specified events.
|
Pattern(Loom loom,
ContinuousFunction function)
A pattern with a value that is a continuous function of time.
|
Pattern(Loom loom,
double defaultValue)
A pattern that returns a constant value between 0.0 and 1.0.
|
Pattern(Loom loom,
EventCollection events)
A pattern comprised of the specified events.
|
Pattern(Loom loom,
EventCollection events,
ContinuousFunction function,
boolean isConcrete)
Creates a Pattern and adds itself to the
Loom . |
Pattern(Loom loom,
LEvent... events)
A pattern comprised of the specified events.
|
Modifier and Type | Method and Description |
---|---|
void |
addAllTurtleDrawCommands() |
Pattern |
after(BigFraction offset,
Callable<Void> callable)
Triggers the specified callback after a given amount of time.
|
Pattern |
after(BigFraction offset,
LEvent... eventsToAdd)
Adds events to the pattern at a certain time offset.
|
Pattern |
after(BigFraction offset,
Transform transform)
Triggers the specified transform after a given amount of time.
|
Pattern |
after(double time,
Callable<Void> callable)
Triggers the specified callback after a given amount of time.
|
Pattern |
after(double time,
LEvent... eventsToAdd)
Adds events to the pattern at a certain time offset.
|
Pattern |
after(double offset,
Transform transform)
Triggers the specified transform after a given amount of time.
|
Callable<Object> |
asCallable() |
Pattern |
asCallable(Callable<?>... callables) |
int |
asColor() |
Pattern |
asColor(int... colors)
Set a mapping from the pattern's events to colors, blending between them
using
lerpColor in HSB mode. |
DrawCommand |
asDrawCommand() |
Pattern |
asDrawCommand(DrawCommand... commands) |
float |
asFloat()
Returns the current float value of this pattern according to the
previously set FloatMapping.
|
Pattern |
asFloat(float lo,
float hi)
Set the mapping from this pattern's values to floats.
|
int |
asInt()
Returns the current int value of this pattern according to the previously
set IntMapping.
|
Pattern |
asInt(int lo,
int hi)
Set the mapping from this pattern's values to integers.
|
int |
asMidiChannel()
Gets the current MIDI channel for this pattern.
|
Pattern |
asMidiChannel(Integer... channels)
Sets the mapping of this pattern's values to MIDI channels.
|
int |
asMidiChannel(Interval now) |
int |
asMidiCommand()
Gets the current MIDI command for this pattern.
|
Pattern |
asMidiCommand(Integer... commands)
Maps this pattern's values to the specified MIDI commands.
|
int |
asMidiCommand(Interval now) |
int |
asMidiData1()
Returns the current value of MIDI data 1.
|
int |
asMidiData1(Interval now) |
Pattern |
asMidiData1(int lo,
int hi)
Maps the pattern's values to MIDI data byte 1.
|
int |
asMidiData2()
Returns the current MIDI data 2 value for this pattern.
|
int |
asMidiData2(Interval now) |
Pattern |
asMidiData2(int lo,
int hi)
Maps the pattern's values to MIDI data 2.
|
Pattern |
asMidiInstrument(MidiTools.Instrument instrument)
Set a mapping from the pattern's events to MIDI notes, using a specified
instrument.
|
Pattern |
asMidiInstrument(String instrument)
Set a mapping from the pattern's events to MIDI notes, using a specified
instrument.
|
Pattern |
asMidiMessage(Pattern notes)
Maps the specified note pattern as a MIDI message, which will be
Typically this will be called using the pattern itself as argument, i.e.
|
Pattern |
asMidiMessage(Pattern commands,
Pattern channels,
Pattern notes,
Pattern velocities)
Maps the current pattern to MIDI messages and schedules them to be sent
out using the Loom's
MidiBusWrapper . |
int |
asMidiNote()
Returns the current MIDI note.
|
Pattern |
asMidiNote(Integer... values)
Maps the values of this pattern to MIDI notes.
|
Pattern |
asMidiPercussion(MidiTools.Percussion sound)
Set a mapping from the pattern's events to a percussive sound.
|
Pattern |
asMidiPercussion(String sound)
Set a mapping from the pattern's events to a percussive sound.
|
Object |
asObject() |
Pattern |
asObject(Object... objects) |
OscBundle |
asOscBundle()
Returns the pattern's value as an OSC bundle.
|
Pattern |
asOscBundle(NetAddress remoteAddress)
Sets a mapping to wrap up the OSC messages for this pattern's onsets into
bundles and schedules them to be sent using the Loom's
OscP5Wrapper . |
Pattern |
asOscBundle(NetAddress remoteAddress,
Pattern... patterns)
Sets a mapping to wrap up the OSC messages for this pattern's onsets into
bundles and schedules them to be sent using the Loom's
OscP5Wrapper . |
OscMessage |
asOscMessage()
Returns the current OSC message value of this pattern.
|
Pattern |
asOscMessage(String addressPattern)
Maps this pattern to an OSC message with a default argument of 1.
|
Pattern |
asOscMessage(String addressPattern,
int value)
Maps this pattern to an OSC message with a single integer argument.
|
Pattern |
asOscMessage(String addressPattern,
Mapping<?> mapping)
Sets a mapping of this pattern to OSC messages, with a new
Mapping used to provide the arguments. |
Pattern |
asOscMessage(String addressPattern,
Pattern subPattern,
Mapping<?> mapping)
Sets this pattern's mapping to OSC messages, using a second pattern
subPattern to provide the values that will be translated
into the message's arguments. |
Pattern |
asSample(AudioSample sample)
Sets a mapping that triggers a Minim AudioSample when this pattern's
events have a value of 1.0.
|
Pattern |
asSoundFile(SoundFile soundFile)
Sets a mapping that triggers a SoundFile when this pattern's
events have a value of 1.0.
|
StatefulCallable |
asStatefulCallable() |
Pattern |
asStatefulCallable(StatefulCallable... callables) |
Pattern |
asSynthParam(Synth synth,
String param,
float lo,
float hi)
Sets a mapping from this pattern to the parameters of a
supercollider.Synth object.
|
TurtleDrawCommand |
asTurtleDrawCommand() |
Pattern |
asTurtleDrawCommand(boolean clearing,
TurtleDrawCommand... commands) |
Pattern |
asTurtleDrawCommand(TurtleDrawCommand... commands) |
Pattern |
clear() |
Pattern |
clone() |
Pattern |
delay(BigFraction amt) |
Pattern |
delay(double amt) |
void |
draw() |
Pattern |
every(BigFraction fraction,
Callable<Void> callable) |
Pattern |
every(double cycles,
Callable<Void> callable) |
Pattern |
every(double cycles,
Transform transform) |
Pattern |
extend(BigFraction offset,
Collection<LEvent> newEvents)
Extends the pattern by adding the given events after a specified offset.
|
Pattern |
extend(BigFraction offset,
LEvent... newEvents)
Extends the pattern by adding the given events after a specified offset.
|
Pattern |
extend(Collection<LEvent> newEvents)
Extends the pattern by adding the events specified after the last event
currently in the pattern.
|
Pattern |
extend(double offset,
LEvent... newEvents)
Extends the pattern by adding the given events after a specified offset.
|
Pattern |
extend(Integer... ints)
Extends the current pattern by treating the input as equally spaced
events within a single cycle.
|
Pattern |
extend(LEvent... events)
Extends the pattern by adding the events specified after the last event
currently in the pattern.
|
Pattern |
extend(String string)
Extends the current pattern by treating the input as equally spaced
events within a single cycle.
|
static Pattern |
following(Pattern other)
Create a new pattern that returns the same value as another.
|
static Pattern |
fromABC(Loom loom,
String tune)
Takes an ABC tune as input and creates a new pattern suitable for MIDI
output.
|
static Pattern |
fromInts(Loom loom,
Integer... ints)
Creates a new pattern using a sequence of integers, which will be turned
into equally spaced events.
|
static Pattern |
fromString(Loom loom,
String string)
Creates a new pattern using a numerical string, which will be turned into
equally spaced events.
|
Collection<Callable<?>> |
getActiveMappingsFor(Interval interval) |
Interval |
getCurrentInterval()
Returns the current interval from the perspective of this pattern,
transformed by its time scale, offset, and loop interval (if applicable).
|
Interval |
getCurrentInterval(boolean useOffset)
Returns the current interval from the perspective of this pattern,
transformed by its time scale, offset, and loop interval (if applicable).
|
Collection<DrawCommand> |
getDrawCommands() |
Interval |
getLoopInterval() |
BigFraction |
getMinimumResolution() |
ConcurrentMap<Pattern.MappingType,Mapping<?>> |
getOutputMappings() |
int |
getRepeats() |
BigFraction |
getTimeOffset() |
BigFraction |
getTimeScale() |
Interval |
getTotalInterval()
Retrieve the total interval encompassed by this pattern's events (if
applicable), or its loop interval.
|
double |
getValue()
Returns the value of this Pattern at the current interval, a number
between 0.0 and 1.0 inclusive.
|
double |
getValueFor(Interval now)
Returns the value of the pattern for a specified
Interval . |
double |
getValueOffset() |
double |
getValueScale() |
boolean |
hasActiveMappings()
Check if this pattern or its children have any active mappings, i.e.
|
boolean |
hasMapping(Pattern.MappingType mapping) |
Pattern |
invert() |
boolean |
isConcretePattern() |
boolean |
isDiscretePattern() |
Pattern |
loop()
Turns looping on.
|
Pattern |
once()
Turns looping off.
|
Pattern |
onOnset(Callable<Void>... callables) |
Pattern |
onOnset(Callable<Void> callable) |
Pattern |
onRelease(Callable<Void>... callables) |
Pattern |
onRelease(Callable<Void> callable) |
Pattern |
putMapping(Pattern.MappingType mappingType,
Mapping<?> mapping)
Sets the
Mapping of this pattern for a certain
Pattern.MappingType . |
void |
rect(float x,
float y,
float width,
float height) |
void |
rect(float x,
float y,
float width,
float height,
Interval interval) |
Pattern |
repeat(int n)
Repeats this pattern a specified number of times.
|
Pattern |
reverse() |
Pattern |
rewrite(EventRewriter eventRewriter) |
Pattern |
select(int i) |
Pattern |
selectFrom(Pattern... patterns)
Creates a new pattern, using the current pattern as a selector to choose
between the patterns provided as input.
|
void |
setLoopInterval(Interval loopInterval) |
void |
setTimeMatch(Pattern pattern) |
void |
setTimeOffset(BigFraction timeOffset) |
void |
setTimeOffset(double i) |
void |
setTimeScale(BigFraction timeScale) |
void |
setTimeScale(double i) |
void |
setValueOffset(double valueOffset) |
void |
setValueScale(double valueScale) |
Pattern |
shift(BigFraction amt) |
Pattern |
shift(double amt) |
Pattern |
speed(BigFraction multiplier) |
Pattern |
speed(double multiplier) |
Pattern |
then(Pattern other)
Gives back a new pattern that switches from this pattern to another after
the loop interval/total interval has elapsed.
|
String |
toString() |
Interval |
transform(Interval interval)
Performs the transformation of a given interval, according to the
pattern's time scaling, offset, and loop interval.
|
Interval |
transform(Interval interval,
boolean useOffset)
Performs the transformation of a given interval, according to the
pattern's time scaling, offset, and loop interval.
|
Pattern |
transpose(Integer semitones)
Transposes the pattern by a specified number of semitones.
|
public Turtle turtle
public Pattern(Loom loom)
loom
- the Loom
that holds this pattern (can be null)public Pattern(Loom loom, double defaultValue)
loom
- the Loom
that holds this pattern (can be null)defaultValue
- the value of this patternpublic Pattern(Loom loom, ContinuousFunction function)
loom
- the Loom
that holds this pattern (can be null)function
- the value of the pattern as a function of timepublic Pattern(Loom loom, LEvent... events)
loom
- the Loom
that holds this pattern (can be null)events
- the events to be addedpublic Pattern(Loom loom, Collection<LEvent> events)
loom
- the Loom
that holds this pattern (can be null)events
- the events to be addedpublic Pattern(Loom loom, EventCollection events)
loom
- the Loom
that holds this pattern (can be null)events
- the EventCollection
to be addedpublic Pattern(Loom loom, EventCollection events, ContinuousFunction function, boolean isConcrete)
Loom
.
Either a EventCollection
or ContinuousFunction
(not both)
can be passed in, in which case it will create an underlying
ConcretePattern.loom
- the Loom
that holds this pattern (can be null)events
- an EventCollection
for the patternfunction
- a ContinuousFunction
for the patternisConcrete
- is the pattern concrete (i.e. does it contain events/a
function directly)public static Pattern fromABC(Loom loom, String tune)
loom
- the Loom on which the new pattern should be createdtune
- a string containing a valid ABC tunepublic static Pattern fromString(Loom loom, String string)
Pattern.fromString(loom, "024");
creates a
pattern with three events, each 1/3 a cycle long, with values 0.0, 0.5,
and 1.0.loom
- the Loom on which the new pattern should be createdstring
- a string with digitsextend(String)
public static Pattern fromInts(Loom loom, Integer... ints)
Pattern.fromString(loom, 0, 2, 4);
creates a pattern with three events, each 1/3 a cycle long, with values
0.0, 0.5, and 1.0.loom
- the Loom on which the new pattern should be createdints
- the integer values for each eventpublic static Pattern following(Pattern other)
other
- the pattern to followpublic Pattern putMapping(Pattern.MappingType mappingType, Mapping<?> mapping)
Mapping
of this pattern for a certain
Pattern.MappingType
.mappingType
- the type of mapping that will be setmapping
- a Mapping
Pattern.MappingType
public ConcurrentMap<Pattern.MappingType,Mapping<?>> getOutputMappings()
public Pattern extend(String string)
string
- a string such as "10010010" describing a pattern to be tacked
on at the endEventCollection.fromString(String)
public Pattern extend(Integer... ints)
ints
- the integer values of each eventEventCollection.fromInts(Integer...)
public Pattern extend(LEvent... events)
newEvents
- the events to be appendedextend(Collection)
public Pattern extend(Collection<LEvent> newEvents)
newEvents
- the events to be appendedpublic Pattern extend(double offset, LEvent... newEvents)
offset
- the amount to delay the new eventsnewEvents
- the events to be addedpublic Pattern extend(BigFraction offset, LEvent... newEvents)
offset
- the amount to delay the new eventsnewEvents
- the events to be addedpublic Pattern extend(BigFraction offset, Collection<LEvent> newEvents)
offset
- the amount to delay the new eventsnewEvents
- the events to be addedpublic double getValue()
public double getValueFor(Interval now)
Interval
.now
- the interval to querypublic Interval getCurrentInterval()
getCurrentInterval(boolean)
public Interval getCurrentInterval(boolean useOffset)
useOffset
is false, it will ignore the time offset in its
calculations. This is needed so that every(double, com.corajr.loom.transforms.Transform)
and other functions
act in the expected manner when a parent pattern is transformed.useOffset
- use the time offset when calculating intervaltransform(Interval, boolean)
public Interval transform(Interval interval)
interval
- the interval to be transformedtransform(Interval, boolean)
public Interval transform(Interval interval, boolean useOffset)
useOffset
is false, the offset will be ignored.interval
- the interval to be transformeduseOffset
- whether or not to use the offsetpublic Pattern once()
public Pattern loop()
public Pattern repeat(int n)
n
- the number of times to looppublic int getRepeats()
public Pattern asInt(int lo, int hi)
lo
to hi
is inclusive, so 1.0 will be mapped to
hi
; values are rounded to the nearest whole number using
Math.round.lo
- the low end of the rangehi
- the high end of the range (inclusive)public int asInt()
public Pattern asFloat(float lo, float hi)
hi
.lo
- the low end of the rangehi
- the high end of the range (inclusive)public float asFloat()
public Pattern asMidiInstrument(String instrument)
instrument
- the name of a MIDI instrument to trigger as a stringMidiTools.Instrument
,
#asMidiInstrument(Instrument)
public Pattern asMidiInstrument(MidiTools.Instrument instrument)
instrument
- the name of a MIDI instrument to triggerMidiTools.Instrument
public Pattern asMidiPercussion(String sound)
sound
- a MIDI percussion instrumentMidiTools.Percussion
public Pattern asMidiPercussion(MidiTools.Percussion sound)
sound
- a MIDI percussion instrumentMidiTools.Percussion
public Pattern asMidiCommand(Integer... commands)
asMidiCommand(-1, ShortMessage.NOTE_OFF, ShortMessage.NOTE_ON);
maps the values 0.0, 0.5, and 1.0 (output from
ConcretePattern.forEach(Pattern)
) to the appropriate MIDI
commands for each note.commands
- the commands to executepublic int asMidiCommand()
public int asMidiCommand(Interval now)
public Pattern asMidiChannel(Integer... channels)
channels
- the channels to map topublic int asMidiChannel()
public int asMidiChannel(Interval now)
public Pattern asMidiData1(int lo, int hi)
lo
- the low end of the rangehi
- the high end of the range (inclusive)IntMapping
public int asMidiData1()
public int asMidiData1(Interval now)
public Pattern asMidiNote(Integer... values)
asMidiData1(int, int)
, but output will be constrained to the
possibilities specified. Useful to map to certain notes of the scale.
Example: asMidiNote(60, 64, 67) will map the values 0.0, 0.5, and 1.0 to
the notes middle C, E, and G. Other values will be floored (e.g. 0.25 =>
60).values
- the notes to be mapped topublic int asMidiNote()
asMidiData1(int, int)
.public Pattern asMidiData2(int lo, int hi)
lo
- the low end of the rangehi
- the high end of the range (inclusive)public int asMidiData2()
public int asMidiData2(Interval now)
public Pattern asMidiMessage(Pattern notes)
notePattern.asMidiMessage(notePattern);
notes
- the pattern that provides the MIDI notes (must have an
asMidiData1(int, int)
mapping).asMidiMessage(Pattern, Pattern, Pattern, Pattern)
public Pattern asMidiMessage(Pattern commands, Pattern channels, Pattern notes, Pattern velocities)
MidiBusWrapper
. A
new message is sent each time there is an onset in the
commands
pattern.
This takes four patterns as input (they need not be distinct). This
allows each parameter of the MIDI message to be set separately if
desired.commands
- the pattern that specifies the MIDI commandchannels
- the pattern that specifies the MIDI channelnotes
- the pattern that specifies MIDI data 1velocities
- the pattern that specifies MIDI data 2public Pattern asOscMessage(String addressPattern)
asOscMessage("/light")
will result in a message of
"/light 1".addressPattern
- the address to send the message toasOscBundle(NetAddress, Pattern...)
public Pattern asOscMessage(String addressPattern, int value)
asOscMessage("/light", 1)
will result in a message
of "/light 1".addressPattern
- the address to send the message tovalue
- the integer valueasOscBundle(NetAddress, Pattern...)
public Pattern asOscMessage(String addressPattern, Mapping<?> mapping)
Mapping
used to provide the arguments.
Example: asOscMessage("/light", new IntMapping(0, 1));
will
call the IntMapping
on the current pattern, then create a message
like "/light 0" or "/light 1" depending on its value.addressPattern
- the address of the messagemapping
- the mapping from this pattern's values to the OSC message's
argumentspublic Pattern asOscMessage(String addressPattern, Pattern subPattern, Mapping<?> mapping)
subPattern
to provide the values that will be translated
into the message's arguments.
The mapping
will be called using the subpattern's current
value when this pattern is queried. For example, the subpattern could
have a mapping that turns 0.0 into the three floats [0.0, 0.0, 0.0] and
1.0 into the three floats [0.1, 0.2, 0.3], which would work independently
of the values of the current pattern.addressPattern
- the address to send the message tosubPattern
- the pattern that will be used to provide the values for the
mappingmapping
- the mapping from subPattern's values to the OSC messages'
argumentspublic OscMessage asOscMessage()
public Pattern asOscBundle(NetAddress remoteAddress)
OscP5Wrapper
. The current pattern's children are assumed to
contain mappings to OSC messages.remoteAddress
- the server to send the messages toasOscMessage(String, Mapping)
,
asOscBundle(NetAddress, Pattern...)
public Pattern asOscBundle(NetAddress remoteAddress, Pattern... patterns)
OscP5Wrapper
.remoteAddress
- the address of the OSC server to send topatterns
- the patterns that contain the OSC messages to be bundledpublic OscBundle asOscBundle()
public Pattern asSynthParam(Synth synth, String param, float lo, float hi)
synth
- the supercollider.Synth objectparam
- the name of the parameterlo
- the low range of the valuehi
- the high range of the valuepublic Pattern asSample(AudioSample sample)
sample
- the AudioSamplepublic Pattern asSoundFile(SoundFile soundFile)
sample
- the AudioSamplepublic Pattern asColor(int... colors)
lerpColor
in HSB mode.colors
- a list of colors to represent each statepublic int asColor()
public Pattern asDrawCommand(DrawCommand... commands)
public DrawCommand asDrawCommand()
public Pattern asTurtleDrawCommand(TurtleDrawCommand... commands)
public Pattern asTurtleDrawCommand(boolean clearing, TurtleDrawCommand... commands)
public TurtleDrawCommand asTurtleDrawCommand()
public void addAllTurtleDrawCommands()
public Object asObject()
public StatefulCallable asStatefulCallable()
public Pattern asStatefulCallable(StatefulCallable... callables)
public Collection<DrawCommand> getDrawCommands()
public Collection<Callable<?>> getActiveMappingsFor(Interval interval)
public boolean hasMapping(Pattern.MappingType mapping)
public boolean hasActiveMappings()
public boolean isConcretePattern()
public boolean isDiscretePattern()
public Pattern selectFrom(Pattern... patterns)
Let N be the number of input patterns. When this pattern is 0.0, the output pattern will return the values/mappings of its first child by default. When this pattern has a value of i/N, where i is a 1-based index into the input patterns, the output pattern will return the values and mappings of pattern i.
patterns
- the patterns from which to selectpublic Pattern select(int i)
public Pattern speed(double multiplier)
public Pattern speed(BigFraction multiplier)
public Pattern reverse()
public Pattern delay(double amt)
public Pattern delay(BigFraction amt)
public Pattern shift(double amt)
public Pattern shift(BigFraction amt)
public Pattern transpose(Integer semitones)
semitones
- the number of semitones to transpose bysetValueOffset(double)
public Pattern invert()
public Pattern after(double time, Callable<Void> callable)
offset
- the duration after which to trigger the callablecallable
- the callable to triggerpublic Pattern after(BigFraction offset, Callable<Void> callable)
offset
- the duration after which to trigger the callablecallable
- the callable to triggerpublic Pattern after(double offset, Transform transform)
offset
- the duration after which to trigger the transformtransform
- the transform to triggerpublic Pattern after(BigFraction offset, Transform transform)
offset
- the duration after which to trigger the transformtransform
- the transform to triggerpublic Pattern after(double time, LEvent... eventsToAdd)
extend(double, LEvent...)
.offset
- the time offseteventsToAdd
- events to be addedpublic Pattern after(BigFraction offset, LEvent... eventsToAdd)
extend(BigFraction, LEvent...)
.offset
- the time offseteventsToAdd
- events to be addedpublic Pattern then(Pattern other)
other
- the pattern to run after this onepublic Pattern rewrite(EventRewriter eventRewriter)
public Pattern clear()
public BigFraction getMinimumResolution()
public BigFraction getTimeOffset()
public void setTimeOffset(double i)
public void setTimeOffset(BigFraction timeOffset)
public BigFraction getTimeScale()
public void setTimeScale(double i)
public void setTimeScale(BigFraction timeScale)
public void setTimeMatch(Pattern pattern)
public Interval getLoopInterval()
public void setLoopInterval(Interval loopInterval)
public Interval getTotalInterval()
public double getValueOffset()
public void setValueOffset(double valueOffset)
public double getValueScale()
public void setValueScale(double valueScale)
public void draw()
public void rect(float x, float y, float width, float height)
public void rect(float x, float y, float width, float height, Interval interval)
Processing Library loom by Cora Johnson-Roberson. (c) 2014-2016