aboutsummaryrefslogtreecommitdiff
path: root/utils/xmi2mid
diff options
context:
space:
mode:
authorJP Cimalando <jpcima@users.noreply.github.com>2018-07-09 00:34:14 +0200
committerJP Cimalando <jpcima@users.noreply.github.com>2018-07-09 00:34:14 +0200
commita2992e21fe70ec3f0ebf530fc501a6a3ddecdc27 (patch)
tree7f0d08d0c35a4fefd8c429f09bb8733d514a81b7 /utils/xmi2mid
parent2a33defa5770a585f26c35ea731904859afd4ea6 (diff)
downloadlibADLMIDI-a2992e21fe70ec3f0ebf530fc501a6a3ddecdc27.tar.gz
libADLMIDI-a2992e21fe70ec3f0ebf530fc501a6a3ddecdc27.tar.bz2
libADLMIDI-a2992e21fe70ec3f0ebf530fc501a6a3ddecdc27.zip
provide XMI to MID conversion as tool
Diffstat (limited to 'utils/xmi2mid')
-rw-r--r--utils/xmi2mid/xmi2mid.cpp74
1 files changed, 74 insertions, 0 deletions
diff --git a/utils/xmi2mid/xmi2mid.cpp b/utils/xmi2mid/xmi2mid.cpp
new file mode 100644
index 0000000..65d5858
--- /dev/null
+++ b/utils/xmi2mid/xmi2mid.cpp
@@ -0,0 +1,74 @@
+
+#include "cvt_xmi2mid.hpp"
+#include <stdio.h>
+#include <sys/stat.h>
+#if !defined(_WIN32)
+#include <unistd.h>
+#else
+#include <io.h>
+#define fileno(fd) _fileno(fd)
+#define isatty(fd) _isatty(fd)
+#endif
+
+int main(int argc, char *argv[])
+{
+ if(argc != 2)
+ {
+ fprintf(stderr, "Usage: xmi2mid <midi-file>\n");
+ return 1;
+ }
+
+ const char *filename = argv[1];
+
+ FILE *fh = fopen(filename, "rb");
+ if(!fh)
+ {
+ fprintf(stderr, "Error opening file.\n");
+ return 1;
+ }
+
+ struct stat st;
+ if(fstat(fileno(fh), &st) != 0)
+ {
+ fprintf(stderr, "Error reading file status.\n");
+ return 1;
+ }
+
+ size_t insize = (size_t)st.st_size;
+ if(insize > 8 * 1024 * 1024)
+ {
+ fprintf(stderr, "File too large.\n");
+ return 1;
+ }
+
+ uint8_t *filedata = new uint8_t[insize];
+ if(fread(filedata, 1, insize, fh) != insize)
+ {
+ fprintf(stderr, "Error reading file data.\n");
+ return 1;
+ }
+
+ uint8_t *xmidata = NULL;
+ uint32_t xmisize = 0;
+ if(Convert_xmi2midi(filedata, insize, &xmidata, &xmisize, XMIDI_CONVERT_NOCONVERSION) < 0)
+ {
+ fprintf(stderr, "Error converting XMI to SMF.\n");
+ return 1;
+ }
+
+ FILE *out = stdout;
+ if(isatty(fileno(out)))
+ {
+ fprintf(stderr, "Not writing SMF data on the text terminal.\n");
+ }
+ else
+ {
+ if (fwrite(xmidata, 1, xmisize, out) != xmisize || fflush(out) != 0)
+ {
+ fprintf(stderr, "Error writing SMF data.\n");
+ return 1;
+ }
+ }
+
+ return 0;
+}