Changeset View
Changeset View
Standalone View
Standalone View
src/streamrestore.cpp
Show All 32 Lines | 31 | { | |||
---|---|---|---|---|---|
33 | memset(&m_channelMap, 0, sizeof(m_channelMap)); | 33 | memset(&m_channelMap, 0, sizeof(m_channelMap)); | ||
34 | 34 | | |||
35 | m_index = index; | 35 | m_index = index; | ||
36 | m_properties = properties; | 36 | m_properties = properties; | ||
37 | } | 37 | } | ||
38 | 38 | | |||
39 | void StreamRestore::update(const pa_ext_stream_restore_info *info) | 39 | void StreamRestore::update(const pa_ext_stream_restore_info *info) | ||
40 | { | 40 | { | ||
41 | m_cache.valid = false; | ||||
41 | const QString infoName = QString::fromUtf8(info->name); | 42 | const QString infoName = QString::fromUtf8(info->name); | ||
42 | if (m_name != infoName) { | 43 | if (m_name != infoName) { | ||
43 | m_name = infoName; | 44 | m_name = infoName; | ||
44 | emit nameChanged(); | 45 | emit nameChanged(); | ||
45 | } | 46 | } | ||
46 | const QString infoDevice = QString::fromUtf8(info->device); | 47 | const QString infoDevice = QString::fromUtf8(info->device); | ||
47 | if (m_device != infoDevice) { | 48 | if (m_device != infoDevice) { | ||
48 | m_device = infoDevice; | 49 | m_device = infoDevice; | ||
Show All 26 Lines | |||||
75 | 76 | | |||
76 | QString StreamRestore::device() const | 77 | QString StreamRestore::device() const | ||
77 | { | 78 | { | ||
78 | return m_device; | 79 | return m_device; | ||
79 | } | 80 | } | ||
80 | 81 | | |||
81 | void StreamRestore::setDevice(const QString &device) | 82 | void StreamRestore::setDevice(const QString &device) | ||
82 | { | 83 | { | ||
84 | if (m_cache.valid) { | ||||
85 | writeChanges(m_cache.volume, m_cache.channelMap, m_cache.muted, device); | ||||
86 | } else { | ||||
83 | writeChanges(m_volume, m_channelMap, m_muted, device); | 87 | writeChanges(m_volume, m_channelMap, m_muted, device); | ||
84 | } | 88 | } | ||
89 | } | ||||
85 | 90 | | |||
86 | qint64 StreamRestore::volume() const | 91 | qint64 StreamRestore::volume() const | ||
87 | { | 92 | { | ||
88 | return m_volume.values[0]; | 93 | return m_volume.values[0]; | ||
89 | } | 94 | } | ||
90 | 95 | | |||
91 | void StreamRestore::setVolume(qint64 volume) | 96 | void StreamRestore::setVolume(qint64 volume) | ||
92 | { | 97 | { | ||
93 | pa_cvolume vol = m_volume; | 98 | pa_cvolume vol = m_cache.valid ? m_cache.volume : m_volume; | ||
94 | for (int i = 0; i < vol.channels; ++i) { | 99 | for (int i = 0; i < vol.channels; ++i) { | ||
95 | vol.values[i] = volume; | 100 | vol.values[i] = volume; | ||
96 | } | 101 | } | ||
102 | | ||||
103 | if (m_cache.valid) { | ||||
104 | writeChanges(vol, m_cache.channelMap, m_cache.muted, m_cache.device); | ||||
105 | } else { | ||||
97 | writeChanges(vol, m_channelMap, m_muted, m_device); | 106 | writeChanges(vol, m_channelMap, m_muted, m_device); | ||
98 | } | 107 | } | ||
108 | } | ||||
99 | 109 | | |||
100 | bool StreamRestore::isMuted() const | 110 | bool StreamRestore::isMuted() const | ||
101 | { | 111 | { | ||
102 | return m_muted; | 112 | return m_muted; | ||
103 | } | 113 | } | ||
104 | 114 | | |||
105 | void StreamRestore::setMuted(bool muted) | 115 | void StreamRestore::setMuted(bool muted) | ||
106 | { | 116 | { | ||
107 | if (m_muted == muted) { | 117 | if (m_cache.valid) { | ||
108 | return; | 118 | writeChanges(m_cache.volume, m_cache.channelMap, muted, m_cache.device); | ||
109 | } | 119 | } else { | ||
110 | | ||||
111 | writeChanges(m_volume, m_channelMap, muted, m_device); | 120 | writeChanges(m_volume, m_channelMap, muted, m_device); | ||
112 | } | 121 | } | ||
122 | } | ||||
113 | 123 | | |||
114 | bool StreamRestore::hasVolume() const | 124 | bool StreamRestore::hasVolume() const | ||
115 | { | 125 | { | ||
116 | return true; | 126 | return true; | ||
117 | } | 127 | } | ||
118 | 128 | | |||
119 | bool StreamRestore::isVolumeWritable() const | 129 | bool StreamRestore::isVolumeWritable() const | ||
120 | { | 130 | { | ||
Show All 13 Lines | 143 | for (int i = 0; i < m_volume.channels; ++i) { | |||
134 | ret << m_volume.values[i]; | 144 | ret << m_volume.values[i]; | ||
135 | } | 145 | } | ||
136 | return ret; | 146 | return ret; | ||
137 | } | 147 | } | ||
138 | 148 | | |||
139 | void StreamRestore::setChannelVolume(int channel, qint64 volume) | 149 | void StreamRestore::setChannelVolume(int channel, qint64 volume) | ||
140 | { | 150 | { | ||
141 | Q_ASSERT(channel >= 0 && channel < m_volume.channels); | 151 | Q_ASSERT(channel >= 0 && channel < m_volume.channels); | ||
142 | pa_cvolume vol = m_volume; | 152 | pa_cvolume vol = m_cache.valid ? m_cache.volume : m_volume; | ||
143 | vol.values[channel] = volume; | 153 | vol.values[channel] = volume; | ||
154 | | ||||
155 | if (m_cache.valid) { | ||||
156 | writeChanges(vol, m_cache.channelMap, m_cache.muted, m_cache.device); | ||||
157 | } else { | ||||
144 | writeChanges(vol, m_channelMap, m_muted, m_device); | 158 | writeChanges(vol, m_channelMap, m_muted, m_device); | ||
145 | } | 159 | } | ||
drosca: You can see here what the problem is, I forgot to add the same logic here (it doesn't use… | |||||
160 | } | ||||
146 | 161 | | |||
147 | quint32 StreamRestore::deviceIndex() const | 162 | quint32 StreamRestore::deviceIndex() const | ||
148 | { | 163 | { | ||
149 | return PA_INVALID_INDEX; | 164 | return PA_INVALID_INDEX; | ||
150 | } | 165 | } | ||
151 | 166 | | |||
152 | void StreamRestore::setDeviceIndex(quint32 deviceIndex) | 167 | void StreamRestore::setDeviceIndex(quint32 deviceIndex) | ||
153 | { | 168 | { | ||
154 | Q_UNUSED(deviceIndex); | 169 | Q_UNUSED(deviceIndex); | ||
155 | qCWarning(PLASMAPA) << "Not implemented"; | 170 | qCWarning(PLASMAPA) << "Not implemented"; | ||
156 | } | 171 | } | ||
157 | 172 | | |||
158 | void StreamRestore::writeChanges(const pa_cvolume &volume, const pa_channel_map &channelMap, bool muted, const QString &device) | 173 | void StreamRestore::writeChanges(const pa_cvolume &volume, const pa_channel_map &channelMap, bool muted, const QString &device) | ||
159 | { | 174 | { | ||
160 | const QByteArray nameData = m_name.toUtf8(); | 175 | const QByteArray nameData = m_name.toUtf8(); | ||
161 | const QByteArray deviceData = device.toUtf8(); | 176 | const QByteArray deviceData = device.toUtf8(); | ||
162 | 177 | | |||
163 | pa_ext_stream_restore_info info; | 178 | pa_ext_stream_restore_info info; | ||
164 | info.name = nameData.constData(); | 179 | info.name = nameData.constData(); | ||
165 | info.channel_map = channelMap; | 180 | info.channel_map = channelMap; | ||
166 | info.volume = volume; | 181 | info.volume = volume; | ||
167 | info.device = deviceData.isEmpty() ? nullptr : deviceData.constData(); | 182 | info.device = deviceData.isEmpty() ? nullptr : deviceData.constData(); | ||
168 | info.mute = muted; | 183 | info.mute = muted; | ||
169 | 184 | | |||
185 | m_cache.valid = true; | ||||
186 | m_cache.volume = volume; | ||||
187 | m_cache.channelMap = channelMap; | ||||
188 | m_cache.muted = muted; | ||||
189 | m_cache.device = device; | ||||
190 | | ||||
170 | context()->streamRestoreWrite(&info); | 191 | context()->streamRestoreWrite(&info); | ||
171 | } | 192 | } | ||
172 | 193 | | |||
173 | } // QPulseAudio | 194 | } // QPulseAudio |
You can see here what the problem is, I forgot to add the same logic here (it doesn't use cache).