Commit 769be0be authored by Hanspeter Portner's avatar Hanspeter Portner

cov: atom_osc.c.

parent 8fcf4c18
......@@ -719,11 +719,11 @@ _lforge_osc_message(lua_State *L)
case LV2_OSC_SYMBOL:
{
const char *s = luaL_checkstring(L, pos++);
const LV2_URID sym = moony->map->map(moony->map->handle, s);
if(!lv2_osc_forge_symbol(forge, osc_urid, sym))
const LV2_URID S = luaL_checkinteger(L, pos++);
if(!lv2_osc_forge_symbol(forge, osc_urid, S))
luaL_error(L, forge_buffer_overflow);
break;
break;
}
case LV2_OSC_MIDI:
{
......
......@@ -27,7 +27,7 @@ typedef struct _osc_responder_data_t osc_responder_data_t;
struct _osc_responder_data_t {
moony_t *moony;
bool handled;
bool matched;
};
__realtime static inline bool
......@@ -58,7 +58,7 @@ const char *loscresponder_match =
"end\n"
"\n"
"function __match(v, o, ...)\n"
" local handled = false\n"
" local matched = false\n"
" v = string.gsub(v, '%?', '.')\n"
" v = string.gsub(v, '%*', '.*')\n"
" v = string.gsub(v, '%[%!', '[^')\n"
......@@ -67,11 +67,11 @@ const char *loscresponder_match =
" for k, x in pairs(o) do\n"
" if string.match(k, w) then\n"
" x(o, ...)\n"
" handled = handled or true\n"
" matched = matched or true\n"
" end\n"
" end\n"
" end\n"
" return handled\n"
" return matched\n"
"end";
__realtime static inline void
......@@ -88,17 +88,17 @@ _loscresponder_method(const char *path, const LV2_Atom_Tuple *arguments, void *d
// 2: frames
// 3: data
int matching = 0;
int has_wildcard = 0;
if(_osc_path_has_wildcards(path))
{
lua_getglobal(L, "__match"); // push pattern matching function
lua_getglobal(L, "__match"); // push pattern has_wildcard function
lua_pushstring(L, path); // path
matching = 1;
has_wildcard = 1;
}
else if(lua_getfield(L, 1, path) == LUA_TNIL) // raw string match
{
lua_pop(L, 1); // nil
ord->handled = ord->handled || false;
ord->matched = ord->matched || false;
return;
}
......@@ -200,9 +200,9 @@ _loscresponder_method(const char *path, const LV2_Atom_Tuple *arguments, void *d
case LV2_OSC_SYMBOL:
{
const char *S;
LV2_URID S;
if(lv2_osc_symbol_get(&moony->osc_urid, atom, &S))
lua_pushstring(L, S);
lua_pushinteger(L, S);
break;
}
case LV2_OSC_MIDI:
......@@ -224,22 +224,22 @@ _loscresponder_method(const char *path, const LV2_Atom_Tuple *arguments, void *d
{
uint8_t r, g, b, a;
if(lv2_osc_rgba_get(&moony->osc_urid, atom, &r, &g, &b, &a))
lua_pushinteger(L, (r << 24) | (g << 16) | (b << 8) | a);
lua_pushinteger(L, ((int64_t)r << 24) | (g << 16) | (b << 8) | a);
break;
}
}
}
lua_call(L, 4 + matching + lua_gettop(L) - oldtop, matching);
lua_call(L, 4 + has_wildcard + lua_gettop(L) - oldtop, has_wildcard);
if(matching)
if(has_wildcard)
{
ord->handled = ord->handled || lua_toboolean(L, -1);
ord->matched = ord->matched || lua_toboolean(L, -1);
lua_pop(L, 1);
}
else
else // raw string
{
ord->handled = ord->handled || true;
ord->matched = ord->matched || true;
}
}
......@@ -277,13 +277,13 @@ _loscresponder__call(lua_State *L)
osc_responder_data_t ord = {
.moony = moony,
.handled = false
.matched = false
};
lv2_osc_body_unroll(&moony->osc_urid, latom->atom->size, latom->body.obj,
_loscresponder_method, &ord);
if(!ord.handled && *through) // not handled and through mode
if(!ord.matched && *through) // not handled and through mode
{
const int64_t frames = luaL_checkinteger(L, 2);
lforge_t *lforge = luaL_checkudata(L, 3, "lforge");
......@@ -299,7 +299,8 @@ _loscresponder__call(lua_State *L)
}
lua_pushboolean(L, 1); // handled
return 1;
lua_pushboolean(L, ord.matched); // matched a registered path
return 2;
}
__realtime int
......
......@@ -1625,7 +1625,7 @@ function stash(forge)
local bndl = forge:bundle() -- create derived container forge object
bndl:message('/hello', 'ifs', 2016, 12.5, 'hello')
bndl:message('/hello', 'b', string.char(0x1, 0x2, 0x3))
bndl:message('/hello', 'hdS', 2017, 13.5, 'world')
bndl:message('/hello', 'hdS', 2017, 13.5, Param.sampleRate)
bndl:message('/hello', 't', 0xdb89c74c040c3199)
bndl:message('/hello', 'TFNI')
bndl:message('/hello', 'm', string.char(MIDI.NoteOn, 69, 0x7f))
......@@ -3903,6 +3903,8 @@ end</code></pre>
<dd>atom body of event</dd>
<dt class="ret">(boolean)</dt>
<dd>flag whether the event was handled, e.g. whether is was any OSC at all</dd>
<dt class="ret">(boolean)</dt>
<dd>flag whether any path could be matched</dd>
</dl>
<pre><code data-ref="responder-osc">-- OSCResponder
......@@ -3933,8 +3935,9 @@ function apply_sequence(n, seq, forge)
assert(atom.otype == OSC.Message)
assert(atom[OSC.messagePath].body == '/ping')
local handled = oscR(frames, forge, atom)
local handled, matched = oscR(frames, forge, atom)
assert(handled == true)
assert(matched == true)
end
end
......
......@@ -706,7 +706,7 @@ do
forge:message('/hello', 'sif', 'world', 12, 13.0)
forge:frameTime(1)
forge:message('/hallo', 'Shdt', 'velo', 12, 13.0, 1)
forge:message('/hallo', 'Shdt', Atom.Int, 12, 13.0, 1)
forge:frameTime(2)
forge:message('/yup', 'c', string.byte('a'))
......@@ -774,7 +774,7 @@ do
assert(#args == 4)
assert(args[0] == nil)
assert(args[1].type == Atom.URID)
assert(args[1].body == Map['velo'])
assert(args[1].body == Atom.Int)
assert(args[2].type == Atom.Long)
assert(args[2].body == 12)
assert(args[3].type == Atom.Double)
......@@ -898,8 +898,30 @@ end
-- OSCResponder
print('[test] OSCResponder')
do
local vals = {
i = 13,
f = 0.5,
h = 14,
d = 0.1,
c = string.byte('c'),
r = 0xff0000ff,
b = string.char(0x1, 0x2, 0x3),
m = string.char(MIDI.NoteOn, 0x20, 0x7f),
S = Atom.Int,
s = 'hello world',
t = 0x0111111122222222,
T = true,
F = false,
I = math.huge
}
local nvals = 15
local function producer(forge)
forge:frameTime(0):message('/ping', 'i', 13)
for k, v in pairs(vals) do
forge:frameTime(0):message('/types', k, v)
end
forge:frameTime(0):message('/types', 'N')
forge:frameTime(1):bundle(0):message('/pong', 's', 'world'):pop()
forge:frameTime(2):message('/one/two/three', 'd', 12.3)
......@@ -909,18 +931,25 @@ do
forge:frameTime(2):message('/?ne/*/[tT]hree', 'd', 12.3)
forge:frameTime(2):message('/?ne/*/[!T]hree', 'd', 12.3)
forge:frameTime(2):message('/{one,eins}/*/{three,drei}', 'd', 12.3)
forge:frameTime(3):message('/foo', 'd', 12.3)
forge:frameTime(4):string('just fooling you')
end
local ping_responded = false
local types_responded = 0
local pong_responded = false
local complex_responded = 0
local osc_responder = OSCResponder({
['/ping'] = function(self, frames, forge, fmt, i)
['/types'] = function(self, frames, forge, fmt, val)
assert(frames == 0)
assert(fmt == 'i')
assert(i == 13)
ping_responded = true
if fmt == 'N' then
assert(vals[fmt] == nil)
else
assert(vals[fmt] ~= nil)
end
assert(vals[fmt] == val)
types_responded = types_responded + 1
end,
['/pong'] = function(self, frames, forge, fmt, s)
assert(frames == 1)
......@@ -934,14 +963,26 @@ do
assert(d == 12.3)
complex_responded = complex_responded + 1
end
})
}, true)
local function consumer(seq)
local function consumer(seq, forge)
for frames, atom in seq:foreach() do
assert(osc_responder(frames, nil, atom) == true)
local handled, matched = osc_responder(frames, forge, atom)
if frames == 4 then
assert(handled == false)
else
assert(handled == true)
if frames == 3 then
assert(matched == false)
else
assert(matched == true)
end
end
end
assert(ping_responded)
assert(types_responded == nvals)
assert(pong_responded)
assert(complex_responded == 7)
end
......
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