From 25bfa70eafc4aabe9be0c253e9a5f0ab2a2bbe23 Mon Sep 17 00:00:00 2001 From: Volker Fischer Date: Mon, 22 Jun 2020 16:38:44 +0200 Subject: [PATCH] support a clip LED, coded by fleutot (#220) --- ChangeLog | 7 +++++ src/levelmeter.cpp | 66 ++++++++++++++++++++++------------------------ src/levelmeter.h | 14 +++++++--- 3 files changed, 50 insertions(+), 37 deletions(-) diff --git a/ChangeLog b/ChangeLog index 093d80ae..f2ba22a3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -11,6 +11,8 @@ - new group switch to change several faders in sync, coded by Alberstein8 (#202, #379) +- support a clip LED, coded by fleutot (#220) + - add server recording indicator, coded by pljones (#295) - support for storing/recovering the server window positions (#357) @@ -28,6 +30,11 @@ + + + + + 3.5.6 (2020-06-09) - support sorting faders by channel name (#178) diff --git a/src/levelmeter.cpp b/src/levelmeter.cpp index 67a4159b..a60d2c52 100755 --- a/src/levelmeter.cpp +++ b/src/levelmeter.cpp @@ -40,16 +40,16 @@ CLevelMeter::CLevelMeter ( QWidget* parent, Qt::WindowFlags f ) : pLEDLayout->setMargin ( 0 ); pLEDLayout->setSpacing ( 0 ); - // create LEDs - vecpLEDs.Init ( NUM_STEPS_LED_BAR ); + // create LEDs plus the clip LED + vecpLEDs.Init ( NUM_LEDS_INCL_CLIP_LED ); - for ( int iLEDIdx = NUM_STEPS_LED_BAR - 1; iLEDIdx >= 0; iLEDIdx-- ) + for ( int iLEDIdx = NUM_LEDS_INCL_CLIP_LED - 1; iLEDIdx >= 0; iLEDIdx-- ) { // create LED object vecpLEDs[iLEDIdx] = new cLED ( parent ); // add LED to layout with spacer (do not add spacer on the bottom of the first LED) - if ( iLEDIdx < NUM_STEPS_LED_BAR - 1 ) + if ( iLEDIdx < NUM_LEDS_INCL_CLIP_LED - 1 ) { pLEDLayout->addStretch(); } @@ -76,44 +76,26 @@ CLevelMeter::CLevelMeter ( QWidget* parent, Qt::WindowFlags f ) : // update the meter type (using the default value of the meter type) SetLevelMeterType ( eLevelMeterType ); + + // setup clip indicator timer + TimerClip.setSingleShot ( true ); + TimerClip.setInterval ( CLIP_IND_TIME_OUT_MS ); + + + // Connections ------------------------------------------------------------- + QObject::connect ( &TimerClip, &QTimer::timeout, + this, &CLevelMeter::ClipReset ); } CLevelMeter::~CLevelMeter() { // clean up the LED objects - for ( int iLEDIdx = 0; iLEDIdx < NUM_STEPS_LED_BAR; iLEDIdx++ ) + for ( int iLEDIdx = 0; iLEDIdx < NUM_LEDS_INCL_CLIP_LED; iLEDIdx++ ) { delete vecpLEDs[iLEDIdx]; } } -void CLevelMeter::changeEvent ( QEvent* curEvent ) -{ - // act on enabled changed state - if ( curEvent->type() == QEvent::EnabledChange ) - { - // reset all LEDs - Reset ( this->isEnabled() ); - } -} - -void CLevelMeter::Reset ( const bool bEnabled ) -{ - // update state of all LEDs - for ( int iLEDIdx = 0; iLEDIdx < NUM_STEPS_LED_BAR; iLEDIdx++ ) - { - // different reset behavoiur for enabled and disabled control - if ( bEnabled ) - { - vecpLEDs[iLEDIdx]->setColor ( cLED::RL_BLACK ); - } - else - { - vecpLEDs[iLEDIdx]->setColor ( cLED::RL_DISABLED ); - } - } -} - void CLevelMeter::SetLevelMeterType ( const ELevelMeterType eNType ) { eLevelMeterType = eNType; @@ -135,7 +117,7 @@ void CLevelMeter::SetLevelMeterType ( const ELevelMeterType eNType ) case MT_SLIM_BAR: // set all LEDs to disabled, otherwise we would not get our desired small width - for ( int iLEDIdx = 0; iLEDIdx < NUM_STEPS_LED_BAR; iLEDIdx++ ) + for ( int iLEDIdx = 0; iLEDIdx < NUM_LEDS_INCL_CLIP_LED; iLEDIdx++ ) { vecpLEDs[iLEDIdx]->setColor ( cLED::RL_DISABLED ); } @@ -158,7 +140,7 @@ void CLevelMeter::SetValue ( const double dValue ) switch ( eLevelMeterType ) { case MT_LED: - // update state of all LEDs for current level value + // update state of all LEDs for current level value (except of the clip LED) for ( int iLEDIdx = 0; iLEDIdx < NUM_STEPS_LED_BAR; iLEDIdx++ ) { // set active LED color if value is above current LED index @@ -190,6 +172,13 @@ void CLevelMeter::SetValue ( const double dValue ) vecpLEDs[iLEDIdx]->setColor ( cLED::RL_BLACK ); } } + + // clip LED management + if ( dValue > LEV_METER_CLIP_LIMIT_RATIO * NUM_STEPS_LED_BAR) + { + vecpLEDs[NUM_STEPS_LED_BAR]->setColor ( cLED::RL_RED ); + TimerClip.start(); + } break; case MT_BAR: @@ -200,6 +189,15 @@ void CLevelMeter::SetValue ( const double dValue ) } } +void CLevelMeter::ClipReset() +{ + if ( eLevelMeterType == MT_LED ) + { + vecpLEDs[NUM_STEPS_LED_BAR]->setColor ( cLED::RL_BLACK ); + } +} + + CLevelMeter::cLED::cLED ( QWidget* parent ) : BitmCubeRoundBlack ( QString::fromUtf8 ( ":/png/LEDs/res/HLEDBlackSmall.png" ) ), BitmCubeRoundGreen ( QString::fromUtf8 ( ":/png/LEDs/res/HLEDGreenSmall.png" ) ), diff --git a/src/levelmeter.h b/src/levelmeter.h index 63683342..aedf7fee 100755 --- a/src/levelmeter.h +++ b/src/levelmeter.h @@ -34,6 +34,12 @@ #include "global.h" +/* Definitions ****************************************************************/ +#define LEV_METER_CLIP_LIMIT_RATIO 0.99 +#define NUM_LEDS_INCL_CLIP_LED ( NUM_STEPS_LED_BAR + 1 ) +#define CLIP_IND_TIME_OUT_MS 20000 + + /* Classes ********************************************************************/ class CLevelMeter : public QWidget { @@ -80,11 +86,13 @@ protected: QLabel* pLEDLabel; }; - void Reset ( const bool bEnabled ); - virtual void changeEvent ( QEvent* curEvent ); - QStackedLayout* pStackedLayout; ELevelMeterType eLevelMeterType; CVector vecpLEDs; QProgressBar* pBarMeter; + + QTimer TimerClip; + +protected slots: + void ClipReset(); };