Subversion Repositories Kolibri OS

Rev

Rev 5793 | 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_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.31\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.                                                 z1 = Form.left + mouse.x - tmp_x;
  153.                                                 z2 = Form.top + mouse.y - tmp_y;
  154.                                                 if(z1<=10)z1=0;
  155.                                                 if(z2<=10)z2=0;
  156.                                                 if(z1>screen.width-Form.width-10)z1=screen.width-Form.width;
  157.                                                 if(z2>screen.height-Form.height-10)z2=screen.height-Form.height;
  158.                                                 //if(z2<10)z2=0;
  159.                                                 MoveSize(z1 , z2, OLD, OLD);
  160.                                                 draw_window();
  161.                                         }
  162.                                         pause(1);
  163.                                 } while (mouse.lkm);
  164.                         }
  165.                         break;
  166.                 case evButton:
  167.                         id=GetButtonID();
  168.                         switch(id) {
  169.                                 case BUTTON_WINDOW_CLOSE:
  170.                                         StopPlayingMp3();
  171.                                         SaveIniConfig();
  172.                                         ExitProcess();
  173.                                         break;
  174.                                 case BUTTON_WINDOW_MINIMIZE:
  175.                                         MinimizeWindow();
  176.                                         break;
  177.                                 case BUTTON_WINDOW_REDUCE:
  178.                                         if (window_mode == WINDOW_MODE_NORMAL)
  179.                                         {
  180.                                                 window_mode = WINDOW_MODE_SMALL;
  181.                                                 win_x_normal = Form.left;
  182.                                                 win_y_normal = Form.top;
  183.                                                 MoveSize(OLD, OLD, 99, skin.h - 1);
  184.                                                 MoveSize(OLD, win_y_small, OLD, OLD);
  185.                                                 MoveSize(win_x_small, OLD, OLD, OLD);
  186.                                         }
  187.                                         else
  188.                                         {
  189.                                                 window_mode = WINDOW_MODE_NORMAL;
  190.                                                 win_x_small = Form.left;
  191.                                                 win_y_small = Form.top;
  192.                                                 MoveSize(win_x_normal, win_y_normal, skin.w -1 ,skin.h + list.h);
  193.                                         }
  194.                                         break;
  195.                                 case BUTTON_PLAYBACK_PREV: _PLAY_PREVIOUS:
  196.                                         current_playing_file_n--;
  197.                                         StartPlayingMp3();
  198.                                         break;
  199.                                 case BUTTON_PLAYBACK_NEXT: _PLAY_NEXT:
  200.                                         current_playing_file_n++;
  201.                                         StartPlayingMp3();
  202.                                         break;
  203.                                 case BUTTON_PLAYBACK_PLAY_PAUSE:
  204.                                         PlayAndPauseClick();
  205.                                         break;
  206.                         }
  207.                         break;   
  208.                 case evKey:
  209.                         GetKeys();
  210.                         if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
  211.                                 if (key_scancode==SCAN_CODE_LEFT) goto _PLAY_PREVIOUS;
  212.                                 if (key_scancode==SCAN_CODE_RIGHT) goto _PLAY_NEXT;
  213.                                 break;
  214.                         }              
  215.                         if (key_scancode==024) { OpenDialog_start stdcall (#o_dialog); if (o_dialog.status==1) OpenFolder(#openfile_path); }
  216.                         if (key_scancode==059) SetColorThemeLight();
  217.                         if (key_scancode==060) SetColorThemeDark();
  218.                         if (key_scancode==SCAN_CODE_LEFT) RunProgram("@VOLUME", "-");
  219.                         if (key_scancode==SCAN_CODE_RIGHT) RunProgram("@VOLUME", "+");
  220.                         if (key_scancode==050) RunProgram("@VOLUME", "m");
  221.                         if (key_scancode==SCAN_CODE_ENTER) { current_playing_file_n=list.current; StartPlayingMp3(); }
  222.                         if (key_scancode==025) || (key_scancode==SCAN_CODE_SPACE) PlayAndPauseClick();
  223.                         if (list.ProcessKey(key_scancode)) DrawPlayList();
  224.                         break;
  225.                 case evReDraw:
  226.                         if (window_mode == WINDOW_MODE_NORMAL) DefineAndDrawWindow(win_x_normal, win_y_normal, skin.w - 1, skin.h + list.h, 0x41,0,0,0);
  227.                         if (window_mode == WINDOW_MODE_SMALL) DefineAndDrawWindow(win_x_small, win_y_small, 99, skin.h - 1, 0x41,0,0,0);
  228.                         draw_window();
  229.                         break;
  230.                 default:
  231.                         if (playback_mode == PLAYBACK_MODE_PLAYING) && (!GetProcessSlot(player_run_id))
  232.                         {
  233.                                 current_playing_file_n++;
  234.                                 StartPlayingMp3();
  235.                         }
  236.           }
  237.   }
  238. }
  239.  
  240. void PlayAndPauseClick()
  241. {
  242.         if (playback_mode == PLAYBACK_MODE_PLAYING)
  243.         {
  244.                 playback_mode = PLAYBACK_MODE_STOPED;
  245.                 StopPlayingMp3();
  246.         }
  247.         else
  248.         {
  249.                 playback_mode = PLAYBACK_MODE_PLAYING;
  250.                 StartPlayingMp3();
  251.         }
  252. }
  253.  
  254.  
  255. void DrawPlayList()
  256. {
  257.         int i;
  258.         int yyy;
  259.         char temp_filename[4096];
  260.         for (i=0; i<list.visible; i++;)
  261.         {
  262.                 strcpy(#temp_filename, files_mas[i + list.first] * 304 + buf + 72);
  263.                 temp_filename[strlen(#temp_filename)-4] = '\0';
  264.                 if (strlen(#temp_filename)>47) strcpy(#temp_filename+44, "...");
  265.                
  266.                 yyy = i*list.line_h+list.y;
  267.                
  268.                 //this is selected file
  269.                 if (list.current - list.first == i)
  270.                 {
  271.                         if (i>=list.count) continue;
  272.                         DrawBar(list.x, yyy, list.w, list.line_h, theme.color_list_active_bg);
  273.                         WriteText(12,yyy+list.text_y,0x80, theme.color_list_active_text, #temp_filename);
  274.                 }
  275.                 //this is not selected file
  276.                 else
  277.                 {
  278.                         if (i>=list.count) continue;
  279.                         DrawBar(list.x,yyy,list.w, list.line_h, theme.color_list_bg);
  280.                         WriteText(12,yyy+list.text_y,0x80, theme.color_list_text, #temp_filename);
  281.                 }
  282.                 //this is current playing file
  283.                 if (i + list.first == current_playing_file_n) && (playback_mode == PLAYBACK_MODE_PLAYING)
  284.                 {
  285.                         WriteText(3, yyy+list.text_y,0x80, theme.color_list_active_pointer, "\x10");
  286.                         WriteText(12,yyy+list.text_y,0x80, theme.color_list_active_text, #temp_filename);
  287.                 }
  288.         }
  289.         DrawBar(list.x,list.visible * list.line_h + list.y, list.w, -list.visible * list.line_h + list.h, theme.color_list_bg);
  290.         DrawScroller();
  291. }
  292.  
  293.  
  294. void StopPlayingMp3()
  295. {
  296.         if (player_run_id) player_run_id = KillProcess(player_run_id);
  297.         if (notify_run_id) notify_run_id = KillProcess(notify_run_id);
  298.         playback_mode = PLAYBACK_MODE_STOPED;
  299.         DrawTopPanel();
  300.         DrawPlayList();
  301. }
  302.  
  303.  
  304. int NotifyAndBackFocus(dword msg)
  305. {
  306.         int nid;
  307.         nid = notify(msg);
  308.         pause(5);
  309.         Form.num_slot = GetProcessSlot(Form.ID);
  310.         if (Form.ID) ActivateWindow(Form.num_slot);
  311.         return nid;
  312. }
  313.  
  314.  
  315. void StartPlayingMp3()
  316. {
  317.         word i;
  318.         char item_path[4096];
  319.         char notify_message[512];
  320.         StopPlayingMp3();
  321.         if (!list.count) { NotifyAndBackFocus("'Pixie Player\nPress O key to open file' -St"); return; }
  322.         if (current_playing_file_n > list.count) { current_playing_file_n = list.count; return; }
  323.         if (current_playing_file_n < 0) { current_playing_file_n = 0; return; }
  324.         playback_mode = PLAYBACK_MODE_PLAYING;
  325.         strlcpy(#current_filename, GetCurrentItemName(), sizeof(current_filename));
  326.         sprintf(#item_path,"\"%s/%s\"",#work_folder,#current_filename);
  327.         DrawPlayList();
  328.         DrawTopPanel();
  329.         if (strcmpi(#item_path+strlen(#item_path)-4,".mp3")) player_run_id = RunProgram(abspath("minimp3"), #item_path);       
  330.         sprintf(#notify_message,"'Now playing:\n%s' -St",#current_filename);
  331.         for (i=2; i<strlen(#notify_message)-6; i++) if (notify_message[i]=='\'') notify_message[i]=96; //replace ' char to avoid @notify misunderstood
  332.         notify_run_id = NotifyAndBackFocus(#notify_message);
  333. }
  334.  
  335.  
  336. void draw_window() {
  337.         GetProcessInfo(#Form, SelfInfo);
  338.         DrawTopPanel();
  339.         IF (Form.status_window>=2) return;
  340.         if (window_mode == WINDOW_MODE_NORMAL)
  341.         {
  342.                 DrawListBorder(0, skin.h-1, skin.w-1, list.h+1, theme.color_list_border);
  343.                 DrawPlayList();
  344.         }
  345. }
  346.  
  347. void DrawTopPanel()
  348. {
  349.         char current_playing_title[245];
  350.         img_draw stdcall(skin.image, 0, 0, Form.width - 14, skin.h, 0, 0);
  351.         img_draw stdcall(skin.image, Form.width - 14, 0, 15, skin.h, skin.w - 15, 0);
  352.         if (playback_mode == PLAYBACK_MODE_STOPED) img_draw stdcall(skin.image, 13, 0, 22, skin.h, 300, 0);
  353.         //Playing control buttons
  354.         DefineButton(13, 1, 21, 21, BUTTON_PLAYBACK_PLAY_PAUSE + BT_HIDE, 0);
  355.         DefineButton(36, 1, 21, 21, BUTTON_PLAYBACK_PREV + BT_HIDE, 0);
  356.         DefineButton(60, 1, 21, 21, BUTTON_PLAYBACK_NEXT + BT_HIDE, 0);
  357.         //Window control buttons
  358.         DefineButton(Form.width - 14,  1, 11, 11, BUTTON_WINDOW_CLOSE + BT_HIDE, 0);
  359.         DefineButton(Form.width - 14, 12, 12, 11, BUTTON_WINDOW_REDUCE + BT_HIDE, 0);
  360.         //Mode depended
  361.         if (window_mode == WINDOW_MODE_NORMAL)
  362.         {
  363.                 DefineButton(Form.width - 26,  1, 12, 11, BUTTON_WINDOW_MINIMIZE + BT_HIDE, 0);
  364.                 strcpy(#current_playing_title, #current_filename);
  365.                 current_playing_title[strlen(#current_playing_title)-4] = '\0';
  366.                 if (strlen(#current_playing_title) > 29) strcpy(#current_playing_title + 26, "...");
  367.                 WriteText(90, 9, 0x80, theme.color_top_panel_text, #current_playing_title);
  368.         }
  369.         else
  370.         {
  371.                 DefineButton(0, 0, 12, skin.h, 99 + BT_HIDE + BT_NOFRAME, 0);
  372.         }
  373. }
  374.  
  375.  
  376. void DrawScroller()
  377. {
  378.         scroll1.max_area = list.count;
  379.         scroll1.cur_area = list.visible;
  380.         scroll1.position = list.first;
  381.         scroll1.all_redraw = 0;
  382.         scroll1.start_x = skin.w - scroll1.size_x - 1;
  383.         scroll1.start_y = list.y-1;
  384.         scroll1.size_y = list.h+2;
  385.         if (list.count > list.visible) scrollbar_v_draw(#scroll1);
  386. }
  387.  
  388. void DrawListBorder(dword x,y,w,h,color1)
  389. {
  390.         DrawBar(x,y+h,w,1,color1);
  391.         DrawBar(x,y,1,h,color1);
  392.         DrawBar(x+w,y,1,h+1,color1);
  393. }
  394.  
  395.  
  396. stop:
  397.  
  398. char menu_stak[4096];