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/eg-sampler.lv2 | |
| parent | 7f0ebf206c3654e66b1ad40450d54253f7bfd17f (diff) | |
| download | lv2-22bf425ab9d3724e8eb6961b945169c3dabd5b04.tar.xz | |
Clean up example plugin initialization
Diffstat (limited to 'plugins/eg-sampler.lv2')
| -rw-r--r-- | plugins/eg-sampler.lv2/sampler.c | 57 | ||||
| -rw-r--r-- | plugins/eg-sampler.lv2/sampler_ui.c | 38 | 
2 files changed, 36 insertions, 59 deletions
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");  |