Rev 7192 | Rev 7200 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 7192 | Rev 7196 | ||
---|---|---|---|
Line 9... | Line 9... | ||
9 | #include "../lib/file_system.h" |
9 | #include "../lib/file_system.h" |
10 | #include "../lib/list_box.h" |
10 | #include "../lib/list_box.h" |
11 | #include "../lib/gui.h" |
11 | #include "../lib/gui.h" |
12 | #include "../lib/random.h" |
12 | #include "../lib/random.h" |
13 | #include "../lib/kfont.h" |
13 | #include "../lib/kfont.h" |
14 | #include "../lib/collection.h" |
- | |
Line 15... | Line 14... | ||
15 | 14 | ||
16 | #include "../lib/obj/libio.h" |
15 | #include "../lib/obj/libio.h" |
17 | #include "../lib/obj/libimg.h" |
16 | #include "../lib/obj/libimg.h" |
18 | #include "../lib/obj/libini.h" |
17 | #include "../lib/obj/libini.h" |
Line 30... | Line 29... | ||
30 | 29 | ||
31 | //simple open dialog data |
30 | //simple open dialog data |
32 | char default_dir[] = "/rd/1"; |
31 | char default_dir[] = "/rd/1"; |
Line 33... | Line 32... | ||
33 | od_filter filter2 = { 15, "MP3\0WAV\0XM\0\0" }; |
32 | od_filter filter2 = { 15, "MP3\0WAV\0XM\0\0" }; |
Line 34... | Line 33... | ||
34 | 33 | ||
35 | #define ABOUT_MESSAGE "Pixie Player v2.7 |
34 | #define ABOUT_MESSAGE "Pixie Player v2.8 |
Line 36... | Line 35... | ||
36 | 35 | ||
37 | A tiny music folder player. |
36 | A tiny music folder player. |
38 | Supports MP3, WAV, XM audio file formats. |
37 | Supports MP3, WAV, XM audio file formats. |
39 | 38 | ||
40 | Controls: |
39 | Controls: |
41 | Open file: O key |
40 | Open file: O key |
- | 41 | Play/Stop: Space or P key |
|
42 | Play/Stop: Space or P key |
42 | Start playing selected file: Enter |
43 | Start playing selected file: Enter |
43 | Goto next/previous track: Ctrl + Left/Right |
44 | Goto next/previous track: Ctrl + Left/Right |
44 | Change sound volume: Left/Right key |
Line 45... | Line 45... | ||
45 | Change sound volume: Left/Right key |
45 | Remove from the list: Delete |
Line 93... | Line 93... | ||
93 | enum { |
93 | enum { |
94 | PLAYBACK_MODE_STOPED, |
94 | PLAYBACK_MODE_STOPED, |
95 | PLAYBACK_MODE_PLAYING |
95 | PLAYBACK_MODE_PLAYING |
96 | }; |
96 | }; |
Line 97... | Line -... | ||
97 | - | ||
98 | collection music_col; |
- | |
99 | 97 | ||
Line 100... | Line 98... | ||
100 | #define LAST_FOLDER_EXISTS 1 |
98 | #define LAST_FOLDER_EXISTS 1 |
101 | 99 | ||
102 | //===================================================// |
100 | //===================================================// |
Line 181... | Line 179... | ||
181 | if (key_scancode==SCAN_CODE_KEY_R) EventRepeatClick(); |
179 | if (key_scancode==SCAN_CODE_KEY_R) EventRepeatClick(); |
182 | if (key_scancode==SCAN_CODE_KEY_S) EventShuffleClick(); |
180 | if (key_scancode==SCAN_CODE_KEY_S) EventShuffleClick(); |
183 | if (key_scancode==SCAN_CODE_RIGHT) RunProgram("/sys/@VOLUME", "+"); |
181 | if (key_scancode==SCAN_CODE_RIGHT) RunProgram("/sys/@VOLUME", "+"); |
184 | if (key_scancode==SCAN_CODE_LEFT) RunProgram("/sys/@VOLUME", "-"); |
182 | if (key_scancode==SCAN_CODE_LEFT) RunProgram("/sys/@VOLUME", "-"); |
185 | if (key_scancode==SCAN_CODE_ENTER) EventStartPlayingSelectedItem(); |
183 | if (key_scancode==SCAN_CODE_ENTER) EventStartPlayingSelectedItem(); |
- | 184 | if (key_scancode==SCAN_CODE_DEL) EventDeleteItem(); |
|
186 | if (key_scancode==SCAN_CODE_KEY_P)||(key_scancode==SCAN_CODE_SPACE) EventPlayAndPause(); |
185 | if (key_scancode==SCAN_CODE_KEY_P)||(key_scancode==SCAN_CODE_SPACE) EventPlayAndPause(); |
187 | if (list.ProcessKey(key_scancode)) DrawPlayList(); |
186 | if (list.ProcessKey(key_scancode)) DrawPlayList(); |
188 | break; |
187 | break; |
189 | case evReDraw: |
188 | case evReDraw: |
190 | if (window_mode == WINDOW_MODE_NORMAL) |
189 | if (window_mode == WINDOW_MODE_NORMAL) |
Line 207... | Line 206... | ||
207 | 206 | ||
208 | void DrawPlayList() |
207 | void DrawPlayList() |
209 | { |
208 | { |
210 | int i; |
209 | int i; |
- | 210 | int yyy; |
|
211 | int yyy; |
211 | int kfont_width; |
212 | char temp_filename[4096]; |
212 | char temp_filename[4096]; |
213 | dword text_color, bg_color; |
213 | dword text_color, bg_color; |
214 | for (i=0; i |
214 | for (i=0; i |
215 | { |
215 | { |
Line 238... | Line 238... | ||
238 | && (playback_mode == PLAYBACK_MODE_PLAYING) |
238 | && (playback_mode == PLAYBACK_MODE_PLAYING) |
239 | { |
239 | { |
240 | text_color = theme.color_list_active_text; |
240 | text_color = theme.color_list_active_text; |
241 | } |
241 | } |
242 | DrawBar(list.x, yyy, list.w, list.item_h, bg_color); |
242 | DrawBar(list.x, yyy, list.w, list.item_h, bg_color); |
243 | kfont.WriteIntoWindow(6, yyy+list.text_y, bg_color, |
243 | kfont_width = kfont.WriteIntoWindow(6, yyy+list.text_y, bg_color, |
244 | text_color, list.font_type, #temp_filename); |
244 | text_color, list.font_type, #temp_filename); |
- | 245 | if (kfont_width>skin.w-15) DrawBar(skin.w-1, yyy, 1, list.item_h, theme.color_list_border); |
|
245 | } |
246 | } |
246 | DrawBar(list.x,list.visible * list.item_h + list.y, list.w, |
247 | DrawBar(list.x,list.visible * list.item_h + list.y, list.w, |
247 | -list.visible * list.item_h + list.h, theme.color_list_bg); |
248 | -list.visible * list.item_h + list.h, theme.color_list_bg); |
248 | DrawScroller(); |
249 | DrawScroller(); |
249 | } |
250 | } |
Line 258... | Line 259... | ||
258 | DrawPlayList(); |
259 | DrawPlayList(); |
259 | DrawRectangle(0, skin.h-1, skin.w-1, list.h+1, theme.color_list_border); |
260 | DrawRectangle(0, skin.h-1, skin.w-1, list.h+1, theme.color_list_border); |
260 | } |
261 | } |
261 | } |
262 | } |
Line 262... | Line -... | ||
262 | - | ||
263 | dword GetSongTitle() |
- | |
264 | { |
- | |
265 | char cur_y_playing_title[245]; |
- | |
266 | strcpy(#cur_y_playing_title, #current_filename); |
- | |
267 | cur_y_playing_title[strrchr(#cur_y_playing_title, '.')-1] = '\0'; |
- | |
268 | //if (strlen(#cur_y_playing_title) > 36) strcpy(#cur_y_playing_title + 34, "..."); |
- | |
269 | return #cur_y_playing_title; |
- | |
270 | } |
- | |
271 | - | ||
272 | 263 | ||
273 | void DrawTopPanel() |
264 | void DrawTopPanel() |
274 | { |
- | |
- | 265 | { |
|
275 | 266 | int kfont_width; |
|
276 | int button_y; |
267 | int button_y; |
277 | //Mode depended |
268 | //Mode depended |
278 | if (window_mode == WINDOW_MODE_NORMAL) |
269 | if (window_mode == WINDOW_MODE_NORMAL) |
279 | { |
270 | { |
Line 286... | Line 277... | ||
286 | if (shuffle) |
277 | if (shuffle) |
287 | img_draw stdcall(skin.image, 196, button_y+2, 17,17, skin.w+62, WIN_H_SMALL+1); |
278 | img_draw stdcall(skin.image, 196, button_y+2, 17,17, skin.w+62, WIN_H_SMALL+1); |
Line 288... | Line 279... | ||
288 | 279 | ||
289 | if (!work_folder) DrawPixieTitle("Pixie"); |
280 | if (!work_folder) DrawPixieTitle("Pixie"); |
290 | else DrawPixieTitle(#work_folder + strrchr(#work_folder, '/')); |
281 | else DrawPixieTitle(#work_folder + strrchr(#work_folder, '/')); |
291 | kfont.WriteIntoWindow(8, 24, theme.color_top_panel_bg, |
282 | kfont_width = kfont.WriteIntoWindow(8, 24, theme.color_top_panel_bg, |
- | 283 | theme.color_top_panel_song_name, list.font_type, #current_filename); |
|
292 | theme.color_top_panel_song_name, list.font_type, GetSongTitle()); |
284 | if (kfont_width>skin.w-15) DrawBar(skin.w-1, 24, 1, list.item_h, theme.color_list_border); |
293 | //Playing control buttons |
285 | //Playing control buttons |
294 | DefineHiddenButton(7, button_y, 38, 20, BUTTON_PLAYBACK_PREV); |
286 | DefineHiddenButton(7, button_y, 38, 20, BUTTON_PLAYBACK_PREV); |
295 | DefineHiddenButton(47, button_y, 38, 20, BUTTON_PLAYBACK_PLAY_PAUSE); |
287 | DefineHiddenButton(47, button_y, 38, 20, BUTTON_PLAYBACK_PLAY_PAUSE); |
296 | DefineHiddenButton(87, button_y, 38, 20, BUTTON_PLAYBACK_NEXT); |
288 | DefineHiddenButton(87, button_y, 38, 20, BUTTON_PLAYBACK_NEXT); |
Line 306... | Line 298... | ||
306 | } |
298 | } |
307 | else if (window_mode == WINDOW_MODE_SMALL) |
299 | else if (window_mode == WINDOW_MODE_SMALL) |
308 | { |
300 | { |
309 | button_y = 7; |
301 | button_y = 7; |
310 | img_draw stdcall(skin.image, 0, 0, WIN_W_SMALL, WIN_H_SMALL, skin.w-1, 0); |
302 | img_draw stdcall(skin.image, 0, 0, WIN_W_SMALL, WIN_H_SMALL, skin.w-1, 0); |
- | 303 | if (playback_mode != PLAYBACK_MODE_STOPED) |
|
- | 304 | img_draw stdcall(skin.image, 46, button_y-1, 27, 19, skin.w+83, WIN_H_SMALL+1); |
|
311 | DefineHiddenButton(0, 0, WIN_W_SMALL, WIN_H_SMALL, 99 + BT_NOFRAME); |
305 | DefineHiddenButton(0, 0, WIN_W_SMALL, WIN_H_SMALL, 99 + BT_NOFRAME); |
312 | //Playing control buttons |
306 | //Playing control buttons |
313 | DefineHiddenButton(20, button_y, 24, 16, BUTTON_PLAYBACK_PREV); |
307 | DefineHiddenButton(20, button_y, 24, 16, BUTTON_PLAYBACK_PREV); |
314 | DefineHiddenButton(46, button_y, 24, 16, BUTTON_PLAYBACK_PLAY_PAUSE); |
308 | DefineHiddenButton(46, button_y, 24, 16, BUTTON_PLAYBACK_PLAY_PAUSE); |
315 | DefineHiddenButton(72, button_y, 24, 16, BUTTON_PLAYBACK_NEXT); |
309 | DefineHiddenButton(72, button_y, 24, 16, BUTTON_PLAYBACK_NEXT); |
Line 367... | Line 361... | ||
367 | } |
361 | } |
368 | else |
362 | else |
369 | { |
363 | { |
370 | list.w -= scroll1.size_x; |
364 | list.w -= scroll1.size_x; |
371 | } |
365 | } |
372 | MoveSize(OLD, OLD, OLD, skin.h + list.h); |
366 | if (window_mode==WINDOW_MODE_NORMAL) MoveSize(OLD, OLD, OLD, skin.h + list.h); |
373 | list.KeyHome(); |
367 | list.KeyHome(); |
374 | current_playing_file_n=0; |
368 | current_playing_file_n=0; |
375 | EventStopPlayingMp3(); |
369 | EventStopPlaying(); |
376 | if (_open_path) EventStartPlayingMp3(); |
370 | if (_open_path) EventStartPlaying(); |
377 | } |
371 | } |
Line 378... | Line 372... | ||
378 | 372 | ||
379 | 373 | ||
380 | void EventStopPlayingMp3() |
374 | void EventStopPlaying() |
381 | { |
375 | { |
382 | if (player_run_id) player_run_id = KillProcess(player_run_id); |
376 | if (player_run_id) player_run_id = KillProcess(player_run_id); |
383 | if (notify_run_id) notify_run_id = KillProcess(notify_run_id); |
377 | if (notify_run_id) notify_run_id = KillProcess(notify_run_id); |
384 | playback_mode = PLAYBACK_MODE_STOPED; |
378 | playback_mode = PLAYBACK_MODE_STOPED; |
385 | DrawTopPanel(); |
379 | DrawTopPanel(); |
Line 386... | Line 380... | ||
386 | DrawPlayList(); |
380 | DrawPlayList(); |
387 | } |
381 | } |
388 | 382 | ||
389 | 383 | ||
390 | void EventStartPlayingMp3() |
384 | void EventStartPlaying() |
391 | { |
385 | { |
392 | word i; |
386 | word i; |
393 | char item_path[4096]; |
387 | char item_path[4096]; |
394 | char notify_message[512]; |
388 | char notify_message[512]; |
395 | EventStopPlayingMp3(); |
389 | EventStopPlaying(); |
396 | if (current_playing_file_n >= list.count) { |
390 | if (current_playing_file_n >= list.count) { |
Line 402... | Line 396... | ||
402 | return; |
396 | return; |
403 | } |
397 | } |
404 | playback_mode = PLAYBACK_MODE_PLAYING; |
398 | playback_mode = PLAYBACK_MODE_PLAYING; |
405 | strlcpy(#current_filename, Getcur_yItemName(), sizeof(current_filename)); |
399 | strlcpy(#current_filename, Getcur_yItemName(), sizeof(current_filename)); |
406 | sprintf(#item_path,"-h %s/%s",#work_folder,#current_filename); |
400 | sprintf(#item_path,"-h %s/%s",#work_folder,#current_filename); |
- | 401 | current_filename[strrchr(#current_filename, '.')-1] = '\0'; |
|
407 | DrawPlayList(); |
402 | DrawPlayList(); |
408 | DrawTopPanel(); |
403 | DrawTopPanel(); |
409 | player_run_id = RunProgram("/sys/media/ac97snd", #item_path); |
404 | player_run_id = RunProgram("/sys/media/ac97snd", #item_path); |
410 | sprintf(#notify_message,"'Now playing:\n%s' -St",#current_filename); |
405 | sprintf(#notify_message,"'Now playing:\n%s' -St",#current_filename); |
411 | if (!repeat) |
406 | if (!repeat) && (window_mode==WINDOW_MODE_SMALL) |
412 | { |
407 | { |
413 | for (i=2; i |
408 | for (i=2; i |
414 | { |
409 | { |
415 | //replace ' char to avoid @notify misunderstood |
410 | //replace ' char to avoid @notify misunderstood |
416 | if (notify_message[i]=='\'') notify_message[i]=96; |
411 | if (notify_message[i]=='\'') notify_message[i]=96; |
Line 423... | Line 418... | ||
423 | void EventPlayAndPause() |
418 | void EventPlayAndPause() |
424 | { |
419 | { |
425 | if (playback_mode == PLAYBACK_MODE_PLAYING) |
420 | if (playback_mode == PLAYBACK_MODE_PLAYING) |
426 | { |
421 | { |
427 | playback_mode = PLAYBACK_MODE_STOPED; |
422 | playback_mode = PLAYBACK_MODE_STOPED; |
428 | EventStopPlayingMp3(); |
423 | EventStopPlaying(); |
429 | } |
424 | } |
430 | else |
425 | else |
431 | { |
426 | { |
432 | playback_mode = PLAYBACK_MODE_PLAYING; |
427 | playback_mode = PLAYBACK_MODE_PLAYING; |
433 | EventStartPlayingMp3(); |
428 | EventStartPlaying(); |
434 | } |
429 | } |
435 | } |
430 | } |
Line 436... | Line 431... | ||
436 | 431 | ||
Line 455... | Line 450... | ||
455 | } |
450 | } |
456 | } |
451 | } |
Line 457... | Line 452... | ||
457 | 452 | ||
458 | void EventExitApp() |
453 | void EventExitApp() |
459 | { |
454 | { |
460 | EventStopPlayingMp3(); |
455 | EventStopPlaying(); |
461 | SaveIniConfig(); |
456 | SaveIniConfig(); |
462 | ExitProcess(); |
457 | ExitProcess(); |
Line 463... | Line 458... | ||
463 | } |
458 | } |
464 | 459 | ||
465 | void EventPlaybackPrevious() |
460 | void EventPlaybackPrevious() |
466 | { |
461 | { |
467 | if (shuffle) current_playing_file_n = random(list.count); |
462 | if (shuffle) current_playing_file_n = random(list.count); |
468 | else current_playing_file_n--; |
463 | else current_playing_file_n--; |
Line 469... | Line 464... | ||
469 | EventStartPlayingMp3(); |
464 | EventStartPlaying(); |
470 | } |
465 | } |
471 | 466 | ||
472 | void EventPlaybackNext() |
467 | void EventPlaybackNext() |
473 | { |
468 | { |
474 | if (shuffle) current_playing_file_n = random(list.count); |
469 | if (shuffle) current_playing_file_n = random(list.count); |
Line 475... | Line 470... | ||
475 | else current_playing_file_n++; |
470 | else current_playing_file_n++; |
476 | EventStartPlayingMp3(); |
471 | EventStartPlaying(); |
477 | } |
472 | } |
478 | 473 | ||
479 | void EventStartPlayingSelectedItem() |
474 | void EventStartPlayingSelectedItem() |
Line 480... | Line 475... | ||
480 | { |
475 | { |
481 | current_playing_file_n=list.cur_y; |
476 | current_playing_file_n=list.cur_y; |
482 | EventStartPlayingMp3(); |
477 | EventStartPlaying(); |
Line 490... | Line 485... | ||
490 | 485 | ||
491 | void EventCheckSongFinished() |
486 | void EventCheckSongFinished() |
492 | { |
487 | { |
493 | if (playback_mode == PLAYBACK_MODE_PLAYING) |
488 | if (playback_mode == PLAYBACK_MODE_PLAYING) |
494 | && (!GetProcessSlot(player_run_id)) { |
489 | && (!GetProcessSlot(player_run_id)) { |
495 | if (repeat) EventStartPlayingMp3(); |
490 | if (repeat) EventStartPlaying(); |
496 | else EventPlaybackNext(); |
491 | else EventPlaybackNext(); |
497 | } |
492 | } |
Line 498... | Line 493... | ||
498 | } |
493 | } |
Line 507... | Line 502... | ||
507 | { |
502 | { |
508 | shuffle ^= 1; |
503 | shuffle ^= 1; |
509 | DrawTopPanel(); |
504 | DrawTopPanel(); |
510 | } |
505 | } |
Line -... | Line 506... | ||
- | 506 | ||
- | 507 | void EventDeleteItem() |
|
- | 508 | { |
|
- | 509 | int i; |
|
- | 510 | if (list.cur_y == current_playing_file_n) EventStopPlaying(); |
|
- | 511 | for (i=list.cur_y; i |
|
- | 512 | list.count--; |
|
- | 513 | if (i + list.first <= current_playing_file_n) current_playing_file_n--; |
|
- | 514 | list.CheckDoesValuesOkey(); |
|
- | 515 | if (list.count <= list.visible) |
|
- | 516 | { |
|
- | 517 | list.h = list.count * list.item_h; |
|
- | 518 | list.visible = list.count; |
|
- | 519 | list.w -= 1; |
|
- | 520 | if (window_mode==WINDOW_MODE_NORMAL) MoveSize(OLD, OLD, OLD, skin.h + list.h); |
|
- | 521 | } |
|
- | 522 | else DrawPlayList(); |
|
- | 523 | } |
|
511 | 524 | ||
512 | void EventShowAbout() |
525 | void EventShowAbout() |
513 | { |
526 | { |
514 | proc_info pop_up; |
527 | proc_info pop_up; |
515 | loop() switch(WaitEvent()) |
528 | loop() switch(WaitEvent()) |
Line 520... | Line 533... | ||
520 | case evKey: |
533 | case evKey: |
521 | GetKeys(); |
534 | GetKeys(); |
522 | if (key_scancode == SCAN_CODE_ESC) ExitProcess(); |
535 | if (key_scancode == SCAN_CODE_ESC) ExitProcess(); |
523 | break; |
536 | break; |
524 | case evReDraw: |
537 | case evReDraw: |
525 | DefineDragableWindow(150, 200, 400, 327); |
538 | DefineDragableWindow(150, 200, 400, 346); |
526 | GetProcessInfo(#pop_up, SelfInfo); |
539 | GetProcessInfo(#pop_up, SelfInfo); |
527 | DrawBar(0, 0, pop_up.width, pop_up.height, theme.color_top_panel_bg); |
540 | DrawBar(0, 0, pop_up.width, pop_up.height, theme.color_top_panel_bg); |
528 | DrawRectangle(0, 0, pop_up.width, pop_up.height, theme.color_list_border); |
541 | DrawRectangle(0, 0, pop_up.width, pop_up.height, theme.color_list_border); |
529 | WriteTextLines(10, 10, 0x90, theme.color_top_panel_song_name, ABOUT_MESSAGE, 19); |
542 | WriteTextLines(10, 10, 0x90, theme.color_top_panel_song_name, ABOUT_MESSAGE, 19); |