diff options
author | Wohlstand <admin@wohlnet.ru> | 2020-02-22 13:04:09 +0300 |
---|---|---|
committer | Wohlstand <admin@wohlnet.ru> | 2020-02-22 13:04:09 +0300 |
commit | 58c5becbdfd451b4181661a5ff2d3e556e4e8501 (patch) | |
tree | 3cca40873685179f2f6a3ed8a90a6a3760011e48 /utils/mus2mid/mus2mid.cpp | |
parent | 5e5f59c9a31a206195f7a9d48fa33f3d9b7c449c (diff) | |
parent | bdb7f81da3e43db01f4ab5781287d22ecb56e025 (diff) | |
download | libADLMIDI-58c5becbdfd451b4181661a5ff2d3e556e4e8501.tar.gz libADLMIDI-58c5becbdfd451b4181661a5ff2d3e556e4e8501.tar.bz2 libADLMIDI-58c5becbdfd451b4181661a5ff2d3e556e4e8501.zip |
Merge branch 'master' of github.com:Wohlstand/libADLMIDI
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; +} |