Subversion Repositories Kolibri OS

Rev

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