Browse Source

Use logger; print info on save and restore

Signed-off-by: falkTX <falktx@falktx.com>
master
falkTX 4 years ago
parent
commit
2f1602ea43
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
3 changed files with 82 additions and 15 deletions
  1. +5
    -0
      Makefile
  2. +70
    -11
      lv2-state-test.c
  3. +7
    -4
      lv2-state-test.lv2/manifest.ttl

+ 5
- 0
Makefile View File

@@ -3,8 +3,13 @@
CC ?= gcc CC ?= gcc


CFLAGS += -O0 -g -Wall -Wextra -std=gnu99 CFLAGS += -O0 -g -Wall -Wextra -std=gnu99
CFLAGS += -fPIC -DPIC
CFLAGS += $(shell pkg-config --cflags lv2) CFLAGS += $(shell pkg-config --cflags lv2)


ifneq ($(shell pkg-config --atleast-version=1.18 lv2 && echo true),true)
CFLAGS += -DDO_NOT_HAVE_LV2_STATE_FREE_PATH
endif

LDFLAGS += -Wl,--no-undefined LDFLAGS += -Wl,--no-undefined
LDFLAGS += $(shell pkg-config --libs lv2) LDFLAGS += $(shell pkg-config --libs lv2)




+ 70
- 11
lv2-state-test.c View File

@@ -7,13 +7,14 @@


#include <lv2.h> #include <lv2.h>
#include <lv2/atom/atom.h> #include <lv2/atom/atom.h>
#include <lv2/log/logger.h>
#include <lv2/state/state.h> #include <lv2/state/state.h>


#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>


