Make NanoMeter usable for generic things
Signed-off-by: falkTX <falktx@falktx.com>
This commit is contained in:
parent
7f7d6bd8b2
commit
96c64ba7a9
4 changed files with 42 additions and 33 deletions
|
|
@ -23,36 +23,6 @@
|
||||||
|
|
||||||
USE_NAMESPACE_DISTRHO;
|
USE_NAMESPACE_DISTRHO;
|
||||||
|
|
||||||
/*
|
|
||||||
* Find the highest absolute and normalized value within a float array.
|
|
||||||
*/
|
|
||||||
static inline
|
|
||||||
float d_findMaxNormalizedFloat(const float floats[], const std::size_t count)
|
|
||||||
{
|
|
||||||
DISTRHO_SAFE_ASSERT_RETURN(floats != nullptr, 0.0f);
|
|
||||||
DISTRHO_SAFE_ASSERT_RETURN(count > 0, 0.0f);
|
|
||||||
|
|
||||||
static const float kEmptyFloats[8192] = {};
|
|
||||||
|
|
||||||
if (count <= 8192 && std::memcmp(floats, kEmptyFloats, count) == 0)
|
|
||||||
return 0.0f;
|
|
||||||
|
|
||||||
float tmp, maxf2 = std::abs(floats[0]);
|
|
||||||
|
|
||||||
for (std::size_t i=1; i<count; ++i)
|
|
||||||
{
|
|
||||||
tmp = std::abs(*floats++);
|
|
||||||
|
|
||||||
if (tmp > maxf2)
|
|
||||||
maxf2 = tmp;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (maxf2 > 1.0f)
|
|
||||||
maxf2 = 1.0f;
|
|
||||||
|
|
||||||
return maxf2;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<int numIO>
|
template<int numIO>
|
||||||
struct HostAudio : Module {
|
struct HostAudio : Module {
|
||||||
CardinalPluginContext* const pcontext;
|
CardinalPluginContext* const pcontext;
|
||||||
|
|
@ -65,6 +35,8 @@ struct HostAudio : Module {
|
||||||
// for rack core audio module compatibility
|
// for rack core audio module compatibility
|
||||||
dsp::RCFilter dcFilters[numIO];
|
dsp::RCFilter dcFilters[numIO];
|
||||||
bool dcFilterEnabled = (numIO == 2);
|
bool dcFilterEnabled = (numIO == 2);
|
||||||
|
|
||||||
|
// for stereo meter
|
||||||
volatile bool resetMeters = true;
|
volatile bool resetMeters = true;
|
||||||
float gainMeterL = 0.0f;
|
float gainMeterL = 0.0f;
|
||||||
float gainMeterR = 0.0f;
|
float gainMeterR = 0.0f;
|
||||||
|
|
@ -190,7 +162,10 @@ struct HostAudioNanoMeter : NanoMeter {
|
||||||
HostAudio<numIO>* const module;
|
HostAudio<numIO>* const module;
|
||||||
|
|
||||||
HostAudioNanoMeter(HostAudio<numIO>* const m)
|
HostAudioNanoMeter(HostAudio<numIO>* const m)
|
||||||
: module(m) {}
|
: module(m)
|
||||||
|
{
|
||||||
|
hasGainKnob = true;
|
||||||
|
}
|
||||||
|
|
||||||
void updateMeters() override
|
void updateMeters() override
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -29,7 +29,7 @@ template<int hp>
|
||||||
struct ModuleWidgetWithSideScrews : ModuleWidget {
|
struct ModuleWidgetWithSideScrews : ModuleWidget {
|
||||||
static constexpr const float startX_In = 10.65f;
|
static constexpr const float startX_In = 10.65f;
|
||||||
static constexpr const float startX_Out = (hp - 3) * 15 + startX_In;
|
static constexpr const float startX_Out = (hp - 3) * 15 + startX_In;
|
||||||
static constexpr const float startY = 73.0f; // note out bg box has 2px extra
|
static constexpr const float startY = 73.0f; // note: out bg box has 2px extra
|
||||||
static constexpr const float padding = 29.0f;
|
static constexpr const float padding = 29.0f;
|
||||||
static constexpr const float middleX = startX_In + (startX_Out - startX_In) * 0.5f /*+ padding * 0.35f*/;
|
static constexpr const float middleX = startX_In + (startX_Out - startX_In) * 0.5f /*+ padding * 0.35f*/;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -242,6 +242,7 @@ struct NanoKnob : Knob {
|
||||||
};
|
};
|
||||||
|
|
||||||
struct NanoMeter : Widget {
|
struct NanoMeter : Widget {
|
||||||
|
bool hasGainKnob = false;
|
||||||
float gainMeterL = 0.0f;
|
float gainMeterL = 0.0f;
|
||||||
float gainMeterR = 0.0f;
|
float gainMeterR = 0.0f;
|
||||||
|
|
||||||
|
|
@ -252,7 +253,7 @@ struct NanoMeter : Widget {
|
||||||
if (layer != 1)
|
if (layer != 1)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const float usableHeight = box.size.y - 10.0f;
|
const float usableHeight = box.size.y - (hasGainKnob ? 10.0f : 0.0f);
|
||||||
|
|
||||||
// draw background
|
// draw background
|
||||||
nvgBeginPath(args.vg);
|
nvgBeginPath(args.vg);
|
||||||
|
|
@ -281,6 +282,9 @@ struct NanoMeter : Widget {
|
||||||
nvgFill(args.vg);
|
nvgFill(args.vg);
|
||||||
nvgStroke(args.vg);
|
nvgStroke(args.vg);
|
||||||
|
|
||||||
|
if (! hasGainKnob)
|
||||||
|
return;
|
||||||
|
|
||||||
nvgLineCap(args.vg, NVG_ROUND);
|
nvgLineCap(args.vg, NVG_ROUND);
|
||||||
|
|
||||||
nvgBeginPath(args.vg);
|
nvgBeginPath(args.vg);
|
||||||
|
|
|
||||||
|
|
@ -44,3 +44,33 @@ extern Model* modelHostTime;
|
||||||
extern Model* modelIldaeil;
|
extern Model* modelIldaeil;
|
||||||
extern Model* modelMPV;
|
extern Model* modelMPV;
|
||||||
extern Model* modelTextEditor;
|
extern Model* modelTextEditor;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Find the highest absolute and normalized value within a float array.
|
||||||
|
*/
|
||||||
|
static inline
|
||||||
|
float d_findMaxNormalizedFloat(const float floats[], const std::size_t count)
|
||||||
|
{
|
||||||
|
DISTRHO_SAFE_ASSERT_RETURN(floats != nullptr, 0.0f);
|
||||||
|
DISTRHO_SAFE_ASSERT_RETURN(count > 0, 0.0f);
|
||||||
|
|
||||||
|
static const float kEmptyFloats[8192] = {};
|
||||||
|
|
||||||
|
if (count <= 8192 && std::memcmp(floats, kEmptyFloats, count) == 0)
|
||||||
|
return 0.0f;
|
||||||
|
|
||||||
|
float tmp, maxf2 = std::abs(floats[0]);
|
||||||
|
|
||||||
|
for (std::size_t i=1; i<count; ++i)
|
||||||
|
{
|
||||||
|
tmp = std::abs(*floats++);
|
||||||
|
|
||||||
|
if (tmp > maxf2)
|
||||||
|
maxf2 = tmp;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (maxf2 > 1.0f)
|
||||||
|
maxf2 = 1.0f;
|
||||||
|
|
||||||
|
return maxf2;
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue