From a67272ac54439defffcd18f4f69da4c44c596036 Mon Sep 17 00:00:00 2001 From: Andrew Belt Date: Wed, 2 May 2018 22:37:33 -0400 Subject: [PATCH] Header file tweaks --- include/dsp/frame.hpp | 2 ++ include/dsp/functions.hpp | 10 +++++++++- include/util/color.hpp | 5 +++++ include/widgets.hpp | 5 +++-- 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/include/dsp/frame.hpp b/include/dsp/frame.hpp index 91ee7510..82c8d1be 100644 --- a/include/dsp/frame.hpp +++ b/include/dsp/frame.hpp @@ -9,6 +9,8 @@ namespace rack { template struct Frame { float samples[CHANNELS]; + + Frame() {} }; } // namespace rack diff --git a/include/dsp/functions.hpp b/include/dsp/functions.hpp index 4359b906..72602612 100644 --- a/include/dsp/functions.hpp +++ b/include/dsp/functions.hpp @@ -1,6 +1,6 @@ #pragma once -#include +#include "util/math.hpp" namespace rack { @@ -42,5 +42,13 @@ inline float exponentialBipolar(float b, float x) { return (powf(b, x) - powf(b, -x)) / a; } +inline float gainToDb(float gain) { + return log10f(gain) * 20.f; +} + +inline float dbToGain(float db) { + return powf(10.f, db / 20.f); +} + } // namespace rack diff --git a/include/util/color.hpp b/include/util/color.hpp index 85fc0fbf..25134425 100644 --- a/include/util/color.hpp +++ b/include/util/color.hpp @@ -54,5 +54,10 @@ inline NVGcolor colorScreen(NVGcolor a, NVGcolor b) { return c; } +inline NVGcolor colorAlpha(NVGcolor a, float alpha) { + a.a *= alpha; + return a; +} + } // namespace rack diff --git a/include/widgets.hpp b/include/widgets.hpp index 2e021a8e..26bd710b 100644 --- a/include/widgets.hpp +++ b/include/widgets.hpp @@ -7,6 +7,7 @@ #include "util/common.hpp" #include "events.hpp" +#include "util/color.hpp" namespace rack { @@ -144,10 +145,10 @@ struct Widget { /** Helper function for creating and initializing a Widget with certain arguments (in this case just the position). In this project, you will find this idiom everywhere, as an easier alternative to constructor arguments, for building a Widget (or a subclass) with a one-liner. Example: - addChild(Widget::create(Vec(0, 0))) + addChild(Widget::create(Vec(10, 10))) */ template - static T *create(Vec pos) { + static T *create(Vec pos = Vec()) { T *o = new T(); o->box.pos = pos; return o;