summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKazumasa Mitsunari <knimitz@witz-inc.co.jp>2017-10-23 19:50:33 +0900
committerKazumasa Mitsunari <knimitz@witz-inc.co.jp>2017-10-23 21:55:02 +0900
commit25009f24b154f38628928a363d0b52b2d664c9c5 (patch)
treeed50aa60e433bee8c8db8c5ced7bb7ce0153f8b7
parent4153b3eef4907427a27e318a21f976132ca9da3b (diff)
Adopt statemachine class to manage sound right
It seems better to have statemachine to be simple because app has some state if it works with sound state. sound state is like play, pause, stop, active, inactive and so on. This is same as AAAA I think because AAAA and SoundManager have same concept I add states into this app as following playing ... app has sound right and output sound lostSoundRight ... app lost sound right. The last state is playing temporaryLostSoundRight ... app lost sound right temporarily. The last state is playing haveSoundRight ... app has sound right to output. App can output sound stop ... app doesn't have sound right pause ... app's sound right is temporarily lost Change-Id: I938ed8d9038252deaab2a1e972cb8d76e5401b4b Signed-off-by: Kazumasa Mitsunari <knimitz@witz-inc.co.jp>
-rw-r--r--app/Radio.qml176
-rw-r--r--app/app.pro2
2 files changed, 175 insertions, 3 deletions
diff --git a/app/Radio.qml b/app/Radio.qml
index f812af1..d4f2810 100644
--- a/app/Radio.qml
+++ b/app/Radio.qml
@@ -1,6 +1,7 @@
/*
* Copyright (C) 2016 The Qt Company Ltd.
* Copyright (C) 2017 Konsulko Group
+ * Copyright (C) 2017 Toyota Motor Corporation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -19,6 +20,7 @@ import QtQuick 2.6
import QtQuick.Layouts 1.1
import QtQuick.Controls 2.0
import AGL.Demo.Controls 1.0
+import QtQml.StateMachine 1.0 as RSM
import 'api' as API
ApplicationWindow {
@@ -36,6 +38,169 @@ ApplicationWindow {
slider.value = frequency
}
}
+ property int sourceID
+ property int connectionID
+ signal playRadio
+ signal stopRadio
+ signal disconnected
+ signal paused
+ signal connected
+
+ RSM.StateMachine{
+ id: radioState
+ initialState: stop
+ running: true
+ RSM.State{
+ id: haveSoundRight
+ RSM.SignalTransition{
+ targetState: stop
+ signal: disconnected
+ }
+ RSM.SignalTransition{
+ targetState: pause
+ signal: paused
+ }
+ RSM.SignalTransition{
+ targetState: playing
+ signal: playRadio
+ }
+ onEntered: {
+ console.log("enter haveSoundRight")
+ }
+ onExited : {
+ // Nothing to do
+ }
+ }
+ RSM.State{
+ id: stop
+ RSM.SignalTransition{
+ targetState: haveSoundRight
+ signal: connected
+ }
+ onEntered: {
+ console.log("enter stop state")
+ }
+ onExited : {
+ // Nothing to do
+ }
+ }
+ RSM.State{
+ id: pause
+ RSM.SignalTransition{
+ targetState: haveSoundRight
+ signal: connected
+ }
+ RSM.SignalTransition{
+ targetState: stop
+ signal: disconnected
+ }
+ onEntered: {
+ console.log("enter pause state")
+ }
+ onExited : {
+ // Nothing to do
+ }
+ }
+ RSM.State{
+ id: playing
+ RSM.SignalTransition{
+ targetState: haveSoundRight
+ signal: stopRadio
+ }
+ RSM.SignalTransition{
+ targetState: lostSoundRight
+ signal: disconnected
+ }
+ RSM.SignalTransition{
+ targetState: temporaryLostSoundRight
+ signal: paused
+ }
+ onEntered: {
+ console.log("enter playing state")
+ radio.start()
+ }
+ onExited : {
+ radio.stop()
+ }
+ }
+ RSM.State{
+ id: lostSoundRight
+ RSM.SignalTransition{
+ targetState: playing
+ signal: connected
+ }
+ onEntered: {
+ console.log("enter lostSoundRight")
+ }
+ onExited : {
+ }
+ }
+ RSM.State{
+ id: temporaryLostSoundRight
+ RSM.SignalTransition{
+ targetState: playing
+ signal: connected
+ }
+ RSM.SignalTransition{
+ targetState: lostSoundRight
+ signal: disconnected
+ }
+ onEntered: {
+ console.log("enter temporaryLostSoundRight")
+ }
+ onExited : {
+ }
+ }
+ }
+
+ function slotReply(msg){
+ var jstr = JSON.stringify(msg)
+ var content = JSON.parse(jstr);
+ var verb = content.response.verb
+ var err = content.response.error
+ switch(verb)
+ {
+ case "connect":
+ if(err == 0){
+ connectionID = content.response.mainConnectionID
+ console.log("radio: mainConnectionID is " + connectionID)
+ }
+ break;
+ case "registerSource":
+ if(err == 0){
+ sourceID = content.response.sourceID
+ }
+ default:
+ break;
+ }
+ }
+
+ function slotEvent(event,msg){
+ var jstr = JSON.stringify(msg)
+ var content = JSON.parse(jstr);
+ var eventName = content.event
+ switch(eventName)
+ {
+ case "soundmanager\/asyncSetSourceState":
+ if(sourceID == content.data.sourceID){
+ smw.ackSetSourceState(content.data.handle, 0)
+ switch(content.data.sourceState){
+ case "on":
+ connected()
+ break;
+ case "off":
+ disconnected()
+ break;
+ case "paused":
+ paused()
+ break;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
ColumnLayout {
anchors.fill: parent
@@ -156,14 +321,18 @@ ApplicationWindow {
ImageButton {
id: play
offImage: './images/AGL_MediaPlayer_Player_Play.svg'
- onClicked: radio.start()
+ onClicked: {
+ playRadio()
+ }
states: [
State {
when: radio.state === radio.activeState
PropertyChanges {
target: play
offImage: './images/AGL_MediaPlayer_Player_Pause.svg'
- onClicked: radio.stop()
+ onClicked: {
+ stopRadio()
+ }
}
}
]
@@ -257,5 +426,8 @@ ApplicationWindow {
}
}
}
+ Component.onCompleted: {
+ smw.registerSource("radio")
+ }
}
}
diff --git a/app/app.pro b/app/app.pro
index 093b67b..bbc92a0 100644
--- a/app/app.pro
+++ b/app/app.pro
@@ -1,5 +1,5 @@
TARGET = radio
-QT = quickcontrols2
+QT = quickcontrols2 qml
HEADERS = PresetDataObject.h qlibwindowmanager.h qlibsoundmanager.h
SOURCES = main.cpp PresetDataObject.cpp qlibwindowmanager.cpp qlibsoundmanager.cpp