Skip to content

Commit

Permalink
Add MIDI support
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoran Vuckovic committed Jun 16, 2018
1 parent 0045e1f commit b487c3c
Show file tree
Hide file tree
Showing 32 changed files with 1,832 additions and 7 deletions.
8 changes: 8 additions & 0 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,8 @@ OBJ += frontend/frontend.o \
$(LIBRETRO_COMM_DIR)/features/features_cpu.o \
performance_counters.o \
verbosity.o \
midi/midi_driver.o \
midi/drivers/null_midi.o

ifeq ($(HAVE_RUNAHEAD), 1)
DEFINES += -DHAVE_RUNAHEAD
Expand Down Expand Up @@ -686,6 +688,12 @@ ifeq ($(HAVE_XAUDIO), 1)
LIBS += -lole32
endif

ifeq ($(HAVE_WINMM), 1)
OBJ += midi/drivers/winmm_midi.o
DEFINES += -DHAVE_WINMM
LIBS += -lwinmm
endif

# Audio Resamplers

ifeq ($(HAVE_NEON),1)
Expand Down
1 change: 1 addition & 0 deletions Makefile.msvc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ HAVE_XAUDIO := 1
HAVE_XINPUT := 1
HAVE_WASAPI := 0
HAVE_THREAD_STORAGE := 1
HAVE_WINMM := 1

HAVE_RPNG := 1
HAVE_ZLIB := 1
Expand Down
1 change: 1 addition & 0 deletions Makefile.win
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ HAVE_PYTHON = 0
DYNAMIC = 1

HAVE_XINPUT = 1
HAVE_WINMM = 1

HAVE_SDL := 0
HAVE_SDL2 := 0
Expand Down
2 changes: 2 additions & 0 deletions command.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include <string/stdstring.h>
#include <streams/file_stream.h>
#include <streams/stdin_stream.h>
#include <midi/midi_driver.h>

#ifdef HAVE_CONFIG_H
#include "config.h"
Expand Down Expand Up @@ -2040,6 +2041,7 @@ TODO: Add a setting for these tweaks */
command_event_save_auto_state();
break;
case CMD_EVENT_AUDIO_STOP:
midi_driver_set_all_sounds_off();
return audio_driver_stop();
case CMD_EVENT_AUDIO_START:
return audio_driver_start(rarch_ctl(RARCH_CTL_IS_SHUTDOWN, NULL));
Expand Down
5 changes: 5 additions & 0 deletions config.def.h
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,11 @@ static enum resampler_quality audio_resampler_quality_level = RESAMPLER_QUALITY_
static enum resampler_quality audio_resampler_quality_level = RESAMPLER_QUALITY_NORMAL;
#endif

/* MIDI */
static const char *midi_input = "Off";
static const char *midi_output = "Off";
static const unsigned midi_volume = 100;

#if defined(ANDROID)
#if defined(ANDROID_ARM)
static char buildbot_server_url[] = "http://buildbot.libretro.com/nightly/android/latest/armeabi-v7a/";
Expand Down
49 changes: 49 additions & 0 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@

#include "tasks/tasks_internal.h"

#include "../list_special.h"

static const char* invalid_filename_chars[] = {
/* https://support.microsoft.com/en-us/help/905231/information-about-the-characters-that-you-cannot-use-in-site-names--fo */
"~", "#", "%", "&", "*", "{", "}", "\\", ":", "[", "]", "?", "/", "|", "\'", "\"",
Expand Down Expand Up @@ -281,6 +283,11 @@ enum record_driver_enum
RECORD_NULL
};

enum midi_driver_enum
{
MIDI_WINMM = RECORD_NULL + 1,
MIDI_NULL
};

#if defined(HAVE_OPENGL) || defined(HAVE_OPENGLES) || defined(__CELLOS_LV2__)
static enum video_driver_enum VIDEO_DEFAULT_DRIVER = VIDEO_GL;
Expand Down Expand Up @@ -386,6 +393,12 @@ static enum record_driver_enum RECORD_DEFAULT_DRIVER = RECORD_FFMPEG;
static enum record_driver_enum RECORD_DEFAULT_DRIVER = RECORD_NULL;
#endif

#ifdef HAVE_WINMM
static enum midi_driver_enum MIDI_DEFAULT_DRIVER = MIDI_WINMM;
#else
static enum midi_driver_enum MIDI_DEFAULT_DRIVER = MIDI_NULL;
#endif

