Pixie Player v1.0 upload

git-svn-id: svn://kolibrios.org@5465 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Kirill Lipatov (Leency) 2015-02-24 20:47:16 +00:00
parent 2dc8a43f9b
commit 64e8265b0e
12 changed files with 631 additions and 4 deletions

View File

@ -32,6 +32,25 @@ char program_path[4096];
#define BT_HIDE 0x40000000
#define BT_NOFRAME 0x20000000
//ASCII KEYS
#define ASCII_KEY_BS 008
#define ASCII_KEY_TAB 009
#define ASCII_KEY_ENTER 013
#define ASCII_KEY_ESC 027
#define ASCII_KEY_DEL 182
#define ASCII_KEY_INS 185
#define ASCII_KEY_SPACE 032
#define ASCII_KEY_LEFT 176
#define ASCII_KEY_RIGHT 179
#define ASCII_KEY_DOWN 177
#define ASCII_KEY_UP 178
#define ASCII_KEY_HOME 180
#define ASCII_KEY_END 181
#define ASCII_KEY_PGDN 183
#define ASCII_KEY_PGUP 184
//-------------------------------------------------------------------------
struct mouse

View File

@ -97,10 +97,10 @@ int llist::ProcessKey(dword key)
{
switch(key)
{
case 177: return KeyDown();
case 178: return KeyUp();
case 180: return KeyHome();
case 181: return KeyEnd();
case ASCII_KEY_DOWN: return KeyDown();
case ASCII_KEY_UP: return KeyUp();
case ASCII_KEY_HOME: return KeyHome();
case ASCII_KEY_END: return KeyEnd();
}
return 0;
}

View File

@ -0,0 +1,6 @@
if tup.getconfig("NO_CMM") ~= "" then return end
if tup.getconfig("LANG") == "ru"
then C_LANG = "LANG_RUS"
else C_LANG = "LANG_ENG" -- this includes default case without config
end
tup.rule("pixie.c", "c-- /D=AUTOBUILD /D=$(C_LANG) %f" .. tup.getconfig("KPACK_CMD"), "pixie.com")

View File

