support clip indication for bar meter as well

This commit is contained in:
Volker Fischer 2020-06-24 18:28:47 +02:00
parent d60b538ce6
commit 938112d65d
3 changed files with 124 additions and 62 deletions

View File

@ -31,8 +31,7 @@
TODO support clip indicator for bar meter as well TODO use signal level meter class for meter calculation in the server (avoid doubling code), i.e., max calc and smoothing
-> change background to red in case of clipping
TODO the new translation loading does not work on MacOS TODO the new translation loading does not work on MacOS

View File

@ -113,11 +113,6 @@ void CLevelMeter::SetLevelMeterType ( const ELevelMeterType eNType )
case MT_BAR: case MT_BAR:
pStackedLayout->setCurrentIndex ( 1 ); pStackedLayout->setCurrentIndex ( 1 );
pBarMeter->setStyleSheet (
"QProgressBar { margin: 1px;"
" padding: 1px;"
" width: 15px; }"
"QProgressBar::chunk { background: green; }" );
break; break;
case MT_SLIM_BAR: case MT_SLIM_BAR:
@ -128,75 +123,140 @@ void CLevelMeter::SetLevelMeterType ( const ELevelMeterType eNType )
} }
pStackedLayout->setCurrentIndex ( 1 ); pStackedLayout->setCurrentIndex ( 1 );
pBarMeter->setStyleSheet ( break;
"QProgressBar { border: 0px;" }
" margin: 0px;"
" padding: 0px;" // update bar meter style and reset clip state
" width: 4px; }" SetBarMeterStyleAndClipStatus ( eNType, false );
"QProgressBar::chunk { background: green; }" ); }
void CLevelMeter::SetBarMeterStyleAndClipStatus ( const ELevelMeterType eNType,
const bool bIsClip )
{
switch ( eNType )
{
case MT_SLIM_BAR:
if ( bIsClip )
{
pBarMeter->setStyleSheet (
"QProgressBar { border: 0px solid red;"
" margin: 0px;"
" padding: 0px;"
" width: 4px;"
" background: red; }"
"QProgressBar::chunk { background: green; }" );
}
else
{
pBarMeter->setStyleSheet (
"QProgressBar { border: 0px;"
" margin: 0px;"
" padding: 0px;"
" width: 4px; }"
"QProgressBar::chunk { background: green; }" );
}
break;
default: /* MT_BAR */
if ( bIsClip )
{
pBarMeter->setStyleSheet (
"QProgressBar { border: 2px solid red;"
" margin: 1px;"
" padding: 1px;"
" width: 15px;"
" background: transparent; }"
"QProgressBar::chunk { background: green; }" );
}
else
{
pBarMeter->setStyleSheet (
"QProgressBar { margin: 1px;"
" padding: 1px;"
" width: 15px; }"
"QProgressBar::chunk { background: green; }" );
}
break; break;
} }
} }
void CLevelMeter::SetValue ( const double dValue ) void CLevelMeter::SetValue ( const double dValue )
{ {
if ( this->isEnabled() ) switch ( eLevelMeterType )
{
case MT_LED:
// 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
if ( iLEDIdx < dValue )
{
// check which color we should use (green, yellow or red)
if ( iLEDIdx < YELLOW_BOUND_LED_BAR )
{
// green region
vecpLEDs[iLEDIdx]->SetColor ( cLED::RL_GREEN );
}
else
{
if ( iLEDIdx < RED_BOUND_LED_BAR )
{
// yellow region
vecpLEDs[iLEDIdx]->SetColor ( cLED::RL_YELLOW );
}
else
{
// red region
vecpLEDs[iLEDIdx]->SetColor ( cLED::RL_RED );
}
}
}
else
{
// we use black LED for inactive state
vecpLEDs[iLEDIdx]->SetColor ( cLED::RL_BLACK );
}
}
break;
case MT_BAR:
case MT_SLIM_BAR:
pBarMeter->setValue ( 100 * dValue );
break;
}
// clip indicator management (note that in case of clipping, i.e. full
// scale level, the value is above NUM_STEPS_LED_BAR since the minimum
// value of int16 is -32768 but we normalize with 32767 -> therefore
// we really only show the clipping indicator, if actually the largest
// value of int16 is used)
if ( dValue > NUM_STEPS_LED_BAR )
{ {
switch ( eLevelMeterType ) switch ( eLevelMeterType )
{ {
case MT_LED: case MT_LED:
// update state of all LEDs for current level value (except of the clip LED) vecpLEDs[NUM_STEPS_LED_BAR]->SetColor ( cLED::RL_RED );
for ( int iLEDIdx = 0; iLEDIdx < NUM_STEPS_LED_BAR; iLEDIdx++ )
{
// set active LED color if value is above current LED index
if ( iLEDIdx < dValue )
{
// check which color we should use (green, yellow or red)
if ( iLEDIdx < YELLOW_BOUND_LED_BAR )
{
// green region
vecpLEDs[iLEDIdx]->SetColor ( cLED::RL_GREEN );
}
else
{
if ( iLEDIdx < RED_BOUND_LED_BAR )
{
// yellow region
vecpLEDs[iLEDIdx]->SetColor ( cLED::RL_YELLOW );
}
else
{
// red region
vecpLEDs[iLEDIdx]->SetColor ( cLED::RL_RED );
}
}
}
else
{
// we use black LED for inactive state
vecpLEDs[iLEDIdx]->SetColor ( cLED::RL_BLACK );
}
}
// clip LED management (note that in case of clipping, i.e. full
// scale level, the value is above NUM_STEPS_LED_BAR since the minimum
// value of int16 is -32768 but we normalize with 32767 -> therefore
// we really only show the clipping indicator, if actually the largest
// value of int16 is used)
if ( dValue > NUM_STEPS_LED_BAR )
{
vecpLEDs[NUM_STEPS_LED_BAR]->SetColor ( cLED::RL_RED );
TimerClip.start();
}
else if ( vecpLEDs[NUM_STEPS_LED_BAR]->GetColor() != cLED::RL_RED )
{
vecpLEDs[NUM_STEPS_LED_BAR]->SetColor ( cLED::RL_BLACK );
}
break; break;
case MT_BAR: case MT_BAR:
case MT_SLIM_BAR: case MT_SLIM_BAR:
pBarMeter->setValue ( 100 * dValue ); SetBarMeterStyleAndClipStatus ( eLevelMeterType, true );
break;
}
TimerClip.start();
}
else if ( !TimerClip.isActive() )
{
switch ( eLevelMeterType )
{
case MT_LED:
vecpLEDs[NUM_STEPS_LED_BAR]->SetColor ( cLED::RL_BLACK );
break;
case MT_BAR:
case MT_SLIM_BAR:
SetBarMeterStyleAndClipStatus ( eLevelMeterType, false );
break; break;
} }
} }

View File

@ -87,6 +87,9 @@ protected:
QLabel* pLEDLabel; QLabel* pLEDLabel;
}; };
void SetBarMeterStyleAndClipStatus ( const ELevelMeterType eNType,
const bool bIsClip );
QStackedLayout* pStackedLayout; QStackedLayout* pStackedLayout;
ELevelMeterType eLevelMeterType; ELevelMeterType eLevelMeterType;
CVector<cLED*> vecpLEDs; CVector<cLED*> vecpLEDs;