#if defined(XENON)
static enum input_driver_enum INPUT_DEFAULT_DRIVER = INPUT_XENON360;
#elif defined(_XBOX360) || defined(_XBOX) || defined(HAVE_XINPUT2) || defined(HAVE_XINPUT_XBOX1)
Expand Down Expand Up @@ -1005,6 +1018,26 @@ const char *config_get_default_menu(void)
return "null";
}

const char *config_get_default_midi(void)
{
enum midi_driver_enum default_driver = MIDI_DEFAULT_DRIVER;

switch (default_driver)
{
case MIDI_WINMM:
return "winmm";
case MIDI_NULL:
break;
}

return "null";
}

const char *config_get_midi_driver_options(void)
{
return char_list_new_special(STRING_LIST_MIDI_DRIVERS, NULL);
}

bool config_overlay_enable_default(void)
{
if (g_defaults.overlay.set)
Expand Down Expand Up @@ -1046,6 +1079,9 @@ static struct config_array_setting *populate_settings_array(settings_t *settings
SETTING_ARRAY("bundle_assets_dst_path_subdir", settings->arrays.bundle_assets_dst_subdir, false, NULL, true);
SETTING_ARRAY("led_driver", settings->arrays.led_driver, false, NULL, true);
SETTING_ARRAY("netplay_mitm_server", settings->arrays.netplay_mitm_server, false, NULL, true);
SETTING_ARRAY("midi_driver", settings->arrays.midi_driver, false, NULL, true);
SETTING_ARRAY("midi_input", settings->arrays.midi_input, true, midi_input, true);
SETTING_ARRAY("midi_output", settings->arrays.midi_output, true, midi_output, true);
*size = count;

return tmp;
Expand Down Expand Up @@ -1532,6 +1568,8 @@ static struct config_uint_setting *populate_settings_uint(settings_t *settings,

SETTING_UINT("run_ahead_frames", &settings->uints.run_ahead_frames, true, 1, false);

SETTING_UINT("midi_volume", &settings->uints.midi_volume, true, midi_volume, false);

*size = count;

return tmp;
Expand Down Expand Up @@ -1585,6 +1623,7 @@ static void config_set_defaults(void)
const char *def_led = config_get_default_led();
const char *def_location = config_get_default_location();
const char *def_record = config_get_default_record();
const char *def_midi = config_get_default_midi();
const char *def_mitm = netplay_mitm_server;
struct config_float_setting *float_settings = populate_settings_float (settings, &float_settings_size);
struct config_bool_setting *bool_settings = populate_settings_bool (settings, &bool_settings_size);
Expand Down Expand Up @@ -1665,6 +1704,9 @@ static void config_set_defaults(void)
if (def_record)
strlcpy(settings->arrays.record_driver,
def_record, sizeof(settings->arrays.record_driver));
if (def_midi)
strlcpy(settings->arrays.midi_driver,
def_midi, sizeof(settings->arrays.midi_driver));
if (def_mitm)
strlcpy(settings->arrays.netplay_mitm_server,
def_mitm, sizeof(settings->arrays.netplay_mitm_server));
Expand Down Expand Up @@ -1982,6 +2024,13 @@ static void config_set_defaults(void)
free(temp_str);
}

if (midi_input)
strlcpy(settings->arrays.midi_input,
midi_input, sizeof(settings->arrays.midi_input));
if (midi_output)
strlcpy(settings->arrays.midi_output,
midi_output, sizeof(settings->arrays.midi_output));

/* Avoid reloading config on every content load */
if (default_block_config_read)
rarch_ctl(RARCH_CTL_SET_BLOCK_CONFIG_READ, NULL);
Expand Down
9 changes: 9 additions & 0 deletions configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,8 @@ typedef struct settings
unsigned led_map[MAX_LEDS];

unsigned run_ahead_frames;

unsigned midi_volume;
} uints;

struct
Expand All @@ -424,6 +426,7 @@ typedef struct settings
char audio_resampler[32];
char input_driver[32];
char input_joypad_driver[32];
char midi_driver[32];

char input_keyboard_layout[64];

Expand All @@ -437,6 +440,9 @@ typedef struct settings
char bundle_assets_dst_subdir[PATH_MAX_LENGTH];

char netplay_mitm_server[255];

char midi_input[32];
char midi_output[32];
} arrays;

