Changeset View
Changeset View
Standalone View
Standalone View
src/streamrestore.cpp
Show First 20 Lines • Show All 77 Lines • ▼ Show 20 Line(s) | |||||
78 | { | 78 | { | ||
79 | return m_device; | 79 | return m_device; | ||
80 | } | 80 | } | ||
81 | 81 | | |||
82 | void StreamRestore::setDevice(const QString &device) | 82 | void StreamRestore::setDevice(const QString &device) | ||
83 | { | 83 | { | ||
84 | if (m_cache.valid) { | 84 | if (m_cache.valid) { | ||
85 | if (m_cache.device != device) { | 85 | if (m_cache.device != device) { | ||
86 | writeChanges(m_cache.volume, m_cache.channelMap, m_cache.muted, device); | 86 | writeChanges(m_cache.volume, m_cache.muted, device); | ||
87 | } | 87 | } | ||
88 | } else { | 88 | } else { | ||
89 | if (m_device != device) { | 89 | if (m_device != device) { | ||
90 | writeChanges(m_volume, m_channelMap, m_muted, device); | 90 | writeChanges(m_volume, m_muted, device); | ||
91 | } | 91 | } | ||
92 | } | 92 | } | ||
93 | } | 93 | } | ||
94 | 94 | | |||
95 | qint64 StreamRestore::volume() const | 95 | qint64 StreamRestore::volume() const | ||
96 | { | 96 | { | ||
97 | return m_volume.values[0]; | 97 | return m_volume.values[0]; | ||
98 | } | 98 | } | ||
99 | 99 | | |||
100 | void StreamRestore::setVolume(qint64 volume) | 100 | void StreamRestore::setVolume(qint64 volume) | ||
101 | { | 101 | { | ||
102 | pa_cvolume vol = m_cache.valid ? m_cache.volume : m_volume; | 102 | pa_cvolume vol = m_cache.valid ? m_cache.volume : m_volume; | ||
103 | for (int i = 0; i < vol.channels; ++i) { | 103 | vol.channels = 1; | ||
104 | vol.values[i] = volume; | 104 | vol.values[0] = volume; | ||
105 | } | | |||
106 | 105 | | |||
107 | if (m_cache.valid) { | 106 | if (m_cache.valid) { | ||
108 | writeChanges(vol, m_cache.channelMap, m_cache.muted, m_cache.device); | 107 | writeChanges(vol, m_cache.muted, m_cache.device); | ||
109 | } else { | 108 | } else { | ||
110 | writeChanges(vol, m_channelMap, m_muted, m_device); | 109 | writeChanges(vol, m_muted, m_device); | ||
111 | } | 110 | } | ||
112 | } | 111 | } | ||
113 | 112 | | |||
114 | bool StreamRestore::isMuted() const | 113 | bool StreamRestore::isMuted() const | ||
115 | { | 114 | { | ||
116 | return m_muted; | 115 | return m_muted; | ||
117 | } | 116 | } | ||
118 | 117 | | |||
119 | void StreamRestore::setMuted(bool muted) | 118 | void StreamRestore::setMuted(bool muted) | ||
120 | { | 119 | { | ||
121 | if (m_cache.valid) { | 120 | if (m_cache.valid) { | ||
122 | if (m_cache.muted != muted) { | 121 | if (m_cache.muted != muted) { | ||
123 | writeChanges(m_cache.volume, m_cache.channelMap, muted, m_cache.device); | 122 | writeChanges(m_cache.volume, muted, m_cache.device); | ||
124 | } | 123 | } | ||
125 | } else { | 124 | } else { | ||
126 | if (m_muted != muted) { | 125 | if (m_muted != muted) { | ||
127 | writeChanges(m_volume, m_channelMap, muted, m_device); | 126 | writeChanges(m_volume, muted, m_device); | ||
128 | } | 127 | } | ||
129 | } | 128 | } | ||
130 | } | 129 | } | ||
131 | 130 | | |||
132 | bool StreamRestore::hasVolume() const | 131 | bool StreamRestore::hasVolume() const | ||
133 | { | 132 | { | ||
134 | return true; | 133 | return true; | ||
135 | } | 134 | } | ||
Show All 20 Lines | |||||
156 | 155 | | |||
157 | void StreamRestore::setChannelVolume(int channel, qint64 volume) | 156 | void StreamRestore::setChannelVolume(int channel, qint64 volume) | ||
158 | { | 157 | { | ||
159 | Q_ASSERT(channel >= 0 && channel < m_volume.channels); | 158 | Q_ASSERT(channel >= 0 && channel < m_volume.channels); | ||
160 | pa_cvolume vol = m_cache.valid ? m_cache.volume : m_volume; | 159 | pa_cvolume vol = m_cache.valid ? m_cache.volume : m_volume; | ||
161 | vol.values[channel] = volume; | 160 | vol.values[channel] = volume; | ||
162 | 161 | | |||
163 | if (m_cache.valid) { | 162 | if (m_cache.valid) { | ||
164 | writeChanges(vol, m_cache.channelMap, m_cache.muted, m_cache.device); | 163 | writeChanges(vol, m_cache.muted, m_cache.device); | ||
165 | } else { | 164 | } else { | ||
166 | writeChanges(vol, m_channelMap, m_muted, m_device); | 165 | writeChanges(vol, m_muted, m_device); | ||
167 | } | 166 | } | ||
168 | } | 167 | } | ||
169 | 168 | | |||
170 | quint32 StreamRestore::deviceIndex() const | 169 | quint32 StreamRestore::deviceIndex() const | ||
171 | { | 170 | { | ||
172 | return PA_INVALID_INDEX; | 171 | return PA_INVALID_INDEX; | ||
173 | } | 172 | } | ||
174 | 173 | | |||
175 | void StreamRestore::setDeviceIndex(quint32 deviceIndex) | 174 | void StreamRestore::setDeviceIndex(quint32 deviceIndex) | ||
176 | { | 175 | { | ||
177 | Q_UNUSED(deviceIndex); | 176 | Q_UNUSED(deviceIndex); | ||
178 | qCWarning(PLASMAPA) << "Not implemented"; | 177 | qCWarning(PLASMAPA) << "Not implemented"; | ||
179 | } | 178 | } | ||
180 | 179 | | |||
181 | void StreamRestore::writeChanges(const pa_cvolume &volume, const pa_channel_map &channelMap, bool muted, const QString &device) | 180 | void StreamRestore::writeChanges(const pa_cvolume &volume, bool muted, const QString &device) | ||
182 | { | 181 | { | ||
183 | const QByteArray nameData = m_name.toUtf8(); | 182 | const QByteArray nameData = m_name.toUtf8(); | ||
184 | const QByteArray deviceData = device.toUtf8(); | 183 | const QByteArray deviceData = device.toUtf8(); | ||
185 | 184 | | |||
186 | pa_ext_stream_restore_info info; | 185 | pa_ext_stream_restore_info info; | ||
187 | info.name = nameData.constData(); | 186 | info.name = nameData.constData(); | ||
188 | info.channel_map = channelMap; | 187 | info.channel_map.channels = 1; | ||
188 | info.channel_map.map[0] = PA_CHANNEL_POSITION_MONO; | ||||
189 | info.volume = volume; | 189 | info.volume = volume; | ||
190 | info.device = deviceData.isEmpty() ? nullptr : deviceData.constData(); | 190 | info.device = deviceData.isEmpty() ? nullptr : deviceData.constData(); | ||
191 | info.mute = muted; | 191 | info.mute = muted; | ||
192 | 192 | | |||
193 | m_cache.valid = true; | 193 | m_cache.valid = true; | ||
194 | m_cache.volume = volume; | 194 | m_cache.volume = volume; | ||
195 | m_cache.channelMap = channelMap; | | |||
196 | m_cache.muted = muted; | 195 | m_cache.muted = muted; | ||
197 | m_cache.device = device; | 196 | m_cache.device = device; | ||
198 | 197 | | |||
199 | context()->streamRestoreWrite(&info); | 198 | context()->streamRestoreWrite(&info); | ||
200 | } | 199 | } | ||
201 | 200 | | |||
202 | } // QPulseAudio | 201 | } // QPulseAudio |