acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

lv_demo_music_main.c (35582B)

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