Commit 540fcfa9 authored by RIOU Cedric's avatar RIOU Cedric

[plugins] LUA Stimulator: add 'delay(s)' as modifiable setting handled by name

  - example to test settings handling
  - identify 'delay(s)' setting by CIdentifier

[CORE-1249](https://jira.mensiatech.com/browse/CORE-1249)
parent b4a37d00
......@@ -242,7 +242,7 @@ SET(SKIP_DOCUMENTATION "1")
#SET(SKIP_CONTRIB_PLUGINS_PROCESSING_PYTHON "1")
# Skipping demos can speed up compilation a lot, if you don't need them
#SET(SKIP_APPLICATIONS_DEMOS "1")
SET(SKIP_APPLICATIONS_DEMOS "1")
#SET(SKIP_CONTRIB_APPLICATIONS "1")
IF(UNIX)
......
<OpenViBE-Scenario>
<FormatVersion>1</FormatVersion>
<Creator>openvibe</Creator>
<CreatorVersion>2.0</CreatorVersion>
<Creator>OpenVIBE</Creator>
<CreatorVersion>0.4.99</CreatorVersion>
<Settings></Settings>
<Inputs></Inputs>
<Outputs></Outputs>
<Boxes>
<Box>
<Identifier>(0x00007851, 0x00004cd4)</Identifier>
......@@ -91,10 +94,6 @@
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>304.000000</Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa963f5, 0x1a638cd4)</Identifier>
<Value>38</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>480.000000</Value>
......@@ -107,18 +106,10 @@
<Identifier>(0x527ad68d, 0x16d746a0)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xad100179, 0xa3c984ab)</Identifier>
<Value>113</Value>
</Attribute>
<Attribute>
<Identifier>(0xc46b3d00, 0x3e0454e1)</Identifier>
<Value>(0x00000000, 0x00fdd416)</Value>
</Attribute>
<Attribute>
<Identifier>(0xc67a01dc, 0x28ce06c1)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xc73e83ec, 0xf855c5bc)</Identifier>
<Value>false</Value>
......@@ -157,10 +148,6 @@
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>80</Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa963f5, 0x1a638cd4)</Identifier>
<Value>25</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>640</Value>
......@@ -169,10 +156,6 @@
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0x8d89d3b7, 0x8339d210)</Value>
</Attribute>
<Attribute>
<Identifier>(0xad100179, 0xa3c984ab)</Identifier>
<Value>161</Value>
</Attribute>
<Attribute>
<Identifier>(0xc46b3d00, 0x3e0454e1)</Identifier>
<Value>(0x00000000, 0x003bc1b1)</Value>
......@@ -188,8 +171,8 @@
</Attributes>
</Box>
<Box>
<Identifier>(0x2b9fd0aa, 0x64525c3a)</Identifier>
<Name>Mux + 5s delay</Name>
<Identifier>(0x355b6ad7, 0x03c8a962)</Identifier>
<Name>Mux + x s delay</Name>
<AlgorithmClassIdentifier>(0x0b5a2787, 0x02750621)</AlgorithmClassIdentifier>
<Inputs>
<Input>
......@@ -198,7 +181,7 @@
</Input>
<Input>
<TypeIdentifier>(0x6f752dd0, 0x082a321e)</TypeIdentifier>
<Name>New input</Name>
<Name>New input 1</Name>
</Input>
</Inputs>
<Outputs>
......@@ -215,6 +198,13 @@
<Value>${Player_ScenarioDirectory}/scripts/sample-lua-script.lua</Value>
<Modifiability>false</Modifiability>
</Setting>
<Setting>
<TypeIdentifier>(0x79a9edeb, 0x245d83fc)</TypeIdentifier>
<Name>delay(s)</Name>
<DefaultValue>0</DefaultValue>
<Value>0</Value>
<Modifiability>true</Modifiability>
</Setting>
</Settings>
<Attributes>
<Attribute>
......@@ -225,30 +215,18 @@
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>192</Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa963f5, 0x1a638cd4)</Identifier>
<Value>51</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>528</Value>
</Attribute>
<Attribute>
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0xd6e3f48b, 0xbee3523a)</Value>
<Value>(0x554a19f2, 0x55beae1e)</Value>
</Attribute>
<Attribute>
<Identifier>(0x61d11811, 0x71e65362)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xad100179, 0xa3c984ab)</Identifier>
<Value>123</Value>
</Attribute>
<Attribute>
<Identifier>(0xc46b3d00, 0x3e0454e1)</Identifier>
<Value>(0x00000000, 0x05321c99)</Value>
</Attribute>
<Attribute>
<Identifier>(0xc80ce8af, 0xf699f813)</Identifier>
<Value>1</Value>
......@@ -298,10 +276,6 @@
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>80</Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa963f5, 0x1a638cd4)</Identifier>
<Value>25</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>480</Value>
......@@ -310,10 +284,6 @@
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0x27b3ee3c, 0xc50527e6)</Value>
</Attribute>
<Attribute>
<Identifier>(0xad100179, 0xa3c984ab)</Identifier>
<Value>130</Value>
</Attribute>
<Attribute>
<Identifier>(0xc46b3d00, 0x3e0454e1)</Identifier>
<Value>(0x00000000, 0x004737e8)</Value>
......@@ -359,10 +329,6 @@
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>80</Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa963f5, 0x1a638cd4)</Identifier>
<Value>25</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>320</Value>
......@@ -371,10 +337,6 @@
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0x9e5ca01e, 0x30a4d8c3)</Value>
</Attribute>
<Attribute>
<Identifier>(0xad100179, 0xa3c984ab)</Identifier>
<Value>94</Value>
</Attribute>
<Attribute>
<Identifier>(0xc46b3d00, 0x3e0454e1)</Identifier>
<Value>(0x00000000, 0x005a4c5f)</Value>
......@@ -392,120 +354,48 @@
</Boxes>
<Links>
<Link>
<Identifier>(0x000006db, 0x00007628)</Identifier>
<Identifier>(0x00003a74, 0x00007163)</Identifier>
<Source>
<BoxIdentifier>(0x2b9fd0aa, 0x64525c3a)</BoxIdentifier>
<BoxIdentifier>(0x7f12f9f6, 0x1203d055)</BoxIdentifier>
<BoxOutputIndex>0</BoxOutputIndex>
</Source>
<Target>
<BoxIdentifier>(0x00007851, 0x00004cd4)</BoxIdentifier>
<BoxInputIndex>1</BoxInputIndex>
<BoxInputIndex>0</BoxInputIndex>
</Target>
<Attributes>
<Attribute>
<Identifier>(0x1b32c44c, 0x1905e0e9)</Identifier>
<Value>224</Value>
</Attribute>
<Attribute>
<Identifier>(0x358ae8b5, 0x0f8bacd1)</Identifier>
<Value>528</Value>
</Attribute>
<Attribute>
<Identifier>(0x3f0a3b27, 0x570913d2)</Identifier>
<Value>280</Value>
</Attribute>
<Attribute>
<Identifier>(0x6267b5c5, 0x676e3e42)</Identifier>
<Value>480</Value>
</Attribute>
</Attributes>
</Link>
<Link>
<Identifier>(0x00003a74, 0x00007163)</Identifier>
<Identifier>(0x17d3cbbf, 0x33f91f67)</Identifier>
<Source>
<BoxIdentifier>(0x7f12f9f6, 0x1203d055)</BoxIdentifier>
<BoxIdentifier>(0x44d592ef, 0x79906895)</BoxIdentifier>
<BoxOutputIndex>0</BoxOutputIndex>
</Source>
<Target>
<BoxIdentifier>(0x00007851, 0x00004cd4)</BoxIdentifier>
<BoxIdentifier>(0x355b6ad7, 0x03c8a962)</BoxIdentifier>
<BoxInputIndex>0</BoxInputIndex>
</Target>
<Attributes>
<Attribute>
<Identifier>(0x1b32c44c, 0x1905e0e9)</Identifier>
<Value>99</Value>
</Attribute>
<Attribute>
<Identifier>(0x358ae8b5, 0x0f8bacd1)</Identifier>
<Value>320</Value>
</Attribute>
<Attribute>
<Identifier>(0x3f0a3b27, 0x570913d2)</Identifier>
<Value>280</Value>
</Attribute>
<Attribute>
<Identifier>(0x6267b5c5, 0x676e3e42)</Identifier>
<Value>465</Value>
</Attribute>
</Attributes>
</Link>
<Link>
<Identifier>(0x11bc52c7, 0x7d39e76b)</Identifier>
<Identifier>(0x568acc3e, 0x7715f607)</Identifier>
<Source>
<BoxIdentifier>(0x44d592ef, 0x79906895)</BoxIdentifier>
<BoxIdentifier>(0x355b6ad7, 0x03c8a962)</BoxIdentifier>
<BoxOutputIndex>0</BoxOutputIndex>
</Source>
<Target>
<BoxIdentifier>(0x2b9fd0aa, 0x64525c3a)</BoxIdentifier>
<BoxInputIndex>0</BoxInputIndex>
<BoxIdentifier>(0x00007851, 0x00004cd4)</BoxIdentifier>
<BoxInputIndex>1</BoxInputIndex>
</Target>
<Attributes>
<Attribute>
<Identifier>(0x1b32c44c, 0x1905e0e9)</Identifier>
<Value>99</Value>
</Attribute>
<Attribute>
<Identifier>(0x358ae8b5, 0x0f8bacd1)</Identifier>
<Value>480</Value>
</Attribute>
<Attribute>
<Identifier>(0x3f0a3b27, 0x570913d2)</Identifier>
<Value>162</Value>
</Attribute>
<Attribute>
<Identifier>(0x6267b5c5, 0x676e3e42)</Identifier>
<Value>520</Value>
</Attribute>
</Attributes>
</Link>
<Link>
<Identifier>(0x68865d3e, 0x16e4e1af)</Identifier>
<Identifier>(0x78a4b36e, 0x69746b88)</Identifier>
<Source>
<BoxIdentifier>(0x0f152388, 0x4bae9e07)</BoxIdentifier>
<BoxOutputIndex>0</BoxOutputIndex>
</Source>
<Target>
<BoxIdentifier>(0x2b9fd0aa, 0x64525c3a)</BoxIdentifier>
<BoxIdentifier>(0x355b6ad7, 0x03c8a962)</BoxIdentifier>
<BoxInputIndex>1</BoxInputIndex>
</Target>
<Attributes>
<Attribute>
<Identifier>(0x1b32c44c, 0x1905e0e9)</Identifier>
<Value>99</Value>
</Attribute>
<Attribute>
<Identifier>(0x358ae8b5, 0x0f8bacd1)</Identifier>
<Value>640</Value>
</Attribute>
<Attribute>
<Identifier>(0x3f0a3b27, 0x570913d2)</Identifier>
<Value>162</Value>
</Attribute>
<Attribute>
<Identifier>(0x6267b5c5, 0x676e3e42)</Identifier>
<Value>535</Value>
</Attribute>
</Attributes>
</Link>
</Links>
<Comments>
......@@ -521,7 +411,7 @@ boxes. Each muxed stimulation is delayed by 5 seconds.</Text>
</Attribute>
<Attribute>
<Identifier>(0x7234b86b, 0x2b8651a5)</Identifier>
<Value>192</Value>
<Value>272</Value>
</Attribute>
</Attributes>
</Comment>
......@@ -544,7 +434,49 @@ boxes. Each muxed stimulation is delayed by 5 seconds.</Text>
<Entry>
<Identifier>(0x0000775c, 0x000078ff)</Identifier>
<Type>(0x3bcce5d2, 0x43f2d968)</Type>
<Data>[{"boxIdentifier":"(0x00007851, 0x00004cd4)","childCount":0,"identifier":"(0x000036ad, 0x00006f70)","index":0,"parentIdentifier":"(0xffffffff, 0xffffffff)","type":3},{"boxIdentifier":"(0x0f152388, 0x4bae9e07)","childCount":0,"identifier":"(0x06ca0825, 0x1209828e)","index":0,"parentIdentifier":"(0xffffffff, 0xffffffff)","type":3},{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":1,"height":400,"identifier":"(0x492edea0, 0x7fcf1a84)","index":0,"name":"Default window","parentIdentifier":"(0xffffffff, 0xffffffff)","type":1,"width":400},{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":1,"identifier":"(0x333b0470, 0x69c97194)","index":0,"name":"Default tab","parentIdentifier":"(0x492edea0, 0x7fcf1a84)","type":2},{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":0,"identifier":"(0x36539222, 0x0801778f)","index":0,"name":"Empty","parentIdentifier":"(0x333b0470, 0x69c97194)","type":0}]</Data>
<Data>[{"boxIdentifier":"(0x0f152388, 0x4bae9e07)","childCount":0,"identifier":"(0x06ca0825, 0x1209828e)","parentIdentifier":"(0xffffffff, 0xffffffff)","type":3},{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":1,"height":555,"identifier":"(0x492edea0, 0x7fcf1a84)","name":"Default window","parentIdentifier":"(0xffffffff, 0xffffffff)","type":1,"width":419},{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":1,"identifier":"(0x333b0470, 0x69c97194)","index":0,"name":"Default tab","parentIdentifier":"(0x492edea0, 0x7fcf1a84)","type":2},{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":2,"dividerPosition":250,"identifier":"(0x1f748c73, 0x252e99ac)","index":0,"maxDividerPosition":505,"name":"Vertical split","parentIdentifier":"(0x333b0470, 0x69c97194)","type":4},{"boxIdentifier":"(0x355b6ad7, 0x03c8a962)","childCount":0,"identifier":"(0x5b05acb5, 0x422751a8)","index":0,"parentIdentifier":"(0x1f748c73, 0x252e99ac)","type":3},{"boxIdentifier":"(0x00007851, 0x00004cd4)","childCount":0,"identifier":"(0x000036ad, 0x00006f70)","index":1,"parentIdentifier":"(0x1f748c73, 0x252e99ac)","type":3}]</Data>
</Entry>
</Metadata>
<Attributes>
<Attribute>
<Identifier>(0x079d1f09, 0x667c7871)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x60bc58ab, 0x7a1b4d83)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x790d75b8, 0x3bb90c33)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x7a3a1558, 0xf12c63c2)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x84009d7c, 0x3c4e763b)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x8c1fc55b, 0x7b433dc2)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x9f5c4075, 0x4a0d3666)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xf36a1567, 0xd13c53da)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xf6b2e3fa, 0x7bd43926)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xf8034a49, 0x8b3f37cc)</Identifier>
<Value></Value>
</Attribute>
</Attributes>
</OpenViBE-Scenario>
\ No newline at end of file
......@@ -48,7 +48,7 @@ function process(box)
box:remove_stimulation(input, 1)
-- triggers a new OVTK_StimulationId_Label_00 stimulation five seconds after
box:send_stimulation(1, OVTK_StimulationId_Label_00, t+5, 0)
box:send_stimulation(1, OVTK_StimulationId_Label_00, t+box:get_setting_by_name("delay(s)"), 0)
end
end
......
......@@ -163,6 +163,19 @@ static int lua_get_setting_cb(lua_State* pState)
return 1;
}
static int lua_get_setting_by_name_cb(lua_State* pState)
{
CString l_sSetting;
CBoxAlgorithmLuaStimulator* l_pThis=static_cast < CBoxAlgorithmLuaStimulator* >(lua_touserdata(pState, lua_upvalueindex(1)));
__CB_Assert__(l_pThis != NULL);
if(!lua_check_argument_count(pState, "get_setting_by_name", 1)) return 0;
__CB_Assert__(l_pThis->getSettingCB(lua_tostring(pState, 2), l_sSetting));
lua_pushstring(pState, l_sSetting.toASCIIString());
return 1;
}
static int lua_get_config_cb(lua_State* pState)
{
CString l_sConfiguration;
......@@ -401,6 +414,7 @@ boolean CBoxAlgorithmLuaStimulator::initialize(void)
lua_setcallback(m_pLuaState, "get_output_count", ::lua_get_output_count_cb, this);
lua_setcallback(m_pLuaState, "get_setting_count", ::lua_get_setting_count_cb, this);
lua_setcallback(m_pLuaState, "get_setting", ::lua_get_setting_cb, this);
lua_setcallback(m_pLuaState, "get_setting_by_name", ::lua_get_setting_by_name_cb, this);
lua_setcallback(m_pLuaState, "get_config", ::lua_get_config_cb, this);
lua_setcallback(m_pLuaState, "get_current_time", ::lua_get_current_time_cb, this);
lua_setcallback(m_pLuaState, "sleep", ::lua_sleep_cb, this);
......@@ -753,6 +767,26 @@ boolean CBoxAlgorithmLuaStimulator::getSettingCountCB(uint32& rui32Count)
return true;
}
boolean CBoxAlgorithmLuaStimulator::getSettingCB(const CString& rsName, CString& rsSetting)
{
char *pEnd;
if(!this->getStaticBoxContext().getSettingValue(rsName, rsSetting))
{
this->getLogManager() << LogLevel_Warning << "Setting " << rsName << " does not exist\n";
rsSetting=CString("");
return true;
}
rsSetting = CString(std::to_string(std::strtol(rsSetting.toASCIIString(),&pEnd,10)).c_str());
// catch non numeric value
if(*pEnd)
{
// conversion has failed
this->getStaticBoxContext().getSettingDefaultValue(rsName,rsSetting);
this->getLogManager() << LogLevel_Warning << "Bad value for setting '" << rsName << "'. Use default value: " << rsSetting << "\n";
}
return true;
}
boolean CBoxAlgorithmLuaStimulator::getSettingCB(uint32 ui32SettingIndex, CString& rsSetting)
{
if(ui32SettingIndex >= this->getStaticBoxContext().getSettingCount())
......
......@@ -16,6 +16,10 @@
#include <cstdio>
#include <cstring>
#include <openvibe/ov_all.h>
#include <toolkit/ovtk_all.h>
#include <visualization-toolkit/ovviz_all.h>
extern "C"
{
#include "lua.h"
......@@ -27,8 +31,10 @@ extern "C"
// - please move the identifier definitions in ovp_defines.h
// - please include your desciptor in ovp_main.cpp
#define OVP_ClassId_BoxAlgorithm_LuaStimulator OpenViBE::CIdentifier(0x0B5A2787, 0x02750621)
#define OVP_ClassId_BoxAlgorithm_LuaStimulatorDesc OpenViBE::CIdentifier(0x67AF36F3, 0x2B424F46)
#define OVP_ClassId_BoxAlgorithm_LuaStimulator OpenViBE::CIdentifier(0x0B5A2787, 0x02750621)
#define OVP_ClassId_BoxAlgorithm_LuaStimulatorDesc OpenViBE::CIdentifier(0x67AF36F3, 0x2B424F46)
#define OVP_ClassId_BoxAlgorithm_Setting_Delay_Seconds OpenViBE::CIdentifier(0x646836F3, 0x2A5624F46)
namespace OpenViBEPlugins
{
......@@ -58,6 +64,7 @@ namespace OpenViBEPlugins
virtual OpenViBE::boolean getOutputCountCB(OpenViBE::uint32& rui64Count);
virtual OpenViBE::boolean getSettingCountCB(OpenViBE::uint32& rui64Count);
virtual OpenViBE::boolean getSettingCB(OpenViBE::uint32 ui32SettingIndex, OpenViBE::CString& rsSetting);
virtual OpenViBE::boolean getSettingCB(const OpenViBE::CString& rsName, OpenViBE::CString& rsSetting);
virtual OpenViBE::boolean getConfigCB(const OpenViBE::CString& rsString, OpenViBE::CString& rsConfig);
virtual OpenViBE::boolean getCurrentTimeCB(OpenViBE::uint64& rui64Time);
......@@ -162,12 +169,18 @@ namespace OpenViBEPlugins
virtual OpenViBE::Plugins::IBoxListener* createBoxListener(void) const { return new CBoxAlgorithmLuaStimulatorListener; }
virtual void releaseBoxListener(OpenViBE::Plugins::IBoxListener* pBoxListener) const { delete pBoxListener; }
virtual bool hasFunctionality(OpenViBE::CIdentifier functionalityIdentifier) const
{
return functionalityIdentifier == OVD_Functionality_Visualization;
}
virtual OpenViBE::boolean getBoxPrototype(
OpenViBE::Kernel::IBoxProto& rBoxAlgorithmPrototype) const
{
rBoxAlgorithmPrototype.addOutput ("Stimulations", OV_TypeId_Stimulations);
rBoxAlgorithmPrototype.addSetting("Lua Script", OV_TypeId_Script, "");
rBoxAlgorithmPrototype.addSetting("delay(s)", OV_TypeId_String, "0", false, OVP_ClassId_BoxAlgorithm_Setting_Delay_Seconds);
rBoxAlgorithmPrototype.addFlag (OpenViBE::Kernel::BoxFlag_CanAddOutput);
rBoxAlgorithmPrototype.addFlag (OpenViBE::Kernel::BoxFlag_CanAddInput);
......
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