VCV Rack API v2
Loading...
Searching...
No Matches
Quantity.hpp
Go to the documentation of this file.
1#pragma once
2#include <common.hpp>
3#include <math.hpp>
4#include <random.hpp>
5
6
7namespace rack {
8
9
14struct Quantity {
15 virtual ~Quantity() {}
16
20 virtual void setValue(float value) {}
21
25 virtual float getValue() {
26 return 0.f;
27 }
28
30 virtual float getMinValue() {
31 return 0.f;
32 }
33
35 virtual float getMaxValue() {
36 return 1.f;
37 }
38
40 virtual float getDefaultValue() {
41 return 0.f;
42 }
43
47 virtual float getDisplayValue();
48
50 virtual void setDisplayValue(float displayValue);
51
53 virtual int getDisplayPrecision();
54
56 virtual std::string getDisplayValueString();
57
59 virtual void setDisplayValueString(std::string s);
60
62 virtual std::string getLabel() {
63 return "";
64 }
65
69 virtual std::string getUnit() {
70 return "";
71 }
72
74 virtual std::string getString();
75
77 virtual void reset();
78
80 virtual void randomize();
81
82 // Helper methods
83
85 bool isMin();
87 bool isMax();
89 void setMin();
91 void setMax();
93 void toggle();
95 void moveValue(float deltaValue);
96
98 float getRange();
100 bool isBounded();
102 float toScaled(float value);
104 float fromScaled(float scaledValue);
106 void setScaledValue(float scaledValue);
110 void moveScaledValue(float deltaScaledValue);
111};
112
113
114} // namespace rack
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
A controller for manipulating a float value (which subclasses must store somehow) with limits and lab...
Definition Quantity.hpp:14
float toScaled(float value)
Transforms a value to the range 0 to 1.
float fromScaled(float scaledValue)
Transforms a value from the range 0 to 1.
virtual int getDisplayPrecision()
The number of total decimal places for generating the display value string.
virtual float getMaxValue()
Returns the maximum recommended value.
Definition Quantity.hpp:35
virtual float getDisplayValue()
Returns the value, transformed for displaying.
virtual float getMinValue()
Returns the minimum recommended value.
Definition Quantity.hpp:30
virtual ~Quantity()
Definition Quantity.hpp:15
bool isMin()
Checks whether the value is at the min value.
virtual float getDefaultValue()
Returns the default value, for resetting.
Definition Quantity.hpp:40
virtual void setDisplayValueString(std::string s)
Sets the value from a display string.
void setMin()
Sets the value to the min value.
void setMax()
Sets the value to the max value.
virtual std::string getDisplayValueString()
Returns a string representation of the display value.
float getRange()
The difference between the max and min values.
float getScaledValue()
Returns the value scaled to the range 0 to 1.
bool isMax()
Checks whether the value is at the max value.
virtual void setDisplayValue(float displayValue)
Inversely transforms the display value and sets the value.
virtual float getValue()
Returns the value.
Definition Quantity.hpp:25
bool isBounded()
Checks whether the bounds are finite.
virtual void randomize()
Sets the value to a uniform random value between the bounds.
virtual std::string getLabel()
The name of the quantity.
Definition Quantity.hpp:62
void moveScaledValue(float deltaScaledValue)
Adds an amount to the value scaled to the range 0 to 1.
virtual void reset()
Resets the value to the default value.
virtual std::string getUnit()
The unit abbreviation of the quantity.
Definition Quantity.hpp:69
void moveValue(float deltaValue)
Adds an amount to the value.
virtual void setValue(float value)
Sets the value directly.
Definition Quantity.hpp:20
virtual std::string getString()
Returns a string representation of the quantity.
void toggle()
Sets the value to max if the current value is min, otherwise sets the value to min.
void setScaledValue(float scaledValue)
Sets value from the range 0 to 1.