Merge pull request #2491 from jriwanek-forks/cleanups

Cleanups to various bits of code
This commit is contained in:
Miran Grča
2022-07-22 04:42:33 +02:00
committed by GitHub
8 changed files with 2138 additions and 2276 deletions

View File

@@ -1458,7 +1458,7 @@ acpi_apm_out(uint16_t port, uint8_t val, void *p)
dev->apm->cmd = val; dev->apm->cmd = val;
if (dev->vendor == VEN_INTEL) if (dev->vendor == VEN_INTEL)
dev->regs.glbsts |= 0x20; dev->regs.glbsts |= 0x20;
acpi_raise_smi(dev, dev->apm->do_smi); acpi_raise_smi(dev, dev->apm->do_smi);
} else } else
dev->apm->stat = val; dev->apm->stat = val;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -51,21 +51,21 @@
enum { enum {
CPUID_FPU = (1 << 0), CPUID_FPU = (1 << 0),
CPUID_VME = (1 << 1), CPUID_VME = (1 << 1),
CPUID_PSE = (1 << 3), CPUID_PSE = (1 << 3),
CPUID_TSC = (1 << 4), CPUID_TSC = (1 << 4),
CPUID_MSR = (1 << 5), CPUID_MSR = (1 << 5),
CPUID_PAE = (1 << 6), CPUID_PAE = (1 << 6),
CPUID_MCE = (1 << 7), CPUID_MCE = (1 << 7),
CPUID_CMPXCHG8B = (1 << 8), CPUID_CMPXCHG8B = (1 << 8),
CPUID_AMDSEP = (1 << 10), CPUID_AMDSEP = (1 << 10),
CPUID_SEP = (1 << 11), CPUID_SEP = (1 << 11),
CPUID_MTRR = (1 << 12), CPUID_MTRR = (1 << 12),
CPUID_MCA = (1 << 14), CPUID_MCA = (1 << 14),
CPUID_CMOV = (1 << 15), CPUID_CMOV = (1 << 15),
CPUID_MMX = (1 << 23), CPUID_MMX = (1 << 23),
CPUID_FXSR = (1 << 24) CPUID_FXSR = (1 << 24)
}; };
/*Addition flags returned by CPUID function 0x80000001*/ /*Addition flags returned by CPUID function 0x80000001*/

View File

