Subversion Repositories Kolibri OS

Rev

Rev 7051 | Rev 7177 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. //TODO
  2. //repeat track
  3. //edit list manually
  4.  
  5. #define MEMSIZE 4096 * 50
  6.  
  7. //===================================================//
  8. //                                                   //
  9. //                       LIB                         //
  10. //                                                   //
  11. //===================================================//
  12.  
  13. #include "../lib/file_system.h"
  14. #include "../lib/list_box.h"
  15. #include "../lib/gui.h"
  16.  
  17. #include "../lib/obj/box_lib.h"
  18. #include "../lib/obj/libio.h"
  19. #include "../lib/obj/libimg.h"
  20. #include "../lib/obj/libini.h"
  21.  
  22. #include "../lib/patterns/libimg_load_skin.h"
  23.  
  24. #include "../lib/obj/proc_lib.h"
  25. #include "../lib/patterns/simple_open_dialog.h"
  26.  
  27. //===================================================//
  28. //                                                   //
  29. //                       DATA                        //
  30. //                                                   //
  31. //===================================================//
  32.  
  33. //simple open dialog data
  34. char default_dir[] = "/rd/1";
  35. od_filter filter2 = { 8, "MP3\0\0" };
  36.  
  37. #define ABOUT_MESSAGE "'Pixies Player v2.3
  38. A tiny MP3 folder player.
  39.  
  40. Controls:
  41. Open file: O key
  42. Play/Stop: Space or P key
  43. Start playing selected file: Enter
  44. Goto next/previous track: Ctrl + Left/Right
  45. Change sound volume: Left/Right key
  46. Mute: M key' -td"
  47.  
  48. scroll_bar scroll1 = { 5,200,398,44,0,2,115,15,0,0xeeeeee,0xBBBbbb,0xeeeeee,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1};
  49.  
  50. proc_info Form;
  51. llist list;
  52.  
  53. char pixie_ini_path[4096];
  54. char work_folder[4096];
  55. char current_filename[256];
  56.  
  57. enum {
  58.         BUTTON_WINDOW_CLOSE = 1,
  59.         BUTTON_WINDOW_MINIMIZE,
  60.         BUTTON_WINDOW_REDUCE,
  61.         BUTTON_PLAYBACK_PLAY_PAUSE = 10,
  62.         BUTTON_PLAYBACK_PREV,
  63.         BUTTON_PLAYBACK_NEXT,
  64.         BUTTON_OPEN_DIALOG,
  65.         BUTTON_SHOW_VOLUME
  66. };
  67.  
  68. int player_run_id;
  69. int notify_run_id;
  70.  
  71. int current_playing_file_n=0;
  72.  
  73. word win_x_normal, win_y_normal;
  74. word win_x_small, win_y_small;
  75.  
  76. byte window_mode;
  77. enum {
  78.         WINDOW_MODE_NORMAL,
  79.         WINDOW_MODE_SMALL
  80. };
  81.  
  82. byte playback_mode;
  83. enum {
  84.         PLAYBACK_MODE_STOPED,
  85.         PLAYBACK_MODE_PLAYING
  86. };
  87.  
  88. //===================================================//
  89. //                                                   //
  90. //                       CODE                        //
  91. //                                                   //
  92. //===================================================//
  93.  
  94. #include "get_files_list.h"
  95. #include "settings.h"
  96.  
  97. void LoadLibraries()
  98. {
  99.         load_dll(boxlib, #box_lib_init,0);
  100.         load_dll(libio, #libio_init,1);
  101.         load_dll(libimg, #libimg_init,1);
  102.         load_dll(libini, #lib_init,1);
  103.         load_dll(Proc_lib, #OpenDialog_init,0);
  104.         OpenDialog_init stdcall (#o_dialog);   
  105. }
  106.  
  107. void main()
  108. {
  109.         int tempstr;
  110.         tempstr = abspath("pixie.ini");
  111.         strcpy(#pixie_ini_path, tempstr);
  112.         list.SetFont(8, 14, 0x90);
  113.         if (!param) notify("'Pixie Player\nPress O key to open MP3 file' -St");
  114.         LoadLibraries();
  115.         LoadIniConfig();
  116.         SetEventMask(0100111b);
  117.         loop()
  118.         {
  119.           WaitEventTimeout(10);
  120.           switch(EAX & 0xFF) {
  121.                 case evMouse:
  122.                         if (!CheckActiveProcess(Form.ID)) break;
  123.                         mouse.get();
  124.                         scrollbar_v_mouse (#scroll1);
  125.                         if (list.first != scroll1.position)
  126.                         {
  127.                                 list.first = scroll1.position;
  128.                                 DrawPlayList();
  129.                                 break;
  130.                         }
  131.                         if (list.MouseOver(mouse.x, mouse.y))
  132.                         {
  133.                                 if (mouse.vert) && (list.MouseScroll(mouse.vert)) DrawPlayList();
  134.                                 if (mouse.dblclick) EventStartPlayingSelectedItem();
  135.                                 if (mouse.down) && (mouse.key&MOUSE_LEFT) && (list.ProcessMouse(mouse.x, mouse.y)) DrawPlayList();
  136.                                 if (mouse.down) && (mouse.key&MOUSE_RIGHT) notify(ABOUT_MESSAGE);
  137.                         }
  138.                         if(mouse.key&MOUSE_LEFT) && (mouse.y<skin.h) && (window_mode == WINDOW_MODE_SMALL) EventDragWindow();
  139.                         break;
  140.                 case evButton:
  141.                         switch(GetButtonID()) {
  142.                                 case BUTTON_WINDOW_CLOSE: EventExitApp(); break;
  143.                                 case BUTTON_WINDOW_MINIMIZE: MinimizeWindow(); break;
  144.                                 case BUTTON_WINDOW_REDUCE: EventChangeWindowMode(); break;
  145.                                 case BUTTON_PLAYBACK_PREV: EventPlaybackPrevious();     break;
  146.                                 case BUTTON_PLAYBACK_NEXT: EventPlaybackNext(); break;
  147.                                 case BUTTON_PLAYBACK_PLAY_PAUSE: EventPlayAndPause(); break;
  148.                                 case BUTTON_OPEN_DIALOG: EventFileDialogOpen(); break;
  149.                                 case BUTTON_SHOW_VOLUME: RunProgram("/sys/@VOLUME", NULL); break;
  150.                         }
  151.                         break;   
  152.                 case evKey:
  153.                         GetKeys();
  154.                         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
  155.                                 if (key_scancode==SCAN_CODE_LEFT) EventPlaybackPrevious();
  156.                                 if (key_scancode==SCAN_CODE_RIGHT) EventPlaybackNext();
  157.                                 break;
  158.                         }              
  159.                         if (key_scancode==SCAN_CODE_KEY_O) EventFileDialogOpen();
  160.                         if (key_scancode==SCAN_CODE_KEY_M) RunProgram("/sys/@VOLUME", "m");
  161.                         if (key_scancode==SCAN_CODE_RIGHT) RunProgram("/sys/@VOLUME", "+");
  162.                         if (key_scancode==SCAN_CODE_LEFT)  RunProgram("/sys/@VOLUME", "-");
  163.                         if (key_scancode==SCAN_CODE_ENTER) EventStartPlayingSelectedItem();
  164.                         if (key_scancode==SCAN_CODE_KEY_P) || (key_scancode==SCAN_CODE_SPACE) EventPlayAndPause();
  165.                         if (list.ProcessKey(key_scancode)) DrawPlayList();
  166.                         break;
  167.                 case evReDraw:
  168.                         if (window_mode == WINDOW_MODE_NORMAL) DefineDragableWindow(win_x_normal, win_y_normal, skin.w - 1, skin.h + list.h-1);
  169.                         if (window_mode == WINDOW_MODE_SMALL) DefineDragableWindow(win_x_small, win_y_small, WIN_W_SMALL, WIN_H_SMALL);
  170.                         draw_window();
  171.                         if (param[0]) {
  172.                                 EventOpenFolder(#param);
  173.                                 param[0] = NULL;
  174.                         }
  175.                         break;
  176.                 default:
  177.                         EventCheckSongFinished();
  178.           }
  179.   }
  180. }
  181.  
  182.  
  183. void DrawPlayList()
  184. {
  185.         int i;
  186.         int yyy;
  187.         char temp_filename[4096];
  188.         for (i=0; i<list.visible; i++;)
  189.         {
  190.                 strcpy(#temp_filename, files_mas[i + list.first] * 304 + buf + 72);
  191.                 temp_filename[strlen(#temp_filename)-4] = '\0';
  192.                 if (strlen(#temp_filename)>47) strcpy(#temp_filename+44, "...");
  193.                
  194.                 yyy = i*list.item_h+list.y;
  195.                
  196.                 //this is selected file
  197.                 if (list.cur_y - list.first == i)
  198.                 {
  199.                         if (i>=list.count) continue;
  200.                         DrawBar(list.x, yyy, list.w, list.item_h, theme.color_list_active_bg);
  201.                         WriteText(12,yyy+list.text_y,list.font_type, theme.color_list_active_text, #temp_filename);
  202.                 }
  203.                 //this is not selected file
  204.                 else
  205.                 {
  206.                         if (i>=list.count) continue;
  207.                         DrawBar(list.x,yyy,list.w, list.item_h, theme.color_list_bg);
  208.                         WriteText(12,yyy+list.text_y,list.font_type, theme.color_list_text, #temp_filename);
  209.                 }
  210.                 //this is cur_y playing file
  211.                 if (i + list.first == current_playing_file_n) && (playback_mode == PLAYBACK_MODE_PLAYING)
  212.                 {
  213.                         WriteText(3, yyy+list.text_y+3,0x80, theme.color_list_active_pointer, "\x10");
  214.                         WriteText(12,yyy+list.text_y,list.font_type, theme.color_list_active_text, #temp_filename);
  215.                 }
  216.         }
  217.         DrawBar(list.x,list.visible * list.item_h + list.y, list.w, -list.visible * list.item_h + list.h, theme.color_list_bg);
  218.         DrawScroller();
  219. }
  220.  
  221.  
  222. void draw_window() {
  223.         GetProcessInfo(#Form, SelfInfo);
  224.         DrawTopPanel();
  225.         IF (Form.status_window>=2) return;
  226.         if (window_mode == WINDOW_MODE_NORMAL)
  227.         {
  228.                 DrawPlayList();
  229.                 DrawRectangle(0, skin.h-1, skin.w-1, list.h+1, theme.color_list_border);
  230.         }
  231. }
  232.  
  233. dword GetSongTitle()
  234. {
  235.         char cur_y_playing_title[245];
  236.         strcpy(#cur_y_playing_title, #current_filename);
  237.         cur_y_playing_title[strlen(#cur_y_playing_title)-4] = '\0';
  238.         if (strlen(#cur_y_playing_title) > 36) strcpy(#cur_y_playing_title + 34, "...");
  239.         return #cur_y_playing_title;
  240. }
  241.  
  242.  
  243. void DrawTopPanel()
  244. {
  245.        
  246.         int button_y;
  247.         //Mode depended
  248.         if (window_mode == WINDOW_MODE_NORMAL)
  249.         {
  250.                 button_y = 47;
  251.                 img_draw stdcall(skin.image, 0, 0, skin.w, skin.h, 0, 0);
  252.                 if (playback_mode != PLAYBACK_MODE_STOPED) img_draw stdcall(skin.image, 38, button_y, 33, 17, skin.w+1, WIN_H_SMALL+1);
  253.                 if /*(!list.count) && */ (!work_folder) DrawPixieTitle("Pixie");
  254.                 else DrawPixieTitle(#work_folder + strrchr(#work_folder, '/'));
  255.                 WriteText(10, 26, list.font_type, theme.color_top_panel_song_name, GetSongTitle());
  256.                 //Playing control buttons
  257.                 DefineHiddenButton(7, button_y, 30, 16, BUTTON_PLAYBACK_PREV);
  258.                 DefineHiddenButton(39, button_y, 30, 16, BUTTON_PLAYBACK_PLAY_PAUSE);
  259.                 DefineHiddenButton(71, button_y, 30, 16, BUTTON_PLAYBACK_NEXT);
  260.                 //Window control buttons
  261.                 DefineHiddenButton(Form.width - 21, 1, 20, 13, BUTTON_WINDOW_CLOSE);
  262.                 DefineHiddenButton(Form.width - 43, 1, 20, 13, BUTTON_WINDOW_MINIMIZE);
  263.                 DefineHiddenButton(Form.width - 65, 1, 20, 13, BUTTON_WINDOW_REDUCE);
  264.                 //Open and volume
  265.                 DefineHiddenButton(Form.width - 56, button_y, 23, 23, BUTTON_OPEN_DIALOG);
  266.                 DefineHiddenButton(Form.width - 27, button_y, 23, 23, BUTTON_SHOW_VOLUME);
  267.         }
  268.         else if (window_mode == WINDOW_MODE_SMALL)
  269.         {
  270.                 button_y = 7;
  271.                 img_draw stdcall(skin.image, 0, 0, WIN_W_SMALL, WIN_H_SMALL, skin.w-1, 0);
  272.                 DefineHiddenButton(0, 0, WIN_W_SMALL, WIN_H_SMALL, 99 + BT_NOFRAME);
  273.                 //Playing control buttons
  274.                 DefineHiddenButton(8, button_y, 24, 16, BUTTON_PLAYBACK_PREV);
  275.                 DefineHiddenButton(34, button_y, 24, 16, BUTTON_PLAYBACK_PLAY_PAUSE);
  276.                 DefineHiddenButton(60, button_y, 24, 16, BUTTON_PLAYBACK_NEXT);
  277.                 //Window control buttons
  278.                 DefineHiddenButton(Form.width - 20, 1, 19, 13, BUTTON_WINDOW_CLOSE);
  279.                 DefineHiddenButton(Form.width - 20, 16, 19, 13, BUTTON_WINDOW_REDUCE);
  280.         }
  281. }
  282.  
  283.  
  284. void DrawScroller()
  285. {
  286.         scroll1.max_area = list.count;
  287.         scroll1.cur_area = list.visible;
  288.         scroll1.position = list.first;
  289.         scroll1.all_redraw = 0;
  290.         scroll1.start_x = skin.w - scroll1.size_x-1;
  291.         scroll1.start_y = list.y-1;
  292.         scroll1.size_y = list.h+2;
  293.         if (list.count > list.visible) scrollbar_v_draw(#scroll1);
  294. }
  295.  
  296. void DrawPixieTitle(dword _title)
  297. {
  298.         WriteTextB(10, 6, list.font_type, theme.color_top_panel_folder_name, _title);
  299. }
  300.  
  301. //===================================================//
  302. //                                                   //
  303. //                     EVENTS                        //
  304. //                                                   //
  305. //===================================================//
  306.  
  307.  
  308. void EventOpenFolder(dword _open_path)
  309. {
  310.         if (ESBYTE[_open_path])
  311.         {
  312.                 strcpy(#work_folder, _open_path);
  313.                 work_folder[strrchr(#work_folder, '/')-1]='\0';
  314.                 OpenDirectory(#work_folder);
  315.                 SetOpenedFileFirst(_open_path);
  316.         }
  317.         list.SetSizes(1, skin.h, skin.w-1, 22*15, 22);
  318.         if (list.count <= list.visible)
  319.         {
  320.                 list.h = list.count * list.item_h;
  321.                 list.visible = list.count;
  322.                 list.w -= 1;
  323.         }
  324.         else
  325.         {
  326.                 list.w -= scroll1.size_x;
  327.         }
  328.         MoveSize(OLD, OLD, OLD, skin.h + list.h);
  329.         list.KeyHome();
  330.         current_playing_file_n=0;
  331.         EventStopPlayingMp3();
  332.         EventStartPlayingMp3();
  333. }
  334.  
  335.  
  336. void EventStopPlayingMp3()
  337. {
  338.         if (player_run_id) player_run_id = KillProcess(player_run_id);
  339.         if (notify_run_id) notify_run_id = KillProcess(notify_run_id);
  340.         playback_mode = PLAYBACK_MODE_STOPED;
  341.         DrawTopPanel();
  342.         DrawPlayList();
  343. }
  344.  
  345.  
  346. void EventStartPlayingMp3()
  347. {
  348.         word i;
  349.         char item_path[4096];
  350.         char notify_message[512];
  351.         EventStopPlayingMp3();
  352.         if (current_playing_file_n > list.count) {
  353.                 current_playing_file_n = list.count;
  354.                 return;
  355.         }
  356.         if (current_playing_file_n < 0) {
  357.                 current_playing_file_n = 0;
  358.                 return;
  359.         }
  360.         playback_mode = PLAYBACK_MODE_PLAYING;
  361.         strlcpy(#current_filename, Getcur_yItemName(), sizeof(current_filename));
  362.         sprintf(#item_path,"\"%s/%s\"",#work_folder,#current_filename);
  363.         DrawPlayList();
  364.         DrawTopPanel();
  365.         if (strcmpi(#item_path+strlen(#item_path)-4,".mp3")) player_run_id = RunProgram(abspath("minimp3"), #item_path);       
  366.         sprintf(#notify_message,"'Now playing:\n%s' -St",#current_filename);
  367.         for (i=2; i<strlen(#notify_message)-6; i++) if (notify_message[i]=='\'') notify_message[i]=96; //replace ' char to avoid @notify misunderstood
  368.         notify_run_id = notify(#notify_message);
  369. }
  370.  
  371.  
  372. void EventPlayAndPause()
  373. {
  374.         if (playback_mode == PLAYBACK_MODE_PLAYING)
  375.         {
  376.                 playback_mode = PLAYBACK_MODE_STOPED;
  377.                 EventStopPlayingMp3();
  378.         }
  379.         else
  380.         {
  381.                 playback_mode = PLAYBACK_MODE_PLAYING;
  382.                 EventStartPlayingMp3();
  383.         }
  384. }
  385.  
  386.  
  387. void EventChangeWindowMode()
  388. {
  389.         if (window_mode == WINDOW_MODE_NORMAL)
  390.         {
  391.                 window_mode = WINDOW_MODE_SMALL;
  392.                 win_x_normal = Form.left;
  393.                 win_y_normal = Form.top;
  394.                 MoveSize(OLD, OLD, WIN_W_SMALL-1, WIN_H_SMALL-1);
  395.                 MoveSize(OLD, win_y_small, OLD, OLD);
  396.                 MoveSize(win_x_small, OLD, OLD, OLD);
  397.         }
  398.         else
  399.         {
  400.                 window_mode = WINDOW_MODE_NORMAL;
  401.                 win_x_small = Form.left;
  402.                 win_y_small = Form.top;
  403.                 MoveSize(win_x_normal, win_y_normal, skin.w -1 ,skin.h + list.h);
  404.         }
  405. }
  406.  
  407. void EventExitApp()
  408. {
  409.         EventStopPlayingMp3();
  410.         SaveIniConfig();
  411.         ExitProcess();
  412. }
  413.  
  414. void EventPlaybackPrevious()
  415. {
  416.         current_playing_file_n--;
  417.         EventStartPlayingMp3();
  418. }
  419.  
  420. void EventPlaybackNext()
  421. {
  422.         current_playing_file_n++;
  423.         EventStartPlayingMp3();
  424. }
  425.  
  426. void EventStartPlayingSelectedItem()
  427. {
  428.         current_playing_file_n=list.cur_y;
  429.         EventStartPlayingMp3();
  430. }
  431.  
  432. void EventFileDialogOpen()
  433. {
  434.         OpenDialog_start stdcall (#o_dialog);
  435.         if (o_dialog.status==1) EventOpenFolder(#openfile_path);
  436. }
  437.  
  438. void EventCheckSongFinished()
  439. {
  440.         if (playback_mode == PLAYBACK_MODE_PLAYING) && (!GetProcessSlot(player_run_id)) {
  441.                 EventPlaybackNext();
  442.         }
  443. }
  444.  
  445.  
  446. stop:
  447.  
  448. char menu_stak[4096];