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.c (6370B)
1 /** 2 * @file lv_demo_music.c 3 * 4 */ 5 6 /********************* 7 * INCLUDES 8 *********************/ 9 #include "lv_demo_music.h" 10 11 #if LV_USE_DEMO_MUSIC 12 13 #include "lv_demo_music_main.h" 14 #include "lv_demo_music_list.h" 15 16 /********************* 17 * DEFINES 18 *********************/ 19 20 /********************** 21 * TYPEDEFS 22 **********************/ 23 24 /********************** 25 * STATIC PROTOTYPES 26 **********************/ 27 #if LV_DEMO_MUSIC_AUTO_PLAY 28 static void auto_step_cb(lv_timer_t * timer); 29 #endif 30 31 /********************** 32 * STATIC VARIABLES 33 **********************/ 34 static lv_obj_t * ctrl; 35 static lv_obj_t * list; 36 37 static const char * title_list[] = { 38 "Waiting for true love", 39 "Need a Better Future", 40 "Vibrations", 41 "Why now?", 42 "Never Look Back", 43 "It happened Yesterday", 44 "Feeling so High", 45 "Go Deeper", 46 "Find You There", 47 "Until the End", 48 "Unknown", 49 "Unknown", 50 "Unknown", 51 "Unknown", 52 }; 53 54 static const char * artist_list[] = { 55 "The John Smith Band", 56 "My True Name", 57 "Robotics", 58 "John Smith", 59 "My True Name", 60 "Robotics", 61 "Robotics", 62 "Unknown artist", 63 "Unknown artist", 64 "Unknown artist", 65 "Unknown artist", 66 "Unknown artist", 67 "Unknown artist", 68 "Unknown artist", 69 "Unknown artist", 70 }; 71 72 static const char * genre_list[] = { 73 "Rock - 1997", 74 "Drum'n bass - 2016", 75 "Psy trance - 2020", 76 "Metal - 2015", 77 "Metal - 2015", 78 "Metal - 2015", 79 "Metal - 2015", 80 "Metal - 2015", 81 "Metal - 2015", 82 "Metal - 2015", 83 "Metal - 2015", 84 "Metal - 2015", 85 "Metal - 2015", 86 "Metal - 2015", 87 }; 88 89 static const uint32_t time_list[] = { 90 1 * 60 + 14, 91 2 * 60 + 26, 92 1 * 60 + 54, 93 2 * 60 + 24, 94 2 * 60 + 37, 95 3 * 60 + 33, 96 1 * 60 + 56, 97 3 * 60 + 31, 98 2 * 60 + 20, 99 2 * 60 + 19, 100 2 * 60 + 20, 101 2 * 60 + 19, 102 2 * 60 + 20, 103 2 * 60 + 19, 104 }; 105 106 /********************** 107 * MACROS 108 **********************/ 109 110 /********************** 111 * GLOBAL FUNCTIONS 112 **********************/ 113 114 void lv_demo_music(void) 115 { 116 lv_obj_set_style_bg_color(lv_scr_act(), lv_color_hex(0x343247), 0); 117 118 list = _lv_demo_music_list_create(lv_scr_act()); 119 ctrl = _lv_demo_music_main_create(lv_scr_act()); 120 121 #if LV_DEMO_MUSIC_AUTO_PLAY 122 lv_timer_create(auto_step_cb, 1000, NULL); 123 #endif 124 } 125 126 const char * _lv_demo_music_get_title(uint32_t track_id) 127 { 128 if(track_id >= sizeof(title_list) / sizeof(title_list[0])) return NULL; 129 return title_list[track_id]; 130 } 131 132 const char * _lv_demo_music_get_artist(uint32_t track_id) 133 { 134 if(track_id >= sizeof(artist_list) / sizeof(artist_list[0])) return NULL; 135 return artist_list[track_id]; 136 } 137 138 const char * _lv_demo_music_get_genre(uint32_t track_id) 139 { 140 if(track_id >= sizeof(genre_list) / sizeof(genre_list[0])) return NULL; 141 return genre_list[track_id]; 142 } 143 144 uint32_t _lv_demo_music_get_track_length(uint32_t track_id) 145 { 146 if(track_id >= sizeof(time_list) / sizeof(time_list[0])) return 0; 147 return time_list[track_id]; 148 } 149 150 /********************** 151 * STATIC FUNCTIONS 152 **********************/ 153 154 #if LV_DEMO_MUSIC_AUTO_PLAY 155 static void auto_step_cb(lv_timer_t * t) 156 { 157 LV_UNUSED(t); 158 static uint32_t state = 0; 159 160 #if LV_DEMO_MUSIC_LARGE 161 const lv_font_t * font_small = &lv_font_montserrat_22; 162 const lv_font_t * font_large = &lv_font_montserrat_32; 163 #else 164 const lv_font_t * font_small = &lv_font_montserrat_12; 165 const lv_font_t * font_large = &lv_font_montserrat_16; 166 #endif 167 168 switch(state) { 169 case 5: 170 _lv_demo_music_album_next(true); 171 break; 172 173 case 6: 174 _lv_demo_music_album_next(true); 175 break; 176 case 7: 177 _lv_demo_music_album_next(true); 178 break; 179 case 8: 180 _lv_demo_music_play(0); 181 break; 182 #if LV_DEMO_MUSIC_SQUARE || LV_DEMO_MUSIC_ROUND 183 case 11: 184 lv_obj_scroll_by(ctrl, 0, -LV_VER_RES, LV_ANIM_ON); 185 break; 186 case 13: 187 lv_obj_scroll_by(ctrl, 0, -LV_VER_RES, LV_ANIM_ON); 188 break; 189 #else 190 case 12: 191 lv_obj_scroll_by(ctrl, 0, -LV_VER_RES, LV_ANIM_ON); 192 break; 193 #endif 194 case 15: 195 lv_obj_scroll_by(list, 0, -300, LV_ANIM_ON); 196 break; 197 case 16: 198 lv_obj_scroll_by(list, 0, 300, LV_ANIM_ON); 199 break; 200 case 18: 201 _lv_demo_music_play(1); 202 break; 203 case 19: 204 lv_obj_scroll_by(ctrl, 0, LV_VER_RES, LV_ANIM_ON); 205 break; 206 #if LV_DEMO_MUSIC_SQUARE || LV_DEMO_MUSIC_ROUND 207 case 20: 208 lv_obj_scroll_by(ctrl, 0, LV_VER_RES, LV_ANIM_ON); 209 break; 210 #endif 211 case 30: 212 _lv_demo_music_play(2); 213 break; 214 case 40: { 215 lv_obj_t * bg = lv_layer_top(); 216 lv_obj_set_style_bg_color(bg, lv_color_hex(0x6f8af6), 0); 217 lv_obj_set_style_text_color(bg, lv_color_white(), 0); 218 lv_obj_set_style_bg_opa(bg, LV_OPA_COVER, 0); 219 lv_obj_fade_in(bg, 400, 0); 220 lv_obj_t * dsc = lv_label_create(bg); 221 lv_obj_set_style_text_font(dsc, font_small, 0); 222 lv_label_set_text(dsc, "The average FPS is"); 223 lv_obj_align(dsc, LV_ALIGN_TOP_MID, 0, 90); 224 225 lv_obj_t * num = lv_label_create(bg); 226 lv_obj_set_style_text_font(num, font_large, 0); 227 #if LV_USE_PERF_MONITOR 228 lv_label_set_text_fmt(num, "%d", lv_refr_get_fps_avg()); 229 #endif 230 lv_obj_align(num, LV_ALIGN_TOP_MID, 0, 120); 231 232 lv_obj_t * attr = lv_label_create(bg); 233 lv_obj_set_style_text_align(attr, LV_TEXT_ALIGN_CENTER, 0); 234 lv_obj_set_style_text_font(attr, font_small, 0); 235 #if LV_DEMO_MUSIC_SQUARE || LV_DEMO_MUSIC_ROUND 236 lv_label_set_text(attr, "Copyright 2020 LVGL Kft.\nwww.lvgl.io | lvgl@lvgl.io"); 237 #else 238 lv_label_set_text(attr, "Copyright 2020 LVGL Kft. | www.lvgl.io | lvgl@lvgl.io"); 239 #endif 240 lv_obj_align(attr, LV_ALIGN_BOTTOM_MID, 0, -10); 241 break; 242 } 243 case 41: 244 lv_scr_load(lv_obj_create(NULL)); 245 _lv_demo_music_pause(); 246 break; 247 } 248 state++; 249 } 250 251 #endif /*LV_DEMO_MUSIC_AUTO_PLAY*/ 252 253 #endif /*LV_USE_DEMO_MUSIC*/