EffectBase Documentation

GitHub repository: https://github.com/KaixoCode/SoundMixr

Documentation

Pair

template<typename T>
class Pair

Simple pair used for size/position/range.

Object

class Effects::Object

Basis for any Effect related object

Subclassed by Effects::Div, Effects::DropDown, Effects::DynamicsSlider, Effects::Parameter, Effects::RadioButton, Effects::ToggleButton, Effects::XYController

Public Functions

void Size(const Pair<int> &size)

Set the size.

Parameters
  • size: size

auto Size() -> Pair<int>

Get the size.

Return

size

void Position(const Pair<int> &p)

Set the position.

Parameters
  • p: position

auto Position() -> Pair<int>

Get the position.

Return

position

Div

struct Effects::Div : public Effects::Object

Public Types

enum Alignment

Allignment of objects inside of a Div.

Values:

enumerator Left
enumerator Right
enumerator Top
enumerator Bottom
enumerator Center
enumerator Vertical
enumerator Horizontal
enum Type

Type of Div. Either containing a single Object or more Divs.

Values:

enumerator Divs
enumerator Object

Public Functions

Div(Alignment t = Alignment::Horizontal)

Constructor.

Parameters
  • t: alignment

auto DivType() -> Type

Get the type of this Div, either Divs or Object.

void Align(Alignment a)

Depending on the Div type: Set the alignment of the Divs contained in this Div or the alignment of the Object in this Div.

Parameters
  • a: alignment

auto Align() -> Alignment

Get the current alignment of this Div.

auto Object() -> Object&

Get the object if this Div is of type Object.

Return

object

void Object(Effects::Object *o)

Set the object if this Div is of type Object.

Parameters
  • o: object

void Object(Effects::Object &o)

Set the object if this Div is of type Object.

Parameters
  • o: object

void Padding(int s)

Set padding for this Div.

Parameters
  • s: padding

int Padding()

Get padding for this Div.

Return

padding

void Dividers(bool s)

When Dividers is set to true, the interpretter will put dividers between the Divs contained in this Div.

Parameters
  • s: dividers

bool Dividers()

Returns true when dividers should be displayed between the Divs inside this Div.

Return

true if has dividers

void DivSize(int s)

Set the size of this Div in pixels.

Parameters
  • s: size

int DivSize()

Get the size of this Div in pixels.

Return

size

auto Divs() -> std::vector<std::unique_ptr<Div>>&

Returns all the Divs inside this Div.

Return

all the Divs in this Div

void Divs(int i)

Set the amount of Divs in this Div.

Parameters
  • i: amount of Divs

Div &operator[](int index)

Get the Div at the index.

Parameters
  • index: index

void operator=(Effects::Object &o)

Set the object if this Div is of type Object.

Parameters
  • o: object

void operator=(Effects::Object *o)

Set the object if this Div is of type Object.

Parameters
  • o: object

Public Static Attributes

int AUTO = -1

When DivSize is set to AUTO (-1), the layout interpretter will equally divide available space between all Divs marked AUTO within a Div.

Parameter

class Effects::Parameter : public Effects::Object

Parameter base class, anything that has a range and a value, slider/knob etc.

Subclassed by Effects::VolumeSlider

Public Functions

Parameter(const std::string &name = "", ParameterType t = ParameterType::Knob)

Constructor.

Parameters
  • name: name

  • t: type

void Name(const std::string &n)

Set the name of this Parameter.

Parameters
  • n: name

auto Name() -> std::string&

Get the name of this Parameter.

Return

name

void Range(const Pair<double> &r)

Set the range of this Parameter.

Parameters
  • r: range

auto Range() -> Pair<double> const

Get the range of this Parameter.

Return

range

void Value(double v)

Set the value of this Parameter.

Parameters
  • v: value

double Value() const

Get the value of this Parameter.

Return

value

void NormalizedValue(double v)

Set the normalized value of this Parameter.

Parameters
  • v: normalized value

double NormalizedValue() const

Get the normalized value of this Parameter.

Return

normalized value

void ResetValue(double v)

Set the reset-value of this Parameter.

Parameters
  • v: reset-value

void ResetValue()

Reset the value to the reset-value of this Parameter.

