From bc11d604c87c2a04406e0750106e17a5c32f2e27 Mon Sep 17 00:00:00 2001 From: Loïc Collignon Date: Thu, 5 Jul 2018 16:13:31 +0200 Subject: Make volume sliders works correctly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Volume sliders are now binded to the High Level 4a API. Change-Id: I46c4d80a19cf2a9047a502d9faa8bec6f7bd173e Signed-off-by: Loïc Collignon --- app/Mixer.qml | 34 ++++++++++++++++++++++++++++------ app/VolumeSlider.qml | 11 +++-------- app/mixer.cpp | 3 ++- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/app/Mixer.qml b/app/Mixer.qml index 725c2bb..18fae40 100644 --- a/app/Mixer.qml +++ b/app/Mixer.qml @@ -25,12 +25,29 @@ import AGL.Demo.Controls 1.0 import Mixer 1.0 ApplicationWindow { + // ----- Signals + + // ----- Properties property Component volumeSlider + // ----- Setup id: root + // ----- Childs Mixer { + // ----- Signals + signal sliderVolumeChanged(string role, int value) + + // ----- Properties + + // ----- Setup id: mixer + + onSliderVolumeChanged: { + console.log("======role: " + role + ", volume: " + value); + mixer.setVolume(role, value); + } + Component.onCompleted: { root.volumeSlider = Qt.createComponent("VolumeSlider.qml"); if (root.VolumeSlider.status !== Component.Ready) { @@ -38,6 +55,7 @@ ApplicationWindow { } mixer.open(bindingAddress); } + onRolesChanged: { // Remove existing sliders for(var i = sliders.children.length; i > 0 ; --i) { @@ -52,17 +70,21 @@ ApplicationWindow { } onVolumeChanged: { + console.log("onVolumeChanged(\"" + name + "\", " + value + ")"); for(var i = 0; i < sliders.children.length ; i++) { - console.log("Slider found: " + i); - //if (sliders[i].role === name) { - // sliders[i].value = value; - //} + var sld = sliders.children[i]; + console.log(i + " - Slider found:" + sld + "[\"" + sld.role + "\"] = " + sld.value); + if (sld.role === name) { + sld.value = value; + } } } + // ----- Functions function addSlider(name) { - var sld = root.volumeSlider.createObject(sliders); - sld.role = name; + var sld = root.volumeSlider.createObject(sliders) + sld.role = name + sld.onSliderValueChanged.connect(mixer.sliderVolumeChanged) mixer.getVolume(name); // Update volume } diff --git a/app/VolumeSlider.qml b/app/VolumeSlider.qml index 56881b7..130eed4 100644 --- a/app/VolumeSlider.qml +++ b/app/VolumeSlider.qml @@ -4,6 +4,7 @@ import QtQuick.Controls 2.0 RowLayout { property int value property string role + signal sliderValueChanged(string role, int value) onRoleChanged: sliderName.text = role onValueChanged: { @@ -11,7 +12,6 @@ RowLayout { sliderControl.value = value; } - //id: slider_" + name + " Layout.minimumHeight: 75 Label { id: sliderName @@ -21,24 +21,19 @@ RowLayout { } Label { id: sliderValue - //id: slider_" + name + "_textvalue font.pixelSize: 24 text: "0 %" } Slider { id: sliderControl - //id: slider_" + name + "_slider Layout.fillWidth: true from: 0 to: 100 stepSize: 1 snapMode: Slider.SnapOnRelease onValueChanged: { - //slider_" + name + "_textvalue.text = value + \" %\" - //mixer.setVolume(\"" + name + "\", value) + sliderValue.text = value + " %"; + sliderValueChanged(role, value); } - //Component.onCompleted: { - //mixer.getVolume(\"" + name + "\") - //} } } diff --git a/app/mixer.cpp b/app/mixer.cpp index 6a1245c..f231b6d 100644 --- a/app/mixer.cpp +++ b/app/mixer.cpp @@ -82,7 +82,8 @@ void Mixer::getVolume(const QString& name) if (r && v.isObject()) { // TODO: Success, update the slider - int newVolume = v.toObject()["response"].toObject()["volnew"].toInt(); + qDebug() << "Volume changed: " << v; + int newVolume = v.toObject()["response"].toObject()["response"].toObject()["volnew"].toInt(); auto currentVolume = volumes_.find(name); if (currentVolume != volumes_.end() && *currentVolume == newVolume) return; -- cgit 1.2.3-korg