Subversion Repositories Kolibri OS

Rev

Rev 5789 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 5789 Rev 5793
Line 1... Line 1...
1
//flac
1
//flac
2
//do not open multiple threads
2
//do not open multiple threads
3
//edit list manually
3
//edit list manually
Line 4... Line -...
4
 
-
 
5
 
4
 
-
 
5
#define MEMSIZE 0xFFFFF
6
#define MEMSIZE 0xFFFFF
6
 
7
#include "..\lib\kolibri.h"
7
#include "..\lib\obj\proc_lib.h"
8
#include "..\lib\mem.h"
8
#include "..\lib\patterns\simple_open_dialog.h"
9
#include "..\lib\strings.h"
9
char default_dir[] = "/rd/1";
-
 
10
od_filter filter2 = { "MP3", 0 };
10
#include "..\lib\dll.h"
11
 
11
#include "..\lib\file_system.h"
12
#include "..\lib\file_system.h"
12
#include "..\lib\list_box.h"
13
#include "..\lib\list_box.h"
Line 13... Line 14...
13
#include "..\lib\gui.h"
14
#include "..\lib\gui.h"
Line 35... Line 36...
35
};
36
};
Line 36... Line 37...
36
 
37
 
37
int player_run_id,
38
int player_run_id,
Line 38... Line 39...
38
    notify_run_id;
39
    notify_run_id;
Line 39... Line 40...
39
 
40
 
40
int current_playing_file_n;
41
int current_playing_file_n=0;
Line 41... Line 42...
41
 
42
 
Line 53... Line 54...
53
enum {
54
enum {
54
	PLAYBACK_MODE_STOPED,
55
	PLAYBACK_MODE_STOPED,
55
	PLAYBACK_MODE_PLAYING
56
	PLAYBACK_MODE_PLAYING
56
};
57
};
Line 57... Line -...
57
 
-
 
58
byte current_theme;
-
 
59
enum {
-
 
60
	THEME_DARK,
-
 
61
	THEME_LIGHT
-
 
62
};
-
 
63
 
58
 
64
char work_folder[4096],
59
char work_folder[4096],
Line 65... Line 60...
65
     current_filename[256];
60
     current_filename[256];
66
 
61
 
67
 
62
 
Line -... Line 63...
-
 
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();
68
#include "get_files_list.h"
90
	current_playing_file_n=0;
69
#include "settings.h"
91
	StopPlayingMp3();
70
#include "check_default_player.h"
92
	StartPlayingMp3();	
Line 71... Line 93...
71
 
93
}
Line 81... Line 103...
81
	mem_Init();
103
	mem_Init();
