diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/control.c | 6 | ||||
-rw-r--r-- | src/jack.c | 76 | ||||
-rw-r--r-- | src/jalv.c | 153 | ||||
-rw-r--r-- | src/jalv_gtk.c | 18 | ||||
-rw-r--r-- | src/jalv_internal.h | 16 | ||||
-rw-r--r-- | src/jalv_qt.cpp | 2 | ||||
-rw-r--r-- | src/lv2_evbuf.h | 43 | ||||
-rw-r--r-- | src/portaudio.c | 12 | ||||
-rw-r--r-- | src/symap.c | 19 | ||||
-rw-r--r-- | src/symap.h | 16 |
10 files changed, 171 insertions, 190 deletions
diff --git a/src/control.c b/src/control.c index ca3a73f..5c60c16 100644 --- a/src/control.c +++ b/src/control.c @@ -72,7 +72,7 @@ new_port_control(Jalv* jalv, uint32_t index) lilv_port_get_range(plug, lport, &id->def, &id->min, &id->max); if (lilv_port_has_property(plug, lport, jalv->nodes.lv2_sampleRate)) { - /* Adjust range for lv2:sampleRate controls */ + // Adjust range for lv2:sampleRate controls if (lilv_node_is_float(id->min) || lilv_node_is_int(id->min)) { const float min = lilv_node_as_float(id->min) * jalv->sample_rate; lilv_node_free(id->min); @@ -85,7 +85,7 @@ new_port_control(Jalv* jalv, uint32_t index) } } - /* Get scale points */ + // Get scale points LilvScalePoints* sp = lilv_port_get_scale_points(plug, lport); if (sp) { id->points = @@ -102,7 +102,7 @@ new_port_control(Jalv* jalv, uint32_t index) strdup(lilv_node_as_string(lilv_scale_point_get_label(p))); ++np; } - /* TODO: Non-float scale points? */ + // TODO: Non-float scale points? } qsort(id->points, @@ -1,5 +1,5 @@ /* - Copyright 2007-2016 David Robillard <d@drobilla.net> + Copyright 2007-2022 David Robillard <d@drobilla.net> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -46,15 +46,15 @@ struct JalvBackend { bool is_internal_client; ///< Running inside jackd }; -/** Internal Jack client initialization entry point */ +/// Internal Jack client initialization entry point int jack_initialize(jack_client_t* client, const char* load_init); -/** Internal Jack client finalization entry point */ +/// Internal Jack client finalization entry point void jack_finish(void* arg); -/** Jack buffer size callback. */ +/// Jack buffer size callback static int jack_buffer_size_cb(jack_nframes_t nframes, void* data) { @@ -69,7 +69,7 @@ jack_buffer_size_cb(jack_nframes_t nframes, void* data) return 0; } -/** Jack shutdown callback. */ +/// Jack shutdown callback static void jack_shutdown_cb(void* data) { @@ -78,19 +78,19 @@ jack_shutdown_cb(void* data) zix_sem_post(&jalv->done); } -/** Jack process callback. */ +/// Jack process callback static REALTIME int jack_process_cb(jack_nframes_t nframes, void* data) { Jalv* const jalv = (Jalv*)data; jack_client_t* client = jalv->backend->client; - /* Get Jack transport position */ + // Get Jack transport position jack_position_t pos; const bool rolling = (jack_transport_query(client, &pos) == JackTransportRolling); - /* If transport state is not as expected, then something has changed */ + // If transport state is not as expected, then something has changed const bool xport_changed = (rolling != jalv->rolling || pos.frame != jalv->position || pos.beats_per_minute != jalv->bpm); @@ -98,7 +98,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) uint8_t pos_buf[256]; LV2_Atom* lv2_pos = (LV2_Atom*)pos_buf; if (xport_changed) { - /* Build an LV2 position object to report change to plugin */ + // Build an LV2 position object to report change to plugin lv2_atom_forge_set_buffer(&jalv->forge, pos_buf, sizeof(pos_buf)); LV2_Atom_Forge* forge = &jalv->forge; LV2_Atom_Forge_Frame frame; @@ -137,7 +137,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) } } - /* Update transport state to expected values for next cycle */ + // Update transport state to expected values for next cycle jalv->position = rolling ? pos.frame + nframes : pos.frame; jalv->bpm = pos.beats_per_minute; jalv->rolling = rolling; @@ -164,23 +164,23 @@ jack_process_cb(jack_nframes_t nframes, void* data) break; } - /* Prepare port buffers */ + // Prepare port buffers for (uint32_t p = 0; p < jalv->num_ports; ++p) { struct Port* port = &jalv->ports[p]; if (port->type == TYPE_AUDIO && port->sys_port) { - /* Connect plugin port directly to Jack port buffer */ + // Connect plugin port directly to Jack port buffer lilv_instance_connect_port( jalv->instance, p, jack_port_get_buffer(port->sys_port, nframes)); #ifdef HAVE_JACK_METADATA } else if (port->type == TYPE_CV && port->sys_port) { - /* Connect plugin port directly to Jack port buffer */ + // Connect plugin port directly to Jack port buffer lilv_instance_connect_port( jalv->instance, p, jack_port_get_buffer(port->sys_port, nframes)); #endif } else if (port->type == TYPE_EVENT && port->flow == FLOW_INPUT) { lv2_evbuf_reset(port->evbuf, true); - /* Write transport change event if applicable */ + // Write transport change event if applicable LV2_Evbuf_Iterator iter = lv2_evbuf_begin(port->evbuf); if (xport_changed) { lv2_evbuf_write(&iter, @@ -192,7 +192,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) } if (jalv->request_update) { - /* Plugin state has changed, request an update */ + // Plugin state has changed, request an update const LV2_Atom_Object get = { {sizeof(LV2_Atom_Object_Body), jalv->urids.atom_Object}, {0, jalv->urids.patch_Get}}; @@ -205,7 +205,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) } if (port->sys_port) { - /* Write Jack MIDI input */ + // Write Jack MIDI input void* buf = jack_port_get_buffer(port->sys_port, nframes); for (uint32_t i = 0; i < jack_midi_get_event_count(buf); ++i) { jack_midi_event_t ev; @@ -215,16 +215,16 @@ jack_process_cb(jack_nframes_t nframes, void* data) } } } else if (port->type == TYPE_EVENT) { - /* Clear event output for plugin to write to */ + // Clear event output for plugin to write to lv2_evbuf_reset(port->evbuf, false); } } jalv->request_update = false; - /* Run plugin for this cycle */ + // Run plugin for this cycle const bool send_ui_updates = jalv_run(jalv, nframes); - /* Deliver MIDI output and UI events */ + // Deliver MIDI output and UI events for (uint32_t p = 0; p < jalv->num_ports; ++p) { struct Port* const port = &jalv->ports[p]; if (port->flow == FLOW_OUTPUT && port->type == TYPE_CONTROL && @@ -279,7 +279,7 @@ jack_process_cb(jack_nframes_t nframes, void* data) return 0; } -/** Calculate latency assuming all ports depend on each other. */ +/// Calculate latency assuming all ports depend on each other static void jack_latency_cb(jack_latency_callback_mode_t mode, void* data) { @@ -287,7 +287,7 @@ jack_latency_cb(jack_latency_callback_mode_t mode, void* data) const enum PortFlow flow = ((mode == JackCaptureLatency) ? FLOW_INPUT : FLOW_OUTPUT); - /* First calculate the min/max latency of all feeding ports */ + // First calculate the min/max latency of all feeding ports uint32_t ports_found = 0; jack_latency_range_t range = {UINT32_MAX, 0}; for (uint32_t p = 0; p < jalv->num_ports; ++p) { @@ -309,11 +309,11 @@ jack_latency_cb(jack_latency_callback_mode_t mode, void* data) range.min = 0; } - /* Add the plugin's own latency */ + // Add the plugin's own latency range.min += jalv->plugin_latency; range.max += jalv->plugin_latency; - /* Tell Jack about it */ + // Tell Jack about it for (uint32_t p = 0; p < jalv->num_ports; ++p) { struct Port* port = &jalv->ports[p]; if (port->sys_port && port->flow == flow) { @@ -327,24 +327,24 @@ jack_create_client(Jalv* jalv) { jack_client_t* client = NULL; - /* Determine the name of the JACK client */ + // Determine the name of the JACK client char* jack_name = NULL; if (jalv->opts.name) { - /* Name given on command line */ + // Name given on command line jack_name = jalv_strdup(jalv->opts.name); } else { - /* Use plugin name */ + // Use plugin name LilvNode* name = lilv_plugin_get_name(jalv->plugin); jack_name = jalv_strdup(lilv_node_as_string(name)); lilv_node_free(name); } - /* Truncate client name to suit JACK if necessary */ + // Truncate client name to suit JACK if necessary if (strlen(jack_name) >= (unsigned)jack_client_name_size() - 1) { jack_name[jack_client_name_size() - 1] = '\0'; } - /* Connect to JACK */ + // Connect to JACK if (!client) { client = jack_client_open( jack_name, @@ -369,7 +369,7 @@ jalv_backend_init(Jalv* jalv) printf("JACK Name: %s\n", jack_get_client_name(client)); - /* Set audio engine properties */ + // Set audio engine properties jalv->sample_rate = (float)jack_get_sample_rate(client); jalv->block_length = jack_get_buffer_size(client); jalv->midi_buf_size = 4096; @@ -378,7 +378,7 @@ jalv_backend_init(Jalv* jalv) jack_port_type_get_buffer_size(client, JACK_DEFAULT_MIDI_TYPE); #endif - /* Set JACK callbacks */ + // Set JACK callbacks void* const arg = (void*)jalv; jack_set_process_callback(client, &jack_process_cb, arg); jack_set_buffer_size_callback(client, &jack_buffer_size_cb, arg); @@ -386,12 +386,12 @@ jalv_backend_init(Jalv* jalv) jack_set_latency_callback(client, &jack_latency_cb, arg); if (jalv->backend) { - /* Internal JACK client, jalv->backend->is_internal_client was already - set in jack_initialize() when allocating the backend */ + /* Internal JACK client, jalv->backend->is_internal_client was already set + in jack_initialize() when allocating the backend. */ return jalv->backend; } - /* External JACK client, allocate and return opaque backend */ + // External JACK client, allocate and return opaque backend JalvBackend* backend = (JalvBackend*)calloc(1, sizeof(JalvBackend)); backend->client = client; backend->is_internal_client = false; @@ -433,17 +433,17 @@ jalv_backend_activate_port(Jalv* jalv, uint32_t port_index) const LilvNode* sym = lilv_port_get_symbol(jalv->plugin, port->lilv_port); - /* Connect unsupported ports to NULL (known to be optional by this point) */ + // Connect unsupported ports to NULL (known to be optional by this point) if (port->flow == FLOW_UNKNOWN || port->type == TYPE_UNKNOWN) { lilv_instance_connect_port(jalv->instance, port_index, NULL); return; } - /* Build Jack flags for port */ + // Build Jack flags for port enum JackPortFlags jack_flags = (port->flow == FLOW_INPUT) ? JackPortIsInput : JackPortIsOutput; - /* Connect the port based on its type */ + // Connect the port based on its type switch (port->type) { case TYPE_CONTROL: lilv_instance_connect_port(jalv->instance, port_index, &port->control); @@ -524,12 +524,12 @@ jack_initialize(jack_client_t* const client, const char* const load_init) jalv->backend->client = client; jalv->backend->is_internal_client = true; - /* Build full command line with "program" name for building argv */ + // Build full command line with "program" name for building argv const size_t cmd_len = strlen("jalv ") + args_len; char* const cmd = (char*)calloc(cmd_len + 1, 1); snprintf(cmd, cmd_len + 1, "jalv %s", load_init); - /* Build argv */ + // Build argv int argc = 0; char** argv = NULL; char* tok = cmd; @@ -14,8 +14,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#define _POSIX_C_SOURCE 200809L /* for mkdtemp */ -#define _DARWIN_C_SOURCE /* for mkdtemp on OSX */ +#define _POSIX_C_SOURCE 200809L // for mkdtemp +#define _DARWIN_C_SOURCE // for mkdtemp on OSX #include "jalv_config.h" #include "jalv_internal.h" @@ -55,7 +55,7 @@ #endif #ifdef _WIN32 -# include <io.h> /* for _mktemp */ +# include <io.h> // for _mktemp # define snprintf _snprintf #endif @@ -84,14 +84,17 @@ # define ARRAY_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) #endif -/* Size factor for UI ring buffers. The ring size is a few times the size of - an event output to give the UI a chance to keep up. Experiments with Ingen, - which can highly saturate its event output, led me to this value. It - really ought to be enough for anybody(TM). +/** + Size factor for UI ring buffers. + + The ring size is a few times the size of an event output to give the UI a + chance to keep up. Experiments with Ingen, which can highly saturate its + event output, led me to this value. It really ought to be enough for + anybody(TM). */ #define N_BUFFER_CYCLES 16 -static ZixSem* exit_sem = NULL; /**< Exit semaphore used by signal handler*/ +static ZixSem* exit_sem = NULL; ///< Exit semaphore used by signal handler static LV2_URID map_uri(LV2_URID_Map_Handle handle, const char* uri) @@ -115,14 +118,14 @@ unmap_uri(LV2_URID_Unmap_Handle handle, LV2_URID urid) #define NS_EXT "http://lv2plug.in/ns/ext/" -/** These features have no data */ +/// These features have no data static const LV2_Feature static_features[] = { {LV2_STATE__loadDefaultState, NULL}, {LV2_BUF_SIZE__powerOf2BlockLength, NULL}, {LV2_BUF_SIZE__fixedBlockLength, NULL}, {LV2_BUF_SIZE__boundedBlockLength, NULL}}; -/** Return true iff Jalv supports the given feature. */ +/// Return true iff Jalv supports the given feature static bool feature_is_supported(Jalv* jalv, const char* uri) { @@ -139,7 +142,7 @@ feature_is_supported(Jalv* jalv, const char* uri) return false; } -/** Abort and exit on error */ +/// Abort and exit on error static void die(const char* msg) { @@ -148,9 +151,10 @@ die(const char* msg) } /** - Create a port structure from data description. This is called before plugin - and Jack instantiation. The remaining instance-specific setup - (e.g. buffers) is done later in activate_port(). + Create a port structure from data description. + + This is called before plugin and Jack instantiation. The remaining + instance-specific setup (e.g. buffers) is done later in activate_port(). */ static void create_port(Jalv* jalv, uint32_t port_index, float default_value) @@ -168,7 +172,7 @@ create_port(Jalv* jalv, uint32_t port_index, float default_value) const bool optional = lilv_port_has_property( jalv->plugin, port->lilv_port, jalv->nodes.lv2_connectionOptional); - /* Set the port flow (input or output) */ + // Set the port flow (input or output) if (lilv_port_is_a( jalv->plugin, port->lilv_port, jalv->nodes.lv2_InputPort)) { port->flow = FLOW_INPUT; @@ -184,7 +188,7 @@ create_port(Jalv* jalv, uint32_t port_index, float default_value) port->lilv_port, jalv->nodes.pprops_notOnGUI); - /* Set control values */ + // Set control values if (lilv_port_is_a( jalv->plugin, port->lilv_port, jalv->nodes.lv2_ControlPort)) { port->type = TYPE_CONTROL; @@ -217,9 +221,7 @@ create_port(Jalv* jalv, uint32_t port_index, float default_value) lilv_node_free(min_size); } -/** - Create port structures from data (via create_port()) for all ports. -*/ +/// Create port structures from data (via create_port()) for all ports void jalv_create_ports(Jalv* jalv) { @@ -250,9 +252,7 @@ jalv_create_ports(Jalv* jalv) free(default_values); } -/** - Allocate port buffers (only necessary for MIDI). -*/ +/// Allocate port buffers (only necessary for MIDI) void jalv_allocate_port_buffers(Jalv* jalv) { @@ -596,7 +596,7 @@ jalv_send_to_ui(Jalv* jalv, uint32_t size, const void* body) { - /* TODO: Be more disciminate about what to send */ + // TODO: Be more disciminate about what to send char evbuf[sizeof(ControlChange) + sizeof(LV2_Atom)]; ControlChange* ev = (ControlChange*)evbuf; ev->index = port_index; @@ -620,22 +620,22 @@ jalv_send_to_ui(Jalv* jalv, bool jalv_run(Jalv* jalv, uint32_t nframes) { - /* Read and apply control change events from UI */ + // Read and apply control change events from UI jalv_apply_ui_events(jalv, nframes); - /* Run plugin for this cycle */ + // Run plugin for this cycle lilv_instance_run(jalv->instance, nframes); - /* Process any worker replies. */ + // Process any worker replies jalv_worker_emit_responses(&jalv->state_worker, jalv->instance); jalv_worker_emit_responses(&jalv->worker, jalv->instance); - /* Notify the plugin the run() cycle is finished */ + // Notify the plugin the run() cycle is finished if (jalv->worker.iface && jalv->worker.iface->end_run) { jalv->worker.iface->end_run(jalv->instance->lv2_handle); } - /* Check if it's time to send updates to the UI */ + // Check if it's time to send updates to the UI jalv->event_delta_t += nframes; bool send_ui_updates = false; float update_frames = jalv->sample_rate / jalv->ui_update_hz; @@ -650,28 +650,28 @@ jalv_run(Jalv* jalv, uint32_t nframes) int jalv_update(Jalv* jalv) { - /* Check quit flag and close if set. */ + // Check quit flag and close if set if (zix_sem_try_wait(&jalv->done)) { jalv_close_ui(jalv); return 0; } - /* Emit UI events. */ + // Emit UI events ControlChange ev; const size_t space = zix_ring_read_space(jalv->plugin_events); for (size_t i = 0; i + sizeof(ev) < space; i += sizeof(ev) + ev.size) { - /* Read event header to get the size */ + // Read event header to get the size zix_ring_read(jalv->plugin_events, (char*)&ev, sizeof(ev)); - /* Resize read buffer if necessary */ + // Resize read buffer if necessary jalv->ui_event_buf = realloc(jalv->ui_event_buf, ev.size); void* const buf = jalv->ui_event_buf; - /* Read event body */ + // Read event body zix_ring_read(jalv->plugin_events, (char*)buf, ev.size); if (jalv->opts.dump && ev.protocol == jalv->urids.atom_eventTransfer) { - /* Dump event in Turtle to the console */ + // Dump event in Turtle to the console LV2_Atom* atom = (LV2_Atom*)buf; char* str = sratom_to_turtle(jalv->ui_sratom, &jalv->unmap, @@ -745,7 +745,7 @@ setup_signals(Jalv* const jalv) sigaction(SIGINT, &action, NULL); sigaction(SIGTERM, &action, NULL); #else - /* May not work in combination with fgets in the console interface */ + // May not work in combination with fgets in the console interface signal(SIGINT, signal_handler); signal(SIGTERM, signal_handler); #endif @@ -814,8 +814,8 @@ int jalv_open(Jalv* const jalv, int* argc, char*** argv) { jalv->prog_name = (*argv)[0]; - jalv->block_length = 4096; /* Should be set by backend */ - jalv->midi_buf_size = 1024; /* Should be set by backend */ + jalv->block_length = 4096; // Should be set by backend + jalv->midi_buf_size = 1024; // Should be set by backend jalv->play_state = JALV_PAUSED; jalv->bpm = 120.0f; jalv->control_in = (uint32_t)-1; @@ -937,13 +937,13 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) zix_sem_init(&jalv->paused, 0); zix_sem_init(&jalv->worker.sem, 0); - /* Find all installed plugins */ + // Find all installed plugins LilvWorld* world = lilv_world_new(); lilv_world_load_all(world); jalv->world = world; const LilvPlugins* plugins = lilv_world_get_all_plugins(world); - /* Cache URIs for concepts we'll use */ + // Cache URIs for concepts we'll use jalv->nodes.atom_AtomPort = lilv_new_uri(world, LV2_ATOM__AtomPort); jalv->nodes.atom_Chunk = lilv_new_uri(world, LV2_ATOM__Chunk); jalv->nodes.atom_Float = lilv_new_uri(world, LV2_ATOM__Float); @@ -988,7 +988,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) jalv->nodes.work_schedule = lilv_new_uri(world, LV2_WORKER__schedule); jalv->nodes.end = NULL; - /* Get plugin URI from loaded state or command line */ + // Get plugin URI from loaded state or command line LilvState* state = NULL; LilvNode* plugin_uri = NULL; if (jalv->opts.load) { @@ -1018,7 +1018,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) return -3; } - /* Find plugin */ + // Find plugin printf("Plugin: %s\n", lilv_node_as_string(plugin_uri)); jalv->plugin = lilv_plugins_get_by_uri(plugins, plugin_uri); lilv_node_free(plugin_uri); @@ -1028,7 +1028,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) return -4; } - /* Load preset, if specified */ + // Load preset, if specified if (jalv->opts.preset) { LilvNode* preset = lilv_new_uri(jalv->world, jalv->opts.preset); @@ -1043,7 +1043,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) } } - /* Check for thread-safe state restore() method. */ + // Check for thread-safe state restore() method LilvNode* state_threadSafeRestore = lilv_new_uri(jalv->world, LV2_STATE__threadSafeRestore); if (lilv_plugin_has_feature(jalv->plugin, state_threadSafeRestore)) { @@ -1052,12 +1052,12 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) lilv_node_free(state_threadSafeRestore); if (!state) { - /* Not restoring state, load the plugin as a preset to get default */ + // Not restoring state, load the plugin as a preset to get default state = lilv_state_new_from_world( jalv->world, &jalv->map, lilv_plugin_get_uri(jalv->plugin)); } - /* Get a plugin UI */ + // Get a plugin UI jalv->uis = lilv_plugin_get_uis(jalv->plugin); if (!jalv->opts.generic_ui) { if ((jalv->ui = jalv_select_custom_ui(jalv))) { @@ -1075,7 +1075,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) } } - /* Create ringbuffers for UI if necessary */ + // Create ringbuffers for UI if necessary if (jalv->ui) { fprintf(stderr, "UI: %s\n", @@ -1084,7 +1084,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) fprintf(stderr, "UI: None\n"); } - /* Create port and control structures */ + // Create port and control structures jalv_create_ports(jalv); jalv_create_controls(jalv, true); jalv_create_controls(jalv, false); @@ -1101,39 +1101,38 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) if (jalv->opts.buffer_size == 0) { /* The UI ring is fed by plugin output ports (usually one), and the UI - updates roughly once per cycle. The ring size is a few times the - size of the MIDI output to give the UI a chance to keep up. The UI - should be able to keep up with 4 cycles, and tests show this works - for me, but this value might need increasing to avoid overflows. - */ + updates roughly once per cycle. The ring size is a few times the size + of the MIDI output to give the UI a chance to keep up. The UI should be + able to keep up with 4 cycles, and tests show this works for me, but + this value might need increasing to avoid overflows. */ jalv->opts.buffer_size = jalv->midi_buf_size * N_BUFFER_CYCLES; } if (jalv->opts.update_rate == 0.0) { - /* Calculate a reasonable UI update frequency. */ + // Calculate a reasonable UI update frequency jalv->ui_update_hz = jalv_ui_refresh_rate(jalv); } else { - /* Use user-specified UI update rate. */ + // Use user-specified UI update rate jalv->ui_update_hz = jalv->opts.update_rate; jalv->ui_update_hz = MAX(1.0f, jalv->ui_update_hz); } if (jalv->opts.scale_factor == 0.0) { - /* Calculate the monitor's scale factor. */ + // Calculate the monitor's scale factor jalv->ui_scale_factor = jalv_ui_scale_factor(jalv); } else { - /* Use user-specified UI scale factor. */ + // Use user-specified UI scale factor jalv->ui_scale_factor = jalv->opts.scale_factor; } - /* The UI can only go so fast, clamp to reasonable limits */ + // The UI can only go so fast, clamp to reasonable limits jalv->ui_update_hz = MIN(60, jalv->ui_update_hz); jalv->opts.buffer_size = MAX(4096, jalv->opts.buffer_size); fprintf(stderr, "Comm buffers: %u bytes\n", jalv->opts.buffer_size); fprintf(stderr, "Update rate: %.01f Hz\n", jalv->ui_update_hz); fprintf(stderr, "Scale factor: %.01f\n", jalv->ui_scale_factor); - /* Build options array to pass to plugin */ + // Build options array to pass to plugin const LV2_Options_Option options[ARRAY_SIZE(jalv->features.options)] = { {LV2_OPTIONS_INSTANCE, 0, @@ -1181,13 +1180,13 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) init_feature( &jalv->features.safe_restore_feature, LV2_STATE__threadSafeRestore, NULL); - /* Create Plugin <=> UI communication buffers */ + // Create Plugin <=> UI communication buffers jalv->ui_events = zix_ring_new(jalv->opts.buffer_size); jalv->plugin_events = zix_ring_new(jalv->opts.buffer_size); zix_ring_mlock(jalv->ui_events); zix_ring_mlock(jalv->plugin_events); - /* Build feature list for passing to plugins */ + // Build feature list for passing to plugins const LV2_Feature* const features[] = {&jalv->features.map_feature, &jalv->features.unmap_feature, &jalv->features.sched_feature, @@ -1206,7 +1205,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) } memcpy(jalv->feature_list, features, sizeof(features)); - /* Check that any required features are supported */ + // Check that any required features are supported LilvNodes* req_feats = lilv_plugin_get_required_features(jalv->plugin); LILV_FOREACH (nodes, f, req_feats) { const char* uri = lilv_node_as_uri(lilv_nodes_get(req_feats, f)); @@ -1218,7 +1217,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) } lilv_nodes_free(req_feats); - /* Instantiate the plugin */ + // Instantiate the plugin jalv->instance = lilv_plugin_instantiate( jalv->plugin, jalv->sample_rate, jalv->feature_list); if (!jalv->instance) { @@ -1235,7 +1234,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) jalv_allocate_port_buffers(jalv); } - /* Create workers if necessary */ + // Create workers if necessary if (lilv_plugin_has_extension_data(jalv->plugin, jalv->nodes.work_interface)) { const LV2_Worker_Interface* iface = @@ -1248,7 +1247,7 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) } } - /* Apply loaded state to plugin instance if necessary */ + // Apply loaded state to plugin instance if necessary if (state) { jalv_apply_state(jalv, state); } @@ -1259,12 +1258,12 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) } } - /* Create Jack ports and connect plugin ports to buffers */ + // Create Jack ports and connect plugin ports to buffers for (uint32_t i = 0; i < jalv->num_ports; ++i) { jalv_backend_activate_port(jalv, i); } - /* Print initial control values */ + // Print initial control values for (size_t i = 0; i < jalv->controls.n_controls; ++i) { ControlID* control = jalv->controls.controls[i]; if (control->type == PORT && control->is_writable) { @@ -1273,13 +1272,13 @@ jalv_open(Jalv* const jalv, int* argc, char*** argv) } } - /* Activate plugin */ + // Activate plugin lilv_instance_activate(jalv->instance); - /* Discover UI */ + // Discover UI jalv->has_ui = jalv_discover_ui(jalv); - /* Activate Jack */ + // Activate Jack jalv_backend_activate(jalv); jalv->play_state = JALV_RUNNING; @@ -1293,10 +1292,10 @@ jalv_close(Jalv* const jalv) fprintf(stderr, "Exiting...\n"); - /* Terminate the worker */ + // Terminate the worker jalv_worker_finish(&jalv->worker); - /* Deactivate audio */ + // Deactivate audio jalv_backend_deactivate(jalv); for (uint32_t i = 0; i < jalv->num_ports; ++i) { if (jalv->ports[i].evbuf) { @@ -1305,10 +1304,10 @@ jalv_close(Jalv* const jalv) } jalv_backend_close(jalv); - /* Destroy the worker */ + // Destroy the worker jalv_worker_destroy(&jalv->worker); - /* Deactivate plugin */ + // Deactivate plugin #ifdef HAVE_SUIL suil_instance_free(jalv->ui_instance); #endif @@ -1317,7 +1316,7 @@ jalv_close(Jalv* const jalv) lilv_instance_free(jalv->instance); } - /* Clean up */ + // Clean up free(jalv->ports); zix_ring_free(jalv->ui_events); zix_ring_free(jalv->plugin_events); @@ -1376,13 +1375,13 @@ main(int argc, char** argv) return EXIT_FAILURE; } - /* Set up signal handlers */ + // Set up signal handlers setup_signals(&jalv); - /* Run UI (or prompt at console) */ + // Run UI (or prompt at console) jalv_open_ui(&jalv); - /* Wait for finish signal from UI or signal handler */ + // Wait for finish signal from UI or signal handler zix_sem_wait(&jalv.done); return jalv_close(&jalv); diff --git a/src/jalv_gtk.c b/src/jalv_gtk.c index 33b4b48..e95a53d 100644 --- a/src/jalv_gtk.c +++ b/src/jalv_gtk.c @@ -47,7 +47,7 @@ LV2_DISABLE_DEPRECATION_WARNINGS static GtkCheckMenuItem* active_preset_item = NULL; static bool updating = false; -/** Widget for a control. */ +/// Widget for a control typedef struct { GtkSpinButton* spin; GtkWidget* control; @@ -1186,14 +1186,14 @@ build_control_widget(Jalv* jalv, GtkWidget* window) { GtkWidget* port_table = gtk_table_new(jalv->num_ports, 3, false); - /* Make an array of controls sorted by group */ + // Make an array of controls sorted by group GArray* controls = g_array_new(FALSE, TRUE, sizeof(ControlID*)); for (unsigned i = 0; i < jalv->controls.n_controls; ++i) { g_array_append_vals(controls, &jalv->controls.controls[i], 1); } g_array_sort_with_data(controls, control_group_cmp, jalv); - /* Add controls in group order */ + // Add controls in group order LilvNode* last_group = NULL; int n_rows = 0; for (size_t i = 0; i < controls->len; ++i) { @@ -1201,7 +1201,7 @@ build_control_widget(Jalv* jalv, GtkWidget* window) Controller* controller = NULL; LilvNode* group = record->group; - /* Check group and add new heading if necessary */ + // Check group and add new heading if necessary if (group && !lilv_node_equals(group, last_group)) { LilvNode* group_name = lilv_world_get(jalv->world, group, jalv->nodes.lv2_name, NULL); @@ -1221,7 +1221,7 @@ build_control_widget(Jalv* jalv, GtkWidget* window) } last_group = group; - /* Make control widget */ + // Make control widget if (record->value_type == jalv->forge.String) { controller = make_entry(record); } else if (record->value_type == jalv->forge.Path) { @@ -1236,14 +1236,14 @@ build_control_widget(Jalv* jalv, GtkWidget* window) jalv->ports[record->index].widget = controller; } if (controller) { - /* Add row to table for this controller */ + // Add row to table for this controller add_control_row(port_table, n_rows++, (record->label ? lilv_node_as_string(record->label) : lilv_node_as_uri(record->node)), controller); - /* Set tooltip text from comment, if available */ + // Set tooltip text from comment, if available LilvNode* comment = lilv_world_get( jalv->world, record->node, jalv->nodes.rdfs_comment, NULL); if (comment) { @@ -1378,12 +1378,12 @@ jalv_open_ui(Jalv* jalv) build_menu(jalv, window, vbox); } - /* Create/show alignment to contain UI (whether custom or generic) */ + // Create/show alignment to contain UI (whether custom or generic) GtkWidget* alignment = gtk_alignment_new(0.5, 0.5, 1.0, 1.0); gtk_box_pack_start(GTK_BOX(vbox), alignment, TRUE, TRUE, 0); gtk_widget_show(alignment); - /* Attempt to instantiate custom UI if necessary */ + // Attempt to instantiate custom UI if necessary if (jalv->ui && !jalv->opts.generic_ui) { jalv_ui_instantiate(jalv, jalv_native_ui_type(), alignment); } diff --git a/src/jalv_internal.h b/src/jalv_internal.h index 4a710d7..33e214f 100644 --- a/src/jalv_internal.h +++ b/src/jalv_internal.h @@ -1,5 +1,5 @@ /* - Copyright 2007-2016 David Robillard <d@drobilla.net> + Copyright 2007-2022 David Robillard <d@drobilla.net> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -94,9 +94,9 @@ struct Port { float control; ///< For control ports, otherwise 0.0f }; -/* Controls */ +// Controls -/** Type of plugin control. */ +/// Type of plugin control typedef enum { PORT, ///< Control port PROPERTY ///< Property (set via atom message) @@ -107,11 +107,11 @@ typedef struct { char* label; } ScalePoint; -/** Order scale points by value. */ +/// Order scale points by value int scale_point_cmp(const ScalePoint* a, const ScalePoint* b); -/** Plugin control. */ +/// Plugin control typedef struct { Jalv* jalv; ControlType type; @@ -153,9 +153,7 @@ add_control(Controls* controls, ControlID* control); ControlID* get_property_control(const Controls* controls, LV2_URID property); -/** - Control change event, sent through ring buffers for UI updates. -*/ +/// Control change event, sent through ring buffers for UI updates typedef struct { uint32_t index; uint32_t protocol; @@ -370,7 +368,7 @@ jalv_backend_deactivate(Jalv* jalv); void jalv_backend_close(Jalv* jalv); -/** Expose a port to the system (if applicable) and connect it to its buffer. */ +/// Expose a port to the system (if applicable) and connect it to its buffer void jalv_backend_activate_port(Jalv* jalv, uint32_t port_index); diff --git a/src/jalv_qt.cpp b/src/jalv_qt.cpp index c7c2743..746ecdc 100644 --- a/src/jalv_qt.cpp +++ b/src/jalv_qt.cpp @@ -661,7 +661,7 @@ build_control_widget(Jalv* jalv) lilv_port_get(plugin, port->lilv_port, jalv->nodes.pg_group); if (group) { if (!lilv_node_equals(group, lastGroup)) { - /* Group has changed */ + // Group has changed LilvNode* groupName = lilv_world_get(world, group, jalv->nodes.lv2_name, nullptr); if (!groupName) { diff --git a/src/lv2_evbuf.h b/src/lv2_evbuf.h index 40acbe5..31f3f08 100644 --- a/src/lv2_evbuf.h +++ b/src/lv2_evbuf.h @@ -1,5 +1,5 @@ /* - Copyright 2008-2014 David Robillard <d@drobilla.net> + Copyright 2008-2022 David Robillard <d@drobilla.net> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -25,14 +25,10 @@ extern "C" { # include <stdbool.h> #endif -/** - An abstract/opaque LV2 event buffer. -*/ +/// An abstract/opaque LV2 event buffer typedef struct LV2_Evbuf_Impl LV2_Evbuf; -/** - An iterator over an LV2_Evbuf. -*/ +/// An iterator over an LV2_Evbuf typedef struct { LV2_Evbuf* evbuf; uint32_t offset; @@ -40,54 +36,50 @@ typedef struct { /** Allocate a new, empty event buffer. + URIDs for atom:Chunk and atom:Sequence must be passed for LV2_EVBUF_ATOM. */ LV2_Evbuf* lv2_evbuf_new(uint32_t capacity, uint32_t atom_Chunk, uint32_t atom_Sequence); -/** - Free an event buffer allocated with lv2_evbuf_new. -*/ +/// Free an event buffer allocated with lv2_evbuf_new void lv2_evbuf_free(LV2_Evbuf* evbuf); /** Clear and initialize an existing event buffer. + The contents of buf are ignored entirely and overwritten, except capacity - which is unmodified. - If input is false and this is an atom buffer, the buffer will be prepared - for writing by the plugin. This MUST be called before every run cycle. + which is unmodified. If input is false and this is an atom buffer, the + buffer will be prepared for writing by the plugin. This MUST be called + before every run cycle. */ void lv2_evbuf_reset(LV2_Evbuf* evbuf, bool input); -/** - Return the total padded size of the events stored in the buffer. -*/ +/// Return the total padded size of the events stored in the buffer uint32_t lv2_evbuf_get_size(LV2_Evbuf* evbuf); /** Return the actual buffer implementation. + The format of the buffer returned depends on the buffer type. */ void* lv2_evbuf_get_buffer(LV2_Evbuf* evbuf); -/** - Return an iterator to the start of `evbuf`. -*/ +/// Return an iterator to the start of `evbuf` LV2_Evbuf_Iterator lv2_evbuf_begin(LV2_Evbuf* evbuf); -/** - Return an iterator to the end of `evbuf`. -*/ +/// Return an iterator to the end of `evbuf` LV2_Evbuf_Iterator lv2_evbuf_end(LV2_Evbuf* evbuf); /** Check if `iter` is valid. + @return True if `iter` is valid, otherwise false (past end of buffer) */ bool @@ -95,7 +87,9 @@ lv2_evbuf_is_valid(LV2_Evbuf_Iterator iter); /** Advance `iter` forward one event. + `iter` must be valid. + @return True if `iter` is valid, otherwise false (reached end of buffer) */ LV2_Evbuf_Iterator @@ -103,6 +97,7 @@ lv2_evbuf_next(LV2_Evbuf_Iterator iter); /** Dereference an event iterator (i.e. get the event currently pointed to). + `iter` must be valid. `type` Set to the type of the event. `size` Set to the size of the event. @@ -119,9 +114,11 @@ lv2_evbuf_get(LV2_Evbuf_Iterator iter, /** Write an event at `iter`. + The event (if any) pointed to by `iter` will be overwritten, and `iter` incremented to point to the following event (i.e. several calls to this function can be done in sequence without twiddling iter in-between). + @return True if event was written, otherwise false (buffer is full). */ bool @@ -136,4 +133,4 @@ lv2_evbuf_write(LV2_Evbuf_Iterator* iter, } #endif -#endif /* LV2_EVBUF_H */ +#endif // LV2_EVBUF_H diff --git a/src/portaudio.c b/src/portaudio.c index dda88ae..6b43dc7 100644 --- a/src/portaudio.c +++ b/src/portaudio.c @@ -1,5 +1,5 @@ /* - Copyright 2007-2016 David Robillard <d@drobilla.net> + Copyright 2007-2022 David Robillard <d@drobilla.net> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -35,7 +35,7 @@ pa_process_cb(const void* inputs, { Jalv* jalv = (Jalv*)handle; - /* Prepare port buffers */ + // Prepare port buffers uint32_t in_index = 0; uint32_t out_index = 0; for (uint32_t i = 0; i < jalv->num_ports; ++i) { @@ -52,7 +52,7 @@ pa_process_cb(const void* inputs, lv2_evbuf_reset(port->evbuf, true); if (jalv->request_update) { - /* Plugin state has changed, request an update */ + // Plugin state has changed, request an update const LV2_Atom_Object get = { {sizeof(LV2_Atom_Object_Body), jalv->urids.atom_Object}, {0, jalv->urids.patch_Get}}; @@ -65,16 +65,16 @@ pa_process_cb(const void* inputs, (const uint8_t*)LV2_ATOM_BODY(&get)); } } else if (port->type == TYPE_EVENT) { - /* Clear event output for plugin to write to */ + // Clear event output for plugin to write to lv2_evbuf_reset(port->evbuf, false); } } jalv->request_update = false; - /* Run plugin for this cycle */ + // Run plugin for this cycle const bool send_ui_updates = jalv_run(jalv, nframes); - /* Deliver UI events */ + // Deliver UI events for (uint32_t p = 0; p < jalv->num_ports; ++p) { struct Port* const port = &jalv->ports[p]; if (port->flow == FLOW_OUTPUT && port->type == TYPE_EVENT) { diff --git a/src/symap.c b/src/symap.c index 196c963..4a1a989 100644 --- a/src/symap.c +++ b/src/symap.c @@ -38,20 +38,13 @@ */ struct SymapImpl { - /** - Unsorted array of strings, such that the symbol for ID i is found - at symbols[i - 1]. - */ + /// Unsorted array of strings, so symbols[i] is the symbol for ID i char** symbols; - /** - Array of IDs, sorted by corresponding string in `symbols`. - */ + /// Array of IDs, sorted by corresponding string in `symbols` uint32_t* index; - /** - Number of symbols (number of items in `symbols` and `index`). - */ + /// Number of symbols (number of items in `symbols` and `index`) uint32_t size; }; @@ -160,11 +153,11 @@ symap_map(Symap* map, const char* sym) const uint32_t id = ++map->size; char* const str = symap_strdup(sym); - /* Append new symbol to symbols array */ + // Append new symbol to symbols array map->symbols = (char**)realloc(map->symbols, map->size * sizeof(str)); map->symbols[id - 1] = str; - /* Insert new index element into sorted index */ + // Insert new index element into sorted index map->index = (uint32_t*)realloc(map->index, map->size * sizeof(uint32_t)); if (index < map->size - 1) { memmove(map->index + index + 1, @@ -237,4 +230,4 @@ main() return 0; } -#endif /* STANDALONE */ +#endif // STANDALONE diff --git a/src/symap.h b/src/symap.h index 25b12cd..7b74d9f 100644 --- a/src/symap.h +++ b/src/symap.h @@ -1,5 +1,5 @@ /* - Copyright 2011-2014 David Robillard <d@drobilla.net> + Copyright 2011-2022 David Robillard <d@drobilla.net> Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above @@ -29,21 +29,15 @@ typedef struct SymapImpl Symap; -/** - Create a new symbol map. -*/ +/// Create a new symbol map Symap* symap_new(void); -/** - Free a symbol map. -*/ +/// Free a symbol map void symap_free(Symap* map); -/** - Map a string to a symbol ID if it is already mapped, otherwise return 0. -*/ +/// Map a string to a symbol ID if it is already mapped, otherwise return 0 uint32_t symap_try_map(Symap* map, const char* sym); @@ -63,4 +57,4 @@ symap_map(Symap* map, const char* sym); const char* symap_unmap(Symap* map, uint32_t id); -#endif /* SYMAP_H */ +#endif // SYMAP_H |