volume-control.cpp 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  1. #include "window-basic-main.hpp"
  2. #include "volume-control.hpp"
  3. #include "qt-wrappers.hpp"
  4. #include "obs-app.hpp"
  5. #include "mute-checkbox.hpp"
  6. #include "slider-ignorewheel.hpp"
  7. #include "slider-absoluteset-style.hpp"
  8. #include <QFontDatabase>
  9. #include <QHBoxLayout>
  10. #include <QPushButton>
  11. #include <QLabel>
  12. #include <QPainter>
  13. #include <QStyleFactory>
  14. using namespace std;
  15. #define CLAMP(x, min, max) ((x) < (min) ? (min) : ((x) > (max) ? (max) : (x)))
  16. #define FADER_PRECISION 4096.0
  17. QWeakPointer<VolumeMeterTimer> VolumeMeter::updateTimer;
  18. void VolControl::OBSVolumeChanged(void *data, float db)
  19. {
  20. Q_UNUSED(db);
  21. VolControl *volControl = static_cast<VolControl *>(data);
  22. QMetaObject::invokeMethod(volControl, "VolumeChanged");
  23. }
  24. void VolControl::OBSVolumeLevel(void *data,
  25. const float magnitude[MAX_AUDIO_CHANNELS],
  26. const float peak[MAX_AUDIO_CHANNELS],
  27. const float inputPeak[MAX_AUDIO_CHANNELS])
  28. {
  29. VolControl *volControl = static_cast<VolControl *>(data);
  30. volControl->volMeter->setLevels(magnitude, peak, inputPeak);
  31. }
  32. void VolControl::OBSVolumeMuted(void *data, calldata_t *calldata)
  33. {
  34. VolControl *volControl = static_cast<VolControl *>(data);
  35. bool muted = calldata_bool(calldata, "muted");
  36. QMetaObject::invokeMethod(volControl, "VolumeMuted",
  37. Q_ARG(bool, muted));
  38. }
  39. void VolControl::VolumeChanged()
  40. {
  41. slider->blockSignals(true);
  42. slider->setValue(
  43. (int)(obs_fader_get_deflection(obs_fader) * FADER_PRECISION));
  44. slider->blockSignals(false);
  45. updateText();
  46. }
  47. void VolControl::VolumeMuted(bool muted)
  48. {
  49. if (mute->isChecked() != muted)
  50. mute->setChecked(muted);
  51. volMeter->muted = muted;
  52. }
  53. void VolControl::SetMuted(bool checked)
  54. {
  55. bool prev = obs_source_muted(source);
  56. obs_source_set_muted(source, checked);
  57. auto undo_redo = [](const std::string &name, bool val) {
  58. OBSSourceAutoRelease source =
  59. obs_get_source_by_name(name.c_str());
  60. obs_source_set_muted(source, val);
  61. };
  62. QString text =
  63. QTStr(checked ? "Undo.Volume.Mute" : "Undo.Volume.Unmute");
  64. const char *name = obs_source_get_name(source);
  65. OBSBasic::Get()->undo_s.add_action(
  66. text.arg(name),
  67. std::bind(undo_redo, std::placeholders::_1, prev),
  68. std::bind(undo_redo, std::placeholders::_1, checked), name,
  69. name);
  70. }
  71. void VolControl::SliderChanged(int vol)
  72. {
  73. float prev = obs_source_get_volume(source);
  74. obs_fader_set_deflection(obs_fader, float(vol) / FADER_PRECISION);
  75. updateText();
  76. auto undo_redo = [](const std::string &name, float val) {
  77. OBSSourceAutoRelease source =
  78. obs_get_source_by_name(name.c_str());
  79. obs_source_set_volume(source, val);
  80. };
  81. float val = obs_source_get_volume(source);
  82. const char *name = obs_source_get_name(source);
  83. OBSBasic::Get()->undo_s.add_action(
  84. QTStr("Undo.Volume.Change").arg(name),
  85. std::bind(undo_redo, std::placeholders::_1, prev),
  86. std::bind(undo_redo, std::placeholders::_1, val), name, name,
  87. true);
  88. }
  89. void VolControl::updateText()
  90. {
  91. QString text;
  92. float db = obs_fader_get_db(obs_fader);
  93. if (db < -96.0f)
  94. text = "-inf dB";
  95. else
  96. text = QString::number(db, 'f', 1).append(" dB");
  97. volLabel->setText(text);
  98. bool muted = obs_source_muted(source);
  99. const char *accTextLookup = muted ? "VolControl.SliderMuted"
  100. : "VolControl.SliderUnmuted";
  101. QString sourceName = obs_source_get_name(source);
  102. QString accText = QTStr(accTextLookup).arg(sourceName);
  103. slider->setAccessibleName(accText);
  104. }
  105. QString VolControl::GetName() const
  106. {
  107. return nameLabel->text();
  108. }
  109. void VolControl::SetName(const QString &newName)
  110. {
  111. nameLabel->setText(newName);
  112. }
  113. void VolControl::EmitConfigClicked()
  114. {
  115. emit ConfigClicked();
  116. }
  117. void VolControl::SetMeterDecayRate(qreal q)
  118. {
  119. volMeter->setPeakDecayRate(q);
  120. }
  121. void VolControl::setPeakMeterType(enum obs_peak_meter_type peakMeterType)
  122. {
  123. volMeter->setPeakMeterType(peakMeterType);
  124. }
  125. VolControl::VolControl(OBSSource source_, bool showConfig, bool vertical)
  126. : source(std::move(source_)),
  127. levelTotal(0.0f),
  128. levelCount(0.0f),
  129. obs_fader(obs_fader_create(OBS_FADER_LOG)),
  130. obs_volmeter(obs_volmeter_create(OBS_FADER_LOG)),
  131. vertical(vertical),
  132. contextMenu(nullptr)
  133. {
  134. nameLabel = new QLabel();
  135. volLabel = new QLabel();
  136. mute = new MuteCheckBox();
  137. QString sourceName = obs_source_get_name(source);
  138. setObjectName(sourceName);
  139. if (showConfig) {
  140. config = new QPushButton(this);
  141. config->setProperty("themeID", "configIconSmall");
  142. config->setFlat(true);
  143. config->setSizePolicy(QSizePolicy::Maximum,
  144. QSizePolicy::Maximum);
  145. config->setMaximumSize(22, 22);
  146. config->setAutoDefault(false);
  147. config->setAccessibleName(
  148. QTStr("VolControl.Properties").arg(sourceName));
  149. connect(config, &QAbstractButton::clicked, this,
  150. &VolControl::EmitConfigClicked);
  151. }
  152. QVBoxLayout *mainLayout = new QVBoxLayout;
  153. mainLayout->setContentsMargins(4, 4, 4, 4);
  154. mainLayout->setSpacing(2);
  155. if (vertical) {
  156. QHBoxLayout *nameLayout = new QHBoxLayout;
  157. QHBoxLayout *controlLayout = new QHBoxLayout;
  158. QHBoxLayout *volLayout = new QHBoxLayout;
  159. QHBoxLayout *meterLayout = new QHBoxLayout;
  160. volMeter = new VolumeMeter(nullptr, obs_volmeter, true);
  161. slider = new VolumeSlider(obs_fader, Qt::Vertical);
  162. nameLayout->setAlignment(Qt::AlignCenter);
  163. meterLayout->setAlignment(Qt::AlignCenter);
  164. controlLayout->setAlignment(Qt::AlignCenter);
  165. volLayout->setAlignment(Qt::AlignCenter);
  166. nameLayout->setContentsMargins(0, 0, 0, 0);
  167. nameLayout->setSpacing(0);
  168. nameLayout->addWidget(nameLabel);
  169. controlLayout->setContentsMargins(0, 0, 0, 0);
  170. controlLayout->setSpacing(0);
  171. if (showConfig)
  172. controlLayout->addWidget(config);
  173. controlLayout->addItem(new QSpacerItem(3, 0));
  174. // Add Headphone (audio monitoring) widget here
  175. controlLayout->addWidget(mute);
  176. meterLayout->setContentsMargins(0, 0, 0, 0);
  177. meterLayout->setSpacing(0);
  178. meterLayout->addWidget(volMeter);
  179. meterLayout->addWidget(slider);
  180. volLayout->setContentsMargins(0, 0, 0, 0);
  181. volLayout->setSpacing(0);
  182. volLayout->addWidget(volLabel);
  183. mainLayout->addItem(nameLayout);
  184. mainLayout->addItem(volLayout);
  185. mainLayout->addItem(meterLayout);
  186. mainLayout->addItem(controlLayout);
  187. volMeter->setFocusProxy(slider);
  188. setMaximumWidth(110);
  189. } else {
  190. QHBoxLayout *volLayout = new QHBoxLayout;
  191. QHBoxLayout *textLayout = new QHBoxLayout;
  192. QHBoxLayout *botLayout = new QHBoxLayout;
  193. volMeter = new VolumeMeter(nullptr, obs_volmeter, false);
  194. slider = new VolumeSlider(obs_fader, Qt::Horizontal);
  195. textLayout->setContentsMargins(0, 0, 0, 0);
  196. textLayout->addWidget(nameLabel);
  197. textLayout->addWidget(volLabel);
  198. textLayout->setAlignment(nameLabel, Qt::AlignLeft);
  199. textLayout->setAlignment(volLabel, Qt::AlignRight);
  200. volLayout->addWidget(slider);
  201. volLayout->addWidget(mute);
  202. volLayout->setSpacing(5);
  203. botLayout->setContentsMargins(0, 0, 0, 0);
  204. botLayout->setSpacing(0);
  205. botLayout->addLayout(volLayout);
  206. if (showConfig)
  207. botLayout->addWidget(config);
  208. mainLayout->addItem(textLayout);
  209. mainLayout->addWidget(volMeter);
  210. mainLayout->addItem(botLayout);
  211. volMeter->setFocusProxy(slider);
  212. }
  213. setLayout(mainLayout);
  214. QFont font = nameLabel->font();
  215. font.setPointSize(font.pointSize() - 1);
  216. nameLabel->setText(sourceName);
  217. nameLabel->setFont(font);
  218. volLabel->setFont(font);
  219. slider->setMinimum(0);
  220. slider->setMaximum(int(FADER_PRECISION));
  221. bool muted = obs_source_muted(source);
  222. mute->setChecked(muted);
  223. volMeter->muted = muted;
  224. mute->setAccessibleName(QTStr("VolControl.Mute").arg(sourceName));
  225. obs_fader_add_callback(obs_fader, OBSVolumeChanged, this);
  226. obs_volmeter_add_callback(obs_volmeter, OBSVolumeLevel, this);
  227. signal_handler_connect(obs_source_get_signal_handler(source), "mute",
  228. OBSVolumeMuted, this);
  229. QWidget::connect(slider, SIGNAL(valueChanged(int)), this,
  230. SLOT(SliderChanged(int)));
  231. QWidget::connect(mute, SIGNAL(clicked(bool)), this,
  232. SLOT(SetMuted(bool)));
  233. obs_fader_attach_source(obs_fader, source);
  234. obs_volmeter_attach_source(obs_volmeter, source);
  235. QString styleName = slider->style()->objectName();
  236. QStyle *style;
  237. style = QStyleFactory::create(styleName);
  238. if (!style) {
  239. style = new SliderAbsoluteSetStyle();
  240. } else {
  241. style = new SliderAbsoluteSetStyle(style);
  242. }
  243. style->setParent(slider);
  244. slider->setStyle(style);
  245. /* Call volume changed once to init the slider position and label */
  246. VolumeChanged();
  247. }
  248. void VolControl::EnableSlider(bool enable)
  249. {
  250. slider->setEnabled(enable);
  251. }
  252. VolControl::~VolControl()
  253. {
  254. obs_fader_remove_callback(obs_fader, OBSVolumeChanged, this);
  255. obs_volmeter_remove_callback(obs_volmeter, OBSVolumeLevel, this);
  256. signal_handler_disconnect(obs_source_get_signal_handler(source), "mute",
  257. OBSVolumeMuted, this);
  258. obs_fader_destroy(obs_fader);
  259. obs_volmeter_destroy(obs_volmeter);
  260. if (contextMenu)
  261. contextMenu->close();
  262. }
  263. QColor VolumeMeter::getBackgroundNominalColor() const
  264. {
  265. return backgroundNominalColor;
  266. }
  267. QColor VolumeMeter::getBackgroundNominalColorDisabled() const
  268. {
  269. return backgroundNominalColorDisabled;
  270. }
  271. void VolumeMeter::setBackgroundNominalColor(QColor c)
  272. {
  273. backgroundNominalColor = std::move(c);
  274. }
  275. void VolumeMeter::setBackgroundNominalColorDisabled(QColor c)
  276. {
  277. backgroundNominalColorDisabled = std::move(c);
  278. }
  279. QColor VolumeMeter::getBackgroundWarningColor() const
  280. {
  281. return backgroundWarningColor;
  282. }
  283. QColor VolumeMeter::getBackgroundWarningColorDisabled() const
  284. {
  285. return backgroundWarningColorDisabled;
  286. }
  287. void VolumeMeter::setBackgroundWarningColor(QColor c)
  288. {
  289. backgroundWarningColor = std::move(c);
  290. }
  291. void VolumeMeter::setBackgroundWarningColorDisabled(QColor c)
  292. {
  293. backgroundWarningColorDisabled = std::move(c);
  294. }
  295. QColor VolumeMeter::getBackgroundErrorColor() const
  296. {
  297. return backgroundErrorColor;
  298. }
  299. QColor VolumeMeter::getBackgroundErrorColorDisabled() const
  300. {
  301. return backgroundErrorColorDisabled;
  302. }
  303. void VolumeMeter::setBackgroundErrorColor(QColor c)
  304. {
  305. backgroundErrorColor = std::move(c);
  306. }
  307. void VolumeMeter::setBackgroundErrorColorDisabled(QColor c)
  308. {
  309. backgroundErrorColorDisabled = std::move(c);
  310. }
  311. QColor VolumeMeter::getForegroundNominalColor() const
  312. {
  313. return foregroundNominalColor;
  314. }
  315. QColor VolumeMeter::getForegroundNominalColorDisabled() const
  316. {
  317. return foregroundNominalColorDisabled;
  318. }
  319. void VolumeMeter::setForegroundNominalColor(QColor c)
  320. {
  321. foregroundNominalColor = std::move(c);
  322. }
  323. void VolumeMeter::setForegroundNominalColorDisabled(QColor c)
  324. {
  325. foregroundNominalColorDisabled = std::move(c);
  326. }
  327. QColor VolumeMeter::getForegroundWarningColor() const
  328. {
  329. return foregroundWarningColor;
  330. }
  331. QColor VolumeMeter::getForegroundWarningColorDisabled() const
  332. {
  333. return foregroundWarningColorDisabled;
  334. }
  335. void VolumeMeter::setForegroundWarningColor(QColor c)
  336. {
  337. foregroundWarningColor = std::move(c);
  338. }
  339. void VolumeMeter::setForegroundWarningColorDisabled(QColor c)
  340. {
  341. foregroundWarningColorDisabled = std::move(c);
  342. }
  343. QColor VolumeMeter::getForegroundErrorColor() const
  344. {
  345. return foregroundErrorColor;
  346. }
  347. QColor VolumeMeter::getForegroundErrorColorDisabled() const
  348. {
  349. return foregroundErrorColorDisabled;
  350. }
  351. void VolumeMeter::setForegroundErrorColor(QColor c)
  352. {
  353. foregroundErrorColor = std::move(c);
  354. }
  355. void VolumeMeter::setForegroundErrorColorDisabled(QColor c)
  356. {
  357. foregroundErrorColorDisabled = std::move(c);
  358. }
  359. QColor VolumeMeter::getClipColor() const
  360. {
  361. return clipColor;
  362. }
  363. void VolumeMeter::setClipColor(QColor c)
  364. {
  365. clipColor = std::move(c);
  366. }
  367. QColor VolumeMeter::getMagnitudeColor() const
  368. {
  369. return magnitudeColor;
  370. }
  371. void VolumeMeter::setMagnitudeColor(QColor c)
  372. {
  373. magnitudeColor = std::move(c);
  374. }
  375. QColor VolumeMeter::getMajorTickColor() const
  376. {
  377. return majorTickColor;
  378. }
  379. void VolumeMeter::setMajorTickColor(QColor c)
  380. {
  381. majorTickColor = std::move(c);
  382. }
  383. QColor VolumeMeter::getMinorTickColor() const
  384. {
  385. return minorTickColor;
  386. }
  387. void VolumeMeter::setMinorTickColor(QColor c)
  388. {
  389. minorTickColor = std::move(c);
  390. }
  391. qreal VolumeMeter::getMinimumLevel() const
  392. {
  393. return minimumLevel;
  394. }
  395. void VolumeMeter::setMinimumLevel(qreal v)
  396. {
  397. minimumLevel = v;
  398. }
  399. qreal VolumeMeter::getWarningLevel() const
  400. {
  401. return warningLevel;
  402. }
  403. void VolumeMeter::setWarningLevel(qreal v)
  404. {
  405. warningLevel = v;
  406. }
  407. qreal VolumeMeter::getErrorLevel() const
  408. {
  409. return errorLevel;
  410. }
  411. void VolumeMeter::setErrorLevel(qreal v)
  412. {
  413. errorLevel = v;
  414. }
  415. qreal VolumeMeter::getClipLevel() const
  416. {
  417. return clipLevel;
  418. }
  419. void VolumeMeter::setClipLevel(qreal v)
  420. {
  421. clipLevel = v;
  422. }
  423. qreal VolumeMeter::getMinimumInputLevel() const
  424. {
  425. return minimumInputLevel;
  426. }
  427. void VolumeMeter::setMinimumInputLevel(qreal v)
  428. {
  429. minimumInputLevel = v;
  430. }
  431. qreal VolumeMeter::getPeakDecayRate() const
  432. {
  433. return peakDecayRate;
  434. }
  435. void VolumeMeter::setPeakDecayRate(qreal v)
  436. {
  437. peakDecayRate = v;
  438. }
  439. qreal VolumeMeter::getMagnitudeIntegrationTime() const
  440. {
  441. return magnitudeIntegrationTime;
  442. }
  443. void VolumeMeter::setMagnitudeIntegrationTime(qreal v)
  444. {
  445. magnitudeIntegrationTime = v;
  446. }
  447. qreal VolumeMeter::getPeakHoldDuration() const
  448. {
  449. return peakHoldDuration;
  450. }
  451. void VolumeMeter::setPeakHoldDuration(qreal v)
  452. {
  453. peakHoldDuration = v;
  454. }
  455. qreal VolumeMeter::getInputPeakHoldDuration() const
  456. {
  457. return inputPeakHoldDuration;
  458. }
  459. void VolumeMeter::setInputPeakHoldDuration(qreal v)
  460. {
  461. inputPeakHoldDuration = v;
  462. }
  463. void VolumeMeter::setPeakMeterType(enum obs_peak_meter_type peakMeterType)
  464. {
  465. obs_volmeter_set_peak_meter_type(obs_volmeter, peakMeterType);
  466. switch (peakMeterType) {
  467. case TRUE_PEAK_METER:
  468. // For true-peak meters EBU has defined the Permitted Maximum,
  469. // taking into account the accuracy of the meter and further
  470. // processing required by lossy audio compression.
  471. //
  472. // The alignment level was not specified, but I've adjusted
  473. // it compared to a sample-peak meter. Incidentally Youtube
  474. // uses this new Alignment Level as the maximum integrated
  475. // loudness of a video.
  476. //
  477. // * Permitted Maximum Level (PML) = -2.0 dBTP
  478. // * Alignment Level (AL) = -13 dBTP
  479. setErrorLevel(-2.0);
  480. setWarningLevel(-13.0);
  481. break;
  482. case SAMPLE_PEAK_METER:
  483. default:
  484. // For a sample Peak Meter EBU has the following level
  485. // definitions, taking into account inaccuracies of this meter:
  486. //
  487. // * Permitted Maximum Level (PML) = -9.0 dBFS
  488. // * Alignment Level (AL) = -20.0 dBFS
  489. setErrorLevel(-9.0);
  490. setWarningLevel(-20.0);
  491. break;
  492. }
  493. }
  494. void VolumeMeter::mousePressEvent(QMouseEvent *event)
  495. {
  496. setFocus(Qt::MouseFocusReason);
  497. event->accept();
  498. }
  499. void VolumeMeter::wheelEvent(QWheelEvent *event)
  500. {
  501. QApplication::sendEvent(focusProxy(), event);
  502. }
  503. VolumeMeter::VolumeMeter(QWidget *parent, obs_volmeter_t *obs_volmeter,
  504. bool vertical)
  505. : QWidget(parent), obs_volmeter(obs_volmeter), vertical(vertical)
  506. {
  507. setAttribute(Qt::WA_OpaquePaintEvent, true);
  508. // Use a font that can be rendered small.
  509. tickFont = QFont("Arial");
  510. tickFont.setPixelSize(7);
  511. // Default meter color settings, they only show if
  512. // there is no stylesheet, do not remove.
  513. backgroundNominalColor.setRgb(0x26, 0x7f, 0x26); // Dark green
  514. backgroundWarningColor.setRgb(0x7f, 0x7f, 0x26); // Dark yellow
  515. backgroundErrorColor.setRgb(0x7f, 0x26, 0x26); // Dark red
  516. foregroundNominalColor.setRgb(0x4c, 0xff, 0x4c); // Bright green
  517. foregroundWarningColor.setRgb(0xff, 0xff, 0x4c); // Bright yellow
  518. foregroundErrorColor.setRgb(0xff, 0x4c, 0x4c); // Bright red
  519. backgroundNominalColorDisabled.setRgb(90, 90, 90);
  520. backgroundWarningColorDisabled.setRgb(117, 117, 117);
  521. backgroundErrorColorDisabled.setRgb(65, 65, 65);
  522. foregroundNominalColorDisabled.setRgb(163, 163, 163);
  523. foregroundWarningColorDisabled.setRgb(217, 217, 217);
  524. foregroundErrorColorDisabled.setRgb(113, 113, 113);
  525. clipColor.setRgb(0xff, 0xff, 0xff); // Bright white
  526. magnitudeColor.setRgb(0x00, 0x00, 0x00); // Black
  527. majorTickColor.setRgb(0xff, 0xff, 0xff); // Black
  528. minorTickColor.setRgb(0xcc, 0xcc, 0xcc); // Black
  529. minimumLevel = -60.0; // -60 dB
  530. warningLevel = -20.0; // -20 dB
  531. errorLevel = -9.0; // -9 dB
  532. clipLevel = -0.5; // -0.5 dB
  533. minimumInputLevel = -50.0; // -50 dB
  534. peakDecayRate = 11.76; // 20 dB / 1.7 sec
  535. magnitudeIntegrationTime = 0.3; // 99% in 300 ms
  536. peakHoldDuration = 20.0; // 20 seconds
  537. inputPeakHoldDuration = 1.0; // 1 second
  538. channels = (int)audio_output_get_channels(obs_get_audio());
  539. handleChannelCofigurationChange();
  540. updateTimerRef = updateTimer.toStrongRef();
  541. if (!updateTimerRef) {
  542. updateTimerRef = QSharedPointer<VolumeMeterTimer>::create();
  543. updateTimerRef->setTimerType(Qt::PreciseTimer);
  544. updateTimerRef->start(16);
  545. updateTimer = updateTimerRef;
  546. }
  547. updateTimerRef->AddVolControl(this);
  548. }
  549. VolumeMeter::~VolumeMeter()
  550. {
  551. updateTimerRef->RemoveVolControl(this);
  552. delete tickPaintCache;
  553. }
  554. void VolumeMeter::setLevels(const float magnitude[MAX_AUDIO_CHANNELS],
  555. const float peak[MAX_AUDIO_CHANNELS],
  556. const float inputPeak[MAX_AUDIO_CHANNELS])
  557. {
  558. uint64_t ts = os_gettime_ns();
  559. QMutexLocker locker(&dataMutex);
  560. currentLastUpdateTime = ts;
  561. for (int channelNr = 0; channelNr < MAX_AUDIO_CHANNELS; channelNr++) {
  562. currentMagnitude[channelNr] = magnitude[channelNr];
  563. currentPeak[channelNr] = peak[channelNr];
  564. currentInputPeak[channelNr] = inputPeak[channelNr];
  565. }
  566. // In case there are more updates then redraws we must make sure
  567. // that the ballistics of peak and hold are recalculated.
  568. locker.unlock();
  569. calculateBallistics(ts);
  570. }
  571. inline void VolumeMeter::resetLevels()
  572. {
  573. currentLastUpdateTime = 0;
  574. for (int channelNr = 0; channelNr < MAX_AUDIO_CHANNELS; channelNr++) {
  575. currentMagnitude[channelNr] = -M_INFINITE;
  576. currentPeak[channelNr] = -M_INFINITE;
  577. currentInputPeak[channelNr] = -M_INFINITE;
  578. displayMagnitude[channelNr] = -M_INFINITE;
  579. displayPeak[channelNr] = -M_INFINITE;
  580. displayPeakHold[channelNr] = -M_INFINITE;
  581. displayPeakHoldLastUpdateTime[channelNr] = 0;
  582. displayInputPeakHold[channelNr] = -M_INFINITE;
  583. displayInputPeakHoldLastUpdateTime[channelNr] = 0;
  584. }
  585. }
  586. inline void VolumeMeter::handleChannelCofigurationChange()
  587. {
  588. QMutexLocker locker(&dataMutex);
  589. int currentNrAudioChannels = obs_volmeter_get_nr_channels(obs_volmeter);
  590. if (displayNrAudioChannels != currentNrAudioChannels) {
  591. displayNrAudioChannels = currentNrAudioChannels;
  592. // Make room for 3 pixels meter, with one pixel between each.
  593. // Then 9/13 pixels for ticks and numbers.
  594. if (vertical)
  595. setMinimumSize(displayNrAudioChannels * 4 + 14, 130);
  596. else
  597. setMinimumSize(130, displayNrAudioChannels * 4 + 8);
  598. resetLevels();
  599. }
  600. }
  601. inline bool VolumeMeter::detectIdle(uint64_t ts)
  602. {
  603. double timeSinceLastUpdate = (ts - currentLastUpdateTime) * 0.000000001;
  604. if (timeSinceLastUpdate > 0.5) {
  605. resetLevels();
  606. return true;
  607. } else {
  608. return false;
  609. }
  610. }
  611. inline void
  612. VolumeMeter::calculateBallisticsForChannel(int channelNr, uint64_t ts,
  613. qreal timeSinceLastRedraw)
  614. {
  615. if (currentPeak[channelNr] >= displayPeak[channelNr] ||
  616. isnan(displayPeak[channelNr])) {
  617. // Attack of peak is immediate.
  618. displayPeak[channelNr] = currentPeak[channelNr];
  619. } else {
  620. // Decay of peak is 40 dB / 1.7 seconds for Fast Profile
  621. // 20 dB / 1.7 seconds for Medium Profile (Type I PPM)
  622. // 24 dB / 2.8 seconds for Slow Profile (Type II PPM)
  623. float decay = float(peakDecayRate * timeSinceLastRedraw);
  624. displayPeak[channelNr] = CLAMP(displayPeak[channelNr] - decay,
  625. currentPeak[channelNr], 0);
  626. }
  627. if (currentPeak[channelNr] >= displayPeakHold[channelNr] ||
  628. !isfinite(displayPeakHold[channelNr])) {
  629. // Attack of peak-hold is immediate, but keep track
  630. // when it was last updated.
  631. displayPeakHold[channelNr] = currentPeak[channelNr];
  632. displayPeakHoldLastUpdateTime[channelNr] = ts;
  633. } else {
  634. // The peak and hold falls back to peak
  635. // after 20 seconds.
  636. qreal timeSinceLastPeak =
  637. (uint64_t)(ts -
  638. displayPeakHoldLastUpdateTime[channelNr]) *
  639. 0.000000001;
  640. if (timeSinceLastPeak > peakHoldDuration) {
  641. displayPeakHold[channelNr] = currentPeak[channelNr];
  642. displayPeakHoldLastUpdateTime[channelNr] = ts;
  643. }
  644. }
  645. if (currentInputPeak[channelNr] >= displayInputPeakHold[channelNr] ||
  646. !isfinite(displayInputPeakHold[channelNr])) {
  647. // Attack of peak-hold is immediate, but keep track
  648. // when it was last updated.
  649. displayInputPeakHold[channelNr] = currentInputPeak[channelNr];
  650. displayInputPeakHoldLastUpdateTime[channelNr] = ts;
  651. } else {
  652. // The peak and hold falls back to peak after 1 second.
  653. qreal timeSinceLastPeak =
  654. (uint64_t)(ts -
  655. displayInputPeakHoldLastUpdateTime[channelNr]) *
  656. 0.000000001;
  657. if (timeSinceLastPeak > inputPeakHoldDuration) {
  658. displayInputPeakHold[channelNr] =
  659. currentInputPeak[channelNr];
  660. displayInputPeakHoldLastUpdateTime[channelNr] = ts;
  661. }
  662. }
  663. if (!isfinite(displayMagnitude[channelNr])) {
  664. // The statements in the else-leg do not work with
  665. // NaN and infinite displayMagnitude.
  666. displayMagnitude[channelNr] = currentMagnitude[channelNr];
  667. } else {
  668. // A VU meter will integrate to the new value to 99% in 300 ms.
  669. // The calculation here is very simplified and is more accurate
  670. // with higher frame-rate.
  671. float attack =
  672. float((currentMagnitude[channelNr] -
  673. displayMagnitude[channelNr]) *
  674. (timeSinceLastRedraw / magnitudeIntegrationTime) *
  675. 0.99);
  676. displayMagnitude[channelNr] =
  677. CLAMP(displayMagnitude[channelNr] + attack,
  678. (float)minimumLevel, 0);
  679. }
  680. }
  681. inline void VolumeMeter::calculateBallistics(uint64_t ts,
  682. qreal timeSinceLastRedraw)
  683. {
  684. QMutexLocker locker(&dataMutex);
  685. for (int channelNr = 0; channelNr < MAX_AUDIO_CHANNELS; channelNr++)
  686. calculateBallisticsForChannel(channelNr, ts,
  687. timeSinceLastRedraw);
  688. }
  689. void VolumeMeter::paintInputMeter(QPainter &painter, int x, int y, int width,
  690. int height, float peakHold)
  691. {
  692. QMutexLocker locker(&dataMutex);
  693. QColor color;
  694. if (peakHold < minimumInputLevel)
  695. color = backgroundNominalColor;
  696. else if (peakHold < warningLevel)
  697. color = foregroundNominalColor;
  698. else if (peakHold < errorLevel)
  699. color = foregroundWarningColor;
  700. else if (peakHold <= clipLevel)
  701. color = foregroundErrorColor;
  702. else
  703. color = clipColor;
  704. painter.fillRect(x, y, width, height, color);
  705. }
  706. void VolumeMeter::paintHTicks(QPainter &painter, int x, int y, int width,
  707. int height)
  708. {
  709. qreal scale = width / minimumLevel;
  710. painter.setFont(tickFont);
  711. painter.setPen(majorTickColor);
  712. // Draw major tick lines and numeric indicators.
  713. for (int i = 0; i >= minimumLevel; i -= 5) {
  714. int position = int(x + width - (i * scale) - 1);
  715. QString str = QString::number(i);
  716. if (i == 0 || i == -5)
  717. painter.drawText(position - 3, height, str);
  718. else
  719. painter.drawText(position - 5, height, str);
  720. painter.drawLine(position, y, position, y + 2);
  721. }
  722. // Draw minor tick lines.
  723. painter.setPen(minorTickColor);
  724. for (int i = 0; i >= minimumLevel; i--) {
  725. int position = int(x + width - (i * scale) - 1);
  726. if (i % 5 != 0)
  727. painter.drawLine(position, y, position, y + 1);
  728. }
  729. }
  730. void VolumeMeter::paintVTicks(QPainter &painter, int x, int y, int height)
  731. {
  732. qreal scale = height / minimumLevel;
  733. painter.setFont(tickFont);
  734. painter.setPen(majorTickColor);
  735. // Draw major tick lines and numeric indicators.
  736. for (int i = 0; i >= minimumLevel; i -= 5) {
  737. int position = y + int((i * scale) - 1);
  738. QString str = QString::number(i);
  739. if (i == 0)
  740. painter.drawText(x + 5, position + 4, str);
  741. else if (i == -60)
  742. painter.drawText(x + 4, position, str);
  743. else
  744. painter.drawText(x + 4, position + 2, str);
  745. painter.drawLine(x, position, x + 2, position);
  746. }
  747. // Draw minor tick lines.
  748. painter.setPen(minorTickColor);
  749. for (int i = 0; i >= minimumLevel; i--) {
  750. int position = y + int((i * scale) - 1);
  751. if (i % 5 != 0)
  752. painter.drawLine(x, position, x + 1, position);
  753. }
  754. }
  755. #define CLIP_FLASH_DURATION_MS 1000
  756. void VolumeMeter::ClipEnding()
  757. {
  758. clipping = false;
  759. }
  760. void VolumeMeter::paintHMeter(QPainter &painter, int x, int y, int width,
  761. int height, float magnitude, float peak,
  762. float peakHold)
  763. {
  764. qreal scale = width / minimumLevel;
  765. QMutexLocker locker(&dataMutex);
  766. int minimumPosition = x + 0;
  767. int maximumPosition = x + width;
  768. int magnitudePosition = int(x + width - (magnitude * scale));
  769. int peakPosition = int(x + width - (peak * scale));
  770. int peakHoldPosition = int(x + width - (peakHold * scale));
  771. int warningPosition = int(x + width - (warningLevel * scale));
  772. int errorPosition = int(x + width - (errorLevel * scale));
  773. int nominalLength = warningPosition - minimumPosition;
  774. int warningLength = errorPosition - warningPosition;
  775. int errorLength = maximumPosition - errorPosition;
  776. locker.unlock();
  777. if (clipping) {
  778. peakPosition = maximumPosition;
  779. }
  780. if (peakPosition < minimumPosition) {
  781. painter.fillRect(minimumPosition, y, nominalLength, height,
  782. muted ? backgroundNominalColorDisabled
  783. : backgroundNominalColor);
  784. painter.fillRect(warningPosition, y, warningLength, height,
  785. muted ? backgroundWarningColorDisabled
  786. : backgroundWarningColor);
  787. painter.fillRect(errorPosition, y, errorLength, height,
  788. muted ? backgroundErrorColorDisabled
  789. : backgroundErrorColor);
  790. } else if (peakPosition < warningPosition) {
  791. painter.fillRect(minimumPosition, y,
  792. peakPosition - minimumPosition, height,
  793. muted ? foregroundNominalColorDisabled
  794. : foregroundNominalColor);
  795. painter.fillRect(peakPosition, y,
  796. warningPosition - peakPosition, height,
  797. muted ? backgroundNominalColorDisabled
  798. : backgroundNominalColor);
  799. painter.fillRect(warningPosition, y, warningLength, height,
  800. muted ? backgroundWarningColorDisabled
  801. : backgroundWarningColor);
  802. painter.fillRect(errorPosition, y, errorLength, height,
  803. muted ? backgroundErrorColorDisabled
  804. : backgroundErrorColor);
  805. } else if (peakPosition < errorPosition) {
  806. painter.fillRect(minimumPosition, y, nominalLength, height,
  807. muted ? foregroundNominalColorDisabled
  808. : foregroundNominalColor);
  809. painter.fillRect(warningPosition, y,
  810. peakPosition - warningPosition, height,
  811. muted ? foregroundWarningColorDisabled
  812. : foregroundWarningColor);
  813. painter.fillRect(peakPosition, y, errorPosition - peakPosition,
  814. height,
  815. muted ? backgroundWarningColorDisabled
  816. : backgroundWarningColor);
  817. painter.fillRect(errorPosition, y, errorLength, height,
  818. muted ? backgroundErrorColorDisabled
  819. : backgroundErrorColor);
  820. } else if (peakPosition < maximumPosition) {
  821. painter.fillRect(minimumPosition, y, nominalLength, height,
  822. muted ? foregroundNominalColorDisabled
  823. : foregroundNominalColor);
  824. painter.fillRect(warningPosition, y, warningLength, height,
  825. muted ? foregroundWarningColorDisabled
  826. : foregroundWarningColor);
  827. painter.fillRect(errorPosition, y, peakPosition - errorPosition,
  828. height,
  829. muted ? foregroundErrorColorDisabled
  830. : foregroundErrorColor);
  831. painter.fillRect(peakPosition, y,
  832. maximumPosition - peakPosition, height,
  833. muted ? backgroundErrorColorDisabled
  834. : backgroundErrorColor);
  835. } else if (int(magnitude) != 0) {
  836. if (!clipping) {
  837. QTimer::singleShot(CLIP_FLASH_DURATION_MS, this,
  838. SLOT(ClipEnding()));
  839. clipping = true;
  840. }
  841. int end = errorLength + warningLength + nominalLength;
  842. painter.fillRect(minimumPosition, y, end, height,
  843. QBrush(muted ? foregroundErrorColorDisabled
  844. : foregroundErrorColor));
  845. }
  846. if (peakHoldPosition - 3 < minimumPosition)
  847. ; // Peak-hold below minimum, no drawing.
  848. else if (peakHoldPosition < warningPosition)
  849. painter.fillRect(peakHoldPosition - 3, y, 3, height,
  850. muted ? foregroundNominalColorDisabled
  851. : foregroundNominalColor);
  852. else if (peakHoldPosition < errorPosition)
  853. painter.fillRect(peakHoldPosition - 3, y, 3, height,
  854. muted ? foregroundWarningColorDisabled
  855. : foregroundWarningColor);
  856. else
  857. painter.fillRect(peakHoldPosition - 3, y, 3, height,
  858. muted ? foregroundErrorColorDisabled
  859. : foregroundErrorColor);
  860. if (magnitudePosition - 3 >= minimumPosition)
  861. painter.fillRect(magnitudePosition - 3, y, 3, height,
  862. magnitudeColor);
  863. }
  864. void VolumeMeter::paintVMeter(QPainter &painter, int x, int y, int width,
  865. int height, float magnitude, float peak,
  866. float peakHold)
  867. {
  868. qreal scale = height / minimumLevel;
  869. QMutexLocker locker(&dataMutex);
  870. int minimumPosition = y + 0;
  871. int maximumPosition = y + height;
  872. int magnitudePosition = int(y + height - (magnitude * scale));
  873. int peakPosition = int(y + height - (peak * scale));
  874. int peakHoldPosition = int(y + height - (peakHold * scale));
  875. int warningPosition = int(y + height - (warningLevel * scale));
  876. int errorPosition = int(y + height - (errorLevel * scale));
  877. int nominalLength = warningPosition - minimumPosition;
  878. int warningLength = errorPosition - warningPosition;
  879. int errorLength = maximumPosition - errorPosition;
  880. locker.unlock();
  881. if (clipping) {
  882. peakPosition = maximumPosition;
  883. }
  884. if (peakPosition < minimumPosition) {
  885. painter.fillRect(x, minimumPosition, width, nominalLength,
  886. muted ? backgroundNominalColorDisabled
  887. : backgroundNominalColor);
  888. painter.fillRect(x, warningPosition, width, warningLength,
  889. muted ? backgroundWarningColorDisabled
  890. : backgroundWarningColor);
  891. painter.fillRect(x, errorPosition, width, errorLength,
  892. muted ? backgroundErrorColorDisabled
  893. : backgroundErrorColor);
  894. } else if (peakPosition < warningPosition) {
  895. painter.fillRect(x, minimumPosition, width,
  896. peakPosition - minimumPosition,
  897. muted ? foregroundNominalColorDisabled
  898. : foregroundNominalColor);
  899. painter.fillRect(x, peakPosition, width,
  900. warningPosition - peakPosition,
  901. muted ? backgroundNominalColorDisabled
  902. : backgroundNominalColor);
  903. painter.fillRect(x, warningPosition, width, warningLength,
  904. muted ? backgroundWarningColorDisabled
  905. : backgroundWarningColor);
  906. painter.fillRect(x, errorPosition, width, errorLength,
  907. muted ? backgroundErrorColorDisabled
  908. : backgroundErrorColor);
  909. } else if (peakPosition < errorPosition) {
  910. painter.fillRect(x, minimumPosition, width, nominalLength,
  911. muted ? foregroundNominalColorDisabled
  912. : foregroundNominalColor);
  913. painter.fillRect(x, warningPosition, width,
  914. peakPosition - warningPosition,
  915. muted ? foregroundWarningColorDisabled
  916. : foregroundWarningColor);
  917. painter.fillRect(x, peakPosition, width,
  918. errorPosition - peakPosition,
  919. muted ? backgroundWarningColorDisabled
  920. : backgroundWarningColor);
  921. painter.fillRect(x, errorPosition, width, errorLength,
  922. muted ? backgroundErrorColorDisabled
  923. : backgroundErrorColor);
  924. } else if (peakPosition < maximumPosition) {
  925. painter.fillRect(x, minimumPosition, width, nominalLength,
  926. muted ? foregroundNominalColorDisabled
  927. : foregroundNominalColor);
  928. painter.fillRect(x, warningPosition, width, warningLength,
  929. muted ? foregroundWarningColorDisabled
  930. : foregroundWarningColor);
  931. painter.fillRect(x, errorPosition, width,
  932. peakPosition - errorPosition,
  933. muted ? foregroundErrorColorDisabled
  934. : foregroundErrorColor);
  935. painter.fillRect(x, peakPosition, width,
  936. maximumPosition - peakPosition,
  937. muted ? backgroundErrorColorDisabled
  938. : backgroundErrorColor);
  939. } else {
  940. if (!clipping) {
  941. QTimer::singleShot(CLIP_FLASH_DURATION_MS, this,
  942. SLOT(ClipEnding()));
  943. clipping = true;
  944. }
  945. int end = errorLength + warningLength + nominalLength;
  946. painter.fillRect(x, minimumPosition, width, end,
  947. QBrush(muted ? foregroundErrorColorDisabled
  948. : foregroundErrorColor));
  949. }
  950. if (peakHoldPosition - 3 < minimumPosition)
  951. ; // Peak-hold below minimum, no drawing.
  952. else if (peakHoldPosition < warningPosition)
  953. painter.fillRect(x, peakHoldPosition - 3, width, 3,
  954. muted ? foregroundNominalColorDisabled
  955. : foregroundNominalColor);
  956. else if (peakHoldPosition < errorPosition)
  957. painter.fillRect(x, peakHoldPosition - 3, width, 3,
  958. muted ? foregroundWarningColorDisabled
  959. : foregroundWarningColor);
  960. else
  961. painter.fillRect(x, peakHoldPosition - 3, width, 3,
  962. muted ? foregroundErrorColorDisabled
  963. : foregroundErrorColor);
  964. if (magnitudePosition - 3 >= minimumPosition)
  965. painter.fillRect(x, magnitudePosition - 3, width, 3,
  966. magnitudeColor);
  967. }
  968. void VolumeMeter::paintEvent(QPaintEvent *event)
  969. {
  970. uint64_t ts = os_gettime_ns();
  971. qreal timeSinceLastRedraw = (ts - lastRedrawTime) * 0.000000001;
  972. const QRect rect = event->region().boundingRect();
  973. int width = rect.width();
  974. int height = rect.height();
  975. handleChannelCofigurationChange();
  976. calculateBallistics(ts, timeSinceLastRedraw);
  977. bool idle = detectIdle(ts);
  978. // Draw the ticks in a off-screen buffer when the widget changes size.
  979. QSize tickPaintCacheSize;
  980. if (vertical)
  981. tickPaintCacheSize = QSize(14, height);
  982. else
  983. tickPaintCacheSize = QSize(width, 9);
  984. if (tickPaintCache == nullptr ||
  985. tickPaintCache->size() != tickPaintCacheSize) {
  986. delete tickPaintCache;
  987. tickPaintCache = new QPixmap(tickPaintCacheSize);
  988. QColor clearColor(0, 0, 0, 0);
  989. tickPaintCache->fill(clearColor);
  990. QPainter tickPainter(tickPaintCache);
  991. if (vertical) {
  992. tickPainter.translate(0, height);
  993. tickPainter.scale(1, -1);
  994. paintVTicks(tickPainter, 0, 11,
  995. tickPaintCacheSize.height() - 11);
  996. } else {
  997. paintHTicks(tickPainter, 6, 0,
  998. tickPaintCacheSize.width() - 6,
  999. tickPaintCacheSize.height());
  1000. }
  1001. tickPainter.end();
  1002. }
  1003. // Actual painting of the widget starts here.
  1004. QPainter painter(this);
  1005. // Paint window background color (as widget is opaque)
  1006. QColor background = palette().color(QPalette::ColorRole::Window);
  1007. painter.fillRect(rect, background);
  1008. if (vertical) {
  1009. // Invert the Y axis to ease the math
  1010. painter.translate(0, height);
  1011. painter.scale(1, -1);
  1012. painter.drawPixmap(displayNrAudioChannels * 4 - 1, 7,
  1013. *tickPaintCache);
  1014. } else {
  1015. painter.drawPixmap(0, height - 9, *tickPaintCache);
  1016. }
  1017. for (int channelNr = 0; channelNr < displayNrAudioChannels;
  1018. channelNr++) {
  1019. int channelNrFixed =
  1020. (displayNrAudioChannels == 1 && channels > 2)
  1021. ? 2
  1022. : channelNr;
  1023. if (vertical)
  1024. paintVMeter(painter, channelNr * 4, 8, 3, height - 10,
  1025. displayMagnitude[channelNrFixed],
  1026. displayPeak[channelNrFixed],
  1027. displayPeakHold[channelNrFixed]);
  1028. else
  1029. paintHMeter(painter, 5, channelNr * 4, width - 5, 3,
  1030. displayMagnitude[channelNrFixed],
  1031. displayPeak[channelNrFixed],
  1032. displayPeakHold[channelNrFixed]);
  1033. if (idle)
  1034. continue;
  1035. // By not drawing the input meter boxes the user can
  1036. // see that the audio stream has been stopped, without
  1037. // having too much visual impact.
  1038. if (vertical)
  1039. paintInputMeter(painter, channelNr * 4, 3, 3, 3,
  1040. displayInputPeakHold[channelNrFixed]);
  1041. else
  1042. paintInputMeter(painter, 0, channelNr * 4, 3, 3,
  1043. displayInputPeakHold[channelNrFixed]);
  1044. }
  1045. lastRedrawTime = ts;
  1046. }
  1047. void VolumeMeterTimer::AddVolControl(VolumeMeter *meter)
  1048. {
  1049. volumeMeters.push_back(meter);
  1050. }
  1051. void VolumeMeterTimer::RemoveVolControl(VolumeMeter *meter)
  1052. {
  1053. volumeMeters.removeOne(meter);
  1054. }
  1055. void VolumeMeterTimer::timerEvent(QTimerEvent *)
  1056. {
  1057. for (VolumeMeter *meter : volumeMeters)
  1058. meter->update();
  1059. }