@@ -344,15 +344,6 @@ extern int machine_ppc512_init(const machine_t *);
extern int machine_pc2086_init(const machine_t *); extern int machine_pc2086_init(const machine_t *);
extern int machine_pc3086_init(const machine_t *); extern int machine_pc3086_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *pc1512_get_device(void);
extern const device_t *pc1640_get_device(void);
extern const device_t *pc200_get_device(void);
extern const device_t *ppc512_get_device(void);
extern const device_t *pc2086_get_device(void);
extern const device_t *pc3086_get_device(void);
#endif
/* m_at.c */ /* m_at.c */
extern void machine_at_common_init_ex(const machine_t *, int type); extern void machine_at_common_init_ex(const machine_t *, int type);
extern void machine_at_common_init(const machine_t *); extern void machine_at_common_init(const machine_t *);
@@ -425,14 +416,6 @@ extern int machine_at_awardsx_init(const machine_t *);
extern int machine_at_pc916sx_init(const machine_t *); extern int machine_at_pc916sx_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *at_ama932j_get_device(void);
extern const device_t *at_flytech386_get_device(void);
extern const device_t *at_cmdsl386sx25_get_device(void);
extern const device_t *at_spc4620p_get_device(void);
extern const device_t *at_spc6033p_get_device(void);
#endif
/* m_at_386dx_486.c */ /* m_at_386dx_486.c */
extern int machine_at_acc386_init(const machine_t *); extern int machine_at_acc386_init(const machine_t *);
extern int machine_at_asus386_init(const machine_t *); extern int machine_at_asus386_init(const machine_t *);
@@ -516,15 +499,6 @@ extern int machine_at_actionpc2600_init(const machine_t *);
extern int machine_at_m919_init(const machine_t *); extern int machine_at_m919_init(const machine_t *);
extern int machine_at_spc7700plw_init(const machine_t *); extern int machine_at_spc7700plw_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *at_acera1g_get_device(void);
extern const device_t *at_vect486vl_get_device(void);
extern const device_t *at_d824_get_device(void);
extern const device_t *at_pcs46c_get_device(void);
extern const device_t *at_valuepoint433_get_device(void);
extern const device_t *at_sbc490_get_device(void);
#endif
/* m_at_commodore.c */ /* m_at_commodore.c */
extern int machine_at_cmdpc_init(const machine_t *); extern int machine_at_cmdpc_init(const machine_t *);
@@ -535,9 +509,6 @@ extern int machine_at_portableiii386_init(const machine_t *);
#if defined(DEV_BRANCH) && defined(USE_DESKPRO386) #if defined(DEV_BRANCH) && defined(USE_DESKPRO386)
extern int machine_at_deskpro386_init(const machine_t *); extern int machine_at_deskpro386_init(const machine_t *);
#endif #endif
#ifdef EMU_DEVICE_H
extern const device_t *at_cpqiii_get_device(void);
#endif
/* m_at_socket4.c */ /* m_at_socket4.c */
extern void machine_at_premiere_common_init(const machine_t *, int); extern void machine_at_premiere_common_init(const machine_t *, int);
@@ -562,10 +533,6 @@ extern int machine_at_p5vl_init(const machine_t *);
extern int machine_at_excaliburpci2_init(const machine_t *); extern int machine_at_excaliburpci2_init(const machine_t *);
extern int machine_at_p5sp4_init(const machine_t *); extern int machine_at_p5sp4_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *at_pb520r_get_device(void);
#endif
/* m_at_socket5.c */ /* m_at_socket5.c */
extern int machine_at_plato_init(const machine_t *); extern int machine_at_plato_init(const machine_t *);
extern int machine_at_ambradp90_init(const machine_t *); extern int machine_at_ambradp90_init(const machine_t *);
@@ -609,14 +576,6 @@ extern int machine_at_gw2kte_init(const machine_t *);
extern int machine_at_ap5s_init(const machine_t *); extern int machine_at_ap5s_init(const machine_t *);
extern int machine_at_vectra54_init(const machine_t *); extern int machine_at_vectra54_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *at_endeavor_get_device(void);
#define at_vectra54_get_device at_endeavor_get_device
extern const device_t *at_thor_get_device(void);
#define at_mrthor_get_device at_thor_get_device
extern const device_t *at_pb640_get_device(void);
#endif
/* m_at_socket7.c */ /* m_at_socket7.c */
extern int machine_at_acerv35n_init(const machine_t *); extern int machine_at_acerv35n_init(const machine_t *);
extern int machine_at_p55t2p4_init(const machine_t *); extern int machine_at_p55t2p4_init(const machine_t *);
@@ -658,11 +617,6 @@ extern int machine_at_ms5146_init(const machine_t *);
extern int machine_at_m560_init(const machine_t *); extern int machine_at_m560_init(const machine_t *);
extern int machine_at_ms5164_init(const machine_t *); extern int machine_at_ms5164_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *at_presario2240_get_device(void);
#define at_presario4500_get_device at_presario2240_get_device
#endif
/* m_at_sockets7.c */ /* m_at_sockets7.c */
extern int machine_at_p5a_init(const machine_t *); extern int machine_at_p5a_init(const machine_t *);
extern int machine_at_m579_init(const machine_t *); extern int machine_at_m579_init(const machine_t *);
@@ -718,14 +672,6 @@ extern int machine_at_vei8_init(const machine_t *);
extern int machine_at_borapro_init(const machine_t *); extern int machine_at_borapro_init(const machine_t *);
extern int machine_at_ms6168_init(const machine_t *); extern int machine_at_ms6168_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *at_s1846_get_device(void);
#define at_s1857_get_device at_s1846_get_device
#define at_gt694va_get_device at_s1846_get_device
extern const device_t *at_ms6168_get_device(void);
#define at_borapro_get_device at_ms6168_get_device
#endif
/* m_at_slot2.c */ /* m_at_slot2.c */
extern int machine_at_6gxu_init(const machine_t *); extern int machine_at_6gxu_init(const machine_t *);
extern int machine_at_s2dge_init(const machine_t *); extern int machine_at_s2dge_init(const machine_t *);
@@ -743,9 +689,6 @@ extern int machine_at_s370sba_init(const machine_t *);
extern int machine_at_apas3_init(const machine_t *); extern int machine_at_apas3_init(const machine_t *);
extern int machine_at_gt694va_init(const machine_t *); extern int machine_at_gt694va_init(const machine_t *);
extern int machine_at_cuv4xls_init(const machine_t *); extern int machine_at_cuv4xls_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *at_cuv4xls_get_device(void);
#endif
extern int machine_at_6via90ap_init(const machine_t *); extern int machine_at_6via90ap_init(const machine_t *);
extern int machine_at_s1857_init(const machine_t *); extern int machine_at_s1857_init(const machine_t *);
extern int machine_at_p6bap_init(const machine_t *); extern int machine_at_p6bap_init(const machine_t *);
@@ -764,22 +707,12 @@ extern const device_t europc_device;
/* m_xt_olivetti.c */ /* m_xt_olivetti.c */
extern int machine_xt_m24_init(const machine_t *); extern int machine_xt_m24_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *m24_get_device(void);
#endif
extern int machine_xt_m240_init(const machine_t *); extern int machine_xt_m240_init(const machine_t *);
extern int machine_xt_m19_init(const machine_t *); extern int machine_xt_m19_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *m19_get_device(void);
#endif
/* m_pcjr.c */ /* m_pcjr.c */
extern int machine_pcjr_init(const machine_t *); extern int machine_pcjr_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *pcjr_get_device(void);
#endif
/* m_ps1.c */ /* m_ps1.c */
extern int machine_ps1_m2011_init(const machine_t *); extern int machine_ps1_m2011_init(const machine_t *);
extern int machine_ps1_m2121_init(const machine_t *); extern int machine_ps1_m2121_init(const machine_t *);
@@ -811,12 +744,6 @@ extern int machine_tandy1000sl2_init(const machine_t *);
/* m_v86p.c */ /* m_v86p.c */
extern int machine_v86p_init(const machine_t *); extern int machine_v86p_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *tandy1k_get_device(void);
extern const device_t *tandy1k_hx_get_device(void);
extern const device_t *tandy1k_sl_get_device(void);
#endif
/* m_xt.c */ /* m_xt.c */
extern int machine_pc_init(const machine_t *); extern int machine_pc_init(const machine_t *);
extern int machine_pc82_init(const machine_t *); extern int machine_pc82_init(const machine_t *);
@@ -866,24 +793,13 @@ extern int machine_xt_p3120_init(const machine_t *);
extern int machine_xt_t1000_init(const machine_t *); extern int machine_xt_t1000_init(const machine_t *);
extern int machine_xt_t1200_init(const machine_t *); extern int machine_xt_t1200_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *t1000_get_device(void);
extern const device_t *t1200_get_device(void);
#endif
/* m_xt_zenith.c */ /* m_xt_zenith.c */
extern int machine_xt_z184_init(const machine_t *); extern int machine_xt_z184_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *z184_get_device(void);
#endif
extern int machine_xt_z151_init(const machine_t *); extern int machine_xt_z151_init(const machine_t *);
extern int machine_xt_z159_init(const machine_t *); extern int machine_xt_z159_init(const machine_t *);
/* m_xt_xi8088.c */ /* m_xt_xi8088.c */
extern int machine_xt_xi8088_init(const machine_t *); extern int machine_xt_xi8088_init(const machine_t *);
#ifdef EMU_DEVICE_H
extern const device_t *xi8088_get_device(void);
#endif
#endif /*EMU_MACHINE_H*/ #endif /*EMU_MACHINE_H*/

