Browse Source

Implement a few more stub functions

Signed-off-by: falkTX <falktx@falktx.com>
remotes/origin/master
falkTX 2 years ago
parent
commit
e5dbf45ad2
Signed by: falkTX <falktx@falktx.com> GPG Key ID: CDBAA37ABC74FBA0
1 changed files with 104 additions and 2 deletions
  1. +104
    -2
      lv2-state-test.c

+ 104
- 2
lv2-state-test.c View File

@@ -6,32 +6,106 @@
*/

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

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

#ifndef HAVE_LV2_STATE_FREE_PATH
// forwards compatibility with old lv2 headers
#define LV2_STATE__freePath LV2_STATE_PREFIX "freePath"
typedef void* LV2_State_Free_Path_Handle;
typedef struct {
LV2_State_Free_Path_Handle handle;
void (*free_path)(LV2_State_Free_Path_Handle handle, char* path);
} LV2_State_Free_Path;
#endif

typedef struct {
bool activated, deactivated, saved, restored;
const LV2_Atom_Sequence* seqIn;
LV2_Atom_Sequence* seqOut;
const LV2_State_Free_Path* freePath;
const LV2_State_Make_Path* makePath;
const LV2_State_Map_Path* mapPath;
} StateTest;

static LV2_Handle instantiate(const LV2_Descriptor* const descriptor,
const double sample_rate,
const char* const bundle_path,
const LV2_Feature* const* const features)
{
return NULL;
StateTest* instance = calloc(1, sizeof(StateTest));

for (int i=0; features[i] != NULL; ++i)
{
if (strcmp(features[i]->URI, LV2_STATE__freePath) == 0)
instance->freePath = features[i]->data;
if (strcmp(features[i]->URI, LV2_STATE__makePath) == 0)
instance->makePath = features[i]->data;
if (strcmp(features[i]->URI, LV2_STATE__mapPath) == 0)
instance->mapPath = features[i]->data;
}

return instance;

// unused
(void)descriptor;
(void)sample_rate;
(void)bundle_path;
}

#define instancePtr ((StateTest*)instance)

static void connect_port(LV2_Handle instance, uint32_t port, void* data_location)
{
switch (port)
{
case 0:
instancePtr->seqIn = data_location;
break;
case 1:
instancePtr->seqOut = data_location;
break;
}
}

static void activate(LV2_Handle instance)
{
instancePtr->activated = true;
}

static void run(LV2_Handle instance, uint32_t sample_count)
{
if (instancePtr->deactivated)
{
// TODO something
instancePtr->deactivated = false;
}

if (instancePtr->activated)
{
// TODO something
instancePtr->activated = false;
}

if (instancePtr->restored)
{
// TODO something
instancePtr->restored = false;
}

if (instancePtr->saved)
{
// TODO something
instancePtr->saved = false;
}
}

static void deactivate(LV2_Handle instance)
{
instancePtr->deactivated = true;
}

static void cleanup(LV2_Handle instance)
@@ -39,8 +113,36 @@ static void cleanup(LV2_Handle instance)
free(instance);
}

static LV2_State_Status save(LV2_Handle instance,
LV2_State_Store_Function store,
LV2_State_Handle handle,
uint32_t flags,
const LV2_Feature* const* features)
{
instancePtr->saved = false;
return LV2_STATE_SUCCESS;
}

static LV2_State_Status restore(LV2_Handle instance,
LV2_State_Retrieve_Function retrieve,
LV2_State_Handle handle,
uint32_t flags,
const LV2_Feature* const* features)
{
instancePtr->restored = true;
return LV2_STATE_SUCCESS;
}

static const void* extension_data(const char* const uri)
{
static const LV2_State_Interface iface = {
.save = save,
.restore = restore
};

if (strcmp(uri, LV2_STATE__interface) == 0)
return &iface;

return NULL;
}

@@ -48,7 +150,7 @@ LV2_SYMBOL_EXPORT
const LV2_Descriptor* lv2_descriptor(const uint32_t index)
{
static const LV2_Descriptor desc = {
.URI = "",
.URI = "https://git.kx.studio/falkTX/lv2-state-test",
.connect_port = connect_port,
.activate = activate,
.run = run,


Loading…
Cancel
Save