Subversion Repositories Kolibri OS

Rev

Rev 6742 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. //flac
  2. //do not open multiple threads
  3. //edit list manually
  4.  
  5. #define MEMSIZE 0xFFFFF
  6.  
  7. #include "..\lib\obj\proc_lib.h"
  8. #include "..\lib\patterns\simple_open_dialog.h"
  9. char default_dir[] = "/rd/1";
  10. od_filter filter2 = { "MP3", 0 };
  11.  
  12. #include "..\lib\file_system.h"
  13. #include "..\lib\list_box.h"
  14. #include "..\lib\gui.h"
  15.  
  16. #include "..\lib\obj\box_lib.h"
  17. #include "..\lib\obj\libio.h"
  18. #include "..\lib\obj\libimg.h"
  19. #include "..\lib\obj\libini.h"
  20.  
  21. #include "..\lib\patterns\libimg_load_skin.h"
  22.  
  23. #define ABOUT_MESSAGE "'Pixies Player v1.33\n\nOpen file: O key\nChange skin: F1/F2
  24. Play/Stop: Space or P key\nStart playing selected file: Enter
  25. Goto next/previous track: Ctrl + Left/Right
  26. Change sound volume: Left/Right key\nMute: M key' -St\n"
  27.  
  28. 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};
  29.  
  30. proc_info Form;
  31. llist list;
  32.  
  33. char pixie_ini_path[4096];
  34.  
  35. enum {
  36.         BUTTON_WINDOW_CLOSE = 1,
  37.         BUTTON_WINDOW_MINIMIZE,
  38.         BUTTON_WINDOW_REDUCE,
  39.         BUTTON_PLAYBACK_PLAY_PAUSE = 10,
  40.         BUTTON_PLAYBACK_PREV,
  41.         BUTTON_PLAYBACK_NEXT
  42. };
  43.  
  44. int player_run_id,
  45.    notify_run_id;
  46.  
  47. int current_playing_file_n=0;
  48.  
  49. word win_x_normal, win_y_normal;
  50. word win_x_small, win_y_small;
  51.  
  52. byte window_mode;
  53. enum {
  54.         WINDOW_MODE_NORMAL,
  55.         WINDOW_MODE_SMALL
  56. };
  57.  
  58.  
  59. byte playback_mode;
  60. enum {
  61.         PLAYBACK_MODE_STOPED,
  62.         PLAYBACK_MODE_PLAYING
  63. };
  64.  
  65. char work_folder[4096],
  66.     current_filename[256];
  67.  
  68.  
  69. #include "get_files_list.h"
  70. #include "settings.h"
  71. #include "check_default_player.h"
  72.  
  73.  
  74. void OpenFolder(dword path111)
  75. {
  76.         if (ESBYTE[path111])
  77.         {
  78.                 strcpy(#work_folder, path111);
  79.                 work_folder[strrchr(#work_folder, '/')-1]='\0';
  80.                 OpenDirectory(#work_folder);
  81.                 SetOpenedFileFirst(path111);
  82.         }
  83.         list.SetFont(6, 9, 10000000b);
  84.         list.SetSizes(1, skin.h, skin.w-1, 198, 18);
  85.         if (list.count <= list.visible)
  86.         {
  87.                 list.h = list.count * list.item_h;
  88.                 list.visible = list.count;
  89.         }
  90.         else
  91.         {
  92.                 list.w -= scroll1.size_x;
  93.         }
  94.         MoveSize(OLD, OLD, OLD, skin.h + list.h);
  95.         list.KeyHome();
  96.         current_playing_file_n=0;
  97.         StopPlayingMp3();
  98.         StartPlayingMp3();     
  99. }
  100.  
  101. void main()
  102. {
  103.         int id;
  104.  
  105.         dword tmp_x,tmp_y;
  106.         dword z1,z2;
  107.        
  108.         load_dll(boxlib, #box_lib_init,0);
  109.         load_dll(libio, #libio_init,1);
  110.         load_dll(libimg, #libimg_init,1);
  111.         load_dll(libini, #lib_init,1);
  112.         load_dll(Proc_lib, #OpenDialog_init,0);
  113.         OpenDialog_init stdcall (#o_dialog);
  114.  
  115.         id = abspath("pixie.ini");
  116.         strcpy(#pixie_ini_path, id);
  117.         LoadIniConfig();
  118.         CheckDefaultForTheFirstStart();
  119.         OpenFolder(#param);
  120.         SetEventMask(0100111b);
  121.         loop()
  122.         {
  123.           WaitEventTimeout(10);
  124.           switch(EAX & 0xFF) {
  125.                 case evMouse:
  126.                         if (!CheckActiveProcess(Form.ID)) break;
  127.                         mouse.get();
  128.                         scrollbar_v_mouse (#scroll1);
  129.                         if (list.first != scroll1.position)
  130.                         {
  131.                                 list.first = scroll1.position;
  132.                                 DrawPlayList();
  133.                                 break;
  134.                         }
  135.                         if (list.MouseOver(mouse.x, mouse.y))
  136.                         {
  137.                                 if (mouse.vert) if (list.MouseScroll(mouse.vert)) DrawPlayList();
  138.                                 if (mouse.dblclick) {current_playing_file_n=list.cur_y; StartPlayingMp3();}
  139.                                 if (mouse.down) && (mouse.key&MOUSE_LEFT) if (list.ProcessMouse(mouse.x, mouse.y)) DrawPlayList();
  140.                                 if (mouse.down) && (mouse.key&MOUSE_RIGHT) NotifyAndBackFocus(ABOUT_MESSAGE);
  141.                         }
  142.                         //drag window - emulate windows header
  143.                         if(mouse.key&MOUSE_LEFT) && (mouse.y<skin.h) && (mouse.x < 13)
  144.                         {
  145.                                 tmp_x = mouse.x;
  146.                                 tmp_y = mouse.y;
  147.                                 do {
  148.                                         mouse.get();
  149.                                         if (tmp_x!=mouse.x) || (tmp_y!=mouse.y)
  150.                                         {
  151.                                                 z1 = Form.left + mouse.x - tmp_x;
  152.                                                 z2 = Form.top + mouse.y - tmp_y;
  153.                                                 if(z1<=10) || (z1>20000) z1=0; else if(z1>screen.width-Form.width-10)z1=screen.width-Form.width;
  154.                                                 if(z2<=10) || (z2>20000) z2=0; else if(z2>screen.height-Form.height-10)z2=screen.height-Form.height;
  155.                                                 MoveSize(z1 , z2, OLD, OLD);
  156.                                                 draw_window();
  157.                                         }
  158.                                         pause(1);
  159.                                 } while (mouse.lkm);
  160.                         }
  161.                         break;
  162.                 case evButton:
  163.                         id=GetButtonID();
  164.                         switch(id) {
  165.                                 case BUTTON_WINDOW_CLOSE:
  166.                                         StopPlayingMp3();
  167.                                         SaveIniConfig();
  168.                                         ExitProcess();
  169.                                         break;
  170.                                 case BUTTON_WINDOW_MINIMIZE:
  171.                                         MinimizeWindow();
  172.                                         break;
  173.                                 case BUTTON_WINDOW_REDUCE:
  174.                                         if (window_mode == WINDOW_MODE_NORMAL)
  175.                                         {
  176.                                                 window_mode = WINDOW_MODE_SMALL;
  177.                                                 win_x_normal = Form.left;
  178.                                                 win_y_normal = Form.top;
  179.                                                 MoveSize(OLD, OLD, 99, skin.h - 1);
  180.                                                 MoveSize(OLD, win_y_small, OLD, OLD);
  181.                                                 MoveSize(win_x_small, OLD, OLD, OLD);
  182.                                         }
  183.                                         else
  184.                                         {
  185.                                                 window_mode = WINDOW_MODE_NORMAL;
  186.                                                 win_x_small = Form.left;
  187.                                                 win_y_small = Form.top;
  188.                                                 MoveSize(win_x_normal, win_y_normal, skin.w -1 ,skin.h + list.h);
  189.                                         }
  190.                                         break;
  191.                                 case BUTTON_PLAYBACK_PREV: _PLAY_PREVIOUS:
  192.                                         current_playing_file_n--;
  193.                                         StartPlayingMp3();
  194.                                         break;
  195.                                 case BUTTON_PLAYBACK_NEXT: _PLAY_NEXT:
  196.                                         current_playing_file_n++;
  197.                                         StartPlayingMp3();
  198.                                         break;
  199.                                 case BUTTON_PLAYBACK_PLAY_PAUSE:
  200.                                         PlayAndPauseClick();
  201.                                         break;
  202.                         }
  203.                         break;   
  204.                 case evKey:
  205.                         GetKeys();
  206.                         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
  207.                                 if (key_scancode==SCAN_CODE_LEFT) goto _PLAY_PREVIOUS;
  208.                                 if (key_scancode==SCAN_CODE_RIGHT) goto _PLAY_NEXT;
  209.                                 break;
  210.                         }              
  211.                         if (key_scancode==024) { OpenDialog_start stdcall (#o_dialog); if (o_dialog.status==1) OpenFolder(#openfile_path); }
  212.                         if (key_scancode==059) SetColorThemeLight();
  213.                         if (key_scancode==060) SetColorThemeDark();
  214.                         if (key_scancode==SCAN_CODE_LEFT) RunProgram("@VOLUME", "-");
  215.                         if (key_scancode==SCAN_CODE_RIGHT) RunProgram("@VOLUME", "+");
  216.                         if (key_scancode==050) RunProgram("@VOLUME", "m");
  217.                         if (key_scancode==SCAN_CODE_ENTER) { current_playing_file_n=list.cur_y; StartPlayingMp3(); }
  218.                         if (key_scancode==025) || (key_scancode==SCAN_CODE_SPACE) PlayAndPauseClick();
  219.                         if (list.ProcessKey(key_scancode)) DrawPlayList();
  220.                         break;
  221.                 case evReDraw:
  222.                         if (window_mode == WINDOW_MODE_NORMAL) DefineAndDrawWindow(win_x_normal, win_y_normal, skin.w - 1, skin.h + list.h, 0x41,0,0,0);
  223.                         if (window_mode == WINDOW_MODE_SMALL) DefineAndDrawWindow(win_x_small, win_y_small, 99, skin.h - 1, 0x41,0,0,0);
  224.                         draw_window();
  225.                         break;
  226.                 default:
  227.                         if (playback_mode == PLAYBACK_MODE_PLAYING) && (!GetProcessSlot(player_run_id))
  228.                         {
  229.                                 current_playing_file_n++;
  230.                                 StartPlayingMp3();
  231.                         }
  232.           }
  233.   }
  234. }
  235.  
  236. void PlayAndPauseClick()
  237. {
  238.         if (playback_mode == PLAYBACK_MODE_PLAYING)
  239.         {
  240.                 playback_mode = PLAYBACK_MODE_STOPED;
  241.                 StopPlayingMp3();
  242.         }
  243.         else
  244.         {
  245.                 playback_mode = PLAYBACK_MODE_PLAYING;
  246.                 StartPlayingMp3();
  247.         }
  248. }
  249.  
  250.  
  251. void DrawPlayList()
  252. {
  253.         int i;
  254.         int yyy;
  255.         char temp_filename[4096];
  256.         for (i=0; i<list.visible; i++;)
  257.         {
  258.                 strcpy(#temp_filename, files_mas[i + list.first] * 304 + buf + 72);
  259.                 temp_filename[strlen(#temp_filename)-4] = '\0';
  260.                 if (strlen(#temp_filename)>47) strcpy(#temp_filename+44, "...");
  261.                
  262.                 yyy = i*list.item_h+list.y;
  263.                
  264.                 //this is selected file
  265.                 if (list.cur_y - list.first == i)
  266.                 {
  267.                         if (i>=list.count) continue;
  268.                         DrawBar(list.x, yyy, list.w, list.item_h, theme.color_list_active_bg);
  269.                         WriteText(12,yyy+list.text_y,0x80, theme.color_list_active_text, #temp_filename);
  270.                 }
  271.                 //this is not selected file
  272.                 else
  273.                 {
  274.                         if (i>=list.count) continue;
  275.                         DrawBar(list.x,yyy,list.w, list.item_h, theme.color_list_bg);
  276.                         WriteText(12,yyy+list.text_y,0x80, theme.color_list_text, #temp_filename);
  277.                 }
  278.                 //this is cur_y playing file
  279.                 if (i + list.first == current_playing_file_n) && (playback_mode == PLAYBACK_MODE_PLAYING)
  280.                 {
  281.                         WriteText(3, yyy+list.text_y,0x80, theme.color_list_active_pointer, "\x10");
  282.                         WriteText(12,yyy+list.text_y,0x80, theme.color_list_active_text, #temp_filename);
  283.                 }
  284.         }
  285.         DrawBar(list.x,list.visible * list.item_h + list.y, list.w, -list.visible * list.item_h + list.h, theme.color_list_bg);
  286.         DrawScroller();
  287. }
  288.  
  289.  
  290. void StopPlayingMp3()
  291. {
  292.         if (player_run_id) player_run_id = KillProcess(player_run_id);
  293.         if (notify_run_id) notify_run_id = KillProcess(notify_run_id);
  294.         playback_mode = PLAYBACK_MODE_STOPED;
  295.         DrawTopPanel();
  296.         DrawPlayList();
  297. }
  298.  
  299.  
  300. int NotifyAndBackFocus(dword msg)
  301. {
  302.         int nid;
  303.         nid = notify(msg);
  304.         pause(5);
  305.         Form.num_slot = GetProcessSlot(Form.ID);
  306.         if (Form.ID) ActivateWindow(Form.num_slot);
  307.         return nid;
  308. }
  309.  
  310.  
  311. void StartPlayingMp3()
  312. {
  313.         word i;
  314.         char item_path[4096];
  315.         char notify_message[512];
  316.         StopPlayingMp3();
  317.         if (!list.count) { NotifyAndBackFocus("'Pixie Player\nPress O key to open MP3 file' -St"); return; }
  318.         if (current_playing_file_n > list.count) { current_playing_file_n = list.count; return; }
  319.         if (current_playing_file_n < 0) { current_playing_file_n = 0; return; }
  320.         playback_mode = PLAYBACK_MODE_PLAYING;
  321.         strlcpy(#current_filename, Getcur_yItemName(), sizeof(current_filename));
  322.         sprintf(#item_path,"\"%s/%s\"",#work_folder,#current_filename);
  323.         DrawPlayList();
  324.         DrawTopPanel();
  325.         if (strcmpi(#item_path+strlen(#item_path)-4,".mp3")) player_run_id = RunProgram(abspath("minimp3"), #item_path);       
  326.         sprintf(#notify_message,"'Now playing:\n%s' -St",#current_filename);
  327.         for (i=2; i<strlen(#notify_message)-6; i++) if (notify_message[i]=='\'') notify_message[i]=96; //replace ' char to avoid @notify misunderstood
  328.         notify_run_id = NotifyAndBackFocus(#notify_message);
  329. }
  330.  
  331.  
  332. void draw_window() {
  333.         GetProcessInfo(#Form, SelfInfo);
  334.         DrawTopPanel();
  335.         IF (Form.status_window>=2) return;
  336.         if (window_mode == WINDOW_MODE_NORMAL)
  337.         {
  338.                 DrawListBorder(0, skin.h-1, skin.w-1, list.h+1, theme.color_list_border);
  339.                 DrawPlayList();
  340.         }
  341. }
  342.  
  343. void DrawTopPanel()
  344. {
  345.         char cur_y_playing_title[245];
  346.         img_draw stdcall(skin.image, 0, 0, Form.width - 14, skin.h, 0, 0);
  347.         img_draw stdcall(skin.image, Form.width - 14, 0, 15, skin.h, skin.w - 15, 0);
  348.         if (playback_mode == PLAYBACK_MODE_STOPED) img_draw stdcall(skin.image, 13, 0, 22, skin.h, 300, 0);
  349.         //Playing control buttons
  350.         DefineButton(13, 1, 21, 21, BUTTON_PLAYBACK_PLAY_PAUSE + BT_HIDE, 0);
  351.         DefineButton(36, 1, 21, 21, BUTTON_PLAYBACK_PREV + BT_HIDE, 0);
  352.         DefineButton(60, 1, 21, 21, BUTTON_PLAYBACK_NEXT + BT_HIDE, 0);
  353.         //Window control buttons
  354.         DefineButton(Form.width - 14,  1, 11, 11, BUTTON_WINDOW_CLOSE + BT_HIDE, 0);
  355.         DefineButton(Form.width - 14, 12, 12, 11, BUTTON_WINDOW_REDUCE + BT_HIDE, 0);
  356.         //Mode depended
  357.         if (window_mode == WINDOW_MODE_NORMAL)
  358.         {
  359.                 DefineButton(Form.width - 26,  1, 12, 11, BUTTON_WINDOW_MINIMIZE + BT_HIDE, 0);
  360.                 strcpy(#cur_y_playing_title, #current_filename);
  361.                 cur_y_playing_title[strlen(#cur_y_playing_title)-4] = '\0';
  362.                 if (strlen(#cur_y_playing_title) > 29) strcpy(#cur_y_playing_title + 26, "...");
  363.                 WriteText(90, 9, 0x80, theme.color_top_panel_text, #cur_y_playing_title);
  364.         }
  365.         else
  366.         {
  367.                 DefineButton(0, 0, 12, skin.h, 99 + BT_HIDE + BT_NOFRAME, 0);
  368.         }
  369. }
  370.  
  371.  
  372. void DrawScroller()
  373. {
  374.         scroll1.max_area = list.count;
  375.         scroll1.cur_area = list.visible;
  376.         scroll1.position = list.first;
  377.         scroll1.all_redraw = 0;
  378.         scroll1.start_x = skin.w - scroll1.size_x - 1;
  379.         scroll1.start_y = list.y-1;
  380.         scroll1.size_y = list.h+2;
  381.         if (list.count > list.visible) scrollbar_v_draw(#scroll1);
  382. }
  383.  
  384. void DrawListBorder(dword x,y,w,h,color1)
  385. {
  386.         DrawBar(x,y+h,w,1,color1);
  387.         DrawBar(x,y,1,h,color1);
  388.         DrawBar(x+w,y,1,h+1,color1);
  389. }
  390.  
  391.  
  392. stop:
  393.  
  394. char menu_stak[4096];