Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion data/darktableconfig.xml.in
Original file line number Diff line number Diff line change
Expand Up @@ -4007,6 +4007,6 @@
<type>string</type>
<default></default>
<shortdescription>order or exclude MIDI devices</shortdescription>
<longdescription>comma-separated list of device name fragments that if matched load MIDI device at id given by location in list\nor if preceded by '-' prevent matching devices from loading. add encoding and number of knobs like 'BeatStep:63:16'</longdescription>
<longdescription>comma-separated list of device name fragments that if matched load MIDI device at id given by location in list\nadd encoding and number of knobs like 'Loupedeck:127,BeatStep:63:16'\nprefix with '-' to ignore matching devices\njust '-' stops loading all further devices or on its own disables midi completely</longdescription>
</dtconfig>
</dtconfiglist>
27 changes: 16 additions & 11 deletions src/libs/tools/midi.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,11 @@ static gboolean _poll_devices(gpointer user_data)

static void _midi_open_devices(dt_lib_module_t *self)
{
dt_input_device_t id = dt_register_input_driver(self, &_driver_definition);
const char *devices_string = dt_conf_get_string_const("plugins/midi/devices");
if(!strcmp(devices_string, "-"))
return;

if(Pm_Initialize())
{
dt_print(DT_DEBUG_ALWAYS, "[_midi_open_devices] ERROR initialising PortMidi");
Expand All @@ -487,11 +492,7 @@ static void _midi_open_devices(dt_lib_module_t *self)
else
dt_print(DT_DEBUG_INPUT, "[_midi_open_devices] PortMidi initialized");

dt_input_device_t id = dt_register_input_driver(self, &_driver_definition);

const char *devices_string = dt_conf_get_string_const("plugins/midi/devices");
gchar **dev_strings = g_strsplit(devices_string, ",", 0);

int last_dev = -1;

for(int i = 0; i < Pm_CountDevices(); i++)
Expand Down Expand Up @@ -620,7 +621,10 @@ static void _midi_open_devices(dt_lib_module_t *self)

g_strfreev(dev_strings);

if(self->data) g_timeout_add(10, _poll_devices, self);
if(self->data)
g_timeout_add(10, _poll_devices, self);
else
Pm_Terminate();
}

static void _midi_device_free(dt_midi_device_t *midi)
Expand All @@ -637,12 +641,13 @@ static void _midi_device_free(dt_midi_device_t *midi)

static void _midi_close_devices(dt_lib_module_t *self)
{
g_source_remove_by_user_data(self);

g_slist_free_full(self->data, (void (*)(void *))_midi_device_free);
self->data = NULL;

Pm_Terminate();
if(self->data)
{
g_source_remove_by_user_data(self);
g_slist_free_full(self->data, (void (*)(void *))_midi_device_free);
self->data = NULL;
Pm_Terminate();
}
}

static gboolean _update_devices(gpointer user_data)
Expand Down
Loading