A light switch that loads svg's instead og drawing the light?

Hey :slight_smile:

I was wondering if there is such a thing in VCV, like the light latch, for example the MediumLight function, but instead of drawing the light with code, it loads SVG images?

That would be a bit like the VCVLightLatch button, which uses SVG’s, but without the button function itself, you can only send it data, it doesn’t have a button function itself.

I did a switch, like this, which makes me able to get different colors for my switch, depending on it’s state. 0 has one color, 1 has another color, 2 has another color, etc. It works great.

struct SwitchLED1 : SvgSwitch { 
	SwitchLED1() {
		addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/LED/LED-0.svg")));
		addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/LED/LED-1.svg")));
		addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/LED/LED-2.svg")));
    addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/LED/LED-3.svg")));
    addFrame(APP->window->loadSvg(asset::plugin(pluginInstance, "res/LED/LED-4.svg")));

	}																															// B0 B1

I load this switch UI like this:

addParam(createParamCentered<Switch1>(mm2px(Vec( 100, 100)), module, PhaseSeq4::MUTE_PARAM));

But I’d like to turn it into what I described above, a kind of light switch that only can receives values and doesn’t have any button functionality itself, that loads SVG’s instead of drawing the values.

Are there any examples of this?

Thanks :wink:

Does your widget let you set the “brightness” with a continuous value like the ones in the sdk do? There are plenty of modules the have custom buttons that look lit up when they are pushed down, of course.

The waveform selector switches from my ancient EV3 do this: image

Yeah, I am using it as a switch, I send it continuous values like, 0,1,2,etc. to change the SVG’s.

res/LED/LED-0.svg = Off 0 color res/LED/LED-1.svg = On 1 color res/LED/LED-2.svg = On 2 color Etc.

I just would like one, that doesn’t have a switch itself, just the display/svg functionality.

Looks cool, the switch thing. Does it load a different SVG for each waveform?

I am looking at the code now… Man this is a whole new world of code for me :sweat_smile: Looks completely different than anything else I’ve seen yet. I’ve got a lot to learn… :wink:

I tracked down the WaveformSwitch in your lib. I see it loads different SVG, but is it a parameter itself? Or just a light switch that displays different images.

Yes, If you look where it’s used you can see I call addParam on it. Also, the fact that it’s derived from rack::ParamWidget is a giveaway.

It used to be quite slow until I added FramebufferWidget. Before that it had to load the SVG on every frame - super slow.

Thanks. I had to reinstall your modules to see what it actually did.

But I was looking for something that is not a parameter itself, just a switch that can change SVGs coming from any source.

As long as you don’t call addParam on it no one will every know it has that capability. But to be sure you could derive from some other widget so that there is absolutely no param quantity associated with it.

Thanks, you got me on the right track. I think I managed to get something working now :slight_smile:

In the widget struct I add the param I just want to use as display like this:

addChild(createParamCentered<SwitchLED1>(mm2px(Vec(20   , 20)), module, TestADSR::DISPLAY_PARAM));

I don’t declare it in the config struct. I did first, but then it didn’t work very well. As soon as I remove it from config, it worked better. I’d have so set range and stuff like that, if there is no config for it it “just” works.

In process I send values to it like this:

params[DISPLAY_PARAM].setValue( VALUE IN);

This seems to work, all though if I push the display param itself, it flickers a tiny bit, but since it’s used for anything else than display I can live with that for now I think. Will see when I start to switch out the SVG images with something bigger, where the flickering os more noticeable.

Since this is a UI thing you really don’t need to be driving changes at sample rate from process(). Instead, set the value in either step() or draw(). This will consume less CPU, and perhaps reduce the flickering. Alternatively, you can reduce how often you change the UI by doing this only every n samples.

Most of my parameters are only set when I change them or on a trigger from something. I’ll keep in mind adding the .setvalue to the same structure.

Something like this:

if (Gate  && ntrig) {
	Set the parameter values	
	ntrig = 0;
	else if(  Gate == 0 ){
	ntrig = 1;

The values are set one time when gate and ntrig is high. Ntrig is turned off, then the if statement is not true anymore and goes to else if >> when gate is off, the ntrig is set to 1, ready for a new gate.

Just tested the above “only set on gate” and that didn’t work well. If I push the display button itself it stays off until next gate.

So yeah… This is not it. Need to find a better way. Though I do have a sequencer with atleast 48 of these SVG param display things, when I change preset and change them all at once, it seems to be okay, I don’t see any cpu spikes or anything. Sometimes have a few of them loaded, which is then 96 changing at a time. But yeah, need to do this in a more “correct” way, this seems a bit hacky… :laughing:

I am not sure about the step() and draw(), haven’t used that before. Will look into it.

Lookie here

and here

and here


Thanks, I’ll look into that :slight_smile:

1 Like

Would this sort of light still be affected by the “Light Bloom” setting?

You have to write it that way to consider that setting (settings::haloBrightness); but yeah, it can be done.

1 Like

um - can’t anything be done?

If a tree falls and no one is there to hear it… does it make any noise?

Can anything be done if nothing is written?

Do Abrash’s books promote zen or the opposite?

1 Like