VCV Rack API v2
Loading...
Searching...
No Matches
Light.hpp
Go to the documentation of this file.
1#pragma once
2#include <common.hpp>
3
4
5namespace rack {
6namespace engine {
7
8
9struct Light {
13 float value = 0.f;
14
16 void setBrightness(float brightness) {
17 value = brightness;
18 }
19
20 float getBrightness() {
21 return value;
22 }
23
27 void setBrightnessSmooth(float brightness, float deltaTime, float lambda = 30.f) {
28 if (brightness < value) {
29 // Fade out light
30 value += (brightness - value) * lambda * deltaTime;
31 }
32 else {
33 // Immediately illuminate light
34 value = brightness;
35 }
36 }
38 void setSmoothBrightness(float brightness, float deltaTime) {
39 setBrightnessSmooth(brightness, deltaTime);
40 }
41
43 DEPRECATED void setBrightnessSmooth(float brightness, int frames = 1) {
44 setBrightnessSmooth(brightness, frames / 44100.f);
45 }
46};
47
48
49} // namespace engine
50} // namespace rack
#define DEPRECATED
Attribute for deprecated functions and symbols.
Definition common.hpp:26
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
Definition Light.hpp:9
float getBrightness()
Definition Light.hpp:20
DEPRECATED void setBrightnessSmooth(float brightness, int frames=1)
Use setBrightnessSmooth(brightness, sampleTime * frames) instead.
Definition Light.hpp:43
void setBrightnessSmooth(float brightness, float deltaTime, float lambda=30.f)
Emulates light decay with slow fall but immediate rise.
Definition Light.hpp:27
float value
The square of the brightness.
Definition Light.hpp:13
void setSmoothBrightness(float brightness, float deltaTime)
DEPRECATED Alias for setBrightnessSmooth()
Definition Light.hpp:38
void setBrightness(float brightness)
Sets the brightness immediately with no light decay.
Definition Light.hpp:16