struct
Expand Down Expand Up @@ -583,6 +589,9 @@ const char *config_get_default_joypad(void);
**/
const char *config_get_default_menu(void);

const char *config_get_default_midi(void);
const char *config_get_midi_driver_options(void);

const char *config_get_default_record(void);

/**
Expand Down
13 changes: 13 additions & 0 deletions driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "location/location_driver.h"
#include "wifi/wifi_driver.h"
#include "led/led_driver.h"
#include "midi/midi_driver.h"
#include "configuration.h"
#include "core.h"
#include "core_info.h"
Expand Down Expand Up @@ -113,6 +114,12 @@ static const void *find_driver_nonempty(const char *label, int i,
if (drv)
strlcpy(s, record_driver_find_ident(i), len);
}
else if (string_is_equal(label, "midi_driver"))
{
drv = midi_driver_find_handle(i);
if (drv)
strlcpy(s, midi_driver_find_ident(i), len);
}
else if (string_is_equal(label, "audio_resampler_driver"))
{
drv = audio_resampler_driver_find_handle(i);
Expand Down Expand Up @@ -396,6 +403,9 @@ void drivers_init(int flags)
{
led_driver_init();
}

if (flags & DRIVER_MIDI_MASK)
midi_driver_init();
}


Expand Down Expand Up @@ -459,6 +469,9 @@ void driver_uninit(int flags)

if ((flags & DRIVER_AUDIO_MASK) && !audio_driver_owns_driver())
audio_driver_destroy_data();

if (flags & DRIVER_MIDI_MASK)
midi_driver_free();
}

bool driver_ctl(enum driver_ctl_state state, void *data)
Expand Down
12 changes: 8 additions & 4 deletions driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ RETRO_BEGIN_DECLS
| DRIVER_MENU_MASK \
| DRIVERS_VIDEO_INPUT_MASK \
| DRIVER_WIFI_MASK \
| DRIVER_LED_MASK )
| DRIVER_LED_MASK \
| DRIVER_MIDI_MASK )

#define DRIVERS_CMD_ALL_BUT_MENU \
( DRIVER_AUDIO_MASK \
Expand All @@ -45,7 +46,8 @@ RETRO_BEGIN_DECLS
| DRIVER_LOCATION_MASK \
| DRIVERS_VIDEO_INPUT_MASK \
| DRIVER_WIFI_MASK \
| DRIVER_LED_MASK )
| DRIVER_LED_MASK \
| DRIVER_MIDI_MASK )

enum
{
Expand All @@ -57,7 +59,8 @@ enum
DRIVER_MENU,
DRIVERS_VIDEO_INPUT,
DRIVER_WIFI,
DRIVER_LED
DRIVER_LED,
DRIVER_MIDI
};

enum
Expand All @@ -70,7 +73,8 @@ enum
DRIVER_MENU_MASK = 1 << DRIVER_MENU,
DRIVERS_VIDEO_INPUT_MASK = 1 << DRIVERS_VIDEO_INPUT,
DRIVER_WIFI_MASK = 1 << DRIVER_WIFI,
DRIVER_LED_MASK = 1 << DRIVER_LED
DRIVER_LED_MASK = 1 << DRIVER_LED,
DRIVER_MIDI_MASK = 1 << DRIVER_MIDI
};

enum driver_ctl_state
Expand Down
17 changes: 17 additions & 0 deletions dynamic.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
#include "performance_counters.h"
#include "gfx/video_driver.h"
#include "led/led_driver.h"
#include "midi/midi_driver.h"

#include "cores/internal_cores.h"
#include "frontend/frontend_driver.h"
Expand Down Expand Up @@ -1778,6 +1779,22 @@ bool rarch_environment_cb(unsigned cmd, void *data)
}
}
break;

case RETRO_ENVIRONMENT_GET_MIDI_INTERFACE:
{
struct retro_midi_interface *midi_interface =
(struct retro_midi_interface *)data;

if (midi_interface)
{
midi_interface->input_enabled = midi_driver_input_enabled;
midi_interface->output_enabled = midi_driver_output_enabled;
midi_interface->read = midi_driver_read;
midi_interface->write = midi_driver_write;
midi_interface->flush = midi_driver_flush;
}
}
break;

default:
RARCH_LOG("Environ UNSUPPORTED (#%u).\n", cmd);
Expand Down
12 changes: 12 additions & 0 deletions intl/msg_hash_lbl.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ MSG_HASH(MENU_ENUM_LABEL_DEFERRED_PLAYLIST_SETTINGS_LIST,
"deferred_playlist_settings")
MSG_HASH(MENU_ENUM_LABEL_DEFERRED_PRIVACY_SETTINGS_LIST,
"deferred_privacy_settings_list")
MSG_HASH(MENU_ENUM_LABEL_DEFERRED_MIDI_SETTINGS_LIST,
"deferred_midi_settings_list")
MSG_HASH(MENU_ENUM_LABEL_DEFERRED_RDB_ENTRY_DETAIL,
"deferred_rdb_entry_detail")
MSG_HASH(MENU_ENUM_LABEL_DEFERRED_RECORDING_SETTINGS_LIST,
Expand Down Expand Up @@ -789,6 +791,8 @@ MSG_HASH(MENU_ENUM_LABEL_POINTER_ENABLE,
"menu_pointer_enable")
MSG_HASH(MENU_ENUM_LABEL_PRIVACY_SETTINGS,
"privacy_settings")
MSG_HASH(MENU_ENUM_LABEL_MIDI_SETTINGS,
"midi_settings")
MSG_HASH(MENU_ENUM_LABEL_QUIT_RETROARCH,
"quit_retroarch")
MSG_HASH(MENU_ENUM_LABEL_RDB_ENTRY,
Expand Down Expand Up @@ -889,6 +893,8 @@ MSG_HASH(MENU_ENUM_LABEL_RECORD_CONFIG,
"record_config")
MSG_HASH(MENU_ENUM_LABEL_RECORD_DRIVER,
"record_driver")
MSG_HASH(MENU_ENUM_LABEL_MIDI_DRIVER,
"midi_driver")
MSG_HASH(MENU_ENUM_LABEL_RECORD_ENABLE,
"record_enable")
MSG_HASH(MENU_ENUM_LABEL_RECORD_PATH,
Expand Down Expand Up @@ -1517,3 +1523,9 @@ MSG_HASH(MENU_ENUM_LABEL_DEFERRED_QUICK_MENU_OVERRIDE_OPTIONS,
"deferred_quick_menu_override_options")
MSG_HASH(MENU_ENUM_LABEL_DISCORD_IN_MENU,
"discord_in_menu")
MSG_HASH(MENU_ENUM_LABEL_MIDI_INPUT,
"midi_input")
MSG_HASH(MENU_ENUM_LABEL_MIDI_OUTPUT,
"midi_output")
MSG_HASH(MENU_ENUM_LABEL_MIDI_VOLUME,
"midi_volume")
24 changes: 24 additions & 0 deletions intl/msg_hash_us.c
Original file line number Diff line number Diff line change
Expand Up @@ -2037,6 +2037,30 @@ int menu_hash_get_help_us_enum(enum msg_hash_enums msg, char *s, size_t len)
snprintf(s, len,
"Sets the blue value of the OSD text color. Valid values are between 0 and 255.");
break;
case MENU_ENUM_LABEL_MIDI_DRIVER:
snprintf(s, len,
"MIDI driver to use.");
break;
case MENU_ENUM_LABEL_MIDI_INPUT:
snprintf(s, len,
"Sets the input device (driver specific).\n"
"When set to \"Off\", MIDI input will be disabled.\n"
"Device name can also be typed in.");
break;
case MENU_ENUM_LABEL_MIDI_OUTPUT:
snprintf(s, len,
"Sets the output device (driver specific).\n"
"When set to \"Off\", MIDI output will be disabled.\n"
"Device name can also be typed in.\n"
" \n"
"When MIDI output is enabled and core and game/app support MIDI output,\n"
"some or all sounds (depends on game/app) will be generated by MIDI device.\n"
"In case of \"null\" MIDI driver this means that those sounds won't be audible.");
break;
case MENU_ENUM_LABEL_MIDI_VOLUME:
snprintf(s, len,
"Sets the master volume of the output device.");
break;
default:
if (string_is_empty(s))
strlcpy(s, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NO_INFORMATION_AVAILABLE), len);
Expand Down
Loading

0 comments on commit b487c3c

Please sign in to comment.