-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
68 lines (58 loc) · 2.04 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
/*=============================================================================
| Written by Rayerdyne (2019) to make midi file from custom music format used |
| in Azimuth, using parts of Azimuth's functionnalities. |
| |
| Do wathever you want with this part of the code, its only initial goal was |
| to make music arrangement easier. The code is given without any warranty. |
| |
| /!\ See Azimuth's sources files for their licenses. |
| |
=============================================================================*/
#include <stdbool.h>
#include <stdlib.h>
#include "azimuth/util/music.h"
#include "azimuth/state/music.h"
#include "midi/midi.h"
#include "midi/data.h"
// <copied>
az_music_t music;
static void destroy_music(void) {
az_destroy_music(&music);
}
// </copied>
int main(int argc, char **argv)
{
if (argc < 3) {
fprintf(stderr, "Usage: <input file> <output file>\n");
return EXIT_SUCCESS;
}
midi_music_voices_data *data = midi_read_voices_data(argv[1]);
// <copied>
// Initialize drum kit:
int num_drums = 0;
const az_sound_data_t *drums = NULL;
az_get_drum_kit(&num_drums, &drums);
// Load music:
az_reader_t reader;
if (!az_file_reader(argv[1], &reader)) {
fprintf(stderr, "ERROR: could not open %s\n", argv[1]);
return EXIT_FAILURE;
}
if (!az_read_music(&reader, num_drums, drums, &music)) {
fprintf(stderr, "ERROR: failed to parse music.\n");
return EXIT_FAILURE;
}
az_rclose(&reader);
atexit(destroy_music);
// </copied>
FILE *file = fopen(argv[2], "w");
if (!file) {
fprintf(stderr, "ERROR: could not open %s\n", argv[2]);
return EXIT_FAILURE;
}
midi_write_music(&music, data, file);
fclose(file);
midi_free_music_voices_data(data);
printf("Done.\n");
return EXIT_SUCCESS;
}