Subversion Repositories Kolibri OS

Rev

Rev 5798 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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