2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 #include <efl_assist.h>
19 #include "MicEffector.h"
21 using namespace is::ui;
24 * animation configuration values
27 static size_t start_stop_anim_count = 28;
28 static size_t spectrum_count = SAMPLE_COUNT;
29 static float spectrum_posx = 40.0f;
31 static float timeout_s = 1.0f / 60.0f;
33 #define MATH_PI (3.141592)
35 double cubic_easy_in_out(double index, double start, double end, double duration)
39 return end/2*index*index*index + start;
42 return end/2*(index*index*index + 2) + start;
45 double cubic_easy_in(double index, double start, double end, double duration)
48 return end*index*index*index*index*index + start;
51 double cubic_easy_out(double index, double start, double end, double duration)
55 return end*(index*index*index + 1) + start;
62 * #1. Create ea_vector handle for drawing effect.
63 * ( 1 canvas, 1 paint and 45 paths )
64 * #2. Drawing empty frame to avoid broken screen.
68 MicEffector::MicEffector(Evas_Object *canvas, Evas_Object *layout, IMicEffector& effect)
77 // path = ea_vector_path_create();
78 // paint = ea_vector_paint_create();
79 // ea_vector_paint_set_style(paint, EA_VECTOR_PAINT_STYLE_STROKE);
80 // ea_vector_paint_set_line_cap(paint, EA_VECTOR_PAINT_LINE_CAP_ROUND);
81 // ea_vector_paint_set_line_join(paint, EA_VECTOR_PAINT_LINE_JOIN_ROUND);
82 // ea_vector_paint_set_line_width(paint, 3.0);
83 // ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, 1.0f);
85 // this->canvas = ea_vector_canvas_create(canvas);
95 * #1. Destroy ea_vector handle
98 MicEffector::~MicEffector()
102 ecore_timer_del(timer);
106 // ea_vector_path_destroy(path);
107 // ea_vector_paint_destroy(paint);
108 // ea_vector_canvas_destroy(canvas);
114 * Draw empty frame to remove or initiate screen
117 void MicEffector::DrawDummyFrame()
119 // ea_vector_path_reset(path);
120 // ea_vector_path_move_to(path, 0, 0);
121 // ea_vector_path_line_to(path, 0, 0);
122 // ea_vector_canvas_draw(canvas, path, paint);
130 * In case of start, it shows 2 more dots per one time.
131 * In case of stop, it remove 2 dots per one time.
133 * it works during 22 times.
136 void MicEffector::DrawQue(int idx, bool is_start)
138 float margin = spectrum_posx;
141 double speed = cubic_easy_out(idx + 1.0, 0.0, 23.0, 23);
143 unsigned int start = start_stop_anim_count - (int) speed;
144 unsigned int end = start_stop_anim_count + (int) speed;
149 opacity = cubic_easy_out(idx, 0.0, 1.0, 26.0);
151 opacity = cubic_easy_out(idx, 0, 1.0, 26.0);
154 // ea_vector_path_reset(path);
156 for(unsigned int i = start; i < end; i++)
158 posx = margin + (i * 5);
160 // ea_vector_path_move_to(path, posx, 37.0f);
161 // ea_vector_path_line_to(path, posx, 38.0f);
163 // ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, opacity);
166 // ea_vector_canvas_draw(canvas, path, paint);
171 float MicEffector::GetAmplifyValue(unsigned int idx)
175 int max[SAMPLE_COUNT] = {
183 1, 1, 1, 1, 1, 1, 1, 1, 1,
189 10, 8, 2, 3, 10, 11, 6, 12, 4,
195 3, 5, 9, 12, 11, 8, 14, 15, 13, 11, 12, 6, 8, 3, 2,
198 * reverse dot "B" (9)
201 4, 12, 6, 11, 10, 3, 2, 8, 10,
207 1, 1, 1, 1, 1, 1, 1, 1, 1,
212 amplify = (float) max[idx] / 10.0f * 1.9f;
218 * Draw effect animation
220 * It draws volume effect. during 5 times.
221 * Center of effect area, it applies amplified value.
224 void MicEffector::DrawWave(unsigned int idx, int amount, int prev_amount, double opacity, bool is_lastcmd)
226 float ratio = GetAmplifyValue(idx);
228 float am = ((float) amount) * ratio;
229 float pam = ((float) prev_amount) * ratio;
230 float cnt = (float) drawcount;
232 float posx = spectrum_posx;
234 float height = pam > am?
235 pam - cubic_easy_in_out(cnt + 1.0, am, pam, 7):
236 cubic_easy_in_out(cnt + 1.0, pam, am, 7);
240 // ea_vector_path_move_to(path, posx, (37.0f - (height / 2.0)));
241 // ea_vector_path_line_to(path, posx, (38.0f + (height / 2.0)));
244 // ea_vector_paint_set_color(paint, 0.1451f, 0.204f, 0.255f, opacity);//RGB = 37:52:65
246 // ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, opacity);//RGB: 255 255 255
256 void MicEffector::Start()
259 ecore_timer_del(timer);
268 for(size_t i = 0; i < spectrum_count; i++)
271 current.push_back(0);
280 timer = ecore_timer_add(timeout_s,
281 [](void *data)->Eina_Bool
283 MicEffector *effector = static_cast<MicEffector*>(data);
285 effector->DrawQue(effector->drawcount);
287 if(effector->drawcount < (int) start_stop_anim_count) {
288 effector->drawcount += 2;
289 return ECORE_CALLBACK_RENEW;
291 for(unsigned int i = 0; i < spectrum_count; i++)
292 effector->DrawWave(i, 0, 0);
294 // ea_vector_canvas_draw(effector->canvas, effector->path, effector->paint);
296 effector->drawcount = 0;
297 effector->timer = NULL;
298 effector->VolumeCheck();
300 return ECORE_CALLBACK_CANCEL;
310 void MicEffector::Effect(bool fake)
313 * Volume effect animation
317 ecore_timer_del(timer);
321 timer = ecore_timer_add(timeout_s,
322 [](void *data)->Eina_Bool
324 MicEffector *effector = static_cast<MicEffector *>(data);
326 bool is_empty_prev = effector->prev.empty();
329 // ea_vector_path_reset(effector->path);
331 for(unsigned int i = 0; i < effector->current.size(); i++)
334 effector->DrawWave(i, effector->current.at(i), 0);
336 effector->DrawWave(i, effector->current.at(i), effector->prev.at(i));
338 // ea_vector_canvas_draw(effector->canvas, effector->path, effector->paint);
340 if (effector->drawcount < 7) {
341 effector->drawcount++;
343 effector->drawcount = 0;
344 effector->VolumeCheck(effector->fake);
347 return ECORE_CALLBACK_RENEW;
354 * Stop volume animation effect
357 void MicEffector::Stop(bool forced)
361 ecore_timer_del(timer);
373 timer = ecore_timer_add(timeout_s,
374 [](void *data)->Eina_Bool
376 MicEffector *effector = static_cast<MicEffector*>(data);
378 effector->DrawQue(start_stop_anim_count - effector->drawcount, false);
380 if(effector->drawcount < (int) start_stop_anim_count) {
381 effector->drawcount += 2;
382 return ECORE_CALLBACK_RENEW;
384 if(!effector->forcestop) {
385 effector->Processing();
390 effector->forcestop = false;
391 effector->drawcount = 0;
392 effector->timer = NULL;
393 return ECORE_CALLBACK_CANCEL;
399 * Signal. Refresh volume effect
402 void MicEffector::VolumeCheck(bool fake)
404 std::vector<int> volumes;
409 volumes = ieffect.GetVolume();
411 for(unsigned int i = 0; i < spectrum_count; i++) {
412 volumes.push_back(rand() % 2);
417 prev.assign(current.begin(), current.end());
420 current.assign(volumes.begin(), volumes.end());
426 * Signal. Listening effect
429 void MicEffector::Listening()
433 elm_object_signal_emit(layout, "elm,state,eq,show", "eq");
434 elm_object_signal_emit(layout, "elm,state,listening", "elm");
440 * Signal. Processing effect
443 void MicEffector::Processing()
447 elm_object_signal_emit(layout, "elm,state,eq,hide", "eq");
448 elm_object_signal_emit(layout, "elm,state,processing", "elm");
450 ieffect.ProcessingAnimationStart();
456 * Signal. Idle effect
459 void MicEffector::Idle()
467 elm_object_signal_emit(layout, "elm,state,eq,hide", "eq");
469 text = elm_object_part_text_get(layout, "elm.text");
470 state = edje_object_part_state_get(elm_layout_edje_get(layout), "guide_text_block", &val);
472 if ((text && strlen(text) > 0) && (state && !strcmp(state, "bottom")))
473 elm_object_signal_emit(layout, "elm,state,init_message", "elm");
475 elm_object_signal_emit(layout, "elm,state,init", "elm");
477 ieffect.ProcessingAnimationStop();