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);
152 opacity = cubic_easy_out(idx, 0, 1.0, 26.0);
155 // ea_vector_path_reset(path);
157 for(unsigned int i = start; i < end; i++)
159 posx = margin + (i * 5);
161 // ea_vector_path_move_to(path, posx, 37.0f);
162 // ea_vector_path_line_to(path, posx, 38.0f);
164 // ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, opacity);
167 // ea_vector_canvas_draw(canvas, path, paint);
172 float MicEffector::GetAmplifyValue(unsigned int idx)
176 int max[SAMPLE_COUNT] = {
184 1, 1, 1, 1, 1, 1, 1, 1, 1,
190 10, 8, 2, 3, 10, 11, 6, 12, 4,
196 3, 5, 9, 12, 11, 8, 14, 15, 13, 11, 12, 6, 8, 3, 2,
199 * reverse dot "B" (9)
202 4, 12, 6, 11, 10, 3, 2, 8, 10,
208 1, 1, 1, 1, 1, 1, 1, 1, 1,
213 amplify = (float) max[idx] / 10.0f * 1.9f;
219 * Draw effect animation
221 * It draws volume effect. during 5 times.
222 * Center of effect area, it applies amplified value.
225 void MicEffector::DrawWave(unsigned int idx, int amount, int prev_amount, double opacity,bool is_lastcmd)
227 float ratio = GetAmplifyValue(idx);
229 float am = ((float) amount) * ratio;
230 float pam = ((float) prev_amount) * ratio;
231 float cnt = (float) drawcount;
233 float posx = spectrum_posx;
235 float height = pam > am?
236 pam - cubic_easy_in_out(cnt + 1.0, am, pam, 7):
237 cubic_easy_in_out(cnt + 1.0, pam, am, 7);
241 // ea_vector_path_move_to(path, posx, (37.0f - (height / 2.0)));
242 // ea_vector_path_line_to(path, posx, (38.0f + (height / 2.0)));
245 // ea_vector_paint_set_color(paint, 0.1451f, 0.204f, 0.255f, opacity);//RGB = 37:52:65
248 // ea_vector_paint_set_color(paint, 1.0f, 1.0f, 1.0f, opacity);//RGB: 255 255 255
258 void MicEffector::Start()
261 ecore_timer_del(timer);
270 for(size_t i = 0; i < spectrum_count; i++)
273 current.push_back(0);
282 timer = ecore_timer_add ( timeout_s,
283 [](void *data)->Eina_Bool
285 MicEffector *effector = static_cast<MicEffector*>(data);
287 effector->DrawQue(effector->drawcount);
289 if(effector->drawcount < (int) start_stop_anim_count)
291 effector->drawcount += 2;
292 return ECORE_CALLBACK_RENEW;
296 for(unsigned int i = 0; i < spectrum_count; i++)
297 effector->DrawWave(i, 0, 0);
299 // ea_vector_canvas_draw(effector->canvas, effector->path, effector->paint);
301 effector->drawcount = 0;
302 effector->timer = NULL;
303 effector->VolumeCheck();
305 return ECORE_CALLBACK_CANCEL;
317 void MicEffector::Effect(bool fake)
320 * Volume effect animation
324 ecore_timer_del(timer);
328 timer = ecore_timer_add ( timeout_s,
329 [](void *data)->Eina_Bool
332 MicEffector *effector = static_cast<MicEffector *>(data);
334 bool is_empty_prev = effector->prev.empty();
337 // ea_vector_path_reset(effector->path);
339 for(unsigned int i = 0; i < effector->current.size(); i++)
342 effector->DrawWave(i, effector->current.at(i), 0);
344 effector->DrawWave(i, effector->current.at(i), effector->prev.at(i));
346 // ea_vector_canvas_draw(effector->canvas, effector->path, effector->paint);
348 if(effector->drawcount < 7) {
349 effector->drawcount++;
352 effector->drawcount = 0;
353 effector->VolumeCheck(effector->fake);
356 return ECORE_CALLBACK_RENEW;
363 * Stop volume animation effect
366 void MicEffector::Stop(bool forced)
370 ecore_timer_del(timer);
382 timer = ecore_timer_add(timeout_s,
383 [](void *data)->Eina_Bool
385 MicEffector *effector = static_cast<MicEffector*>(data);
387 effector->DrawQue(start_stop_anim_count - effector->drawcount, false);
389 if(effector->drawcount < (int) start_stop_anim_count)
391 effector->drawcount += 2;
392 return ECORE_CALLBACK_RENEW;
396 if(!effector->forcestop) {
397 effector->Processing();
403 effector->forcestop = false;
404 effector->drawcount = 0;
405 effector->timer = NULL;
406 return ECORE_CALLBACK_CANCEL;
415 * Signal. Refresh volume effect
418 void MicEffector::VolumeCheck(bool fake)
420 std::vector<int> volumes;
425 volumes = ieffect.GetVolume();
428 for(unsigned int i = 0; i < spectrum_count; i++) {
429 volumes.push_back(rand() % 2);
434 prev.assign(current.begin(), current.end());
437 current.assign(volumes.begin(), volumes.end());
443 * Signal. Listening effect
446 void MicEffector::Listening()
450 elm_object_signal_emit(layout, "elm,state,eq,show", "eq");
451 elm_object_signal_emit(layout, "elm,state,listening", "elm");
457 * Signal. Processing effect
460 void MicEffector::Processing()
464 elm_object_signal_emit(layout, "elm,state,eq,hide", "eq");
465 elm_object_signal_emit(layout, "elm,state,processing", "elm");
467 ieffect.ProcessingAnimationStart();
473 * Signal. Idle effect
476 void MicEffector::Idle()
484 elm_object_signal_emit(layout, "elm,state,eq,hide", "eq");
486 text = elm_object_part_text_get(layout, "elm.text");
487 state = edje_object_part_state_get(elm_layout_edje_get(layout), "guide_text_block", &val);
489 if ((text && strlen(text) > 0) && (state && !strcmp(state, "bottom")))
490 elm_object_signal_emit(layout, "elm,state,init_message", "elm");
492 elm_object_signal_emit(layout, "elm,state,init", "elm");
494 ieffect.ProcessingAnimationStop();