From e0905f77927ae963b3e87cabfc14a9b207204909 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 8 Jan 2013 05:17:22 +0000 Subject: Add logger convenience API. --- lv2/lv2plug.in/ns/ext/log/lv2-log.doap.ttl | 8 +++++ lv2/lv2plug.in/ns/ext/log/manifest.ttl | 2 +- plugins/eg-sampler.lv2/sampler.c | 53 +++++++++++------------------- plugins/eg-sampler.lv2/uris.h | 4 --- plugins/eg-sampler.lv2/wscript | 2 +- wscript | 2 +- 6 files changed, 30 insertions(+), 41 deletions(-) diff --git a/lv2/lv2plug.in/ns/ext/log/lv2-log.doap.ttl b/lv2/lv2plug.in/ns/ext/log/lv2-log.doap.ttl index 3601e7c..d8e22e2 100644 --- a/lv2/lv2plug.in/ns/ext/log/lv2-log.doap.ttl +++ b/lv2/lv2plug.in/ns/ext/log/lv2-log.doap.ttl @@ -11,6 +11,14 @@ doap:created "2012-01-12" ; doap:developer ; doap:release [ + doap:revision "1.1" ; + doap:created "2013-01-08" ; + dcs:changeset [ + dcs:item [ + rdfs:label "Add logger convenience API." + ] + ] + ] , [ doap:revision "1.0" ; doap:created "2012-04-17" ; doap:file-release ; diff --git a/lv2/lv2plug.in/ns/ext/log/manifest.ttl b/lv2/lv2plug.in/ns/ext/log/manifest.ttl index 09f7c65..4ecb131 100644 --- a/lv2/lv2plug.in/ns/ext/log/manifest.ttl +++ b/lv2/lv2plug.in/ns/ext/log/manifest.ttl @@ -4,6 +4,6 @@ a lv2:Specification ; lv2:minorVersion 1 ; - lv2:microVersion 0 ; + lv2:microVersion 1 ; rdfs:seeAlso . diff --git a/plugins/eg-sampler.lv2/sampler.c b/plugins/eg-sampler.lv2/sampler.c index 9e66b1f..eb6b496 100644 --- a/plugins/eg-sampler.lv2/sampler.c +++ b/plugins/eg-sampler.lv2/sampler.c @@ -44,11 +44,12 @@ #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/log.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/ext/worker/worker.h" -#include "lv2/lv2plug.in/ns/ext/midi/midi.h" #include "lv2/lv2plug.in/ns/lv2core/lv2.h" #include "./uris.h" @@ -77,6 +78,9 @@ typedef struct { /* Forge for creating atoms */ LV2_Atom_Forge forge; + /* Logger convenience API */ + LV2_Log_Logger logger; + /* Sample */ Sample* sample; @@ -99,23 +103,6 @@ typedef struct { bool play; } Sampler; -/** - Print an error message to the host log if available, or stderr otherwise. -*/ -LV2_LOG_FUNC(3, 4) -static void -print(Sampler* self, LV2_URID type, const char* fmt, ...) -{ - va_list args; - va_start(args, fmt); - if (self->log) { - self->log->vprintf(self->log->handle, type, fmt, args); - } else { - vfprintf(stderr, fmt, args); - } - va_end(args); -} - /** An atom-like message used internally to apply/free samples. @@ -141,16 +128,14 @@ load_sample(Sampler* self, const char* path) { const size_t path_len = strlen(path); - print(self, self->uris.log_Trace, - "Loading sample %s\n", path); + lv2_log_trace(&self->logger, "Loading sample %s\n", path); Sample* const sample = (Sample*)malloc(sizeof(Sample)); SF_INFO* const info = &sample->info; SNDFILE* const sndfile = sf_open(path, SFM_READ, info); if (!sndfile || !info->frames || (info->channels != 1)) { - print(self, self->uris.log_Error, - "Failed to open sample '%s'.\n", path); + lv2_log_error(&self->logger, "Failed to open sample '%s'\n", path); free(sample); return NULL; } @@ -158,8 +143,7 @@ load_sample(Sampler* self, const char* path) /* Read data */ float* const data = malloc(sizeof(float) * info->frames); if (!data) { - print(self, self->uris.log_Error, - "Failed to allocate memory for sample.\n"); + lv2_log_error(&self->logger, "Failed to allocate memory for sample\n"); return NULL; } sf_seek(sndfile, 0ul, SEEK_SET); @@ -179,7 +163,7 @@ static void free_sample(Sampler* self, Sample* sample) { if (sample) { - print(self, self->uris.log_Trace, "Freeing %s\n", sample->path); + lv2_log_trace(&self->logger, "Freeing %s\n", sample->path); free(sample->path); free(sample->data); free(sample); @@ -304,16 +288,17 @@ instantiate(const LV2_Descriptor* descriptor, } } if (!self->map) { - print(self, self->uris.log_Error, "Missing feature urid:map.\n"); + lv2_log_error(&self->logger, "Missing feature urid:map\n"); goto fail; } else if (!self->schedule) { - print(self, self->uris.log_Error, "Missing feature work:schedule.\n"); + lv2_log_error(&self->logger, "Missing feature work:schedule\n"); goto fail; } - /* Map URIs and initialise forge */ + /* Map URIs and initialise forge/logger */ 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); @@ -376,17 +361,17 @@ run(LV2_Handle instance, const LV2_Atom_Object* obj = (LV2_Atom_Object*)&ev->body; if (obj->body.otype == uris->patch_Set) { /* Received a set message, send it to the worker. */ - print(self, self->uris.log_Trace, "Queueing set message\n"); + lv2_log_trace(&self->logger, "Queueing set message\n"); self->schedule->schedule_work(self->schedule->handle, lv2_atom_total_size(&ev->body), &ev->body); } else { - print(self, self->uris.log_Trace, - "Unknown object type %d\n", obj->body.otype); + lv2_log_trace(&self->logger, + "Unknown object type %d\n", obj->body.otype); } } else { - print(self, self->uris.log_Trace, - "Unknown event type %d\n", ev->body.type); + lv2_log_trace(&self->logger, + "Unknown event type %d\n", ev->body.type); } } @@ -469,7 +454,7 @@ restore(LV2_Handle instance, if (value) { const char* path = (const char*)value; - print(self, self->uris.log_Trace, "Restoring file %s\n", path); + lv2_log_trace(&self->logger, "Restoring file %s\n", path); free_sample(self, self->sample); self->sample = load_sample(self, path); } diff --git a/plugins/eg-sampler.lv2/uris.h b/plugins/eg-sampler.lv2/uris.h index 3482dda..2efccf9 100644 --- a/plugins/eg-sampler.lv2/uris.h +++ b/plugins/eg-sampler.lv2/uris.h @@ -36,8 +36,6 @@ typedef struct { LV2_URID eg_applySample; LV2_URID eg_file; LV2_URID eg_freeSample; - LV2_URID log_Error; - LV2_URID log_Trace; LV2_URID midi_Event; LV2_URID patch_Set; LV2_URID patch_body; @@ -54,8 +52,6 @@ map_sampler_uris(LV2_URID_Map* map, SamplerURIs* uris) uris->eg_applySample = map->map(map->handle, EG_SAMPLER__applySample); uris->eg_file = map->map(map->handle, EG_SAMPLER__file); uris->eg_freeSample = map->map(map->handle, EG_SAMPLER__freeSample); - uris->log_Error = map->map(map->handle, LV2_LOG__Error); - uris->log_Trace = map->map(map->handle, LV2_LOG__Trace); uris->midi_Event = map->map(map->handle, LV2_MIDI__MidiEvent); uris->patch_Set = map->map(map->handle, LV2_PATCH__Set); uris->patch_body = map->map(map->handle, LV2_PATCH__body); diff --git a/plugins/eg-sampler.lv2/wscript b/plugins/eg-sampler.lv2/wscript index d5c0cf0..0ce7c08 100644 --- a/plugins/eg-sampler.lv2/wscript +++ b/plugins/eg-sampler.lv2/wscript @@ -21,7 +21,7 @@ def configure(conf): autowaf.display_header('Sampler Configuration') if not autowaf.is_child(): - autowaf.check_pkg(conf, 'lv2', atleast_version='0.2.0', uselib_store='LV2') + autowaf.check_pkg(conf, 'lv2', atleast_version='1.2.3', uselib_store='LV2') autowaf.check_pkg(conf, 'sndfile', uselib_store='SNDFILE', atleast_version='1.0.0', mandatory=True) diff --git a/wscript b/wscript index 94062d7..1a01688 100644 --- a/wscript +++ b/wscript @@ -14,7 +14,7 @@ import waflib.Scripting as Scripting # Variables for 'waf dist' APPNAME = 'lv2' -VERSION = '1.2.1' +VERSION = '1.2.3' # Mandatory variables top = '.' -- cgit v1.2.1