View File

@@ -39,7 +39,7 @@
# define EMU_NVRPS2_H # define EMU_NVRPS2_H
extern const device_t ps2_nvr_device; extern const device_t ps2_nvr_device;
extern const device_t ps2_nvr_55ls_device; extern const device_t ps2_nvr_55ls_device;

View File

@@ -10,44 +10,44 @@
#define VAR_ROW1_MA14 (1 << 3) #define VAR_ROW1_MA14 (1 << 3)
#define ADDRESS_REMAP_FUNC(nr) \ #define ADDRESS_REMAP_FUNC(nr) \
static uint32_t address_remap_func_ ## nr(ega_t *ega, uint32_t in_addr) \ static uint32_t address_remap_func_ ## nr(ega_t *ega, uint32_t in_addr) \
{ \ { \
uint32_t out_addr; \ uint32_t out_addr; \
\ \
switch (nr & VAR_MODE_MASK) \ switch (nr & VAR_MODE_MASK) \
{ \ { \
case VAR_BYTE_MODE: \ case VAR_BYTE_MODE: \
out_addr = in_addr; \ out_addr = in_addr; \
break; \ break; \
\ \
case VAR_WORD_MODE_MA13: \ case VAR_WORD_MODE_MA13: \
out_addr = ((in_addr << 1) & 0x1fff8) | \ out_addr = ((in_addr << 1) & 0x1fff8) | \
((in_addr >> 13) & 0x4) | \ ((in_addr >> 13) & 0x4) | \
(in_addr & ~0x1ffff); \ (in_addr & ~0x1ffff); \
break; \ break; \
\ \
case VAR_WORD_MODE_MA15: \ case VAR_WORD_MODE_MA15: \
out_addr = ((in_addr << 1) & 0x1fff8) | \ out_addr = ((in_addr << 1) & 0x1fff8) | \
((in_addr >> 15) & 0x4) | \ ((in_addr >> 15) & 0x4) | \
(in_addr & ~0x1ffff); \ (in_addr & ~0x1ffff); \
break; \ break; \
\ \
case VAR_DWORD_MODE: \ case VAR_DWORD_MODE: \
out_addr = ((in_addr << 2) & 0x3fff0) | \ out_addr = ((in_addr << 2) & 0x3fff0) | \
((in_addr >> 14) & 0xc) | \ ((in_addr >> 14) & 0xc) | \
(in_addr & ~0x3ffff); \ (in_addr & ~0x3ffff); \
break; \ break; \
} \ } \
\ \
if (nr & VAR_ROW0_MA13) \ if (nr & VAR_ROW0_MA13) \
out_addr = (out_addr & ~0x8000) | \ out_addr = (out_addr & ~0x8000) | \
((ega->sc & 1) ? 0x8000 : 0); \ ((ega->sc & 1) ? 0x8000 : 0); \
if (nr & VAR_ROW1_MA14) \ if (nr & VAR_ROW1_MA14) \
out_addr = (out_addr & ~0x10000) | \ out_addr = (out_addr & ~0x10000) | \
((ega->sc & 2) ? 0x10000 : 0); \ ((ega->sc & 2) ? 0x10000 : 0); \
\ \
return out_addr; \ return out_addr; \
} }
ADDRESS_REMAP_FUNC(0) ADDRESS_REMAP_FUNC(0)
ADDRESS_REMAP_FUNC(1) ADDRESS_REMAP_FUNC(1)
@@ -68,22 +68,22 @@ ADDRESS_REMAP_FUNC(15)
static uint32_t (*address_remap_funcs[16])(ega_t *ega, uint32_t in_addr) = static uint32_t (*address_remap_funcs[16])(ega_t *ega, uint32_t in_addr) =
{ {
address_remap_func_0, address_remap_func_0,
address_remap_func_1, address_remap_func_1,
address_remap_func_2, address_remap_func_2,
address_remap_func_3, address_remap_func_3,
address_remap_func_4, address_remap_func_4,
address_remap_func_5, address_remap_func_5,
address_remap_func_6, address_remap_func_6,
address_remap_func_7, address_remap_func_7,
address_remap_func_8, address_remap_func_8,
address_remap_func_9, address_remap_func_9,
address_remap_func_10, address_remap_func_10,
address_remap_func_11, address_remap_func_11,
address_remap_func_12, address_remap_func_12,
address_remap_func_13, address_remap_func_13,
address_remap_func_14, address_remap_func_14,
address_remap_func_15 address_remap_func_15
}; };
void ega_recalc_remap_func(ega_t *ega) void ega_recalc_remap_func(ega_t *ega)

