85682b8d29b2751fa770dd0fcff007a61b166f34
[platform/core/uifw/inputdelegator.git] / inc / MicEffector.h
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #pragma once
18
19 #include <vector>
20 #include <efl_assist.h>
21
22 #include "Debug.h"
23
24 #define SAMPLE_COUNT 59
25
26 namespace is {  /** name space input selector */
27 namespace ui {  /** name space ui */
28
29 /**
30  * Interface for external controller
31  *
32  */
33 class IMicEffector
34 {
35         public :
36                 virtual ~IMicEffector() = 0;
37                 virtual std::vector<int> GetVolume() = 0;
38                 virtual void ProcessingAnimationStart() = 0;
39                 virtual void ProcessingAnimationStop() = 0;
40 };
41 inline IMicEffector::~IMicEffector() { };
42
43 /**
44  * Effect & Effect Controller
45  *
46  */
47 class MicEffector
48 {
49         public :
50                 MicEffector(Evas_Object *canvas, Evas_Object *layout, IMicEffector& effect);
51                 ~MicEffector();
52
53                 /**
54                  * Start Effect.
55                  *
56                  * It support signaling to edje and start animation.
57                  *
58                  */
59                 void Start();
60
61                 /**
62                  * Equalizer Effect animation.
63                  *
64                  * @param volumes sampled volume values.
65                  * @param fake default false. if it set as true, it works using fixed volume values.
66                  *
67                  */
68                 void Effect(bool fake = false);
69
70                 /**
71                  * Stop Effect.
72                  *
73                  * It support signaling to edje and stop animation.
74                  *
75                  * @param forced default false. if it set as true, it should go idle state without processing.
76                  *
77                  */
78                 void Stop(bool forced = false);
79
80                 /**
81                  * Get volumes via ieffect and refresh equalizer effect.
82                  *
83                  * @param fake default false. if it set as true, it works using fixed volume values.
84                  *
85                  */
86                 void VolumeCheck(bool fake = false);
87
88                 /**
89                  * Draw image to show que animation.
90                  *
91                  * @param idx frame index value
92                  *
93                  */
94                 void DrawQue(int idx, bool is_start=true);
95
96                 /**
97                  * Draw image to show que animation.
98                  *
99                  * @param idx frame index value
100                  * @param amount current volume amount
101                  * @param prev_amount previous volume amount
102                  * @param opacity opacity value for effect
103                  * @param is_lastcmd
104                  *
105                  */
106                 void DrawWave(unsigned int idx, int amount, int prev_amount, double opacity = 1.0f, bool is_lastcmd=false);
107
108                 /**
109                  * Get ratio for tuned volume value.
110                  *
111                  * @param idx volume stick index
112                  * @return ratio for each volume stick
113                  *
114                  */
115                 float GetAmplifyValue(unsigned int idx);
116
117         private :
118                 /**
119                  * Support idle state actions.
120                  *
121                  */
122                 void Idle();
123
124                 /**
125                  * Support listening state actions.
126                  *
127                  */
128                 void Listening();
129
130                 /**
131                  * Support processing state actions.
132                  *
133                  */
134                 void Processing();
135
136                 /**
137                  * Draw dummy frame to avoid broken frame showing.
138                  * It have to be call one time internally.
139                  *
140                  */
141                 void DrawDummyFrame();
142
143                 /**
144                  * Efl vector canvas handle
145                  *
146                  */
147 //              ea_vector_canvas_h *canvas;
148 //              ea_vector_path_h *path;
149 //              ea_vector_paint_h *paint;
150
151                 /**
152                  * Volume values.
153                  *
154                  */
155                 std::vector<int> prev;
156                 std::vector<int> current;
157
158         public :
159                 int startcount;
160                 int drawcount;
161                 bool forcestop;
162                 bool started;
163                 bool fake;
164
165                 /**
166                  * timer handle
167                  *
168                  */
169                 Ecore_Timer *timer;
170
171                 /**
172                  * mic widget layout
173                  *
174                  */
175                 Evas_Object *layout;
176
177                 /**
178                  * interface with app
179                  *
180                  */
181                 IMicEffector& ieffect;
182
183 };
184
185 }} /** end of is::ui */
186