From 486955fa713e7b7beda9e82411fee69dcb65fcb4 Mon Sep 17 00:00:00 2001 From: falkTX Date: Fri, 12 Jul 2024 15:47:48 +0100 Subject: [PATCH 01/79] Fix handling multiple incoming messages at once Signed-off-by: falkTX --- src/socket.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/src/socket.c b/src/socket.c index b21afae..5b90044 100644 --- a/src/socket.c +++ b/src/socket.c @@ -391,10 +391,27 @@ void socket_run(int exit_on_failure) msgbuffer = buffer; } - msg.sender_id = clientfd; - msg.data = msgbuffer; - msg.data_size = count; - if (g_receive_cb) g_receive_cb(&msg); + if (g_receive_cb) + { + msg.data = msgbuffer; + + while (count != 0) + { + if (*msg.data == '\0') + { + --count; + ++msg.data; + continue; + } + + msg.sender_id = clientfd; + msg.data_size = strlen(msg.data) + 1; + g_receive_cb(&msg); + + count -= msg.data_size; + msg.data += msg.data_size; + } + } if (msgbuffer != buffer) free(msgbuffer); From 5ae41b28bb7b4b511122749726d7e7bda447a9eb Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 20 Aug 2024 12:37:26 +0200 Subject: [PATCH 02/79] Disable IO processing compressor by default Signed-off-by: falkTX --- src/monitor/monitor-client.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/monitor/monitor-client.c b/src/monitor/monitor-client.c index cc68a99..847d5d9 100644 --- a/src/monitor/monitor-client.c +++ b/src/monitor/monitor-client.c @@ -40,6 +40,10 @@ ************************************************************************************************************************ */ +#if defined(_MOD_DEVICE_DUOX) || defined(_MOD_DEVICE_DWARF) +#define MOD_IO_PROCESSING_ENABLED +#endif + // used for local stack variables #define MAX_CHAR_BUF_SIZE 255 @@ -86,9 +90,11 @@ typedef struct MONITOR_CLIENT_T { bool apply_compressor; bool apply_volume, apply_smoothing; bool muted; +#ifdef MOD_IO_PROCESSING_ENABLED sf_compressor_state_st compressor; #ifdef _MOD_DEVICE_DUOX sf_compressor_state_st compressor2; +#endif #endif float volume, smooth_volume; } monitor_client_t; @@ -99,6 +105,8 @@ typedef struct MONITOR_CLIENT_T { ************************************************************************************************************************ */ +#define UNUSED_PARAM(var) do { (void)(var); } while (0) + /* ************************************************************************************************************************ * LOCAL GLOBAL VARIABLES @@ -177,9 +185,11 @@ static int ProcessMonitor(jack_nframes_t nframes, void *arg) mon->apply_smoothing = true; } - const bool apply_compressor = mon->apply_compressor; const bool apply_smoothing = mon->apply_smoothing; const bool apply_volume = mon->apply_volume; +#ifdef MOD_IO_PROCESSING_ENABLED + const bool apply_compressor = mon->apply_compressor; +#endif #ifdef _MOD_DEVICE_DUOX if (mon->extra_active) @@ -193,6 +203,7 @@ static int ProcessMonitor(jack_nframes_t nframes, void *arg) if (bufOut2 != bufIn2) memcpy(bufOut2, bufIn2, sizeof(float)*nframes); +#ifdef MOD_IO_PROCESSING_ENABLED // input1 and input2 have connections if (apply_compressor) { @@ -210,6 +221,7 @@ static int ProcessMonitor(jack_nframes_t nframes, void *arg) } } else +#endif { if (apply_volume) { @@ -238,6 +250,7 @@ static int ProcessMonitor(jack_nframes_t nframes, void *arg) if (bufOutR != bufInR) memcpy(bufOutR, bufInR, sizeof(float)*nframes); +#ifdef MOD_IO_PROCESSING_ENABLED if (apply_compressor) { compressor_process_mono(&mon->compressor, nframes, bufOutR); @@ -253,6 +266,7 @@ static int ProcessMonitor(jack_nframes_t nframes, void *arg) } } else +#endif { if (apply_volume) { @@ -434,15 +448,18 @@ int jack_initialize(jack_client_t* client, const char* load_init) mon->extra_active = access("/data/separate-spdif-outs", F_OK) != -1; #endif - mon->apply_compressor = false; mon->apply_volume = false; mon->muted = false; mon->volume = 1.0f; +#ifdef MOD_IO_PROCESSING_ENABLED + mon->apply_compressor = false; + compressor_init(&mon->compressor, jack_get_sample_rate(client)); #ifdef _MOD_DEVICE_DUOX if (mon->extra_active) compressor_init(&mon->compressor2, jack_get_sample_rate(client)); +#endif #endif /* Register jack ports */ @@ -588,6 +605,7 @@ bool monitor_client_init(void) bool monitor_client_setup_compressor(int mode, float release) { +#ifdef MOD_IO_PROCESSING_ENABLED monitor_client_t *const mon = g_monitor_handle; if (!mon) @@ -630,6 +648,13 @@ bool monitor_client_setup_compressor(int mode, float release) mon->apply_compressor = mode != 0; return true; +#else + fprintf(stderr, "asked to setup compressor while IO processing is not enabled\n"); + return false; + + UNUSED_PARAM(mode); + UNUSED_PARAM(release); +#endif } bool monitor_client_setup_volume(float volume) From c12a00ba4d29bedcae4165e0ff18e79f809c1036 Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 20 Aug 2024 12:38:13 +0200 Subject: [PATCH 03/79] Add activate and preload commands Signed-off-by: falkTX --- README.md | 13 ++++++++++++- src/effects.c | 37 +++++++++++++++++++++++++++++++++++-- src/effects.h | 3 ++- src/mod-host.c | 18 +++++++++++++++++- src/mod-host.h | 2 ++ 5 files changed, 68 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 42b7f2a..b1f2fcd 100644 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ Commands (or Protocol) The commands supported by mod-host are: add - * add an LV2 plugin encapsulated as a jack client + * add an LV2 plugin encapsulated as a jack client, in activated state e.g.: add "http://lv2plug.in/plugins/eg-amp" 0 instance_number must be any value between 0 ~ 9990, inclusively @@ -116,6 +116,17 @@ The commands supported by mod-host are: e.g.: remove 0 when instance_number is -1 all plugins will be removed + activate + * toggle effect activated state + e.g.: activate 0 1 + if bypass_value = 1 activate effect + if bypass_value = 0 deactivate effect + + preload + * add an LV2 plugin encapsulated as a jack client, in deactivated state + e.g.: preload "http://lv2plug.in/plugins/eg-amp" 0 + instance_number must be any value between 0 ~ 9990, inclusively + preset_load * load a preset state of an effect instance e.g.: preset_load 0 "http://drobilla.net/plugins/mda/presets#JX10-moogcury-lite" diff --git a/src/effects.c b/src/effects.c index 5281193..c0df983 100644 --- a/src/effects.c +++ b/src/effects.c @@ -428,6 +428,8 @@ typedef struct EFFECT_T { jack_ringbuffer_t *events_out_buffer; char *events_in_buffer_helper; + bool activated; + // previous transport state bool transport_rolling; uint32_t transport_frame; @@ -1713,7 +1715,7 @@ static int ProcessPlugin(jack_nframes_t nframes, void *arg) if (arg == NULL) return 0; effect = arg; - if (!g_processing_enabled || ( + if (!g_processing_enabled || !effect->activated || ( (effect->hints & HINT_STATE_UNSAFE) && pthread_mutex_trylock(&effect->state_restore_mutex) != 0)) { for (i = 0; i < effect->output_audio_ports_count; i++) @@ -4538,7 +4540,7 @@ int effects_finish(int close_client) return SUCCESS; } -int effects_add(const char *uri, int instance) +int effects_add(const char *uri, int instance, int activate) { unsigned int ports_count; char effect_name[32], port_name[MAX_CHAR_BUF_SIZE+1]; @@ -4579,6 +4581,7 @@ int effects_add(const char *uri, int instance) /* Init the struct */ mod_memset(effect, 0, sizeof(effect_t)); effect->instance = instance; + effect->activated = activate; /* Init the pointers */ plugin_uri = NULL; @@ -5967,6 +5970,36 @@ int effects_remove(int effect_id) return SUCCESS; } +int effects_activate(int effect_id, int value) +{ + if (!InstanceExist(effect_id)) + { + return ERR_INSTANCE_NON_EXISTS; + } + + effect_t *effect = &g_effects[effect_id]; + + if (value) + { + if (! effect->activated) + { + lilv_instance_deactivate(effect->lilv_instance); + lilv_instance_activate(effect->lilv_instance); + + effect->activated = true; + } + } + else + { + if (effect->activated) + { + effect->activated = false; + } + } + + return SUCCESS; +} + int effects_connect(const char *portA, const char *portB) { int ret; diff --git a/src/effects.h b/src/effects.h index c0adebe..b0f550a 100644 --- a/src/effects.h +++ b/src/effects.h @@ -135,8 +135,9 @@ typedef struct { int effects_init(void* client); int effects_finish(int close_client); -int effects_add(const char *uri, int instance); +int effects_add(const char *uri, int instance, int activate); int effects_remove(int effect_id); +int effects_activate(int effect_id, int value); int effects_preset_load(int effect_id, const char *uri); int effects_preset_save(int effect_id, const char *dir, const char *file_name, const char *label); int effects_preset_show(const char *uri, char **state_str); diff --git a/src/mod-host.c b/src/mod-host.c index 4b4d5d9..302aada 100644 --- a/src/mod-host.c +++ b/src/mod-host.c @@ -131,7 +131,7 @@ static pthread_t intclient_socket_thread; static void effects_add_cb(proto_t *proto) { int resp; - resp = effects_add(proto->list[1], atoi(proto->list[2])); + resp = effects_add(proto->list[1], atoi(proto->list[2]), 1); protocol_response_int(resp, proto); } @@ -142,6 +142,20 @@ static void effects_remove_cb(proto_t *proto) protocol_response_int(resp, proto); } +static void effects_activate_cb(proto_t *proto) +{ + int resp; + resp = effects_activate(atoi(proto->list[1]), atoi(proto->list[2])); + protocol_response_int(resp, proto); +} + +static void effects_preload_cb(proto_t *proto) +{ + int resp; + resp = effects_add(proto->list[1], atoi(proto->list[2]), 0); + protocol_response_int(resp, proto); +} + static void effects_preset_save_cb(proto_t *proto) { int resp; @@ -674,6 +688,8 @@ static int mod_host_init(jack_client_t* client, int socket_port, int feedback_po /* Setup the protocol */ protocol_add_command(EFFECT_ADD, effects_add_cb); protocol_add_command(EFFECT_REMOVE, effects_remove_cb); + protocol_add_command(EFFECT_ACTIVATE, effects_activate_cb); + protocol_add_command(EFFECT_PRELOAD, effects_preload_cb); protocol_add_command(EFFECT_PRESET_LOAD, effects_preset_load_cb); protocol_add_command(EFFECT_PRESET_SAVE, effects_preset_save_cb); protocol_add_command(EFFECT_PRESET_SHOW, effects_preset_show_cb); diff --git a/src/mod-host.h b/src/mod-host.h index 3ded3d2..5690c05 100644 --- a/src/mod-host.h +++ b/src/mod-host.h @@ -53,6 +53,8 @@ /* Protocol commands definition */ #define EFFECT_ADD "add %s %i" #define EFFECT_REMOVE "remove %i" +#define EFFECT_ACTIVATE "activate %i %i" +#define EFFECT_PRELOAD "preload %s %i" #define EFFECT_PRESET_LOAD "preset_load %i %s" #define EFFECT_PRESET_SAVE "preset_save %i %s %s %s" #define EFFECT_PRESET_SHOW "preset_show %s" From c40de249ed4d68156f49a17fa03647c7cf4d3f1b Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 20 Aug 2024 15:04:32 +0200 Subject: [PATCH 04/79] [de]activate plugins for buffer size changes Signed-off-by: falkTX --- src/effects.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/effects.c b/src/effects.c index c0df983..e2a46cb 100644 --- a/src/effects.c +++ b/src/effects.c @@ -1042,7 +1042,11 @@ static int BufferSize(jack_nframes_t nframes, void* data) options[4].type = 0; options[4].value = NULL; + lilv_instance_deactivate(effect->lilv_instance); + effect->options_interface->set(effect->lilv_instance->lv2_handle, options); + + lilv_instance_activate(effect->lilv_instance); } } #ifdef HAVE_HYLIA From 995da29e0bca51301ffefb0c9233c0b28c2019f1 Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 20 Aug 2024 18:52:53 +0200 Subject: [PATCH 05/79] Alternative approach to [de]activate clients, do it in parallel Signed-off-by: falkTX --- README.md | 10 ++-- src/effects.c | 136 ++++++++++++++++++++++++++++++++++++++++++------- src/effects.h | 2 +- src/mod-host.c | 2 +- src/mod-host.h | 2 +- 5 files changed, 125 insertions(+), 27 deletions(-) diff --git a/README.md b/README.md index b1f2fcd..6d060ad 100644 --- a/README.md +++ b/README.md @@ -116,11 +116,11 @@ The commands supported by mod-host are: e.g.: remove 0 when instance_number is -1 all plugins will be removed - activate - * toggle effect activated state - e.g.: activate 0 1 - if bypass_value = 1 activate effect - if bypass_value = 0 deactivate effect + activate + * toggle effects activated state + e.g.: activate 0 0 1 + if activate_value = 1 activate effect + if activate_value = 0 deactivate effect preload * add an LV2 plugin encapsulated as a jack client, in deactivated state diff --git a/src/effects.c b/src/effects.c index e2a46cb..2e08314 100644 --- a/src/effects.c +++ b/src/effects.c @@ -1042,11 +1042,13 @@ static int BufferSize(jack_nframes_t nframes, void* data) options[4].type = 0; options[4].value = NULL; - lilv_instance_deactivate(effect->lilv_instance); + if (effect->activated) + lilv_instance_deactivate(effect->lilv_instance); effect->options_interface->set(effect->lilv_instance->lv2_handle, options); - lilv_instance_activate(effect->lilv_instance); + if (effect->activated) + lilv_instance_activate(effect->lilv_instance); } } #ifdef HAVE_HYLIA @@ -1719,7 +1721,7 @@ static int ProcessPlugin(jack_nframes_t nframes, void *arg) if (arg == NULL) return 0; effect = arg; - if (!g_processing_enabled || !effect->activated || ( + if (!g_processing_enabled || ( (effect->hints & HINT_STATE_UNSAFE) && pthread_mutex_trylock(&effect->state_restore_mutex) != 0)) { for (i = 0; i < effect->output_audio_ports_count; i++) @@ -5419,14 +5421,18 @@ int effects_add(const char *uri, int instance, int activate) jack_set_buffer_size_callback(jack_client, BufferSize, effect); jack_set_freewheel_callback(jack_client, FreeWheelMode, effect); - lilv_instance_activate(lilv_instance); - /* Try activate the Jack client */ - if (jack_activate(jack_client) != 0) + if (activate) { - fprintf(stderr, "can't activate jack_client\n"); - error = ERR_JACK_CLIENT_ACTIVATION; - goto error; + lilv_instance_activate(lilv_instance); + + /* Try activate the Jack client */ + if (jack_activate(jack_client) != 0) + { + fprintf(stderr, "can't activate jack_client\n"); + error = ERR_JACK_CLIENT_ACTIVATION; + goto error; + } } if (raw_midi_port != NULL) @@ -5974,30 +5980,122 @@ int effects_remove(int effect_id) return SUCCESS; } -int effects_activate(int effect_id, int value) +static void* effects_activate_thread(void* arg) +{ + jack_client_t *jack_client = arg; + + if (jack_activate(jack_client) != 0) + fprintf(stderr, "can't activate jack_client\n"); + + return NULL; +} + +static void* effects_deactivate_thread(void* arg) +{ + jack_client_t *jack_client = arg; + + if (jack_deactivate(jack_client) != 0) + fprintf(stderr, "can't deactivate jack_client\n"); + + return NULL; +} + +int effects_activate(int effect_id, int effect_id_end, int value) { if (!InstanceExist(effect_id)) { return ERR_INSTANCE_NON_EXISTS; } + if (effect_id > effect_id_end) + { + return ERR_INVALID_OPERATION; + } - effect_t *effect = &g_effects[effect_id]; - - if (value) + if (effect_id == effect_id_end) { - if (! effect->activated) + effect_t *effect = &g_effects[effect_id]; + + if (value) + { + if (! effect->activated) + { + effect->activated = true; + lilv_instance_activate(effect->lilv_instance); + + if (jack_activate(effect->jack_client) != 0) + { + fprintf(stderr, "can't activate jack_client\n"); + return ERR_JACK_CLIENT_ACTIVATION; + } + } + } + else { - lilv_instance_deactivate(effect->lilv_instance); - lilv_instance_activate(effect->lilv_instance); + if (effect->activated) + { + effect->activated = false; - effect->activated = true; + if (jack_deactivate(effect->jack_client) != 0) + { + fprintf(stderr, "can't deactivate jack_client\n"); + return ERR_JACK_CLIENT_DEACTIVATION; + } + + lilv_instance_deactivate(effect->lilv_instance); + } } } else { - if (effect->activated) + int num_threads = 0; + pthread_t *threads = malloc(sizeof(pthread_t) * (effect_id_end - effect_id)); + + // create threads to activate all clients + for (int i = effect_id; i <= effect_id_end; ++i) + { + effect_t *effect = &g_effects[i]; + + if (effect->jack_client == NULL) + continue; + + if (value) + { + if (! effect->activated) + { + effect->activated = true; + lilv_instance_activate(effect->lilv_instance); + + pthread_create(&threads[num_threads++], NULL, effects_activate_thread, effect->jack_client); + } + } + else + { + if (effect->activated) + { + pthread_create(&threads[num_threads++], NULL, effects_deactivate_thread, effect->jack_client); + } + } + } + + // wait for all threads to be done + for (int i = 0; i < num_threads; ++i) + pthread_join(threads[i], NULL); + + free(threads); + + // if deactivating, do the last lv2 deactivate step now + if (! value) { - effect->activated = false; + for (int i = effect_id; i <= effect_id_end; ++i) + { + effect_t *effect = &g_effects[i]; + + if (! effect->activated || effect->jack_client == NULL) + continue; + + effect->activated = false; + lilv_instance_deactivate(effect->lilv_instance); + } } } diff --git a/src/effects.h b/src/effects.h index b0f550a..98a1e53 100644 --- a/src/effects.h +++ b/src/effects.h @@ -137,7 +137,7 @@ int effects_init(void* client); int effects_finish(int close_client); int effects_add(const char *uri, int instance, int activate); int effects_remove(int effect_id); -int effects_activate(int effect_id, int value); +int effects_activate(int effect_id, int effect_id_end, int value); int effects_preset_load(int effect_id, const char *uri); int effects_preset_save(int effect_id, const char *dir, const char *file_name, const char *label); int effects_preset_show(const char *uri, char **state_str); diff --git a/src/mod-host.c b/src/mod-host.c index 302aada..0ed9e0f 100644 --- a/src/mod-host.c +++ b/src/mod-host.c @@ -145,7 +145,7 @@ static void effects_remove_cb(proto_t *proto) static void effects_activate_cb(proto_t *proto) { int resp; - resp = effects_activate(atoi(proto->list[1]), atoi(proto->list[2])); + resp = effects_activate(atoi(proto->list[1]), atoi(proto->list[2]), atoi(proto->list[3])); protocol_response_int(resp, proto); } diff --git a/src/mod-host.h b/src/mod-host.h index 5690c05..11d59b5 100644 --- a/src/mod-host.h +++ b/src/mod-host.h @@ -53,7 +53,7 @@ /* Protocol commands definition */ #define EFFECT_ADD "add %s %i" #define EFFECT_REMOVE "remove %i" -#define EFFECT_ACTIVATE "activate %i %i" +#define EFFECT_ACTIVATE "activate %i %i %i" #define EFFECT_PRELOAD "preload %s %i" #define EFFECT_PRESET_LOAD "preset_load %i %s" #define EFFECT_PRESET_SAVE "preset_save %i %s %s %s" From 6c1cdd852608914b7d776373ef23fb4111db658b Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 20 Aug 2024 19:11:20 +0200 Subject: [PATCH 06/79] Fix last commit, unloading deactivated plugins Signed-off-by: falkTX --- src/effects.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/effects.c b/src/effects.c index 2e08314..628a0c4 100644 --- a/src/effects.c +++ b/src/effects.c @@ -5903,8 +5903,12 @@ int effects_remove(int effect_id) } if (effect->lilv_instance) - lilv_instance_deactivate(effect->lilv_instance); - lilv_instance_free(effect->lilv_instance); + { + if (effect->activated) + lilv_instance_deactivate(effect->lilv_instance); + + lilv_instance_free(effect->lilv_instance); + } if (effect->jack_client) jack_client_close(effect->jack_client); From 46f909692586c8fefa63193cbc617999a1a56871 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 21 Sep 2024 00:25:38 +0200 Subject: [PATCH 07/79] make monitor client generic, matching system playback ports Signed-off-by: falkTX --- src/monitor/monitor-client.c | 407 +++++++++++++++-------------------- 1 file changed, 171 insertions(+), 236 deletions(-) diff --git a/src/monitor/monitor-client.c b/src/monitor/monitor-client.c index 847d5d9..fb9b8bc 100644 --- a/src/monitor/monitor-client.c +++ b/src/monitor/monitor-client.c @@ -53,23 +53,6 @@ ************************************************************************************************************************ */ -enum Ports { - PORT_IN1, - PORT_IN2, - PORT_OUT1, - PORT_OUT2, - PORT_COUNT, -#ifdef _MOD_DEVICE_DUOX - PORT_EXTRA_IN3 = PORT_COUNT, - PORT_EXTRA_IN4, - PORT_EXTRA_OUT3, - PORT_EXTRA_OUT4, - PORT_EXTRA_COUNT -#else - PORT_EXTRA_COUNT = PORT_COUNT -#endif -}; - /* ************************************************************************************************************************ * LOCAL DATA TYPES @@ -78,14 +61,13 @@ enum Ports { typedef struct MONITOR_CLIENT_T { jack_client_t *client; - jack_port_t *ports[PORT_EXTRA_COUNT]; + jack_port_t **in_ports; + jack_port_t **out_ports; + uint32_t numports; + uint64_t connected; bool mono_copy; - bool in1_connected; - bool in2_connected; #ifdef _MOD_DEVICE_DUOX bool extra_active; - bool in3_connected; - bool in4_connected; #endif bool apply_compressor; bool apply_volume, apply_smoothing; @@ -145,33 +127,19 @@ static inline float db2lin(const float db) return powf(10.0f, 0.05f * db); } -#ifdef _MOD_DEVICE_DUOX -static void ProcessMonitorExtra(monitor_client_t *const mon, jack_nframes_t nframes); -#endif - -static int ProcessMonitor(jack_nframes_t nframes, void *arg) +#if defined(_MOD_DEVICE_DUO) || defined(_MOD_DEVICE_DUOX) || defined(_MOD_DEVICE_DWARF) +static void ProcessMonitorLoopStereo(monitor_client_t *const mon, jack_nframes_t nframes, uint32_t offset) { - monitor_client_t *const mon = arg; - const float *const bufIn1 = jack_port_get_buffer(mon->ports[PORT_IN1], nframes); - const float *const bufIn2 = jack_port_get_buffer(mon->ports[PORT_IN2], nframes); - /* */ float *const bufOut1 = jack_port_get_buffer(mon->ports[PORT_OUT1], nframes); - /* */ float *const bufOut2 = jack_port_get_buffer(mon->ports[PORT_OUT2], nframes); + const float *const bufIn1 = jack_port_get_buffer(mon->in_ports[offset], nframes); + const float *const bufIn2 = jack_port_get_buffer(mon->in_ports[offset + 1], nframes); + /* */ float *const bufOut1 = jack_port_get_buffer(mon->out_ports[offset], nframes); + /* */ float *const bufOut2 = jack_port_get_buffer(mon->out_ports[offset + 1], nframes); - if (mon->muted) - { - memset(bufOut1, 0, sizeof(float)*nframes); - memset(bufOut2, 0, sizeof(float)*nframes); -#ifdef _MOD_DEVICE_DUOX - if (mon->extra_active) - { - float *const bufOut3 = jack_port_get_buffer(mon->ports[PORT_EXTRA_OUT3], nframes); - float *const bufOut4 = jack_port_get_buffer(mon->ports[PORT_EXTRA_OUT4], nframes); - memset(bufOut3, 0, sizeof(float)*nframes); - memset(bufOut4, 0, sizeof(float)*nframes); - } -#endif - return 0; - } + #ifdef MOD_IO_PROCESSING_ENABLED + const bool apply_compressor = mon->apply_compressor; + #endif + const bool apply_smoothing = mon->apply_smoothing; + const bool apply_volume = mon->apply_volume; const float new_volume_weight = 0.001f; const float old_volume_weight = 1.f - new_volume_weight; @@ -180,34 +148,27 @@ static int ProcessMonitor(jack_nframes_t nframes, void *arg) float smooth_volume = mon->smooth_volume; - if (floats_differ_enough(volume, smooth_volume)) { - mon->apply_volume = true; - mon->apply_smoothing = true; - } + const bool in1_connected = mon->connected & (1 << offset); + const bool in2_connected = mon->connected & (1 << (offset + 1)); - const bool apply_smoothing = mon->apply_smoothing; - const bool apply_volume = mon->apply_volume; -#ifdef MOD_IO_PROCESSING_ENABLED - const bool apply_compressor = mon->apply_compressor; -#endif - -#ifdef _MOD_DEVICE_DUOX - if (mon->extra_active) - ProcessMonitorExtra(mon, nframes); -#endif + #ifdef _MOD_DEVICE_DUOX + const sf_compressor_state_st* const compressor = offset == 2 ? &mon->compressor2 : &mon->compressor; + #else + const sf_compressor_state_st* const compressor = &mon->compressor; + #endif - if (mon->in1_connected && mon->in2_connected) + if (in1_connected && in2_connected) { if (bufOut1 != bufIn1) memcpy(bufOut1, bufIn1, sizeof(float)*nframes); if (bufOut2 != bufIn2) memcpy(bufOut2, bufIn2, sizeof(float)*nframes); -#ifdef MOD_IO_PROCESSING_ENABLED + #ifdef MOD_IO_PROCESSING_ENABLED // input1 and input2 have connections if (apply_compressor) { - compressor_process(&mon->compressor, nframes, bufOut1, bufOut2); + compressor_process(compressor, nframes, bufOut1, bufOut2); if (apply_volume) { @@ -221,7 +182,7 @@ static int ProcessMonitor(jack_nframes_t nframes, void *arg) } } else -#endif + #endif { if (apply_volume) { @@ -234,26 +195,21 @@ static int ProcessMonitor(jack_nframes_t nframes, void *arg) } } } - - mon->apply_volume = floats_differ_enough(smooth_volume, 1.0f); - mon->smooth_volume = smooth_volume; - return 0; } - - if (mon->in1_connected || mon->in2_connected) + else if (in1_connected || in2_connected) { // only one input has connections - const float *const bufInR = mon->in1_connected ? bufIn1 : bufIn2; - /* */ float *const bufOutR = mon->in1_connected ? bufOut1 : bufOut2; - /* */ float *const bufOutC = mon->in1_connected ? bufOut2 : bufOut1; + const float *const bufInR = in1_connected ? bufIn1 : bufIn2; + /* */ float *const bufOutR = in1_connected ? bufOut1 : bufOut2; + /* */ float *const bufOutC = in1_connected ? bufOut2 : bufOut1; if (bufOutR != bufInR) memcpy(bufOutR, bufInR, sizeof(float)*nframes); -#ifdef MOD_IO_PROCESSING_ENABLED + #ifdef MOD_IO_PROCESSING_ENABLED if (apply_compressor) { - compressor_process_mono(&mon->compressor, nframes, bufOutR); + compressor_process_mono(compressor, nframes, bufOutR); if (apply_volume) { @@ -266,7 +222,7 @@ static int ProcessMonitor(jack_nframes_t nframes, void *arg) } } else -#endif + #endif { if (apply_volume) { @@ -279,140 +235,109 @@ static int ProcessMonitor(jack_nframes_t nframes, void *arg) } } - if (mon->mono_copy) + if (offset == 0 && mon->mono_copy) memcpy(bufOutC, bufInR, sizeof(float)*nframes); else memset(bufOutC, 0, sizeof(float)*nframes); - - mon->apply_volume = floats_differ_enough(smooth_volume, 1.0f); - mon->smooth_volume = smooth_volume; - return 0; + } + else + { + // nothing connected in input1 or input2 + memset(bufOut1, 0, sizeof(float)*nframes); + memset(bufOut2, 0, sizeof(float)*nframes); } - // nothing connected in input1 or input2 - memset(bufOut1, 0, sizeof(float)*nframes); - memset(bufOut2, 0, sizeof(float)*nframes); - return 0; + return smooth_volume; } +#endif -#ifdef _MOD_DEVICE_DUOX -static void ProcessMonitorExtra(monitor_client_t *const mon, jack_nframes_t nframes) +static int ProcessMonitor(jack_nframes_t nframes, void *arg) { - const float *const bufIn3 = jack_port_get_buffer(mon->ports[PORT_EXTRA_IN3], nframes); - const float *const bufIn4 = jack_port_get_buffer(mon->ports[PORT_EXTRA_IN4], nframes); - /* */ float *const bufOut3 = jack_port_get_buffer(mon->ports[PORT_EXTRA_OUT3], nframes); - /* */ float *const bufOut4 = jack_port_get_buffer(mon->ports[PORT_EXTRA_OUT4], nframes); + monitor_client_t *const mon = arg; - const float new_volume_weight = 0.001f; - const float old_volume_weight = 1.f - new_volume_weight; + if (mon->muted) + { + for (uint32_t i=0; inumports; ++i) + memset(jack_port_get_buffer(mon->out_ports[i], nframes), 0, sizeof(float)*nframes); + + return 0; + } const float volume = mon->volume; + float smooth_volume = mon->smooth_volume; + + if (floats_differ_enough(volume, smooth_volume)) + { + mon->apply_volume = true; + mon->apply_smoothing = true; + } + + #if defined(_MOD_DEVICE_DUO) || defined(_MOD_DEVICE_DUOX) || defined(_MOD_DEVICE_DWARF) + smooth_volume = ProcessMonitorLoopStereo(mon, nframes, 0); + + #ifdef _MOD_DEVICE_DUOX + if (mon->extra_active) + ProcessMonitorLoopStereo(mon, nframes, 2); + #endif + #else + const float* bufIn[mon->numports]; + /* */ float* bufOut[mon->numports]; + + const float new_volume_weight = 0.001f; + const float old_volume_weight = 1.f - new_volume_weight; - const bool apply_compressor = mon->apply_compressor; const bool apply_smoothing = mon->apply_smoothing; const bool apply_volume = mon->apply_volume; + const uint64_t connected = mon->connected; - float smooth_volume = mon->smooth_volume; - - if (mon->in3_connected && mon->in4_connected) + for (uint32_t i=0; inumports; ++i) { - if (bufOut3 != bufIn3) - memcpy(bufOut3, bufIn3, sizeof(float)*nframes); - if (bufOut4 != bufIn4) - memcpy(bufOut4, bufIn4, sizeof(float)*nframes); + bufIn[i] = jack_port_get_buffer(mon->in_ports[i], nframes); + bufOut[i] = jack_port_get_buffer(mon->out_ports[i], nframes); - // input3 and input4 have connections - if (apply_compressor) + if (connected & (1 << i)) { - compressor_process(&mon->compressor2, nframes, bufOut3, bufOut4); - - if (apply_volume) - { - for (jack_nframes_t i=0; iin3_connected || mon->in4_connected) + if (apply_volume) { - // only one input has connections - const float *const bufInR = mon->in3_connected ? bufIn3 : bufIn4; - /* */ float *const bufOutR = mon->in3_connected ? bufOut3 : bufOut4; - /* */ float *const bufOutC = mon->in3_connected ? bufOut4 : bufOut3; - - if (bufOutR != bufInR) - memcpy(bufOutR, bufInR, sizeof(float)*nframes); - - if (apply_compressor) + for (jack_nframes_t i=0; icompressor2, nframes, bufOutR); + if (apply_smoothing) + smooth_volume = new_volume_weight * volume + old_volume_weight * smooth_volume; - if (apply_volume) - { - for (jack_nframes_t i=0; inumports; ++j) + bufOut[j][i] *= smooth_volume; } - memset(bufOutC, 0, sizeof(float)*nframes); - return; } + #endif - // nothing connected in input3 or input4 - memset(bufOut3, 0, sizeof(float)*nframes); - memset(bufOut4, 0, sizeof(float)*nframes); + mon->apply_volume = floats_differ_enough(smooth_volume, 1.0f); + mon->smooth_volume = smooth_volume; + return 0; } -#endif static int GraphOrder(void* arg) { monitor_client_t *const mon = arg; - mon->in1_connected = jack_port_connected(mon->ports[PORT_IN1]) > 0; - mon->in2_connected = jack_port_connected(mon->ports[PORT_IN2]) > 0; - -#ifdef _MOD_DEVICE_DUOX - if (mon->extra_active) + for (uint32_t i=0; inumports; ++i) { - mon->in3_connected = jack_port_connected(mon->ports[PORT_EXTRA_IN3]) > 0; - mon->in4_connected = jack_port_connected(mon->ports[PORT_EXTRA_IN4]) > 0; + const uint64_t flag = 1 << i; + + if (jack_port_connected(mon->in_ports[i]) > 0) + mon->connected |= flag; + else + mon->connected &= ~flag; } -#endif + return 0; } @@ -441,8 +366,7 @@ int jack_initialize(jack_client_t* client, const char* load_init) } mon->client = client; - mon->in1_connected = false; - mon->in2_connected = false; + mon->connected = 0; mon->mono_copy = (load_init && !strcmp(load_init, "1")) || access("/data/jack-mono-copy", F_OK) != -1; #ifdef _MOD_DEVICE_DUOX mon->extra_active = access("/data/separate-spdif-outs", F_OK) != -1; @@ -463,47 +387,59 @@ int jack_initialize(jack_client_t* client, const char* load_init) #endif /* Register jack ports */ - mon->ports[PORT_IN1 ] = jack_port_register(client, "in_1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); - mon->ports[PORT_IN2 ] = jack_port_register(client, "in_2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); - mon->ports[PORT_OUT1] = jack_port_register(client, "out_1", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); - mon->ports[PORT_OUT2] = jack_port_register(client, "out_2", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); +#if defined(_MOD_DEVICE_DUO) || defined(_MOD_DEVICE_DWARF) + const uint32_t numports = 2; +#elif defined(_MOD_DEVICE_DUOX) + const uint32_t numports = mon->extra_active ? 4 : 2; +#else + uint32_t numports = 0; - jack_port_tie(mon->ports[PORT_IN1], mon->ports[PORT_OUT1]); - jack_port_tie(mon->ports[PORT_IN2], mon->ports[PORT_OUT2]); + const char** const sysports = jack_get_ports(client, "system:playback_", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput); + if (sysports != NULL) + { + while (sysports[numports]) + ++numports; + jack_free(sysports); + } - for (int i=0; iports[i]) - { - fprintf(stderr, "can't register jack ports\n"); - free(mon); - return 1; - } + fprintf(stderr, "no jack playback ports\n"); + free(mon); + return 1; } +#endif -#ifdef _MOD_DEVICE_DUOX - if (mon->extra_active) + mon->numports = numports; + mon->in_ports = malloc(sizeof(jack_port_t*) * numports); + mon->out_ports = malloc(sizeof(jack_port_t*) * numports); + + if (!mon->in_ports || !mon->out_ports) + { + fprintf(stderr, "out of memory\n"); + return 1; + } + + char portname[MAX_CHAR_BUF_SIZE+1]; + portname[MAX_CHAR_BUF_SIZE] = '\0'; + + for (uint32_t i=0; iports[PORT_EXTRA_IN3 ] = jack_port_register(client, "in_3", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); - mon->ports[PORT_EXTRA_IN4 ] = jack_port_register(client, "in_4", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); - mon->ports[PORT_EXTRA_OUT3] = jack_port_register(client, "out_3", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); - mon->ports[PORT_EXTRA_OUT4] = jack_port_register(client, "out_4", JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); + snprintf(portname, MAX_CHAR_BUF_SIZE, "in_%d", i + 1); + mon->in_ports[i] = jack_port_register(client, portname, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0); - jack_port_tie(mon->ports[PORT_EXTRA_IN3], mon->ports[PORT_EXTRA_OUT3]); - jack_port_tie(mon->ports[PORT_EXTRA_IN4], mon->ports[PORT_EXTRA_OUT4]); + snprintf(portname, MAX_CHAR_BUF_SIZE, "out_%d", i + 1); + mon->out_ports[i] = jack_port_register(client, portname, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0); - for (int i=PORT_COUNT; iin_ports[i] || !mon->out_ports[i]) { - if (! mon->ports[i]) - { - fprintf(stderr, "can't register jack ports\n"); - free(mon); - return 1; - } + fprintf(stderr, "can't register jack ports\n"); + free(mon); + return 1; } + + jack_port_tie(mon->in_ports[i], mon->out_ports[i]); } -#endif /* Set jack callbacks */ jack_set_graph_order_callback(client, GraphOrder, mon); @@ -526,39 +462,33 @@ int jack_initialize(jack_client_t* client, const char* load_init) const char* const ourclientname = jack_get_client_name(client); - if (jack_port_by_name(client, "system:playback_1") != NULL) - { - #ifndef _MOD_DEVICE_DWARF - snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_1", ourclientname); - #else - snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_2", ourclientname); - #endif - jack_connect(client, ourportname, "system:playback_1"); - } - - if (jack_port_by_name(client, "system:playback_2") != NULL) - { - #ifndef _MOD_DEVICE_DWARF - snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_2", ourclientname); - #else - snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_1", ourclientname); - #endif - jack_connect(client, ourportname, "system:playback_2"); - } + #if defined(_MOD_DEVICE_DUO) || defined(_MOD_DEVICE_DUOX) + snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_1", ourclientname); + jack_connect(client, ourportname, "system:playback_1"); + snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_2", ourclientname); + jack_connect(client, ourportname, "system:playback_2"); #ifdef _MOD_DEVICE_DUOX - if (jack_port_by_name(client, "system:playback_3") != NULL) - { - snprintf(ourportname, MAX_CHAR_BUF_SIZE, mon->extra_active ? "%s:out_3" : "%s:out_1", ourclientname); - jack_connect(client, ourportname, "system:playback_3"); - } + snprintf(ourportname, MAX_CHAR_BUF_SIZE, mon->extra_active ? "%s:out_3" : "%s:out_1", ourclientname); + jack_connect(client, ourportname, "system:playback_3"); - if (jack_port_by_name(client, "system:playback_4") != NULL) + snprintf(ourportname, MAX_CHAR_BUF_SIZE, mon->extra_active ? "%s:out_4" : "%s:out_2", ourclientname); + jack_connect(client, ourportname, "system:playback_4"); + #endif + #elif defined(_MOD_DEVICE_DWARF) + snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_2", ourclientname); + jack_connect(client, ourportname, "system:playback_1"); + + snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_1", ourclientname); + jack_connect(client, ourportname, "system:playback_2"); + #else + for (uint32_t i=0; iextra_active ? "%s:out_4" : "%s:out_2", ourclientname); - jack_connect(client, ourportname, "system:playback_4"); + snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_%d", ourclientname, i + 1); + snprintf(portname, MAX_CHAR_BUF_SIZE, "system:playback_%d", i + 1); + jack_connect(client, ourportname, portname); } - #endif + #endif return 0; } @@ -578,9 +508,14 @@ void jack_finish(void* arg) g_monitor_handle = NULL; g_active = false; - for (int i=0; iclient, mon->ports[i]); + for (uint32_t i=0; inumports; ++i) + { + jack_port_unregister(mon->client, mon->in_ports[i]); + jack_port_unregister(mon->client, mon->out_ports[i]); + } + free(mon->in_ports); + free(mon->out_ports); free(mon); } @@ -670,7 +605,7 @@ bool monitor_client_setup_volume(float volume) // local variables for calculations before changing the real struct values const float final_volume = db2lin(volume); const bool apply_volume = floats_differ_enough(final_volume, 1.0f); - const bool muted = !floats_differ_enough(volume, -30.0f); + const bool muted = volume <= -30.f || !floats_differ_enough(volume, -30.0f); mon->volume = final_volume; mon->apply_volume = apply_volume; From 3218168681043089b3cd40a685237bb013ccd7c8 Mon Sep 17 00:00:00 2001 From: falkTX Date: Sat, 21 Sep 2024 12:56:02 +0200 Subject: [PATCH 08/79] Cleanup monitor client Signed-off-by: falkTX --- src/monitor/monitor-client.c | 132 ++++++++++++++++++++--------------- 1 file changed, 75 insertions(+), 57 deletions(-) diff --git a/src/monitor/monitor-client.c b/src/monitor/monitor-client.c index fb9b8bc..261fe5c 100644 --- a/src/monitor/monitor-client.c +++ b/src/monitor/monitor-client.c @@ -40,6 +40,10 @@ ************************************************************************************************************************ */ +#if defined(_MOD_DEVICE_DUO) || defined(_MOD_DEVICE_DUOX) || defined(_MOD_DEVICE_DWARF) +#define MOD_MONITOR_STEREO_HANDLING +#endif + #if defined(_MOD_DEVICE_DUOX) || defined(_MOD_DEVICE_DWARF) #define MOD_IO_PROCESSING_ENABLED #endif @@ -63,22 +67,22 @@ typedef struct MONITOR_CLIENT_T { jack_client_t *client; jack_port_t **in_ports; jack_port_t **out_ports; - uint32_t numports; uint64_t connected; - bool mono_copy; -#ifdef _MOD_DEVICE_DUOX + uint32_t numports; + float volume, smooth_volume; + #ifdef MOD_IO_PROCESSING_ENABLED + sf_compressor_state_st compressor; + #endif + #ifdef _MOD_DEVICE_DUOX + sf_compressor_state_st compressor2; bool extra_active; -#endif + #endif + #ifdef MOD_MONITOR_STEREO_HANDLING + bool mono_copy; + #endif bool apply_compressor; bool apply_volume, apply_smoothing; bool muted; -#ifdef MOD_IO_PROCESSING_ENABLED - sf_compressor_state_st compressor; -#ifdef _MOD_DEVICE_DUOX - sf_compressor_state_st compressor2; -#endif -#endif - float volume, smooth_volume; } monitor_client_t; /* @@ -127,7 +131,7 @@ static inline float db2lin(const float db) return powf(10.0f, 0.05f * db); } -#if defined(_MOD_DEVICE_DUO) || defined(_MOD_DEVICE_DUOX) || defined(_MOD_DEVICE_DWARF) +#ifdef MOD_MONITOR_STEREO_HANDLING static void ProcessMonitorLoopStereo(monitor_client_t *const mon, jack_nframes_t nframes, uint32_t offset) { const float *const bufIn1 = jack_port_get_buffer(mon->in_ports[offset], nframes); @@ -272,7 +276,7 @@ static int ProcessMonitor(jack_nframes_t nframes, void *arg) mon->apply_smoothing = true; } - #if defined(_MOD_DEVICE_DUO) || defined(_MOD_DEVICE_DUOX) || defined(_MOD_DEVICE_DWARF) + #ifdef MOD_MONITOR_STEREO_HANDLING smooth_volume = ProcessMonitorLoopStereo(mon, nframes, 0); #ifdef _MOD_DEVICE_DUOX @@ -367,31 +371,35 @@ int jack_initialize(jack_client_t* client, const char* load_init) mon->client = client; mon->connected = 0; - mon->mono_copy = (load_init && !strcmp(load_init, "1")) || access("/data/jack-mono-copy", F_OK) != -1; -#ifdef _MOD_DEVICE_DUOX - mon->extra_active = access("/data/separate-spdif-outs", F_OK) != -1; -#endif - - mon->apply_volume = false; - mon->muted = false; - mon->volume = 1.0f; -#ifdef MOD_IO_PROCESSING_ENABLED + #ifdef MOD_IO_PROCESSING_ENABLED mon->apply_compressor = false; - compressor_init(&mon->compressor, jack_get_sample_rate(client)); -#ifdef _MOD_DEVICE_DUOX + #endif + + #ifdef _MOD_DEVICE_DUOX + mon->extra_active = access("/data/separate-spdif-outs", F_OK) != -1; + if (mon->extra_active) compressor_init(&mon->compressor2, jack_get_sample_rate(client)); -#endif -#endif + #endif + + #ifdef MOD_MONITOR_STEREO_HANDLING + mon->mono_copy = (load_init && !strcmp(load_init, "1")) || access("/data/jack-mono-copy", F_OK) != -1; + #endif + + mon->apply_volume = false; + mon->muted = false; + mon->volume = 1.0f; /* Register jack ports */ -#if defined(_MOD_DEVICE_DUO) || defined(_MOD_DEVICE_DWARF) + #if defined(_MOD_DEVICE_DUO) || defined(_MOD_DEVICE_DWARF) const uint32_t numports = 2; -#elif defined(_MOD_DEVICE_DUOX) + #elif defined(_MOD_DEVICE_DUOX) const uint32_t numports = mon->extra_active ? 4 : 2; -#else + #elif defined(_DARKGLASS_DEVICE_PABLITO) + const uint32_t numports = 2; + #else uint32_t numports = 0; const char** const sysports = jack_get_ports(client, "system:playback_", JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput); @@ -408,7 +416,7 @@ int jack_initialize(jack_client_t* client, const char* load_init) free(mon); return 1; } -#endif + #endif mon->numports = numports; mon->in_ports = malloc(sizeof(jack_port_t*) * numports); @@ -462,35 +470,45 @@ int jack_initialize(jack_client_t* client, const char* load_init) const char* const ourclientname = jack_get_client_name(client); - #if defined(_MOD_DEVICE_DUO) || defined(_MOD_DEVICE_DUOX) - snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_1", ourclientname); - jack_connect(client, ourportname, "system:playback_1"); - - snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_2", ourclientname); - jack_connect(client, ourportname, "system:playback_2"); - #ifdef _MOD_DEVICE_DUOX - snprintf(ourportname, MAX_CHAR_BUF_SIZE, mon->extra_active ? "%s:out_3" : "%s:out_1", ourclientname); - jack_connect(client, ourportname, "system:playback_3"); - - snprintf(ourportname, MAX_CHAR_BUF_SIZE, mon->extra_active ? "%s:out_4" : "%s:out_2", ourclientname); - jack_connect(client, ourportname, "system:playback_4"); - #endif - #elif defined(_MOD_DEVICE_DWARF) + #ifdef _MOD_DEVICE_DWARF snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_2", ourclientname); jack_connect(client, ourportname, "system:playback_1"); snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_1", ourclientname); jack_connect(client, ourportname, "system:playback_2"); - #else + #else for (uint32_t i=0; iextra_active) + { + snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_1", ourclientname); + jack_connect(client, ourportname, "system:playback_3"); + + snprintf(ourportname, MAX_CHAR_BUF_SIZE, "%s:out_2", ourclientname); + jack_connect(client, ourportname, "system:playback_4"); + } + #endif return 0; + + #ifndef MOD_MONITOR_STEREO_HANDLING + UNUSED_PARAM(load_init); + #endif } #ifdef STANDALONE_MONITOR_CLIENT @@ -540,7 +558,7 @@ bool monitor_client_init(void) bool monitor_client_setup_compressor(int mode, float release) { -#ifdef MOD_IO_PROCESSING_ENABLED + #ifdef MOD_IO_PROCESSING_ENABLED monitor_client_t *const mon = g_monitor_handle; if (!mon) @@ -553,43 +571,43 @@ bool monitor_client_setup_compressor(int mode, float release) { case 1: compressor_set_params(&mon->compressor, -12.f, 12.f, 2.f, 0.0001f, release / 1000, -3.f); -#ifdef _MOD_DEVICE_DUOX + #ifdef _MOD_DEVICE_DUOX if (mon->extra_active) compressor_set_params(&mon->compressor2, -12.f, 12.f, 2.f, 0.0001f, release / 1000, -3.f); -#endif + #endif break; case 2: compressor_set_params(&mon->compressor, -12.f, 12.f, 3.f, 0.0001f, release / 1000, -3.f); -#ifdef _MOD_DEVICE_DUOX + #ifdef _MOD_DEVICE_DUOX if (mon->extra_active) compressor_set_params(&mon->compressor2, -12.f, 12.f, 3.f, 0.0001f, release / 1000, -3.f); -#endif + #endif break; case 3: compressor_set_params(&mon->compressor, -15.f, 15.f, 4.f, 0.0001f, release / 1000, -3.f); -#ifdef _MOD_DEVICE_DUOX + #ifdef _MOD_DEVICE_DUOX if (mon->extra_active) compressor_set_params(&mon->compressor2, -15.f, 15.f, 4.f, 0.0001f, release / 1000, -3.f); -#endif + #endif break; case 4: compressor_set_params(&mon->compressor, -25.f, 15.f, 10.f, 0.0001f, release / 1000, -6.f); -#ifdef _MOD_DEVICE_DUOX + #ifdef _MOD_DEVICE_DUOX if (mon->extra_active) compressor_set_params(&mon->compressor2, -25.f, 15.f, 10.f, 0.0001f, release / 1000, -6.f); -#endif + #endif break; } mon->apply_compressor = mode != 0; return true; -#else + #else fprintf(stderr, "asked to setup compressor while IO processing is not enabled\n"); return false; UNUSED_PARAM(mode); UNUSED_PARAM(release); -#endif + #endif } bool monitor_client_setup_volume(float volume) From c1edf9f88b5fffe761cb793b293f4731002946ad Mon Sep 17 00:00:00 2001 From: falkTX Date: Mon, 23 Sep 2024 14:35:31 +0200 Subject: [PATCH 09/79] Fix socket read with extra leftover null bytes Signed-off-by: falkTX --- src/socket.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/socket.c b/src/socket.c index 5b90044..752f1ce 100644 --- a/src/socket.c +++ b/src/socket.c @@ -371,6 +371,17 @@ void socket_run(int exit_on_failure) if (new_count > 0) /* Data received */ { count += new_count; + + if (msgbuffer[count - 1] == '\0') + { + // ignore leftover null bytes + while (count > 1 && msgbuffer[count - 1] == '\0') + --count; + + // make sure to keep 1 null byte at the end of the string + ++count; + break; + } } else if (new_count < 0) /* Error */ { @@ -395,7 +406,7 @@ void socket_run(int exit_on_failure) { msg.data = msgbuffer; - while (count != 0) + while (count > 0) { if (*msg.data == '\0') { From 87702268572f889d4058fe3b64ffd6040f29160e Mon Sep 17 00:00:00 2001 From: falkTX Date: Tue, 24 Sep 2024 18:41:23 +0200 Subject: [PATCH 10/79] Fix documentation for cc_map Signed-off-by: falkTX --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6d060ad..ec9b3e1 100644 --- a/README.md +++ b/README.md @@ -212,9 +212,9 @@ The commands supported by mod-host are: * set the MIDI channel which changes pedalboard snapshots on MIDI program change. is in the range of [0,15]. e.g.: set_midi_program_change_pedalboard_snapshot_channel 1 4 to enable listening for preset changes on channel 5 - cc_map