View File

@@ -61,7 +61,6 @@ static uint16_t smi_irq_mask = 0x0000,
static void (*update_pending)(void); static void (*update_pending)(void);
#ifdef ENABLE_PIC_LOG #ifdef ENABLE_PIC_LOG
int pic_do_log = ENABLE_PIC_LOG; int pic_do_log = ENABLE_PIC_LOG;

View File

@@ -15,12 +15,12 @@
*/ */
#if defined __has_include #if defined __has_include
# if __has_include (<RtMidi.h>) # if __has_include(<RtMidi.h>)
# include <RtMidi.h> # include <RtMidi.h>
# endif # endif
# if __has_include (<rtmidi/RtMidi.h>) # if __has_include(<rtmidi/RtMidi.h>)
# include <rtmidi/RtMidi.h> # include <rtmidi/RtMidi.h>
# endif # endif
#endif #endif
#include <cstdint> #include <cstdint>
@@ -38,16 +38,15 @@ extern "C"
// Disable c99-designator to avoid the warnings in rtmidi_*_device // Disable c99-designator to avoid the warnings in rtmidi_*_device
#ifdef __clang__ #ifdef __clang__
#if __has_warning("-Wc99-designator") # if __has_warning("-Wc99-designator")
#pragma clang diagnostic ignored "-Wc99-designator" # pragma clang diagnostic ignored "-Wc99-designator"
#endif # endif
#endif #endif
static RtMidiOut * midiout = nullptr; static RtMidiOut *midiout = nullptr;
static RtMidiIn * midiin = nullptr; static RtMidiIn *midiin = nullptr;
static int midi_out_id = 0, midi_in_id = 0; static int midi_out_id = 0, midi_in_id = 0;
static const int midi_lengths[8] = {3, 3, 3, 3, 2, 2, 3, 1}; static const int midi_lengths[8] = { 3, 3, 3, 3, 2, 2, 3, 1 };
int int
rtmidi_write(uint8_t val) rtmidi_write(uint8_t val)
@@ -55,55 +54,53 @@ rtmidi_write(uint8_t val)
return 0; return 0;
} }
void void
rtmidi_play_msg(uint8_t *msg) rtmidi_play_msg(uint8_t *msg)
{ {
if (midiout) if (midiout)
midiout->sendMessage(msg, midi_lengths[(msg[0] >> 4) & 7]); midiout->sendMessage(msg, midi_lengths[(msg[0] >> 4) & 7]);
} }
void void
rtmidi_play_sysex(uint8_t *sysex, unsigned int len) rtmidi_play_sysex(uint8_t *sysex, unsigned int len)
{ {
if (midiout) if (midiout)
midiout->sendMessage(sysex, len); midiout->sendMessage(sysex, len);
} }
void* void*
rtmidi_output_init(const device_t *info) rtmidi_output_init(const device_t *info)
{ {
midi_device_t* dev = (midi_device_t*)malloc(sizeof(midi_device_t)); midi_device_t *dev = (midi_device_t *) malloc(sizeof(midi_device_t));
memset(dev, 0, sizeof(midi_device_t)); memset(dev, 0, sizeof(midi_device_t));
dev->play_msg = rtmidi_play_msg; dev->play_msg = rtmidi_play_msg;
dev->play_sysex = rtmidi_play_sysex; dev->play_sysex = rtmidi_play_sysex;
dev->write = rtmidi_write; dev->write = rtmidi_write;
try { try {
if (!midiout) midiout = new RtMidiOut; if (!midiout)
} catch (RtMidiError& error) { midiout = new RtMidiOut;
pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str()); } catch (RtMidiError &error) {
return nullptr;
}
midi_out_id = config_get_int((char*)SYSTEM_MIDI_NAME, (char*)"midi", 0);
try {
midiout->openPort(midi_out_id);
} catch (RtMidiError& error) {
pclog("Fallback to default MIDI output port: %s\n", error.getMessage().c_str());
try {
midiout->openPort(0);
} catch (RtMidiError& error) {
pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str()); pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str());
delete midiout;
midiout = nullptr;
return nullptr; return nullptr;
} }
midi_out_id = config_get_int((char *) SYSTEM_MIDI_NAME, (char *) "midi", 0);
try {
midiout->openPort(midi_out_id);
} catch (RtMidiError &error) {
pclog("Fallback to default MIDI output port: %s\n", error.getMessage().c_str());
try {
midiout->openPort(0);
} catch (RtMidiError &error) {
pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str());
delete midiout;
midiout = nullptr;
return nullptr;
}
} }
midi_out_init(dev); midi_out_init(dev);
@@ -111,12 +108,11 @@ rtmidi_output_init(const device_t *info)
return dev; return dev;
} }
void void
rtmidi_output_close(void *p) rtmidi_output_close(void *p)
{ {
if (!midiout) if (!midiout)
return; return;
midiout->closePort(); midiout->closePort();
@@ -126,68 +122,64 @@ rtmidi_output_close(void *p)
midi_out_close(); midi_out_close();
} }
int int
rtmidi_out_get_num_devs(void) rtmidi_out_get_num_devs(void)
{ {
if (!midiout) { if (!midiout) {
try { try {
midiout = new RtMidiOut; midiout = new RtMidiOut;
} catch (RtMidiError& error) { } catch (RtMidiError &error) {
pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str()); pclog("Failed to initialize MIDI output: %s\n", error.getMessage().c_str());
} }
} }
return midiout ? midiout->getPortCount() : 0; return midiout ? midiout->getPortCount() : 0;
} }
void void
rtmidi_out_get_dev_name(int num, char *s) rtmidi_out_get_dev_name(int num, char *s)
{ {
strcpy(s, midiout->getPortName(num).c_str()); strcpy(s, midiout->getPortName(num).c_str());
} }
void void
rtmidi_input_callback(double timeStamp, std::vector<unsigned char> *message, void *userData) rtmidi_input_callback(double timeStamp, std::vector<unsigned char> *message, void *userData)
{ {
if (message->front() == 0xF0) if (message->front() == 0xF0)
midi_in_sysex(message->data(), message->size()); midi_in_sysex(message->data(), message->size());
else else
midi_in_msg(message->data(), message->size()); midi_in_msg(message->data(), message->size());
} }
void* void*
rtmidi_input_init(const device_t *info) rtmidi_input_init(const device_t *info)
{ {
midi_device_t* dev = (midi_device_t*)malloc(sizeof(midi_device_t)); midi_device_t *dev = (midi_device_t *) malloc(sizeof(midi_device_t));
memset(dev, 0, sizeof(midi_device_t)); memset(dev, 0, sizeof(midi_device_t));
try { try {
if (!midiin) if (!midiin)
midiin = new RtMidiIn; midiin = new RtMidiIn;
} catch (RtMidiError& error) { } catch (RtMidiError &error) {
pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str());
return nullptr;
}
midi_in_id = config_get_int((char*)MIDI_INPUT_NAME, (char*)"midi_input", 0);
try {
midiin->openPort(midi_in_id);
} catch (RtMidiError& error) {
pclog("Fallback to default MIDI input port: %s\n", error.getMessage().c_str());
try {
midiin->openPort(0);
} catch (RtMidiError& error) {
pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str()); pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str());
delete midiin;
midiin = nullptr;
return nullptr; return nullptr;
} }
midi_in_id = config_get_int((char *) MIDI_INPUT_NAME, (char *) "midi_input", 0);
try {
midiin->openPort(midi_in_id);
} catch (RtMidiError &error) {
pclog("Fallback to default MIDI input port: %s\n", error.getMessage().c_str());
try {
midiin->openPort(0);
} catch (RtMidiError &error) {
pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str());
delete midiin;
midiin = nullptr;
return nullptr;
}
} }
midiin->setCallback(&rtmidi_input_callback); midiin->setCallback(&rtmidi_input_callback);
@@ -198,15 +190,14 @@ rtmidi_input_init(const device_t *info)
midi_in_init(dev, &midi_in); midi_in_init(dev, &midi_in);
midi_in->midi_realtime = device_get_config_int("realtime"); midi_in->midi_realtime = device_get_config_int("realtime");
midi_in->thruchan = device_get_config_int("thruchan"); midi_in->thruchan = device_get_config_int("thruchan");
midi_in->midi_clockout = device_get_config_int("clockout"); midi_in->midi_clockout = device_get_config_int("clockout");
return dev; return dev;
} }
void void
rtmidi_input_close(void* p) rtmidi_input_close(void *p)
{ {
midiin->cancelCallback(); midiin->cancelCallback();
midiin->closePort(); midiin->closePort();
@@ -217,22 +208,20 @@ rtmidi_input_close(void* p)
midi_out_close(); midi_out_close();
} }
int int
rtmidi_in_get_num_devs(void) rtmidi_in_get_num_devs(void)
{ {
if (!midiin) { if (!midiin) {
try { try {
midiin = new RtMidiIn; midiin = new RtMidiIn;
} catch (RtMidiError& error) { } catch (RtMidiError &error) {
pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str()); pclog("Failed to initialize MIDI input: %s\n", error.getMessage().c_str());
} }
} }
return midiin ? midiin->getPortCount() : 0; return midiin ? midiin->getPortCount() : 0;
} }
void void
rtmidi_in_get_dev_name(int num, char *s) rtmidi_in_get_dev_name(int num, char *s)
{ {
@@ -240,6 +229,7 @@ rtmidi_in_get_dev_name(int num, char *s)
} }
static const device_config_t system_midi_config[] = { static const device_config_t system_midi_config[] = {
// clang-format off
{ {
.name = "midi", .name = "midi",
.description = "MIDI out device", .description = "MIDI out device",
@@ -248,9 +238,11 @@ static const device_config_t system_midi_config[] = {
.default_int = 0 .default_int = 0
}, },
{ .name = "", .description = "", .type = CONFIG_END } { .name = "", .description = "", .type = CONFIG_END }
// clang-format on
}; };
static const device_config_t midi_input_config[] = { static const device_config_t midi_input_config[] = {
// clang-format off
{ {
.name = "midi_input", .name = "midi_input",
.description = "MIDI in device", .description = "MIDI in device",
@@ -280,6 +272,7 @@ static const device_config_t midi_input_config[] = {
.default_int = 1 .default_int = 1
}, },
{ .name = "", .description = "", .type = CONFIG_END } { .name = "", .description = "", .type = CONFIG_END }
// clang-format on
}; };
const device_t rtmidi_output_device = { const device_t rtmidi_output_device = {
@@ -309,5 +302,4 @@ const device_t rtmidi_input_device = {
.force_redraw = NULL, .force_redraw = NULL,
.config = midi_input_config .config = midi_input_config
}; };
} }