Skip to content
This repository was archived by the owner on Jun 10, 2024. It is now read-only.

Commit a36531b

Browse files
committed
fix: do not use null tunes
1 parent 9b03ab7 commit a36531b

1 file changed

Lines changed: 15 additions & 10 deletions

File tree

src/cli/main.c

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,15 @@
77
#include <string.h>
88
#include <unistd.h>
99

10+
#include "../lib/parser/error.h"
1011
#include "../lib/parser/parser.h"
1112
#include "../lib/synth/sequencer.h"
1213

1314
Sequencer *sequencer;
1415
Tune *tune;
1516

17+
const char *name = "sidplay";
18+
1619
void callback(void *userdata, Uint8 *stream, int len) {
1720
(void)userdata;
1821
int samples = len / sizeof(float);
@@ -22,24 +25,26 @@ void callback(void *userdata, Uint8 *stream, int len) {
2225
}
2326
}
2427

25-
void load(char *filename) {
26-
tune = fromFile(filename);
27-
sequencer = newSequencer(tune);
28-
}
28+
void usage() { printf("Usage: %s <filename>\n", name); }
2929

3030
int main(int argc, char *argv[]) {
3131
if (argc != 2) {
32-
char *name = basename(argv[0]);
33-
printf("Usage: %s <filename>\n", name);
34-
exit(1);
32+
usage();
33+
return 1;
3534
}
3635

3736
if (0 != SDL_Init(SDL_INIT_AUDIO)) {
38-
printf("SDL_Init: %s\n", SDL_GetError());
39-
exit(1);
37+
error("Cannot initialize audio.");
38+
return 1;
4039
}
4140

42-
load(argv[1]);
41+
tune = fromFile(argv[1]);
42+
if (tune == NULL) {
43+
usage();
44+
return 1;
45+
}
46+
47+
sequencer = newSequencer(tune);
4348

4449
SDL_AudioSpec spec = {.format = AUDIO_F32,
4550
.channels = 1,

0 commit comments

Comments
 (0)