Commit 97b7dc12 authored by Hanspeter Portner's avatar Hanspeter Portner

cov: api_state.c.

parent 6081b726
......@@ -1051,7 +1051,7 @@ _lforge_get(lua_State *L)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lforge_t *lforge = lua_touserdata(L, 1);
const LV2_URID property = luaL_checkinteger(L, 2);
const LV2_URID property = luaL_optinteger(L, 2, 0);
const LV2_URID subject = luaL_optinteger(L, 3, 0);
const int32_t sequence_num = luaL_optinteger(L, 4, 0);
......@@ -1068,16 +1068,19 @@ _lforge_get(lua_State *L)
luaL_error(L, forge_buffer_overflow);
}
if(property)
{
if(!lv2_atom_forge_key(lforge->forge, moony->uris.patch.property))
luaL_error(L, forge_buffer_overflow);
if(!lv2_atom_forge_urid(lforge->forge, property))
luaL_error(L, forge_buffer_overflow);
}
if(!lv2_atom_forge_key(lforge->forge, moony->uris.patch.sequence))
luaL_error(L, forge_buffer_overflow);
if(!lv2_atom_forge_int(lforge->forge, sequence_num))
luaL_error(L, forge_buffer_overflow);
if(!lv2_atom_forge_key(lforge->forge, moony->uris.patch.property))
luaL_error(L, forge_buffer_overflow);
if(!lv2_atom_forge_urid(lforge->forge, property))
luaL_error(L, forge_buffer_overflow);
lv2_atom_forge_pop(lforge->forge, &frame);
lua_settop(L, 1);
......
......@@ -373,175 +373,170 @@ _lstateresponder__call(lua_State *L)
int64_t frames = luaL_checkinteger(L, 2);
lforge_t *lforge = luaL_checkudata(L, 3, "lforge");
latom_t *latom = NULL;
if(luaL_testudata(L, 4, "latom"))
latom = lua_touserdata(L, 4);
latom_t *latom = luaL_checkudata(L, 4, "latom");
lua_pop(L, 1); // atom
if(!latom) // not a valid atom, abort
{
lua_pushboolean(L, 0);
return 1;
}
// replace self with its uservalue
lua_getuservalue(L, 1);
lua_replace(L, 1);
if(latom->body.obj->otype == moony->uris.patch.get)
if(lv2_atom_forge_is_object_type(lforge->forge, latom->atom->type))
{
const LV2_Atom_URID *subject = NULL;
const LV2_Atom_URID *property = NULL;
const LV2_Atom_Int *sequence = NULL;
lv2_atom_object_body_get(latom->atom->size, latom->body.obj,
moony->uris.patch.subject, &subject,
moony->uris.patch.property, &property,
moony->uris.patch.sequence, &sequence,
0);
if(latom->body.obj->otype == moony->uris.patch.get)
{
const LV2_Atom_URID *subject = NULL;
const LV2_Atom_URID *property = NULL;
const LV2_Atom_Int *sequence = NULL;
int32_t sequence_num = 0;
if(sequence && (sequence->atom.type == moony->forge.Int) )
sequence_num = sequence->body;
lv2_atom_object_body_get(latom->atom->size, latom->body.obj,
moony->uris.patch.subject, &subject,
moony->uris.patch.property, &property,
moony->uris.patch.sequence, &sequence,
0);
if(!subject || ((subject->atom.type == moony->forge.URID) && (subject->body == moony->uris.patch.self)) )
{
if(!property)
{
// register state
_lstateresponder_reg(L, moony, frames, lforge, subject, sequence_num);
int32_t sequence_num = 0;
if(sequence && (sequence->atom.type == moony->forge.Int) )
sequence_num = sequence->body;
lua_pushboolean(L, 1); // handled
return 1;
}
else if(property->atom.type == moony->forge.URID)
if(!subject || ((subject->atom.type == moony->forge.URID) && (subject->body == moony->uris.patch.self)) )
{
bool found_it = false;
if(lua_geti(L, 1, moony->uris.patch.writable) != LUA_TNIL)
if(!property)
{
if(lua_geti(L, -1, property->body) != LUA_TNIL)
found_it = true;
else
lua_pop(L, 1); // nil
}
else
lua_pop(L, 1); // nil
// register state
_lstateresponder_reg(L, moony, frames, lforge, subject, sequence_num);
if(!found_it)
lua_pushboolean(L, 1); // handled
return 1;
}
else if(property->atom.type == moony->forge.URID)
{
if(lua_geti(L, 1, moony->uris.patch.readable) != LUA_TNIL)
bool found_it = false;
if(lua_geti(L, 1, moony->uris.patch.writable) != LUA_TNIL)
{
if(lua_geti(L, -1, property->body) != LUA_TNIL)
found_it = true;
else
lua_pop(L, 1); // readable, property nil
lua_pop(L, 1); // nil
}
else
lua_pop(L, 1); // nil
}
if(found_it)
{
LV2_URID range = 0; // fallback
LV2_URID child_type = 0; //fallback
// get atom type
if(lua_geti(L, -1, moony->uris.rdfs_range) == LUA_TNUMBER)
range = lua_tointeger(L, -1);
lua_pop(L, 1); // range
// get child type
if(lua_geti(L, -1, moony->uris.atom_child_type) == LUA_TNUMBER)
child_type = lua_tointeger(L, -1);
lua_pop(L, 1); // child_type
LV2_Atom_Forge_Frame obj_frame;
if( !lv2_atom_forge_frame_time(lforge->forge, frames)
|| !lv2_atom_forge_object(lforge->forge, &obj_frame, 0, moony->uris.patch.set) )
luaL_error(L, forge_buffer_overflow);
if(!found_it)
{
if(subject)
if(lua_geti(L, 1, moony->uris.patch.readable) != LUA_TNIL)
{
if( !lv2_atom_forge_key(lforge->forge, moony->uris.patch.subject)
|| !lv2_atom_forge_urid(lforge->forge, subject->body) )
luaL_error(L, forge_buffer_overflow);
if(lua_geti(L, -1, property->body) != LUA_TNIL)
found_it = true;
else
lua_pop(L, 1); // readable, property nil
}
else
lua_pop(L, 1); // nil
}
if(sequence_num)
{
if( !lv2_atom_forge_key(lforge->forge, moony->uris.patch.sequence)
|| !lv2_atom_forge_int(lforge->forge, sequence_num) )
luaL_error(L, forge_buffer_overflow);
}
if(found_it)
{
LV2_URID range = 0; // fallback
LV2_URID child_type = 0; //fallback
if( !lv2_atom_forge_key(lforge->forge, moony->uris.patch.property)
|| !lv2_atom_forge_urid(lforge->forge, property->body) )
luaL_error(L, forge_buffer_overflow);
// get atom type
if(lua_geti(L, -1, moony->uris.rdfs_range) == LUA_TNUMBER)
range = lua_tointeger(L, -1);
lua_pop(L, 1); // range
// get child type
if(lua_geti(L, -1, moony->uris.atom_child_type) == LUA_TNUMBER)
child_type = lua_tointeger(L, -1);
lua_pop(L, 1); // child_type
LV2_Atom_Forge_Frame obj_frame;
if(lua_geti(L, -1, moony->uris.rdf_value) != LUA_TNIL)
if( !lv2_atom_forge_frame_time(lforge->forge, frames)
|| !lv2_atom_forge_object(lforge->forge, &obj_frame, 0, moony->uris.patch.set) )
luaL_error(L, forge_buffer_overflow);
{
if( !lv2_atom_forge_key(lforge->forge, moony->uris.patch.value)
|| !_lforge_basic(L, -1, lforge->forge, range, child_type) )
if(subject)
{
if( !lv2_atom_forge_key(lforge->forge, moony->uris.patch.subject)
|| !lv2_atom_forge_urid(lforge->forge, subject->body) )
luaL_error(L, forge_buffer_overflow);
}
if(sequence_num)
{
if( !lv2_atom_forge_key(lforge->forge, moony->uris.patch.sequence)
|| !lv2_atom_forge_int(lforge->forge, sequence_num) )
luaL_error(L, forge_buffer_overflow);
}
if( !lv2_atom_forge_key(lforge->forge, moony->uris.patch.property)
|| !lv2_atom_forge_urid(lforge->forge, property->body) )
luaL_error(L, forge_buffer_overflow);
if(lua_geti(L, -1, moony->uris.rdf_value) != LUA_TNIL)
{
if( !lv2_atom_forge_key(lforge->forge, moony->uris.patch.value)
|| !_lforge_basic(L, -1, lforge->forge, range, child_type) )
luaL_error(L, forge_buffer_overflow);
}
lua_pop(L, 1); // value
}
lua_pop(L, 1); // value
}
lv2_atom_forge_pop(lforge->forge, &obj_frame);
lv2_atom_forge_pop(lforge->forge, &obj_frame);
lua_pushboolean(L, 1); // handled
return 1;
lua_pushboolean(L, 1); // handled
return 1;
}
}
}
if(sequence_num)
_lstateresponder_error(L, lforge, moony, frames, sequence_num);
if(sequence_num)
_lstateresponder_error(L, lforge, moony, frames, sequence_num);
}
}
}
else if(latom->body.obj->otype == moony->uris.patch.set)
{
const LV2_Atom_URID *subject = NULL;
const LV2_Atom_URID *property = NULL;
const LV2_Atom_Int *sequence = NULL;
const LV2_Atom *value = NULL;
lv2_atom_object_body_get(latom->atom->size, latom->body.obj,
moony->uris.patch.subject, &subject,
moony->uris.patch.property, &property,
moony->uris.patch.sequence, &sequence,
moony->uris.patch.value, &value,
0);
int32_t sequence_num = 0;
if(sequence && (sequence->atom.type == moony->forge.Int) )
sequence_num = sequence->body;
if(!subject || ((subject->atom.type == moony->forge.URID) && (subject->body == moony->uris.patch.self)) )
else if(latom->body.obj->otype == moony->uris.patch.set)
{
if(property && (property->atom.type == moony->forge.URID) && value)
const LV2_Atom_URID *subject = NULL;
const LV2_Atom_URID *property = NULL;
const LV2_Atom_Int *sequence = NULL;
const LV2_Atom *value = NULL;
lv2_atom_object_body_get(latom->atom->size, latom->body.obj,
moony->uris.patch.subject, &subject,
moony->uris.patch.property, &property,
moony->uris.patch.sequence, &sequence,
moony->uris.patch.value, &value,
0);
int32_t sequence_num = 0;
if(sequence && (sequence->atom.type == moony->forge.Int) )
sequence_num = sequence->body;
if(!subject || ((subject->atom.type == moony->forge.URID) && (subject->body == moony->uris.patch.self)) )
{
if( (lua_geti(L, 1, moony->uris.patch.writable) != LUA_TNIL)
&& (lua_geti(L, -1, property->body) != LUA_TNIL) ) // self[property]
if(property && (property->atom.type == moony->forge.URID) && value)
{
_latom_value(L, value);
lua_seti(L, -2, moony->uris.rdf_value); // self[property][RDF.value] = value
if( (lua_geti(L, 1, moony->uris.patch.writable) != LUA_TNIL)
&& (lua_geti(L, -1, property->body) != LUA_TNIL) ) // self[property]
{
_latom_value(L, value);
lua_seti(L, -2, moony->uris.rdf_value); // self[property][RDF.value] = value
if(sequence_num)
_lstateresponder_ack(L, lforge, moony, frames, sequence_num);
if(sequence_num)
_lstateresponder_ack(L, lforge, moony, frames, sequence_num);
lua_pushboolean(L, 1); // handled
return 1;
lua_pushboolean(L, 1); // handled
return 1;
}
}
}
if(sequence_num)
_lstateresponder_error(L, lforge, moony, frames, sequence_num);
if(sequence_num)
_lstateresponder_error(L, lforge, moony, frames, sequence_num);
}
}
else if(latom->body.obj->otype == moony->uris.patch.put)
{
//TODO implement this
}
}
else if(latom->body.obj->otype == moony->uris.patch.put)
{
//TODO implement this
}
lua_pushboolean(L, 0); // not handled
......
......@@ -1585,12 +1585,9 @@ end
-- StateResponder
print('[test] StateResponder')
do
prefix = 'http://open-music-kontrollers.ch/lv2/moony#test'
local urid = {
subject = Map[prefix],
int = Map[prefix .. '#int'],
flt = Map[prefix .. '#flt']
}
prefix = 'http://open-music-kontrollers.ch/lv2/moony#test#'
local urid = Mapper(prefix)
local subj = Map('http://open-music-kontrollers.ch/lv2/moony#test')
local flt_get_responded = false
local flt_set_responded = false
......@@ -1598,8 +1595,10 @@ do
local state_int = Parameter{
[RDFS.label] = 'Int',
[RDFS.range] = Atom.Int,
[Atom.childType] = Atom.Bool, -- only for unit testing
[LV2.minimum] = 0,
[LV2.maximum] = 10,
[Units.unit] = Units.ms,
[RDF.value] = 2
}
......@@ -1613,6 +1612,7 @@ do
[RDFS.range] = Atom.Float,
[LV2.minimum] = -0.5,
[LV2.maximum] = 10.0,
[Units.symbol] = 'flt',
_value = 1.0,
[Patch.Get] = function(self)
flt_get_responded = true
......@@ -1624,6 +1624,16 @@ do
end
}
local state_bool = Parameter{
[RDFS.label] = 'Bool',
[RDFS.range] = Atom.Bool,
[Atom.childType] = Atom.Bool, -- only for unit testing
[Moony.color] = 0xff0000ff,
[Moony.syntax] = Lua.lang,
[LV2.scalePoint] = {},
[RDF.value] = false,
}
local state_dummy = Parameter()
assert(type(state_dummy) == 'table')
......@@ -1631,32 +1641,40 @@ do
[Patch.writable] = {
[urid.int] = state_int,
[urid.flt] = state_flt
},
[Patch.readable] = {
[urid.bool] = state_bool
}
})
local function producer(forge)
forge:frameTime(0):get(urid.int, urid.subject)
forge:frameTime(1):set(urid.int, urid.subject):typed(Atom.Int, 2):pop()
forge:frameTime(0):get(urid.int, subj, Blank())
forge:frameTime(1):set(urid.int, subj, Blank()):typed(Atom.Int, 2):pop()
forge:frameTime(2):get(urid.flt, urid.subject)
forge:frameTime(3):set(urid.flt, urid.subject):typed(Atom.Float, 2.0):pop()
forge:frameTime(2):get(urid.flt, subj, Blank())
forge:frameTime(3):set(urid.flt, subj, Blank()):typed(Atom.Float, 2.0):pop()
forge:frameTime(4):get(nil, nil, Blank())
-- state:stash
forge:frameTime(4)
forge:frameTime(5)
state:stash(forge)
-- state:sync
state:sync(5, forge)
state:sync(6, forge)
--FIXME state:register()
end
local function consumer(seq, forge)
assert(#seq == 6)
assert(#seq == 7)
for frames, atom in seq:foreach() do
if frames < 4 then
assert(state(frames, forge, atom) == true)
local handled = state(frames, forge, atom)
if frames < 5 then
assert(handled == true)
else
assert(handled == false)
end
end
......@@ -1667,9 +1685,25 @@ do
assert(flt_get_responded)
assert(flt_set_responded)
--test state:stash
assert(#seq == 7)
local atom = seq[4]
assert(atom.type == Atom.Object)
assert(atom.otype == Patch.Set)
assert(#atom == 4)
assert(atom[Patch.subject].body == subj)
assert(atom[Patch.property].body == urid.flt)
assert(atom[Patch.value].body == 2.0)
assert(atom[Patch.sequenceNumber].body ~= 0)
local atom = seq[5]
assert(atom.type == Atom.Object)
assert(atom.otype == Patch.Get)
assert(atom[Patch.sequenceNumber].body ~= 0)
--test state:stash
local atom = seq[6]
assert(atom.type == Atom.Object)
assert(#atom == 2)
assert(atom[urid.int].type == Atom.Int)
assert(atom[urid.int].body == 1)
......@@ -1681,8 +1715,10 @@ do
assert(state_int() == 1)
assert(state_flt() == 1.0)
assert(state:apply(Stash():int(1):read()) == false)
-- test state:sync
atom = seq[6]
atom = seq[7]
assert(atom.type == Atom.Object)
assert(#atom == 3)
assert(atom[Patch.subject].type == Atom.URID)
......@@ -1690,11 +1726,13 @@ do
assert(atom[Patch.sequenceNumber].body == 0)
local body = atom[Patch.body]
assert(body.type == Atom.Object)
assert(#body == 2)
assert(#body == 3)
assert(body[urid.int].type == Atom.Int)
assert(body[urid.int].body == 1)
assert(body[urid.flt].type == Atom.Float)
assert(body[urid.flt].body == 1.0)
assert(body[urid.bool].type == Atom.Bool)
assert(body[urid.bool].body == false)
end
test(producer, consumer)
......
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