- QJsonObject arg;
- arg.insert("action", "volume");
- arg.insert("value", QJsonValue(value));
- m_client.call("ahl-4a", name, arg, [name](bool r, const QJsonValue& v) {
- if (r && v.isObject())
- {
- // TODO: Success, update the slider
- }
- else
- {
- // TODO: Failed, reset the slider to previous value
- }
- });
+ qDebug() << "Mixer::onClientEventReceived[" << eventName << "]: " << data;
+
+ if (eventName == "audiomixer/controls_changed") {
+ m_client.call("audiomixer", "list_controls", QJsonObject(), [this](bool r, const QJsonValue& v) {
+ if (r && v.isObject()) {
+ parseControls(v.toObject()["response"]);
+ }
+ });
+ }
+ else if (eventName == "audiomixer/volume_changed") {
+ QString name = data.toObject()["control"].toString();
+ int value = static_cast<int>(data.toObject()["value"].toDouble() * 100);
+ value = qBound(0, value, 100);
+
+ for (QObject *o : m_roles) {
+ AudioRole *ar = static_cast<AudioRole*>(o);
+ if (ar->Name() == name) {
+ ar->BeginUpdate();
+ ar->setValue(value);
+ break;
+ }
+ }
+ }
+}
+
+void Mixer::onRoleValueChanged()
+{
+ AudioRole* role = qobject_cast<AudioRole*>(QObject::sender());
+ if (role == nullptr) return;
+
+ /* if the role was not being updated by us, it was modified from the UI,
+ in which case we have to set it to the backend */
+ if (!role->EndUpdate())
+ setRoleVolume(role);