-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
170 lines (145 loc) · 3.02 KB
/
main.c
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
/*
Linux 2SF player - main program
Rewritten by Jesse N. Richardson
Ported to use LibAO by Michael Holmes
*/
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <termios.h>
#include <unistd.h>
#include <sys/stat.h>
#include <stdint.h>
#include "ao/ao.h"
#include "ao.h"
#include "libao.h"
#include "corlett.h"
#include "vio2sf/vio2sf.h"
#include "color.h"
#include "xsf_player.h"
#include "common.h"
char *xsf_tagget(const char *tag, const char *pData, int dwSize);
// load and set up a 2sf file
int setup_playback(char *name)
{
int res;
res = read_in_file(name);
if (res < 0) {
return res;
}
m1sdr_Init(44100);
m1sdr_SetCallback(do_frame);
m1sdr_PlayStart();
if ((c != NULL) && (c->inf_title[0] != '\0'))
{
BOLD();
//printf("Playing \"%s\" by %s from %s. Copyright %s %s.\nFilename: %s\n", c->inf_title, c->inf_artist, c->inf_game, c->inf_copy, c->inf_year, name);
printf("Playing \"%s\" by %s from %s.\n", c->inf_title, c->inf_artist, c->inf_game);
printf("Copyright %s %s.\n", c->inf_copy, c->inf_year);
printf("Filename: %s.\n", name);
NONBOLDYELLOW();
printf("----------------------------------------------------------------\n");
NORMAL();
}
else
{
BOLD();
printf("Playing %s\n", name);
NORMAL();
}
return 0;
}
int main(int argc, char *argv[])
{
struct termios tp;
struct timeval tv;
int fds;
fd_set watchset;
char ch = 0;
int song;
MAGENTA();
printf("NDS Music Player, libao edition\n");
printf("Version 4.0\n");
printf("Using vio2sf 0.15\n");
NORMAL();
// check if an argument was given
if (argc < 2)
{
RED();
printf("Error: must specify a filename or names!\n");
NORMAL();
return -1;
}
GREEN();
printf("Press ESC or Q to stop. p = previous song, n = next song\n\n", argv[1]);
NORMAL();
if (setup_playback(argv[1]) < 0)
{
return -1;
}
tcgetattr(STDIN_FILENO, &tp);
tp.c_lflag &= ~ICANON;
tp.c_lflag &= ~(ECHO | ECHOCTL | ECHONL);
tcsetattr(STDIN_FILENO, TCSANOW, &tp);
ch = 0;
song = 1;
while ((ch != 27) && (ch != 'q') && (ch != 'Q'))
{
fds = STDIN_FILENO;
FD_ZERO(&watchset);
FD_SET(fds, &watchset);
tv.tv_sec = 0;
tv.tv_usec = 16666/2; // timeout every 1/120th of a second
if (select(fds+1, &watchset, NULL, NULL, &tv))
{
ch = getchar(); // (blocks until something is pressed)
}
else
{
ch = 0;
}
m1sdr_TimeCheck();
// Added the ability to press the n key to goto the next song
if ((ch == 'n') && ((song+1) < argc))
{
xsf_term();
m1sdr_Exit();
if (c)
{
free(c);
c = NULL;
}
free(buffer);
song++;
if (setup_playback(argv[song]) < 0)
{
ch = 27;
}
}
if ((ch == 'p') && (song > 1))
{
xsf_term();
m1sdr_Exit();
if (c)
{
free(c);
c = NULL;
}
free(buffer);
song--;
if (setup_playback(argv[song]) < 0)
{
ch = 27;
}
}
}
xsf_term();
tcgetattr(STDIN_FILENO, &tp);
tp.c_lflag |= ICANON;
tp.c_lflag |= (ECHO | ECHOCTL | ECHONL);
tcsetattr(STDIN_FILENO, TCSANOW, &tp);
free(buffer);
return 1;
}