Commit 6f4dd2cf authored by Hanspeter Portner's avatar Hanspeter Portner

implement through mode in MIDIResponder.

if through mode is:
* enabled, unmatched MIDI messages go through.
* disabled (default), unmatched MIDI messages are discarded.
parent 92f5a905
...@@ -17,25 +17,25 @@ ...@@ -17,25 +17,25 @@
#include <api_midi.h> #include <api_midi.h>
#include <api_atom.h> #include <api_atom.h>
#include <api_forge.h>
static int static int
_lmidiresponder__call(lua_State *L) _lmidiresponder__call(lua_State *L)
{ {
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1)); moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
const bool *through = lua_touserdata(L, 1);
lua_settop(L, 4); // discard superfluous arguments lua_settop(L, 4); // discard superfluous arguments
// 1: self // 1: self
// 2: frames // 2: frames
// 3: data // 3: forge
// 4: atom // 4: atom
latom_t *lchunk = NULL; latom_t *lchunk = luaL_checkudata(L, 4, "latom");
if(luaL_testudata(L, 4, "latom"))
lchunk = lua_touserdata(L, 4);
lua_pop(L, 1); // atom lua_pop(L, 1); // atom
// check for valid atom and event type // check for valid atom and event type
if(!lchunk || (lchunk->atom->type != moony->uris.midi_event)) if(lchunk->atom->type != moony->uris.midi_event)
{ {
lua_pushboolean(L, 0); // not handled lua_pushboolean(L, 0); // not handled
return 1; return 1;
...@@ -63,6 +63,20 @@ _lmidiresponder__call(lua_State *L) ...@@ -63,6 +63,20 @@ _lmidiresponder__call(lua_State *L)
lua_call(L, 4 + lchunk->atom->size - 1, 0); lua_call(L, 4 + lchunk->atom->size - 1, 0);
} }
else if(*through) // through
{
const int64_t frames = luaL_checkinteger(L, 2);
lforge_t *lforge = luaL_checkudata(L, 3, "lforge");
if(frames < lforge->last.frames)
luaL_error(L, "invalid frame time, must not decrease");
lforge->last.frames = frames;
if( !lv2_atom_forge_frame_time(lforge->forge, frames)
|| !lv2_atom_forge_atom(lforge->forge, lchunk->atom->size, lchunk->atom->type)
|| !lv2_atom_forge_write(lforge->forge, lchunk->body.raw, lchunk->atom->size) )
luaL_error(L, forge_buffer_overflow);
}
lua_pushboolean(L, 1); // handled lua_pushboolean(L, 1); // handled
return 1; return 1;
...@@ -73,11 +87,14 @@ _lmidiresponder(lua_State *L) ...@@ -73,11 +87,14 @@ _lmidiresponder(lua_State *L)
{ {
//moony_t *moony = lua_touserdata(L, lua_upvalueindex(1)); //moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lua_settop(L, 1); // discard superfluous arguments lua_settop(L, 2); // discard superfluous arguments
const bool _through = lua_toboolean(L, 2);
lua_pop(L, 1); // bool
// o = new // o = new
int32_t *dummy = lua_newuserdata(L, sizeof(int32_t)); bool *through = lua_newuserdata(L, sizeof(bool));
(void)dummy; *through= _through;
// o.uservalue = uservalue // o.uservalue = uservalue
lua_insert(L, 1); lua_insert(L, 1);
......
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