Browse Source

Continue rework

tags/1.9.6
falkTX 9 years ago
parent
commit
780a5c54fa
4 changed files with 426 additions and 379 deletions
  1. +56
    -36
      source/widgets/Makefile
  2. +2
    -272
      source/widgets/digitalpeakmeter.cpp
  3. +321
    -28
      source/widgets/digitalpeakmeter.hpp
  4. +47
    -43
      source/widgets/digitalpeakmeter.py

+ 56
- 36
source/widgets/Makefile View File

@@ -1,14 +1,27 @@
#!/usr/bin/make -f #!/usr/bin/make -f
# Makefile for widgets #
# -------------------- #
# Makefile for carla-widgets #
# -------------------------- #
# Created by falkTX # Created by falkTX
# #


include ../../Makefile.mk
CWD=..
include $(CWD)/Makefile.mk


# --------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------------


BUILD_CXX_FLAGS += -I. -I.. -I../../includes -I../../utils
BINDIR := $(CWD)/../bin

ifeq ($(DEBUG),true)
OBJDIR := $(CWD)/../build/widgets/Debug
MODULEDIR := $(CWD)/../build/modules/Debug
else
OBJDIR := $(CWD)/../build/widgets/Release
MODULEDIR := $(CWD)/../build/modules/Release
endif

# ----------------------------------------------------------------------------------------------------------------------------

BUILD_CXX_FLAGS += -I. -I$(CWD)/includes -I$(CWD)/modules -I$(CWD)/utils


ifeq ($(HAVE_QT4),true) ifeq ($(HAVE_QT4),true)
BUILD_CXX_FLAGS += $(shell pkg-config --cflags QtCore QtGui) BUILD_CXX_FLAGS += $(shell pkg-config --cflags QtCore QtGui)
@@ -18,50 +31,57 @@ BUILD_CXX_FLAGS += $(shell pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets)
LINK_FLAGS += $(shell pkg-config --libs Qt5Core Qt5Gui Qt5Widgets) LINK_FLAGS += $(shell pkg-config --libs Qt5Core Qt5Gui Qt5Widgets)
endif endif


# --------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------------


FILES = \
moc_paramspinbox.cpp \
moc_pixmapkeyboard.cpp
# FILES = \
# moc_paramspinbox.cpp \
# moc_pixmapkeyboard.cpp


OBJS = \ OBJS = \
digitalpeakmeter.cpp.o \
ledbutton.cpp.o \
paramspinbox.cpp.o \
pixmapdial.cpp.o \
pixmapkeyboard.cpp.o
$(OBJDIR)/digitalpeakmeter.cpp.o


OBJS += \
moc_paramspinbox.cpp.o \
moc_pixmapkeyboard.cpp.o
# ledbutton.cpp.o \
# paramspinbox.cpp.o \
# pixmapdial.cpp.o \
# pixmapkeyboard.cpp.o


# --------------------------------------------------------------
# OBJS += \
# moc_paramspinbox.cpp.o \
# moc_pixmapkeyboard.cpp.o


all: ../widgets.a
TARGET = $(MODULEDIR)/widgets.a


# --------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------------


../widgets.a: $(FILES) $(OBJS)
$(RM) $@
$(AR) crs $@ $(OBJS)
all: $(TARGET)


# --------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------------


%.cpp.o: %.cpp %.hpp
$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@
clean:
rm -f $(OBJDIR)/*.o $(TARGET)

debug:
$(MAKE) DEBUG=true


moc_%.cpp.o: %.cpp
$(CXX) moc_$< $(BUILD_CXX_FLAGS) -c -o $@
# ----------------------------------------------------------------------------------------------------------------------------


moc_%.cpp: %.hpp
$(MOC) $< -o $@
$(MODULEDIR)/widgets.a: $(FILES) $(OBJS)
$(RM) $@
$(AR) crs $@ $(OBJS)


# --------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------------


clean:
$(RM) *.o ../widgets*.a $(FILES)
$(OBJDIR)/%.cpp.o: %.cpp
-@mkdir -p $(OBJDIR)
@echo "Compiling $<"
$(CXX) $< $(BUILD_CXX_FLAGS) -c -o $@


debug:
$(MAKE) DEBUG=true
-include $(OBJS:%.o=%.d)

# moc_%.cpp.o: %.cpp
# $(CXX) moc_$< $(BUILD_CXX_FLAGS) -c -o $@
#
# moc_%.cpp: %.hpp
# $(MOC) $< -o $@


# --------------------------------------------------------------
# ----------------------------------------------------------------------------------------------------------------------------

+ 2
- 272
source/widgets/digitalpeakmeter.cpp View File

@@ -1,6 +1,6 @@
/* /*
* Digital Peak Meter, a custom Qt4 widget
* Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
* Digital Peak Meter, a custom Qt widget
* Copyright (C) 2011-2015 Filipe Coelho <falktx@falktx.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
@@ -16,273 +16,3 @@
*/ */


