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

Factory presets. More...

#include <klang.h>

+ Inheritance diagram for klang::Presets:

Public Member Functions

void operator+= (const Preset &preset)
 
void operator= (const Presets &presets)
 
void operator= (std::initializer_list< Preset > presets)
 
template<typename... Values>
void add (const char *name, const Values... values)
 
unsigned int size () const
 The current number of items in the array.
 
void add (const Preset &item)
 Add the specified item to the end of the array.
 
Presetadd ()
 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;.
 
Presetoperator[] (int index)
 Returns a reference to the array item at the given index.
 
const Presetoperator[] (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

Preset items [CAPACITY]
 
unsigned int count
 

Detailed Description

Definition at line 1160 of file klang.h.

Member Function Documentation

◆ add() [1/3]

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

Definition at line 255 of file klang.h.

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

◆ add() [2/3]

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

Definition at line 249 of file klang.h.

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

◆ add() [3/3]

template<typename... Values>
void klang::Presets::add ( const char * name,
const Values... values )
inline

Definition at line 1176 of file klang.h.

1176 {
1177 items[count].name = name;
1178
1179 const float preset[] = { values... };
1180 int nbValues = sizeof...(values);
1181 for(int p=0; p<nbValues; p++)
1182 items[count].values.add(preset[p]);
1183 count++;
1184 }
Caption name
Definition klang.h:1145

◆ capacity()

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

Definition at line 243 of file klang.h.

243{ return CAPACITY; }

◆ clear()

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

Definition at line 262 of file klang.h.

262{ count = 0; }

◆ max()

float klang::Array< Preset, 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< Preset, 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< Preset, 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::Presets::operator+= ( const Preset & preset)
inline

Definition at line 1161 of file klang.h.

1161 {
1162 items[count++] = preset;
1163 }

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

◆ operator=() [1/2]

void klang::Presets::operator= ( const Presets & presets)
inline

Definition at line 1165 of file klang.h.

1165 {
1166 for (int p = 0; p < 128 && presets[p].name[0]; p++)
1167 operator+=(presets[p]);
1168 }

References klang::Preset::name, operator+=(), and klang::Array< TYPE, CAPACITY >::operator[]().

◆ operator=() [2/2]

void klang::Presets::operator= ( std::initializer_list< Preset > presets)
inline

Definition at line 1170 of file klang.h.

1170 {
1171 for(auto preset : presets)
1172 operator+=(preset);
1173 }
void operator+=(const Preset &preset)
Definition klang.h:1161

References operator+=().

◆ operator[]() [1/2]

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

Definition at line 300 of file klang.h.

300{ return items[index]; }

◆ operator[]() [2/2]

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

Definition at line 303 of file klang.h.

303{ return items[index]; }

◆ rms()

float klang::Array< Preset, 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< Preset, CAPACITY >::size ( ) const
inlineinherited

Definition at line 246 of file klang.h.

246{ return count; }

Member Data Documentation

◆ count

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

Definition at line 240 of file klang.h.

◆ items

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

Definition at line 239 of file klang.h.