refactor: replace C++ lambdas with C callback functions

Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
Loic Coenen
2026-05-02 21:30:31 +00:00
parent 6bd2e762cb
commit d61632d54c

83
tui.c
View File

@@ -221,6 +221,49 @@ static void play_prev_scene(void) {
selected_row = prev_row; selected_row = prev_row;
} }
// Callback for adding a plugin via fuzzy search
static void rack_add_plugin_callback(const char *selection) {
if (selection) {
// Parse URI from selection (format: "uri - name")
char uri[512];
const char *space = strchr(selection, ' ');
if (space) {
size_t len = space - selection;
strncpy(uri, selection, len);
uri[len] = '\0';
} else {
strncpy(uri, selection, sizeof(uri) - 1);
}
Action action = {
.type = ACTION_RACK_ADD_PLUGIN,
.data.rack_add_plugin = {
.channel = rack_selected_channel,
.type = PLUGIN_TYPE_INTERNAL
}
};
strncpy(action.data.rack_add_plugin.uri, uri, sizeof(action.data.rack_add_plugin.uri) - 1);
action.data.rack_add_plugin.uri[sizeof(action.data.rack_add_plugin.uri) - 1] = '\0';
g_dispatch(action);
}
}
// Callback for MIDI from selection
static void midi_from_callback(const char *selection) {
if (selection) {
printf("Selected MIDI input: %s\n", selection);
// In a real implementation, this would connect JACK ports
}
}
// Callback for MIDI to selection
static void midi_to_callback(const char *selection) {
if (selection) {
printf("Selected MIDI output: %s\n", selection);
// In a real implementation, this would connect JACK ports
}
}
// Fuzzy matching function // Fuzzy matching function
static bool fuzzy_match(const char *pattern, const char *text) { static bool fuzzy_match(const char *pattern, const char *text) {
if (!pattern || !*pattern) return true; if (!pattern || !*pattern) return true;
@@ -472,31 +515,7 @@ static bool handle_rack_view(int ch) {
break; break;
case 'a': { case 'a': {
// Start fuzzy search for plugin selection // Start fuzzy search for plugin selection
start_fuzzy_search("Add plugin:", [](const char *selection) { start_fuzzy_search("Add plugin:", rack_add_plugin_callback);
if (selection) {
// Parse URI from selection (format: "uri - name")
char uri[512];
const char *space = strchr(selection, ' ');
if (space) {
size_t len = space - selection;
strncpy(uri, selection, len);
uri[len] = '\0';
} else {
strncpy(uri, selection, sizeof(uri) - 1);
}
Action action = {
.type = ACTION_RACK_ADD_PLUGIN,
.data.rack_add_plugin = {
.channel = rack_selected_channel,
.type = PLUGIN_TYPE_INTERNAL
}
};
strncpy(action.data.rack_add_plugin.uri, uri, sizeof(action.data.rack_add_plugin.uri) - 1);
action.data.rack_add_plugin.uri[sizeof(action.data.rack_add_plugin.uri) - 1] = '\0';
g_dispatch(action);
}
});
break; break;
} }
case 'd': { case 'd': {
@@ -704,20 +723,10 @@ static bool handle_command_mode(void) {
g_dispatch(action); g_dispatch(action);
} else if (strcmp(cmd_buffer, "from") == 0) { } else if (strcmp(cmd_buffer, "from") == 0) {
// :from - open fuzzy search for MIDI input source // :from - open fuzzy search for MIDI input source
start_fuzzy_search("Select MIDI input source:", [](const char *selection) { start_fuzzy_search("Select MIDI input source:", midi_from_callback);
if (selection) {
printf("Selected MIDI input: %s\n", selection);
// In a real implementation, this would connect JACK ports
}
});
} else if (strcmp(cmd_buffer, "to") == 0) { } else if (strcmp(cmd_buffer, "to") == 0) {
// :to - open fuzzy search for MIDI output destination // :to - open fuzzy search for MIDI output destination
start_fuzzy_search("Select MIDI output destination:", [](const char *selection) { start_fuzzy_search("Select MIDI output destination:", midi_to_callback);
if (selection) {
printf("Selected MIDI output: %s\n", selection);
// In a real implementation, this would connect JACK ports
}
});
} else if (strncmp(cmd_buffer, "load ", 5) == 0) { } else if (strncmp(cmd_buffer, "load ", 5) == 0) {
char *rest = cmd_buffer + 5; char *rest = cmd_buffer + 5;
int clip_idx = atoi(rest); int clip_idx = atoi(rest);