Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
6920 leency 1
//TODO
2
//repeat track
3
//edit list manually
4
 
5
#define MEMSIZE 4096 * 50
6
 
7
//===================================================//
8
//                                                   //
9
//                       LIB                         //
10
//                                                   //
11
//===================================================//
12
 
13
#include "../lib/file_system.h"
14
#include "../lib/list_box.h"
15
#include "../lib/gui.h"
7183 leency 16
#include "../lib/random.h"
7182 leency 17
#include "../lib/kfont.h"
18
#include "../lib/collection.h"
6920 leency 19
 
7049 leency 20
#include "../lib/obj/libio.h"
21
#include "../lib/obj/libimg.h"
6920 leency 22
#include "../lib/obj/libini.h"
7182 leency 23
#include "../lib/obj/proc_lib.h"
24
#include "../lib/obj/box_lib.h"
6920 leency 25
 
26
#include "../lib/patterns/libimg_load_skin.h"
27
#include "../lib/patterns/simple_open_dialog.h"
28
 
29
//===================================================//
30
//                                                   //
31
//                       DATA                        //
32
//                                                   //
33
//===================================================//
34
 
35
//simple open dialog data
36
char default_dir[] = "/rd/1";
7051 leency 37
od_filter filter2 = { 8, "MP3\0\0" };
6920 leency 38
 
7183 leency 39
#define ABOUT_MESSAGE "'Pixies Player v2.6
6920 leency 40
A tiny MP3 folder player.
41
 
42
Controls:
43
Open file: O key
44
Play/Stop: Space or P key
45
Start playing selected file: Enter
46
Goto next/previous track: Ctrl + Left/Right
47
Change sound volume: Left/Right key
7166 leency 48
Mute: M key' -td"
6920 leency 49
 
50
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};
51
 
52
proc_info Form;
53
llist list;
54
 
55
char pixie_ini_path[4096];
56
char work_folder[4096];
57
char current_filename[256];
58
 
59
enum {
60
	BUTTON_WINDOW_CLOSE = 1,
61
	BUTTON_WINDOW_MINIMIZE,
62
	BUTTON_WINDOW_REDUCE,
63
	BUTTON_PLAYBACK_PLAY_PAUSE = 10,
64
	BUTTON_PLAYBACK_PREV,
65
	BUTTON_PLAYBACK_NEXT,
7183 leency 66
	BUTTON_REPEAT,
67
	BUTTON_SHUFFLE,
6920 leency 68
	BUTTON_OPEN_DIALOG,
69
	BUTTON_SHOW_VOLUME
70
};
71
 
72
int player_run_id;
73
int notify_run_id;
74
 
7183 leency 75
bool repeat;
76
bool shuffle;
77
 
6920 leency 78
int current_playing_file_n=0;
79
 
80
word win_x_normal, win_y_normal;
81
word win_x_small, win_y_small;
82
 
83
byte window_mode;
84
enum {
85
	WINDOW_MODE_NORMAL,
86
	WINDOW_MODE_SMALL
87
};
88
 
89
byte playback_mode;
90
enum {
91
	PLAYBACK_MODE_STOPED,
92
	PLAYBACK_MODE_PLAYING
93
};
94
 
7182 leency 95
collection music_col;
96
 
6920 leency 97
//===================================================//
98
//                                                   //
99
//                       CODE                        //
100
//                                                   //
101
//===================================================//
102
 
103
#include "get_files_list.h"
104
#include "settings.h"
105
 