#ifndef HAVE_LV2_STATE_FREE_PATH
#ifdef DO_NOT_HAVE_LV2_STATE_FREE_PATH
// forwards compatibility with old lv2 headers // forwards compatibility with old lv2 headers
#define LV2_STATE__freePath LV2_STATE_PREFIX "freePath" #define LV2_STATE__freePath LV2_STATE_PREFIX "freePath"
typedef void* LV2_State_Free_Path_Handle; typedef void* LV2_State_Free_Path_Handle;
@@ -25,6 +26,7 @@ typedef struct {


typedef struct { typedef struct {
bool activated, deactivated, saved, restored; bool activated, deactivated, saved, restored;
LV2_Log_Logger logger;
const LV2_Atom_Sequence* seqIn; const LV2_Atom_Sequence* seqIn;
LV2_Atom_Sequence* seqOut; LV2_Atom_Sequence* seqOut;
const LV2_State_Free_Path* freePath; const LV2_State_Free_Path* freePath;
@@ -40,6 +42,8 @@ static LV2_Handle instantiate(const LV2_Descriptor* const descriptor,
const LV2_State_Free_Path* freePath = NULL; const LV2_State_Free_Path* freePath = NULL;
const LV2_State_Make_Path* makePath = NULL; const LV2_State_Make_Path* makePath = NULL;
const LV2_State_Map_Path* mapPath = NULL; const LV2_State_Map_Path* mapPath = NULL;
const LV2_Log_Log* log = NULL;
const LV2_URID_Map* uridMap = NULL;


for (int i=0; features[i] != NULL; ++i) for (int i=0; features[i] != NULL; ++i)
{ {
@@ -49,30 +53,42 @@ static LV2_Handle instantiate(const LV2_Descriptor* const descriptor,
makePath = features[i]->data; makePath = features[i]->data;
else if (strcmp(features[i]->URI, LV2_STATE__mapPath) == 0) else if (strcmp(features[i]->URI, LV2_STATE__mapPath) == 0)
mapPath = features[i]->data; mapPath = features[i]->data;
else if (strcmp(features[i]->URI, LV2_LOG__log) == 0)
log = features[i]->data;
else if (strcmp(features[i]->URI, LV2_URID__map) == 0)
uridMap = features[i]->data;
} }


if (freePath == NULL || makePath == NULL || mapPath == NULL)
return NULL;

StateTest* instance = calloc(1, sizeof(StateTest)); StateTest* instance = calloc(1, sizeof(StateTest));


instance->freePath = freePath; instance->freePath = freePath;
instance->makePath = makePath; instance->makePath = makePath;
instance->mapPath = mapPath; instance->mapPath = mapPath;


lv2_log_logger_init(&instance->logger, uridMap, log);

if (makePath != NULL)
{ {
char* const projectPath = makePath->path(makePath->handle, "."); char* const projectPath = makePath->path(makePath->handle, ".");


if (projectPath != NULL) if (projectPath != NULL)
{ {
printf("state-test init ok, initial path is: '%s'\n", projectPath);
freePath->free_path(freePath->handle, projectPath);
lv2_log_note(&instance->logger, "state-test init, host has makePath and initial path is: '%s'\n", projectPath);

if (freePath != NULL)
freePath->free_path(freePath->handle, projectPath);
else
free(projectPath);
} }
else else
{ {
printf("state-test init ok, but failed to get initial path\n");
lv2_log_note(&instance->logger, "state-test init, host has makePath but failed to get initial path\n");
} }
} }
else
{
lv2_log_note(&instance->logger, "state-test init, host does not have makePath\n");
}


return instance; return instance;


@@ -106,27 +122,32 @@ static void run(LV2_Handle instance, uint32_t sample_count)
{ {
if (instancePtr->deactivated) if (instancePtr->deactivated)
{ {
// TODO something
instancePtr->deactivated = false; instancePtr->deactivated = false;
lv2_log_note(&instancePtr->logger, "plugin was deactivated\n");
} }


if (instancePtr->activated) if (instancePtr->activated)
{ {
// TODO something
instancePtr->activated = false; instancePtr->activated = false;
lv2_log_note(&instancePtr->logger, "plugin was activated\n");
} }


if (instancePtr->restored) if (instancePtr->restored)
{ {
// TODO something
instancePtr->restored = false; instancePtr->restored = false;
lv2_log_note(&instancePtr->logger, "plugin state was restored\n");
} }


if (instancePtr->saved) if (instancePtr->saved)
{ {
// TODO something
instancePtr->saved = false; instancePtr->saved = false;
lv2_log_note(&instancePtr->logger, "plugin state was saved\n");
} }

return;

// unused
(void)sample_count;
} }


static void deactivate(LV2_Handle instance) static void deactivate(LV2_Handle instance)
@@ -145,6 +166,25 @@ static LV2_State_Status save(LV2_Handle instance,
uint32_t flags, uint32_t flags,
const LV2_Feature* const* features) const LV2_Feature* const* features)
{ {
const LV2_State_Free_Path* freePath = instancePtr->freePath;
const LV2_State_Make_Path* makePath = instancePtr->makePath;

char* const projectPath = makePath->path(makePath->handle, ".");

if (projectPath != NULL)
{
lv2_log_note(&instancePtr->logger, "state-test save ok, path is: '%s'\n", projectPath);

if (freePath != NULL)
freePath->free_path(freePath->handle, projectPath);
else
free(projectPath);
}
else
{
lv2_log_note(&instancePtr->logger, "state-test save ok, but failed to get initial path\n");
}

instancePtr->saved = true; instancePtr->saved = true;
return LV2_STATE_SUCCESS; return LV2_STATE_SUCCESS;


@@ -161,6 +201,25 @@ static LV2_State_Status restore(LV2_Handle instance,
uint32_t flags, uint32_t flags,
const LV2_Feature* const* features) const LV2_Feature* const* features)
{ {
const LV2_State_Free_Path* freePath = instancePtr->freePath;
const LV2_State_Make_Path* makePath = instancePtr->makePath;

char* const projectPath = makePath->path(makePath->handle, ".");

if (projectPath != NULL)
{
lv2_log_note(&instancePtr->logger, "state-test restore ok, path is: '%s'\n", projectPath);

if (freePath != NULL)
freePath->free_path(freePath->handle, projectPath);
else
free(projectPath);
}
else
{
lv2_log_note(&instancePtr->logger, "state-test restore ok, but failed to get initial path\n");
}

instancePtr->restored = true; instancePtr->restored = true;
return LV2_STATE_SUCCESS; return LV2_STATE_SUCCESS;




+ 7
- 4
lv2-state-test.lv2/manifest.ttl View File

@@ -5,7 +5,7 @@
@prefix state: <http://lv2plug.in/ns/ext/state#> . @prefix state: <http://lv2plug.in/ns/ext/state#> .


<https://git.kx.studio/falkTX/lv2-state-test> <https://git.kx.studio/falkTX/lv2-state-test>
a lv2:Plugin ;
a lv2:UtilityPlugin, lv2:Plugin ;
lv2:binary <lv2-state-test.so> ; lv2:binary <lv2-state-test.so> ;


lv2:extensionData state:interface ; lv2:extensionData state:interface ;
@@ -18,15 +18,18 @@
state:makePath , state:makePath ,
state:mapPath ; state:mapPath ;


state:state [];

rdfs:comment "A simple and dumb lv2 plugin to test host state support." ; rdfs:comment "A simple and dumb lv2 plugin to test host state support." ;


doap:name "lv2 state test" ; doap:name "lv2 state test" ;
doap:license "WTFPLv2" ;
doap:license <http://www.wtfpl.net/> ;


doap:maintainer [ doap:maintainer [
foaf:name "falkTX" ;
foaf:homepage <https://www.falktx.com/> ; foaf:homepage <https://www.falktx.com/> ;
foaf:mbox <mailto:falktx@falktx.com> ;
foaf:name "Filipe Coelho" ;
] ; ] ;


lv2:microVersion 0 ; lv2:microVersion 0 ;
lv2:minorVersion 2 .
lv2:minorVersion 0 .

Loading…
Cancel
Save