diff options
author | David Robillard <d@drobilla.net> | 2016-07-30 19:21:53 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2016-07-31 15:19:35 -0400 |
commit | 22bf425ab9d3724e8eb6961b945169c3dabd5b04 (patch) | |
tree | 916e21565b681d6c0517852623c27503143ff310 /plugins | |
parent | 7f0ebf206c3654e66b1ad40450d54253f7bfd17f (diff) | |
download | lv2-22bf425ab9d3724e8eb6961b945169c3dabd5b04.tar.xz |
Clean up example plugin initialization
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/eg-fifths.lv2/fifths.c | 23 | ||||
-rw-r--r-- | plugins/eg-metro.lv2/metro.c | 29 | ||||
-rw-r--r-- | plugins/eg-midigate.lv2/midigate.c | 36 | ||||
-rw-r--r-- | plugins/eg-params.lv2/params.c | 58 | ||||
-rw-r--r-- | plugins/eg-sampler.lv2/sampler.c | 57 | ||||
-rw-r--r-- | plugins/eg-sampler.lv2/sampler_ui.c | 38 | ||||
-rw-r--r-- | plugins/eg-scope.lv2/examploscope.c | 22 |
7 files changed, 110 insertions, 153 deletions
diff --git a/plugins/eg-fifths.lv2/fifths.c b/plugins/eg-fifths.lv2/fifths.c index 8282dd5..0141fa2 100644 --- a/plugins/eg-fifths.lv2/fifths.c +++ b/plugins/eg-fifths.lv2/fifths.c @@ -24,11 +24,13 @@ #endif #include "lv2/lv2plug.in/ns/ext/atom/util.h" +#include "lv2/lv2plug.in/ns/ext/log/logger.h" #include "lv2/lv2plug.in/ns/ext/midi/midi.h" #include "lv2/lv2plug.in/ns/ext/patch/patch.h" #include "lv2/lv2plug.in/ns/ext/state/state.h" #include "lv2/lv2plug.in/ns/ext/urid/urid.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" +#include "lv2/lv2plug.in/ns/lv2core/lv2_util.h" #include "./uris.h" @@ -39,7 +41,8 @@ enum { typedef struct { // Features - LV2_URID_Map* map; + LV2_URID_Map* map; + LV2_Log_Logger logger; // Ports const LV2_Atom_Sequence* in_port; @@ -79,19 +82,19 @@ instantiate(const LV2_Descriptor* descriptor, return NULL; } - // Get host features - for (int i = 0; features[i]; ++i) { - if (!strcmp(features[i]->URI, LV2_URID__map)) { - self->map = (LV2_URID_Map*)features[i]->data; - } - } - if (!self->map) { - fprintf(stderr, "Missing feature urid:map\n"); + // Scan host features for URID map + const char* missing = lv2_features_query( + features, + LV2_LOG__log, &self->logger.log, false, + LV2_URID__map, &self->map, true, + NULL); + lv2_log_logger_set_map(&self->logger, self->map); + if (missing) { + lv2_log_error(&self->logger, "Missing feature <%s>\n", missing); free(self); return NULL; } - // Map URIs and initialise forge/logger map_fifths_uris(self->map, &self->uris); return (LV2_Handle)self; diff --git a/plugins/eg-metro.lv2/metro.c b/plugins/eg-metro.lv2/metro.c index 84d042d..810a411 100644 --- a/plugins/eg-metro.lv2/metro.c +++ b/plugins/eg-metro.lv2/metro.c @@ -25,9 +25,11 @@ #include "lv2/lv2plug.in/ns/ext/atom/atom.h" #include "lv2/lv2plug.in/ns/ext/atom/util.h" +#include "lv2/lv2plug.in/ns/ext/log/logger.h" #include "lv2/lv2plug.in/ns/ext/time/time.h" #include "lv2/lv2plug.in/ns/ext/urid/urid.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" +#include "lv2/lv2plug.in/ns/lv2core/lv2_util.h" #ifndef M_PI # define M_PI 3.14159265 @@ -73,10 +75,11 @@ typedef enum { This example uses a simple AD envelope with fixed parameters. A more sophisticated implementation might use a more advanced envelope and allow the user to modify these parameters, the frequency of the wave, and so on. - */ +*/ typedef struct { - LV2_URID_Map* map; // URID map feature - MetroURIs uris; // Cache of mapped URIDs + LV2_URID_Map* map; // URID map feature + LV2_Log_Logger logger; // Logger API + MetroURIs uris; // Cache of mapped URIDs struct { LV2_Atom_Sequence* control; @@ -152,21 +155,21 @@ instantiate(const LV2_Descriptor* descriptor, } // Scan host features for URID map - LV2_URID_Map* map = NULL; - for (int i = 0; features[i]; ++i) { - if (!strcmp(features[i]->URI, LV2_URID_URI "#map")) { - map = (LV2_URID_Map*)features[i]->data; - } - } - if (!map) { - fprintf(stderr, "Host does not support urid:map.\n"); + const char* missing = lv2_features_query( + features, + LV2_LOG__log, &self->logger.log, false, + LV2_URID__map, &self->map, true, + NULL); + lv2_log_logger_set_map(&self->logger, self->map); + if (missing) { + lv2_log_error(&self->logger, "Missing feature <%s>\n", missing); free(self); return NULL; } // Map URIS - MetroURIs* const uris = &self->uris; - self->map = map; + MetroURIs* const uris = &self->uris; + LV2_URID_Map* const map = self->map; uris->atom_Blank = map->map(map->handle, LV2_ATOM__Blank); uris->atom_Float = map->map(map->handle, LV2_ATOM__Float); uris->atom_Object = map->map(map->handle, LV2_ATOM__Object); diff --git a/plugins/eg-midigate.lv2/midigate.c b/plugins/eg-midigate.lv2/midigate.c index 8d2bd74..aab668a 100644 --- a/plugins/eg-midigate.lv2/midigate.c +++ b/plugins/eg-midigate.lv2/midigate.c @@ -21,9 +21,11 @@ #include "lv2/lv2plug.in/ns/ext/atom/atom.h" #include "lv2/lv2plug.in/ns/ext/atom/util.h" +#include "lv2/lv2plug.in/ns/ext/log/logger.h" #include "lv2/lv2plug.in/ns/ext/midi/midi.h" #include "lv2/lv2plug.in/ns/ext/urid/urid.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" +#include "lv2/lv2plug.in/ns/lv2core/lv2_util.h" #define MIDIGATE_URI "http://lv2plug.in/plugins/eg-midigate" @@ -40,7 +42,8 @@ typedef struct { float* out; // Features - LV2_URID_Map* map; + LV2_URID_Map* map; + LV2_Log_Logger logger; struct { LV2_URID midi_MidiEvent; @@ -56,25 +59,26 @@ instantiate(const LV2_Descriptor* descriptor, const char* bundle_path, const LV2_Feature* const* features) { - /** Scan features array for the URID feature we need. */ - LV2_URID_Map* map = NULL; - for (int i = 0; features[i]; ++i) { - if (!strcmp(features[i]->URI, LV2_URID__map)) { - map = (LV2_URID_Map*)features[i]->data; - break; - } + Midigate* self = (Midigate*)calloc(1, sizeof(Midigate)); + if (!self) { + return NULL; } - if (!map) { - /** - No URID feature given. This is a host bug since we require this - feature, but should be handled gracefully anyway. - */ + + // Scan host features for URID map + const char* missing = lv2_features_query( + features, + LV2_LOG__log, &self->logger.log, false, + LV2_URID__map, &self->map, true, + NULL); + lv2_log_logger_set_map(&self->logger, self->map); + if (missing) { + lv2_log_error(&self->logger, "Missing feature <%s>\n", missing); + free(self); return NULL; } - Midigate* self = (Midigate*)calloc(1, sizeof(Midigate)); - self->map = map; - self->uris.midi_MidiEvent = map->map(map->handle, LV2_MIDI__MidiEvent); + self->uris.midi_MidiEvent = self->map->map( + self->map->handle, LV2_MIDI__MidiEvent); return (LV2_Handle)self; } diff --git a/plugins/eg-params.lv2/params.c b/plugins/eg-params.lv2/params.c index 677bfe1..06def6e 100644 --- a/plugins/eg-params.lv2/params.c +++ b/plugins/eg-params.lv2/params.c @@ -31,6 +31,7 @@ #include "lv2/lv2plug.in/ns/ext/state/state.h" #include "lv2/lv2plug.in/ns/ext/urid/urid.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" +#include "lv2/lv2plug.in/ns/lv2core/lv2_util.h" #define MAX_STRING 1024 @@ -113,14 +114,11 @@ typedef struct { // Features LV2_URID_Map* map; LV2_URID_Unmap* unmap; - LV2_Log_Log* log; + LV2_Log_Logger logger; // Forge for creating atoms LV2_Atom_Forge forge; - // Logger convenience API - LV2_Log_Logger logger; - // Ports const LV2_Atom_Sequence* in_port; LV2_Atom_Sequence* out_port; @@ -153,36 +151,6 @@ connect_port(LV2_Handle instance, } } -static inline int -get_features(const LV2_Feature* const* features, ...) -{ - va_list args; - va_start(args, features); - - const char* uri = NULL; - while ((uri = va_arg(args, const char*))) { - void** data = va_arg(args, void**); - bool required = va_arg(args, int); - bool found = false; - - for (int i = 0; features[i]; ++i) { - if (!strcmp(features[i]->URI, uri)) { - *data = features[i]->data; - found = true; - break; - } - } - - if (required && !found) { - fprintf(stderr, "Missing required feature <%s>\n", uri); - return 1; - } - } - - return 0; -} - - #define INIT_PARAM(atype, param) { \ (param)->atom.type = (atype); \ (param)->atom.size = sizeof((param)->body); \ @@ -201,19 +169,22 @@ instantiate(const LV2_Descriptor* descriptor, } // Get host features - if (get_features(features, - LV2_URID__map, &self->map, true, - LV2_URID__unmap, &self->unmap, false, - LV2_LOG__log, &self->log, false, - NULL)) { + const char* missing = lv2_features_query( + features, + LV2_LOG__log, &self->logger.log, false, + LV2_URID__map, &self->map, true, + LV2_URID__unmap, &self->unmap, false, + NULL); + lv2_log_logger_set_map(&self->logger, self->map); + if (missing) { + lv2_log_error(&self->logger, "Missing feature <%s>\n", missing); free(self); return NULL; } - // Map URIs and initialise forge/logger + // Map URIs and initialise forge map_uris(self->map, &self->uris); lv2_atom_forge_init(&self->forge, self->map); - lv2_log_logger_init(&self->logger, self->map, self->log); // Initialize state INIT_PARAM(self->forge.Int, &self->state.aint); @@ -457,8 +428,9 @@ save(LV2_Handle instance, const LV2_Feature* const* features) { Params* self = (Params*)instance; - LV2_State_Map_Path* map_path = NULL; - get_features(features, LV2_STATE__mapPath, &map_path, true, NULL); + LV2_State_Map_Path* map_path = (LV2_State_Map_Path*)lv2_features_data( + features, LV2_STATE__mapPath); + return store_state(self, store, handle, flags, map_path); } diff --git a/plugins/eg-sampler.lv2/sampler.c b/plugins/eg-sampler.lv2/sampler.c index 38776c0..1fd8c0e 100644 --- a/plugins/eg-sampler.lv2/sampler.c +++ b/plugins/eg-sampler.lv2/sampler.c @@ -36,6 +36,7 @@ #include "lv2/lv2plug.in/ns/ext/urid/urid.h" #include "lv2/lv2plug.in/ns/ext/worker/worker.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" +#include "lv2/lv2plug.in/ns/lv2core/lv2_util.h" #include "./uris.h" @@ -58,14 +59,11 @@ typedef struct { // Features LV2_URID_Map* map; LV2_Worker_Schedule* schedule; - LV2_Log_Log* log; + LV2_Log_Logger logger; // Forge for creating atoms LV2_Atom_Forge forge; - // Logger convenience API - LV2_Log_Logger logger; - // Sample Sample* sample; bool sample_changed; @@ -264,27 +262,22 @@ instantiate(const LV2_Descriptor* descriptor, } // Get host features - for (int i = 0; features[i]; ++i) { - if (!strcmp(features[i]->URI, LV2_URID__map)) { - self->map = (LV2_URID_Map*)features[i]->data; - } else if (!strcmp(features[i]->URI, LV2_WORKER__schedule)) { - self->schedule = (LV2_Worker_Schedule*)features[i]->data; - } else if (!strcmp(features[i]->URI, LV2_LOG__log)) { - self->log = (LV2_Log_Log*)features[i]->data; - } - } - if (!self->map) { - lv2_log_error(&self->logger, "Missing feature urid:map\n"); - goto fail; - } else if (!self->schedule) { - lv2_log_error(&self->logger, "Missing feature work:schedule\n"); - goto fail; + const char* missing = lv2_features_query( + features, + LV2_LOG__log, &self->logger.log, false, + LV2_URID__map, &self->map, true, + LV2_WORKER__schedule, &self->schedule, true, + NULL); + lv2_log_logger_set_map(&self->logger, self->map); + if (missing) { + lv2_log_error(&self->logger, "Missing feature <%s>\n", missing); + free(self); + return NULL; } - // Map URIs and initialise forge/logger + // Map URIs and initialise forge map_sampler_uris(self->map, &self->uris); lv2_atom_forge_init(&self->forge, self->map); - lv2_log_logger_init(&self->logger, self->map, self->log); // Load the default sample file const size_t path_len = strlen(path); @@ -296,10 +289,6 @@ instantiate(const LV2_Descriptor* descriptor, free(sample_path); return (LV2_Handle)self; - -fail: - free(self); - return 0; } static void @@ -431,18 +420,6 @@ run(LV2_Handle instance, } } -static LV2_State_Map_Path* -get_map_path(LV2_Log_Logger* logger, const LV2_Feature* const* features) -{ - for (int i = 0; features[i]; ++i) { - if (!strcmp(features[i]->URI, LV2_STATE__mapPath)) { - return (LV2_State_Map_Path*)features[i]->data; - } - } - lv2_log_error(logger, "Missing map:path feature\n"); - return NULL; -} - static LV2_State_Status save(LV2_Handle instance, LV2_State_Store_Function store, @@ -455,7 +432,8 @@ save(LV2_Handle instance, return LV2_STATE_SUCCESS; } - LV2_State_Map_Path* map_path = get_map_path(&self->logger, features); + LV2_State_Map_Path* map_path = lv2_features_data( + features, LV2_STATE__mapPath); if (!map_path) { return LV2_STATE_ERR_NO_FEATURE; } @@ -498,7 +476,8 @@ restore(LV2_Handle instance, return LV2_STATE_ERR_BAD_TYPE; } - LV2_State_Map_Path* map_path = get_map_path(&self->logger, features); + LV2_State_Map_Path* map_path = (LV2_State_Map_Path*)lv2_features_data( + features, LV2_STATE__mapPath); if (!map_path) { return LV2_STATE_ERR_NO_FEATURE; } diff --git a/plugins/eg-sampler.lv2/sampler_ui.c b/plugins/eg-sampler.lv2/sampler_ui.c index aff7e53..1a8ee2e 100644 --- a/plugins/eg-sampler.lv2/sampler_ui.c +++ b/plugins/eg-sampler.lv2/sampler_ui.c @@ -1,6 +1,6 @@ /* LV2 Sampler Example Plugin UI - Copyright 2011-2012 David Robillard <d@drobilla.net> + Copyright 2011-2016 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 @@ -22,9 +22,11 @@ #include "lv2/lv2plug.in/ns/ext/atom/atom.h" #include "lv2/lv2plug.in/ns/ext/atom/forge.h" #include "lv2/lv2plug.in/ns/ext/atom/util.h" +#include "lv2/lv2plug.in/ns/ext/log/logger.h" #include "lv2/lv2plug.in/ns/ext/patch/patch.h" #include "lv2/lv2plug.in/ns/ext/urid/urid.h" #include "lv2/lv2plug.in/ns/extensions/ui/ui.h" +#include "lv2/lv2plug.in/ns/lv2core/lv2_util.h" #include "./uris.h" @@ -32,9 +34,9 @@ typedef struct { LV2_Atom_Forge forge; - - LV2_URID_Map* map; - SamplerURIs uris; + LV2_URID_Map* map; + LV2_Log_Logger logger; + SamplerURIs uris; LV2UI_Write_Function write; LV2UI_Controller controller; @@ -100,32 +102,28 @@ instantiate(const LV2UI_Descriptor* descriptor, return NULL; } - ui->map = NULL; ui->write = write_function; ui->controller = controller; - ui->box = NULL; - ui->button = NULL; - ui->label = NULL; - ui->window = NULL; - - *widget = NULL; + *widget = NULL; - for (int i = 0; features[i]; ++i) { - if (!strcmp(features[i]->URI, LV2_URID_URI "#map")) { - ui->map = (LV2_URID_Map*)features[i]->data; - } - } - - if (!ui->map) { - fprintf(stderr, "sampler_ui: Host does not support urid:Map\n"); + // Get host features + const char* missing = lv2_features_query( + features, + LV2_LOG__log, &ui->logger.log, false, + LV2_URID__map, &ui->map, true, + NULL); + lv2_log_logger_set_map(&ui->logger, ui->map); + if (missing) { + lv2_log_error(&ui->logger, "Missing feature <%s>\n", missing); free(ui); return NULL; } + // Map URIs and initialise forge map_sampler_uris(ui->map, &ui->uris); - lv2_atom_forge_init(&ui->forge, ui->map); + // Construct Gtk UI ui->box = gtk_vbox_new(FALSE, 4); ui->label = gtk_label_new("?"); ui->button = gtk_button_new_with_label("Load Sample"); diff --git a/plugins/eg-scope.lv2/examploscope.c b/plugins/eg-scope.lv2/examploscope.c index 9860f1d..d672d25 100644 --- a/plugins/eg-scope.lv2/examploscope.c +++ b/plugins/eg-scope.lv2/examploscope.c @@ -1,4 +1,5 @@ /* + Copyright 2016 David Robillard <d@drobilla.net> Copyright 2013 Robin Gareus <robin@gareus.org> Permission to use, copy, modify, and/or distribute this software for any @@ -22,6 +23,7 @@ #include "lv2/lv2plug.in/ns/ext/log/logger.h" #include "lv2/lv2plug.in/ns/ext/state/state.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" +#include "lv2/lv2plug.in/ns/lv2core/lv2_util.h" #include "./uris.h" @@ -47,7 +49,6 @@ typedef struct { LV2_Atom_Forge_Frame frame; // Log feature and convenience API - LV2_Log_Log* log; LV2_Log_Logger logger; // Instantiation settings @@ -88,16 +89,14 @@ instantiate(const LV2_Descriptor* descriptor, } // Get host features - for (int i = 0; features[i]; ++i) { - if (!strcmp(features[i]->URI, LV2_URID__map)) { - self->map = (LV2_URID_Map*)features[i]->data; - } else if (!strcmp(features[i]->URI, LV2_LOG__log)) { - self->log = (LV2_Log_Log*)features[i]->data; - } - } - - if (!self->map) { - fprintf(stderr, "EgScope.lv2 error: Host does not support urid:map\n"); + const char* missing = lv2_features_query( + features, + LV2_LOG__log, &self->logger.log, false, + LV2_URID__map, &self->map, true, + NULL); + lv2_log_logger_set_map(&self->logger, self->map); + if (missing) { + lv2_log_error(&self->logger, "Missing feature <%s>\n", missing); free(self); return NULL; } @@ -124,7 +123,6 @@ instantiate(const LV2_Descriptor* descriptor, // Map URIs and initialise forge/logger map_sco_uris(self->map, &self->uris); lv2_atom_forge_init(&self->forge, self->map); - lv2_log_logger_init(&self->logger, self->map, self->log); return (LV2_Handle)self; } |