-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlaybackBlock.cpp
More file actions
112 lines (86 loc) · 3.25 KB
/
Copy pathPlaybackBlock.cpp
File metadata and controls
112 lines (86 loc) · 3.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "PlaybackBlock.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
PlaybackBlock::PlaybackBlock(const PwNodeInfo& info, const QList<PwNodeInfo>& sinks, QWidget* parent)
: QWidget(parent), m_id(info.id), m_info(info)
{
auto* outer = new QVBoxLayout(this);
outer->setContentsMargins(4, 2, 4, 10);
outer->setSpacing(2);
// --- Row 1: Mute button + stream name ---
auto* row1 = new QHBoxLayout();
row1->setSpacing(4);
m_muteBtn = new QPushButton("Mute", this);
m_muteBtn->setFixedSize(48, 22);
m_muteBtn->setStyleSheet("background-color: #994444;");
row1->addWidget(m_muteBtn);
m_nameLabel = new QLabel(info.name, this);
m_nameLabel->setStyleSheet("font-weight: bold;");
row1->addWidget(m_nameLabel, 1);
outer->addLayout(row1);
// --- Row 2: Destination sink selector ---
m_sinkCombo = new QComboBox(this);
m_sinkCombo->setStyleSheet("background-color: #226666;");
outer->addWidget(m_sinkCombo);
// --- Row 3: VU bar — same width as combo box ---
m_vuBar = new VuBar(this);
outer->addWidget(m_vuBar);
updateSinks(sinks);
connect(m_sinkCombo, &QComboBox::activated, this, [this](int index) {
if (index < 0) return;
uint32_t targetId = m_sinkCombo->itemData(index).toUInt();
emit routingChanged(m_info.id, targetId);
});
connect(m_muteBtn, &QPushButton::clicked, this, [this]() {
m_isMuted = !m_isMuted;
m_muteBtn->setText(m_isMuted ? "Unmute" : "Mute");
m_muteBtn->setStyleSheet(m_isMuted ? "background-color: #552222; color: white;" : "");
emit volumeChanged(m_id, m_isMuted ? 0.0f : m_lastVol);
});
}
void PlaybackBlock::updateSinks(const QList<PwNodeInfo>& sinks) {
if (!m_sinkCombo) return;
uint32_t currentId = 0;
if (m_sinkCombo->currentIndex() >= 0)
currentId = m_sinkCombo->itemData(m_sinkCombo->currentIndex()).toUInt();
m_sinkCombo->blockSignals(true);
m_sinkCombo->clear();
for (const auto& sink : sinks) {
m_sinkCombo->addItem(sink.name, sink.id);
if (sink.id == currentId)
m_sinkCombo->setCurrentIndex(m_sinkCombo->count() - 1);
}
if (m_sinkCombo->currentIndex() < 0 && m_sinkCombo->count() > 0)
m_sinkCombo->setCurrentIndex(0);
m_sinkCombo->blockSignals(false);
}
void PlaybackBlock::setCurrentSink(uint32_t sinkId) {
if (!m_sinkCombo) return;
m_sinkCombo->blockSignals(true);
for (int i = 0; i < m_sinkCombo->count(); ++i) {
if (m_sinkCombo->itemData(i).toUInt() == sinkId) {
m_sinkCombo->setCurrentIndex(i);
break;
}
}
m_sinkCombo->blockSignals(false);
}
void PlaybackBlock::setVuLevel(int levelL, int levelR) {
if (m_vuBar)
m_vuBar->setLevels(levelL, levelR);
}
void PlaybackBlock::updateVolume(float volume, bool muted) {
if (!m_nameLabel) return;
if (!m_isMuted && volume > 0.0f)
m_lastVol = volume;
}
void PlaybackBlock::onSliderMoved(int val) {
emit volumeChanged(m_id, val / 100.0f);
}
void PlaybackBlock::onMuteClicked() {
emit muteToggled(m_id, m_muteCheck->isChecked());
}
void PlaybackBlock::onComboChanged(int index) {
if (index >= 0 && index < m_sinkIds.size())
emit routingChanged(m_id, m_sinkIds[index]);
}