void Multiplier(double v)

Set a Multiplier for the speed at which the parameter value changes per pixel dragged with the mouse.

Parameters
  • v: multiplier

double Multiplier()

Get the Multiplier for the speed at which the parameter value changes per pixel dragged with the mouse.

Return

multiplier

void Power(double v)

Set a power to this parameter’s value range, useful when a range is non-linear.

Parameters
  • v: power

double Power()

Get the power to this parameter’s value range.

Return

power

bool Vertical()

Is this parameter displayed/dragged vertically?

void Vertical(bool v)

Is this parameter displayed/dragged vertically?

Parameters
  • v: vertical

void Unit(const std::string &str, int tenp = 0)

Set a Unit to display behind the value of this Parameter. the ‘tenp’ determines the power of 10 at which this unit is displayed. For example, (“kHz”, 3) and (“Hz”, 0) will display Hz up to 1000, and after that kHz.

Parameters
  • str: unit

  • tenp: power of 10

auto Units() -> std::unordered_map<int, std::string>&

Get a map of all units defined for this Parameter.

Return

all units

void Decimals(int d)

Set the amount of decimals that should be displayed for this Parameter.

Parameters
  • d: decimals

int Decimals()

Get the amount of decimals that will be displayed for this Parameter.

Return

decimals

bool DisplayValue()

Returns true when the value should be displayed.

Return

true when value should be displayed

void DisplayValue(bool v)

Enable/Disable the displaying of the value.

Parameters
  • v: display value

bool DisplayName()

Returns true when the name should be displayed.

Return

true when value should be displayed

void DisplayName(bool v)

Enable/Disable the displaying of the name.

Parameters
  • v: display name

bool Disabled()

Returns true when this Parameter is disabled.

Return

true when disabled

void Disable()

Disable this Parameter.

void Enable()

Enable this Parameter.

auto Type() -> ParameterType

Returns the type of this Parameter.

Return

type

VolumeSlider

class Effects::VolumeSlider : public Effects::Parameter

A volume slider, with a display of a level meter with variable amount of channels.

Public Functions

void Channels(int n)

Set the amount of channels.

Parameters
  • n: channels.

int Channels()

Get the amount of channels for this VolumeSlider.

Return

amount of channels

auto Values() -> std::vector<float>

Get the list of levels of all channels in this VolumeSlider. These will be displayed behind the adjusted levels.

Return

levels

auto Reduces() -> std::vector<float>

Get the list of adjusted levels of all channels in this VolumeSlider. These will be displayed in front of the levels.

Return

adjusted levels

void SetValue(int i, float v)

Set a level for channel i.

Parameters
  • i: channel

  • v: level

void SetReduce(int i, float v)

Set an adjusted level for channel i.

Parameters
  • i: channel

  • v: adjusted level

ToggleButton

class Effects::ToggleButton : public Effects::Object

Simple toggleable button.

Public Functions

ToggleButton(const std::string &n)

Constructor.

Parameters
  • n: name

void State(bool s)

Set the state of this button.

Parameters
  • s: state

bool State()

Get the state of this button.

Return

state

auto Name() -> std::string&

Get the name of this button.

Return

name

Public Members

bool state = false

The state of this toggle button.

RadioButton

class Effects::RadioButton : public Effects::Object

Simple radio button.

Public Functions

RadioButton(const std::string &n, int id, std::function<void()> callback = [] {})

Constructor

Parameters
  • n: name

  • id: id of the group of buttons this is part of

  • callback: callback

void Selected(bool s)

Select this button in the group of buttons with the same id. Will call the callback!

Parameters
  • s: select

bool Selected()

Returns true when this button is selected.

Return

true when selected

int Id()

Returns the id of the group of buttons this button is part of.

Return

id

auto Name() -> std::string&

Returns name

Return

name

Public Members

std::function<void()> Callback

The callback.

bool selected = false

True when this button is selected. Use Selected(bool s) when changing the state! This is simply exposed so the Gui component can directly link with this boolean.

XYController

class Effects::XYController : public Effects::Object

Simple X-Y controller.

Public Functions

XYController(Parameter &p1, Parameter &p2)

Constructor

