Subversion Repositories Kolibri OS

Rev

Rev 5509 | 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.  
  6. #define MEMSIZE 0xFFFFF
  7. #include "..\lib\kolibri.h"
  8. #include "..\lib\mem.h"
  9. #include "..\lib\strings.h"
  10. #include "..\lib\dll.h"
  11. #include "..\lib\file_system.h"
  12. #include "..\lib\list_box.h"
  13. #include "..\lib\gui.h"
  14.  
  15. #include "..\lib\obj\box_lib.h"
  16. #include "..\lib\obj\libio_lib.h"
  17. #include "..\lib\obj\libimg_lib.h"
  18. #include "..\lib\obj\libini.h"
  19.  
  20. #include "..\lib\patterns\libimg_load_skin.h"
  21.  
  22. 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};
  23. llist list;
  24. proc_info Form;
  25. libimg_image skin;
  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;
  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. byte current_theme;
  60. enum {
  61.         THEME_DARK,
  62.         THEME_LIGHT
  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 main()
  75. {
  76.         int id, key, mouse_clicked;
  77.         mouse m, drag_mouse;
  78.  
  79.         mem_Init();
  80.         SetEventMask(0x27);
  81.         if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("'Error: library doesn't exists - box_lib' -E");
  82.         if (load_dll2(libio, #libio_init,1)!=0) notify("'Error: library doesn't exists - libio' -E");
  83.         if (load_dll2(libimg, #libimg_init,1)!=0) notify("'Error: library doesn't exists - libimg' -E");
  84.         if (load_dll2(libini, #lib_init,1)!=0) notify("'Error: library doesn't exists - libini' -E");
  85.  
  86.         id = abspath("pixie.ini");
  87.         strcpy(#pixie_ini_path, id);
  88.         LoadIniConfig();
  89.         CheckDefaultForTheFirstStart();
  90.         if (param)
  91.         {
  92.                 strcpy(#work_folder, #param);
  93.                 work_folder[strrchr(#work_folder, '/')-1]='\0';
  94.         }
  95.         if (work_folder)
  96.         {
  97.                 OpenDirectory(#work_folder);
  98.                 SetOpenedFileFirst(#param);
  99.         }
  100.  
  101.         StartPlayingMp3();
  102.         list.SetSizes(1, skin.h, skin.w-1, 198, 40, 18);
  103.         if (list.count <= list.visible)
  104.         {
  105.                 list.h = list.count * list.line_h;
  106.                 list.visible = list.count;
  107.         }
  108.         else
  109.         {
  110.                 list.w -= scroll1.size_x;
  111.         }
  112.  
  113.         loop()
  114.         {
  115.           WaitEventTimeout(60);
  116.           switch(EAX & 0xFF) {
  117.                 case evMouse:
  118.                         if (!CheckActiveProcess(Form.ID)) break;
  119.                         scrollbar_v_mouse (#scroll1);
  120.                         if (list.first <> scroll1.position)
  121.                         {
  122.                                 list.first = scroll1.position;
  123.                                 DrawPlayList();
  124.                                 break;
  125.                         }
  126.                         m.get();
  127.  
  128.                         if (m.vert) if (list.MouseScroll(m.vert))
  129.                         {
  130.                                 DrawPlayList();
  131.                         }
  132.  
  133.                         if (mouse_clicked)
  134.                         {
  135.                                 if (!m.lkm) && (list.ProcessMouse(m.x, m.y)) StartPlayingMp3();
  136.                                 mouse_clicked=0;
  137.                         }
  138.                         if (m.lkm) && (list.MouseOver(m.x, m.y)) mouse_clicked=1;
  139.                         //drag window - emulate windows header
  140.                         if (window_mode == WINDOW_MODE_SMALL) && (m.lkm) && (m.y < skin.h) && (m.x < 13)
  141.                         {
  142.                                 do {
  143.                                         drag_mouse.get();
  144.                                         if (drag_mouse.x!=m.x) || (drag_mouse.y!=m.y)
  145.                                         {
  146.                                                 MoveSize(Form.left + drag_mouse.x - m.x, Form.top + drag_mouse.y - m.y, OLD, OLD);
  147.                                                 DrawWindow();
  148.                                         }
  149.                                         pause(2);
  150.                                 } while (drag_mouse.lkm);
  151.                         }
  152.                         if (m.pkm) && (m.y > skin.h)
  153.                                 notify("'Pixies Player v1.11\nChange sound volume: Left/Right key\nChange skin: F1/F2\nMute: M key' -St\n");
  154.                         break;
  155.  
  156.                 case evButton:
  157.                         id=GetButtonID();
  158.                         switch(id) {
  159.                                 case BUTTON_WINDOW_CLOSE:
  160.                                         StopPlayingMp3();
  161.                                         SaveIniConfig();
  162.                                         ExitProcess();
  163.                                         break;
  164.                                 case BUTTON_WINDOW_MINIMIZE:
  165.                                         MinimizeWindow();
  166.                                         break;
  167.                                 case BUTTON_WINDOW_REDUCE:
  168.                                         if (window_mode == WINDOW_MODE_NORMAL)
  169.                                         {
  170.                                                 window_mode = WINDOW_MODE_SMALL;
  171.                                                 win_x_normal = Form.left;
  172.                                                 win_y_normal = Form.top;
  173.                                                 MoveSize(OLD, OLD, 99, skin.h - 1);
  174.                                                 MoveSize(OLD, win_y_small, OLD, OLD);
  175.                                                 MoveSize(win_x_small, OLD, OLD, OLD);
  176.                                         }
  177.                                         else
  178.                                         {
  179.                                                 window_mode = WINDOW_MODE_NORMAL;
  180.                                                 win_x_small = Form.left;
  181.                                                 win_y_small = Form.top;
  182.                                                 MoveSize(win_x_normal, win_y_normal, skin.w -1 ,skin.h + list.h);
  183.                                         }
  184.                                         break;
  185.                                 case BUTTON_PLAYBACK_PREV:
  186.                                         if (list.KeyUp()) {
  187.                                                 current_playing_file_n = list.current;
  188.                                                 StartPlayingMp3();
  189.                                         }
  190.                                         break;
  191.                                 case BUTTON_PLAYBACK_NEXT:
  192.                                         if (list.KeyDown())
  193.                                         {
  194.                                                 current_playing_file_n = list.current;
  195.                                                 StartPlayingMp3();
  196.                                         }
  197.                                         break;
  198.                                 case BUTTON_PLAYBACK_PLAY_PAUSE:
  199.                                         if (playback_mode == PLAYBACK_MODE_PLAYING)
  200.                                         {
  201.                                                 playback_mode = PLAYBACK_MODE_STOPED;
  202.                                                 DrawInactivePlayButton();
  203.                                                 StopPlayingMp3();
  204.                                         }
  205.                                         else
  206.                                         {
  207.                                                 playback_mode = PLAYBACK_MODE_PLAYING;
  208.                                                 StartPlayingMp3();
  209.                                         }
  210.                                         break;
  211.                         }
  212.                         break;
  213.          
  214.                 case evKey:
  215.                         key = GetKey();
  216.                         if (key==50) SetColorThemeLight();
  217.                         if (key==51) SetColorThemeDark();
  218.                         if (key==ASCII_KEY_LEFT) RunProgram("@VOLUME", "-");
  219.                         if (key==ASCII_KEY_RIGHT) RunProgram("@VOLUME", "+");
  220.                         if (key=='m') RunProgram("@VOLUME", "m");
  221.                         if (key==ASCII_KEY_ENTER) StartPlayingMp3();
  222.                         if (key=='p') || (key==ASCII_KEY_SPACE)
  223.                         {
  224.                                 if (playback_mode == PLAYBACK_MODE_PLAYING) StopPlayingMp3();
  225.                                 else StartPlayingMp3();
  226.                         }
  227.                         if (list.ProcessKey(key)) DrawPlayList();
  228.                         break;
  229.  
  230.                 case evReDraw:
  231.                         if (window_mode == WINDOW_MODE_NORMAL) DefineAndDrawWindow(win_x_normal, win_y_normal, skin.w - 1, skin.h + list.h, 0x01,0,0,0);
  232.                         if (window_mode == WINDOW_MODE_SMALL) DefineAndDrawWindow(win_x_small, win_y_small, 99, skin.h - 1, 0x01,0,0,0);
  233.                         DrawWindow();
  234.                         break;
  235.  
  236.                 default:
  237.                         if (playback_mode == PLAYBACK_MODE_PLAYING) && (GetProcessSlot(player_run_id)==0)
  238.                         {
  239.                                 if (current_playing_file_n < list.count)
  240.                                 {
  241.                                         current_playing_file_n = list.current;
  242.                                         if (list.KeyDown()) StartPlayingMp3();
  243.                                 }
  244.                                 else
  245.                                 {
  246.                                         StopPlayingMp3();
  247.                                         DrawWindow();
  248.                                 }
  249.                         }
  250.           }
  251.    }
  252. }
  253.  
  254.  
  255. void DrawPlayList()
  256. {
  257.         int i;
  258.         int yyy;
  259.         char temp_filename[4096];
  260.        
  261.         for (i=0; i<list.visible; i++;)
  262.         {
  263.                 strcpy(#temp_filename, files_mas[i + list.first] * 304 + buf + 72);
  264.                 temp_filename[strlen(#temp_filename)-4] = '\0';
  265.                 if (strlen(#temp_filename)>47) strcpy(#temp_filename+44, "...");
  266.                
  267.                 yyy = i*list.line_h+list.y;
  268.                
  269.                 //this is selected file
  270.                 if (list.current - list.first == i)
  271.                 {
  272.                         if (i>=list.count) continue;
  273.                         DrawBar(list.x, yyy, list.w, list.line_h, theme.color_list_active_bg);
  274.                         WriteText(12,yyy+list.text_y,0x80, theme.color_list_active_text, #temp_filename);
  275.                 }
  276.                 //this is not selected file
  277.                 else
  278.                 {
  279.                         if (i>=list.count) continue;
  280.                         DrawBar(list.x,yyy,list.w, list.line_h, theme.color_list_bg);
  281.                         WriteText(12,yyy+list.text_y,0x80, theme.color_list_text, #temp_filename);
  282.                 }
  283.                 //this is current playing file
  284.                 if (i + list.first == current_playing_file_n) && (playback_mode == PLAYBACK_MODE_PLAYING)
  285.                 {
  286.                         WriteText(3, yyy+list.text_y,0x80, theme.color_list_active_pointer, "\x10");
  287.                         WriteText(12,yyy+list.text_y,0x80, theme.color_list_active_text, #temp_filename);
  288.                 }
  289.         }
  290.         DrawBar(list.x,list.visible * list.line_h + list.y, list.w, -list.visible * list.line_h + list.h, theme.color_list_bg);
  291.         DrawScroller();
  292. }
  293.  
  294.  
  295. void StopPlayingMp3()
  296. {
  297.         if (player_run_id) player_run_id = KillProcess(player_run_id);
  298.         if (notify_run_id) notify_run_id = KillProcess(notify_run_id);
  299.         playback_mode = PLAYBACK_MODE_STOPED;
  300. }
  301.  
  302.  
  303. void StartPlayingMp3()
  304. {
  305.         word i;
  306.         char item_path[4096], notify_message[512];
  307.         dword item_path_end_pointer;
  308.         StopPlayingMp3();
  309.  
  310.         if (list.current > list.count)
  311.         {
  312.                 list.current = list.count;
  313.                 return;
  314.         }
  315.         if (!list.count)
  316.         {
  317.                 notify_run_id = notify("'Pixie Player\nStopped, no file specified' -St");
  318.                 return;
  319.         }
  320.  
  321.         current_playing_file_n = list.current;
  322.  
  323.         playback_mode = PLAYBACK_MODE_PLAYING;
  324.  
  325.         strlcpy(#current_filename, GetCurrentItemName(), sizeof(current_filename));
  326.         strcpy(#item_path, "\"");
  327.         strcat(#item_path, #work_folder);
  328.         strcat(#item_path, "/");
  329.         strcat(#item_path, #current_filename);
  330.         strcat(#item_path, "\"");
  331.  
  332.         DrawPlayList();
  333.         DrawTopPanel();
  334.  
  335.         item_path_end_pointer = #item_path+strlen(#item_path);
  336.         if (strcmpi(item_path_end_pointer-4,".mp3")!=0) player_run_id = RunProgram(abspath("minimp3"), #item_path);    
  337.         strcpy(#notify_message, "'Now playing:\n");
  338.         strcat(#notify_message, #current_filename);
  339.         for (i=2; i<strlen(#notify_message); i++) if (notify_message[i]=='\'') notify_message[i]=96;
  340.         strcat(#notify_message, "' -St");
  341.         notify_run_id = notify(#notify_message);
  342. }
  343.  
  344.  
  345. void DrawInactivePlayButton()
  346. {
  347.         img_draw stdcall(skin.image, 13, 0, 22, skin.h, 300, 0);
  348. }
  349.  
  350. void DrawWindow() {
  351.         GetProcessInfo(#Form, SelfInfo);
  352.         DrawTopPanel();
  353.         IF (Form.status_window>=2) return;
  354.         if (window_mode == WINDOW_MODE_NORMAL)
  355.         {
  356.                 DrawListBorder(0, skin.h-1, skin.w-1, list.h+1, theme.color_list_border);
  357.                 DrawPlayList();
  358.         }
  359. }
  360.  
  361.  
  362. void DrawTopPanel()
  363. {
  364.         char current_playing_title[245];
  365.         img_draw stdcall(skin.image, 0, 0, Form.width - 14, skin.h, 0, 0);
  366.         img_draw stdcall(skin.image, Form.width - 14, 0, 15, skin.h, skin.w - 15, 0);
  367.         if (playback_mode == PLAYBACK_MODE_STOPED) DrawInactivePlayButton();
  368.         //Playing control buttons
  369.         DefineButton(13, 1, 21, 21, BUTTON_PLAYBACK_PLAY_PAUSE + BT_HIDE, 0);
  370.         DefineButton(36, 1, 21, 21, BUTTON_PLAYBACK_PREV + BT_HIDE, 0);
  371.         DefineButton(60, 1, 21, 21, BUTTON_PLAYBACK_NEXT + BT_HIDE, 0);
  372.         //Window control buttons
  373.         DefineButton(Form.width - 14,  1, 11, 11, BUTTON_WINDOW_CLOSE + BT_HIDE, 0);
  374.         DefineButton(Form.width - 14, 12, 12, 11, BUTTON_WINDOW_REDUCE + BT_HIDE, 0);
  375.         //Mode depended
  376.         if (window_mode == WINDOW_MODE_NORMAL)
  377.         {
  378.                 DefineButton(Form.width - 26,  1, 12, 11, BUTTON_WINDOW_MINIMIZE + BT_HIDE, 0);
  379.                 strcpy(#current_playing_title, #current_filename);
  380.                 current_playing_title[strlen(#current_playing_title)-4] = '\0';
  381.                 if (strlen(#current_playing_title) > 29) strcpy(#current_playing_title + 26, "...");
  382.                 WriteText(90, 9, 0x80, theme.color_top_panel_text, #current_playing_title);
  383.         }
  384.         else
  385.         {
  386.                 DefineButton(0, 0, 12, skin.h, 99 + BT_HIDE + BT_NOFRAME, 0);
  387.         }
  388. }
  389.  
  390.  
  391. void DrawScroller()
  392. {
  393.         scroll1.max_area = list.count;
  394.         scroll1.cur_area = list.visible;
  395.         scroll1.position = list.first;
  396.  
  397.         scroll1.all_redraw = 0;
  398.         scroll1.start_x = skin.w - scroll1.size_x - 1;
  399.         scroll1.start_y = list.y-1;
  400.         scroll1.size_y = list.h+2;
  401.  
  402.         if (list.count > list.visible) scrollbar_v_draw(#scroll1);
  403. }
  404.  
  405. void DrawListBorder(dword x,y,w,h,color1)
  406. {
  407.         DrawBar(x,y+h,w,1,color1);
  408.         DrawBar(x,y,1,h,color1);
  409.         DrawBar(x+w,y,1,h+1,color1);
  410. }
  411.  
  412.  
  413. stop:
  414.  
  415. char menu_stak[4096];