-
Notifications
You must be signed in to change notification settings - Fork 0
/
xmp.cpp
4026 lines (3908 loc) · 116 KB
/
xmp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "inc/version.cpp"
const char endl='\n'; //gcc3 fstream bug fix
char text[150]; //id3 main
static unsigned long duration=0; //duration
int nrscr=0; //the screen size, normal terminal 16
int min,sec; //duration main
int vol=90,pcm=90,balance=50; //volumes
int n,n2; //nr of files in playlist, n2 for search
int reread=1; //reread playlist befor pressing a key
bool paused=false; //paused ?
int n1=0; //?
int v=50; //?
bool rnext=true; //random next
int autoplay=false; //-p parameter
char playlistfile[1000], def_playlist[1000]; //playlist filename with path
char memstring[1000]; //memory string, for readstring
char prev[1000][1000]; //previous songs list
int nr_prev=-1; //nr of previous songs
int playerror=0; //error on play
int musicfile = -1;
int nocolor=0; //--nocolors parameter
char mpegfile[1000][1000]; //files
int mpegnumber=-1; //nr of files
char path[1000]; //player path
int nclose=0; //"0" key function
int more=0; //scrolling down
char upcase[100]; //uppercase result
char eypl[100]; //playlist name
int tunknown,thour,tmin,tsec; //total time
int m=0,k=0,l=0; //playlist variables
int nrcols=78,old_nrcols=78; //number of colums of screen
//char consmsg[1000][5000]; //console messages
int nr_consmsg=0; //number of console messages
char strtmp[100]; //temp string
char fs_command[9][100]; //fs commands
int scr_autodetect=1; //audetect screen
int init_text; //init text, ... [press h for help]
char timeformat[10]; // the clock display format
int nr_timeformat=5; //number of clock display formats
int current_timeformat=1; //the current clock format
int timeformat_size; //the size of the clock display
int password=0; //password mode on/off
char passwordstr[100]; //password string
int curent_playlist_nr=-1; //nr of current position in playlist
int dx=4; //x value for control panel display, defaul 4, depends on "Next Song"
int status_bar=0; //status bar display type, 0 normal, 1 next song, 2 filter, 3 radio time, 4 shutdown time, default 0
int quit=0; //quit varable, used for "Shut Down" mode, 0 don't quit, 1 quit
long songs=0; //nr of played songs
long secs=0; //nr of seconds played
long n_songs=0; //nr of played songs during the last session
long n_secs=0; //nr of seconds played during the last session
int nolines=0; //remap acs characters to skip ncurses terminal bug
signed char imported_eq_preset[9]; //equalizer imported data
char exported_eq_preset[9]; //equalizer exported data
int filternr=-1; //nr of files in filter
int save_pos=0; //used for save playlist position
int persistent_filter=0; //persistent filter=1, nonpersistent=0, delault=0
char list_result=0; // result of list_with_key
int new_start=0; // new configuration at startup, default
int refresh_curent=0; //after I, refresh curent position
int radio=0; //radio mode;
int auto_equ=0; //automatic eq load, after song genre
int auto_goto=0; //auto goto current song
int song_changed; //song was changed by playnext
int fake_lines=0; //fake lines indicator. for readstring_with_key
char the_time[256]; //current time variable, used for displaying the time in messages (cursor problem)
int cursor_moved=0; //indicates wheater the cursor has been moevd
int writetime=0; //write the time now (yes/no), used for resettome
char ok_char='.'; //bad chars replacement character
int screen=0; //screen active
int screensaver_time=3; //screen saver time
int showhello=0; // show the welcome screen or not
int show_to_logs=0; //save debug to console and show it on syslog
int try_again=0; //if playnext failed, try again after getting keys
char text_format[150]="%a - %s"; //format of files in playlist (text content)
int show_playlist_numbers=1; //show the playlist numbers (1=yes, 0 no)
int use_id3_plus=1; //use id3 plus information (1=yes, 0=no)
int shut_down_timer=30; //time to shutdown, time for warning
int sysinfo=-1; //whether the system info exists (-1=no)
char mesaj[200]; //string for actually displaying messages
const unsigned int max_mesaje=5000; //max nr. of characters in mesaje
char mesaje[max_mesaje]; //string for messages
int pos_mesaj=0; //current position in message
int sys_clock=0; //nr of interrupts (messages)
int clock_speed=14; //speed of the "clock" - used for displaying the messages (mesaje)
const int nr_mesaje_afisate=7;
int mesaje_afisate[nr_mesaje_afisate]; //displayed "auto" messages, used for random display - 0 - current song, 1 - next song, 2 - date, 3 - paused
int afiseaza_acum=-1; //directly queue a message
int stopped=1; // is the player stopped ?
int ultimul_mesaj_afisat=-1; // the last message queued, it is used in order not to repeat the same message one after the other
const char whats_new_file[100] = "/usr/lib/linuxeyes/linuxeyes.whats-new"; // the what's new file name
char messagesfile[1000]; // the file where to store the messages
int ultimul_mesaj_din_lista_afisat=-1; //the last message from the file that was shown, used for random display
int show_system_messages=1; // display system status in messages bar
int show_file_messages=1; // display file messages in messages bar
int refreshlist_position=-1; //if > 0 does the playlist refresh during messages calls
char *str_memout;
//timevar_type radio_on, radio_off; //radio mode times
//timevar_type sleeptime; // time to shut down for sleep mode
#define VUMETER_OFF 0
#define VUMETER_LEDS 1
#define VUMETER_LED_RGB 2
int vumeter = VUMETER_OFF;
const char playlist_type[7]="LEPZ11";
struct read_text
{
char text[1000];
};
typedef char list_type[1000][1000]; //presets list
typedef char list[200][30];
list genres = {
"Blues", "Classic Rock", "Country", "Dance", "Disco", "Funk", "Grunge",
"Hip-Hop", "Jazz", "Metal", "New Age", "Oldies", "Other", "Pop", "R&B",
"Rap", "Reggae", "Rock", "Techno", "Industrial", "Alternative", "Ska",
"Death Metal", "Pranks", "Soundtrack", "Euro-Techno", "Ambient",
"Trip-Hop", "Vocal", "Jazz+Funk", "Fusion", "Trance", "Classical",
"Instrumental", "Acid", "House", "Game", "Sound Clip", "Gospel",
"Noise", "AlternRock", "Bass", "Soul", "Punk", "Space", "Meditative",
"Instrumental Pop", "Instrumental Rock", "Ethnic", "Gothic",
"Darkwave", "Techno-Industrial", "Electronic", "Pop-Folk",
"Eurodance", "Dream", "Southern Rock", "Comedy", "Cult", "Gangsta",
"Top 40", "Christian Rap", "Pop/Funk", "Jungle", "Native American",
"Cabaret", "New Wave", "Psychadelic", "Rave", "Showtunes", "Trailer",
"Lo-Fi", "Tribal", "Acid Punk", "Acid Jazz", "Polka", "Retro",
"Musical", "Rock & Roll", "Hard Rock", "Folk", "Folk-Rock",
"National Folk", "Swing", "Fast Fusion", "Bebob", "Latin", "Revival",
"Celtic", "Bluegrass", "Avantgarde", "Gothic Rock", "Progressive Rock",
"Psychedelic Rock", "Symphonic Rock", "Slow Rock", "Big Band",
"Chorus", "Easy Listening", "Acoustic", "Humour", "Speech", "Chanson",
"Opera", "Chamber Music", "Sonata", "Symphony", "Booty Bass", "Primus",
"Porn Groove", "Satire", "Slow Jam", "Club", "Tango", "Samba",
"Folklore", "Ballad", "Power Ballad", "Rhythmic Soul", "Freestyle",
"Duet", "Punk Rock", "Drum Solo", "A Capella", "Euro-House", "Dance Hall","Unknown"
};
typedef struct f_list // type of functions list
{
int key[10];
int id;
};
f_list keys[27] = { // list of functions
{{10,-1,-1,-1,-1},0}, //Enter
{{27,-1,-1,-1,-1},1}, //ESC
{{27,91,65,-1,-1},2}, //Up
{{27,91,66,-1,-1},3}, //Down
{{27,91,68,-1,-1},4}, //Left
{{27,91,67,-1,-1},5}, //Right
{{27,91,71,-1,-1},6}, //Numpad "5"
{{27,91,50,126,-1},7}, //Insert
{{27,91,51,126,-1},8}, //Delete
{{27,91,49,126,-1},9}, //Home
{{27,91,52,126,-1},10}, //End
{{27,91,53,126,-1},11}, //PgUp
{{27,91,54,126,-1},12}, //PgDn
{{9,-1,-1,-1,-1},13}, //TAB
{{27,91,91,65,-1},14}, //F1
{{27,91,91,66,-1},15}, //F2
{{27,91,91,67,-1},16}, //F3
{{27,91,91,68,-1},17}, //F4
{{27,91,91,69,-1},18}, //F5
{{27,91,49,55,126},19}, //F6
{{27,91,49,56,126},20}, //F7
{{27,91,49,57,126},21}, //F8
{{27,91,50,48,126},22}, //F9
{{27,91,50,49,126},23}, //F10
{{27,91,50,51,126},24}, //F11
{{27,91,50,52,126},25} //F12
};
int nr_keys=26; //nr of elements in keys
list time_display = {
"Don't display", " 09:00 PM", " 09:00:00 PM", " 21:00", " 21:00:00"
};
// id3 tag structure
struct mpeg_id3 {
char song[31];
char artist[31];
char album [31];
char year[5];
char comment[31];
char track;
signed char genre;
int type;
char plus[30];
} my_id3;
// function forward
void messages();
void play(char *name);
void stop();
void savelist(char *file,int t);
int add_mesaje (char *s);
void add_console_message(char *s);
int saveconfig();
//#include "inc/mpg123.cpp"
//#include "player.h"
//#include "decoder.h"
//#include "file_input.h"
//#include "mpeg_codec.h"
#include "bass.h"
#include <stdlib.h>
#include <wiringPi.h>
#include <stdio.h>
#include <time.h>
#include <curses.h>
#include <string.h>
#include <fstream>
#include <dirent.h>
#include <unistd.h>
#include "inc/misc.cpp"
#include <ctype.h>
#include <sys/stat.h>
#include <syslog.h>
#include <sys/utsname.h>
#include <zlib.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/msg.h>
time_t currenttime; //current time
time_t last_key_time; //time when the last key was pressed
struct utsname computer;
struct LE_sleep_type
{
char time[10]; //time variable def
int mode; // on/off mode (1=on, 0=off)
} le_sleep,radio_on,radio_off;
void showid3 (char *name, int shadow);
void label (int y, int x, char *text, int l);
void labelw (WINDOW *w, int y, int x, char *text, int l);
int readstring(WINDOW *w,int j,int i ,unsigned int l,char *text, char pass);
int readstring_window(char *wintitle, char *title, int shadow, char pass, int path);
int readstring_with_key(WINDOW *w,int j,int i, int l, int maxl, read_text *text, char pass, char *chars, int active);
int list_with_key(WINDOW *w,int j,int i, unsigned int l, int min, int max, char res, list lista, int active);
int list_nr_with_key(WINDOW *w,int j,int i, unsigned int l, int min, int max, int &res, int active);
int check_with_key(WINDOW *w,int j,int i, char *text, int &res, int active);
int button_with_key(WINDOW *w,int j,int i, char *text, int &res, int active);
void save_equ();
void restore_equ();
void set_equ(char *preset);
void load_id3_plus_equ(char *id3_plus, int unde);
void load_id3_plus_tag(char *id3_plus, int unde);
void show_msg (char *message);
int show_timer (char *message, int timp);
void addfile(char *file_);
static const struct {
int acscode;
int character;
} acs_approx [] = {
{ 'q', '-' }, /* ACS_HLINE */
{ 'x', '|' }, /* ACS_VLINE */
{ 'l', '+' }, /* ACS_ULCORNER */
{ 'k', '+' }, /* ACS_URCORNER */
{ 'm', '+' }, /* ACS_LLCORNER */
{ 'j', '+' }, /* ACS_LRCORNER */
{ 'a', '#' }, /* ACS_CKBOARD */
{ 'u', '+' }, /* ACS_RTEE */
{ 't', '+' }, /* ACS_LTEE */
{ 'w', '+' }, /* ACS_TTEE */
{ 'v', '+' }, /* ACS_BTEE */
{ 'n', '+' }, /* ACS_PLUS */
{ '-', '^' }, /* ACS_UARROW */
{ '.', 'v' }, /* ACS_DARROW */
{ ',', '<' }, /* ACS_LARROW */
{ '+', '>' }, /* ACS_RARROW */
{ 0, 0 } };
int char_ok (char x)
{
int f=0;
if ((x>=32) && (x<=126)) f=1;
else f=0;
if (fake_lines==0) f=1;
return f;
}
void fakelines ()
{
for (int i = 0; acs_approx[i].acscode != 0; i++)
{
acs_map[acs_approx[i].acscode] = acs_approx[i].character;
}
fake_lines=1;
}
// ---------------
int getkey (int v)
{
if (v==ERR) return -1;
int nr_v=-1;
int function=-1;
int set_of_keys[10];
int limit = 3;
// mvprintw (1,1," ");
// mvprintw (1,1,"T:");
int g=0;
do
{
while (v!=ERR && nr_v < limit-1)
{
nr_v++;
set_of_keys[nr_v]=v;
// mvprintw (1,3+nr_v*4,"%d",v);
if (nr_v < limit-1) v=getch();
}
for (int i=0;(i<nr_keys) && (!g);i++)
{
g=1;
for (int j=0;j<=nr_v;j++) if (set_of_keys[j]!=keys[i].key[j]) g=0;
if (g) function=keys[i].id;
}
if (!g)
{
limit++;
v=getch ();
}
}
while (v!=ERR && !g);
// mvprintw (2,1," Function: %d ",function);
if (function!=-1) return 10000+function;
else if (nr_v==1) return 20000+set_of_keys[1];
else return set_of_keys[0];
}
int add_mesaje (char *s)
{
if (strlen (mesaje)+strlen (s)+9<max_mesaje)
{
strcat (mesaje," *** ");
strcat (mesaje,s);
} else return 0;
return 1;
}
struct controlfiles
{
char name[1000];
char artist[31];
char song[31];
char text[150];
int min;
int sec;
int tag;
}curent,next; //current song and next song info
struct files
{
char name[1000];
char text[150];
int min;
int sec;
int tag;
}filelist[10000],temp; //filelist, temp list
struct
{
char text[200];
int nr;
}filterlist[10000];
char filesfilter[10000][1000];
// Backspace thing - not used yet
typedef struct nextlist_type
{
char name[1000];
nextlist_type *next;
};
typedef nextlist_type *pnextlist;
// ----------------------
struct
{
signed char left;
signed char right;
} eq;
//XA_Control *player;
//XA_EqualizerInfo equalizer, def_eq;
int fileexists (char *file)
{
int e;
e=access (file,R_OK);
if (e==0)
{
struct stat BUF;
stat (file,&BUF);
if (S_ISDIR(BUF.st_mode) != 0) e=0;
else e=1;
}
else e=0;
return e;
}
void rtrim (char *s, unsigned int max)
{
if (s!=NULL)
{
if (strlen (s)<max) max=strlen (s);
int i=max+1;
int found=0;
do
{
i--;
if ((s[i]==0) || (s[i]==32))
{
max--;
} else found=1;
} while ((i!=0) && (!found));
s[max+1]='\0';
} else s[0]='\0';
}
void split_id3 (mpeg_id3 *id3_tag, char *tag_str)
{
int i=0;
for (i=3;i<=32;i++)
{
id3_tag->song[i-3]=tag_str[i];
}
for (i=33;i<=62;i++)
{
id3_tag->artist[i-33]=tag_str[i];
}
for (i=63;i<=92;i++)
{
id3_tag->album[i-63]=tag_str[i];
}
for (i=93;i<=96;i++)
{
id3_tag->year[i-93]=tag_str[i];
}
for (i=97;i<=126;i++)
{
id3_tag->comment[i-97]=tag_str[i];
id3_tag->plus[i-97]=tag_str[i];
}
if (id3_tag->genre < 0) id3_tag->genre=126;
if (id3_tag->genre > 125) id3_tag->genre=126;
if (id3_tag->comment[28]==0)
{
id3_tag->track=id3_tag->comment[29];
id3_tag->type=11;
}
else
{
id3_tag->track='\0';;
id3_tag->type=1;
}
if ((id3_tag->plus[0]=='\0') && (id3_tag->plus[1]==-7)) id3_tag->type=14;
rtrim (id3_tag->song,30);
rtrim (id3_tag->artist,30);
rtrim (id3_tag->album,30);
rtrim (id3_tag->year,4);
rtrim (id3_tag->comment,30);
}
void write_id3 (mpeg_id3 id3_tag, char *file)
{
char id3[128],s[3];
int e=0;
strcpy (id3,"TAG");
int i=0;
for (i=3;i<=32;i++)
{
id3[i]=id3_tag.song[i-3];
}
for (i=33;i<=62;i++)
{
id3[i]=id3_tag.artist[i-33];
}
for (i=63;i<=92;i++)
{
id3[i]=id3_tag.album[i-63];
}
for (i=93;i<=96;i++)
{
id3[i]=id3_tag.year[i-93];
}
for (i=97;i<=126;i++)
{
id3[i]=id3_tag.comment[i-97];
}
if (id3_tag.track>0)
{
id3[125]='\0';
id3[126]=id3_tag.track;
}
id3[127]=id3_tag.genre;
if (id3_tag.type==14)
for (i=97;i<=124;i++)
{
id3[i]=id3_tag.plus[i-97];
} else if (id3[98]==-7) id3[98]=0;
FILE *f;
f=fopen (file,"r+");
if (f!=NULL)
{
fseek (f,-128,SEEK_END);
if (fread (&s,3,1,f)==1)
{
if (memcmp (s,"TAG",3)==0)
if (id3_tag.type!=0)
{
fseek (f,-128,SEEK_END);
if (fwrite (id3,128,1,f)==1) e=1;
}
else
{
fseek (f,0,SEEK_END);
e=truncate (file,ftell(f)-128)+1;
}
else if (id3_tag.type!=0)
{
fseek (f,1,SEEK_END);
if (fwrite (id3,128,1,f)==1) e=1;
}
}
if (e==1)
fclose (f);
}
if (e!=1)
{
show_msg ("Could not write ID3 Tag");
char temp[1000];
strcpy (temp,"Could not write ID3 TAG to ");
if (file!=NULL) strcat (temp,file);
if (file!=NULL) add_console_message (temp);
} else
{
char temp[1000];
strcpy (temp,"ID3 TAG wrote to ");
if (file!=NULL) strcat (temp,file);
if (file!=NULL) add_console_message (temp);
}
}
int id3 (char *name, mpeg_id3 *my_id3)
{
/* XA_DecoderInfo *decoder;
XA_InputModule module;
XA_CodecModule codec;
decoder_new (&decoder);
file_input_module_register(&module);
decoder_input_module_register(decoder, &module);
mpeg_codec_module_register(&codec);
decoder_codec_module_register(decoder, &codec);
decoder_input_new(decoder, name,XA_DECODER_INPUT_AUTOSELECT);
decoder_input_open(decoder);
if (decoder->status->info.duration != duration) duration = decoder->status->info.duration;
duration=duration / 1000;
min=duration / 60;
sec=duration % 60;
decoder_input_close(decoder);
decoder_delete (decoder); */
int namefile = BASS_StreamCreateFile (FALSE, name, 0, 0, 0);
if (namefile != -1)
{
int d = BASS_ChannelBytes2Seconds(namefile, BASS_ChannelGetLength (namefile, BASS_POS_BYTE));
min = d/60;
sec = d%60;
// min = 10;
// sec=10;
BASS_StreamFree (namefile);
}
strcpy (text,"");
FILE *f;
int tag=0;
char tag_str[128];
f=fopen (name,"r");
if (f!=NULL)
{
fseek (f,-128,SEEK_END);
if (fread (&tag_str,128,1,f)==1) tag=1;
fseek (f,-1,SEEK_END);
int t;
fread (&t,1,1,f);
my_id3->genre=t;
fclose (f);
}
if (tag)
{
if (memcmp (tag_str,"TAG",3)==0)
{
split_id3 (my_id3,tag_str);
if (strcmp(my_id3->artist,"")==0) strcpy (my_id3->artist,"Unknown Artist");
if (strcmp(my_id3->song,"")==0) strcpy (my_id3->song,"Unknown Song");
if (!fileexists(name))
{
strcpy (my_id3->artist,"Unknown");
strcpy (my_id3->song,"Unknown");
}
strcpy (text,"");
for (unsigned int i=0;(i<=strlen (text_format)) && (strlen(text)<=150);i++)
{
if ((text_format[i]=='%') && (i<strlen (text_format)))
{
if (text_format[i+1]=='1')
{
char s[3];
sprintf (s,"%d",my_id3->track);
strcat (text,s);
}
if (text_format[i+1]=='t')
{
char s[3];
sprintf (s,"%d",my_id3->track);
strcat (text,s);
}
if (text_format[i+1]=='2') strcat (text,my_id3->artist);
if (text_format[i+1]=='3') strcat (text,my_id3->song);
if (text_format[i+1]=='4') strcat (text,my_id3->album);
if (text_format[i+1]=='5') strcat (text,my_id3->year);
if (text_format[i+1]=='6') strcat (text,genres[my_id3->genre]);
if (text_format[i+1]=='7') strcat (text,my_id3->comment);
if (text_format[i+1]=='8') strcat (text,name);
if (text_format[i+1]=='a') strcat (text,my_id3->artist);
if (text_format[i+1]=='s') strcat (text,my_id3->song);
if (text_format[i+1]=='A') strcat (text,my_id3->album);
if (text_format[i+1]=='y') strcat (text,my_id3->year);
if (text_format[i+1]=='g') strcat (text,genres[my_id3->genre]);
if (text_format[i+1]=='c') strcat (text,my_id3->comment);
if (text_format[i+1]=='f') strcat (text,name);
if (text_format[i+1]=='%') strcat (text,"%");
i++;
}
else strncat (text,&text_format[i],1);
}
/* strcpy (text,my_id3->artist);
strcat (text," - ");
strcat (text,my_id3->song);*/
}
else tag=0;
}
if (tag==0)
{
strcpy (my_id3->artist,"Unknown Artist");
strcpy (my_id3->song,"Unknown Song");
strcpy (my_id3->album,"");
strcpy (my_id3->year,"");
strcpy (my_id3->comment,"");
my_id3->genre=126;
}
if (((strcmp(my_id3->artist,"Unknown")==0) && (strcmp(my_id3->song,"Unknown")==0) || (strcmp(my_id3->artist,"Unknown Artist")==0) && (strcmp(my_id3->song,"Unknown Song")==0)) && (name!=NULL))
{
tag=0;
unsigned int pos=0,ext=0,i;
char *s;
char *ridx;
s=strdup(name);
if (s[0]=='.') ext=0;
else
{
ridx=rindex (s,'.');
if (ridx!=NULL) ext=strlen(ridx);else ext=0;
}
ridx=rindex (s,'/');
if (ridx!=NULL) pos=strlen(name)-strlen(ridx)+1; else pos=strlen (name)+1;
for (i=pos;i<=strlen(name)-ext;i++) s[i-pos]=s[i];
s[i-pos-1]='\0';
// fprintf (stderr,"%s %d %d\n\r",name,pos,ext);
//getch();
strncpy(text,s,149);
if (strlen (s) > 149) text[149]='\0'; else text[strlen(s)]='\0';
// strcpy(text,(char*)(rindex(name,'/')+1));
}
return tag;
}
void sort(int l,int r)
{
int i=l;
int j=r;
char y[200];
strcpy (y,"");
strcpy (y,filelist[(l+r) / 2].text);
do
{
while (strcasecmp(filelist[i].text,y) < 0) i++;
while (strcasecmp(filelist[j].text,y) > 0) j--;
if (i <= j)
{
temp=filelist[i];
filelist[i]=filelist[j];
filelist[j]=temp;
i++;
j--;
}
}
while (i <= j);
if (l < j) sort (l,j);
if (i < r) sort (i,r);
}
void sort_filter(int l,int r)
{
int i=l;
int j=r;
char y[1000];
char temp[1000];
strcpy (y,"");
strcpy (y,filesfilter[(l+r) / 2]);
do
{
while (strcmp(filesfilter[i],y) < 0) i++;
while (strcmp(filesfilter[j],y) > 0) j--;
if (i <= j)
{
strcpy (temp,filesfilter[i]);
strcpy (filesfilter[i],filesfilter[j]);
strcpy (filesfilter[j],temp);
i++;
j--;
}
}
while (i <= j);
if (l < j) sort_filter (l,j);
if (i < r) sort_filter (i,r);
}
int infilter (char *name)
{
int l=0, r=filternr;
int y;
int res=0;
char str[1000];
strcpy (str,(char*)name);
if (filternr > -1)
{
do
{
y=strcmp (str,filesfilter[(l+r)/2]);
if (y==0) res=1;
if (y<0) r=(l+r)/2-1;
if (y>0) l=(l+r)/2+1;
} while ((l<=r) && (res==0));
} else res=0;
return res;
}
void delete_from_filter (char *name)
{
int l=0, r=filternr;
int y;
int res=0;
char str[1000];
strcpy (str,(char*)name);
if (filternr > -1)
{
do
{
y=strcmp (str,filesfilter[(l+r)/2]);
if (y==0) res=1;
if (y<0) r=(l+r)/2-1;
if (y>0) l=(l+r)/2+1;
} while ((l<=r) && (res==0));
} else res=0;
if (res==1)
{
int pos=(l+r)/2;
for (int i=pos+1;i<=filternr;i++) strcpy (filesfilter[i-1],filesfilter[i]);
filternr--;
sort_filter (0,filternr);
}
if (name != NULL)
{
char temp[1000];
strcpy (temp,"Deleted from filter ");
if (name!=NULL) strcat (temp,name);
if (name!=NULL) add_console_message (temp);
}
}
void add_to_filter (char *name)
{
if (name!=NULL)
if (!infilter(name))
{
filternr++;
strcpy (filesfilter[filternr],(char*)name);
sort_filter (0,filternr);
} else delete_from_filter (name);
{
char temp[1000];
strcpy (temp,"Added to filter ");
if (name!=NULL) strcat (temp,name);
if (name!=NULL) add_console_message (temp);
}
}
void uppercase (char s[100])
{
strcpy (upcase,s);
for (unsigned int i=0;i<=strlen(s);i++) upcase[i]=toupper (s[i]);
}
void le_border (WINDOW *w, int x, int y)
{
mvwhline (w,0,0,ACS_HLINE,x);
mvwhline (w,y-1,0,ACS_HLINE,x);
mvwvline (w,0,0,ACS_VLINE,y);
mvwvline (w,0,x-1,ACS_VLINE,y);
mvwaddch (w,0,0,ACS_ULCORNER);
mvwaddch (w,0,x-1,ACS_URCORNER);
mvwaddch (w,y-1,0,ACS_LLCORNER);
mvwaddch (w,y-1,x-1,ACS_LRCORNER);
}
long getcurent()
{
curent_playlist_nr=-1;
for (int i=0;i<=n;i++) if (strcmp (filelist[i].name,curent.name)==0) curent_playlist_nr=i;
return curent_playlist_nr;
}
void resettime()
{
if (screen==0)
{
setcolor (1,0);
for (int j=0;j<=nrcols+1;j++) mvprintw (0,j," ");
setcolor (3,1);
for (int j=0;j<=nrcols+1;j++) mvprintw (0,j," ");
if (init_text == 1) mvprintw (0,0,"Welcome to LinuxEyes MP3 Player v%s (%s) [press h for help]",version,v_name);
if (init_text == 0) mvprintw (0,0,"LinuxEyes MP3 Player");
setcolor (1,0);
mvprintw (dx,nrcols-7," [00:00] ");
mvprintw (dx+1,nrcols-22," [--------------------] ");
n1=-100;
old_nrcols=nrcols;
writetime=1;
}
}
void reset()
{
clear();
setcolor (3,1);
for (int j=0;j<=nrcols+1;j++)
{
mvprintw (0,j," ");
}
setcolor (1,0);
mvprintw (dx,9," ");
mvprintw (dx+1,9," ");
mvprintw (dx,1,"Artist: ");
mvprintw (dx+1,3,"Song: ");
if (curent.tag==0)
{
mvprintw (4,1," ");
label (dx+1,9,curent.text,nrcols-33);
}
else
{
mvprintw (dx,1,"Artist: ");
label (dx,9,curent.artist,nrcols-33);
mvprintw (dx+1,3,"Song: ");
label (dx+1,9,curent.song,nrcols-33);
}
resettime();
reread=1;
add_console_message ("Display was reset");
}
void position(int n)
{
// control_message_send (player,XA_MSG_COMMAND_SEEK,n1+n,100);
if (musicfile!=-1)
{
long pos = BASS_ChannelGetPosition (musicfile, BASS_POS_BYTE);
long s = BASS_ChannelBytes2Seconds (musicfile, pos);
BASS_ChannelSetPosition (musicfile, BASS_ChannelSeconds2Bytes (musicfile, s+n), BASS_POS_BYTE);
}
}
void mpegpause()
{
/*if (paused==true) control_message_send (player,XA_MSG_COMMAND_PLAY);
else
{
control_message_send (player,XA_MSG_COMMAND_PAUSE);
afiseaza_acum=3;
}*/
if (musicfile != -1)
{
afiseaza_acum=3;
if (!paused) BASS_ChannelPause (musicfile);
else BASS_ChannelPlay (musicfile, FALSE);
paused = !paused;
}
}
void position_refresh (int p)
{
filelist[p].tag=id3 (filelist[p].name,&my_id3);
strcpy(filelist[p].text,text);
filelist[p].min=min;
filelist[p].sec=sec;
}
void play (char *name)
{
init_text=0;
if (fileexists(name))
{
stop ();
playerror=0;
restore_equ();
curent.tag=id3 (name,&my_id3);
if (name!=NULL) strcpy(curent.name,(char*)name);
strcpy(curent.artist,my_id3.artist);
strcpy(curent.song,my_id3.song);
strcpy(curent.text,text);
curent.min=min;
curent.sec=sec;
if (auto_equ==1) set_equ ((char*)genres[my_id3.genre]);
//playmp3 (name);
musicfile = BASS_StreamCreateFile (FALSE, name, 0, 0, 0);
if (musicfile !=-1)
{
BASS_SetVolume ((float)vol/100);
BASS_ChannelSetAttribute (musicfile, BASS_ATTRIB_VOL, (float)pcm/100);
BASS_ChannelSetAttribute (musicfile, BASS_ATTRIB_PAN, (float)balance/50-1);
BASS_ChannelPlay (musicfile, TRUE);
}
// set position range
//control_message_send(player,XA_MSG_COMMAND_INPUT_OPEN,name);
//control_message_send (player,XA_MSG_SET_OUTPUT_VOLUME,balance,pcm,vol);
//control_message_send(player,XA_MSG_COMMAND_PLAY);
if ((my_id3.type==14) && (use_id3_plus==1)) load_id3_plus_tag(my_id3.plus,0);
if (screen==0)
{
setcolor (1,0);
for (int t=0;t<=nrcols-10;t++)
{
mvprintw (4,9+t," ");
mvprintw (5,9+t," ");
}
if (curent.tag==0)
{
mvprintw (4,1," ");
label (5,9,curent.text,nrcols-33);
}
else
{
mvprintw (dx,1,"Artist: ");
label (dx,9,curent.artist,nrcols-33);
label (dx+1,9,curent.song,nrcols-33);
}
}
resettime();
songs++;
n_songs++;
song_changed=1;
}
else playerror=1;
reread=1;
if (playerror!=1)
{
char temp[1000];
strcpy (temp,"Playing ");
if (name!=NULL) strcat (temp,name);
if (name!=NULL) add_console_message (temp);
stopped=0;
afiseaza_acum=0;
}
else
{
char temp[1000];
strcpy (temp,"Error playling ");
if (name!=NULL) strcat (temp,name);
if (name!=NULL) add_console_message (temp);