Browse Source

Add global guard on portmidi init

master
cancel 5 years ago
parent
commit
e2925cf8e9
  1. 15
      tui_main.c

15
tui_main.c

@ -753,6 +753,9 @@ typedef struct {
PmDeviceID device_id; PmDeviceID device_id;
PortMidiStream* stream; PortMidiStream* stream;
} Midi_mode_portmidi; } Midi_mode_portmidi;
// Not sure whether it's OK to call Pm_Terminate() without having a successful
// call to Pm_Initialize() -- let's just treat it with tweezers.
static bool portmidi_is_initialized = false;
#endif #endif
typedef union { typedef union {
@ -769,8 +772,17 @@ void midi_mode_init_osc_bidule(Midi_mode* mm, char const* path) {
mm->osc_bidule.path = path; mm->osc_bidule.path = path;
} }
#ifdef FEAT_PORTMIDI #ifdef FEAT_PORTMIDI
PmError midi_mode_init_portmidi(Midi_mode* mm, PmDeviceID dev_id) { PmError portmidi_init_if_necessary(void) {
if (portmidi_is_initialized)
return 0;
PmError e = Pm_Initialize(); PmError e = Pm_Initialize();
if (e)
return e;
portmidi_is_initialized = true;
return 0;
}
PmError midi_mode_init_portmidi(Midi_mode* mm, PmDeviceID dev_id) {
PmError e = portmidi_init_if_necessary();
if (e) if (e)
return e; return e;
e = Pm_OpenOutput(&mm->portmidi.stream, dev_id, NULL, 0, NULL, NULL, 0); e = Pm_OpenOutput(&mm->portmidi.stream, dev_id, NULL, 0, NULL, NULL, 0);
@ -3327,6 +3339,7 @@ quit:
heapstr_deinit(&file_name); heapstr_deinit(&file_name);
midi_mode_deinit(&midi_mode); midi_mode_deinit(&midi_mode);
#ifdef FEAT_PORTMIDI #ifdef FEAT_PORTMIDI
if (portmidi_is_initialized)
Pm_Terminate(); Pm_Terminate();
#endif #endif
return 0; return 0;

Loading…
Cancel
Save