Parameters
  • p1: parameter to control the x-axis

  • p2: parameter to control the y-axis

Parameter &Param1()

Get the parameter for the x-axis.

Return

param1

Parameter &Param2()

Get the parameter for the y-axis.

Return

param2

EffectBase

class Effects::EffectBase

Base for any Effect.

Public Functions

EffectBase(const std::string &name)

Constructor

Parameters
  • name: name

void Update()

This is called each frame.

float NextSample(float in, int c) = 0

Generate the next sample.

Return

next sample

Parameters
  • in: sample

  • c: channel

void Channels(int c)

This is called whenever the amount of channels changes. Use this to update any buffers you have to make sure you have enough space for ‘c’ channels

Parameters
  • c: channels

operator nlohmann::json() = 0

This operator is used to save the settings of this Effect.

void operator=(const nlohmann::json &json) = 0

This operator is used to load the settings of this Effect.

void SampleRate(double s)

Set the samplerate.

Parameters
  • s: samplerate

double SampleRate()

Get the samplerate.

Return

samplerate

auto Name() -> const std::string&

Get the name of this Effect.

Return

name

void Height(int h)

Set the height of this Effect.

Parameters
  • h: height

int Height()

Get the height of this Effect.

Return

height

int Width()

Get the width of this Effect.

Return

width

auto Div() -> Effects::Div&

Get the layout Div of this Effect.

Return

div

Effects::Parameter &Parameter(const std::string &name, ParameterType type)

Emplace a Parameter.

Parameters
  • name: name

  • type: type

Effects::DropDown &DropDown()

Emplace a DropDown.

Effects::ToggleButton &Toggle(const std::string &name)

Emplace a Toggle Button.

Parameters
  • name: name

Effects::VolumeSlider &VolumeSlider()

Emplace a VolumeSlider.

Effects::DynamicsSlider &DynamicsSlider()

Emplace a DynamicsSlider.

Effects::RadioButton &RadioButton(const std::string &name, int id, std::function<void()> callback = [] {})

Emplace a RadioButton.

Parameters
  • name: name

  • id: group id

  • callback: callback

Effects::XYController &XYController(Effects::Parameter &p1, Effects::Parameter &p2)

Emplace a XYController.

Parameters
  • p1: x-axis parameter

  • p2: y-axis parameter

std::vector<std::unique_ptr<Effects::Object>> &Objects()

Get all objects in this Effect.

Return

objects

Examples

Simple Volume Effect

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#include <EffectBase.hpp>

namespace Effects
{
    /**
     * Simple Volume effect example.
     */
    class Volume : public EffectBase
    {
    public:
        Volume()
            : 
            // Initialize the volume knob
            m_Volume(Parameter("Volume", ParameterType::Knob)),
            EffectBase("Volume") // Set name of effect in EffectBase constructor
        {
            // Set the height of the effect to 80.
            Height(80);

            // Some settings for the volume knob
            m_Volume.Size({ 30, 30 });
            m_Volume.Range({ 0, 100 });
            m_Volume.Unit("%");
            m_Volume.Decimals(1);            
            m_Volume.ResetValue(100);
            m_Volume.ResetValue();
            m_Volume.Multiplier(0.4);
            
            // Put the volume knob in the center of the entire Div.
            Div().Align(Div::Alignment::Center);
            Div() = m_Volume;
        }

        float NextSample(float in, int c) 
        {
            // Multiply the incoming sample with the volume knob
            return in * m_Volume.Value() * 0.01;
        }

        operator nlohmann::json() 
        {
            // Save the value of the volume knob.
            nlohmann::json _json = nlohmann::json::object();
            _json["volume"] = m_Volume.Value();
            return _json;
        }

        void operator=(const nlohmann::json& json)
        {
            // Load the value of the volume knob.
            m_Volume.Value(json.at("volume").get<double>());
        }

    private:

        // The volume parameter
        Effects::Parameter& m_Volume;
    };
}

/**
 * MAKE SURE TO ADD THIS METHOD!!
 * This allows the Gui to create an instance of the effect.
 */
extern "C"
{
    DLLDIR void* NewInstance()
    {
        return new Effects::Volume();
    }
}