diff options
author | Wohlstand <admin@wohlnet.ru> | 2020-01-28 17:42:15 +0300 |
---|---|---|
committer | Wohlstand <admin@wohlnet.ru> | 2020-01-28 17:42:15 +0300 |
commit | 5cf682052a73ef13aeba4fd4c5770c1379382f5f (patch) | |
tree | 80e9a28bafc9a6557c7bd280afbd9ae5d488114b | |
parent | 9874b273aee094e6a5fa1c0b8d66c5e33d7cf078 (diff) | |
parent | bdb7f81da3e43db01f4ab5781287d22ecb56e025 (diff) | |
download | libADLMIDI-5cf682052a73ef13aeba4fd4c5770c1379382f5f.tar.gz libADLMIDI-5cf682052a73ef13aeba4fd4c5770c1379382f5f.tar.bz2 libADLMIDI-5cf682052a73ef13aeba4fd4c5770c1379382f5f.zip |
Merge branch 'master' into wip-new-embedded-banks
-rw-r--r-- | CMakeLists.txt | 6 | ||||
-rw-r--r-- | utils/mus2mid/CMakeLists.txt | 7 | ||||
-rw-r--r-- | utils/mus2mid/mus2mid.cpp | 74 |
3 files changed, 87 insertions, 0 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 3ce3e7d..4063b61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -132,6 +132,7 @@ option(WITH_ADLMIDI2 "Build also classic ADLMIDI player [EXPERIMENTAL]" O option(WITH_VLC_PLUGIN "Build also a plugin for VLC Media Player" OFF) option(VLC_PLUGIN_NOINSTALL "Don't install VLC plugin into VLC directory" OFF) option(WITH_OLD_UTILS "Build also old utilities" OFF) +option(WITH_MUS2MID "Build a MUS to MIDI converter" OFF) option(WITH_XMI2MID "Build a XMI to MIDI converter" OFF) option(EXAMPLE_SDL2_AUDIO "Build also a simple SDL2 demo MIDI player" OFF) @@ -333,6 +334,10 @@ if(WITH_ADLMIDI2) add_subdirectory(utils/adlmidi-2) endif() +if(WITH_MUS2MID) + add_subdirectory(utils/mus2mid) +endif() + if(WITH_XMI2MID) add_subdirectory(utils/xmi2mid) endif() @@ -421,5 +426,6 @@ message("MIDIPLAY_WAVE_ONLY = ${MIDIPLAY_WAVE_ONLY}") message("WITH_ADLMIDI2 = ${WITH_ADLMIDI2}") message("WITH_VLC_PLUGIN = ${WITH_VLC_PLUGIN}") message("WITH_OLD_UTILS = ${WITH_OLD_UTILS}") +message("WITH_MUS2MID = ${WITH_MUS2MID}") message("WITH_XMI2MID = ${WITH_XMI2MID}") message("EXAMPLE_SDL2_AUDIO = ${EXAMPLE_SDL2_AUDIO}") diff --git a/utils/mus2mid/CMakeLists.txt b/utils/mus2mid/CMakeLists.txt new file mode 100644 index 0000000..6430dd4 --- /dev/null +++ b/utils/mus2mid/CMakeLists.txt @@ -0,0 +1,7 @@ +add_executable(mus2mid mus2mid.cpp) +# TODO: Use own library +target_include_directories(mus2mid PRIVATE ${PROJECT_SOURCE_DIR}/src) + +install(TARGETS mus2mid + RUNTIME DESTINATION "${CMAKE_INSTALL_BINDIR}") + 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; +} |