82
	load_dll(boxlib, #box_lib_init,0);
104
	load_dll(boxlib, #box_lib_init,0);
83
	load_dll(libio, #libio_init,1);
105
	load_dll(libio, #libio_init,1);
84
	load_dll(libimg, #libimg_init,1);
106
	load_dll(libimg, #libimg_init,1);
85
	load_dll(libini, #lib_init,1);
107
	load_dll(libini, #lib_init,1);
-
 
108
	load_dll(Proc_lib, #OpenDialog_init,0);
-
 
109
	OpenDialog_init stdcall (#o_dialog);
Line 86... Line 110...
86
 
110
 
87
	id = abspath("pixie.ini");
111
	id = abspath("pixie.ini");
88
	strcpy(#pixie_ini_path, id);
112
	strcpy(#pixie_ini_path, id);
89
	LoadIniConfig();
113
	LoadIniConfig();
90
	CheckDefaultForTheFirstStart();
-
 
91
	if (param)
-
 
92
	{
-
 
93
		strcpy(#work_folder, #param);
-
 
94
		work_folder[strrchr(#work_folder, '/')-1]='\0';
-
 
95
	}
-
 
96
	if (work_folder) 
-
 
97
	{
-
 
98
		OpenDirectory(#work_folder);
114
	CheckDefaultForTheFirstStart();
99
		SetOpenedFileFirst(#param);
-
 
100
	}
-
 
101
 
-
 
102
	StartPlayingMp3();
-
 
103
	list.SetFont(6, 9, 10000000b);
-
 
104
	list.SetSizes(1, skin.h, skin.w-1, 198, 18);
-
 
105
	if (list.count <= list.visible) 
-
 
106
	{
-
 
107
		list.h = list.count * list.line_h;
-
 
108
		list.visible = list.count;
-
 
109
	}
-
 
110
	else
-
 
111
	{
-
 
112
		list.w -= scroll1.size_x;
-
 
113
	}
-
 
114
 
115
	OpenFolder(#param);
115
	SetEventMask(0100111b);
116
	SetEventMask(0100111b);
116
	loop()
117
	loop()
117
	{
118
	{
118
	  WaitEventTimeout(10);
119
	  WaitEventTimeout(10);
Line 128... Line 129...
128
				break;
129
				break;
129
			}
130
			}
130
			if (list.MouseOver(mouse.x, mouse.y))
131
			if (list.MouseOver(mouse.x, mouse.y))
131
			{
132
			{
132
				if (mouse.vert) if (list.MouseScroll(mouse.vert)) DrawPlayList();
133
				if (mouse.vert) if (list.MouseScroll(mouse.vert)) DrawPlayList();
133
				if (mouse.dblclick) StartPlayingMp3();
134
				if (mouse.dblclick) {current_playing_file_n=list.current; StartPlayingMp3();}
134
				if (mouse.key&MOUSE_LEFT) if (list.ProcessMouse(mouse.x, mouse.y)) DrawPlayList();
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(
135
				if (mouse.key&MOUSE_RIGHT) notify("'Pixies Player v1.2\nChange sound volume: Left/Right key\nChange skin: F1/F2\nMute: M key' -St\n");
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
					);
136
			}
139
			}
137
			//drag window - emulate windows header
140
			//drag window - emulate windows header
138
			if(mouse.key&MOUSE_LEFT) && (mouse.y
141
			if(mouse.key&MOUSE_LEFT) && (mouse.y
139
			{
142
			{
140
				tmp_x = mouse.x;
143
				tmp_x = mouse.x;
Line 149... Line 152...
149
						if(z2<=10)z2=0;
152
						if(z2<=10)z2=0;
150
						if(z1>screen.width-Form.width-10)z1=screen.width-Form.width;
153
						if(z1>screen.width-Form.width-10)z1=screen.width-Form.width;
151
						if(z2>screen.height-Form.height-10)z2=screen.height-Form.height;
154
						if(z2>screen.height-Form.height-10)z2=screen.height-Form.height;
152
						//if(z2<10)z2=0;
155
						//if(z2<10)z2=0;
153
						MoveSize(z1 , z2, OLD, OLD);
156
						MoveSize(z1 , z2, OLD, OLD);
154
						DrawWindow();
157
						draw_window();
155
					}
158
					}
156
					pause(1);
159
					pause(1);
157
				} while (mouse.lkm);
160
				} while (mouse.lkm);
158
			}
161
			}
159
			break;
162
			break;
Line 185... Line 188...
185
						win_y_small = Form.top;
188
						win_y_small = Form.top;
186
						MoveSize(win_x_normal, win_y_normal, skin.w -1 ,skin.h + list.h);
189
						MoveSize(win_x_normal, win_y_normal, skin.w -1 ,skin.h + list.h);
187
					}
190
					}
188
					break;
191
					break;
189
				case BUTTON_PLAYBACK_PREV:
192
				case BUTTON_PLAYBACK_PREV:
190
					if (list.KeyUp()) {
-
 
191
						current_playing_file_n = list.current;
193
					current_playing_file_n--;
192
						StartPlayingMp3();
194
					StartPlayingMp3();
193
					}
-
 
194
					break;
195
					break;
195
				case BUTTON_PLAYBACK_NEXT:
196
				case BUTTON_PLAYBACK_NEXT:
196
					if (list.KeyDown()) 
-
 
197
					{
-
 
198
						current_playing_file_n = list.current;
197
					current_playing_file_n++;
199
						StartPlayingMp3();
198
					StartPlayingMp3();
200
					}
-
 
201
					break;
199
					break;
202
				case BUTTON_PLAYBACK_PLAY_PAUSE:
200
				case BUTTON_PLAYBACK_PLAY_PAUSE:
203
					if (playback_mode == PLAYBACK_MODE_PLAYING) 
-
 
204
					{
-
 
205
						playback_mode = PLAYBACK_MODE_STOPED;
-
 
206
						DrawInactivePlayButton();
-
 
207
						StopPlayingMp3();
-
 
208
					}
-
 
209
					else
-
 
210
					{
-
 
211
						playback_mode = PLAYBACK_MODE_PLAYING;
-
 
212
						StartPlayingMp3();
201
					PlayAndPauseClick();
213
					}
-
 
214
					break;
202
					break;
215
			}
203
			}
216
			break;
204
			break;	  
217
	  
-
 
218
		case evKey:
205
		case evKey:
219
			GetKeys();
206
			GetKeys();			
220
			
-
 
-
 
207
			if (key_scancode==024) { OpenDialog_start stdcall (#o_dialog); if (o_dialog.status==1) OpenFolder(#openfile_path); }
221
			if (key_scancode==059) SetColorThemeLight();
208
			if (key_scancode==059) SetColorThemeLight();
222
			if (key_scancode==060) SetColorThemeDark();
209
			if (key_scancode==060) SetColorThemeDark();
223
			if (key_scancode==SCAN_CODE_LEFT) RunProgram("@VOLUME", "-");
210
			if (key_scancode==SCAN_CODE_LEFT) RunProgram("@VOLUME", "-");
224
			if (key_scancode==SCAN_CODE_RIGHT) RunProgram("@VOLUME", "+");
211
			if (key_scancode==SCAN_CODE_RIGHT) RunProgram("@VOLUME", "+");
225
			if (key_scancode==050) RunProgram("@VOLUME", "m");
212
			if (key_scancode==050) RunProgram("@VOLUME", "m");
226
			if (key_scancode==SCAN_CODE_ENTER) StartPlayingMp3();
213
			if (key_scancode==SCAN_CODE_ENTER) { current_playing_file_n=list.current; StartPlayingMp3(); }
227
			if (key_scancode==025) || (key_scancode==SCAN_CODE_SPACE)
214
			if (key_scancode==025) || (key_scancode==SCAN_CODE_SPACE) PlayAndPauseClick();
228
			{
-
 
229
				if (playback_mode == PLAYBACK_MODE_PLAYING) StopPlayingMp3();
-
 
230
				else StartPlayingMp3();
-
 
231
			}
-
 
232
			if (list.ProcessKey(key_scancode)) DrawPlayList();
215
			if (list.ProcessKey(key_scancode)) DrawPlayList();
233
			break;
216
			break;
234
 
-
 
235
		case evReDraw:
217
		case evReDraw:
236
			if (window_mode == WINDOW_MODE_NORMAL) DefineAndDrawWindow(win_x_normal, win_y_normal, skin.w - 1, skin.h + list.h, 0x41,0,0,0);
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);
237
			if (window_mode == WINDOW_MODE_SMALL) DefineAndDrawWindow(win_x_small, win_y_small, 99, skin.h - 1, 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);
238
			DrawWindow();
220
			draw_window();
239
			break;
221
			break;
240
 
-
 
241
		default:
222
		default:
242
			if (playback_mode == PLAYBACK_MODE_PLAYING) && (GetProcessSlot(player_run_id)==0)
223
			if (playback_mode == PLAYBACK_MODE_PLAYING) && (!GetProcessSlot(player_run_id))
243
			{
-
 
244
				if (current_playing_file_n < list.count) 
-
 
245
				{
224
			{
246
					current_playing_file_n++;
225
				current_playing_file_n++;
247
					StartPlayingMp3();
226
				StartPlayingMp3();
248
				}
227
			}
249
				else
-
 
250
				{
-
 
251
					StopPlayingMp3();
-
 
252
					DrawWindow();
-
 
253
				}
228
	  }
254
			}
229
   }
255
	  }
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();
256
   }
243
	}
257
}
244
}
Line 258... Line 245...
258
 
245
 
259
 
246
 
260
void DrawPlayList()
247
void DrawPlayList()
261
{
248
{
262
	int i;
249
	int i;
263
	int yyy;
-
 
264
	char temp_filename[4096];
250
	int yyy;
265
	
251
	char temp_filename[4096];
266
	for (i=0; i
252
	for (i=0; i
267
	{
253
	{
268
		strcpy(#temp_filename, files_mas[i + list.first] * 304 + buf + 72);
254
		strcpy(#temp_filename, files_mas[i + list.first] * 304 + buf + 72);
Line 305... Line 291...
305
	DrawTopPanel();
291
	DrawTopPanel();
306
	DrawPlayList();
292
	DrawPlayList();
307
}
293
}
Line 308... Line 294...
308
 
294
 
309
 
295
 
310
void StartPlayingMp3()
296
int NotifyAndBackFocus(dword msg)
311
{
-
 
312
	word i;
-
 
313
	char item_path[4096], notify_message[512];
297
{
314
	dword item_path_end_pointer;
-
 
315
	StopPlayingMp3();
-
 
316
 
-
 
317
	if (list.current > list.count)
-
 
318
	{
298
	int nid;
319
		list.current = list.count;
-
 
320
		return;
299
	nid = notify(msg);
321
	}
-
 
322
	if (!list.count)
300
	pause(5);
323
	{
301
	Form.num_slot = GetProcessSlot(Form.ID);
324
		notify_run_id = notify("'Pixie Player\nStopped, no file specified' -St");
302
	if (Form.ID) ActivateWindow(Form.num_slot);
Line 325... Line -...
325
		return;
-
 
Line -... Line 303...
-
 
303
	return nid;
-
 
304
}
-
 
305
 
-
 
306
 
-
 
307
void StartPlayingMp3()
-
 
308
{
-
 
309
	word i;
-
 
310
	char item_path[4096];
-
 
311
	char notify_message[512];
326
	}
312
	StopPlayingMp3();
327
 
-
 
328
	current_playing_file_n = list.current;
313
	if (!list.count) { NotifyAndBackFocus("'Pixie Player\nPress O key to open file' -St"); return; }
329
 
-
 
330
	playback_mode = PLAYBACK_MODE_PLAYING;
-
 
331
 
-
 
332
	strlcpy(#current_filename, GetCurrentItemName(), sizeof(current_filename));
314
	if (current_playing_file_n > list.count) { current_playing_file_n = list.count; return; }
333
	strcpy(#item_path, "\"");
-
 
334
	strcat(#item_path, #work_folder);
-
 
335
	strcat(#item_path, "/");
315
	if (current_playing_file_n < 0) { current_playing_file_n = 0; return; }
336
	strcat(#item_path, #current_filename);
316
	playback_mode = PLAYBACK_MODE_PLAYING;
337
	strcat(#item_path, "\"");
-
 
338
 
-
 
339
	DrawPlayList();
317
	strlcpy(#current_filename, GetCurrentItemName(), sizeof(current_filename));
340
	DrawTopPanel();
-
 
341
 
318
	sprintf(#item_path,"\"%s/%s\"",#work_folder,#current_filename);
342
	item_path_end_pointer = #item_path+strlen(#item_path);
319
	DrawPlayList();
343
	if (strcmpi(item_path_end_pointer-4,".mp3")!=0)	player_run_id = RunProgram(abspath("minimp3"), #item_path);	
-
 
344
	strcpy(#notify_message, "'Now playing:\n");
320
	DrawTopPanel();
345
	strcat(#notify_message, #current_filename);
321
	if (strcmpi(#item_path+strlen(#item_path)-4,".mp3")) player_run_id = RunProgram(abspath("minimp3"), #item_path);	
Line 346... Line -...
346
	for (i=2; i
-
 
347
	strcat(#notify_message, "' -St");
-
 
348
	notify_run_id = notify(#notify_message);
-
 
349
}
-
 
350
 
-
 
351
 
322
	sprintf(#notify_message,"'Now playing:\n%s' -St",#current_filename);
352
void DrawInactivePlayButton()
323
	for (i=2; i
353
{
324
	notify_run_id = NotifyAndBackFocus(#notify_message);
354
	img_draw stdcall(skin.image, 13, 0, 22, skin.h, 300, 0);
325
}
355
}
326
 
356
 
327
 
357
void DrawWindow() {
328
void draw_window() {
358
	GetProcessInfo(#Form, SelfInfo);
329
	GetProcessInfo(#Form, SelfInfo);
359
	DrawTopPanel();
330
	DrawTopPanel();
360
	IF (Form.status_window>=2) return;
331
	IF (Form.status_window>=2) return;
Line 361... Line -...
361
	if (window_mode == WINDOW_MODE_NORMAL)
-
 
362
	{
332
	if (window_mode == WINDOW_MODE_NORMAL)
363
		DrawListBorder(0, skin.h-1, skin.w-1, list.h+1, theme.color_list_border);
333
	{
364
		DrawPlayList();
334
		DrawListBorder(0, skin.h-1, skin.w-1, list.h+1, theme.color_list_border);
365
	}
335
		DrawPlayList();
366
}
336
	}
367
 
337
}
368
 
338
 
369
void DrawTopPanel()
339
void DrawTopPanel()
370
{
340
{
371
	char current_playing_title[245];
341
	char current_playing_title[245];
372
	img_draw stdcall(skin.image, 0, 0, Form.width - 14, skin.h, 0, 0);
342
	img_draw stdcall(skin.image, 0, 0, Form.width - 14, skin.h, 0, 0);
Line 398... Line 368...
398
void DrawScroller()
368
void DrawScroller()
399
{
369
{
400
	scroll1.max_area = list.count;
370
	scroll1.max_area = list.count;
401
	scroll1.cur_area = list.visible;
371
	scroll1.cur_area = list.visible;
402
	scroll1.position = list.first;
372
	scroll1.position = list.first;
403
 
-
 
404
	scroll1.all_redraw = 0;
373
	scroll1.all_redraw = 0;
405
	scroll1.start_x = skin.w - scroll1.size_x - 1;
374
	scroll1.start_x = skin.w - scroll1.size_x - 1;
406
	scroll1.start_y = list.y-1;
375
	scroll1.start_y = list.y-1;
407
	scroll1.size_y = list.h+2;
376
	scroll1.size_y = list.h+2;
408
 
-
 
409
	if (list.count > list.visible) scrollbar_v_draw(#scroll1);
377
	if (list.count > list.visible) scrollbar_v_draw(#scroll1);
410
}
378
}
Line 411... Line 379...
411
 
379
 
412
void DrawListBorder(dword x,y,w,h,color1)
380
void DrawListBorder(dword x,y,w,h,color1)