2 * Copyright (C) 2016 The Qt Company Ltd.
3 * Copyright (C) 2016,2017 Konsulko Group
4 * Copyright (C) 2018 IoT.bzh
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
20 #include <QJsonObject>
24 Mixer::Mixer(QObject* parent)
27 connect(&m_client, SIGNAL(connected()), this, SLOT(onClientConnected()));
30 QStringList Mixer::roles() const
35 void Mixer::open(const QUrl &url)
40 void Mixer::onClientConnected()
42 // Call HAL to populate list
43 m_client.call("ahl-4a", "get_roles", QJsonValue(), [this](bool r, const QJsonValue& val) {
47 //BUG: should be able to add this, but not handled right now: m_roles.append("playback");
48 QJsonArray cards = val.toObject()["response"].toArray();
49 foreach (const QJsonValue& card, cards)
51 m_roles.append(card.toString());
52 qDebug() << "Mixer::onClientConnected - added this HAL: " << card.toString();
59 void Mixer::setVolume(const QString& name, int value)
62 arg.insert("action", "volume");
63 arg.insert("value", QJsonValue(value));
64 m_client.call("ahl-4a", name, arg, [name](bool r, const QJsonValue& v) {
65 if (r && v.isObject())
67 // TODO: Success, update the slider
71 // TODO: Failed, reset the slider to previous value
76 void Mixer::getVolume(const QString& name)
79 arg.insert("action", "volume");
80 arg.insert("value", QJsonValue("+0")); // FIXME: Hack to get volume: ask for a relative change with a delta of zero
81 m_client.call("ahl-4a", name, arg, [this, name](bool r, const QJsonValue& v) {
82 if (r && v.isObject())
84 // TODO: Success, update the slider
85 qDebug() << "Volume changed: " << v;
86 int newVolume = v.toObject()["response"].toObject()["response"].toObject()["volnew"].toInt();
87 auto currentVolume = volumes_.find(name);
88 if (currentVolume != volumes_.end() && *currentVolume == newVolume)
91 volumes_[name] = newVolume;
92 emit volumeChanged(name, newVolume);
96 // TODO: Failed, what to do ?