Skip to content

Commit

Permalink
-Add: MIDI using Munt MT32 emulator
Browse files Browse the repository at this point in the history
  • Loading branch information
miniupnp committed Feb 9, 2017
1 parent f1a58e7 commit 59fb88f
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 0 deletions.
16 changes: 16 additions & 0 deletions config.lib
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ set_default() {
with_sdl2="1"
with_asound="1"
with_pulse="1"
with_munt="1"
enable_builtin_depend="1"
with_makedepend="0"
with_sort="1"
Expand Down Expand Up @@ -79,6 +80,7 @@ set_default() {
with_sdl2
with_asound
with_pulse
with_munt
enable_builtin_depend
with_makedepend
with_sort
Expand Down Expand Up @@ -190,6 +192,10 @@ detect_params() {
--without-pulse) with_pulse="0";;
--with-pulse=*) with_pulse="$optarg";;

--with-munt) with_munt="2";;
--without-munt) with_munt="0";;
--with-munt=*) with_munt="$optarg";;

--disable-builtin-depend) enable_builtin_depend="0";;
--enable-builtin-depend) enable_builtin_depend="2";;
--enable-builtin-depend=*) enable_builtin_depend="$optarg";;
Expand Down Expand Up @@ -434,11 +440,13 @@ check_params() {
with_sdl="0"
with_asound="0"
with_pulse="0"
with_munt="0"
fi
detect_sdl2
detect_sdl
detect_asound
detect_pulseaudio
detect_munt

if [ "$os" = "MINGW" ] || [ "$os" = "CYGWIN" ] || [ "$os" = "WINCE" ]; then
log 1 "checking GDI video driver... found"
Expand Down Expand Up @@ -1039,6 +1047,10 @@ make_cflags_and_ldflags() {
CFLAGS="$CFLAGS $(pkg-config --cflags libpulse)"
fi

if [ "$with_munt" != "0" ]; then
LIBS="$LIBS -lmt32emu -lstdc++"
fi

if [ "$enable_assert" = "0" ]; then
CFLAGS="$CFLAGS -DNDEBUG"
CFLAGS_BUILD="$CFLAGS_BUILD -DNDEBUG"
Expand Down Expand Up @@ -1702,6 +1714,10 @@ detect_pulseaudio() {
detect_library "$with_pulse" "pulse" "libpulse.a" "pulse/" "pulseaudio.h"
}

detect_munt() {
detect_library "$with_munt" "munt" "libmt32emu.a" "mt32emu/" "mt32emu.h"
}

_detect_sort() {
sort_test_in="d
a
Expand Down
74 changes: 74 additions & 0 deletions src/audio/midi_munt.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/** @file src/audio/midi_munt.c use the MT32 emulator MUNT */

#include <mt32emu/mt32emu.h>

#include "types.h"
#include "midi.h"
#include "../os/error.h"

static mt32emu_context s_context = NULL;

const char * s_romfiles[] = {
"/Users/nanard/roms/CM32L_CONTROL.1989-12-05.v1.02.ROM",
"/Users/nanard/roms/CM32L_PCM.ROM",
NULL
};

bool midi_init(void)
{
int i;
mt32emu_report_handler_i handler = { NULL };

Debug("munt version : %s\n", mt32emu_get_library_version_string());
s_context = mt32emu_create_context(handler, NULL);
if (s_context == NULL) return false;
for (i = 0; s_romfiles[i] != NULL; i++) {
mt32emu_return_code ret = mt32emu_add_rom_file(s_context, s_romfiles[i]);
if (ret < MT32EMU_RC_OK) {
Error("Failed to load MT32 ROM file '%s' error %d\n", s_romfiles[i], (int)ret);
return false;
}
}
if (mt32emu_open_synth(s_context) != MT32EMU_RC_OK) {
Error("Failed to open synth\n");
return false;
}
return true;
}

void midi_uninit(void)
{
mt32emu_close_synth(s_context);
mt32emu_free_context(s_context);
s_context = NULL;
}

/**
* Sends a midi command
*
* @param data The data to send in "packed" format, ie status | (data1 << 8) | (data2 << 16) */
void midi_send(uint32 data)
{
mt32emu_return_code ret;

ret = mt32emu_play_msg(s_context, data);
if (ret != MT32EMU_RC_OK) Warning("mt32emu_play_msg() error %d\n", (int)ret);
}

uint16 midi_send_string(const uint8 * data, uint16 len)
{
mt32emu_return_code ret;

ret = mt32emu_play_sysex(s_context, data, len);
if (ret != MT32EMU_RC_OK) {
Warning("mt32emu_play_sysex() error %d\n", (int)ret);
return 0;
}
return len;
}

void midi_reset(void)
{
}


0 comments on commit 59fb88f

Please sign in to comment.