-
Notifications
You must be signed in to change notification settings - Fork 1
/
melody.c
65 lines (54 loc) · 1.31 KB
/
melody.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
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "music.h"
#define BUFFER_SIZE 4096
#if 0
static void music_item_print (music_item_t *item) {
while (item) {
switch (item->type) {
case MUSIC_ITEM_NOTE:
printf ("=%u:%u ", item->value.note.id, item->value.note.beats);
break;
case MUSIC_ITEM_REST:
printf (". ");
break;
case MUSIC_ITEM_TEMPO:
printf ("tempo%u ", (unsigned int) item->value.tempo);
break;
case MUSIC_ITEM_SUB:
printf ("[ (%u) ", item->value.sub.beats);
music_item_print (item->value.sub.first);
printf ("] ");
}
item = item->next;
}
}
#endif
int main(int argc, char *argv[]) {
char buffer[BUFFER_SIZE];
char *filename = NULL;
int instr_id = 0;
/* Don't feel like using getopt or whatever */
for (int i = 1; i < argc; i++) {
if (strcmp (argv[i], "-i") == 0) {
i++;
instr_id = atoi (argv[i]);
} else {
filename = argv[i];
}
}
if (!filename) {
fprintf (stderr, "Usage: %s [-i <instrument_number>] filename.mid\n\n", argv[0]);
return 1;
}
if (fgets (buffer, BUFFER_SIZE, stdin)) {
music_item_t *music = music_parse (buffer);
//music_item_print (music);
//putchar ('\n');
if (!music_generate (filename, 120, music, instr_id))
fprintf (stderr, "Could not do music generation\n");
music_item_destroy (music);
}
return 0;
}