#include "digitalpeakmeter.hpp" #include "digitalpeakmeter.hpp"

#include <QtGui/QPainter>
#include <QtGui/QPaintEvent>

DigitalPeakMeter::DigitalPeakMeter(QWidget* parent)
: QWidget(parent),
fChannels(0),
fSmoothMultiplier(1),
fWidth(0),
fHeight(0),
fSizeMeter(0),
fOrientation(VERTICAL),
fColorBackground("#111111"),
fGradientMeter(0, 0, 1, 1),
fColorBase(93, 231, 61),
fColorBaseAlt(15, 110, 15, 100),
fChannelsData(nullptr),
fLastValueData(nullptr)
{
setChannels(0);
setColor(GREEN);
}

DigitalPeakMeter::~DigitalPeakMeter()
{
if (fChannelsData != nullptr)
delete[] fChannelsData;
if (fLastValueData != nullptr)
delete[] fLastValueData;
}

void DigitalPeakMeter::displayMeter(int meter, float level)
{
Q_ASSERT(fChannelsData != nullptr);
Q_ASSERT(meter > 0 && meter <= fChannels);

if (meter <= 0 || meter > fChannels || fChannelsData == nullptr)
return qCritical("DigitalPeakMeter::displayMeter(%i, %f) - invalid meter number", meter, level);

int i = meter - 1;

if (fSmoothMultiplier > 0)
level = (fLastValueData[i] * fSmoothMultiplier + level) / float(fSmoothMultiplier + 1);

if (level < 0.001f)
level = 0.0f;
else if (level > 0.999f)
level = 1.0f;

if (fChannelsData[i] != level)
{
fChannelsData[i] = level;
update();
}

fLastValueData[i] = level;
}

void DigitalPeakMeter::setChannels(int channels)
{
Q_ASSERT(channels >= 0);

if (channels < 0)
return qCritical("DigitalPeakMeter::setChannels(%i) - 'channels' must be a positive integer", channels);

fChannels = channels;

if (fChannelsData != nullptr)
delete[] fChannelsData;
if (fLastValueData != nullptr)
delete[] fLastValueData;

if (channels > 0)
{
fChannelsData = new float[channels];
fLastValueData = new float[channels];

for (int i=0; i < channels; ++i)
{
fChannelsData[i] = 0.0f;
fLastValueData[i] = 0.0f;
}
}
else
{
fChannelsData = nullptr;
fLastValueData = nullptr;
}
}

void DigitalPeakMeter::setColor(Color color)
{
if (color == GREEN)
{
fColorBase = QColor(93, 231, 61);
fColorBaseAlt = QColor(15, 110, 15, 100);
}
else if (color == BLUE)
{
fColorBase = QColor(82, 238, 248);
fColorBaseAlt = QColor(15, 15, 110, 100);
}
else
return qCritical("DigitalPeakMeter::setColor(%i) - invalid color", color);

setOrientation(fOrientation);
}

void DigitalPeakMeter::setOrientation(Orientation orientation)
{
fOrientation = orientation;

if (fOrientation == HORIZONTAL)
{
fGradientMeter.setColorAt(0.0f, fColorBase);
fGradientMeter.setColorAt(0.2f, fColorBase);
fGradientMeter.setColorAt(0.4f, fColorBase);
fGradientMeter.setColorAt(0.6f, fColorBase);
fGradientMeter.setColorAt(0.8f, Qt::yellow);
fGradientMeter.setColorAt(1.0f, Qt::red);
}
else if (fOrientation == VERTICAL)
{
fGradientMeter.setColorAt(0.0f, Qt::red);
fGradientMeter.setColorAt(0.2f, Qt::yellow);
fGradientMeter.setColorAt(0.4f, fColorBase);
fGradientMeter.setColorAt(0.6f, fColorBase);
fGradientMeter.setColorAt(0.8f, fColorBase);
fGradientMeter.setColorAt(1.0f, fColorBase);
}
else
return qCritical("DigitalPeakMeter::setOrientation(%i) - invalid orientation", orientation);

updateSizes();
}

