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

Language Guide / Controls and Parameters

Presets

klang::Presets

Collection of named factory presets.

Each preset pairs a name with values in control order. Use the units declared by each control. Entries shorter than the control list leave the trailing controls as they are. Preset loading skips input-only controls.

Example ยท Define two starting points

Here, the controls are Cutoff in Hz and Resonance.

presets = {
    { "Soft", { 700, 0.7 } },
    { "Bright", { 4200, 1.2 } }
};

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.
 
Preset * add ()
 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;.
 
Preset & operator[] (int index)
 Returns a reference to the array item at the given index.
 
const Preset & operator[] (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

unsigned int count
 
Preset items [CAPACITY]
 

Detailed Description

Definition at line 2582 of file klang.h.

Member Function Documentation

◆ add() [1/3]

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

Definition at line 324 of file klang.h.

324 {
325 if (count < CAPACITY)
326 return &items[count++];
327 return nullptr;
328 }
Preset items[CAPACITY]
Definition klang.h:309

◆ add() [2/3]

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

Definition at line 318 of file klang.h.

318 {
319 if (count < CAPACITY)
320 items[count++] = item;
321 }

◆ add() [3/3]

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

Definition at line 2598 of file klang.h.

2598 {
2599 items[count].name = name;
2600
2601 const float preset[] = { values... };
2602 int nbValues = sizeof...(values);
2603 for (int p = 0; p < nbValues; p++)
2604 items[count].values.add(preset[p]);
2605 count++;
2606 }
Caption name
Definition klang.h:2557

References klang::Array< Preset, 128 >::count, klang::Array< Preset, 128 >::items, and klang::Preset::name.

◆ capacity()

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

Definition at line 312 of file klang.h.

312{ return CAPACITY; }

◆ clear()

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

Definition at line 331 of file klang.h.

331{ count = 0; }

◆ max()

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

Definition at line 334 of file klang.h.

334 {
335 float max = 0.f;
336 for (unsigned int i = 0; i < count; i++)
337 if (abs(items[i]) > max)
338 max = items[i];
339 return max;
340 }

◆ mean()

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

Definition at line 343 of file klang.h.

343 {
344 float sum = 0.f;
345 for (unsigned int i = 0; i < count; i++)
346 sum += abs(items[i]);
347 return sum / count;
348 }

◆ normalise()

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

Definition at line 359 of file klang.h.

359 {
360 if (!count) return;
361
362 const float current = (mode == Peak) ? max() : (mode == Mean) ? mean() : rms();
363 const float scale = current == 0.f ? 0.f : target / current;
364 for (int i = 0; i < count; i++)
365 items[i] *= scale;
366 }
@ Peak
Definition klang.h:149
@ Mean
Definition klang.h:149

◆ operator+=()

void klang::Presets::operator+= ( const Preset & preset)
inline

Definition at line 2583 of file klang.h.

2583 {
2584 items[count++] = preset;
2585 }

References klang::Array< Preset, 128 >::count, and klang::Array< Preset, 128 >::items.

Referenced by operator=().

◆ operator=() [1/2]

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

Definition at line 2587 of file klang.h.

2587 {
2588 for (int p = 0; p < 128 && presets[p].name[0]; p++)
2589 operator+=(presets[p]);
2590 }

◆ operator=() [2/2]

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

Definition at line 2592 of file klang.h.

2592 {
2593 for (auto preset : presets)
2594 operator+=(preset);
2595 }
void operator+=(const Preset &preset)
Definition klang.h:2583

References operator+=().

◆ operator[]() [1/2]

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

Definition at line 369 of file klang.h.

369{ return items[index]; }

◆ operator[]() [2/2]

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

Definition at line 372 of file klang.h.

372{ return items[index]; }

◆ rms()

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

Definition at line 351 of file klang.h.

351 {
352 float sum = 0.f;
353 for (unsigned int i = 0; i < count; i++)
354 sum += items[i] * items[i];
355 return sqrt(sum / count);
356 }

◆ size()

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

Definition at line 315 of file klang.h.

315{ return count; }

Member Data Documentation

◆ count

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

Definition at line 308 of file klang.h.

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

◆ items

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

Definition at line 309 of file klang.h.

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