### Control Modulator Lifecycle (Java) Source: https://chromatik.co/develop/coding Provides examples of controlling the operation of a modulator using standard methods. Includes starting, stopping, resetting to the initial condition, and triggering a restart. ```java // Starts the modulator modulator.start(); // Stops the modulator modulator.stop(); // Stops the modulator and resets to initial condition modulator.reset(); // Re-starts the modulator from initial condition modulator.trigger(); ``` -------------------------------- ### DiscreteParameter: Create and Get Integer Value (Java) Source: https://chromatik.co/develop/coding Provides an example of creating a DiscreteParameter with an initial integer value and a specified range. It also shows how to retrieve the current integer value of the parameter. ```Java // Discrete parameter with an initial value of 4 and range from [0,7] DiscreteParameter parameter = new DiscreteParameter("Discrete", 4, 8); // Values may be retrieved as integers parameter.getValuei(); ``` -------------------------------- ### Register LXModulatorComponent in Constructor (Java) Source: https://chromatik.co/develop/coding Demonstrates registering a SinLFO modulator within the constructor of a custom LXPattern class. The modulator is added and started using addModulator() and start(), or alternately with the shorthand startModulator(). ```java public class MyPattern extends LXPattern { public final SinLFO lfo = new SinLFO("Oscillation", 0, 1, 2500); public MyPattern(LX lx) { super(lx); // Register the modulator addModulator(lfo); // Start the modulator running lfo.start(); } public void run(double deltaMs) { // Retrieve the current LFO value final float lfo = this.lfo.getValuef(); } ... } ``` -------------------------------- ### Complete StripePattern Example Source: https://chromatik.co/develop/devices A full implementation of an LXPattern that generates a visual stripe. It uses CompoundParameters for position (X-Pos) and width (Fade) and calculates brightness based on the distance from the stripe's center, creating a falloff effect. Colors are set using LXColor.gray. ```java @LXCategory("Examples") @LXComponent.Name("Stripe") public class StripePattern extends LXPattern { public final CompoundParameter xPos = new CompoundParameter("X-Pos", .5) .setUnits(CompoundParameter.Units.PERCENT_NORMALIZED) .setDescription("Sets the base position of the stripe"); public final CompoundParameter fade = new CompoundParameter("Fade", .1) .setUnits(CompoundParameter.Units.PERCENT_NORMALIZED) .setDescription("Sets the fade width of the stripe"); public StripePattern(LX lx) { super(lx); addParameter("xPos", this.xPos); addParameter("fade", this.fade); } @Override public void run(double deltaMs) { final float xPos = this.xPos.getValuef(); final float fade = this.fade.getValuef(); // Compute falloff factor based upon fade size final float falloff = 100 / fade; for (LXPoint p : model.points) { // Brightness falls off as distance from xPos increases float level = 100 - falloff * Math.abs(p.xn - xPos); // Set grayscale color, ensure value in range colors[p.index] = LXColor.gray(LXUtils.maxf(0, level)); } } } ``` -------------------------------- ### Scaffolding Basic Modulator Class in Java Source: https://chromatik.co/develop/devices Defines the fundamental structure for an LX Modulator class. It includes necessary annotations, inheritance from LXModulator, and implementation of relevant interfaces like LXNormalizedParameter and LXOscComponent. The example shows a no-argument constructor and an empty computeValue method. ```java @LXCategory("Examples") @LXModulator.Global("Example") @LXModulator.Device("Example") public class ExampleModulator extends LXModulator implements LXNormalizedParameter, LXOscComponent { // No-arg constructor passes default label public ExampleModulator() { super("Example"); } @Override protected double computeValue(double deltaMs) { // Compute the new value for this modulator // based upon elapsed time return 0; } @Override public LXNormalizedParameter setNormalized(double value) { throw new UnsupportedOperationException("ExampleModulator doesn't support setNormalized()") } @Override public double getNormalized() { return getValue(); } } ``` -------------------------------- ### Implementing a Trigger Modulator in Java Source: https://chromatik.co/develop/devices Illustrates how to create a modulator that outputs triggers using the LXTriggerSource interface. This example shows the addition of a TriggerParameter and the logic within computeValue to trigger the output when a condition is met. ```java @LXCategory("Examples") @LXModulator.Global("Example Trigger") @LXModulator.Device("Example Trigger") public class ExampleTriggerModulator extends LXModulator implements LXOscComponent, LXTriggerSource { public final TriggerParameter trigOut = new TriggerParameter("Trig Out") .setDescription("Output trigger fires on some event"); public ExampleTriggerModulator() { super("Trigger"); addParameter("trigOut", this.trigOut); } @Override protected double computeValue(double deltaMs) { if (triggerConditionMet) { this.trigOut.trigger(); } // Compute new value return 0; } public BooleanParameter getTriggerSource() { return this.trigOut; } ... ``` -------------------------------- ### BoundedParameter: Create, Set, and Get Values (Java) Source: https://chromatik.co/develop/coding Demonstrates how to create a BoundedParameter with a specific value and range, set its description, and retrieve or set its value using absolute or normalized ranges. This parameter type is a double-precision floating point with a designated range. ```Java BoundedParameter parameter = new BoundedParameter("Label", 50, 0, 100); // All parameter types have a description field parameter.setDescription("A helpful description that tells the user what this parameter does"); // Values may be set and retrieved either in absolute range... parameter.getValue(); parameter.setValue(100); // ...or in a normalized range, from 0-1 parameter.getNormalized(); parameter.setNormalized(.4); ``` -------------------------------- ### EnumParameter: Represent Enum Values (Java) Source: https://chromatik.co/develop/coding Explains how to create an EnumParameter to represent values from a Java enum. The example shows initialization with an enum type and retrieving the current enum value. ```Java enum MyEnum { ONE, TWO, THREE, ... } EnumParameter parameter = new EnumParameter("Enum", MyEnum.ONE); // Value may be retrieved as an enum MyEnum e = parameter.getEnum(); ``` -------------------------------- ### Complete Pulse Effect with Parameters and Modulators Source: https://chromatik.co/develop/devices Full working example of a PulseEffect that generates visual pulsing with rate and intensity controlled by parameters. Uses CompoundParameter for intensity and period, SinLFO modulator for oscillation, color multiplication with damping, and blending to create a strobing effect that respects the enabledAmount. ```java @LXCategory("Examples") @LXComponent.Name("Pulse") public class PulseEffect extends LXEffect { public final CompoundParameter intensity = new CompoundParameter("Intensity", .5) .setUnits(CompoundParameter.Units.PERCENT_NORMALIZED) .setDescription("Intensity of the effect"); public final CompoundParameter period = new CompoundParameter("Period", 500, 5000) .setUnits(CompoundParameter.Units.MILLISECONDS) .setDescription("Period of the strobe oscillation"); public final SinLFO lfo = new SinLFO(0, 1, this.period); public PulseEffect(LX lx) { super(lx); addParameter("intensity", this.intensity); addParameter("period", this.period); startModulator(this.lfo); } @Override public void run(double deltaMs, double enabledAmount) { // Parameter and modulator values are automatically updated and can be // retrieved at runtime final float intensity = this.intensity.getValuef(); final float lfo = this.lfo.getValuef(); // Compute strobe brightness level final float strobeLevel = 1 - lfo * intensity; // Take enabledAmount into account final double dampedLevel = LXUtils.lerp(1, strobeLevel, enabledAmount); // Make a mask color final int mask = LXColor.gray(100 * dampedLevel); final int alpha = LXColor.BLEND_ALPHA_FULL; // Multiply all colors against mask for (LXPoint p : model.points) { colors[p.index] = LXColor.multiply(colors[p.index], mask, alpha); } } } ``` -------------------------------- ### JavaScript Pattern Lifecycle Callbacks Source: https://chromatik.co/develop/javascript Provides optional functions that are called when a pattern becomes active or inactive. These can be used for setup and cleanup tasks related to the pattern's lifecycle. ```javascript function onActive() { // The pattern will become actively used for rendering } ``` ```javascript function onInactive() { // The pattern will stop being actively used for rendering } ``` -------------------------------- ### Run Chromatik Headless with EULA Acceptance and Authorization Source: https://chromatik.co/develop/raspberry-pi Executes Chromatik in headless mode, loads a project file, accepts the End User License Agreement, and authorizes the machine using provided arguments. Requires the Chromatik JAR file and an authorization code. ```java java -cp chromatik-1.1.0-linux-aarch64.jar heronarts.lx.studio.Chromatik --headless --accept-eula --authorize AUTHCODEAUTH ``` -------------------------------- ### Scaffolding a Chromatik Plugin (Java) Source: https://chromatik.co/develop/plugins This Java code demonstrates how to scaffold a basic plugin for the Chromatik LX Studio. It implements the LXStudio.Plugin interface and includes essential lifecycle callbacks like initialize, initializeUI, onUIReady, and dispose. The @LXPlugin.Name annotation provides a user-facing name for the plugin. ```java @LXPlugin.Name("My Plugin") public class MyPlugin implements LXStudio.Plugin { @Override public void initialize(LX lx) { // Initialize the plugin during engine bootstrapping } @Override public void initializeUI(LXStudio lx, UI ui) { // Initialize UI components before UI is built } @Override public void onUIReady(LXStudio lx, UI ui) { // Add UI components once UI scaffolding is in place } @Override public void dispose() { // Clean up resources at program shutdown } } ``` -------------------------------- ### Register Child Components in LXComponent (Java) Source: https://chromatik.co/develop/coding Illustrates how to add child components to a parent component using the `addChild` method. This establishes a tree hierarchy for organizing components, essential for modulation and OSC message routing. Demonstrates how to prevent conflicts with parameter path names. ```java class MyComponent extends LXComponent { private final OtherComponent other; public MyComponent(LX lx) { super(lx); this.other = new OtherComponent(lx); addChild("other", this.other); } ``` -------------------------------- ### ObjectParameter: Select Object from List (Java) Source: https://chromatik.co/develop/coding Demonstrates the creation of an ObjectParameter, which allows selection from a fixed list of objects. It shows how to instantiate it with an array of objects and retrieve the currently selected object. ```Java // Discrete parameter with an initial value of 4 and range from [0,7] final Thing[] things = { thing1, thing2, thing3, ... }; ObjectParameter parameter = new ObjectParameter("Thing", things); // Value may be retrieved as an object Thing thing = parameter.getObject(); ``` -------------------------------- ### Create Basic LX Effect Class Scaffolding Source: https://chromatik.co/develop/devices Demonstrates the fundamental structure of an LX effect class with required annotations, constructor, and run method. The run method is invoked in real-time when the effect is active, receiving deltaMs (elapsed milliseconds since last frame) and enabledAmount (0-1 strength value). Requires extending LXEffect and implementing the run method. ```java @LXCategory("Examples") @LXComponent.Name("Example") public class ExampleEffect extends LXEffect { // A basic constructor should pass lx to the super constructor public ExampleEffect(LX lx) { super(lx); } @Override public void run(double deltaMs, double enabledAmount) { // This method is called in real-time when the effect is active, with // deltaMs indicating how many milliseconds have passed since the previous frame. // The enabledAmount parameter indicates with a value from 0-1 how strongly // to apply the effect. Damping is automatically enabled when the effect is turned // on or off. // The loop is not called when the effect is inactive. } } ``` -------------------------------- ### Implement OSC Support in LXComponent (Java) Source: https://chromatik.co/develop/coding Shows how to enable OSC support for a component by implementing the `LXOscComponent` marker interface. This makes the component's parameters and children accessible via the OSC system. ```java // Flag this component as supporting OSC class MyComponent extends LXComponent implements LXOscComponent { ``` -------------------------------- ### Implement LXPattern Rendering Loop Source: https://chromatik.co/develop/devices Illustrates the core rendering logic within an LXPattern's run method. It iterates through model points, computes color values (hue, saturation, brightness) based on geometric coordinates or other factors, and assigns them to the colors array using LXColor methods. The colors array is provided by the framework. ```java @Override public void run(double deltaMs) { for (LXPoint p : model.points) { float hue = /* compute hue for this position, 0-360 */ float sat = /* compute saturation for this position, 0-100 */ float brightness = /* compute brightness for this position, 0-100 */ colors[p.index] = LXColor.hsb(hue, sat, brightness); } } ``` -------------------------------- ### Instantiate UI for Global Component in Plugin (Java) Source: https://chromatik.co/develop/global-parameters This Java code demonstrates how to add the UI for a custom global component to the 'GLOBAL' tab in the LX Studio interface. It's implemented within the onUIReady method of an LXStudio plugin. ```Java public class MyPlugin implements LXStudio.Plugin { ... public void onUIReady(LXStudio lx, LXStudio.UI ui) { // Instantiate the UI object and add it to the global section new UIMyComponent(ui, this.myComponent).addToContainer(ui.leftPane.global); } } ``` -------------------------------- ### Register Parameters in Java Source: https://chromatik.co/develop/coding This code demonstrates how to register parameters within a component's constructor, using the addParameter method. It also shows how to access and use the registered parameters within the component. Parameters are unique to the scope of this component. ```java public class MyPattern extends LXPattern { public final CompoundParameter value = new CompoundParameter("Val", 5, 0, 10) .setDescription("An arbitrary value used by this pattern."); public MyPattern(LX lx) { super(lx); addParameter("value", this.value); } public void onParameterChanged(LXParameter p) { super.onParameterChanged(p); if (p == this.value) { // Listenable parameters are automatically registered } } public void run(double deltaMs) { // Retrieve the current (potentially modulated) value final float value = this.value.getValuef(); } ... } ``` -------------------------------- ### BooleanParameter: Set Mode (Java) Source: https://chromatik.co/develop/coding Illustrates the creation of a BooleanParameter and how to set its behavior for UI representation. It supports TOGGLE mode for persistent state changes and MOMENTARY mode for actions that are true only when actively engaged. ```Java BooleanParameter parameter = new BooleanParameter("Bool", false); // The parameter flips between true and false state parameter.setMode(BooleanParameter.Mode.TOGGLE); // The parameter is true when actively engaged parameter.setMode(BooleanParameter.Mode.MOMENTARY); ``` -------------------------------- ### Add Parameters and Modulators to LXPattern Source: https://chromatik.co/develop/devices Demonstrates how to incorporate user-controllable Parameters and time-varying Modulators into an LXPattern. These are declared as fields, registered in the constructor, and their values can be retrieved and used within the run method for dynamic behavior. ```java // This is a parameter with default value 5, range 0-100 public final CompoundParameter example = new CompoundParameter("Param", 5, 0, 100) .setDescription("This is an example parameter"); // This is an LFO oscillating in a sin wave from 0 to 1 every second (1000ms) public final SinLFO lfo = new SinLFO(0, 1, 1000); public ExamplePattern(LX lx) { super(lx); addParameter("example", this.example); startModulator(this.lfo); } @Override public void run(double deltaMs) { // Parameter and modulator values are automatically updated and can be // retrieved at runtime final float example = this.example.getValuef(); final float lfo = this.lfo.getValuef(); ... } ``` -------------------------------- ### Create Basic LXPattern Class Structure Source: https://chromatik.co/develop/devices Defines the fundamental structure for an LXPattern, which acts as a pixel shader for generating animations. It includes a constructor and the core run method called in real-time. Annotations like @LXCategory and @LXComponent.Name are used for organization and naming. ```java @LXCategory("Examples") @LXComponent.Name("Example") public class ExamplePattern extends LXPattern { // A basic constructor should pass lx to the super constructor public ExamplePattern(LX lx) { super(lx); } @Override public void run(double deltaMs) { // This method is called in real-time when the pattern is active, with // deltaMs indicating how many milliseconds have passed since the previous frame } } ``` -------------------------------- ### TriggerParameter: Fire and Register Callback (Java) Source: https://chromatik.co/develop/coding Shows how to create and use a TriggerParameter, which is a momentary boolean that resets to false after being triggered. It also demonstrates registering a callback function to execute when the trigger is activated. ```Java TriggerParameter trig = new TriggerParameter("Trig"); // Fire the trigger trig.trigger(); // A Runnable may be supplied to fire anytime the trigger engages TriggerParameter trig = new TriggerParameter("Trig", () -> { System.out.println("Trig fired!"); }); ``` -------------------------------- ### Save and Load LXComponent (Java) Source: https://chromatik.co/develop/coding Explains the `LXSerializable` interface for saving and restoring component state. Shows how to override the save and load methods to handle custom array serialization, managing the lifecycle of child components and ensuring proper restoration of state. ```java private final List things = new ArrayList<>(); // Assume prior call addArray("thing", this.things); private statc final String KEY_THINGS = "things"; public void save(LX lx, JsonObject object) { super.save(lx, object); object.add(KEY_THINGS, LXSerializable.Utils.toArray(lx, this.things)); } public void load(LX lx, JsonObject object) { super.load(lx, object); if (object.has(KEY_THINGS)) { JsonArray thingsArray = object.getAsJsonArray(KEY_THINGS); for (JsonElement thingElement : thingsArray) { JsonObject thingObj = (JsonObject) thingElement; // Construct appropriately based upon thingObj Thing thing = new Thing(lx); thing.load(lx, thingObj); this.things.add(thing); } } ``` -------------------------------- ### Create LXComponent Subclass (Java) Source: https://chromatik.co/develop/coding Demonstrates the creation of a custom component by extending the base class `LXComponent`. This is the fundamental building block for organizing program state within the LX framework. ```java class MyComponent extends LXComponent { public MyComponent(LX lx) { super(lx); } } ``` -------------------------------- ### Register Parameters in LXComponent (Java) Source: https://chromatik.co/develop/coding Shows how to register parameters within an `LXComponent` using the `addParameter` method. These parameters can be listenable, allowing the component to react to changes, and are uniquely identified by a path for program-wide and OSC access. ```java class MyComponent extends LXComponent { public final BooleanParamter active = new BooleanParamter("Active", false) .setDescription("Whether component is active"); public final CompoundParameter amount = new CompoundParameter("Amount", 0) .setUnits(CompoundParameter.Units.PERCENT_NORMALIZED) .setDescription("Whether component is active"); public MyComponent(LX lx) { super(lx); addParameter("active", this.active); addParameter("amount", this.amount); } public void onParameterChanged(LXParameter p) { super.onParameterChanged(p); // Will fire automatically for registered parameters } } ``` -------------------------------- ### Add Parameters and Modulators to LX Effect Source: https://chromatik.co/develop/devices Demonstrates how to expose CompoundParameters and Modulators (like SinLFO) in an effect class. Parameters and modulators are registered in the constructor using addParameter() and startModulator(), then accessed at runtime via getValuef(). Values are automatically updated by the framework each frame. ```java @LXCategory("Examples") @LXComponent.Name("Example") public class ExampleEffect extends LXEffect { // Intensity parameter public final CompoundParameter intensity = new CompoundParameter("Intensity", .5) .setUnits(CompoundParameter.Units.PERCENT_NORMALIZED) .setDescription("Intensity of the effect"); // This is an LFO oscillating in a sin wave from 0 to 1 every second (1000ms) public final SinLFO lfo = new SinLFO(0, 1, 1000); public ExampleEffect(LX lx) { super(lx); addParameter("intensity", this.intensity); startModulator(this.lfo); } @Override public void run(double deltaMs, double enabledAmount) { // Parameter and modulator values are automatically updated and can be // retrieved at runtime final float intensity = this.intensity.getValuef(); final float lfo = this.lfo.getValuef(); ... } } ``` -------------------------------- ### Customize Parameter UI in Java Source: https://chromatik.co/develop/coding This code snippet shows how to customize the UI of LXParameter. It covers how to set descriptions, units, polarity, and formatters for parameters, allowing for human-readable values and integration with the Chromatik UI. ```java // All parameters should have a helpful description set to educate the user parameter.setDescription("Useful text that explains the parameter"); ``` ```java // Customize display of the value in common units parameter.setUnits(LXParameter.Units.MILLISECONDS); parameter.setUnits(LXParameter.Units.DECIBELS); parameter.setUnits(LXParameter.Units.HERTZ); ``` ```java // A knob for this parameter fills itself up from low to hi (e.g. Volume) parameter.setPolarity(LXParameter.Polarity.UNIPOLAR); // A knob for this parameter draws with a center point (e.g. Left/Right) parameter.setPolarity(LXParameter.Polarity.BIPOLAR); ``` ```java // Use a custom formatter to display the parameter's value parameter.setFormatter(new LXParameter.Formatter() { public String format(double value) { // Render the value for the UI } }); // Or in shorthand parameter.setFormatter(value -> { // Return value as string for the UI }); ``` -------------------------------- ### Initialize Global Component in Plugin (Java) Source: https://chromatik.co/develop/global-parameters This Java code snippet shows how to initialize a custom global component within an LXStudio plugin. It creates an instance of the component and registers it with the LX engine, ensuring its parameters are saved and loadable with the project. ```Java public class MyPlugin implements LXStudio.Plugin { public MyComponent myComponent; @Override public void initialize(LX lx) { // Create an instance of your global component and register it with the LX engine // so that it can be saved and loaded in project files this.myComponent = new MyComponent(lx); lx.engine.registerComponent("myComponent", this.myComponent); } ``` -------------------------------- ### Listen to Parameter Changes in Java Source: https://chromatik.co/develop/coding This code snippet demonstrates how to listen for changes in LXParameter values using the addListener method. The listener is triggered when the parameter's value changes, allowing for actions to be taken in response. It also shows how to force a notification using the 'bang()' method. ```java BoundedParameter parameter = new BoundedParameter("test", 0); parameter.addListener(new LXParameterListener() { public void onParameterChanged(LXParameter p) { // Take action based upon change to p } }); // Better as shorthand parameter.addListener(p -> { // Take action based upon change to p }); // Parameter is given a new value, listener is triggered parameter.setValue(1.); // Parameter already has this value, listener not triggered parameter.setValue(1.); // Listener is explicitly triggered, even though no change in value parameter.bang(); ``` -------------------------------- ### Define Global Component with Parameters (Java) Source: https://chromatik.co/develop/global-parameters This code defines a custom global component class extending LXComponent and implementing LXOscComponent. It registers two BoundedParameters and adds them to the component, allowing them to be controlled and saved with the project. ```Java public class MyComponent extends LXComponent implements LXOscComponent { public final BoundedParameter param1 = new BoundedParameter("p1", 0) .setDescription("A global parameter that does something"); public final BoundedParameter param2 = new BoundedParameter("p2", 0) .setDescription("A global parameter that does something else"); public MyComponent(LX lx) { super(lx); addParameter("param1", this.param1); addParameter("param2", this.param2); } } ``` -------------------------------- ### Mark LXComponent as Renamable (Java) Source: https://chromatik.co/develop/coding Demonstrates marking a component as user-renamable by implementing the `LXComponent.Renamable` interface. This allows users to rename the component. ```java // Flag this component as user-renameable class MyComponent extends LXComponent implements LXComponent.Renamable { ``` -------------------------------- ### FunctionalParameter: Dynamic Value Computation (Java) Source: https://chromatik.co/develop/coding Illustrates how to create a FunctionalParameter that computes its value dynamically each time it's requested. It includes both an anonymous inner class implementation and a shorthand syntactic sugar approach. ```Java FunctionalParameter parameter = new FunctionalParameter() { public double getValue() { // Compute the parameter value dynamically } }; // Shorthand syntactic sugar FunctionalParameter parameter = FunctionalParameter.create("Label", () -> { return value; }); ``` -------------------------------- ### Javascript Lifecycle Callbacks (Javascript) Source: https://chromatik.co/develop/javascript Implements optional callback functions that are invoked during the script's lifecycle. These include initialization (`init`), pre-rendering (`preRender`), post-rendering (`postRender`), and cleanup (`dispose`). ```javascript function init(model) { // Called when script is instantiated or the model has changed // Initialize any device state here } function preRender(deltaMs, nowMillis, model, colors, enabledAmount) { // Called at the start of each animation loop // deltaMs - how many milliseconds since last frmae // nowMillis - current timestamp in millis // model - The current rendering model // colors - The input/output color buffer // enabledAmount is only defined in the effect context } function postRender(deltaMs, nowMillis, model, colors, enabledAmount) { // Called at the end of each animation loop // Arguments are identical to preRender } function dispose() { // Script device has been destroyed } ``` -------------------------------- ### Create LFO Modulators in Java Source: https://chromatik.co/develop/coding This code shows how to create different types of LFO modulators such as SinLFO, TriangleLFO, SquareLFO, and SawLFO. LFO modulators are used to create automatically changing values over time, which can be used for various animation effects. They are based on the Low Frequency Oscillation concept. ```java // A sinusoidal wave that oscillates from 0 to 1 every 2500 milliseconds SinLFO lfo = new SinLFO("Sin Wave", 0, 1, 2500); // A triangular wave oscillating from 2 to 5 every 5000 milliseconds TriangleLFO lfo = new TriangleLFO("Tri Wave", 2, 5, 5000); // A square wave that switches between -4 and 4 every 1000 milliseconds SquareLFO lfo = new TriangleLFO("Square Wave", -4, 4, 1000); // A sawtooth wave that ramps from 5 to 15 every 3000 milliseconds SawLFO lfo = new SawLFO("Saw Wave", 5, 15, 3000); ``` -------------------------------- ### Register Array of Child Components in LXComponent (Java) Source: https://chromatik.co/develop/coding Demonstrates the usage of `addArray` for registering an array of child components. This method allows for dynamic management of child components within the parent component. ```java class MyComponent extends LXComponent { private final List others = new ArrayList<>(); public MyComponent(LX lx) { super(lx); addArray("other", this.others); } ... ``` -------------------------------- ### CompoundParameter: Modulated Bounded Parameter (Java) Source: https://chromatik.co/develop/coding Shows the creation of a CompoundParameter, which is similar to BoundedParameter but supports modulation. This is the recommended parameter type for patterns to allow for dynamic value changes. ```Java // Syntax looks just like other bounded parameters CompoundParameter parameter = new CompoundParameter("Label", 50, 0, 100); ``` -------------------------------- ### Define UI for Global Component (Java) Source: https://chromatik.co/develop/global-parameters This Java code defines a UI class for a custom global component, extending UICollapsibleSection. It creates UIKnob controls for the component's parameters, allowing users to interact with them in the LX studio interface. ```Java public class UIMyComponent extends UICollapsibleSection { public UIMyComponent(LXStudio.UI ui, MyComponent myComponent) { super(ui, 0, 0, ui.leftPane.global.getContentWidth(), 80); setTitle("MY COMPONENT"); new UIKnob(0, 0, myComponent.param1).addToContainer(this); new UIKnob(40, 0, myComponent.param2).addToContainer(this); } } ``` -------------------------------- ### Javascript MIDI Callbacks (Javascript) Source: https://chromatik.co/develop/javascript Provides functions to handle incoming MIDI messages if MIDI is enabled on the device. These include callbacks for note on/off, control change, program change, pitch bend, aftertouch, and MIDI panic. ```javascript function noteOnReceived(noteOn) {} function noteOffReceived(noteOff) {} function controlChangeReceived(controlChange) {} function programChangeReceived(programChange) {} function pitchBendReceived(pitchBend) {} function aftertouchReceived(aftertouch) {} function midiPanicReceived() {} ``` -------------------------------- ### Configure Linux Networking for All Interfaces Source: https://chromatik.co/develop/raspberry-pi Sets the maximum number of bytes that can be queued for packets with unresolved destination addresses across all network interfaces. This is a general setting that may be less optimal for high-latency interfaces like Wi-Fi but can be useful for USB Ethernet adapters. Requires root or sudo privileges. ```shell net.ipv4.neigh.default.unres_qlen_bytes = 4096 ``` -------------------------------- ### Configure Linux Networking for Unresolved Queue Length (Bytes) Source: https://chromatik.co/develop/raspberry-pi Sets the maximum number of bytes that can be queued for packets with unresolved destination addresses on the 'eth0' network interface. This helps prevent output queue saturation and latency issues. Requires root or sudo privileges. ```shell net.ipv4.neigh.eth0.unres_qlen_bytes = 4096 ``` -------------------------------- ### Validate Linux Networking Settings Source: https://chromatik.co/develop/raspberry-pi Checks the current values for the ARP (Address Resolution Protocol) unresolved queue length and queue length in bytes for the 'eth0' network interface. These commands help verify that the previously set networking parameters have taken effect. ```shell cat /proc/sys/net/ipv4/neigh/eth0/unres_qlen cat /proc/sys/net/ipv4/neigh/eth0/unres_qlen_bytes ``` -------------------------------- ### Create Colors using HSB (Javascript) Source: https://chromatik.co/develop/javascript Generates colors using the HSB (Hue, Saturation, Brightness) color model. Hue ranges from 0-360, Saturation and Brightness from 0-100. Alpha is also supported. ```javascript var red = hsb(0, 100, 100); var green = hsb(120, 100, 100); var blue = hsb(240, 100, 100); ``` -------------------------------- ### Marking a Modulator as Non-Mapping Source in Java Source: https://chromatik.co/develop/devices Demonstrates how to specify that a modulator provides utility functionality but should not be used as a valid modulation mapping source. This is achieved by calling `setMappingSource(false)` in the constructor. ```java public class UtilityModulator extends LXModulator implements LXOscComponent { public UtilityModulator() { super("Utility"); setMappingSource(false); } } ``` -------------------------------- ### Access Swatch Colors (Javascript) Source: https://chromatik.co/develop/javascript Accesses predefined color swatches from the global Color Palette via the `_swatch` variable. `_swatch.numColors` provides the count, and `_swatch.colors[index]` retrieves individual colors. ```javascript function renderPoint(point, deltaMs) { // The number of active colors is defined in _swatch.numColors; int numDefinedColors = _swatch.numColors; // The color values are available in _swatch.colors[index] return _swatch.colors[0]; } ``` -------------------------------- ### Include External Javascript Files (Javascript) Source: https://chromatik.co/develop/javascript Loads and executes code from another Javascript file using the `include` function. This is useful for organizing helper functions and shared code across multiple scripts. ```javascript include("helpers.js"); ``` -------------------------------- ### Create Grayscale Colors (Javascript) Source: https://chromatik.co/develop/javascript Generates grayscale colors. The single argument represents the brightness level, ranging from 0 (black) to 100 (white). ```javascript var white = gray(100); var black = gray(0); var midGray = gray(50); ``` -------------------------------- ### JavaScript Pattern Rendering Function Source: https://chromatik.co/develop/javascript Defines a function to render a color for each point in a pattern. It takes point data and time elapsed as input and returns an LXColor value. Geometry is accessed via normalized `point.xn`, `point.yn`, and `point.zn`. ```javascript /** * Return a color value for the given LXPoint * @param {LXPoint} point - The point to render * @param {number} deltaMs - Milliseconds elapsed since previous frame * @return {number} Color value returned from an LXColor method like hsb/rgb */ function renderPoint(point, deltaMs) { var level = brt; if (fade) { level *= clamp(1-LXUtils.dist(cx, cy, point.xn, point.yn), 0, 1); } return hsb(hue * 360, sat * 100, level * 100); } ``` -------------------------------- ### Declare Javascript Parameters (Javascript) Source: https://chromatik.co/develop/javascript Defines parameters like knobs, integer knobs, toggles, and triggers that are exposed in the UI. These parameters are automatically available as variables within the rendering functions. Ensure correct type and range for each parameter. ```javascript // A knob parameter, with defaultValue in range [0, 1] knob("key", "Label", "Description", defaultValue); // An integer knob parameter, with defaultValue in range [0, range-1] knobi("key", "Label", "Description", defaultIntValue, range); // A toggle switch, where defaultValue is true or false toggle("key", "Label", "Description", defaultValue) // A trigger button, where callback is a callback function trigger("key", "Label", "Description", callback) ``` -------------------------------- ### Render and Mutate Colors Array in LX Effect Source: https://chromatik.co/develop/devices Shows how to iterate through model points and mutate the colors array in the effect's run method. The colors array contains source material from previous processing chain elements and is not owned by the effect. To preserve computed values across frames, use a secondary buffer like ModelBuffer. ```java @Override public void run(double deltaMs, double enabledAmount) { for (LXPoint p : model.points) { colors[p.index] = /* perform some mutation of the color here */ } } ``` -------------------------------- ### Create Colors using RGB (Javascript) Source: https://chromatik.co/develop/javascript Generates colors using the RGB (Red, Green, Blue) color model. Each component ranges from 0-255. Alpha is also supported. ```javascript var red = rgb(255, 0, 0); var green = rgb(0, 255, 0); var blue = rgb(0, 0, 255); var alphaRed = rgba(255, 0, 0, 128); ``` -------------------------------- ### Use Declared Parameters in Rendering (Javascript) Source: https://chromatik.co/develop/javascript Demonstrates how to access and utilize declared parameters within a Javascript rendering function. The parameter's value is automatically available as a variable with the same key name defined in scope. ```javascript knob("lev", "Level", "Level of something or other", 0.5); function renderPoint(point, deltaMs) { // The "lev" variable is automatically defined in scope return gray(lev * 100); } ``` -------------------------------- ### JavaScript Effect Rendering Function Source: https://chromatik.co/develop/javascript Defines a function to modify the color of each point for an effect. It accepts point data, time elapsed, the effect's enabled state, and the input color. It returns a modified LXColor value, considering smooth transitions via `enabledAmount`. ```javascript /** * Return a color value for the given LXPoint * @param {LXPoint} point - The point to render * @param {number} deltaMs - Milliseconds elapsed since previous frame * @param {number} enabledAmount - Depth of effect to apply from 0-1 * @param {number} inputColor - Input color value for this point * @return {number} Color value returned from an LXColor method like hsb/rgb */ function renderPoint(point, deltaMs, enabledAmount, inputColor) { var level = lerp(1, clamp(1 - 2 * fade * LXUtils.dist(point.xn, point.yn, cx, cy), 0, 1), enabledAmount); return LXColor.multiply(inputColor, gray(100 * (invert ? (1-level) : level))); } ```