106
void LoadLibraries()
107
{
108
	load_dll(boxlib, #box_lib_init,0);
109
	load_dll(libio, #libio_init,1);
110
	load_dll(libimg, #libimg_init,1);
111
	load_dll(libini, #lib_init,1);
112
	load_dll(Proc_lib, #OpenDialog_init,0);
7182 leency 113
	OpenDialog_init stdcall (#o_dialog);
6920 leency 114
}
115
 
116
void main()
117
{
118
	int tempstr;
119
	tempstr = abspath("pixie.ini");
120
	strcpy(#pixie_ini_path, tempstr);
7183 leency 121
	list.SetFont(8, 16, 13);
6920 leency 122
	if (!param) notify("'Pixie Player\nPress O key to open MP3 file' -St");
123
	LoadLibraries();
124
	LoadIniConfig();
7182 leency 125
	kfont.init(DEFAULT_FONT);
126
	SetEventMask(EVM_REDRAW + EVM_KEY + EVM_BUTTON + EVM_MOUSE + EVM_MOUSE_FILTER);
6920 leency 127
	loop()
128
	{
129
	  WaitEventTimeout(10);
130
	  switch(EAX & 0xFF) {
131
	  	case evMouse:
132
			if (!CheckActiveProcess(Form.ID)) break;
133
			mouse.get();
134
			scrollbar_v_mouse (#scroll1);
135
			if (list.first != scroll1.position)
136
			{
137
				list.first = scroll1.position;
138
				DrawPlayList();
139
				break;
140
			}
141
			if (list.MouseOver(mouse.x, mouse.y))
142
			{
143
				if (mouse.vert) && (list.MouseScroll(mouse.vert)) DrawPlayList();
144
				if (mouse.dblclick) EventStartPlayingSelectedItem();
145
				if (mouse.down) && (mouse.key&MOUSE_LEFT) && (list.ProcessMouse(mouse.x, mouse.y)) DrawPlayList();
146
				if (mouse.down) && (mouse.key&MOUSE_RIGHT) notify(ABOUT_MESSAGE);
147
			}
148
			if(mouse.key&MOUSE_LEFT) && (mouse.y
149
			break;
150
		case evButton:
151
			switch(GetButtonID()) {
152
				case BUTTON_WINDOW_CLOSE: EventExitApp(); break;
153
				case BUTTON_WINDOW_MINIMIZE: MinimizeWindow(); break;
154
				case BUTTON_WINDOW_REDUCE: EventChangeWindowMode(); break;
155
				case BUTTON_PLAYBACK_PREV: EventPlaybackPrevious();	break;
156
				case BUTTON_PLAYBACK_NEXT: EventPlaybackNext(); break;
157
				case BUTTON_PLAYBACK_PLAY_PAUSE: EventPlayAndPause(); break;
7183 leency 158
				case BUTTON_REPEAT: EventRepeatClick(); break;
159
				case BUTTON_SHUFFLE: EventshuffleClick(); break;
6920 leency 160
				case BUTTON_OPEN_DIALOG: EventFileDialogOpen(); break;
161
				case BUTTON_SHOW_VOLUME: RunProgram("/sys/@VOLUME", NULL); break;
162
			}
163
			break;
164
		case evKey:
165
			GetKeys();
166
			if (key_modifier&KEY_LCTRL) || (key_modifier&KEY_RCTRL) {
167
				if (key_scancode==SCAN_CODE_LEFT) EventPlaybackPrevious();
168
				if (key_scancode==SCAN_CODE_RIGHT) EventPlaybackNext();
169
				break;
170
			}
171
			if (key_scancode==SCAN_CODE_KEY_O) EventFileDialogOpen();
172
			if (key_scancode==SCAN_CODE_KEY_M) RunProgram("/sys/@VOLUME", "m");
173
			if (key_scancode==SCAN_CODE_RIGHT) RunProgram("/sys/@VOLUME", "+");
174
			if (key_scancode==SCAN_CODE_LEFT)  RunProgram("/sys/@VOLUME", "-");
175
			if (key_scancode==SCAN_CODE_ENTER) EventStartPlayingSelectedItem();
176
			if (key_scancode==SCAN_CODE_KEY_P) || (key_scancode==SCAN_CODE_SPACE) EventPlayAndPause();
177
			if (list.ProcessKey(key_scancode)) DrawPlayList();
178
			break;
179
		case evReDraw:
7166 leency 180
			if (window_mode == WINDOW_MODE_NORMAL) DefineDragableWindow(win_x_normal, win_y_normal, skin.w - 1, skin.h + list.h-1);
6920 leency 181
			if (window_mode == WINDOW_MODE_SMALL) DefineDragableWindow(win_x_small, win_y_small, WIN_W_SMALL, WIN_H_SMALL);
182
			draw_window();
183
			if (param[0]) {
184
				EventOpenFolder(#param);
185
				param[0] = NULL;
186
			}
187
			break;
188
		default:
189
			EventCheckSongFinished();
190
	  }
191
   }
192
}
193
 
194
 
195
void DrawPlayList()
196
{
197
	int i;
198
	int yyy;
199
	char temp_filename[4096];
7182 leency 200
	dword text_color, bg_color;
6920 leency 201
	for (i=0; i
202
	{
203
		strcpy(#temp_filename, files_mas[i + list.first] * 304 + buf + 72);
7182 leency 204
		//temp_filename[strlen(#temp_filename)-4] = '\0';
205
		//if (strlen(#temp_filename)>47) strcpy(#temp_filename+44, "...");
6920 leency 206
 
207
		yyy = i*list.item_h+list.y;
208
 
209
		//this is selected file
210
		if (list.cur_y - list.first == i)
211
		{
212
			if (i>=list.count) continue;
7182 leency 213
			bg_color = theme.color_list_active_bg;
214
			text_color = theme.color_list_text;
6920 leency 215
		}
216
		//this is not selected file
217
		else
218
		{
219
			if (i>=list.count) continue;
7182 leency 220
			bg_color = theme.color_list_bg;
221
			text_color = theme.color_list_text;
6920 leency 222
		}
223
		//this is cur_y playing file
224
		if (i + list.first == current_playing_file_n) && (playback_mode == PLAYBACK_MODE_PLAYING)
225
		{
7182 leency 226
			text_color = theme.color_list_active_text;
6920 leency 227
		}
7182 leency 228
		DrawBar(list.x, yyy, list.w, list.item_h, bg_color);
7183 leency 229
		kfont.WriteIntoWindow(6, yyy+list.text_y, bg_color, text_color, list.font_type, #temp_filename);
6920 leency 230
	}
231
	DrawBar(list.x,list.visible * list.item_h + list.y, list.w, -list.visible * list.item_h + list.h, theme.color_list_bg);
232
	DrawScroller();
233
}
234
 
235
 
236
void draw_window() {
237
	GetProcessInfo(#Form, SelfInfo);
238
	DrawTopPanel();
239
	IF (Form.status_window>=2) return;
240
	if (window_mode == WINDOW_MODE_NORMAL)
241
	{
242
		DrawPlayList();
243
		DrawRectangle(0, skin.h-1, skin.w-1, list.h+1, theme.color_list_border);
244
	}
245
}
246
 
7166 leency 247
dword GetSongTitle()
248
{
249
	char cur_y_playing_title[245];
250
	strcpy(#cur_y_playing_title, #current_filename);
7182 leency 251
	//cur_y_playing_title[strlen(#cur_y_playing_title)-4] = '\0';
252
	//if (strlen(#cur_y_playing_title) > 36) strcpy(#cur_y_playing_title + 34, "...");
7166 leency 253
	return #cur_y_playing_title;
254
}
6920 leency 255
 
7166 leency 256
 
6920 leency 257
void DrawTopPanel()
258
{
7166 leency 259
 
6920 leency 260
	int button_y;
261
	//Mode depended
262
	if (window_mode == WINDOW_MODE_NORMAL)
263
	{
7182 leency 264
		button_y = 46;
6920 leency 265
		img_draw stdcall(skin.image, 0, 0, skin.w, skin.h, 0, 0);
7183 leency 266
		if (playback_mode != PLAYBACK_MODE_STOPED) img_draw stdcall(skin.image, 46, button_y, 41, 21, skin.w+1, WIN_H_SMALL+1);
267
		if (repeat) img_draw stdcall(skin.image, Form.width - 108+8, button_y, 20, 20, skin.w+50, WIN_H_SMALL+1);
268
		if (shuffle) img_draw stdcall(skin.image, Form.width - 81+5, button_y, 20, 20, skin.w+75, WIN_H_SMALL+1);
269
 
7166 leency 270
		if /*(!list.count) && */ (!work_folder) DrawPixieTitle("Pixie");
271
		else DrawPixieTitle(#work_folder + strrchr(#work_folder, '/'));
7183 leency 272
		kfont.WriteIntoWindow(8, 24, theme.color_top_panel_bg, theme.color_top_panel_song_name, list.font_type, GetSongTitle());
7166 leency 273
	 	//Playing control buttons
7183 leency 274
		DefineHiddenButton(7, button_y, 38, 20, BUTTON_PLAYBACK_PREV);
275
		DefineHiddenButton(47, button_y, 38, 20, BUTTON_PLAYBACK_PLAY_PAUSE);
276
		DefineHiddenButton(87, button_y, 38, 20, BUTTON_PLAYBACK_NEXT);
7166 leency 277
		//Window control buttons
7183 leency 278
		DefineHiddenButton(Form.width - 27, 1, 26, 15, BUTTON_WINDOW_CLOSE);
279
		DefineHiddenButton(Form.width - 55, 1, 26, 15, BUTTON_WINDOW_MINIMIZE);
280
		DefineHiddenButton(Form.width - 83, 1, 26, 15, BUTTON_WINDOW_REDUCE);
281
		//Other buttons
282
		DefineHiddenButton(Form.width - 108,button_y, 23, 23, BUTTON_REPEAT);
283
		DefineHiddenButton(Form.width - 81, button_y, 23, 23, BUTTON_SHUFFLE);
284
		DefineHiddenButton(Form.width - 54, button_y, 23, 23, BUTTON_OPEN_DIALOG);
6920 leency 285
		DefineHiddenButton(Form.width - 27, button_y, 23, 23, BUTTON_SHOW_VOLUME);
286
	}
287
	else if (window_mode == WINDOW_MODE_SMALL)
288
	{
7166 leency 289
		button_y = 7;
6920 leency 290
		img_draw stdcall(skin.image, 0, 0, WIN_W_SMALL, WIN_H_SMALL, skin.w-1, 0);
291
		DefineHiddenButton(0, 0, WIN_W_SMALL, WIN_H_SMALL, 99 + BT_NOFRAME);
7166 leency 292
	 	//Playing control buttons
293
		DefineHiddenButton(8, button_y, 24, 16, BUTTON_PLAYBACK_PREV);
294
		DefineHiddenButton(34, button_y, 24, 16, BUTTON_PLAYBACK_PLAY_PAUSE);
295
		DefineHiddenButton(60, button_y, 24, 16, BUTTON_PLAYBACK_NEXT);
296
		//Window control buttons
297
		DefineHiddenButton(Form.width - 20, 1, 19, 13, BUTTON_WINDOW_CLOSE);
298
		DefineHiddenButton(Form.width - 20, 16, 19, 13, BUTTON_WINDOW_REDUCE);
6920 leency 299
	}
300
}
301
 
302
 
303
void DrawScroller()
304
{
305
	scroll1.max_area = list.count;
306
	scroll1.cur_area = list.visible;
307
	scroll1.position = list.first;
308
	scroll1.all_redraw = 0;
309
	scroll1.start_x = skin.w - scroll1.size_x-1;
310
	scroll1.start_y = list.y-1;
311
	scroll1.size_y = list.h+2;
312
	if (list.count > list.visible) scrollbar_v_draw(#scroll1);
313
}
314
 
315
void DrawPixieTitle(dword _title)
316
{
7183 leency 317
	kfont.WriteIntoWindow(8, 5, theme.color_top_panel_bg, theme.color_top_panel_folder_name, list.font_type, _title);
6920 leency 318
}
319
 
320
//===================================================//
321
//                                                   //
322
//                     EVENTS                        //
323
//                                                   //
324
//===================================================//
325
 
326
 
327
void EventOpenFolder(dword _open_path)
328
{
329
	if (ESBYTE[_open_path])
330
	{
331
		strcpy(#work_folder, _open_path);
332
		work_folder[strrchr(#work_folder, '/')-1]='\0';
333
		OpenDirectory(#work_folder);
334
		SetOpenedFileFirst(_open_path);
335
	}
336
	list.SetSizes(1, skin.h, skin.w-1, 22*15, 22);
337
	if (list.count <= list.visible)
338
	{
339
		list.h = list.count * list.item_h;
340
		list.visible = list.count;
341
		list.w -= 1;
342
	}
343
	else
344
	{
345
		list.w -= scroll1.size_x;
346
	}
347
	MoveSize(OLD, OLD, OLD, skin.h + list.h);
348
	list.KeyHome();
349
	current_playing_file_n=0;
350
	EventStopPlayingMp3();
351
	EventStartPlayingMp3();
352
}
353
 
354
 
355
void EventStopPlayingMp3()
356
{
357
	if (player_run_id) player_run_id = KillProcess(player_run_id);
358
	if (notify_run_id) notify_run_id = KillProcess(notify_run_id);
359
	playback_mode = PLAYBACK_MODE_STOPED;
360
	DrawTopPanel();
361
	DrawPlayList();
362
}
363
 
364
 
365
void EventStartPlayingMp3()
366
{
367
	word i;
368
	char item_path[4096];
369
	char notify_message[512];
370
	EventStopPlayingMp3();
7182 leency 371
	if (current_playing_file_n >= list.count) {
372
		current_playing_file_n = list.count-1;
6920 leency 373
		return;
374
	}
375
	if (current_playing_file_n < 0) {
376
		current_playing_file_n = 0;
377
		return;
378
	}
379
	playback_mode = PLAYBACK_MODE_PLAYING;
380
	strlcpy(#current_filename, Getcur_yItemName(), sizeof(current_filename));
7177 leency 381
	sprintf(#item_path,"-h %s/%s",#work_folder,#current_filename);
6920 leency 382
	DrawPlayList();
383
	DrawTopPanel();
7182 leency 384
	player_run_id = RunProgram("/sys/media/ac97snd", #item_path);
6920 leency 385
	sprintf(#notify_message,"'Now playing:\n%s' -St",#current_filename);
7183 leency 386
	if (!repeat)
387
	{
388
		for (i=2; i
389
			if (notify_message[i]=='\'') notify_message[i]=96; //replace ' char to avoid @notify misunderstood
390
		notify_run_id = notify(#notify_message);
391
	}
6920 leency 392
}
393
 
394
 
395
void EventPlayAndPause()
396
{
397
	if (playback_mode == PLAYBACK_MODE_PLAYING)
398
	{
399
		playback_mode = PLAYBACK_MODE_STOPED;
400
		EventStopPlayingMp3();
401
	}
402
	else
403
	{
404
		playback_mode = PLAYBACK_MODE_PLAYING;
405
		EventStartPlayingMp3();
406
	}
407
}
408
 
409
 
410
void EventChangeWindowMode()
411
{
412
	if (window_mode == WINDOW_MODE_NORMAL)
413
	{
414
		window_mode = WINDOW_MODE_SMALL;
415
		win_x_normal = Form.left;
416
		win_y_normal = Form.top;
417
		MoveSize(OLD, OLD, WIN_W_SMALL-1, WIN_H_SMALL-1);
418
		MoveSize(OLD, win_y_small, OLD, OLD);
419
		MoveSize(win_x_small, OLD, OLD, OLD);
420
	}
421
	else
422
	{
423
		window_mode = WINDOW_MODE_NORMAL;
424
		win_x_small = Form.left;
425
		win_y_small = Form.top;
426
		MoveSize(win_x_normal, win_y_normal, skin.w -1 ,skin.h + list.h);
427
	}
428
}
429
 
430
void EventExitApp()
431
{
432
	EventStopPlayingMp3();
433
	SaveIniConfig();
434
	ExitProcess();
435
}
436
 
437
void EventPlaybackPrevious()
438
{
7183 leency 439
	if (shuffle) current_playing_file_n = random(list.count);
440
	else current_playing_file_n--;
6920 leency 441
	EventStartPlayingMp3();
442
}
443
 
444
void EventPlaybackNext()
445
{
7183 leency 446
	if (shuffle) current_playing_file_n = random(list.count);
447
	else current_playing_file_n++;
6920 leency 448
	EventStartPlayingMp3();
449
}
450
 
451
void EventStartPlayingSelectedItem()
452
{
453
	current_playing_file_n=list.cur_y;
454
	EventStartPlayingMp3();
455
}
456
 
457
void EventFileDialogOpen()
458
{
459
	OpenDialog_start stdcall (#o_dialog);
460
	if (o_dialog.status==1) EventOpenFolder(#openfile_path);
461
}
462
 
463
void EventCheckSongFinished()
464
{
465
	if (playback_mode == PLAYBACK_MODE_PLAYING) && (!GetProcessSlot(player_run_id)) {
7183 leency 466
		if (repeat) EventStartPlayingMp3();
467
		else EventPlaybackNext();
6920 leency 468
	}
469
}
470
 
7183 leency 471
void EventRepeatClick()
472
{
473
	repeat ^= 1;
474
	DrawTopPanel();
475
}
6920 leency 476
 
7183 leency 477
void EventshuffleClick()
478
{
479
	shuffle ^= 1;
480
	DrawTopPanel();
481
}
482
 
6920 leency 483
stop:
484
 
485
char menu_stak[4096];