Subversion Repositories Kolibri OS

Rev

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