void DigitalPeakMeter::setSmoothRelease(int value)
{
Q_ASSERT(value >= 0 && value <= 5);

if (value < 0)
value = 0;
else if (value > 5)
value = 5;

fSmoothMultiplier = value;
}

QSize DigitalPeakMeter::minimumSizeHint() const
{
return QSize(10, 10);
}

QSize DigitalPeakMeter::sizeHint() const
{
return QSize(fWidth, fHeight);
}

void DigitalPeakMeter::updateSizes()
{
fWidth = width();
fHeight = height();
fSizeMeter = 0;

if (fOrientation == HORIZONTAL)
{
fGradientMeter.setFinalStop(fWidth, 0);

if (fChannels > 0)
fSizeMeter = fHeight/fChannels;
}
else if (fOrientation == VERTICAL)
{
fGradientMeter.setFinalStop(0, fHeight);

if (fChannels > 0)
fSizeMeter = fWidth/fChannels;
}
}

void DigitalPeakMeter::paintEvent(QPaintEvent* event)
{
QPainter painter(this);
event->accept();

painter.setPen(Qt::black);
painter.setBrush(Qt::black);
painter.drawRect(0, 0, fWidth, fHeight);

int meterX = 0;
painter.setPen(fColorBackground);
painter.setBrush(fGradientMeter);

for (int i=0; i < fChannels; ++i)
{
float value, level = fChannelsData[i];

if (fOrientation == HORIZONTAL)
value = level * float(fWidth);
else if (fOrientation == VERTICAL)
value = float(fHeight) - (level * float(fHeight));
else
value = 0.0f;

if (fOrientation == HORIZONTAL)
painter.drawRect(0, meterX, int(value), fSizeMeter);
else if (fOrientation == VERTICAL)
painter.drawRect(meterX, int(value), fSizeMeter, fHeight);

meterX += fSizeMeter;
}

painter.setBrush(Qt::black);

if (fOrientation == HORIZONTAL)
{
// Variables
float lsmall = fWidth;
float lfull = fHeight - 1;

// Base
painter.setPen(fColorBaseAlt);
painter.drawLine(lsmall * 0.25f, 2, lsmall * 0.25f, lfull-2.0f);
painter.drawLine(lsmall * 0.50f, 2, lsmall * 0.50f, lfull-2.0f);

// Yellow
painter.setPen(QColor(110, 110, 15, 100));
painter.drawLine(lsmall * 0.70f, 2, lsmall * 0.70f, lfull-2.0f);
painter.drawLine(lsmall * 0.83f, 2, lsmall * 0.83f, lfull-2.0f);

// Orange
painter.setPen(QColor(180, 110, 15, 100));
painter.drawLine(lsmall * 0.90f, 2, lsmall * 0.90f, lfull-2.0f);

// Red
painter.setPen(QColor(110, 15, 15, 100));
painter.drawLine(lsmall * 0.96f, 2, lsmall * 0.96f, lfull-2.0f);

}
else if (fOrientation == VERTICAL)
{
// Variables
float lsmall = fHeight;
float lfull = fWidth - 1;

// Base
painter.setPen(fColorBaseAlt);
painter.drawLine(2, lsmall - (lsmall * 0.25f), lfull-2.0f, lsmall - (lsmall * 0.25f));
painter.drawLine(2, lsmall - (lsmall * 0.50f), lfull-2.0f, lsmall - (lsmall * 0.50f));

// Yellow
painter.setPen(QColor(110, 110, 15, 100));
painter.drawLine(2, lsmall - (lsmall * 0.70f), lfull-2.0f, lsmall - (lsmall * 0.70f));
painter.drawLine(2, lsmall - (lsmall * 0.83f), lfull-2.0f, lsmall - (lsmall * 0.83f));

// Orange
painter.setPen(QColor(180, 110, 15, 100));
painter.drawLine(2, lsmall - (lsmall * 0.90f), lfull-2.0f, lsmall - (lsmall * 0.90f));

// Red
painter.setPen(QColor(110, 15, 15, 100));
painter.drawLine(2, lsmall - (lsmall * 0.96f), lfull-2.0f, lsmall - (lsmall * 0.96f));
}
}

