level meter (need to make it less flashy though)
parent
ec94dce150
commit
b86452b1af
|
@ -0,0 +1,124 @@
|
|||
#include "quicklevel.h"
|
||||
using Xybrid::Gadgets::QuickLevel;
|
||||
using namespace Xybrid::Data;
|
||||
|
||||
#include <QPainter>
|
||||
#include <QGraphicsScene>
|
||||
#include <QStyleOptionGraphicsItem>
|
||||
|
||||
#define qs QStringLiteral
|
||||
|
||||
#include "config/pluginregistry.h"
|
||||
using namespace Xybrid::Config;
|
||||
|
||||
#include "audio/audioengine.h"
|
||||
using namespace Xybrid::Audio;
|
||||
|
||||
#include "ui/patchboard/nodeobject.h"
|
||||
using namespace Xybrid::UI;
|
||||
|
||||
#include "data/audioframe.h"
|
||||
#include "data/porttypes.h"
|
||||
|
||||
namespace {
|
||||
bool _ = PluginRegistry::enqueueRegistration([] {
|
||||
auto i = std::make_shared<PluginInfo>();
|
||||
i->id = "gadget:quicklevel";
|
||||
i->displayName = "Quick Level";
|
||||
i->category = "Gadget";
|
||||
i->createInstance = []{ return std::make_shared<QuickLevel>(); };
|
||||
PluginRegistry::registerPlugin(i);
|
||||
//inf = i;
|
||||
});
|
||||
}
|
||||
|
||||
QuickLevel::QuickLevel() {
|
||||
|
||||
}
|
||||
|
||||
void QuickLevel::init() {
|
||||
auto in = addPort(Port::Input, Port::Audio, 0);
|
||||
auto out = addPort(Port::Output, Port::Audio, 0);
|
||||
out->passthroughTo = in;
|
||||
}
|
||||
|
||||
void QuickLevel::process() {
|
||||
auto in = std::static_pointer_cast<AudioPort>(port(Port::Input, Port::Audio, 0));
|
||||
in->pull();
|
||||
size_t ts = audioEngine->curTickSize();
|
||||
|
||||
for (size_t c = 0; c < 2; c++) {
|
||||
lv[c][0] = std::numeric_limits<double>::max();
|
||||
lv[c][1] = std::numeric_limits<double>::min();
|
||||
}
|
||||
|
||||
for (size_t s = 0; s < ts; s++) {
|
||||
AudioFrame f = (*in)[s];
|
||||
lv[0][0] = std::min(lv[0][0], f.l);
|
||||
lv[0][1] = std::max(lv[0][1], f.l);
|
||||
lv[1][0] = std::min(lv[1][0], f.r);
|
||||
lv[1][1] = std::max(lv[1][1], f.r);
|
||||
}
|
||||
|
||||
//if (obj) obj->update(obj->boundingRect());
|
||||
if (obj) obj->scene()->update();
|
||||
}
|
||||
|
||||
void QuickLevel::onGadgetCreated() {
|
||||
if (!obj) return;
|
||||
|
||||
obj->customChrome = true;
|
||||
//obj->autoPositionPorts = false;
|
||||
//qreal ps = (PortObject::portSize + PortObject::portSpacing) * 2;
|
||||
obj->setGadgetSize(QPointF(48, 95));
|
||||
}
|
||||
|
||||
void QuickLevel::drawCustomChrome(QPainter* painter, const QStyleOptionGraphicsItem* opt) {
|
||||
QColor outline = QColor(31, 31, 31);
|
||||
if (opt->state & QStyle::State_Selected) outline = QColor(127, 127, 255);
|
||||
|
||||
auto r = obj->boundingRect();
|
||||
//auto rf = r - QMarginsF(1, 1, 1, 1);
|
||||
|
||||
QLinearGradient fill(QPointF(0, 0), QPointF(0, r.height()));
|
||||
fill.setColorAt(0, QColor(95, 95, 95));
|
||||
fill.setColorAt(16.0/r.height(), QColor(63, 63, 63));
|
||||
fill.setColorAt(1.0 - (1.0 - 16.0/r.height()) / 2, QColor(55, 55, 55));
|
||||
fill.setColorAt(1, QColor(35, 35, 35));
|
||||
|
||||
painter->setRenderHint(QPainter::RenderHint::Antialiasing);
|
||||
painter->setBrush(QBrush(fill));
|
||||
painter->setPen(QPen(QBrush(outline), 2));
|
||||
painter->drawRoundedRect(r, 8, 8);
|
||||
|
||||
QSizeF barSize(16, 81);
|
||||
//QRectF barL(r.topLeft() + QPointF(1, 1), barSize);
|
||||
QRectF barL(QPointF(), barSize);
|
||||
QRectF barR(QPointF(), barSize);
|
||||
barL.moveCenter(r.center() + QPointF(-10, 0));
|
||||
barR.moveCenter(r.center() + QPointF(10, 0));
|
||||
|
||||
double oh = barSize.height() / 2;
|
||||
|
||||
painter->setPen(Qt::NoPen);
|
||||
|
||||
for (uint8_t i = 0; i < 2; i++) {
|
||||
auto b = i == 0 ? barL : barR;
|
||||
|
||||
painter->setBrush(QColor(0, 0, 0, 127));
|
||||
painter->drawRect(b);
|
||||
|
||||
QRectF bc(QPoint(), QSizeF(b.width(), 0));
|
||||
bc.moveCenter(b.center());
|
||||
bc.adjust(0, std::clamp(lv[i][1], -1.0, 1.0) * oh, 0, std::clamp(lv[i][0], -1.0, 1.0) * oh);
|
||||
|
||||
if (std::abs(lv[i][0]) > 1.0 || std::abs(lv[i][1]) > 1.0) painter->setBrush(QColor(255, 255, 63));
|
||||
else painter->setBrush(QColor(63, 255, 63));
|
||||
painter->drawRect(bc);
|
||||
|
||||
QRectF ln(QPoint(), QSizeF(b.width(), 1));
|
||||
ln.moveCenter(b.center());
|
||||
painter->setBrush(QColor(0, 0, 0));
|
||||
painter->drawRect(ln);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,18 @@
|
|||
#pragma once
|
||||
|
||||
#include "data/node.h"
|
||||
|
||||
namespace Xybrid::Gadgets {
|
||||
class QuickLevel : public Data::Node {
|
||||
std::array<std::array<double, 2>, 2> lv;
|
||||
public:
|
||||
QuickLevel();
|
||||
~QuickLevel() = default;
|
||||
|
||||
void init() override;
|
||||
void process() override;
|
||||
|
||||
void onGadgetCreated() override;
|
||||
void drawCustomChrome(QPainter*, const QStyleOptionGraphicsItem*) override;
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue