diff options
author | Wohlstand <admin@wohlnet.ru> | 2020-02-22 13:04:39 +0300 |
---|---|---|
committer | Wohlstand <admin@wohlnet.ru> | 2020-02-22 13:04:39 +0300 |
commit | 6ae9ca1265f8249af680f366b5a56934c7b2d7bb (patch) | |
tree | db29afc329050729852bfcc86b8b3419ad74ea15 /utils/mus2mid/mus2mid.cpp | |
parent | b92112685b1d1ba0ae376069bc42d61300a97fa1 (diff) | |
parent | 58c5becbdfd451b4181661a5ff2d3e556e4e8501 (diff) | |
download | libADLMIDI-6ae9ca1265f8249af680f366b5a56934c7b2d7bb.tar.gz libADLMIDI-6ae9ca1265f8249af680f366b5a56934c7b2d7bb.tar.bz2 libADLMIDI-6ae9ca1265f8249af680f366b5a56934c7b2d7bb.zip |
Merge branch 'master' into wip-new-embedded-banks
Diffstat (limited to 'utils/mus2mid/mus2mid.cpp')
-rw-r--r-- | utils/mus2mid/mus2mid.cpp | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/utils/mus2mid/mus2mid.cpp b/utils/mus2mid/mus2mid.cpp new file mode 100644 index 0000000..f737f8c --- /dev/null +++ b/utils/mus2mid/mus2mid.cpp @@ -0,0 +1,74 @@ + +#include "cvt_mus2mid.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: mus2mid <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_mus2midi(filedata, static_cast<uint32_t>(insize), &xmidata, &xmisize, 0) < 0) + { + fprintf(stderr, "Error converting MUS 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; +} |