fix: move CarlaHost to Engine struct and fix TUI plugin dialog access
Co-authored-by: aider (deepseek/deepseek-coder) <aider@aider.chat>
This commit is contained in:
4
engine.c
4
engine.c
@@ -191,6 +191,10 @@ int engine_init(Engine *engine, const char *client_name, DispatchFn dispatch) {
|
|||||||
|
|
||||||
engine->sample_rate = jack_get_sample_rate(engine->client);
|
engine->sample_rate = jack_get_sample_rate(engine->client);
|
||||||
|
|
||||||
|
// Initialize Carla host
|
||||||
|
carla_init(&engine->carla_host, engine->client);
|
||||||
|
carla_scan_plugins(&engine->carla_host);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
3
engine.h
3
engine.h
@@ -5,6 +5,7 @@
|
|||||||
#include <jack/midiport.h>
|
#include <jack/midiport.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include "dispatcher.h"
|
#include "dispatcher.h"
|
||||||
|
#include "carla.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
jack_client_t *client;
|
jack_client_t *client;
|
||||||
@@ -18,6 +19,8 @@ typedef struct {
|
|||||||
DispatchFn dispatch;
|
DispatchFn dispatch;
|
||||||
jack_nframes_t sample_rate;
|
jack_nframes_t sample_rate;
|
||||||
bool running;
|
bool running;
|
||||||
|
|
||||||
|
CarlaHost carla_host; // Carla host state for plugin management
|
||||||
} Engine;
|
} Engine;
|
||||||
|
|
||||||
int engine_init(Engine *engine, const char *client_name, DispatchFn dispatch);
|
int engine_init(Engine *engine, const char *client_name, DispatchFn dispatch);
|
||||||
|
|||||||
9
gui.c
9
gui.c
@@ -46,7 +46,7 @@ static int loop_length = 8; /* beats */
|
|||||||
static int current_beat = 0;
|
static int current_beat = 0;
|
||||||
|
|
||||||
/* Carla host and plugin URI input */
|
/* Carla host and plugin URI input */
|
||||||
static CarlaHost carla_host;
|
/* CarlaHost is now stored in Engine struct */
|
||||||
static char plugin_uri_input[256];
|
static char plugin_uri_input[256];
|
||||||
static int plugin_uri_input_len = 0;
|
static int plugin_uri_input_len = 0;
|
||||||
static int selected_channel = 0;
|
static int selected_channel = 0;
|
||||||
@@ -136,7 +136,7 @@ static void gui_update(void)
|
|||||||
mu_layout_row(ctx, 1, (int[]) { -1 }, 0);
|
mu_layout_row(ctx, 1, (int[]) { -1 }, 0);
|
||||||
if (mu_button(ctx, "Add Plugin")) {
|
if (mu_button(ctx, "Add Plugin")) {
|
||||||
if (plugin_uri_input_len > 0) {
|
if (plugin_uri_input_len > 0) {
|
||||||
carla_add_plugin(&carla_host, selected_channel, plugin_uri_input, PLUGIN_TYPE_INTERNAL);
|
carla_add_plugin(&g_engine->carla_host, selected_channel, plugin_uri_input, PLUGIN_TYPE_INTERNAL);
|
||||||
plugin_uri_input_len = 0;
|
plugin_uri_input_len = 0;
|
||||||
plugin_uri_input[0] = '\0';
|
plugin_uri_input[0] = '\0';
|
||||||
}
|
}
|
||||||
@@ -155,8 +155,7 @@ int gui_main(Engine *engine)
|
|||||||
{
|
{
|
||||||
g_engine = engine;
|
g_engine = engine;
|
||||||
|
|
||||||
/* Initialize Carla host */
|
/* Carla host is now initialized in engine_init */
|
||||||
carla_init(&carla_host, engine->client);
|
|
||||||
|
|
||||||
/* initialise microui */
|
/* initialise microui */
|
||||||
ctx = malloc(sizeof(mu_Context));
|
ctx = malloc(sizeof(mu_Context));
|
||||||
@@ -259,7 +258,7 @@ int gui_main(Engine *engine)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* cleanup */
|
/* cleanup */
|
||||||
carla_cleanup(&carla_host);
|
carla_cleanup(&g_engine->carla_host);
|
||||||
endwin();
|
endwin();
|
||||||
free(ctx);
|
free(ctx);
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
5
main.c
5
main.c
@@ -97,10 +97,7 @@ int main(int argc, char *argv[]) {
|
|||||||
initial_state.clips[i].read_position = 0;
|
initial_state.clips[i].read_position = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Initialize Carla host in the initial state (before dispatcher starts)
|
// Carla host is now initialized in engine_init
|
||||||
carla_init(&initial_state.carla_host, NULL);
|
|
||||||
carla_scan_plugins(&initial_state.carla_host);
|
|
||||||
|
|
||||||
// Initialize dispatcher
|
// Initialize dispatcher
|
||||||
dispatch = dispatcher_init(&initial_state);
|
dispatch = dispatcher_init(&initial_state);
|
||||||
|
|
||||||
|
|||||||
8
tui.c
8
tui.c
@@ -323,7 +323,7 @@ static void draw_fuzzy_search(void) {
|
|||||||
attron(A_REVERSE);
|
attron(A_REVERSE);
|
||||||
}
|
}
|
||||||
int count;
|
int count;
|
||||||
const char **plugins = carla_get_available_plugins(NULL, &count);
|
const char **plugins = carla_get_available_plugins(&g_engine->carla_host, &count);
|
||||||
if (plugins && idx >= 0 && idx < count) {
|
if (plugins && idx >= 0 && idx < count) {
|
||||||
mvprintw(start_y + 2 + i, start_x, "%s", plugins[idx]);
|
mvprintw(start_y + 2 + i, start_x, "%s", plugins[idx]);
|
||||||
}
|
}
|
||||||
@@ -360,7 +360,7 @@ static bool handle_fuzzy_search(int ch) {
|
|||||||
// Update results
|
// Update results
|
||||||
fuzzy_search.num_results = 0;
|
fuzzy_search.num_results = 0;
|
||||||
int count;
|
int count;
|
||||||
const char **plugins = carla_get_available_plugins(NULL, &count);
|
const char **plugins = carla_get_available_plugins(&g_engine->carla_host, &count);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (fuzzy_match(fuzzy_search.query, plugins[i])) {
|
if (fuzzy_match(fuzzy_search.query, plugins[i])) {
|
||||||
fuzzy_search.result_indices[fuzzy_search.num_results++] = i;
|
fuzzy_search.result_indices[fuzzy_search.num_results++] = i;
|
||||||
@@ -391,7 +391,7 @@ static bool handle_fuzzy_search(int ch) {
|
|||||||
// Update results
|
// Update results
|
||||||
fuzzy_search.num_results = 0;
|
fuzzy_search.num_results = 0;
|
||||||
int count;
|
int count;
|
||||||
const char **plugins = carla_get_available_plugins(NULL, &count);
|
const char **plugins = carla_get_available_plugins(&g_engine->carla_host, &count);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
if (fuzzy_match(fuzzy_search.query, plugins[i])) {
|
if (fuzzy_match(fuzzy_search.query, plugins[i])) {
|
||||||
fuzzy_search.result_indices[fuzzy_search.num_results++] = i;
|
fuzzy_search.result_indices[fuzzy_search.num_results++] = i;
|
||||||
@@ -417,7 +417,7 @@ static void start_fuzzy_search(const char *prompt, void (*callback)(const char *
|
|||||||
// Initialize results with all plugins
|
// Initialize results with all plugins
|
||||||
fuzzy_search.num_results = 0;
|
fuzzy_search.num_results = 0;
|
||||||
int count = 0;
|
int count = 0;
|
||||||
carla_get_available_plugins(NULL, &count);
|
carla_get_available_plugins(&g_engine->carla_host, &count);
|
||||||
for (int i = 0; i < count; i++) {
|
for (int i = 0; i < count; i++) {
|
||||||
fuzzy_search.result_indices[fuzzy_search.num_results++] = i;
|
fuzzy_search.result_indices[fuzzy_search.num_results++] = i;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user