@ -0,0 +1,52 @@
char open_assoc_ini_path[] = "/sys/settings/assoc.ini";
word program_path_len;
void CheckDefaultForTheFirstStart()
{
ini_get_int stdcall (#open_assoc_ini_path, "Pixie", "icon", -1);
if (EAX!=-1) return;
CreateThread(#ShowPopUp,#menu_stak+4092);
}
void ShowPopUp()
{
byte button_id, key;
proc_info pop_up;
ini_set_int stdcall (#open_assoc_ini_path, "Pixie", "icon", 65);
program_path_len = strlen(#program_path);
ini_set_str stdcall (#open_assoc_ini_path, "Pixie", "exec", #program_path, program_path_len);
loop() switch(WaitEvent())
{
case evButton:
button_id = GetButtonID();
if (button_id==10) SetDefaultPlayer();
if (button_id==11) ExitProcess();
break;
case evKey:
key = GetKey();
if (key==ASCII_KEY_ENTER) SetDefaultPlayer();
if (key==ASCII_KEY_ESC) ExitProcess();
break;
case evReDraw:
DefineAndDrawWindow(150, 200, 220, 90, 0x01,0,0,0);
GetProcessInfo(#pop_up, SelfInfo);
DrawBar(0, 0, pop_up.width, pop_up.height, theme.color_list_bg);
DrawRectangle(0, 0, pop_up.width, pop_up.height, theme.color_list_border);
WriteText(10, 20, 0x80, theme.color_list_text, "Pixie is not a default MP3 player.");
WriteText(10, 32, 0x80, theme.color_list_text, "Make it default?");
DrawCaptButton(10, pop_up.height - 30, 80, 20, 10, theme.color_list_active_bg, theme.color_list_active_text, "Yes");
DrawCaptButton(pop_up.width-10-80, pop_up.height - 30, 80, 20, 11, theme.color_list_active_bg, theme.color_list_active_text, "No");
}
}
void SetDefaultPlayer()
{
ini_set_str stdcall (#open_assoc_ini_path, "Assoc", "mp3", "$Pixie", 6);
ini_set_str stdcall ("/sys/File namagers/KFAR.ini", "Associations", "mp3", #program_path, program_path_len);
ExitProcess();
}

View File

@ -0,0 +1,10 @@
@del lang.h--
@echo #define LANG_ENG 1 >lang.h--
C-- pixie.c
@del pixie
@kpack pixie.com
@rename pixie.com pixie
@del warning.txt
@del lang.h--
@pause

View File

@ -0,0 +1,56 @@
char temp_filename[4096],
work_folder[4096],
current_filename[256];
int files_mas[2000];
dword buf;
void OpenDirectory(dword folder_path)
{
int cur;
dword j, filesnum, end_pointer;
list.count = 0;
//free(buf);
if (GetDir(#buf, #filesnum, folder_path, DIRS_ONLYREAL)==0)
if (filesnum==0)
{
notify("'Error opening folder' -E");
}
for (j=0; j<filesnum; j++)
{
strcpy(#temp_filename, j*304 + buf+72);
end_pointer = #temp_filename+strlen(#temp_filename);
if (strcmpi(end_pointer-4,".mp3")!=0) continue;
cur = list.count;
files_mas[cur]=j;
list.count++;
}
SortByName(0, list.count-1);
SetOpenedFileFirst();
}
void SortByName(int a, b)
{
int j, i = a;
if (a >= b) return;
for (j = a; j <= b; j++)
if (strcmp(files_mas[j]*304 + buf+72, files_mas[b]*304 + buf+72)<=0) { files_mas[i] >< files_mas[j]; i++;}
SortByName(a, i-2);
SortByName(i, b);
}
void SetOpenedFileFirst()
{
int i;
dword opened_filename = #param + strrchr(#param, '/');
for (i=0; i<list.count; i++)
{
if (strcmpi(opened_filename,files_mas[i]*304 + buf+72)==0) { files_mas[0]><files_mas[i]; return; }
}
}
dword GetCurrentItemName() {
return files_mas[list.current]*304 + buf+72;
}

BIN
programs/cmm/pixie/minimp3 Normal file

Binary file not shown.

401
programs/cmm/pixie/pixie.c Normal file
View File

@ -0,0 +1,401 @@
//flac
//open last folder at start up
//do not open multiple threads
//edit list manually
#define MEMSIZE 0xFFFFF
#include "..\lib\kolibri.h"
#include "..\lib\mem.h"
#include "..\lib\strings.h"
#include "..\lib\dll.h"
#include "..\lib\file_system.h"
#include "..\lib\list_box.h"
#include "..\lib\figures.h"
#include "..\lib\lib.obj\box_lib.h"
#include "..\lib\lib.obj\libio_lib.h"
#include "..\lib\lib.obj\libimg_lib.h"
#include "..\lib\lib.obj\libini.h"
#include "..\lib\patterns\libimg_load_skin.h"
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};
llist list;
proc_info Form;
libimg_image skin;
char pixie_ini_path[4096];
enum {
BUTTON_WINDOW_CLOSE = 1,
BUTTON_WINDOW_MINIMIZE,
BUTTON_WINDOW_REDUCE,
BUTTON_PLAYBACK_PLAY_PAUSE = 10,
BUTTON_PLAYBACK_PREV,
BUTTON_PLAYBACK_NEXT
};
int player_run_id,
notify_run_id;
int current_playing_file_n;
word win_x, win_y;
byte window_mode;
enum {
WINDOW_MODE_NORMAL,
WINDOW_MODE_SMALL
};
byte playback_mode;
enum {
PLAYBACK_MODE_STOPED,
PLAYBACK_MODE_PLAYING
};
byte current_theme;
enum {
THEME_DARK,
THEME_LIGHT
};
#include "get_files_list.h"
#include "settings.h"
#include "check_default_player.h"
void main()
{
int id, key, mouse_clicked;
mouse m, drag_mouse;
mem_Init();
SetEventMask(0x27);
if (load_dll2(boxlib, #box_lib_init,0)!=0) notify("'Error: library doesn't exists - box_lib' -E");
if (load_dll2(libio, #libio_init,1)!=0) notify("'Error: library doesn't exists - libio' -E");
if (load_dll2(libimg, #libimg_init,1)!=0) notify("'Error: library doesn't exists - libimg' -E");
if (load_dll2(libini, #lib_init,1)!=0) notify("'Error: library doesn't exists - libini' -E");
id = abspath("pixie.ini");
strcpy(#pixie_ini_path, id);
LoadIniConfig();
CheckDefaultForTheFirstStart();
if (param)
{
strcpy(#work_folder, #param);
work_folder[strrchr(#work_folder, '/')-1]='\0';
}
if (work_folder) OpenDirectory(#work_folder);
StartPlayingMp3();
list.SetSizes(1, skin.h, skin.w-1, 198, 40, 18);
if (list.count <= list.visible)
{
list.h = list.count * list.line_h;
list.visible = list.count;
}
else
{
list.w -= scroll1.size_x;
}
loop()
{
WaitEventTimeout(60);
switch(EAX & 0xFF) {
case evMouse:
if (!CheckActiveProcess(Form.ID)) break;
scrollbar_v_mouse (#scroll1);
if (list.first <> scroll1.position)
{
list.first = scroll1.position;
DrawPlayList();
break;
}
m.get();
if (m.vert) if (list.MouseScroll(m.vert))
{
DrawPlayList();
}
if (mouse_clicked)
{
if (!m.lkm) && (list.ProcessMouse(m.x, m.y)) StartPlayingMp3();
mouse_clicked=0;
}
if (m.lkm) && (list.MouseOver(m.x, m.y)) mouse_clicked=1;
//drag window - emulate windows header
if (window_mode == WINDOW_MODE_SMALL) && (m.lkm) && (m.y < skin.h) && (m.x < 13)
{
do {
drag_mouse.get();
if (drag_mouse.x!=m.x) || (drag_mouse.y!=m.y)
{
MoveSize(Form.left + drag_mouse.x - m.x, Form.top + drag_mouse.y - m.y, OLD, OLD);
DrawWindow();
}
pause(2);
} while (drag_mouse.lkm);
}
if (m.pkm) && (m.y > skin.h)
notify("'Pixies Player v1.01\nChange sound volume: Left/Right key\nChange skin: F1/F2\nMute: M key' -St\n");
break;
case evButton:
id=GetButtonID();
switch(id) {
case BUTTON_WINDOW_CLOSE:
StopPlayingMp3();
SaveIniConfig();
ExitProcess();
break;
case BUTTON_WINDOW_MINIMIZE:
MinimizeWindow();
break;
case BUTTON_WINDOW_REDUCE:
if (window_mode == WINDOW_MODE_NORMAL)
{
window_mode = WINDOW_MODE_SMALL;
MoveSize(OLD, OLD, 99, skin.h - 1);
MoveSize(OLD, GetClientHeight() - skin.h + 1, OLD, OLD);
MoveSize(2000, OLD, OLD, OLD);
}
else
{
window_mode = WINDOW_MODE_NORMAL;
MoveSize(30,80,skin.w -1 ,skin.h + list.h);
}
break;
case BUTTON_PLAYBACK_PREV:
if (list.KeyUp()) StartPlayingMp3();
break;
case BUTTON_PLAYBACK_NEXT:
if (list.KeyDown()) StartPlayingMp3();
break;
case BUTTON_PLAYBACK_PLAY_PAUSE:
if (playback_mode == PLAYBACK_MODE_PLAYING)
{
playback_mode = PLAYBACK_MODE_STOPED;
DrawInactivePlayButton();
StopPlayingMp3();
}
else
{
playback_mode = PLAYBACK_MODE_PLAYING;
StartPlayingMp3();
}
break;
}
break;
case evKey:
key = GetKey();
if (key==50) SetColorThemeLight();
if (key==51) SetColorThemeDark();
if (key==ASCII_KEY_LEFT) RunProgram("@VOLUME", "-");
if (key==ASCII_KEY_RIGHT) RunProgram("@VOLUME", "+");
if (key=='m') RunProgram("@VOLUME", "m");
if (key==ASCII_KEY_ENTER) StartPlayingMp3();
if (key=='p') || (key==ASCII_KEY_SPACE)
{
if (playback_mode == PLAYBACK_MODE_PLAYING) StopPlayingMp3();
else StartPlayingMp3();
}
if (list.ProcessKey(key)) DrawPlayList();
break;
case evReDraw:
if (window_mode == WINDOW_MODE_NORMAL) DefineAndDrawWindow(win_x, win_y, skin.w - 1, skin.h + list.h, 0x01,0,0,0);
if (window_mode == WINDOW_MODE_SMALL) DefineAndDrawWindow(win_x, win_y, 99, skin.h - 1, 0x01,0,0,0);
DrawWindow();
break;
default:
if (playback_mode == PLAYBACK_MODE_PLAYING) && (GetProcessSlot(player_run_id)==0)
{
if (current_playing_file_n < list.count)
{
//пиздец тут быдлокод пошёл
id = list.current;
current_playing_file_n++;
list.current = current_playing_file_n;
StartPlayingMp3();
list.current = id;
DrawPlayList();
}
else
{
StopPlayingMp3();
DrawWindow();
}
}
}
}
}
void DrawPlayList()
{
int i;
int yyy;
for (i=0; i<list.visible; i++;)
{
strcpy(#temp_filename, files_mas[i + list.first] * 304 + buf + 72);
temp_filename[strlen(#temp_filename)-4] = '\0';
if (strlen(#temp_filename)>47) strcpy(#temp_filename+44, "...");
yyy = i*list.line_h+list.y;
//this is selected file
if (list.current - list.first == i)
{
if (i>=list.count) continue;
DrawBar(list.x, yyy, list.w, list.line_h, theme.color_list_active_bg);
WriteText(12,yyy+list.text_y,0x80, theme.color_list_active_text, #temp_filename);
}
//this is not selected file
else
{
if (i>=list.count) continue;
DrawBar(list.x,yyy,list.w, list.line_h, theme.color_list_bg);
WriteText(12,yyy+list.text_y,0x80, theme.color_list_text, #temp_filename);
}
//this is current playing file
if (i + list.first == current_playing_file_n) && (playback_mode == PLAYBACK_MODE_PLAYING)
{
WriteText(3, yyy+list.text_y,0x80, theme.color_list_active_pointer, "\x10");
WriteText(12,yyy+list.text_y,0x80, theme.color_list_active_text, #temp_filename);
}
}
DrawBar(list.x,list.visible * list.line_h + list.y, list.w, -list.visible * list.line_h + list.h, theme.color_list_bg);
DrawScroller();
}
void StopPlayingMp3()
{
if (player_run_id) player_run_id = KillProcess(player_run_id);
if (notify_run_id) notify_run_id = KillProcess(notify_run_id);
playback_mode = PLAYBACK_MODE_STOPED;
}
void StartPlayingMp3()
{
word i;
char item_path[4096], notify_message[512];
dword item_path_end_pointer;
StopPlayingMp3();
if (list.current > list.count)
{
list.current = list.count;
return;
}
if (!list.count)
{
notify_run_id = notify("'Pixie Player\nStopped, no file specified' -St");
return;
}
current_playing_file_n = list.current;
playback_mode = PLAYBACK_MODE_PLAYING;
strlcpy(#current_filename, GetCurrentItemName(), sizeof(current_filename));
strcpy(#item_path, "\"");
strcat(#item_path, #work_folder);
strcat(#item_path, "/");
strcat(#item_path, #current_filename);
strcat(#item_path, "\"");
DrawPlayList();
DrawTopPanel();
item_path_end_pointer = #item_path+strlen(#item_path);
if (strcmpi(item_path_end_pointer-4,".mp3")!=0) player_run_id = RunProgram(abspath("minimp3"), #item_path);
strcpy(#notify_message, "'Now playing:\n");
strcat(#notify_message, #current_filename);
for (i=2; i<strlen(#notify_message); i++) if (notify_message[i]=='\'') notify_message[i]=96;
strcat(#notify_message, "' -St");
notify_run_id = notify(#notify_message);
}
void DrawInactivePlayButton()
{
img_draw stdcall(skin.image, 13, 0, 22, skin.h, 300, 0);
}
void DrawWindow() {
GetProcessInfo(#Form, SelfInfo);
DrawTopPanel();
IF (Form.status_window>=2) return;
if (window_mode == WINDOW_MODE_NORMAL)
{
DrawListBorder(0, skin.h-1, skin.w-1, list.h+1, theme.color_list_border);
DrawPlayList();
}
}
void DrawTopPanel()
{
char current_playing_title[245];
img_draw stdcall(skin.image, 0, 0, Form.width - 14, skin.h, 0, 0);
img_draw stdcall(skin.image, Form.width - 14, 0, 15, skin.h, skin.w - 15, 0);
if (playback_mode == PLAYBACK_MODE_STOPED) DrawInactivePlayButton();
//Playing control buttons
DefineButton(13, 1, 21, 21, BUTTON_PLAYBACK_PLAY_PAUSE + BT_HIDE, 0);
DefineButton(36, 1, 21, 21, BUTTON_PLAYBACK_PREV + BT_HIDE, 0);
DefineButton(60, 1, 21, 21, BUTTON_PLAYBACK_NEXT + BT_HIDE, 0);
//Window control buttons
DefineButton(Form.width - 14, 1, 11, 11, BUTTON_WINDOW_CLOSE + BT_HIDE, 0);
DefineButton(Form.width - 14, 12, 12, 11, BUTTON_WINDOW_REDUCE + BT_HIDE, 0);
//Mode depended
if (window_mode == WINDOW_MODE_NORMAL)
{
DefineButton(Form.width - 26, 1, 12, 11, BUTTON_WINDOW_MINIMIZE + BT_HIDE, 0);
strcpy(#current_playing_title, #current_filename);
current_playing_title[strlen(#current_playing_title)-4] = '\0';
if (strlen(#current_playing_title) > 29) strcpy(#current_playing_title + 26, "...");
WriteText(90, 9, 0x80, theme.color_top_panel_text, #current_playing_title);
}
else
{
DefineButton(0, 0, 12, skin.h, 99 + BT_HIDE + BT_NOFRAME, 0);
}
}
void DrawScroller()
{
scroll1.max_area = list.count;
scroll1.cur_area = list.visible;
scroll1.position = list.first;
scroll1.all_redraw = 0;
scroll1.start_x = skin.w - scroll1.size_x - 1;
scroll1.start_y = list.y-1;
scroll1.size_y = list.h+2;
if (list.count > list.visible) scrollbar_v_draw(#scroll1);
}
void DrawListBorder(dword x,y,w,h,color1)
{
DrawBar(x,y+h,w,1,color1);
DrawBar(x,y,1,h,color1);
DrawBar(x+w,y,1,h+1,color1);
}
stop:
char menu_stak[4096];

View File

@ -0,0 +1,4 @@
[Config]
current_theme=0
window_mode=0
last_folder=

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

View File

@ -0,0 +1,79 @@
void LoadIniConfig()
{
debugln(#pixie_ini_path);
ini_get_int stdcall (#pixie_ini_path, "Config", "current_theme", THEME_DARK);
current_theme = EAX;
if (current_theme == THEME_DARK) SetColorThemeDark(); else SetColorThemeLight();
ini_get_int stdcall (#pixie_ini_path, "Config", "window_mode", WINDOW_MODE_NORMAL);
window_mode = EAX;
ini_get_int stdcall (#pixie_ini_path, "Config", "win_x", 100);
win_x = EAX;
ini_get_int stdcall (#pixie_ini_path, "Config", "win_y", 90);
win_y = EAX;
ini_get_str stdcall (#pixie_ini_path, "Config", "last_folder", #work_folder, sizeof(work_folder), 0);
}
void SaveIniConfig()
{
debugln(#pixie_ini_path);
ini_set_int stdcall (#pixie_ini_path, "Config", "current_theme", current_theme);
ini_set_int stdcall (#pixie_ini_path, "Config", "window_mode", window_mode);
ini_set_int stdcall (#pixie_ini_path, "Config", "win_x", Form.left);
ini_set_int stdcall (#pixie_ini_path, "Config", "win_y", Form.top);
ini_set_str stdcall (#pixie_ini_path, "Config", "last_folder", #work_folder, strlen(#work_folder));
}
struct struct_pixie_colors {
dword color_top_panel_text,
color_list_bg,
color_list_text,
color_list_active_bg,
color_list_active_text,
color_list_active_pointer,
color_list_scroller,
color_list_border;
} theme;
void SetColorThemeDark()
{
current_theme = THEME_DARK;
Libimg_LoadImage(#skin, abspath("pixie_dark.png"));
skin.w = 300;
theme.color_top_panel_text = 0xFCFFBE;
theme.color_list_bg = 0x313031;
theme.color_list_text = 0xADAEAD;
theme.color_list_active_bg = 0x434343;
theme.color_list_active_text = 0xADAEAD;
theme.color_list_active_pointer = 0xD6D6D6;
theme.color_list_scroller = 0xBBBbbb;
theme.color_list_border = 0x121212;
scroll1.bckg_col = theme.color_list_bg;
scroll1.frnt_col = theme.color_list_border;
scroll1.line_col = theme.color_list_border;
DrawWindow();
}
void SetColorThemeLight()
{
current_theme = THEME_LIGHT;
Libimg_LoadImage(#skin, abspath("pixie_light.png"));
skin.w = 300;
theme.color_top_panel_text = 0x85663F;
theme.color_list_bg = 0xE2E2E2;
theme.color_list_text = 0x595959;
theme.color_list_active_bg = 0xFAF3AF;
theme.color_list_active_text = 0x85663F;
theme.color_list_active_pointer = 0x85663F;
theme.color_list_scroller = 0xBBBbbb;
theme.color_list_border = 0x736D65;
scroll1.bckg_col = theme.color_list_bg;
scroll1.frnt_col = theme.color_list_border;
scroll1.line_col = theme.color_list_border;
DrawWindow();
}