Commit bfbbc743 authored by Hanspeter Portner's avatar Hanspeter Portner

sync frame counter to time source.

parent b33ed708
......@@ -29,7 +29,10 @@ struct _handle_t {
LV2_Atom_Sequence *notify;
LV2_Atom_Forge forge;
uint64_t offset;
LV2_URID time_position;
LV2_URID time_frame;
int64_t frame;
};
static LV2_Handle
......@@ -52,6 +55,9 @@ instantiate(const LV2_Descriptor* descriptor, double rate,
return NULL;
}
handle->time_position = handle->map->map(handle->map->handle, LV2_TIME__Position);
handle->time_frame = handle->map->map(handle->map->handle, LV2_TIME__frame);
lv2_atom_forge_init(&handle->forge, handle->map);
return handle;
......@@ -87,6 +93,22 @@ run(LV2_Handle instance, uint32_t nsamples)
LV2_Atom_Forge_Frame frame;
LV2_Atom_Forge_Ref ref;
LV2_ATOM_SEQUENCE_FOREACH(handle->control_in, ev)
{
const LV2_Atom_Object *obj = (const LV2_Atom_Object *)&ev->body;
if(lv2_atom_forge_is_object_type(forge, obj->atom.type))
{
if(obj->body.otype == handle->time_position)
{
const LV2_Atom_Long *time_frame = NULL;
lv2_atom_object_get(obj, handle->time_frame, &time_frame, NULL);
if(time_frame)
handle->frame = time_frame->body - ev->time.frames;
}
}
}
// size of input sequence
size_t size = sizeof(LV2_Atom) + handle->control_in->atom.size;
......@@ -114,7 +136,7 @@ run(LV2_Handle instance, uint32_t nsamples)
if(ref)
ref = lv2_atom_forge_tuple(forge, &tup_frame);
if(ref)
ref = lv2_atom_forge_long(forge, handle->offset);
ref = lv2_atom_forge_long(forge, handle->frame);
if(ref)
ref = lv2_atom_forge_int(forge, nsamples);
if(ref)
......@@ -131,7 +153,7 @@ run(LV2_Handle instance, uint32_t nsamples)
else
lv2_atom_sequence_clear(handle->notify);
handle->offset += nsamples;
handle->frame += nsamples;
}
static void
......
......@@ -31,8 +31,11 @@ struct _handle_t {
LV2_Atom_Sequence *notify;
LV2_Atom_Forge forge;
LV2_URID time_position;
LV2_URID time_frame;
LV2_URID midi_event;
uint64_t offset;
int64_t frame;
};
static LV2_Handle
......@@ -55,6 +58,9 @@ instantiate(const LV2_Descriptor* descriptor, double rate,
return NULL;
}
handle->time_position = handle->map->map(handle->map->handle, LV2_TIME__Position);
handle->time_frame = handle->map->map(handle->map->handle, LV2_TIME__frame);
handle->midi_event = handle->map->map(handle->map->handle, LV2_MIDI__MidiEvent);
lv2_atom_forge_init(&handle->forge, handle->map);
......@@ -92,6 +98,22 @@ run(LV2_Handle instance, uint32_t nsamples)
LV2_Atom_Forge_Frame frame [3];
LV2_Atom_Forge_Ref ref;
LV2_ATOM_SEQUENCE_FOREACH(handle->control_in, ev)
{
const LV2_Atom_Object *obj = (const LV2_Atom_Object *)&ev->body;
if(lv2_atom_forge_is_object_type(forge, obj->atom.type))
{
if(obj->body.otype == handle->time_position)
{
const LV2_Atom_Long *time_frame = NULL;
lv2_atom_object_get(obj, handle->time_frame, &time_frame, NULL);
if(time_frame)
handle->frame = time_frame->body - ev->time.frames;
}
}
}
// size of input sequence
size_t size = sizeof(LV2_Atom) + handle->control_in->atom.size;
......@@ -114,7 +136,7 @@ run(LV2_Handle instance, uint32_t nsamples)
if(ref)
ref = lv2_atom_forge_tuple(forge, &frame[1]);
if(ref)
ref = lv2_atom_forge_long(forge, handle->offset);
ref = lv2_atom_forge_long(forge, handle->frame);
if(ref)
ref = lv2_atom_forge_int(forge, nsamples);
if(ref)
......@@ -147,7 +169,7 @@ run(LV2_Handle instance, uint32_t nsamples)
if(!has_midi) // don't send anything
lv2_atom_sequence_clear(handle->notify);
handle->offset += nsamples;
handle->frame += nsamples;
}
static void
......
......@@ -31,8 +31,12 @@ struct _handle_t {
LV2_Atom_Sequence *notify;
LV2_Atom_Forge forge;
LV2_URID time_position;
LV2_URID time_frame;
osc_forge_t oforge;
uint64_t offset;
int64_t frame;
};
static LV2_Handle
......@@ -55,6 +59,9 @@ instantiate(const LV2_Descriptor* descriptor, double rate,
return NULL;
}
handle->time_position = handle->map->map(handle->map->handle, LV2_TIME__Position);
handle->time_frame = handle->map->map(handle->map->handle, LV2_TIME__frame);
osc_forge_init(&handle->oforge, handle->map);
lv2_atom_forge_init(&handle->forge, handle->map);
......@@ -91,6 +98,22 @@ run(LV2_Handle instance, uint32_t nsamples)
LV2_Atom_Forge_Frame frame [3];
LV2_Atom_Forge_Ref ref;
LV2_ATOM_SEQUENCE_FOREACH(handle->control_in, ev)
{
const LV2_Atom_Object *obj = (const LV2_Atom_Object *)&ev->body;
if(lv2_atom_forge_is_object_type(forge, obj->atom.type))
{
if(obj->body.otype == handle->time_position)
{
const LV2_Atom_Long *time_frame = NULL;
lv2_atom_object_get(obj, handle->time_frame, &time_frame, NULL);
if(time_frame)
handle->frame = time_frame->body - ev->time.frames;
}
}
}
// size of input sequence
size_t size = sizeof(LV2_Atom) + handle->control_in->atom.size;
......@@ -113,7 +136,7 @@ run(LV2_Handle instance, uint32_t nsamples)
if(ref)
ref = lv2_atom_forge_tuple(forge, &frame[1]);
if(ref)
ref = lv2_atom_forge_long(forge, handle->offset);
ref = lv2_atom_forge_long(forge, handle->frame);
if(ref)
ref = lv2_atom_forge_int(forge, nsamples);
if(ref)
......@@ -149,7 +172,7 @@ run(LV2_Handle instance, uint32_t nsamples)
if(!has_osc)
lv2_atom_sequence_clear(handle->notify);
handle->offset += nsamples;
handle->frame += nsamples;
}
static void
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment