Commit 50f31a32 authored by Hanspeter Portner's avatar Hanspeter Portner

prototype Parameter proxy.

parent 8431bfe8
...@@ -257,6 +257,7 @@ add_library(api OBJECT ...@@ -257,6 +257,7 @@ add_library(api OBJECT
api/api_osc.c api/api_osc.c
api/api_time.c api/api_time.c
api/api_state.c api/api_state.c
api/api_parameter.c
api/api_vm.c api/api_vm.c
tlsf-3.0/tlsf.c tlsf-3.0/tlsf.c
tiny-AES128-C/aes.c) tiny-AES128-C/aes.c)
......
0.19.3101 0.19.3103
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include <api_osc.h> #include <api_osc.h>
#include <api_time.h> #include <api_time.h>
#include <api_state.h> #include <api_state.h>
#include <api_parameter.h>
#define RDF_PREFIX "http://www.w3.org/1999/02/22-rdf-syntax-ns#" #define RDF_PREFIX "http://www.w3.org/1999/02/22-rdf-syntax-ns#"
#define RDFS_PREFIX "http://www.w3.org/2000/01/rdf-schema#" #define RDFS_PREFIX "http://www.w3.org/2000/01/rdf-schema#"
...@@ -1701,6 +1702,19 @@ moony_open(moony_t *moony, lua_State *L, bool use_assert) ...@@ -1701,6 +1702,19 @@ moony_open(moony_t *moony, lua_State *L, bool use_assert)
lua_pushcclosure(L, _lstateresponder, 1); lua_pushcclosure(L, _lstateresponder, 1);
lua_setglobal(L, "StateResponder"); lua_setglobal(L, "StateResponder");
// Parameter metatable
luaL_newmetatable(L, "lparameter");
lua_pushlightuserdata(L, moony); // @ upvalueindex 1
luaL_setfuncs (L, lparameter_mt, 1);
_protect_metatable(L, -1);
//_index_metatable(L, -1);
lua_pop(L, 1);
// Parameter factory
lua_pushlightuserdata(L, moony); // @ upvalueindex 1
lua_pushcclosure(L, _lparameter, 1);
lua_setglobal(L, "Parameter");
// Stash factory // Stash factory
lua_pushlightuserdata(L, moony); // @ upvalueindex 1 lua_pushlightuserdata(L, moony); // @ upvalueindex 1
lua_pushcclosure(L, _lstash, 1); lua_pushcclosure(L, _lstash, 1);
......
/*
* Copyright (c) 2015 Hanspeter Portner (dev@open-music-kontrollers.ch)
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the Artistic License 2.0 as published by
* The Perl Foundation.
*
* This source is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Artistic License 2.0 for more details.
*
* You should have received a copy of the Artistic License 2.0
* along the source as a COPYING file. If not, obtain it from
* http://www.perlfoundation.org/artistic_license_2_0.
*/
#include <api_parameter.h>
static int
_lparameter__call(lua_State *L)
{
moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lua_settop(L, 2); // discard superfluous arguments
// 1: self
// 2: value or nil
lua_geti(L, 1, moony->uris.rdf_value);
if(!lua_isnil(L, 2))
{
lua_insert(L, 2);
lua_seti(L, 1, moony->uris.rdf_value);
}
return 1;
}
int
_lparameter(lua_State *L)
{
//moony_t *moony = lua_touserdata(L, lua_upvalueindex(1));
lua_settop(L, 1); // discard superfluous arguments
// o = o or {}
if(lua_isnil(L, 1))
{
lua_pop(L, 1); // nil
lua_newtable(L);
}
// setmetatable(o, self)
luaL_getmetatable(L, "lparameter");
lua_setmetatable(L, -2);
// return o
return 1;
}
const luaL_Reg lparameter_mt [] = {
{"__call", _lparameter__call},
{NULL, NULL}
};
/*
* Copyright (c) 2015 Hanspeter Portner (dev@open-music-kontrollers.ch)
*
* This is free software: you can redistribute it and/or modify
* it under the terms of the Artistic License 2.0 as published by
* The Perl Foundation.
*
* This source is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* Artistic License 2.0 for more details.
*
* You should have received a copy of the Artistic License 2.0
* along the source as a COPYING file. If not, obtain it from
* http://www.perlfoundation.org/artistic_license_2_0.
*/
#ifndef _MOONY_API_PARAMETER_H
#define _MOONY_API_PARAMETER_H
#include <moony.h>
int
_lparameter(lua_State *L);
extern const luaL_Reg lparameter_mt [];
#endif
...@@ -1404,14 +1404,18 @@ do ...@@ -1404,14 +1404,18 @@ do
local flt_get_responded = false local flt_get_responded = false
local flt_set_responded = false local flt_set_responded = false
local state_int = { local state_int = Parameter{
[RDFS.label] = 'Int', [RDFS.label] = 'Int',
[RDFS.range] = Atom.Int, [RDFS.range] = Atom.Int,
[Core.minimum] = 0, [Core.minimum] = 0,
[Core.maximum] = 10, [Core.maximum] = 10,
[RDF.value] = 1 [RDF.value] = 2
} }
assert(state_int() == 2)
assert(state_int(1) == 2)
assert(state_int() == 1)
local state_flt = { local state_flt = {
[RDFS.label] = 'Flt', [RDFS.label] = 'Flt',
[RDFS.range] = Atom.Float, [RDFS.range] = Atom.Float,
......
...@@ -46,7 +46,7 @@ local func = token(l.FUNCTION, word_match{ ...@@ -46,7 +46,7 @@ local func = token(l.FUNCTION, word_match{
'__add', '__sub', '__mul', '__div', '__mod', '__pow', '__unm', '__idiv', '__band', '__bor', '__bxor', '__bnot', '__shl', '__shr', '__concat', '__len', '__eq', '__lt', '__le', '__index', '__newindex', '__call', '__gc', '__mode', '__name', '__tostring', '__metatable', '__pairs', '__add', '__sub', '__mul', '__div', '__mod', '__pow', '__unm', '__idiv', '__band', '__bor', '__bxor', '__bnot', '__shl', '__shr', '__concat', '__len', '__eq', '__lt', '__le', '__index', '__newindex', '__call', '__gc', '__mode', '__name', '__tostring', '__metatable', '__pairs',
-- moony basic -- moony basic
'run', 'once', 'save', 'restore', 'stash', 'apply', 'register', 'midi2cps', 'cps2midi', 'encrypt', 'decrypt', 'run', 'once', 'save', 'restore', 'stash', 'apply', 'register', 'midi2cps', 'cps2midi', 'encrypt', 'decrypt',
'MIDIResponder', 'OSCResponder', 'TimeResponder', 'StateResponder', 'Map', 'Unmap', 'VoiceMap', 'Stash', 'Note', 'HashMap', 'MIDIResponder', 'OSCResponder', 'TimeResponder', 'StateResponder', 'Map', 'Unmap', 'VoiceMap', 'Stash', 'Note', 'HashMap', 'Parameter',
}) })
-- Field funcions -- Field funcions
......
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