forked from VictorYXL/MyOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayTemp.cpp
90 lines (86 loc) · 2 KB
/
PlayTemp.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
#include"system.h"
#include"io.h"
#include"graphic.h"
#include"window.h"
#include"buffer.h"
#include"memory.h"
#include"file.h"
#include<stdio.h>
int main(int argc,char **argv)
{
if (argc!=1)
return 0;
char *fileName=argv[0];
//Open File
struct File *fp;
if ((fp=fileOpen(fileName))==0)
return 0;
int length=fileLength(fp);
//File Buffer
unsigned char *fileBufferC = (unsigned char *)allocMem(length,"File Buffer");
struct Buffer fileBuffer;
initBuffer(&fileBuffer,length,fileBufferC);
readFile(fp,0,length,fileBuffer);
//Sheet Buffer
unsigned char *playerBufferC=(unsigned char *)allocMem(70*28,"Player");
struct Buffer fileBuffer;
initBuffer(playerBufferC,70*28,fileBuffer);
//Alloc Sheet
struct Sheet *playerSheet;
playerSheet=allocSheet();
setBufInSheet(playerSheet,playerBufferC,70,28,-1);
//Init Sheet
makeWindow(playerSheet,70,28,"Player");
slideSheet(playerSheet,180,72);
updownSheet(playerSheet);
char s[8],data;
sprintf (s,"Playing");
putStrAndBackOnSht(musicPlayerSheet,70,28,BLACK,WHITE,str,8);
//Init Timer
struct Timer *timerPlayer;
char bufferTime;
timerPlayer=allocTimer();
initTimer(timerPlayer,&bufferTime,1);
char oneBeat;
while (1)
{
for (int i=0;i<length;i++)
{
//Close
if(isClosedWindow(playerSheet))
{
freeSheet(playerSheet);
freeMem(fileBufferC,length);
freeMem(playerBufferC,70*28);
PlayOneBeat(0);
return;
}
//Suspend
if (iskey(&data) && data==' ')
{
sprintf (s,"Suspend");
putStrAndBackOnSht(musicPlayerSheet,70,28,BLACK,WHITE,str,8);
while (!(iskey(&data) && data==' '));
//COntinue
sprintf (s,"Playing");
putStrAndBackOnSht(musicPlayerSheet,70,28,BLACK,WHITE,str,8);
}
//OneBeat
getBuffer(fileBuffer,oneBeat);
playOneBeat(oneBeat);
//20ms
setTimer(timerPlayer,20);
while (1)
if (getBuffer(&bufferTime,&data))
break;
//Stop
PlayOneBeat(0);
//15ms
setTimer(timerPlayer,15);
while (1)
if (getBuffer(&bufferTime,&data))
break;
}
}
return 0;
}