refactor: replace C++ lambdas with C callback functions
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
83
tui.c
83
tui.c
@@ -221,6 +221,49 @@ static void play_prev_scene(void) {
|
||||
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
|
||||
static bool fuzzy_match(const char *pattern, const char *text) {
|
||||
if (!pattern || !*pattern) return true;
|
||||
@@ -472,31 +515,7 @@ static bool handle_rack_view(int ch) {
|
||||
break;
|
||||
case 'a': {
|
||||
// Start fuzzy search for plugin selection
|
||||
start_fuzzy_search("Add plugin:", [](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);
|
||||
}
|
||||
});
|
||||
start_fuzzy_search("Add plugin:", rack_add_plugin_callback);
|
||||
break;
|
||||
}
|
||||
case 'd': {
|
||||
@@ -704,20 +723,10 @@ static bool handle_command_mode(void) {
|
||||
g_dispatch(action);
|
||||
} else if (strcmp(cmd_buffer, "from") == 0) {
|
||||
// :from - open fuzzy search for MIDI input source
|
||||
start_fuzzy_search("Select MIDI input source:", [](const char *selection) {
|
||||
if (selection) {
|
||||
printf("Selected MIDI input: %s\n", selection);
|
||||
// In a real implementation, this would connect JACK ports
|
||||
}
|
||||
});
|
||||
start_fuzzy_search("Select MIDI input source:", midi_from_callback);
|
||||
} else if (strcmp(cmd_buffer, "to") == 0) {
|
||||
// :to - open fuzzy search for MIDI output destination
|
||||
start_fuzzy_search("Select MIDI output destination:", [](const char *selection) {
|
||||
if (selection) {
|
||||
printf("Selected MIDI output: %s\n", selection);
|
||||
// In a real implementation, this would connect JACK ports
|
||||
}
|
||||
});
|
||||
start_fuzzy_search("Select MIDI output destination:", midi_to_callback);
|
||||
} else if (strncmp(cmd_buffer, "load ", 5) == 0) {
|
||||
char *rest = cmd_buffer + 5;
|
||||
int clip_idx = atoi(rest);
|
||||
|
||||
Reference in New Issue
Block a user