-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathfunction.c
More file actions
1617 lines (1510 loc) · 45.1 KB
/
function.c
File metadata and controls
1617 lines (1510 loc) · 45.1 KB
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"function.h"
#include"face.h"
#include<stdio.h>
#include<conio.h>
#include<io.h>
#include<conio.h>
#include<windows.h>
#include"function.h"
#include"switch.h"
#include<string.h>
#include<time.h>
#include <mmsystem.h> //mci库头文件
#include "LRC.h"
#pragma warning(disable:4996)
#pragma comment(lib, "winmm.lib")
#define PATH "D:\\music\\" //路径宏定义,默认文件存放路径
int K = 0;//判断当前播放状态
int bkcolor = 0;
int textcolor = 0;
int syscolor = 0;//颜色定义为全局变量,syscolor包括界面提示,logo,歌词高亮部分等,
//textcolor包括歌词,打印歌曲列表,歌单列表等
int isFir = 0; //用于判断是否已经是第一曲
int isEnd = 0; //用于判断是否已经是最后一曲
int face1 = 0; //定义主菜单(第一个界面)logo样式
int face2 = 0; //定义其他界面logo样式
struct media //歌曲信息结构体,包括:序号,文件名
{
int num;
char name[100];
struct media* next;
};
/*
* 功能:创建所有歌曲链表
* 返回值:所有歌曲链表头
*/
struct media* CreatHead()//创建结构体链表,加载所有文件信息,返回链表头指针
{
struct media* head, * p, * q;
head = (struct media*)malloc(sizeof(struct media));
long Handle;
struct _finddata_t FileInfo;
if ((Handle = _findfirst("D:\\music\\*.mp3", &FileInfo)) == -1L)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | COMMON_LVB_UNDERSCORE);
printf("\n\t没有找到匹配的项目\n\t请将.mp3文件放入D:\\music\\文件夹中,再重新选曲播放\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
system("pause");
head = NULL;
return head;
}
else
{
int i = 1;
p = (struct media*)malloc(sizeof(struct media));
q = head;
p->num = i;
strcpy(p->name, FileInfo.name);
q->next = p;
q = p;
while (_findnext(Handle, &FileInfo) == 0)
{
i++;
p = (struct media*)malloc(sizeof(struct media));
p->num = i; strcpy(p->name, FileInfo.name);
q->next = p;
q = p;
}
p->next = NULL;
_findclose(Handle);
}
return head;
}
/*
* 功能:打印某个链表内所有信息
* 参数:某个链表头
* 返回值:该链表中节点总数
*/
int Print_List(struct media* head)//打印文件下所有.mp3文件名,并返回文件数目(传参:歌曲信息链表头节点)
{
system("CLS");
struct media* p1;
p1 = head->next;
int i = 0;
setTextcolor();
printf("\t ╔══════════════════════════════════════════════════════\n");
while (p1 != NULL)
{
printf("\t ║ %d. %s\n", p1->num, p1->name);
p1 = p1->next;
i++;
}
return i;
}
/*
* 功能:显示正在播放的歌曲
* 参数:某个链表工作指针
* 返回值:空
*/
void SongPlaying(struct media* p)//当前播放歌曲
{
if (p == NULL)return;
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
setSyscolor();
setCursorPosition(25, 27);
printf("\r%*c\r", 60, ' ');
printf("\t\t\t\t当前正在播放歌曲:%s 请欣赏", p->name);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
}
/*
* 功能:从所有歌曲选择播放歌曲
* 参数:某个链表的链表头,工作指针,最小值,该链表所含节点总数
* 调用函数:play
* 返回值:选择歌曲的指针
*/
struct media* Choose_Song(struct media* HEAD, struct media* P, int num, int max)//选择歌曲选项。传参:列表头指针,工作指针,返回值:工作指针
{
if (HEAD == NULL)//文件夹为空,头指针设为空
return HEAD;
else
{
struct media* p;//返回该工作指针
p = HEAD->next;
do
{
printf("\n\t请输入歌曲序号: ");
scanf("%d", &num);
while (getchar() != '\n')continue;//清除缓冲区,如果用户输入字符将会死循环
if (!(num > 0 && num <= max))
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED | COMMON_LVB_UNDERSCORE);
setSyscolor();
printf("\t请输入歌曲对应序号1~ %d !\n", max);
fflush(stdin);
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |
FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE);
}
} while (!(num > 0 && num <= max));//得到合法的序号
while (p->num != num) p = p->next;
if (P != NULL)Close_Play(P);
return p;
}
}
/*
* 功能:默认列表内查找歌曲(可联想搜索)
* 参数:默认列表链表的链表头,工作指针,最小值,歌曲总数
* 调用函数:Choose_Song
* 返回值:搜索歌曲的工作指针
*/
struct media* FindSong(struct media* head, struct media* p, int num, int max)
{
char str[100] = { 0 };
int i = 0;
char choice;
struct media* pCur = head->next;
system("CLS");
Print_List(head);
printf("请输入您想搜索的歌曲:");
fflush(stdin);
while ((choice = getchar()) != '\n' && choice != EOF)
continue;
gets(str);
strcat(str, "\0");
if (head != NULL)
{
pCur = head->next;
while (pCur != NULL)
{
if (strstr(pCur->name, str) != NULL) //检索到的歌曲
{
printf("\t%d.%s\n", pCur->num, pCur->name);
i++;
}
pCur = pCur->next;
}
}
if (i == 0)
{
printf("\n未找到该歌曲");
system("pause");
}
else
{
num = -1;
p = Choose_Song(head, p, num, max);
}
return p;
}
/*
* 功能:播放歌曲
* 参数:某个链表的链表头,工作指针,该链表所含节点总数
* 调用函数:SongPlaying ,progress_Display
* 返回值:空
*/
void play(struct meida* head, struct media* p, int max)
{
char cmd[100];
char pathname[100];
sprintf(pathname, "%s%s", PATH, p->name);
GetShortPathName(pathname, pathname, 50);//获取短名
sprintf(cmd, "open %s", pathname);
mciSendString(cmd, NULL, 0, NULL);
sprintf(cmd, "play %s", pathname);
mciSendString(cmd, NULL, 0, NULL);
K = 1;
SongPlaying(p);
progress_Display(head, p, max);
}
/*
* 功能:停止播放
* 参数:某个链表的工作指针
* 返回值:空
*/
void Close_Play(struct media* p)//停止播放(其实是关闭文件)
{
if (p == NULL)
{
if (ch1 != 'l')//进播放器不做操作退出时,删掉这个判断会误显示下面的提示语,所以将ch1设置为全局变量
{
setSyscolor();
printf("\n\t\t\t当前无歌曲正在播放,请选曲播放\n");
Sleep(500);
}
return;
}
char cmd[100];
char pathname[100];
sprintf(pathname, "%s%s", PATH, p->name);
GetShortPathName(pathname, pathname, 50);
sprintf(cmd, "close %s", pathname);
mciSendString(cmd, NULL, 0, NULL);
K = 0;//修改文件状态为暂停
}
/*
* 功能:暂停/继续播放歌曲
* 参数:某个链表的工作指针
* 返回值:空
*/
void Pause_Play(struct media* p)//暂停和播放合并
{
if (p == NULL)
{
setSyscolor();
printf("\n\t\t\t当前无歌曲正在播放,请选曲播放\n");
Sleep(500);
return;
}
char pathname[200];
char cmd[200];
if (K == 1)//播放状态,执行暂停
{
sprintf_s(pathname, sizeof(pathname), "%s%s", PATH, p->name); //获取地址
GetShortPathName(pathname, pathname, 50); //获取短名
sprintf_s(cmd, sizeof(cmd), "pause %s", pathname); //获取命令
mciSendString(cmd, NULL, 0, NULL); //执行
K = 0;
}
else if (K == 0)//暂停/停止状态,执行播放
{
sprintf_s(pathname, sizeof(pathname), "%s%s", PATH, p->name);
GetShortPathName(pathname, pathname, 50);
sprintf_s(cmd, sizeof(cmd), "play %s", pathname);
mciSendString(cmd, NULL, 0, NULL);
K = 1;
}
}
/*
* 功能:播放上一曲歌曲
* 参数:某个链表的链表头,工作指针
* 返回值:工作指针
*/
struct media* Last_Play(struct media* head, struct media* p)//上一曲
{
if (p == NULL)
{
setSyscolor();
printf("\n\t\t\t当前无歌曲正在播放,请选曲播放\n");
Sleep(500);
return p;
}
if (p != head->next) {
Close_Play(p);//关闭当前歌曲
struct media* q;
q = (struct media*)malloc(sizeof(struct media));
q = head->next;
while (q->next != p)q = q->next;//将指针指向上一曲
p = q;
isFir = 0;
}
else
{
if (isFir == 1) {
return p;
}
isFir = 1;
printf("\n");
printf("\t\t\t当前是第一首!");
Sleep(500);
printf("\r");
printf("\t\t\t ");
printf("\r");
printf("\n");
}
return p;//返回工作指针
}
/*
* 功能:播放下一曲歌曲
* 参数:某个链表的链表头,工作指针
* 返回值:工作指针
*/
struct media* Next_Play(struct media* head, struct media* p)//下一曲
{
if (p == NULL)
{
setSyscolor();
printf("\n\t\t\t当前无歌曲正在播放,请选曲播放\n");
Sleep(500);
return p;
}
if (p->next != NULL)
{
Close_Play(p);//关闭播放文件
p = p->next;//指针指向下一曲
isEnd = 0;
}
else
{
if (isEnd == 1) {
return p;
}
isEnd = 1;
printf("\n");
printf("\t\t\t当前是最后一首!");
Sleep(500);
printf("\r");
printf("\t\t\t ");
printf("\r");
printf("\n");
}
return p;//返回工作指针
}
/*
* 功能:减小音量
* 参数:某个链表的工作指针
* 返回值:空
*/
void VolDown(struct media* p)//音量减小(文件开始播放时默认音量为1000,每次可更改50)
{
if (p == NULL)
{
setSyscolor();
printf("\n\t\t\t当前无歌曲正在播放,请选曲播放\n");
Sleep(500);
return;
}
TCHAR cmd[256]; // 媒体命令
TCHAR volume[256]; // 音量(字符串)
int nVolume; // 音量(整型)
char pathname[100];
sprintf(pathname, "%s%s", PATH, p->name);
GetShortPathName(pathname, pathname, 50);
sprintf(cmd, "status %s volume", pathname); //pathname2为音乐的路径
mciSendString(cmd, volume, sizeof(volume), 0); // 获取当前音量至 volume 字符串中
nVolume = atoi(volume); // 字符串转化为整型
sprintf(cmd, "setaudio %s volume to %i", pathname, nVolume - 50); // 生成媒体命令,设置音量减 50
mciSendString(cmd, NULL, 0, NULL); // 执行媒体命令
}
/*
* 功能:增大音量
* 参数:某个链表的工作指针
* 返回值:空
*/
void VolUp(struct media* p)//音量增大
{
if (p == NULL)
{
setSyscolor();
printf("\n\t\t\t当前无歌曲正在播放,请选曲播放\n");
Sleep(500);
return;
}
TCHAR cmd[256]; // 媒体命令
TCHAR volume[256]; // 音量(字符串)
int nVolume; // 音量(整型)
char pathname[100];
sprintf(pathname, "%s%s", PATH, p->name);
GetShortPathName(pathname, pathname, 50);
sprintf(cmd, "status %s volume", pathname); //pathname2为音乐的路径
mciSendString(cmd, volume, sizeof(volume), 0); // 获取当前音量至 volume 字符串中
nVolume = atoi(volume); // 字符串转化为整型
sprintf(cmd, "setaudio %s volume to %i", pathname, nVolume + 50); // 生成媒体命令,设置音量减 50
mciSendString(cmd, NULL, 0, NULL); // 执行媒体命令
}
/*
* 功能:快进5s
* 参数:某个链表的工作指针
* 返回值:空
*/
void go(struct media* p)
{
if (p == NULL)
{
printf("\n\t\t\t当前无歌曲正在播放,请选曲播放\n");
Sleep(500);
return;
}
int time = Progress(p) * 1000;
int nPosition;
char position[200];
char pathname[200];
char cmd[200];
sprintf(pathname, "%s%s", PATH, p->name);
GetShortPathName(pathname, pathname, 50);//获取短名
sprintf(cmd, "status %s position", pathname);
mciSendString(cmd, position, sizeof(position), 0);
nPosition = atoi(position) + 5 * 1000;//当前位置
if (nPosition > time) {
nPosition = time;
}
sprintf(cmd, "play %s from %d", pathname, nPosition);
mciSendString(cmd, NULL, 0, NULL); // 后加5000ms
}
/*
* 功能:快退5s
* 参数:某个链表的工作指针
* 返回值:空
*/
void back(struct media* p)
{
if (p == NULL)
{
printf("\n\t\t\t当前无歌曲正在播放,请选曲播放\n");
Sleep(500);
return;
}
int itime;
int nPosition;
char position[200];
char pathname[200];
char cmd[200];
sprintf(pathname, "%s%s", PATH, p->name);
GetShortPathName(pathname, pathname, 50);//获取短名
sprintf(cmd, "status %s position", pathname);
mciSendString(cmd, position, sizeof(position), 0);
nPosition = atoi(position) - 5 * 1000;//当前位置
if (nPosition < 0) {
nPosition = 0;
}
sprintf(cmd, "play %s from %d", pathname, nPosition);
mciSendString(cmd, NULL, 0, NULL); // 后加5000ms
}
/*
* 功能:设置系统文字颜色和文本文字颜色
* 参数:空
* 返回值:空
*/
void changeColor() {
system("CLS");
printf("\n\n\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
printf("\t\t\t\t\t\t0--------------系统颜色\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 1);
printf("\t\t\t\t\t\t1--------------深蓝\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2);
printf("\t\t\t\t\t\t2--------------深绿\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 3);
printf("\t\t\t\t\t\t3--------------草绿\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4);
printf("\t\t\t\t\t\t4--------------深红\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5);
printf("\t\t\t\t\t\t5--------------紫红\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6);
printf("\t\t\t\t\t\t6--------------深黄\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
printf("\t\t\t\t\t\t7--------------白色\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8);
printf("\t\t\t\t\t\t8--------------深灰\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9);
printf("\t\t\t\t\t\t9--------------蓝色\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10);
printf("\t\t\t\t\t\t10-------------浅绿\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11);
printf("\t\t\t\t\t\t11-------------浅蓝\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12);
printf("\t\t\t\t\t\t12-------------红色\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13);
printf("\t\t\t\t\t\t13-------------玫红\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14);
printf("\t\t\t\t\t\t14-------------黄色\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15);
printf("\t\t\t\t\t\t15-------------亮白\n");
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
printf("\t\t\t\t\t╔═════════════════════════════════════╗\n");
printf("\t\t\t\t\t║ 请输入您想要改变的系统字体颜色 ║\n");
printf("\t\t\t\t\t╚═════════════════════════════════════╝\n");
scanf("%d", &syscolor);
printf("\t\t\t\t\t╔═════════════════════════════════════╗\n");
printf("\t\t\t\t\t║ 请输入您想要改变的文本字体颜色 ║\n");
printf("\t\t\t\t\t╚═════════════════════════════════════╝\n");
scanf("%d", &textcolor);
}
/*
* 功能:根据全局变量syscolor定义系统文字颜色
* 参数:空
* 返回值:空
*/
void setSyscolor()
{
switch (syscolor) {
case 0:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_BLUE);
break;
case 1:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 1); break;
case 2:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2); break;
case 3:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 3); break;
case 4:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4); break;
case 5:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5); break;
case 6:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6); break;
case 7:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); break;
case 8:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8); break;
case 9:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9); break;
case 10:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10); break;
case 11:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11); break;
case 12:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12); break;
case 13:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13); break;
case 14:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14); break;
case 15:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15); break;
}
}
/*
* 功能:根据全局变量syscolor定义文本文字颜色
* 参数:空
* 返回值:空
*/
void setTextcolor()
{
switch (textcolor) {
case 0: SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7);
break;
case 1:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 1); break;
case 2:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 2); break;
case 3:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 3); break;
case 4:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 4); break;
case 5:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 5); break;
case 6:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 6); break;
case 7:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 7); break;
case 8:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 8); break;
case 9:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 9); break;
case 10:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 10); break;
case 11:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 11); break;
case 12:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 12); break;
case 13:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 13); break;
case 14:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 14); break;
case 15:SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 15); break;
}
}
/*
* 功能:根据全局变量face1设置主菜单logo
* 参数:空
* 返回值:空
*/
void changeface1() {
system("CLS");
printf("\n\n\n");
setSyscolor();
printf("\t\t\t\t界面 0(默认) \n");
printf("\t\t\t\t╔═════════════════════════════════════════════════════════════╗\n");
printf("\t\t\t\t║ __ _______ _____ ║\n");
printf("\t\t\t\t║ / |/ / __ \\__ / ║\n");
printf("\t\t\t\t║ / /|_/ / /_/ //_ < ║\n");
printf("\t\t\t\t║ / / / / ____/__/ / ║\n");
printf("\t\t\t\t║ /_/__/_/_/__ /___ /_ ___________ _____ ______ ║\n");
printf("\t\t\t\t║ / __ \\/ __ / /__\\ \\/ ___/ / \\ \\ / ____/__ __/ ║\n");
printf("\t\t\t\t║ / /_/ / / / / / | / / / /__| | /_/_ _ / / ║\n");
printf("\t\t\t\t║ / ____/ /__/ / /___/ / /__ /___| | ____/ / / / ║\n");
printf("\t\t\t\t║ /_/ /______/_/___/_/_/___/ / | |/____ / /_/ ║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t╚═════════════════════════════════════════════════════════════╝\n");
printf("\t\t\t\t界面 1 \n");
printf("\t\t\t\t /$$$$$$$ /$$ /$$ \n ");
printf("\t\t\t\t| $$__ $$ | $$ | $$ \n ");
printf("\t\t\t\t| $$ \\ $$ /$$$$$$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ \n");
printf("\t\t\t\t| $$$$$$$//$$__ $$ /$$__ $$ /$$_____/ |____ $$ /$$_____/|_ $$_/ \n");
printf("\t\t\t\t| $$____/| $$ \\ $$| $$ | $$| $$ /$$$$$$$| $$$$$$ | $$ \n");
printf("\t\t\t\t| $$ | $$ | $$| $$ | $$| $$ /$$__ $$ \\____ $$ | $$ /$$\n");
printf("\t\t\t\t| $$ | $$$$$$/| $$$$$$$| $$$$$$$| $$$$$$$ /$$$$$$$/ | $$$$/\n");
printf("\t\t\t\t|__/ \\______/ \\_______/ \\_______/ \\_______/|_______/ \\___/ \n");
printf("\n");
printf("\t\t\t\t界面 2 \n");
printf("\n");
printf(" \t\t ██████╗ ██████╗ ██████╗ ██████╗ █████╗ ███████╗████████ \n");
printf(" \t\t ██╔══██╗██╔═══██╗██╔══██╗██╔════╝██╔══██╗██╔════╝╚══██╔══╝ \n");
printf(" \t\t ██████╔╝██║ ██║██║ ██║██║ ███████║███████╗ ██║ \n");
printf(" \t\t ██╔═══╝ ██║ ██║██║ ██║██║ ██╔══██║╚════██║ ██║ \n");
printf(" \t\t ██║ ╚██████╔╝██████╔╝╚██████╗██║ ██║███████║ ██║ \n");
printf(" \t\t ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═╝ \n\n");
printf("\t\t\t\t\t╔═════════════════════════════════════╗\n");
printf("\t\t\t\t\t║ 请输入您想要改变的系统界面样式 ║\n");
printf("\t\t\t\t\t╚═════════════════════════════════════╝\n");
scanf("%d", &face1);
}
/*
* 功能:根据全局变量face1打印主菜单logo
* 参数:空
* 返回值:空
*/
void setface1() {
switch (face1) {
case 0:
printf("\n\n\n");
printf("\t\t\t\t╔═════════════════════════════════════════════════════════════╗\n");
printf("\t\t\t\t║ __ _______ _____ ║\n");
printf("\t\t\t\t║ / |/ / __ \\__ / ║\n");
printf("\t\t\t\t║ / /|_/ / /_/ //_ < ║\n");
printf("\t\t\t\t║ / / / / ____/__/ / ║\n");
printf("\t\t\t\t║ /_/__/_/_/__ /___ /_ ___________ _____ ______ ║\n");
printf("\t\t\t\t║ / __ \\/ __ / /__\\ \\/ ___/ / \\ \\ / ____/__ __/ ║\n");
printf("\t\t\t\t║ / /_/ / / / / / | / / / /__| | /_/_ _ / / ║\n");
printf("\t\t\t\t║ / ____/ /__/ / /___/ / /__ /___| | ____/ / / / ║\n");
printf("\t\t\t\t║ /_/ /______/_/___/_/_/___/ / | |/____ / /_/ ║\n");
printf("\t\t\t\t║ ║\n");
printf("\t\t\t\t╚═════════════════════════════════════════════════════════════╝\n\n\n");
break;
case 1:
printf("\n\n\n\n\n");
printf("\t\t\t\t /$$$$$$$ /$$ /$$ \n ");
printf("\t\t\t\t| $$__ $$ | $$ | $$ \n ");
printf("\t\t\t\t| $$ \\ $$ /$$$$$$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ \n");
printf("\t\t\t\t| $$$$$$$//$$__ $$ /$$__ $$ /$$_____/ |____ $$ /$$_____/|_ $$_/ \n");
printf("\t\t\t\t| $$____/| $$ \\ $$| $$ | $$| $$ /$$$$$$$| $$$$$$ | $$ \n");
printf("\t\t\t\t| $$ | $$ | $$| $$ | $$| $$ /$$__ $$ \\____ $$ | $$ /$$\n");
printf("\t\t\t\t| $$ | $$$$$$/| $$$$$$$| $$$$$$$| $$$$$$$ /$$$$$$$/ | $$$$/\n");
printf("\t\t\t\t|__/ \\______/ \\_______/ \\_______/ \\_______/|_______/ \\___/ \n");
printf("\n\n\n\n");
break;
case 2:
printf("\n\n\n\n\n\n\n");
printf(" \t\t ██████╗ ██████╗ ██████╗ ██████╗ █████╗ ███████╗████████ \n");
printf(" \t\t ██╔══██╗██╔═══██╗██╔══██╗██╔════╝██╔══██╗██╔════╝╚══██╔══╝ \n");
printf(" \t\t ██████╔╝██║ ██║██║ ██║██║ ███████║███████╗ ██║ \n");
printf(" \t\t ██╔═══╝ ██║ ██║██║ ██║██║ ██╔══██║╚════██║ ██║ \n");
printf(" \t\t ██║ ╚██████╔╝██████╔╝╚██████╗██║ ██║███████║ ██║ \n");
printf(" \t\t ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═╝ \n\n\n\n\n");
break;
}
}
/*
* 功能:根据全局变量face2设置其他界面logo
* 参数:空
* 返回值:空
*/
void changeface2() {
system("CLS");
printf("\n\n\n");
setSyscolor();
printf("\t\t\t\t界面 0(默认) \n");
printf("\t\t _ __ _____ ___ _ _________ _____ ______ \n");
printf("\t\t / __ \\/ __ / /__\\ \\/ ___/ / \\ \\ / ____/__ __/ \n");
printf("\t\t ________________ / /_/ / / / / / | / / / /__| | /_/_ _ / / ________________ \n");
printf("\t\t/___/___/___/___/ / ____/ /__/ / /___/ / /__ /___| | ____/ / / / /___/___/___/___/ \n");
printf("\t\t /_/ /______/_/___/_/_/___/ / | |/____ / /_/ \n");
printf("\n\n");
printf("\t\t\t\t界面 1 \n");
printf("\n");
printf("\t\t\t\t /$$$$$$$ /$$ /$$ \n ");
printf("\t\t\t\t| $$__ $$ | $$ | $$ \n ");
printf("\t\t\t\t| $$ \\ $$ /$$$$$$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ \n");
printf("\t\t\t\t| $$$$$$$//$$__ $$ /$$__ $$ /$$_____/ |____ $$ /$$_____/|_ $$_/ \n");
printf("\t\t\t\t| $$____/| $$ \\ $$| $$ | $$| $$ /$$$$$$$| $$$$$$ | $$ \n");
printf("\t\t\t\t| $$ | $$ | $$| $$ | $$| $$ /$$__ $$ \\____ $$ | $$ /$$\n");
printf("\t\t\t\t| $$ | $$$$$$/| $$$$$$$| $$$$$$$| $$$$$$$ /$$$$$$$/ | $$$$/\n");
printf("\t\t\t\t|__/ \\______/ \\_______/ \\_______/ \\_______/|_______/ \\___/ \n");
printf("\n");
printf("\t\t\t\t界面 2 \n");
printf("\n");
printf(" \t\t ██████╗ ██████╗ ██████╗ ██████╗ █████╗ ███████╗████████ \n");
printf(" \t\t ██╔══██╗██╔═══██╗██╔══██╗██╔════╝██╔══██╗██╔════╝╚══██╔══╝ \n");
printf(" \t\t ██████╔╝██║ ██║██║ ██║██║ ███████║███████╗ ██║ \n");
printf(" \t\t ██╔═══╝ ██║ ██║██║ ██║██║ ██╔══██║╚════██║ ██║ \n");
printf(" \t\t ██║ ╚██████╔╝██████╔╝╚██████╗██║ ██║███████║ ██║ \n");
printf(" \t\t ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═╝ \n");
printf("\t\t\t\t\t╔═════════════════════════════════════╗\n");
printf("\t\t\t\t\t║ 请输入您想要改变的播放界面样式 ║\n");
printf("\t\t\t\t\t╚═════════════════════════════════════╝\n");
scanf("%d", &face2);
}
/*
* 功能:根据全局变量face2打印其他界面logo
* 参数:空
* 返回值:空
*/
void setface2() {
switch (face2) {
case 0:
printf("\t\t _ __ _____ ___ _ _________ _____ ______ \n");
printf("\t\t / __ \\/ __ / /__\\ \\/ ___/ / \\ \\ / ____/__ __/ \n");
printf("\t\t ________________ / /_/ / / / / / | / / / /__| | /_/_ _ / / ________________ \n");
printf("\t\t/___/___/___/___/ / ____/ /__/ / /___/ / /__ /___| | ____/ / / / /___/___/___/___/ \n");
printf("\t\t /_/ /______/_/___/_/_/___/ / | |/____ / /_/ \n");
printf("\n\n");
break;
case 1:
printf("\t\t\t\t /$$$$$$$ /$$ /$$ \n ");
printf("\t\t\t\t| $$__ $$ | $$ | $$ \n ");
printf("\t\t\t\t| $$ \\ $$ /$$$$$$ /$$$$$$$ /$$$$$$$ /$$$$$$ /$$$$$$$ /$$$$$$ \n");
printf("\t\t\t\t| $$$$$$$//$$__ $$ /$$__ $$ /$$_____/ |____ $$ /$$_____/|_ $$_/ \n");
printf("\t\t\t\t| $$____/| $$ \\ $$| $$ | $$| $$ /$$$$$$$| $$$$$$ | $$ \n");
printf("\t\t\t\t| $$ | $$ | $$| $$ | $$| $$ /$$__ $$ \\____ $$ | $$ /$$\n");
printf("\t\t\t\t| $$ | $$$$$$/| $$$$$$$| $$$$$$$| $$$$$$$ /$$$$$$$/ | $$$$/\n");
printf("\t\t\t\t|__/ \\______/ \\_______/ \\_______/ \\_______/|_______/ \\___/ \n");
break;
case 2:
printf("\n");
printf(" \t\t ██████╗ ██████╗ ██████╗ ██████╗ █████╗ ███████╗████████ \n");
printf(" \t\t ██╔══██╗██╔═══██╗██╔══██╗██╔════╝██╔══██╗██╔════╝╚══██╔══╝ \n");
printf(" \t\t ██████╔╝██║ ██║██║ ██║██║ ███████║███████╗ ██║ \n");
printf(" \t\t ██╔═══╝ ██║ ██║██║ ██║██║ ██╔══██║╚════██║ ██║ \n");
printf(" \t\t ██║ ╚██████╔╝██████╔╝╚██████╗██║ ██║███████║ ██║ \n");
printf(" \t\t ╚═╝ ╚═════╝ ╚═════╝ ╚═════╝╚═╝ ╚═╝╚══════╝ ╚═╝ \n\n");
break;
}
}
/*
* 功能:定位光标位置
* 参数:横竖坐标x,y
* 返回值:空
*/
void setCursorPosition(int x, int y) {
COORD coord;
coord.X = x;
coord.Y = y;
SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
}
/*
* 功能:获取歌曲总时长
* 参数:工作指针
* 返回值:歌曲总时长(秒)
*/
int Progress(struct media* p) {
int time;
char len[100];
char pathname[100];
char cmd[100];
sprintf(pathname, "%s%s", PATH, p->name);
GetShortPathName(pathname, pathname, 50);//获取短名
sprintf(cmd, "status %s length", pathname);
mciSendString(cmd, len, sizeof(len), NULL);//获取时间,单位为毫秒
time = atoi(len) / 1000;
return time;
}
/*
* 功能:时间/进度条/歌词显示,播放中功能接入和页面跳转
* 参数:某链表头,工作指针,链表中歌曲数量
* 调用函数:所有播放功能函数,获取时间函数,歌词生成相关函数
* 返回值:空
*/
void progress_Display(struct media* head, struct media* p, int max) {
srand((unsigned)time(NULL));
if (p == NULL) return;
int time = Progress(p); //获取歌曲总秒数
//进度条相关定义
int x = 68;
int y = 24;
double pro = 1 / (double)37;
int min = 0;
int second = 0;
int mtime = time / 60;
int stime = time % 60;
int xp = x + 6;
//歌词相关定义
LRC* heads = NULL, * p_new = NULL, * ps1 = NULL, * ps0 = NULL, * ps2 = NULL, * ps = NULL;
char* str = NULL, * lrc_buf = NULL;
char file_name[20];
int i, j, k, len;
int time_buf[5];
char* q[200];
//定位定样式打印进度条
setSyscolor();
setCursorPosition(x + 5, y);
printf("%c", '|');
setTextcolor();
for (int i = 0; i < 37; i++) {
printf("%c", '-');
}
setSyscolor();
setCursorPosition(x + 43, y);
printf("%c", '|');
setCursorPosition(x + 44, y);
printf("%02d:%02d", mtime, stime);
lrc_buf = read_file(p); //获取所有歌词指针
len = msg_deal(lrc_buf, q, "\r\n"); //分割歌词,获取每行歌词和总行数
//分割每行歌词的时间和歌词
for (int t = 0; (t >= 0) && (t <= time); t++) {
for (k = 0; k < len; k++)
{
str = q[k];
i = 0;
while (*str == '[')//把时间记录在数组里
{
time_buf[i++] = atoi(str + 1) * 60 + atoi(str + 4);
str += 10;
}
for (j = 0; j < i; j++)
{
p_new = (LRC*)malloc(sizeof(LRC));//申请新的节点
p_new->m_time = time_buf[j];
strcpy(p_new->lrc_buf, str);
heads = link_insert(heads, p_new);
}
}
if (t < heads->next->m_time + 1) {
fflush(stdout);//输出刷新
ps2 = link_search(heads, t);
if (ps2 != NULL) {
//printf("1\n");
setCursorPosition(80, 20);
setSyscolor();
printf("\r%*c\r", 60, ' ');
printf(" \t\t%s\n", ps2->lrc_buf);//打印所有时间
setCursorPosition(80, 15);
if (ps1 != NULL) {
setTextcolor();
printf("\r%*c\r", 60, ' ');
printf(" \t\t%s\n", ps1->lrc_buf);//打印所有时间
//printf("22\n");
}
setCursorPosition(80, 10);
if (ps0 != NULL) {
setTextcolor();
printf("\r%*c\r", 60, ' ');
printf(" \t\t%s\n", ps0->lrc_buf);//打印所有时间
}
ps0 = ps1;
ps1 = ps2;
}
}
setCursorPosition(x, y);
setSyscolor();
printf("%02d:%02d", min, second);
second++;
if (second == 60) {
second = 0;
min++;
}
double num = 0;
double pro1 = ((double)t / (double)time);
for (; num < 37; num++) {
if ((pro1 >= (num * pro)) && (pro1 <= ((num + 1) * pro))) {
setCursorPosition(xp + num, y);
printf("%c", '>');
break;
}
}
for (int j = 0; j < 5; j++) {
Sleep(190);
if (GetKeyState(VK_SPACE) < 0) {//暂停
Pause_Play(p);
setbuf(stdin, NULL);
setCursorPosition(x, y + 1);
char a = getchar();
Pause_Play(p);
}
else if (GetKeyState(VK_RETURN) < 0) { //停止
Close_Play(p);
return;
}
else if (GetKeyState(VK_UP) < 0) { //上一曲
p = Last_Play(head, p);
if (isFir == 0) {
play(head, p, max);
}
}
else if (GetKeyState(VK_DOWN) < 0) { //下一曲
p = Next_Play(head, p);
if (isEnd == 0) {
play(head, p, max);
}
}
else if (GetKeyState(VK_OEM_PLUS) < 0) { //音量+
VolUp(p);
}
else if (GetKeyState(VK_OEM_MINUS) < 0) { //音量-
VolDown(p);
}
else if (GetKeyState(VK_TAB) < 0) { //跳到另一个页面
chooseSong2(head, p);
}
else if (GetKeyState(VK_RIGHT) < 0) { //快进
go(p);
second += 5;
if (second >= 60) {
second = second - 60;
min++;
if ((min == mtime && second > stime) || (min > mtime)) {
min = mtime;
second = stime;
}
}
t += 5;
if (t > time) {
t = time;
}
pro1 = ((double)t / (double)time);
for (; num < 37; num++) {
if ((pro1 >= (num * pro)) && (pro1 <= ((num + 1) * pro))) {
setCursorPosition(xp + num, y);
setSyscolor();
printf("%c", '>');
break;
}
}
}
else if (GetKeyState(VK_LEFT) < 0) { //快退 //新加
back(p);
second -= 5;
if (second <= 0) {
second = 60 + second;
min--;
if (min < 0) {
min = 0;
second = 0;
}
}
t -= 5;
if (t < 0) {
t = 0;
}
pro1 = ((double)t / (double)time);
for (; num >= 0; num--) {
if ((pro1 >= (num * pro)) && (pro1 <= ((num + 1) * pro))) {
setCursorPosition(xp + num, y);
setSyscolor();
printf("%c", '>');
setTextcolor();
printf("%c", '-');
printf("%c", '-');