/* * Digital Peak Meter, a custom Qt widget * Copyright (C) 2011-2015 Filipe Coelho * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of * the License, or any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * For a full copy of the GNU General Public License see the doc/GPL.txt file. */ #ifndef DIGITALPEAKMETER_HPP_INCLUDED #define DIGITALPEAKMETER_HPP_INCLUDED #include "CarlaJuceUtils.hpp" #include #include #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) # include #else # include #endif // ------------------------------------------------------------------------------------------------------------ class DigitalPeakMeter : public QWidget { public: enum Color { COLOR_GREEN = 1, COLOR_BLUE = 2 }; enum Orientation { HORIZONTAL = 1, VERTICAL = 2 }; enum Style { STYLE_DEFAULT = 1, STYLE_OPENAV = 2, STYLE_RNCBC = 3 }; // -------------------------------------------------------------------------------------------------------- DigitalPeakMeter(QWidget* const p) : QWidget(p), fChannelCount(0), fChannelData(nullptr), fLastChannelData(nullptr), fMeterColor(COLOR_GREEN), fMeterColorBase(93, 231, 61), fMeterColorBaseAlt(15, 110, 15, 100), fMeterLinesEnabled(true), fMeterOrientation(VERTICAL), fMeterStyle(STYLE_DEFAULT), fMeterBackground("#111111"), fMeterGradient(0, 0, 0, 0), fSmoothMultiplier(1), leakDetector_DigitalPeakMeter() { updateGrandient(); } ~DigitalPeakMeter() override { if (fChannelData != nullptr) { delete[] fChannelData; fChannelData = nullptr; } if (fLastChannelData != nullptr) { delete[] fLastChannelData; fLastChannelData = nullptr; } } // -------------------------------------------------------------------------------------------------------- int channelCount() const noexcept { return fChannelCount; } void setChannelCount(const int count) { if (fChannelCount == count) return; if (count < 0) return qCritical("DigitalPeakMeter::setChannelCount(%i) - channel count must be a positive integer or zero", count); fChannelCount = count; fChannelData = new float[count]; fLastChannelData = new float[count]; for (int i=count; --i >= 0;) { /**/fChannelData[i] = 0.0f; fLastChannelData[i] = 0.0f; } } // -------------------------------------------------------------------------------------------------------- Color meterColor() const noexcept { return fMeterColor; } void setMeterColor(const Color color) { if (fMeterColor == color) return; if (! QList({COLOR_GREEN, COLOR_BLUE}).contains(color)) return qCritical("DigitalPeakMeter::setMeterColor(%i) - invalid color", color); switch (color) { case COLOR_GREEN: fMeterColorBase = QColor(93, 231, 61); fMeterColorBaseAlt = QColor(15, 110, 15, 100); break; case COLOR_BLUE: fMeterColorBase = QColor(82, 238, 248); fMeterColorBaseAlt = QColor(15, 15, 110, 100); break; } fMeterColor = color; updateGrandient(); } // -------------------------------------------------------------------------------------------------------- bool meterLinesEnabled() const noexcept { return fMeterLinesEnabled; } void setMeterLinesEnabled(const bool yesNo) { if (fMeterLinesEnabled == yesNo) return; fMeterLinesEnabled = yesNo; } // -------------------------------------------------------------------------------------------------------- Orientation meterOrientation() const noexcept { return fMeterOrientation; } void setMeterOrientation(const Orientation orientation) { if (fMeterOrientation == orientation) return; if (! QList({HORIZONTAL, VERTICAL}).contains(orientation)) return qCritical("DigitalPeakMeter::setMeterOrientation(%i) - invalid orientation", orientation); fMeterOrientation = orientation; updateGrandient(); } // -------------------------------------------------------------------------------------------------------- Style meterStyle() const noexcept { return fMeterStyle; } void setMeterStyle(const Style style) { if (fMeterStyle == style) return; if (! QList