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 #if LV_DEMO_MUSIC_AUTO_PLAY
107 static lv_timer_t * auto_step_timer;
108 #endif
109
110 static lv_color_t original_screen_bg_color;
111
112 /**********************
113 * MACROS
114 **********************/
115
116 /**********************
117 * GLOBAL FUNCTIONS
118 **********************/
119
lv_demo_music(void)120 void lv_demo_music(void)
121 {
122 original_screen_bg_color = lv_obj_get_style_bg_color(lv_scr_act(), 0);
123 lv_obj_set_style_bg_color(lv_scr_act(), lv_color_hex(0x343247), 0);
124
125 list = _lv_demo_music_list_create(lv_scr_act());
126 ctrl = _lv_demo_music_main_create(lv_scr_act());
127
128 #if LV_DEMO_MUSIC_AUTO_PLAY
129 auto_step_timer = lv_timer_create(auto_step_cb, 1000, NULL);
130 #endif
131 }
132
lv_demo_music_close(void)133 void lv_demo_music_close(void)
134 {
135 /*Delete all aniamtions*/
136 lv_anim_del(NULL, NULL);
137
138 #if LV_DEMO_MUSIC_AUTO_PLAY
139 lv_timer_del(auto_step_timer);
140 #endif
141 _lv_demo_music_list_close();
142 _lv_demo_music_main_close();
143
144 lv_obj_clean(lv_scr_act());
145
146 lv_obj_set_style_bg_color(lv_scr_act(), original_screen_bg_color, 0);
147 }
148
_lv_demo_music_get_title(uint32_t track_id)149 const char * _lv_demo_music_get_title(uint32_t track_id)
150 {
151 if(track_id >= sizeof(title_list) / sizeof(title_list[0])) return NULL;
152 return title_list[track_id];
153 }
154
_lv_demo_music_get_artist(uint32_t track_id)155 const char * _lv_demo_music_get_artist(uint32_t track_id)
156 {
157 if(track_id >= sizeof(artist_list) / sizeof(artist_list[0])) return NULL;
158 return artist_list[track_id];
159 }
160
_lv_demo_music_get_genre(uint32_t track_id)161 const char * _lv_demo_music_get_genre(uint32_t track_id)
162 {
163 if(track_id >= sizeof(genre_list) / sizeof(genre_list[0])) return NULL;
164 return genre_list[track_id];
165 }
166
_lv_demo_music_get_track_length(uint32_t track_id)167 uint32_t _lv_demo_music_get_track_length(uint32_t track_id)
168 {
169 if(track_id >= sizeof(time_list) / sizeof(time_list[0])) return 0;
170 return time_list[track_id];
171 }
172
173 /**********************
174 * STATIC FUNCTIONS
175 **********************/
176
177 #if LV_DEMO_MUSIC_AUTO_PLAY
auto_step_cb(lv_timer_t * t)178 static void auto_step_cb(lv_timer_t * t)
179 {
180 LV_UNUSED(t);
181 static uint32_t state = 0;
182
183 #if LV_DEMO_MUSIC_LARGE
184 const lv_font_t * font_small = &lv_font_montserrat_22;
185 const lv_font_t * font_large = &lv_font_montserrat_32;
186 #else
187 const lv_font_t * font_small = &lv_font_montserrat_12;
188 const lv_font_t * font_large = &lv_font_montserrat_16;
189 #endif
190
191 switch(state) {
192 case 5:
193 _lv_demo_music_album_next(true);
194 break;
195
196 case 6:
197 _lv_demo_music_album_next(true);
198 break;
199 case 7:
200 _lv_demo_music_album_next(true);
201 break;
202 case 8:
203 _lv_demo_music_play(0);
204 break;
205 #if LV_DEMO_MUSIC_SQUARE || LV_DEMO_MUSIC_ROUND
206 case 11:
207 lv_obj_scroll_by(ctrl, 0, -LV_VER_RES, LV_ANIM_ON);
208 break;
209 case 13:
210 lv_obj_scroll_by(ctrl, 0, -LV_VER_RES, LV_ANIM_ON);
211 break;
212 #else
213 case 12:
214 lv_obj_scroll_by(ctrl, 0, -LV_VER_RES, LV_ANIM_ON);
215 break;
216 #endif
217 case 15:
218 lv_obj_scroll_by(list, 0, -300, LV_ANIM_ON);
219 break;
220 case 16:
221 lv_obj_scroll_by(list, 0, 300, LV_ANIM_ON);
222 break;
223 case 18:
224 _lv_demo_music_play(1);
225 break;
226 case 19:
227 lv_obj_scroll_by(ctrl, 0, LV_VER_RES, LV_ANIM_ON);
228 break;
229 #if LV_DEMO_MUSIC_SQUARE || LV_DEMO_MUSIC_ROUND
230 case 20:
231 lv_obj_scroll_by(ctrl, 0, LV_VER_RES, LV_ANIM_ON);
232 break;
233 #endif
234 case 30:
235 _lv_demo_music_play(2);
236 break;
237 case 40: {
238 lv_obj_t * bg = lv_layer_top();
239 lv_obj_set_style_bg_color(bg, lv_color_hex(0x6f8af6), 0);
240 lv_obj_set_style_text_color(bg, lv_color_white(), 0);
241 lv_obj_set_style_bg_opa(bg, LV_OPA_COVER, 0);
242 lv_obj_fade_in(bg, 400, 0);
243 lv_obj_t * dsc = lv_label_create(bg);
244 lv_obj_set_style_text_font(dsc, font_small, 0);
245 lv_label_set_text(dsc, "The average FPS is");
246 lv_obj_align(dsc, LV_ALIGN_TOP_MID, 0, 90);
247
248 lv_obj_t * num = lv_label_create(bg);
249 lv_obj_set_style_text_font(num, font_large, 0);
250 #if LV_USE_PERF_MONITOR
251 lv_label_set_text_fmt(num, "%d", lv_refr_get_fps_avg());
252 #endif
253 lv_obj_align(num, LV_ALIGN_TOP_MID, 0, 120);
254
255 lv_obj_t * attr = lv_label_create(bg);
256 lv_obj_set_style_text_align(attr, LV_TEXT_ALIGN_CENTER, 0);
257 lv_obj_set_style_text_font(attr, font_small, 0);
258 #if LV_DEMO_MUSIC_SQUARE || LV_DEMO_MUSIC_ROUND
259 lv_label_set_text(attr, "Copyright 2020 LVGL Kft.\nwww.lvgl.io | lvgl@lvgl.io");
260 #else
261 lv_label_set_text(attr, "Copyright 2020 LVGL Kft. | www.lvgl.io | lvgl@lvgl.io");
262 #endif
263 lv_obj_align(attr, LV_ALIGN_BOTTOM_MID, 0, -10);
264 break;
265 }
266 case 41:
267 lv_scr_load(lv_obj_create(NULL));
268 _lv_demo_music_pause();
269 break;
270 }
271 state++;
272 }
273
274 #endif /*LV_DEMO_MUSIC_AUTO_PLAY*/
275
276 #endif /*LV_USE_DEMO_MUSIC*/
277