Subversion Repositories Kolibri OS

Rev

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