1 /**
2 * @file lv_demo_music_main.c
3 *
4 */
5
6 /*********************
7 * INCLUDES
8 *********************/
9 #include "lv_demo_music_main.h"
10 #if LV_USE_DEMO_MUSIC
11
12 #include "lv_demo_music_list.h"
13 #include "assets/spectrum_1.h"
14 #include "assets/spectrum_2.h"
15 #include "assets/spectrum_3.h"
16
17 /*********************
18 * DEFINES
19 *********************/
20 #define ACTIVE_TRACK_CNT 3
21 #define INTRO_TIME 2000
22 #define BAR_COLOR1 lv_color_hex(0xe9dbfc)
23 #define BAR_COLOR2 lv_color_hex(0x6f8af6)
24 #define BAR_COLOR3 lv_color_hex(0xffffff)
25 #if LV_DEMO_MUSIC_LARGE
26 #define BAR_COLOR1_STOP 160
27 #define BAR_COLOR2_STOP 200
28 #else
29 #define BAR_COLOR1_STOP 80
30 #define BAR_COLOR2_STOP 100
31 #endif
32 #define BAR_COLOR3_STOP (2 * LV_HOR_RES / 3)
33 #define BAR_CNT 20
34 #define DEG_STEP (180/BAR_CNT)
35 #define BAND_CNT 4
36 #define BAR_PER_BAND_CNT (BAR_CNT / BAND_CNT)
37
38 /**********************
39 * TYPEDEFS
40 **********************/
41
42 /**********************
43 * STATIC PROTOTYPES
44 **********************/
45 static lv_obj_t * create_cont(lv_obj_t * parent);
46 static void create_wave_images(lv_obj_t * parent);
47 static lv_obj_t * create_title_box(lv_obj_t * parent);
48 static lv_obj_t * create_icon_box(lv_obj_t * parent);
49 static lv_obj_t * create_spectrum_obj(lv_obj_t * parent);
50 static lv_obj_t * create_ctrl_box(lv_obj_t * parent);
51 static lv_obj_t * create_handle(lv_obj_t * parent);
52
53 static void spectrum_anim_cb(void * a, int32_t v);
54 static void start_anim_cb(void * a, int32_t v);
55 static void spectrum_draw_event_cb(lv_event_t * e);
56 static lv_obj_t * album_img_create(lv_obj_t * parent);
57 static void album_gesture_event_cb(lv_event_t * e);
58 static void play_event_click_cb(lv_event_t * e);
59 static void prev_click_event_cb(lv_event_t * e);
60 static void next_click_event_cb(lv_event_t * e);
61 static void timer_cb(lv_timer_t * t);
62 static void track_load(uint32_t id);
63 static void stop_start_anim_timer_cb(lv_timer_t * t);
64 static void spectrum_end_cb(lv_anim_t * a);
65 static void album_fade_anim_cb(void * var, int32_t v);
66 static int32_t get_cos(int32_t deg, int32_t a);
67 static int32_t get_sin(int32_t deg, int32_t a);
68
69 /**********************
70 * STATIC VARIABLES
71 **********************/
72 static lv_obj_t * main_cont;
73 static lv_obj_t * spectrum_obj;
74 static lv_obj_t * title_label;
75 static lv_obj_t * artist_label;
76 static lv_obj_t * genre_label;
77 static lv_obj_t * time_obj;
78 static lv_obj_t * album_img_obj;
79 static lv_obj_t * slider_obj;
80 static uint32_t spectrum_i = 0;
81 static uint32_t spectrum_i_pause = 0;
82 static uint32_t bar_ofs = 0;
83 static uint32_t spectrum_lane_ofs_start = 0;
84 static uint32_t bar_rot = 0;
85 static uint32_t time_act;
86 static lv_timer_t * sec_counter_timer;
87 static lv_timer_t * stop_start_anim_timer;
88 static const lv_font_t * font_small;
89 static const lv_font_t * font_large;
90 static uint32_t track_id;
91 static bool playing;
92 static bool start_anim;
93 static lv_coord_t start_anim_values[40];
94 static lv_obj_t * play_obj;
95 static const uint16_t (* spectrum)[4];
96 static uint32_t spectrum_len;
97 static const uint16_t rnd_array[30] = {994, 285, 553, 11, 792, 707, 966, 641, 852, 827, 44, 352, 146, 581, 490, 80, 729, 58, 695, 940, 724, 561, 124, 653, 27, 292, 557, 506, 382, 199};
98
99 /**********************
100 * MACROS
101 **********************/
102
103 /**********************
104 * GLOBAL FUNCTIONS
105 **********************/
106
107 /*
108 * Callback adapter function to convert parameter types to avoid compile-time
109 * warning.
110 */
_img_set_zoom_anim_cb(void * obj,int32_t zoom)111 static void _img_set_zoom_anim_cb(void * obj, int32_t zoom)
112 {
113 lv_img_set_zoom((lv_obj_t *)obj, (uint16_t)zoom);
114 }
115
116 /*
117 * Callback adapter function to convert parameter types to avoid compile-time
118 * warning.
119 */
_obj_set_x_anim_cb(void * obj,int32_t x)120 static void _obj_set_x_anim_cb(void * obj, int32_t x)
121 {
122 lv_obj_set_x((lv_obj_t *)obj, (lv_coord_t)x);
123 }
124
_lv_demo_music_main_create(lv_obj_t * parent)125 lv_obj_t * _lv_demo_music_main_create(lv_obj_t * parent)
126 {
127 #if LV_DEMO_MUSIC_LARGE
128 font_small = &lv_font_montserrat_22;
129 font_large = &lv_font_montserrat_32;
130 #else
131 font_small = &lv_font_montserrat_12;
132 font_large = &lv_font_montserrat_16;
133 #endif
134
135 /*Create the content of the music player*/
136 lv_obj_t * cont = create_cont(parent);
137 create_wave_images(cont);
138 lv_obj_t * title_box = create_title_box(cont);
139 lv_obj_t * icon_box = create_icon_box(cont);
140 lv_obj_t * ctrl_box = create_ctrl_box(cont);
141 spectrum_obj = create_spectrum_obj(cont);
142 lv_obj_t * handle_box = create_handle(cont);
143
144 #if LV_DEMO_MUSIC_ROUND
145 lv_obj_set_style_pad_hor(cont, LV_HOR_RES / 6, 0);
146 #endif
147
148 /*Arrange the content into a grid*/
149 #if LV_DEMO_MUSIC_SQUARE || LV_DEMO_MUSIC_ROUND
150 static const lv_coord_t grid_cols[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
151 static lv_coord_t grid_rows[] = {LV_DEMO_MUSIC_HANDLE_SIZE, /*Spacing*/
152 0, /*Spectrum obj, set later*/
153 LV_GRID_CONTENT, /*Title box*/
154 LV_GRID_FR(3), /*Spacer*/
155 LV_GRID_CONTENT, /*Icon box*/
156 LV_GRID_FR(3), /*Spacer*/
157 LV_GRID_CONTENT, /*Control box*/
158 LV_GRID_FR(3), /*Spacer*/
159 LV_GRID_CONTENT, /*Handle box*/
160 LV_DEMO_MUSIC_HANDLE_SIZE, /*Spacing*/
161 LV_GRID_TEMPLATE_LAST
162 };
163
164 grid_rows[1] = LV_VER_RES;
165
166 lv_obj_set_grid_dsc_array(cont, grid_cols, grid_rows);
167 lv_obj_set_style_grid_row_align(cont, LV_GRID_ALIGN_SPACE_BETWEEN, 0);
168 lv_obj_set_grid_cell(spectrum_obj, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 1, 1);
169 lv_obj_set_grid_cell(title_box, LV_GRID_ALIGN_STRETCH, 0, 1, LV_ALIGN_CENTER, 2, 1);
170 lv_obj_set_grid_cell(icon_box, LV_GRID_ALIGN_STRETCH, 0, 1, LV_ALIGN_CENTER, 4, 1);
171 lv_obj_set_grid_cell(ctrl_box, LV_GRID_ALIGN_STRETCH, 0, 1, LV_ALIGN_CENTER, 6, 1);
172 lv_obj_set_grid_cell(handle_box, LV_GRID_ALIGN_STRETCH, 0, 1, LV_ALIGN_CENTER, 8, 1);
173 #elif LV_DEMO_MUSIC_LANDSCAPE == 0
174 static const lv_coord_t grid_cols[] = {LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
175 static const lv_coord_t grid_rows[] = {LV_DEMO_MUSIC_HANDLE_SIZE, /*Spacing*/
176 LV_GRID_FR(1), /*Spacer*/
177 LV_GRID_CONTENT, /*Title box*/
178 LV_GRID_FR(3), /*Spacer*/
179 LV_GRID_CONTENT, /*Icon box*/
180 LV_GRID_FR(3), /*Spacer*/
181 # if LV_DEMO_MUSIC_LARGE == 0
182 250, /*Spectrum obj*/
183 # else
184 480, /*Spectrum obj*/
185 # endif
186 LV_GRID_FR(3), /*Spacer*/
187 LV_GRID_CONTENT, /*Control box*/
188 LV_GRID_FR(3), /*Spacer*/
189 LV_GRID_CONTENT, /*Handle box*/
190 LV_GRID_FR(1), /*Spacer*/
191 LV_DEMO_MUSIC_HANDLE_SIZE, /*Spacing*/
192 LV_GRID_TEMPLATE_LAST
193 };
194
195 lv_obj_set_grid_dsc_array(cont, grid_cols, grid_rows);
196 lv_obj_set_style_grid_row_align(cont, LV_GRID_ALIGN_SPACE_BETWEEN, 0);
197 lv_obj_set_grid_cell(title_box, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 2, 1);
198 lv_obj_set_grid_cell(icon_box, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 4, 1);
199 lv_obj_set_grid_cell(spectrum_obj, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 6, 1);
200 lv_obj_set_grid_cell(ctrl_box, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 8, 1);
201 lv_obj_set_grid_cell(handle_box, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 10, 1);
202 #else
203 /*Arrange the content into a grid*/
204 static const lv_coord_t grid_cols[] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_TEMPLATE_LAST};
205 static const lv_coord_t grid_rows[] = {LV_DEMO_MUSIC_HANDLE_SIZE, /*Spacing*/
206 LV_GRID_FR(1), /*Spacer*/
207 LV_GRID_CONTENT, /*Title box*/
208 LV_GRID_FR(1), /*Spacer*/
209 LV_GRID_CONTENT, /*Icon box*/
210 LV_GRID_FR(3), /*Spacer*/
211 LV_GRID_CONTENT, /*Control box*/
212 LV_GRID_FR(1), /*Spacer*/
213 LV_GRID_CONTENT, /*Handle box*/
214 LV_GRID_FR(1), /*Spacer*/
215 LV_DEMO_MUSIC_HANDLE_SIZE, /*Spacing*/
216 LV_GRID_TEMPLATE_LAST
217 };
218
219 lv_obj_set_grid_dsc_array(cont, grid_cols, grid_rows);
220 lv_obj_set_style_grid_row_align(cont, LV_GRID_ALIGN_SPACE_BETWEEN, 0);
221 lv_obj_set_grid_cell(title_box, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 2, 1);
222 lv_obj_set_grid_cell(icon_box, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 4, 1);
223 lv_obj_set_grid_cell(ctrl_box, LV_GRID_ALIGN_STRETCH, 0, 1, LV_GRID_ALIGN_CENTER, 6, 1);
224 lv_obj_set_grid_cell(handle_box, LV_GRID_ALIGN_STRETCH, 0, 2, LV_GRID_ALIGN_CENTER, 8, 1);
225 lv_obj_set_grid_cell(spectrum_obj, LV_GRID_ALIGN_STRETCH, 1, 1, LV_GRID_ALIGN_CENTER, 1, 9);
226 #endif
227
228 sec_counter_timer = lv_timer_create(timer_cb, 1000, NULL);
229 lv_timer_pause(sec_counter_timer);
230
231 /*Animate in the content after the intro time*/
232 lv_anim_t a;
233
234 start_anim = true;
235
236 stop_start_anim_timer = lv_timer_create(stop_start_anim_timer_cb, INTRO_TIME + 6000, NULL);
237 lv_timer_set_repeat_count(stop_start_anim_timer, 1);
238
239 lv_anim_init(&a);
240 lv_anim_set_path_cb(&a, lv_anim_path_bounce);
241
242 uint32_t i;
243 lv_anim_set_exec_cb(&a, start_anim_cb);
244 for(i = 0; i < BAR_CNT; i++) {
245 lv_anim_set_values(&a, LV_HOR_RES, 5);
246 lv_anim_set_delay(&a, INTRO_TIME - 200 + rnd_array[i] % 200);
247 lv_anim_set_time(&a, 2500 + rnd_array[i] % 500);
248 lv_anim_set_var(&a, &start_anim_values[i]);
249 lv_anim_start(&a);
250 }
251
252 lv_obj_fade_in(title_box, 1000, INTRO_TIME + 1000);
253 lv_obj_fade_in(icon_box, 1000, INTRO_TIME + 1000);
254 lv_obj_fade_in(ctrl_box, 1000, INTRO_TIME + 1000);
255 lv_obj_fade_in(handle_box, 1000, INTRO_TIME + 1000);
256 lv_obj_fade_in(album_img_obj, 800, INTRO_TIME + 1000);
257 lv_obj_fade_in(spectrum_obj, 0, INTRO_TIME);
258
259 lv_anim_set_path_cb(&a, lv_anim_path_ease_out);
260 lv_anim_set_var(&a, album_img_obj);
261 lv_anim_set_time(&a, 1000);
262 lv_anim_set_delay(&a, INTRO_TIME + 1000);
263 lv_anim_set_values(&a, 1, LV_IMG_ZOOM_NONE);
264 lv_anim_set_exec_cb(&a, _img_set_zoom_anim_cb);
265 lv_anim_set_ready_cb(&a, NULL);
266 lv_anim_start(&a);
267
268 /* Create an intro from a logo + label */
269 LV_IMG_DECLARE(img_lv_demo_music_logo);
270 lv_obj_t * logo = lv_img_create(lv_scr_act());
271 lv_img_set_src(logo, &img_lv_demo_music_logo);
272 lv_obj_move_foreground(logo);
273
274 lv_obj_t * title = lv_label_create(lv_scr_act());
275 lv_label_set_text(title, "LVGL Demo\nMusic player");
276 lv_obj_set_style_text_align(title, LV_TEXT_ALIGN_CENTER, 0);
277 lv_obj_set_style_text_font(title, font_large, 0);
278 lv_obj_set_style_text_line_space(title, 8, 0);
279 lv_obj_fade_out(title, 500, INTRO_TIME);
280 lv_obj_align_to(logo, spectrum_obj, LV_ALIGN_CENTER, 0, 0);
281 lv_obj_align_to(title, logo, LV_ALIGN_OUT_LEFT_MID, -20, 0);
282
283 lv_anim_set_path_cb(&a, lv_anim_path_ease_in);
284 lv_anim_set_var(&a, logo);
285 lv_anim_set_time(&a, 400);
286 lv_anim_set_delay(&a, INTRO_TIME + 800);
287 lv_anim_set_values(&a, LV_IMG_ZOOM_NONE, 10);
288 lv_anim_set_ready_cb(&a, lv_obj_del_anim_ready_cb);
289 lv_anim_start(&a);
290
291 lv_obj_update_layout(main_cont);
292
293 return main_cont;
294 }
295
_lv_demo_music_main_close(void)296 void _lv_demo_music_main_close(void)
297 {
298 if(stop_start_anim_timer) lv_timer_del(stop_start_anim_timer);
299 lv_timer_del(sec_counter_timer);
300 }
301
_lv_demo_music_album_next(bool next)302 void _lv_demo_music_album_next(bool next)
303 {
304 uint32_t id = track_id;
305 if(next) {
306 id++;
307 if(id >= ACTIVE_TRACK_CNT) id = 0;
308 }
309 else {
310 if(id == 0) {
311 id = ACTIVE_TRACK_CNT - 1;
312 }
313 else {
314 id--;
315 }
316 }
317
318 if(playing) {
319 _lv_demo_music_play(id);
320 }
321 else {
322 track_load(id);
323 }
324 }
325
_lv_demo_music_play(uint32_t id)326 void _lv_demo_music_play(uint32_t id)
327 {
328 track_load(id);
329
330 _lv_demo_music_resume();
331 }
332
_lv_demo_music_resume(void)333 void _lv_demo_music_resume(void)
334 {
335 playing = true;
336 spectrum_i = spectrum_i_pause;
337 lv_anim_t a;
338 lv_anim_init(&a);
339 lv_anim_set_values(&a, spectrum_i, spectrum_len - 1);
340 lv_anim_set_exec_cb(&a, spectrum_anim_cb);
341 lv_anim_set_var(&a, spectrum_obj);
342 lv_anim_set_time(&a, ((spectrum_len - spectrum_i) * 1000) / 30);
343 lv_anim_set_playback_time(&a, 0);
344 lv_anim_set_ready_cb(&a, spectrum_end_cb);
345 lv_anim_start(&a);
346
347 lv_timer_resume(sec_counter_timer);
348 lv_slider_set_range(slider_obj, 0, _lv_demo_music_get_track_length(track_id));
349
350 lv_obj_add_state(play_obj, LV_STATE_CHECKED);
351
352 }
353
_lv_demo_music_pause(void)354 void _lv_demo_music_pause(void)
355 {
356 playing = false;
357 spectrum_i_pause = spectrum_i;
358 spectrum_i = 0;
359 lv_anim_del(spectrum_obj, spectrum_anim_cb);
360 lv_obj_invalidate(spectrum_obj);
361 lv_img_set_zoom(album_img_obj, LV_IMG_ZOOM_NONE);
362 lv_timer_pause(sec_counter_timer);
363 lv_obj_clear_state(play_obj, LV_STATE_CHECKED);
364 }
365
366 /**********************
367 * STATIC FUNCTIONS
368 **********************/
369
create_cont(lv_obj_t * parent)370 static lv_obj_t * create_cont(lv_obj_t * parent)
371 {
372 /*A transparent container in which the player section will be scrolled*/
373 main_cont = lv_obj_create(parent);
374 lv_obj_clear_flag(main_cont, LV_OBJ_FLAG_CLICKABLE);
375 lv_obj_clear_flag(main_cont, LV_OBJ_FLAG_SCROLL_ELASTIC);
376 lv_obj_remove_style_all(main_cont); /*Make it transparent*/
377 lv_obj_set_size(main_cont, lv_pct(100), lv_pct(100));
378 lv_obj_set_scroll_snap_y(main_cont, LV_SCROLL_SNAP_CENTER); /*Snap the children to the center*/
379
380 /*Create a container for the player*/
381 lv_obj_t * player = lv_obj_create(main_cont);
382 lv_obj_set_y(player, - LV_DEMO_MUSIC_HANDLE_SIZE);
383 #if LV_DEMO_MUSIC_SQUARE || LV_DEMO_MUSIC_ROUND
384 lv_obj_set_size(player, LV_HOR_RES, 2 * LV_VER_RES + LV_DEMO_MUSIC_HANDLE_SIZE * 2);
385 #else
386 lv_obj_set_size(player, LV_HOR_RES, LV_VER_RES + LV_DEMO_MUSIC_HANDLE_SIZE * 2);
387 #endif
388 lv_obj_clear_flag(player, LV_OBJ_FLAG_SNAPABLE);
389
390 lv_obj_set_style_bg_color(player, lv_color_hex(0xffffff), 0);
391 lv_obj_set_style_border_width(player, 0, 0);
392 lv_obj_set_style_pad_all(player, 0, 0);
393 lv_obj_set_scroll_dir(player, LV_DIR_VER);
394
395 /* Transparent placeholders below the player container
396 * It is used only to snap it to center.*/
397 lv_obj_t * placeholder1 = lv_obj_create(main_cont);
398 lv_obj_remove_style_all(placeholder1);
399 lv_obj_clear_flag(placeholder1, LV_OBJ_FLAG_CLICKABLE);
400 // lv_obj_set_style_bg_color(placeholder1, lv_color_hex(0xff0000), 0);
401 // lv_obj_set_style_bg_opa(placeholder1, LV_OPA_50, 0);
402
403 lv_obj_t * placeholder2 = lv_obj_create(main_cont);
404 lv_obj_remove_style_all(placeholder2);
405 lv_obj_clear_flag(placeholder2, LV_OBJ_FLAG_CLICKABLE);
406 // lv_obj_set_style_bg_color(placeholder2, lv_color_hex(0x00ff00), 0);
407 // lv_obj_set_style_bg_opa(placeholder2, LV_OPA_50, 0);
408
409 #if LV_DEMO_MUSIC_SQUARE || LV_DEMO_MUSIC_ROUND
410 lv_obj_t * placeholder3 = lv_obj_create(main_cont);
411 lv_obj_remove_style_all(placeholder3);
412 lv_obj_clear_flag(placeholder3, LV_OBJ_FLAG_CLICKABLE);
413 // lv_obj_set_style_bg_color(placeholder3, lv_color_hex(0x0000ff), 0);
414 // lv_obj_set_style_bg_opa(placeholder3, LV_OPA_20, 0);
415
416 lv_obj_set_size(placeholder1, lv_pct(100), LV_VER_RES);
417 lv_obj_set_y(placeholder1, 0);
418
419 lv_obj_set_size(placeholder2, lv_pct(100), LV_VER_RES);
420 lv_obj_set_y(placeholder2, LV_VER_RES);
421
422 lv_obj_set_size(placeholder3, lv_pct(100), LV_VER_RES - 2 * LV_DEMO_MUSIC_HANDLE_SIZE);
423 lv_obj_set_y(placeholder3, 2 * LV_VER_RES + LV_DEMO_MUSIC_HANDLE_SIZE);
424 #else
425 lv_obj_set_size(placeholder1, lv_pct(100), LV_VER_RES);
426 lv_obj_set_y(placeholder1, 0);
427
428 lv_obj_set_size(placeholder2, lv_pct(100), LV_VER_RES - 2 * LV_DEMO_MUSIC_HANDLE_SIZE);
429 lv_obj_set_y(placeholder2, LV_VER_RES + LV_DEMO_MUSIC_HANDLE_SIZE);
430 #endif
431
432 lv_obj_update_layout(main_cont);
433
434 return player;
435 }
436
create_wave_images(lv_obj_t * parent)437 static void create_wave_images(lv_obj_t * parent)
438 {
439 LV_IMG_DECLARE(img_lv_demo_music_wave_top);
440 LV_IMG_DECLARE(img_lv_demo_music_wave_bottom);
441 lv_obj_t * wave_top = lv_img_create(parent);
442 lv_img_set_src(wave_top, &img_lv_demo_music_wave_top);
443 lv_obj_set_width(wave_top, LV_HOR_RES);
444 lv_obj_align(wave_top, LV_ALIGN_TOP_MID, 0, 0);
445 lv_obj_add_flag(wave_top, LV_OBJ_FLAG_IGNORE_LAYOUT);
446
447 lv_obj_t * wave_bottom = lv_img_create(parent);
448 lv_img_set_src(wave_bottom, &img_lv_demo_music_wave_bottom);
449 lv_obj_set_width(wave_bottom, LV_HOR_RES);
450 lv_obj_align(wave_bottom, LV_ALIGN_BOTTOM_MID, 0, 0);
451 lv_obj_add_flag(wave_bottom, LV_OBJ_FLAG_IGNORE_LAYOUT);
452
453 LV_IMG_DECLARE(img_lv_demo_music_corner_left);
454 LV_IMG_DECLARE(img_lv_demo_music_corner_right);
455 lv_obj_t * wave_corner = lv_img_create(parent);
456 lv_img_set_src(wave_corner, &img_lv_demo_music_corner_left);
457 #if LV_DEMO_MUSIC_ROUND == 0
458 lv_obj_align(wave_corner, LV_ALIGN_BOTTOM_LEFT, 0, 0);
459 #else
460 lv_obj_align(wave_corner, LV_ALIGN_BOTTOM_LEFT, -LV_HOR_RES / 6, 0);
461 #endif
462 lv_obj_add_flag(wave_corner, LV_OBJ_FLAG_IGNORE_LAYOUT);
463
464 wave_corner = lv_img_create(parent);
465 lv_img_set_src(wave_corner, &img_lv_demo_music_corner_right);
466 #if LV_DEMO_MUSIC_ROUND == 0
467 lv_obj_align(wave_corner, LV_ALIGN_BOTTOM_RIGHT, 0, 0);
468 #else
469 lv_obj_align(wave_corner, LV_ALIGN_BOTTOM_RIGHT, LV_HOR_RES / 6, 0);
470 #endif
471 lv_obj_add_flag(wave_corner, LV_OBJ_FLAG_IGNORE_LAYOUT);
472 }
473
create_title_box(lv_obj_t * parent)474 static lv_obj_t * create_title_box(lv_obj_t * parent)
475 {
476
477 /*Create the titles*/
478 lv_obj_t * cont = lv_obj_create(parent);
479 lv_obj_remove_style_all(cont);
480 lv_obj_set_height(cont, LV_SIZE_CONTENT);
481 lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
482 lv_obj_set_flex_align(cont, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
483
484 title_label = lv_label_create(cont);
485 lv_obj_set_style_text_font(title_label, font_large, 0);
486 lv_obj_set_style_text_color(title_label, lv_color_hex(0x504d6d), 0);
487 lv_label_set_text(title_label, _lv_demo_music_get_title(track_id));
488 lv_obj_set_height(title_label, lv_font_get_line_height(font_large) * 3 / 2);
489
490 artist_label = lv_label_create(cont);
491 lv_obj_set_style_text_font(artist_label, font_small, 0);
492 lv_obj_set_style_text_color(artist_label, lv_color_hex(0x504d6d), 0);
493 lv_label_set_text(artist_label, _lv_demo_music_get_artist(track_id));
494
495 genre_label = lv_label_create(cont);
496 lv_obj_set_style_text_font(genre_label, font_small, 0);
497 lv_obj_set_style_text_color(genre_label, lv_color_hex(0x8a86b8), 0);
498 lv_label_set_text(genre_label, _lv_demo_music_get_genre(track_id));
499
500 return cont;
501 }
502
create_icon_box(lv_obj_t * parent)503 static lv_obj_t * create_icon_box(lv_obj_t * parent)
504 {
505
506 lv_obj_t * cont = lv_obj_create(parent);
507 lv_obj_remove_style_all(cont);
508 lv_obj_set_height(cont, LV_SIZE_CONTENT);
509 lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW);
510 lv_obj_set_flex_align(cont, LV_FLEX_ALIGN_SPACE_EVENLY, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
511
512 lv_obj_t * icon;
513 LV_IMG_DECLARE(img_lv_demo_music_icon_1);
514 LV_IMG_DECLARE(img_lv_demo_music_icon_2);
515 LV_IMG_DECLARE(img_lv_demo_music_icon_3);
516 LV_IMG_DECLARE(img_lv_demo_music_icon_4);
517 icon = lv_img_create(cont);
518 lv_img_set_src(icon, &img_lv_demo_music_icon_1);
519 icon = lv_img_create(cont);
520 lv_img_set_src(icon, &img_lv_demo_music_icon_2);
521 icon = lv_img_create(cont);
522 lv_img_set_src(icon, &img_lv_demo_music_icon_3);
523 icon = lv_img_create(cont);
524 lv_img_set_src(icon, &img_lv_demo_music_icon_4);
525
526 return cont;
527 }
528
create_spectrum_obj(lv_obj_t * parent)529 static lv_obj_t * create_spectrum_obj(lv_obj_t * parent)
530 {
531 /*Create the spectrum visualizer*/
532 lv_obj_t * obj = lv_obj_create(parent);
533 lv_obj_remove_style_all(obj);
534 #if LV_DEMO_MUSIC_LARGE
535 lv_obj_set_height(obj, 500);
536 #else
537 lv_obj_set_height(obj, 250);
538 #endif
539 lv_obj_clear_flag(obj, LV_OBJ_FLAG_CLICKABLE | LV_OBJ_FLAG_SCROLLABLE);
540 lv_obj_add_event_cb(obj, spectrum_draw_event_cb, LV_EVENT_ALL, NULL);
541 lv_obj_refresh_ext_draw_size(obj);
542 album_img_obj = album_img_create(obj);
543 return obj;
544 }
545
create_ctrl_box(lv_obj_t * parent)546 static lv_obj_t * create_ctrl_box(lv_obj_t * parent)
547 {
548 /*Create the control box*/
549 lv_obj_t * cont = lv_obj_create(parent);
550 lv_obj_remove_style_all(cont);
551 lv_obj_set_height(cont, LV_SIZE_CONTENT);
552 #if LV_DEMO_MUSIC_LARGE
553 lv_obj_set_style_pad_bottom(cont, 17, 0);
554 #else
555 lv_obj_set_style_pad_bottom(cont, 8, 0);
556 #endif
557 static const lv_coord_t grid_col[] = {LV_GRID_FR(2), LV_GRID_FR(3), LV_GRID_FR(5), LV_GRID_FR(5), LV_GRID_FR(5), LV_GRID_FR(3), LV_GRID_FR(2), LV_GRID_TEMPLATE_LAST};
558 static const lv_coord_t grid_row[] = {LV_GRID_CONTENT, LV_GRID_CONTENT, LV_GRID_TEMPLATE_LAST};
559 lv_obj_set_grid_dsc_array(cont, grid_col, grid_row);
560
561 LV_IMG_DECLARE(img_lv_demo_music_btn_loop);
562 LV_IMG_DECLARE(img_lv_demo_music_btn_rnd);
563 LV_IMG_DECLARE(img_lv_demo_music_btn_next);
564 LV_IMG_DECLARE(img_lv_demo_music_btn_prev);
565 LV_IMG_DECLARE(img_lv_demo_music_btn_play);
566 LV_IMG_DECLARE(img_lv_demo_music_btn_pause);
567
568 lv_obj_t * icon;
569 icon = lv_img_create(cont);
570 lv_img_set_src(icon, &img_lv_demo_music_btn_rnd);
571 lv_obj_set_grid_cell(icon, LV_GRID_ALIGN_START, 1, 1, LV_GRID_ALIGN_CENTER, 0, 1);
572
573 icon = lv_img_create(cont);
574 lv_img_set_src(icon, &img_lv_demo_music_btn_loop);
575 lv_obj_set_grid_cell(icon, LV_GRID_ALIGN_END, 5, 1, LV_GRID_ALIGN_CENTER, 0, 1);
576
577 icon = lv_img_create(cont);
578 lv_img_set_src(icon, &img_lv_demo_music_btn_prev);
579 lv_obj_set_grid_cell(icon, LV_GRID_ALIGN_CENTER, 2, 1, LV_GRID_ALIGN_CENTER, 0, 1);
580 lv_obj_add_event_cb(icon, prev_click_event_cb, LV_EVENT_CLICKED, NULL);
581
582 play_obj = lv_imgbtn_create(cont);
583 lv_imgbtn_set_src(play_obj, LV_IMGBTN_STATE_RELEASED, NULL, &img_lv_demo_music_btn_play, NULL);
584 lv_imgbtn_set_src(play_obj, LV_IMGBTN_STATE_CHECKED_RELEASED, NULL, &img_lv_demo_music_btn_pause, NULL);
585 lv_obj_add_flag(play_obj, LV_OBJ_FLAG_CHECKABLE);
586 lv_obj_set_grid_cell(play_obj, LV_GRID_ALIGN_CENTER, 3, 1, LV_GRID_ALIGN_CENTER, 0, 1);
587
588 lv_obj_add_event_cb(play_obj, play_event_click_cb, LV_EVENT_CLICKED, NULL);
589 lv_obj_add_flag(play_obj, LV_OBJ_FLAG_CLICKABLE);
590 lv_obj_set_width(play_obj, img_lv_demo_music_btn_play.header.w);
591
592 icon = lv_img_create(cont);
593 lv_img_set_src(icon, &img_lv_demo_music_btn_next);
594 lv_obj_set_grid_cell(icon, LV_GRID_ALIGN_CENTER, 4, 1, LV_GRID_ALIGN_CENTER, 0, 1);
595 lv_obj_add_event_cb(icon, next_click_event_cb, LV_EVENT_CLICKED, NULL);
596 lv_obj_add_flag(icon, LV_OBJ_FLAG_CLICKABLE);
597
598 LV_IMG_DECLARE(img_lv_demo_music_slider_knob);
599 slider_obj = lv_slider_create(cont);
600 lv_obj_set_style_anim_time(slider_obj, 100, 0);
601 lv_obj_add_flag(slider_obj, LV_OBJ_FLAG_CLICKABLE); /*No input from the slider*/
602
603 #if LV_DEMO_MUSIC_LARGE == 0
604 lv_obj_set_height(slider_obj, 3);
605 #else
606 lv_obj_set_height(slider_obj, 6);
607 #endif
608 lv_obj_set_grid_cell(slider_obj, LV_GRID_ALIGN_STRETCH, 1, 4, LV_GRID_ALIGN_CENTER, 1, 1);
609
610 lv_obj_set_style_bg_img_src(slider_obj, &img_lv_demo_music_slider_knob, LV_PART_KNOB);
611 lv_obj_set_style_bg_opa(slider_obj, LV_OPA_TRANSP, LV_PART_KNOB);
612 lv_obj_set_style_pad_all(slider_obj, 20, LV_PART_KNOB);
613 lv_obj_set_style_bg_grad_dir(slider_obj, LV_GRAD_DIR_HOR, LV_PART_INDICATOR);
614 lv_obj_set_style_bg_color(slider_obj, lv_color_hex(0x569af8), LV_PART_INDICATOR);
615 lv_obj_set_style_bg_grad_color(slider_obj, lv_color_hex(0xa666f1), LV_PART_INDICATOR);
616 lv_obj_set_style_outline_width(slider_obj, 0, 0);
617
618 time_obj = lv_label_create(cont);
619 lv_obj_set_style_text_font(time_obj, font_small, 0);
620 lv_obj_set_style_text_color(time_obj, lv_color_hex(0x8a86b8), 0);
621 lv_label_set_text(time_obj, "0:00");
622 lv_obj_set_grid_cell(time_obj, LV_GRID_ALIGN_END, 5, 1, LV_GRID_ALIGN_CENTER, 1, 1);
623
624 return cont;
625 }
626
create_handle(lv_obj_t * parent)627 static lv_obj_t * create_handle(lv_obj_t * parent)
628 {
629 lv_obj_t * cont = lv_obj_create(parent);
630 lv_obj_remove_style_all(cont);
631
632 lv_obj_set_size(cont, lv_pct(100), LV_SIZE_CONTENT);
633 lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
634 lv_obj_set_flex_align(cont, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
635 lv_obj_set_style_pad_row(cont, 8, 0);
636
637 /*A handle to scroll to the track list*/
638 lv_obj_t * handle_label = lv_label_create(cont);
639 lv_label_set_text(handle_label, "ALL TRACKS");
640 lv_obj_set_style_text_font(handle_label, font_small, 0);
641 lv_obj_set_style_text_color(handle_label, lv_color_hex(0x8a86b8), 0);
642
643 lv_obj_t * handle_rect = lv_obj_create(cont);
644 #if LV_DEMO_MUSIC_LARGE
645 lv_obj_set_size(handle_rect, 40, 3);
646 #else
647 lv_obj_set_size(handle_rect, 20, 2);
648 #endif
649
650 lv_obj_set_style_bg_color(handle_rect, lv_color_hex(0x8a86b8), 0);
651 lv_obj_set_style_border_width(handle_rect, 0, 0);
652
653 return cont;
654 }
655
track_load(uint32_t id)656 static void track_load(uint32_t id)
657 {
658 spectrum_i = 0;
659 time_act = 0;
660 spectrum_i_pause = 0;
661 lv_slider_set_value(slider_obj, 0, LV_ANIM_OFF);
662 lv_label_set_text(time_obj, "0:00");
663
664 if(id == track_id) return;
665 bool next = false;
666 if((track_id + 1) % ACTIVE_TRACK_CNT == id) next = true;
667
668 _lv_demo_music_list_btn_check(track_id, false);
669
670 track_id = id;
671
672 _lv_demo_music_list_btn_check(id, true);
673
674 lv_label_set_text(title_label, _lv_demo_music_get_title(track_id));
675 lv_label_set_text(artist_label, _lv_demo_music_get_artist(track_id));
676 lv_label_set_text(genre_label, _lv_demo_music_get_genre(track_id));
677
678 lv_anim_t a;
679 lv_anim_init(&a);
680 lv_anim_set_var(&a, album_img_obj);
681 lv_anim_set_values(&a, lv_obj_get_style_img_opa(album_img_obj, 0), LV_OPA_TRANSP);
682 lv_anim_set_exec_cb(&a, album_fade_anim_cb);
683 lv_anim_set_time(&a, 500);
684 lv_anim_start(&a);
685
686 lv_anim_init(&a);
687 lv_anim_set_var(&a, album_img_obj);
688 lv_anim_set_time(&a, 500);
689 lv_anim_set_path_cb(&a, lv_anim_path_ease_out);
690 #if LV_DEMO_MUSIC_LANDSCAPE
691 if(next) {
692 lv_anim_set_values(&a, 0, - LV_HOR_RES / 7);
693 }
694 else {
695 lv_anim_set_values(&a, 0, LV_HOR_RES / 7);
696 }
697 #else
698 if(next) {
699 lv_anim_set_values(&a, 0, - LV_HOR_RES / 2);
700 }
701 else {
702 lv_anim_set_values(&a, 0, LV_HOR_RES / 2);
703 }
704 #endif
705 lv_anim_set_exec_cb(&a, _obj_set_x_anim_cb);
706 lv_anim_set_ready_cb(&a, lv_obj_del_anim_ready_cb);
707 lv_anim_start(&a);
708
709 lv_anim_set_path_cb(&a, lv_anim_path_linear);
710 lv_anim_set_var(&a, album_img_obj);
711 lv_anim_set_time(&a, 500);
712 lv_anim_set_values(&a, LV_IMG_ZOOM_NONE, LV_IMG_ZOOM_NONE / 2);
713 lv_anim_set_exec_cb(&a, _img_set_zoom_anim_cb);
714 lv_anim_set_ready_cb(&a, NULL);
715 lv_anim_start(&a);
716
717 album_img_obj = album_img_create(spectrum_obj);
718
719 lv_anim_set_path_cb(&a, lv_anim_path_overshoot);
720 lv_anim_set_var(&a, album_img_obj);
721 lv_anim_set_time(&a, 500);
722 lv_anim_set_delay(&a, 100);
723 lv_anim_set_values(&a, LV_IMG_ZOOM_NONE / 4, LV_IMG_ZOOM_NONE);
724 lv_anim_set_exec_cb(&a, _img_set_zoom_anim_cb);
725 lv_anim_set_ready_cb(&a, NULL);
726 lv_anim_start(&a);
727
728 lv_anim_init(&a);
729 lv_anim_set_var(&a, album_img_obj);
730 lv_anim_set_values(&a, 0, LV_OPA_COVER);
731 lv_anim_set_exec_cb(&a, album_fade_anim_cb);
732 lv_anim_set_time(&a, 500);
733 lv_anim_set_delay(&a, 100);
734 lv_anim_start(&a);
735 }
736
get_cos(int32_t deg,int32_t a)737 int32_t get_cos(int32_t deg, int32_t a)
738 {
739 int32_t r = (lv_trigo_cos(deg) * a);
740
741 r += LV_TRIGO_SIN_MAX / 2;
742 return r >> LV_TRIGO_SHIFT;
743 }
744
get_sin(int32_t deg,int32_t a)745 int32_t get_sin(int32_t deg, int32_t a)
746 {
747 int32_t r = lv_trigo_sin(deg) * a;
748
749 r += LV_TRIGO_SIN_MAX / 2;
750 return r >> LV_TRIGO_SHIFT;
751
752 }
753
spectrum_draw_event_cb(lv_event_t * e)754 static void spectrum_draw_event_cb(lv_event_t * e)
755 {
756 lv_event_code_t code = lv_event_get_code(e);
757
758 if(code == LV_EVENT_REFR_EXT_DRAW_SIZE) {
759 #if LV_DEMO_MUSIC_LANDSCAPE
760 lv_event_set_ext_draw_size(e, LV_HOR_RES);
761 #else
762 lv_event_set_ext_draw_size(e, LV_VER_RES);
763 #endif
764 }
765 else if(code == LV_EVENT_COVER_CHECK) {
766 lv_event_set_cover_res(e, LV_COVER_RES_NOT_COVER);
767 }
768 else if(code == LV_EVENT_DRAW_POST) {
769 lv_obj_t * obj = lv_event_get_target(e);
770 lv_draw_ctx_t * draw_ctx = lv_event_get_draw_ctx(e);
771
772 lv_opa_t opa = lv_obj_get_style_opa_recursive(obj, LV_PART_MAIN);
773 if(opa < LV_OPA_MIN) return;
774
775 lv_point_t poly[4];
776 lv_point_t center;
777 center.x = obj->coords.x1 + lv_obj_get_width(obj) / 2;
778 center.y = obj->coords.y1 + lv_obj_get_height(obj) / 2;
779
780 lv_draw_rect_dsc_t draw_dsc;
781 lv_draw_rect_dsc_init(&draw_dsc);
782 draw_dsc.bg_opa = LV_OPA_COVER;
783
784 uint16_t r[64];
785 uint32_t i;
786
787 lv_coord_t min_a = 5;
788 #if LV_DEMO_MUSIC_LARGE == 0
789 lv_coord_t r_in = 77;
790 #else
791 lv_coord_t r_in = 160;
792 #endif
793 r_in = (r_in * lv_img_get_zoom(album_img_obj)) >> 8;
794 for(i = 0; i < BAR_CNT; i++) r[i] = r_in + min_a;
795
796 uint32_t s;
797 for(s = 0; s < 4; s++) {
798 uint32_t f;
799 uint32_t band_w = 0; /*Real number of bars in this band.*/
800 switch(s) {
801 case 0:
802 band_w = 20;
803 break;
804 case 1:
805 band_w = 8;
806 break;
807 case 2:
808 band_w = 4;
809 break;
810 case 3:
811 band_w = 2;
812 break;
813 }
814
815 /* Add "side bars" with cosine characteristic.*/
816 for(f = 0; f < band_w; f++) {
817 uint32_t ampl_main = spectrum[spectrum_i][s];
818 int32_t ampl_mod = get_cos(f * 360 / band_w + 180, 180) + 180;
819 int32_t t = BAR_PER_BAND_CNT * s - band_w / 2 + f;
820 if(t < 0) t = BAR_CNT + t;
821 if(t >= BAR_CNT) t = t - BAR_CNT;
822 r[t] += (ampl_main * ampl_mod) >> 9;
823 }
824 }
825
826 uint32_t amax = 20;
827 int32_t animv = spectrum_i - spectrum_lane_ofs_start;
828 if(animv > amax) animv = amax;
829 for(i = 0; i < BAR_CNT; i++) {
830 uint32_t deg_space = 1;
831 uint32_t deg = i * DEG_STEP + 90;
832 uint32_t j = (i + bar_rot + rnd_array[bar_ofs % 10]) % BAR_CNT;
833 uint32_t k = (i + bar_rot + rnd_array[(bar_ofs + 1) % 10]) % BAR_CNT;
834
835 uint32_t v = (r[k] * animv + r[j] * (amax - animv)) / amax;
836 if(start_anim) {
837 v = r_in + start_anim_values[i];
838 deg_space = v >> 7;
839 if(deg_space < 1) deg_space = 1;
840 }
841
842 if(v < BAR_COLOR1_STOP) draw_dsc.bg_color = BAR_COLOR1;
843 else if(v > BAR_COLOR3_STOP) draw_dsc.bg_color = BAR_COLOR3;
844 else if(v > BAR_COLOR2_STOP) draw_dsc.bg_color = lv_color_mix(BAR_COLOR3, BAR_COLOR2,
845 ((v - BAR_COLOR2_STOP) * 255) / (BAR_COLOR3_STOP - BAR_COLOR2_STOP));
846 else draw_dsc.bg_color = lv_color_mix(BAR_COLOR2, BAR_COLOR1,
847 ((v - BAR_COLOR1_STOP) * 255) / (BAR_COLOR2_STOP - BAR_COLOR1_STOP));
848
849 uint32_t di = deg + deg_space;
850
851 int32_t x1_out = get_cos(di, v);
852 poly[0].x = center.x + x1_out;
853 poly[0].y = center.y + get_sin(di, v);
854
855 int32_t x1_in = get_cos(di, r_in);
856 poly[1].x = center.x + x1_in;
857 poly[1].y = center.y + get_sin(di, r_in);
858 di += DEG_STEP - deg_space * 2;
859
860 int32_t x2_in = get_cos(di, r_in);
861 poly[2].x = center.x + x2_in;
862 poly[2].y = center.y + get_sin(di, r_in);
863
864 int32_t x2_out = get_cos(di, v);
865 poly[3].x = center.x + x2_out;
866 poly[3].y = center.y + get_sin(di, v);
867
868 lv_draw_polygon(draw_ctx, &draw_dsc, poly, 4);
869
870 poly[0].x = center.x - x1_out;
871 poly[1].x = center.x - x1_in;
872 poly[2].x = center.x - x2_in;
873 poly[3].x = center.x - x2_out;
874 lv_draw_polygon(draw_ctx, &draw_dsc, poly, 4);
875 }
876 }
877 }
878
spectrum_anim_cb(void * a,int32_t v)879 static void spectrum_anim_cb(void * a, int32_t v)
880 {
881 lv_obj_t * obj = a;
882 if(start_anim) {
883 lv_obj_invalidate(obj);
884 return;
885 }
886
887 spectrum_i = v;
888 lv_obj_invalidate(obj);
889
890 static uint32_t bass_cnt = 0;
891 static int32_t last_bass = -1000;
892 static int32_t dir = 1;
893 if(spectrum[spectrum_i][0] > 12) {
894 if(spectrum_i - last_bass > 5) {
895 bass_cnt++;
896 last_bass = spectrum_i;
897 if(bass_cnt >= 2) {
898 bass_cnt = 0;
899 spectrum_lane_ofs_start = spectrum_i;
900 bar_ofs++;
901 }
902 }
903 }
904 if(spectrum[spectrum_i][0] < 4) bar_rot += dir;
905
906 lv_img_set_zoom(album_img_obj, LV_IMG_ZOOM_NONE + spectrum[spectrum_i][0]);
907 }
908
start_anim_cb(void * a,int32_t v)909 static void start_anim_cb(void * a, int32_t v)
910 {
911 lv_coord_t * av = a;
912 *av = v;
913 lv_obj_invalidate(spectrum_obj);
914 }
915
album_img_create(lv_obj_t * parent)916 static lv_obj_t * album_img_create(lv_obj_t * parent)
917 {
918 LV_IMG_DECLARE(img_lv_demo_music_cover_1);
919 LV_IMG_DECLARE(img_lv_demo_music_cover_2);
920 LV_IMG_DECLARE(img_lv_demo_music_cover_3);
921
922 lv_obj_t * img;
923 img = lv_img_create(parent);
924
925 switch(track_id) {
926 case 2:
927 lv_img_set_src(img, &img_lv_demo_music_cover_3);
928 spectrum = spectrum_3;
929 spectrum_len = sizeof(spectrum_3) / sizeof(spectrum_3[0]);
930 break;
931 case 1:
932 lv_img_set_src(img, &img_lv_demo_music_cover_2);
933 spectrum = spectrum_2;
934 spectrum_len = sizeof(spectrum_2) / sizeof(spectrum_2[0]);
935 break;
936 case 0:
937 lv_img_set_src(img, &img_lv_demo_music_cover_1);
938 spectrum = spectrum_1;
939 spectrum_len = sizeof(spectrum_1) / sizeof(spectrum_1[0]);
940 break;
941 }
942 lv_img_set_antialias(img, false);
943 lv_obj_align(img, LV_ALIGN_CENTER, 0, 0);
944 lv_obj_add_event_cb(img, album_gesture_event_cb, LV_EVENT_GESTURE, NULL);
945 lv_obj_clear_flag(img, LV_OBJ_FLAG_GESTURE_BUBBLE);
946 lv_obj_add_flag(img, LV_OBJ_FLAG_CLICKABLE);
947
948 return img;
949
950 }
951
album_gesture_event_cb(lv_event_t * e)952 static void album_gesture_event_cb(lv_event_t * e)
953 {
954 lv_dir_t dir = lv_indev_get_gesture_dir(lv_indev_get_act());
955 if(dir == LV_DIR_LEFT) _lv_demo_music_album_next(true);
956 if(dir == LV_DIR_RIGHT) _lv_demo_music_album_next(false);
957 }
958
play_event_click_cb(lv_event_t * e)959 static void play_event_click_cb(lv_event_t * e)
960 {
961 lv_obj_t * obj = lv_event_get_target(e);
962 if(lv_obj_has_state(obj, LV_STATE_CHECKED)) {
963 _lv_demo_music_resume();
964 }
965 else {
966 _lv_demo_music_pause();
967 }
968 }
969
prev_click_event_cb(lv_event_t * e)970 static void prev_click_event_cb(lv_event_t * e)
971 {
972 LV_UNUSED(e);
973 _lv_demo_music_album_next(false);
974 }
975
next_click_event_cb(lv_event_t * e)976 static void next_click_event_cb(lv_event_t * e)
977 {
978 lv_event_code_t code = lv_event_get_code(e);
979 if(code == LV_EVENT_CLICKED) {
980 _lv_demo_music_album_next(true);
981 }
982 }
983
timer_cb(lv_timer_t * t)984 static void timer_cb(lv_timer_t * t)
985 {
986 LV_UNUSED(t);
987 time_act++;
988 lv_label_set_text_fmt(time_obj, "%"LV_PRIu32":%02"LV_PRIu32, time_act / 60, time_act % 60);
989 lv_slider_set_value(slider_obj, time_act, LV_ANIM_ON);
990 }
991
spectrum_end_cb(lv_anim_t * a)992 static void spectrum_end_cb(lv_anim_t * a)
993 {
994 LV_UNUSED(a);
995 _lv_demo_music_album_next(true);
996 }
997
stop_start_anim_timer_cb(lv_timer_t * t)998 static void stop_start_anim_timer_cb(lv_timer_t * t)
999 {
1000 LV_UNUSED(t);
1001 start_anim = false;
1002 stop_start_anim_timer = NULL;
1003 lv_obj_refresh_ext_draw_size(spectrum_obj);
1004 }
1005
album_fade_anim_cb(void * var,int32_t v)1006 static void album_fade_anim_cb(void * var, int32_t v)
1007 {
1008 lv_obj_set_style_img_opa(var, v, 0);
1009 }
1010 #endif /*LV_USE_DEMO_MUSIC*/
1011