82 const double fallSpeed = 200.0;
83 const double maximumPeakFallSpeed = 10.0;
84 auto maximumPeakHoldTime = std::chrono::seconds(2);
90 auto now = clock::now();
94 if(now - maxPeak.ts > maximumPeakHoldTime){
95 maxPeak.val = std::max(maxPeak.val - maximumPeakFallSpeed /
updatesPerSecond, 0.0);
98 double newPeakHeight = 100 - std::max(
peak[i], zeroLevel) * (100 / zeroLevel);
99 double newRmsHeight = 100 - std::max(
rms[i], zeroLevel) * (100 / zeroLevel);
128 const int meterBarPadHorizontal = 1;
129 const int in_width = width - meterBarPadHorizontal * 2;
130 const int in_full_height = height - meterBarPad * 2;
132 int barHeight = in_full_height * (
peak / 100);
133 int rmsHeight = in_full_height * (
rms / 100);
134 int maxPeakHeight = in_full_height * (maxPeak / 100);
136 QLinearGradient gradient(0, 0, in_width, in_full_height);
137 gradient.setColorAt(0, Qt::red);
138 gradient.setColorAt(0.25, Qt::yellow);
139 gradient.setColorAt(0.5, Qt::green);
140 gradient.setColorAt(1, Qt::green);
141 QBrush brush(gradient);
143 using namespace std::chrono_literals;
146 painter.fillRect(x, y + 1, width, height - 2,
enabled ? Qt::black : Qt::gray);
150 painter.fillRect(x + meterBarPadHorizontal,
151 y + meterBarPad + (in_full_height - barHeight),
155 int maxPos = y + meterBarPad + (in_full_height - maxPeakHeight);
156 QPen maxLevelPen(brush, 1);
157 painter.setPen(maxLevelPen);
158 painter.drawLine(x + meterBarPadHorizontal, maxPos, x + in_width, maxPos);
160 QPen rmsPen(Qt::blue);
162 painter.setPen(rmsPen);
163 int pos = y + meterBarPad + (in_full_height - rmsHeight);
164 painter.drawLine(x + meterBarPadHorizontal, pos, x + in_width, pos);
175 const int barHeight = height - meterVerticalPad * 2 - meterBarPad * 2;
176 const int barStart = y + meterVerticalPad + meterBarPad;
177 const float stepPx = (float) barHeight / std::fabs(zeroLevel);
179 painter.setPen(
connected ? Qt::black : Qt::gray);
183 if(leftTicks && rightTicks){
184 textPosX = x + width / 2 - 8;
185 }
else if(leftTicks){
186 textPosX = x + width - 16;
191 for(
float y = barStart; y <= barStart + barHeight + 0.1; y += stepPx){
192 static const int lineLenghtSmall = 2;
193 static const int lineLenghtMid = 4;
194 static const int lineLenghtLarge = 6;
195 static const int drawThreshold = 4;
197 if(leftTicks) painter.drawLine(x, y, x + lineLenghtLarge, y);
198 if(rightTicks) painter.drawLine(x + width - lineLenghtLarge, y, x + width, y);
199 painter.drawText(QRect(textPosX, y - 6, 16, 12), Qt::AlignCenter,QString::number(i));
200 }
else if(i % 5 == 0){
201 if(leftTicks) painter.drawLine(x, y, x + lineLenghtMid, y);
202 if(rightTicks) painter.drawLine(x + width - lineLenghtMid, y, x + width, y);
203 }
else if(stepPx >= drawThreshold){
204 if(leftTicks) painter.drawLine(x, y, x + lineLenghtSmall, y);
205 if(rightTicks) painter.drawLine(x + width - lineLenghtSmall, y, x + width, y);
213 QIcon icon = style()->standardIcon(QStyle::SP_MessageBoxWarning);
214 QPixmap pixmap = icon.pixmap(iconDim,iconDim);
215 painter.eraseRect(x+width/2 - (iconDim+4)/2, y + height / 2 - (iconDim+4)/2,
216 iconDim+4, iconDim+4);
217 painter.drawPixmap(x+width/2 - iconDim/2, y + height / 2 - iconDim/2,
226 const int scaleWidth = 30;
228 const int meterCount = std::max(1,
channels);
230 const int meterWidth = (width() - scaleWidth) / meterCount;
232 QPainter painter(
this);
234 if(meterCount % 2 != 0){
235 int scaleX =
onRightSide ? 0 : meterCount * meterWidth;
238 for(
int i = 0; i < meterCount; i++){
240 metersStartX + i * meterWidth,
243 height() - meterVerticalPad * 2,
258 for(; i < meterCount / 2; i++){
263 height() - meterVerticalPad * 2,
277 for(; i < meterCount; i++){
279 i * meterWidth + scaleWidth,
282 height() - meterVerticalPad * 2,