Klang C++
Language Reference (draft)
Loading...
Searching...
No Matches
klang::Controls

Plugin UI controls. More...

#include <klang.h>

+ Inheritance diagram for klang::Controls:

Public Member Functions

void operator+= (const Control &control)
 
void operator= (const Controls &controls)
 
void operator= (std::initializer_list< Control > controls)
 
void add (const char *name, Control::Type type=Control::ROTARY, float min=0.f, float max=1.f, float initial=0.f, Control::Size size=Automatic)
 
bool changed ()
 
unsigned int size () const
 The current number of items in the array.
 
void add (const Control &item)
 Add the specified item to the end of the array.
 
Controladd ()
 Add a blank item to the end of the array, returning a pointer that allows the item to be modified.
 
void clear ()
 Clear the array contents. Only resets the item count, without wiping memory.
 
float max () const
 Find the maximum value in the array.
 
float mean () const
 Find the mean average of values in the array.
 
float rms () const
 Find the root mean squared (RMS) average of values in the array.
 
void normalise (float target=1.f, int mode=Peak)
 Normalises values in the array to the specified target, based on peak, mean, or RMS value;.
 
Controloperator[] (int index)
 Returns a reference to the array item at the given index.
 
const Controloperator[] (int index) const
 Returns a read-only reference to the array item at the given index.
 

Static Public Member Functions

static int capacity ()
 The maximum capacity of the array.
 

Public Attributes

float value [128] = { 0 }
 
Control items [CAPACITY]
 
unsigned int count
 

Detailed Description

Definition at line 1095 of file klang.h.

Member Function Documentation

◆ add() [1/3]

Control * klang::Array< Control, CAPACITY >::add ( )
inlineinherited

Definition at line 255 of file klang.h.

255 {
256 if (count < CAPACITY)
257 return &items[count++];
258 return nullptr;
259 }
Control items[CAPACITY]
Definition klang.h:239

◆ add() [2/3]

void klang::Array< Control, CAPACITY >::add ( const Control & item)
inlineinherited

Definition at line 249 of file klang.h.

249 {
250 if(count < CAPACITY)
251 items[count++] = item;
252 }

◆ add() [3/3]

void klang::Controls::add ( const char * name,
Control::Type type = Control::ROTARY,
float min = 0.f,
float max = 1.f,
float initial = 0.f,
Control::Size size = Automatic )
inline

Definition at line 1113 of file klang.h.

1113 {
1114 items[count].name = name;
1115 items[count].type = type;
1116 items[count].min = min;
1117 items[count].max = max;
1118 items[count].initial = initial;
1119 items[count].size = size;
1120 items[count++].value = initial;
1121 }
TYPE1 min(TYPE1 a, TYPE2 b)
Return the minimum of two values.
Definition klang.h:212
unsigned int size() const
Definition klang.h:246
Caption name
Definition klang.h:983
float max
Definition klang.h:987
signal value
Definition klang.h:993
float min
Definition klang.h:986
float initial
Definition klang.h:988

References klang::Control::initial, klang::Control::max, klang::Control::min, klang::Control::name, klang::Text< SIZE >::operator=(), klang::Control::size, klang::Control::type, and klang::Control::value.

◆ capacity()

static int klang::Array< Control, CAPACITY >::capacity ( )
inlinestaticinherited

Definition at line 243 of file klang.h.

243{ return CAPACITY; }

◆ changed()

bool klang::Controls::changed ( )
inline

Definition at line 1123 of file klang.h.

1123 {
1124 bool changed = false;
1125 for (unsigned int c = 0; c < count; c++) {
1126 if (items[c].value != value[c]) {
1127 value[c] = items[c].value;
1128 changed = true;
1129 }
1130 }
1131 return changed;
1132 }
bool changed()
Definition klang.h:1123
float value[128]
Definition klang.h:1097

References klang::Control::value, and value.

◆ clear()

void klang::Array< Control, CAPACITY >::clear ( )
inlineinherited

Definition at line 262 of file klang.h.

262{ count = 0; }

◆ max()

float klang::Array< Control, CAPACITY >::max ( ) const
inlineinherited

Definition at line 265 of file klang.h.

265 {
266 float max = 0.f;
267 for (unsigned int i = 0; i < count; i++)
268 if (abs(items[i]) > max)
269 max = items[i];
270 return max;
271 }

◆ mean()

float klang::Array< Control, CAPACITY >::mean ( ) const
inlineinherited

Definition at line 274 of file klang.h.

274 {
275 float sum = 0.f;
276 for (unsigned int i = 0; i < count; i++)
277 sum += abs(items[i]);
278 return sum / count;
279 }

◆ normalise()

void klang::Array< Control, CAPACITY >::normalise ( float target = 1.f,
int mode = Peak )
inlineinherited

Definition at line 290 of file klang.h.

290 {
291 if (!count) return;
292
293 const float current = (mode == Peak) ? max() : (mode == Mean) ? mean() : rms();
294 const float scale = current == 0.f ? 0.f : target / current;
295 for (int i = 0; i < count; i++)
296 items[i] *= scale;
297 }
@ Peak
Definition klang.h:83
@ Mean
Definition klang.h:83

◆ operator+=()

void klang::Controls::operator+= ( const Control & control)
inline

Definition at line 1099 of file klang.h.

1099 {
1100 items[count++] = control;
1101 }

Referenced by operator=(), and operator=().

◆ operator=() [1/2]

void klang::Controls::operator= ( const Controls & controls)
inline

Definition at line 1103 of file klang.h.

1103 {
1104 for (int c = 0; c < 128 && controls[c].type != Control::NONE; c++)
1105 operator+=(controls[c]);
1106 }

References klang::Control::NONE, operator+=(), klang::Array< TYPE, CAPACITY >::operator[](), and klang::Control::type.

◆ operator=() [2/2]

void klang::Controls::operator= ( std::initializer_list< Control > controls)
inline

Definition at line 1108 of file klang.h.

1108 {
1109 for(auto control : controls)
1110 operator+=(control);
1111 }
void operator+=(const Control &control)
Definition klang.h:1099

References operator+=().

◆ operator[]() [1/2]

Control & klang::Array< Control, CAPACITY >::operator[] ( int index)
inlineinherited

Definition at line 300 of file klang.h.

300{ return items[index]; }

◆ operator[]() [2/2]

const Control & klang::Array< Control, CAPACITY >::operator[] ( int index) const
inlineinherited

Definition at line 303 of file klang.h.

303{ return items[index]; }

◆ rms()

float klang::Array< Control, CAPACITY >::rms ( ) const
inlineinherited

Definition at line 282 of file klang.h.

282 {
283 float sum = 0.f;
284 for (unsigned int i = 0; i < count; i++)
285 sum += items[i] * items[i];
286 return sqrt(sum / count);
287 }

◆ size()

unsigned int klang::Array< Control, CAPACITY >::size ( ) const
inlineinherited

Definition at line 246 of file klang.h.

246{ return count; }

Member Data Documentation

◆ count

unsigned int klang::Array< Control, CAPACITY >::count
inherited

Definition at line 240 of file klang.h.

◆ items

Control klang::Array< Control, CAPACITY >::items[CAPACITY]
inherited

Definition at line 239 of file klang.h.

◆ value

float klang::Controls::value[128] = { 0 }

Definition at line 1097 of file klang.h.

1097{ 0 };

Referenced by changed().