-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdx21dump.c
54 lines (48 loc) · 1.4 KB
/
dx21dump.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
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <stdint.h>
#include "platform.h"
#include "syx_dx21.h"
static int midi_write_func(void *buf, size_t bytes, void *data_ptr) {
FILE *f = (FILE *)data_ptr;
return fwrite(buf, 1, bytes, f) == bytes ? 0 : -1;
}
int main(int argc, char **argv) {
for(int i = 1; i < argc; i++) {
FILE *f = fopen(argv[i], "rb");
if(!f) {
fprintf(stderr, "Could not open \"%s\": %s (%d)\n", argv[i], strerror(errno), errno);
continue;
}
fseek(f, 0, SEEK_END);
size_t filesize = ftell(f);
fseek(f, 0, SEEK_SET);
uint8_t *buf = malloc(filesize);
if(!buf) {
fprintf(stderr, "Could not allocate " SIZE_T_FMT " bytes: %s (%d)\n", filesize, strerror(errno), errno);
fclose(f);
continue;
}
size_t bytesread = fread(buf, 1, filesize, f);
if(bytesread != filesize) {
fprintf(stderr, "Could not read " SIZE_T_FMT " bytes: %s (%d)\n", filesize, strerror(errno), errno);
free(buf);
continue;
}
fclose(f);
struct dx21_vced_voice_bank bank;
int r = dx21_vced_voice_bank_from_buffer(&bank, buf, filesize);
free(buf);
if(r != DX21_SUCCESS) {
fprintf(stderr, "Error reading voice bank: %s (%d)\n", dx21_error_string(r), r);
continue;
}
dx21_vced_voice_bank_dump(&bank);
FILE *out = fopen("dx21-out.syx", "wb");
dx21_vced_voice_bank_send(&bank, midi_write_func, (void *)out);
fclose(out);
}
return 0;
}