Skip to content

Commit

Permalink
Enumerate MIDI devices on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
midwan committed Dec 8, 2023
1 parent 4e532b4 commit 20d7258
Show file tree
Hide file tree
Showing 8 changed files with 94 additions and 56 deletions.
2 changes: 1 addition & 1 deletion src/cfgfile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2232,7 +2232,7 @@ void cfgfile_save_options (struct zfile *f, struct uae_prefs *p, int type)
std::array<int, SDL_CONTROLLER_BUTTON_MAX> custom_button_map{};
const TCHAR* custom_name;

// get all of the custom actions
// get all the custom actions
for (auto n = 0; n < SDL_CONTROLLER_BUTTON_MAX; ++n) // loop through all buttons
{
for (auto m = 0; m < 2; m++)
Expand Down
9 changes: 7 additions & 2 deletions src/include/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -951,8 +951,13 @@ struct uae_prefs
bool borderless;
bool automount_removable;
bool automount_cddrives;
int midioutdev;
int midiindev;

// We use the device name in Amiberry
// int midioutdev;
// int midiindev;
TCHAR midioutdev[256];
TCHAR midiindev[256];

bool midirouter;
int uaescsimode;
int soundcard;
Expand Down
21 changes: 12 additions & 9 deletions src/include/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ int shmem_serial_state(void);
extern void unload_ghostscript (void);
extern int load_ghostscript (void);

#define MAX_MIDI_PORTS 100
struct midiportinfo
{
TCHAR *name;
unsigned int devid;
};
extern struct midiportinfo *midiinportinfo[MAX_MIDI_PORTS];
extern struct midiportinfo *midioutportinfo[MAX_MIDI_PORTS];

// In Amiberry, we use libserialport and a more modern structure to hold the results
// Therefore, these are not needed
//
//#define MAX_MIDI_PORTS 100
//struct midiportinfo
//{
// TCHAR *name;
// unsigned int devid;
//};
//extern struct midiportinfo *midiinportinfo[MAX_MIDI_PORTS];
//extern struct midiportinfo *midioutportinfo[MAX_MIDI_PORTS];

//#define MAX_SERPAR_PORTS 100
//struct serparportinfo
//{
Expand All @@ -65,7 +65,10 @@ extern struct midiportinfo *midioutportinfo[MAX_MIDI_PORTS];
//};
//extern struct serparportinfo *comports[MAX_SERPAR_PORTS];
//extern struct serparportinfo *parports[MAX_SERPAR_PORTS];

extern std::vector<std::string> serial_ports;
extern std::vector<std::string> midi_in_ports;
extern std::vector<std::string> midi_out_ports;

extern int enumserialports (void);
extern int enummidiports (void);
Expand Down
73 changes: 38 additions & 35 deletions src/osdep/amiberry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1939,8 +1939,6 @@ void target_default_options(struct uae_prefs* p, int type)
}
if (type == 1 || type == 0 || type == 3) {
p->uaescsimode = UAESCSI_CDEMU;
p->midioutdev = -2;
p->midiindev = 0;
//p->midirouter = false;
p->automount_removable = false;
//p->automount_drives = 0;
Expand Down Expand Up @@ -2191,25 +2189,24 @@ static const TCHAR* scsimode[] = { _T("SCSIEMU"), _T("SPTI"), _T("SPTI+SCSISCAN"
//static const TCHAR* statusbarmode[] = { _T("none"), _T("normal"), _T("extended"), NULL };
//static const TCHAR* configmult[] = { _T("1x"), _T("2x"), _T("3x"), _T("4x"), _T("5x"), _T("6x"), _T("7x"), _T("8x"), NULL };

static struct midiportinfo *getmidiport (struct midiportinfo **mi, int devid)
{
for (int i = 0; i < MAX_MIDI_PORTS; i++) {
if (mi[i] != NULL && mi[i]->devid == devid)
return mi[i];
}
return NULL;
}
//static struct midiportinfo *getmidiport (struct midiportinfo **mi, int devid)
//{
// for (int i = 0; i < MAX_MIDI_PORTS; i++) {
// if (mi[i] != NULL && mi[i]->devid == devid)
// return mi[i];
// }
// return NULL;
//}

extern int scsiromselected;

void target_save_options(struct zfile* f, struct uae_prefs* p)
{
struct midiportinfo *midp;
//struct midiportinfo *midp;

cfgfile_target_write_bool(f, _T("middle_mouse"), (p->input_mouse_untrap & MOUSEUNTRAP_MIDDLEBUTTON) != 0);
cfgfile_target_dwrite_bool(f, _T("map_drives_auto"), p->automount_removable);
cfgfile_target_dwrite_bool(f, _T("map_cd_drives"), p->automount_cddrives);
cfgfile_target_dwrite_str(f, _T("serial_port"), p->sername[0] ? p->sername : _T("none"));

cfgfile_target_dwrite(f, _T("active_priority"), _T("%d"), p->active_capture_priority);
cfgfile_target_dwrite_bool(f, _T("active_not_captured_nosound"), p->active_nocapture_nosound);
Expand All @@ -2227,6 +2224,10 @@ void target_save_options(struct zfile* f, struct uae_prefs* p)
cfgfile_target_dwrite_bool(f, _T("start_minimized"), p->start_minimized);
cfgfile_target_dwrite_bool(f, _T("start_not_captured"), p->start_uncaptured);

#ifdef AMIBERRY
cfgfile_target_dwrite_str_escape(f, _T("midiout_device_name"), p->midioutdev[0] ? p->midioutdev : _T("none"));
cfgfile_target_dwrite_str_escape(f, _T("midiin_device_name"), p->midiindev[0] ? p->midiindev : _T("none"));
#else
cfgfile_target_dwrite (f, _T("midiout_device"), _T("%d"), p->midioutdev);
cfgfile_target_dwrite (f, _T("midiin_device"), _T("%d"), p->midiindev);

Expand All @@ -2243,6 +2244,8 @@ void target_save_options(struct zfile* f, struct uae_prefs* p)
cfgfile_target_dwrite_str_escape(f, _T("midiin_device_name"), _T("none"));
else
cfgfile_target_dwrite_str_escape(f, _T("midiin_device_name"), midp->name);
#endif

cfgfile_target_dwrite_bool (f, _T("midirouter"), p->midirouter);

cfgfile_target_dwrite_bool(f, _T("rtg_match_depth"), p->rtgmatchdepth);
Expand Down Expand Up @@ -2385,9 +2388,9 @@ static int target_parse_option_host(struct uae_prefs *p, const TCHAR *option, co
|| cfgfile_yesno(option, value, _T("minimized_pause"), &p->minimized_pause)
|| cfgfile_yesno(option, value, _T("minimized_nosound"), &p->minimized_nosound)
|| cfgfile_intval(option, value, _T("minimized_input"), &p->minimized_input, 1)
|| cfgfile_intval(option, value, _T("midi_device"), &p->midioutdev, 1)
|| cfgfile_intval(option, value, _T("midiout_device"), &p->midioutdev, 1)
|| cfgfile_intval(option, value, _T("midiin_device"), &p->midiindev, 1)
|| cfgfile_string(option, value, _T("midi_device"), p->midioutdev, sizeof p->midioutdev)
|| cfgfile_string(option, value, _T("midiout_device_name"), p->midioutdev, sizeof p->midioutdev)
|| cfgfile_string(option, value, _T("midiin_device_name"), p->midiindev, sizeof p->midiindev)
|| cfgfile_yesno(option, value, _T("midirouter"), &p->midirouter)
|| cfgfile_yesno(option, value, _T("right_control_is_right_win"), &p->right_control_is_right_win_key)
|| cfgfile_yesno(option, value, _T("always_on_top"), &p->main_alwaysontop)
Expand Down Expand Up @@ -2588,26 +2591,26 @@ static int target_parse_option_host(struct uae_prefs *p, const TCHAR *option, co
return 1;
}

if (cfgfile_string_escape(option, value, _T("midiout_device_name"), tmpbuf, 256)) {
p->midioutdev = -2;
if (!_tcsicmp (tmpbuf, _T("default")) || (midioutportinfo[0] && !_tcsicmp (tmpbuf, midioutportinfo[0]->name)))
p->midioutdev = -1;
for (int i = 0; i < MAX_MIDI_PORTS && midioutportinfo[i]; i++) {
if (!_tcsicmp (midioutportinfo[i]->name, tmpbuf)) {
p->midioutdev = midioutportinfo[i]->devid;
}
}
return 1;
}
if (cfgfile_string_escape(option, value, _T("midiin_device_name"), tmpbuf, 256)) {
p->midiindev = -1;
for (int i = 0; i < MAX_MIDI_PORTS && midiinportinfo[i]; i++) {
if (!_tcsicmp (midiinportinfo[i]->name, tmpbuf)) {
p->midiindev = midiinportinfo[i]->devid;
}
}
return 1;
}
// if (cfgfile_string_escape(option, value, _T("midiout_device_name"), tmpbuf, 256)) {
// p->midioutdev = -2;
// if (!_tcsicmp (tmpbuf, _T("default")) || (midioutportinfo[0] && !_tcsicmp (tmpbuf, midioutportinfo[0]->name)))
// p->midioutdev = -1;
// for (int i = 0; i < MAX_MIDI_PORTS && midioutportinfo[i]; i++) {
// if (!_tcsicmp (midioutportinfo[i]->name, tmpbuf)) {
// p->midioutdev = midioutportinfo[i]->devid;
// }
// }
// return 1;
// }
// if (cfgfile_string_escape(option, value, _T("midiin_device_name"), tmpbuf, 256)) {
// p->midiindev = -1;
// for (int i = 0; i < MAX_MIDI_PORTS && midiinportinfo[i]; i++) {
// if (!_tcsicmp (midiinportinfo[i]->name, tmpbuf)) {
// p->midiindev = midiinportinfo[i]->devid;
// }
// }
// return 1;
// }

return 0;
}
Expand Down
8 changes: 4 additions & 4 deletions src/osdep/amiberry_gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1393,12 +1393,12 @@ int check_prefs_changed_gfx()
#endif
}

if (currprefs.midiindev != changed_prefs.midiindev ||
currprefs.midioutdev != changed_prefs.midioutdev ||
if (_tcscmp(currprefs.midiindev, changed_prefs.midiindev) ||
_tcscmp(currprefs.midioutdev, changed_prefs.midioutdev) ||
currprefs.midirouter != changed_prefs.midirouter)
{
currprefs.midiindev = changed_prefs.midiindev;
currprefs.midioutdev = changed_prefs.midioutdev;
_tcscpy(currprefs.midiindev, changed_prefs.midiindev);
_tcscpy(currprefs.midioutdev, changed_prefs.midioutdev);
currprefs.midirouter = changed_prefs.midirouter;

#ifdef SERIAL_PORT
Expand Down
7 changes: 5 additions & 2 deletions src/osdep/amiberry_gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@ bool config_loaded = false;
int gui_active;

//struct serparportinfo *comports[MAX_SERPAR_PORTS];
//struct midiportinfo *midiinportinfo[MAX_MIDI_PORTS];
//struct midiportinfo *midioutportinfo[MAX_MIDI_PORTS];

std::vector<std::string> serial_ports;
struct midiportinfo *midiinportinfo[MAX_MIDI_PORTS];
struct midiportinfo *midioutportinfo[MAX_MIDI_PORTS];
std::vector<std::string> midi_in_ports;
std::vector<std::string> midi_out_ports;

struct gui_msg
{
Expand Down
2 changes: 1 addition & 1 deletion src/osdep/amiberry_serial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ void serial_hsynchandler (void)
int setbaud(int baud, int org_baud)
{
#ifdef WITH_MIDI
if (org_baud == 31400 && currprefs.midioutdev >= -1) {
if (org_baud == 31400 && _tcscmp(currprefs.midioutdev, "none") != 0) {
/* MIDI baud-rate */
#ifdef WITH_MIDIEMU
if (currprefs.midioutdev >= 0) {
Expand Down
28 changes: 26 additions & 2 deletions src/parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
#include <netdb.h>
#endif

#ifdef WITH_MIDI
#include "portmidi.h"
#endif

#include "uae/socket.h"

#if !defined B300 || !defined B1200 || !defined B2400 || !defined B4800 || !defined B9600
Expand Down Expand Up @@ -528,6 +532,26 @@ int enumserialports (void)

int enummidiports (void)
{
//TODO
return 0;
int total = 0;

#ifdef WITH_MIDI
total = Pm_CountDevices();
write_log(_T("MIDI: found devices: %d\n"), total);
for(int i=0; i<total; i++) {
const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
write_log(_T("MIDI: %d: '%s', '%s' %s %s\n"),
i, info->interf, info->name,
info->input ? "IN" : " ",
info->output ? "OUT" : " ");

if(info->input) {
midi_in_ports.emplace_back(info->name);
}
if(info->output) {
midi_out_ports.emplace_back(info->name);
}
}
#endif

return total;
}

0 comments on commit 20d7258

Please sign in to comment.