void DigitalPeakMeter::resizeEvent(QResizeEvent* event)
{
updateSizes();
QWidget::resizeEvent(event);
}

+ 321
- 28
source/widgets/digitalpeakmeter.hpp View File

@@ -1,6 +1,6 @@
/* /*
* Digital Peak Meter, a custom Qt4 widget
* Copyright (C) 2011-2013 Filipe Coelho <falktx@falktx.com>
* Digital Peak Meter, a custom Qt widget
* Copyright (C) 2011-2015 Filipe Coelho <falktx@falktx.com>
* *
* This program is free software; you can redistribute it and/or * This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as * modify it under the terms of the GNU General Public License as
@@ -20,7 +20,8 @@


#include "CarlaJuceUtils.hpp" #include "CarlaJuceUtils.hpp"


#include <QtCore/QTimer>
#include <QtGui/QPainter>
#include <QtGui/QPaintEvent>


#if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)) #if (QT_VERSION >= QT_VERSION_CHECK(5, 0, 0))
# include <QtWidgets/QWidget> # include <QtWidgets/QWidget>
@@ -28,53 +29,345 @@
# include <QtGui/QWidget> # include <QtGui/QWidget>
#endif #endif


// ------------------------------------------------------------------------------------------------------------

class DigitalPeakMeter : public QWidget class DigitalPeakMeter : public QWidget
{ {
public: public:
enum Color {
COLOR_GREEN = 1,
COLOR_BLUE = 2
};

enum Orientation { enum Orientation {
HORIZONTAL = 1, HORIZONTAL = 1,
VERTICAL = 2 VERTICAL = 2
}; };


enum Color {
GREEN = 1,
BLUE = 2
enum Style {
STYLE_DEFAULT = 1,
STYLE_OPENAV = 2,
STYLE_RNCBC = 3
}; };


DigitalPeakMeter(QWidget* parent);
~DigitalPeakMeter() override;
// --------------------------------------------------------------------------------------------------------

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>({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<Orientation>({HORIZONTAL, VERTICAL}).contains(orientation))
return qCritical("DigitalPeakMeter::setMeterOrientation(%i) - invalid orientation", orientation);

fMeterOrientation = orientation;

updateGrandient();
}

// --------------------------------------------------------------------------------------------------------

Style meterStyle() const noexcept
{
return fMeterStyle;
}


void displayMeter(int meter, float level);
void setChannels(int channels);
void setColor(Color color);
void setOrientation(Orientation orientation);
void setSmoothRelease(int value);
void setMeterStyle(const Style style)
{
if (fMeterStyle == style)
return;


QSize minimumSizeHint() const override;
QSize sizeHint() const override;
if (! QList<Style>({STYLE_DEFAULT, STYLE_OPENAV, STYLE_RNCBC}).contains(style))
return qCritical("DigitalPeakMeter::setMeterStyle(%i) - invalid style", style);

switch (style)
{
case STYLE_DEFAULT:
fMeterBackground = QColor("#111111");
break;
case STYLE_OPENAV:
fMeterBackground = QColor("#1A1A1A");
break;
case STYLE_RNCBC:
fMeterBackground = QColor("#111111");
break;
}

fMeterStyle = style;

updateGrandient();
}

// --------------------------------------------------------------------------------------------------------

int smoothMultiplier() const noexcept
{
return fSmoothMultiplier;
}

void setSmoothMultiplier(const int value)
{
if (fSmoothMultiplier == value)
return;

if (value < 0)
return qCritical("DigitalPeakMeter::setSmoothMultiplier(%i) - value must be >= 0", value);
if (value > 5)
return qCritical("DigitalPeakMeter::setSmoothMultiplier(%i) - value must be < 5", value);

fSmoothMultiplier = value;
}

// --------------------------------------------------------------------------------------------------------

void displayMeter(const int meter, float level, bool forced = false)
{
if (meter <= 0 or meter > fChannelCount)
return qCritical("DigitalPeakMeter::displayMeter(%i, %f) - invalid meter number", meter, level);

const int i = meter - 1;

if (fSmoothMultiplier > 0 && ! forced)
level = (fLastChannelData[i] * float(fSmoothMultiplier) + level) / float(fSmoothMultiplier + 1);

if (level < 0.001f)
level = 0.0f;
else if (level > 0.999f)
level = 1.0f;

if (fChannelData[i] != level)
{
fChannelData[i] = level;
update();
}

fLastChannelData[i] = level;
}

// --------------------------------------------------------------------------------------------------------


protected: protected:
void updateSizes();
void updateGrandient()
{
fMeterGradient = QLinearGradient(0, 0, 1, 1);


void paintEvent(QPaintEvent* event) override;
void resizeEvent(QResizeEvent* event) override;
if (fMeterStyle == STYLE_OPENAV)
{
fMeterGradient.setColorAt(0.0, fMeterColorBase);
fMeterGradient.setColorAt(1.0, fMeterColorBase);
}
else
{
switch (fMeterOrientation)
{
case HORIZONTAL:
fMeterGradient.setColorAt(0.0, fMeterColorBase);
fMeterGradient.setColorAt(0.2, fMeterColorBase);
fMeterGradient.setColorAt(0.4, fMeterColorBase);
fMeterGradient.setColorAt(0.6, fMeterColorBase);
fMeterGradient.setColorAt(0.8, Qt::yellow);
fMeterGradient.setColorAt(1.0, Qt::red);
break;
case VERTICAL:
fMeterGradient.setColorAt(0.0, Qt::red);
fMeterGradient.setColorAt(0.2, Qt::yellow);
fMeterGradient.setColorAt(0.4, fMeterColorBase);
fMeterGradient.setColorAt(0.6, fMeterColorBase);
fMeterGradient.setColorAt(0.8, fMeterColorBase);
fMeterGradient.setColorAt(1.0, fMeterColorBase);
break;
}
}

updateGrandientFinalStop();
}

void updateGrandientFinalStop()
{
switch (fMeterOrientation)
{
case HORIZONTAL:
fMeterGradient.setFinalStop(width(), 0);
break;
case VERTICAL:
fMeterGradient.setFinalStop(0, height());
break;
}
}

// --------------------------------------------------------------------------------------------------------

QSize minimumSizeHint() const override
{
return QSize(10, 10);
}

QSize sizeHint() const override
{
return QSize(width(), height());
}

// --------------------------------------------------------------------------------------------------------

void paintEvent(QPaintEvent* const ev) override
{
QPainter painter(this);
ev->accept();

const int width_ = width();
const int height_ = height();

// draw background
painter.setPen(QPen(fMeterBackground, 2));
painter.setBrush(fMeterBackground);
painter.drawRect(0, 0, width_, height_);
}

// --------------------------------------------------------------------------------------------------------

void resizeEvent(QResizeEvent* const ev) override
{
QWidget::resizeEvent(ev);
updateGrandientFinalStop();
}

// --------------------------------------------------------------------------------------------------------


private: private:
int fChannels;
int fSmoothMultiplier;
int fWidth, fHeight, fSizeMeter;
Orientation fOrientation;
int fChannelCount;
float* fChannelData;
float* fLastChannelData;

Color fMeterColor;
QColor fMeterColorBase;
QColor fMeterColorBaseAlt;


QColor fColorBackground;
QLinearGradient fGradientMeter;
bool fMeterLinesEnabled;
Orientation fMeterOrientation;
Style fMeterStyle;


QColor fColorBase;
QColor fColorBaseAlt;
QColor fMeterBackground;
QLinearGradient fMeterGradient;


float* fChannelsData;
float* fLastValueData;
int fSmoothMultiplier;


CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DigitalPeakMeter) CARLA_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(DigitalPeakMeter)
}; };


// ------------------------------------------------------------------------------------------------------------

#endif // DIGITALPEAKMETER_HPP_INCLUDED #endif // DIGITALPEAKMETER_HPP_INCLUDED

+ 47
- 43
source/widgets/digitalpeakmeter.py View File

@@ -26,11 +26,11 @@ from carla_config import *


if config_UseQt5: if config_UseQt5:
from PyQt5.QtCore import qCritical, Qt, QTimer, QSize from PyQt5.QtCore import qCritical, Qt, QTimer, QSize
from PyQt5.QtGui import QColor, QLinearGradient, QPainter
from PyQt5.QtGui import QColor, QLinearGradient, QPainter, QPen
from PyQt5.QtWidgets import QWidget from PyQt5.QtWidgets import QWidget
else: else:
from PyQt4.QtCore import qCritical, Qt, QTimer, QSize from PyQt4.QtCore import qCritical, Qt, QTimer, QSize
from PyQt4.QtGui import QColor, QLinearGradient, QPainter, QWidget
from PyQt4.QtGui import QColor, QLinearGradient, QPainter, QPen, QWidget


# ------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------
# Widget Class # Widget Class
@@ -49,6 +49,8 @@ class DigitalPeakMeter(QWidget):
STYLE_OPENAV = 2 STYLE_OPENAV = 2
STYLE_RNCBC = 3 STYLE_RNCBC = 3


# --------------------------------------------------------------------------------------------------------

def __init__(self, parent): def __init__(self, parent):
QWidget.__init__(self, parent) QWidget.__init__(self, parent)


@@ -105,8 +107,6 @@ class DigitalPeakMeter(QWidget):
if color not in (self.COLOR_GREEN, self.COLOR_BLUE): if color not in (self.COLOR_GREEN, self.COLOR_BLUE):
return qCritical("DigitalPeakMeter::setMeterColor(%i) - invalid color" % color) return qCritical("DigitalPeakMeter::setMeterColor(%i) - invalid color" % color)


self.fMeterColor = color

if color == self.COLOR_GREEN: if color == self.COLOR_GREEN:
self.fMeterColorBase = QColor(93, 231, 61) self.fMeterColorBase = QColor(93, 231, 61)
self.fMeterColorBaseAlt = QColor(15, 110, 15, 100) self.fMeterColorBaseAlt = QColor(15, 110, 15, 100)
@@ -114,6 +114,8 @@ class DigitalPeakMeter(QWidget):
self.fMeterColorBase = QColor(82, 238, 248) self.fMeterColorBase = QColor(82, 238, 248)
self.fMeterColorBaseAlt = QColor(15, 15, 110, 100) self.fMeterColorBaseAlt = QColor(15, 15, 110, 100)


self.fMeterColor = color

self.updateGrandient() self.updateGrandient()


# -------------------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------------------
@@ -155,8 +157,6 @@ class DigitalPeakMeter(QWidget):
if style not in (self.STYLE_DEFAULT, self.STYLE_OPENAV, self.STYLE_RNCBC): if style not in (self.STYLE_DEFAULT, self.STYLE_OPENAV, self.STYLE_RNCBC):
return qCritical("DigitalPeakMeter::setMeterStyle(%i) - invalid style" % style) return qCritical("DigitalPeakMeter::setMeterStyle(%i) - invalid style" % style)


self.fMeterStyle = style

if style == self.STYLE_DEFAULT: if style == self.STYLE_DEFAULT:
self.fMeterBackground = QColor("#111111") self.fMeterBackground = QColor("#111111")
elif style == self.STYLE_OPENAV: elif style == self.STYLE_OPENAV:
@@ -164,6 +164,8 @@ class DigitalPeakMeter(QWidget):
elif style == self.STYLE_RNCBC: elif style == self.STYLE_RNCBC:
self.fMeterBackground = QColor("#111111") self.fMeterBackground = QColor("#111111")


self.fMeterStyle = style

self.updateGrandient() self.updateGrandient()


# -------------------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------------------
@@ -219,21 +221,22 @@ class DigitalPeakMeter(QWidget):
self.fMeterGradient.setColorAt(0.0, self.fMeterColorBase) self.fMeterGradient.setColorAt(0.0, self.fMeterColorBase)
self.fMeterGradient.setColorAt(1.0, self.fMeterColorBase) self.fMeterGradient.setColorAt(1.0, self.fMeterColorBase)


elif self.fMeterOrientation == self.HORIZONTAL:
self.fMeterGradient.setColorAt(0.0, self.fMeterColorBase)
self.fMeterGradient.setColorAt(0.2, self.fMeterColorBase)
self.fMeterGradient.setColorAt(0.4, self.fMeterColorBase)
self.fMeterGradient.setColorAt(0.6, self.fMeterColorBase)
self.fMeterGradient.setColorAt(0.8, Qt.yellow)
self.fMeterGradient.setColorAt(1.0, Qt.red)
else:
if self.fMeterOrientation == self.HORIZONTAL:
self.fMeterGradient.setColorAt(0.0, self.fMeterColorBase)
self.fMeterGradient.setColorAt(0.2, self.fMeterColorBase)
self.fMeterGradient.setColorAt(0.4, self.fMeterColorBase)
self.fMeterGradient.setColorAt(0.6, self.fMeterColorBase)
self.fMeterGradient.setColorAt(0.8, Qt.yellow)
self.fMeterGradient.setColorAt(1.0, Qt.red)


elif self.fMeterOrientation == self.VERTICAL:
self.fMeterGradient.setColorAt(0.0, Qt.red)
self.fMeterGradient.setColorAt(0.2, Qt.yellow)
self.fMeterGradient.setColorAt(0.4, self.fMeterColorBase)
self.fMeterGradient.setColorAt(0.6, self.fMeterColorBase)
self.fMeterGradient.setColorAt(0.8, self.fMeterColorBase)
self.fMeterGradient.setColorAt(1.0, self.fMeterColorBase)
elif self.fMeterOrientation == self.VERTICAL:
self.fMeterGradient.setColorAt(0.0, Qt.red)
self.fMeterGradient.setColorAt(0.2, Qt.yellow)
self.fMeterGradient.setColorAt(0.4, self.fMeterColorBase)
self.fMeterGradient.setColorAt(0.6, self.fMeterColorBase)
self.fMeterGradient.setColorAt(0.8, self.fMeterColorBase)
self.fMeterGradient.setColorAt(1.0, self.fMeterColorBase)


self.updateGrandientFinalStop() self.updateGrandientFinalStop()


@@ -261,20 +264,19 @@ class DigitalPeakMeter(QWidget):
width = self.width() width = self.width()
height = self.height() height = self.height()


if self.fMeterStyle == self.STYLE_OPENAV:
painter.setPen(QColor("#1A1A1A"))
painter.setBrush(QColor("#1A1A1A"))
else:
painter.setPen(Qt.black)
painter.setBrush(Qt.black)

# draw background
painter.setPen(QPen(self.fMeterBackground, 2))
painter.setBrush(self.fMeterBackground)
painter.drawRect(0, 0, width, height) painter.drawRect(0, 0, width, height)
return


meterX = 0 meterX = 0
startX = -1 if self.fMeterStyle == self.STYLE_OPENAV else 0
padding = 2 if self.fMeterStyle == self.STYLE_OPENAV else 0
startX = 0
padding = 0
#startX = -1 if self.fMeterStyle == self.STYLE_OPENAV else 0
#padding = 2 if self.fMeterStyle == self.STYLE_OPENAV else 0


painter.setPen(self.fMeterBackground) # FIXME ?
painter.setPen(QPen(self.fMeterBackground, 0))
painter.setBrush(self.fMeterGradient) painter.setBrush(self.fMeterGradient)


#if self.fMeterStyle == self.STYLE_OPENAV: #if self.fMeterStyle == self.STYLE_OPENAV:
@@ -285,7 +287,7 @@ class DigitalPeakMeter(QWidget):
#del color #del color


for i in range(self.fChannelCount): for i in range(self.fChannelCount):
level = self.fChannelsData[i]
level = self.fChannelData[i]


if self.fMeterOrientation == self.HORIZONTAL: if self.fMeterOrientation == self.HORIZONTAL:
value = level * float(width) value = level * float(width)
@@ -299,17 +301,17 @@ class DigitalPeakMeter(QWidget):
elif self.fMeterOrientation == self.VERTICAL: elif self.fMeterOrientation == self.VERTICAL:
painter.drawRect(meterX, int(value), self.fSizeMeter, self.fHeight) painter.drawRect(meterX, int(value), self.fSizeMeter, self.fHeight)


meterX += self.fSizeMeter
meterX += self.fMeterSize


if not self.fDrawLines:
if not self.fMeterLinesEnabled:
return return


painter.setBrush(Qt.black) painter.setBrush(Qt.black)


if self.fOrientation == self.HORIZONTAL:
if self.fMeterOrientation == self.HORIZONTAL:
# Variables # Variables
lsmall = float(self.fWidth)
lfull = float(self.fHeight - 1)
lsmall = float(width)
lfull = float(height - 1)


if self.fMeterStyle == self.STYLE_OPENAV: if self.fMeterStyle == self.STYLE_OPENAV:
painter.setPen(QColor(37, 37, 37, 100)) painter.setPen(QColor(37, 37, 37, 100))
@@ -317,12 +319,12 @@ class DigitalPeakMeter(QWidget):
painter.drawLine(lsmall * 0.50, 2, lsmall * 0.50, lfull-2.0) painter.drawLine(lsmall * 0.50, 2, lsmall * 0.50, lfull-2.0)
painter.drawLine(lsmall * 0.75, 2, lsmall * 0.75, lfull-2.0) painter.drawLine(lsmall * 0.75, 2, lsmall * 0.75, lfull-2.0)


if self.fChannels > 1:
if self.fChannelCount > 1:
painter.drawLine(1, lfull/2, lsmall-1, lfull/2) painter.drawLine(1, lfull/2, lsmall-1, lfull/2)


else: else:
# Base # Base
painter.setPen(self.fColorBaseAlt)
painter.setPen(self.fMeterColorBaseAlt)
painter.drawLine(lsmall * 0.25, 2, lsmall * 0.25, lfull-2.0) painter.drawLine(lsmall * 0.25, 2, lsmall * 0.25, lfull-2.0)
painter.drawLine(lsmall * 0.50, 2, lsmall * 0.50, lfull-2.0) painter.drawLine(lsmall * 0.50, 2, lsmall * 0.50, lfull-2.0)


@@ -339,10 +341,10 @@ class DigitalPeakMeter(QWidget):
painter.setPen(QColor(110, 15, 15, 100)) painter.setPen(QColor(110, 15, 15, 100))
painter.drawLine(lsmall * 0.96, 2, lsmall * 0.96, lfull-2.0) painter.drawLine(lsmall * 0.96, 2, lsmall * 0.96, lfull-2.0)


elif self.fOrientation == self.VERTICAL:
elif self.fMeterOrientation == self.VERTICAL:
# Variables # Variables
lsmall = float(self.fHeight)
lfull = float(self.fWidth - 1)
lsmall = float(height)
lfull = float(width - 1)


if self.fMeterStyle == self.STYLE_OPENAV: if self.fMeterStyle == self.STYLE_OPENAV:
# TODO # TODO
@@ -350,7 +352,7 @@ class DigitalPeakMeter(QWidget):


else: else:
# Base # Base
painter.setPen(self.fColorBaseAlt)
painter.setPen(self.fMeterColorBaseAlt)
painter.drawLine(2, lsmall - (lsmall * 0.25), lfull-2.0, lsmall - (lsmall * 0.25)) painter.drawLine(2, lsmall - (lsmall * 0.25), lfull-2.0, lsmall - (lsmall * 0.25))
painter.drawLine(2, lsmall - (lsmall * 0.50), lfull-2.0, lsmall - (lsmall * 0.50)) painter.drawLine(2, lsmall - (lsmall * 0.50), lfull-2.0, lsmall - (lsmall * 0.50))


@@ -370,8 +372,8 @@ class DigitalPeakMeter(QWidget):
# -------------------------------------------------------------------------------------------------------- # --------------------------------------------------------------------------------------------------------


def resizeEvent(self, event): def resizeEvent(self, event):
self.updateGrandientFinalStop()
QWidget.resizeEvent(self, event) QWidget.resizeEvent(self, event)
self.updateGrandientFinalStop()


# ------------------------------------------------------------------------------------------------------------ # ------------------------------------------------------------------------------------------------------------
# Main Testing # Main Testing
@@ -394,3 +396,5 @@ if __name__ == '__main__':
gui.show() gui.show()


sys.exit(app.exec_()) sys.exit(app.exec_())

# ------------------------------------------------------------------------------------------------------------

Loading…
Cancel
Save