Using leds and lights?

I have always found lights and leds to be very perplexing. Whereas widgets are pretty easy. What am I missing? Are they explained anywhere?

Lights are easy in Rack plugins.
Define the light ID in your MyModule class.

enum LightIds {
	CLOCK_LIGHT,
	NUM_LIGHTS
};

Set the light value in your MyModule::process() method between 0.0 (off) and 1.0 (fully on).

void process(const ProcessArgs& args) override {
	bool clock = isClocked();
	lights[CLOCK_LIGHT].setBrightness(clock ? 1.f : 0.f);
}

Add the light widget to your panel in MyModuleWidget().

addChild(createLightCentered<MediumLight<RedLight>>(mm2px(Vec(10.0, 10.0)), module, MyModule::CLOCK_LIGHT));

Multicolored lights

For lights with multiple colors, use adjacent light IDs for each of the colors. This is similar to how physical RGB LEDs work using multiple leads.

enum LightIds {
	ENUMS(RGB_LIGHT, 3), // This reserves 3 "enum slots" rather than just 1
	NUM_LIGHTS
};
...
void process(const ProcessArgs& args) override {
	lights[RGB_LIGHT + 0].setBrightness(red);
	lights[RGB_LIGHT + 1].setBrightness(green);
	lights[RGB_LIGHT + 2].setBrightness(blue);
}
...
addChild(createLightCentered<MediumLight<RedGreenBlueLight>>(mm2px(Vec(10.0, 10.0)), module, MyModule::RGB_LIGHT));
8 Likes

How do you tell the lights to go out when the cables are disconnected? i developed a VCA with VU Meter (actually it’s just aesthetic lights, no real measurement), this is the situation: I open the module, and the lights are off, ok. I connect the audio input, and the lights turn on following the “paramquantity” of the volume, I connect an ADSR in the CV input, and the meter follows the envelope, I disconnect the envelope and the lights return to follow a fixed volume, I disconnect even the oscillator and the lights remain paralyzed, rather than go out.

In your process function, look to see if a cable is connected, and if not, turn off the lights.

3 Likes

I was going crazy for 3-4 months figuring out how to turn off the lights, I tried dozens of codes, even something similar to the correct one, but your advice helped me find just the correct one! thank you! after all it was very simple

2 Likes

ENUMS inside ENUMS - I don’t think it can be done, or can it? What’s the syntax?

enum LightIds {

	// Multi-colored light as explained above by @Vortico
	ENUMS(RGB_LIGHT, 3),

	// I want this one to be a group of 10 multi-colored lights
	ENUMS(RGB_LIGHT_GROUP,  10)
}

You need to to do

ENUMS(RGB_LIGHT_GROUP,  30)

And handle the indexing accordingly in your code.

4 Likes