This commit is contained in:
2021-10-14 13:47:35 +02:00
commit 6625a8dfaa
4026 changed files with 844291 additions and 0 deletions
@@ -0,0 +1,36 @@
PROJECT(openvibe-plugins-contrib-python2)
SET(PROJECT_VERSION_MAJOR ${OV_GLOBAL_VERSION_MAJOR})
SET(PROJECT_VERSION ${OV_GLOBAL_VERSION_STRING})
FILE(GLOB_RECURSE SRC_FILES src/*.cpp src/*.h src/*.inl)
ADD_LIBRARY(${PROJECT_NAME} SHARED ${SRC_FILES})
SET_TARGET_PROPERTIES(${PROJECT_NAME} PROPERTIES
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}
FOLDER ${PLUGINS_FOLDER}
COMPILE_FLAGS "-DOVP_Exports -DOVP_Shared")
# -----------------------------
INCLUDE("FindOpenViBE")
INCLUDE("FindOpenViBECommon")
INCLUDE("FindOpenViBEToolkit")
INCLUDE("FindOpenViBEModuleEBML")
INCLUDE("FindThirdPartyBoost")
INCLUDE("FindThirdPartyPython2")
# -----------------------------
# Install files
# -----------------------------
INSTALL(TARGETS ${PROJECT_NAME}
RUNTIME DESTINATION ${DIST_BINDIR}
LIBRARY DESTINATION ${DIST_LIBDIR}
ARCHIVE DESTINATION ${DIST_LIBDIR})
IF(WIN32)
# The pygame scenario doesn't work on Windows, so do not install it
INSTALL(DIRECTORY box-tutorials DESTINATION ${DIST_DATADIR}/openvibe/scenarios/ PATTERN "*-pygame-*" EXCLUDE)
ELSE()
INSTALL(DIRECTORY box-tutorials DESTINATION ${DIST_DATADIR}/openvibe/scenarios/)
ENDIF()
INSTALL(DIRECTORY share/ DESTINATION ${DIST_DATADIR}/openvibe/plugins/python2)
@@ -0,0 +1,119 @@
<OpenViBE-Scenario>
<FormatVersion>1</FormatVersion>
<Creator>openvibe</Creator>
<CreatorVersion>2.0</CreatorVersion>
<Boxes>
<Box>
<Identifier>(0x00003954, 0x000010bb)</Identifier>
<Name>Hello World!</Name>
<AlgorithmClassIdentifier>(0x5dc4f669, 0xd3fd4d64)</AlgorithmClassIdentifier>
<Settings>
<Setting>
<TypeIdentifier>(0x007deef9, 0x2f3e95c6)</TypeIdentifier>
<Name>Clock frequency (Hz)</Name>
<DefaultValue>60</DefaultValue>
<Value>1</Value>
<Modifiability>false</Modifiability>
</Setting>
<Setting>
<TypeIdentifier>(0xb0d0db45, 0x49cbc34a)</TypeIdentifier>
<Name>Script</Name>
<DefaultValue></DefaultValue>
<Value>${Player_ScenarioDirectory}/scripts/python-hello-world.py</Value>
<Modifiability>false</Modifiability>
</Setting>
<Setting>
<TypeIdentifier>(0x79a9edeb, 0x245d83fc)</TypeIdentifier>
<Name>Message</Name>
<DefaultValue>Hello World!</DefaultValue>
<Value>Hello World!</Value>
<Modifiability>false</Modifiability>
</Setting>
</Settings>
<Attributes>
<Attribute>
<Identifier>(0x17ee7c08, 0x94c14893)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>304</Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa963f5, 0x1a638cd4)</Identifier>
<Value>51</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>176</Value>
</Attribute>
<Attribute>
<Identifier>(0x30a4e5c9, 0x83502953)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0x2a651510, 0xb4fad0d4)</Value>
</Attribute>
<Attribute>
<Identifier>(0x527ad68d, 0x16d746a0)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x61d11811, 0x71e65362)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xad100179, 0xa3c984ab)</Identifier>
<Value>101</Value>
</Attribute>
<Attribute>
<Identifier>(0xc67a01dc, 0x28ce06c1)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xce18836a, 0x9c0eb403)</Identifier>
<Value>2</Value>
</Attribute>
<Attribute>
<Identifier>(0xf191c1c8, 0xa0123976)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xfba64161, 0x65304e21)</Identifier>
<Value></Value>
</Attribute>
</Attributes>
</Box>
</Boxes>
<Links></Links>
<Comments>
<Comment>
<Identifier>(0x000047c8, 0x000050cf)</Identifier>
<Text>&lt;b&gt;Hello World!&lt;/b&gt;
Prints a friendly message.
You can customize the message by editing
the box configuration.
</Text>
<Attributes>
<Attribute>
<Identifier>(0x473d9a43, 0x97fc0a97)</Identifier>
<Value>-80</Value>
</Attribute>
<Attribute>
<Identifier>(0x7234b86b, 0x2b8651a5)</Identifier>
<Value>304</Value>
</Attribute>
</Attributes>
</Comment>
</Comments>
<Metadata>
<Entry>
<Identifier>(0x0000775c, 0x000078ff)</Identifier>
<Type>(0x3bcce5d2, 0x43f2d968)</Type>
<Data>[{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":1,"height":507,"identifier":"(0x00003962, 0x00000a21)","index":0,"name":"Default window","parentIdentifier":"(0xffffffff, 0xffffffff)","type":1,"width":798},{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":1,"identifier":"(0x0000781e, 0x00004e65)","index":0,"name":"Default tab","parentIdentifier":"(0x00003962, 0x00000a21)","type":2},{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":0,"identifier":"(0x00006808, 0x00000e28)","index":0,"name":"Empty","parentIdentifier":"(0x0000781e, 0x00004e65)","type":0}]</Data>
</Entry>
</Metadata>
</OpenViBE-Scenario>
@@ -0,0 +1,215 @@
<OpenViBE-Scenario>
<FormatVersion>1</FormatVersion>
<Creator>openvibe</Creator>
<CreatorVersion>2.0</CreatorVersion>
<Boxes>
<Box>
<Identifier>(0x00004db4, 0x00006a35)</Identifier>
<Name>Python 2 scripting</Name>
<AlgorithmClassIdentifier>(0x5dc4f669, 0xd3fd4d64)</AlgorithmClassIdentifier>
<Inputs>
<Input>
<TypeIdentifier>(0x6f752dd0, 0x082a321e)</TypeIdentifier>
<Name>New input</Name>
</Input>
</Inputs>
<Settings>
<Setting>
<TypeIdentifier>(0x007deef9, 0x2f3e95c6)</TypeIdentifier>
<Name>Clock frequency (Hz)</Name>
<DefaultValue>64</DefaultValue>
<Value>64</Value>
<Modifiability>false</Modifiability>
</Setting>
<Setting>
<TypeIdentifier>(0xb0d0db45, 0x49cbc34a)</TypeIdentifier>
<Name>Script</Name>
<DefaultValue></DefaultValue>
<Value>${Player_ScenarioDirectory}/scripts/python-print-stimulations.py</Value>
<Modifiability>false</Modifiability>
</Setting>
</Settings>
<Attributes>
<Attribute>
<Identifier>(0x17ee7c08, 0x94c14893)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>128.000000</Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa963f5, 0x1a638cd4)</Identifier>
<Value>33</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>400.000000</Value>
</Attribute>
<Attribute>
<Identifier>(0x30a4e5c9, 0x83502953)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0x2a651510, 0xb4fad0d4)</Value>
</Attribute>
<Attribute>
<Identifier>(0x527ad68d, 0x16d746a0)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x61d11811, 0x71e65362)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xad100179, 0xa3c984ab)</Identifier>
<Value>114</Value>
</Attribute>
<Attribute>
<Identifier>(0xc46b3d00, 0x3e0454e1)</Identifier>
<Value>(0x00000000, 0x05874423)</Value>
</Attribute>
<Attribute>
<Identifier>(0xc73e83ec, 0xf855c5bc)</Identifier>
<Value>false</Value>
</Attribute>
<Attribute>
<Identifier>(0xce18836a, 0x9c0eb403)</Identifier>
<Value>2</Value>
</Attribute>
<Attribute>
<Identifier>(0xf191c1c8, 0xa0123976)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xfba64161, 0x65304e21)</Identifier>
<Value></Value>
</Attribute>
</Attributes>
</Box>
<Box>
<Identifier>(0x00005777, 0x00006c19)</Identifier>
<Name>Clock stimulator</Name>
<AlgorithmClassIdentifier>(0x4f756d3f, 0x29ff0b96)</AlgorithmClassIdentifier>
<Outputs>
<Output>
<TypeIdentifier>(0x6f752dd0, 0x082a321e)</TypeIdentifier>
<Name>Generated stimulations</Name>
</Output>
</Outputs>
<Settings>
<Setting>
<TypeIdentifier>(0x512a166f, 0x5c3ef83f)</TypeIdentifier>
<Name>Interstimulation interval (in sec)</Name>
<DefaultValue>1.0</DefaultValue>
<Value>1.0</Value>
<Modifiability>false</Modifiability>
</Setting>
<Setting>
<TypeIdentifier>(0x2c132d6e, 0x44ab0d97)</TypeIdentifier>
<Name>Stimulation</Name>
<DefaultValue>OVTK_StimulationId_Label_00</DefaultValue>
<Value>OVTK_StimulationId_Label_00</Value>
<Modifiability>false</Modifiability>
</Setting>
</Settings>
<Attributes>
<Attribute>
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>48.000000</Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa963f5, 0x1a638cd4)</Identifier>
<Value>23</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>400.000000</Value>
</Attribute>
<Attribute>
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0x27b3ee3c, 0xc50527e6)</Value>
</Attribute>
<Attribute>
<Identifier>(0xad100179, 0xa3c984ab)</Identifier>
<Value>114</Value>
</Attribute>
<Attribute>
<Identifier>(0xc46b3d00, 0x3e0454e1)</Identifier>
<Value>(0x00000000, 0x0062599e)</Value>
</Attribute>
<Attribute>
<Identifier>(0xc73e83ec, 0xf855c5bc)</Identifier>
<Value>false</Value>
</Attribute>
<Attribute>
<Identifier>(0xc80ce8af, 0xf699f813)</Identifier>
<Value>1</Value>
</Attribute>
<Attribute>
<Identifier>(0xce18836a, 0x9c0eb403)</Identifier>
<Value>2</Value>
</Attribute>
</Attributes>
</Box>
</Boxes>
<Links>
<Link>
<Identifier>(0x0000412b, 0x00003ac4)</Identifier>
<Source>
<BoxIdentifier>(0x00005777, 0x00006c19)</BoxIdentifier>
<BoxOutputIndex>0</BoxOutputIndex>
</Source>
<Target>
<BoxIdentifier>(0x00004db4, 0x00006a35)</BoxIdentifier>
<BoxInputIndex>0</BoxInputIndex>
</Target>
<Attributes>
<Attribute>
<Identifier>(0x1b32c44c, 0x1905e0e9)</Identifier>
<Value>66</Value>
</Attribute>
<Attribute>
<Identifier>(0x358ae8b5, 0x0f8bacd1)</Identifier>
<Value>400</Value>
</Attribute>
<Attribute>
<Identifier>(0x3f0a3b27, 0x570913d2)</Identifier>
<Value>107</Value>
</Attribute>
<Attribute>
<Identifier>(0x6267b5c5, 0x676e3e42)</Identifier>
<Value>400</Value>
</Attribute>
</Attributes>
</Link>
</Links>
<Comments>
<Comment>
<Identifier>(0x00003cb4, 0x00004c5e)</Identifier>
<Text>The clock stimulator generates
1 stim per second.
The associated python script should
print all the received stimulations.</Text>
<Attributes>
<Attribute>
<Identifier>(0x473d9a43, 0x97fc0a97)</Identifier>
<Value>640.000000</Value>
</Attribute>
<Attribute>
<Identifier>(0x7234b86b, 0x2b8651a5)</Identifier>
<Value>96.000000</Value>
</Attribute>
</Attributes>
</Comment>
</Comments>
<Metadata>
<Entry>
<Identifier>(0x0000775c, 0x000078ff)</Identifier>
<Type>(0x3bcce5d2, 0x43f2d968)</Type>
<Data>[{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":1,"height":1,"identifier":"(0x000051c6, 0x0000403f)","index":0,"name":"Default window","parentIdentifier":"(0xffffffff, 0xffffffff)","type":1,"width":1},{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":1,"identifier":"(0x00006099, 0x00001a73)","index":0,"name":"Default tab","parentIdentifier":"(0x000051c6, 0x0000403f)","type":2},{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":0,"identifier":"(0x00004197, 0x00001dca)","index":0,"name":"Empty","parentIdentifier":"(0x00006099, 0x00001a73)","type":0}]</Data>
</Entry>
</Metadata>
</OpenViBE-Scenario>
@@ -0,0 +1,276 @@
<OpenViBE-Scenario>
<FormatVersion>1</FormatVersion>
<Creator>OpenVIBE</Creator>
<CreatorVersion>0.2.99</CreatorVersion>
<Settings></Settings>
<Inputs></Inputs>
<Outputs></Outputs>
<Boxes>
<Box>
<Identifier>(0x441e2100, 0x610e711c)</Identifier>
<Name>Multiprocessing</Name>
<AlgorithmClassIdentifier>(0x5dc4f669, 0xd3fd4d64)</AlgorithmClassIdentifier>
<Settings>
<Setting>
<TypeIdentifier>(0x007deef9, 0x2f3e95c6)</TypeIdentifier>
<Name>Clock frequency (Hz)</Name>
<DefaultValue>60</DefaultValue>
<Value>4</Value>
<Modifiability>false</Modifiability>
</Setting>
<Setting>
<TypeIdentifier>(0xb0d0db45, 0x49cbc34a)</TypeIdentifier>
<Name>Script</Name>
<DefaultValue></DefaultValue>
<Value>${Player_ScenarioDirectory}/scripts/python-multiprocessing.py</Value>
<Modifiability>false</Modifiability>
</Setting>
</Settings>
<Attributes>
<Attribute>
<Identifier>(0x17ee7c08, 0x94c14893)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>224</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>256</Value>
</Attribute>
<Attribute>
<Identifier>(0x30a4e5c9, 0x83502953)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0x2a651510, 0xb4fad0d4)</Value>
</Attribute>
<Attribute>
<Identifier>(0x527ad68d, 0x16d746a0)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x61d11811, 0x71e65362)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xce18836a, 0x9c0eb403)</Identifier>
<Value>2</Value>
</Attribute>
<Attribute>
<Identifier>(0xf191c1c8, 0xa0123976)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xfba64161, 0x65304e21)</Identifier>
<Value></Value>
</Attribute>
</Attributes>
</Box>
<Box>
<Identifier>(0x47008917, 0x4f6a4317)</Identifier>
<Name>Moving circle</Name>
<AlgorithmClassIdentifier>(0x5dc4f669, 0xd3fd4d64)</AlgorithmClassIdentifier>
<Settings>
<Setting>
<TypeIdentifier>(0x007deef9, 0x2f3e95c6)</TypeIdentifier>
<Name>Clock frequency (Hz)</Name>
<DefaultValue>60</DefaultValue>
<Value>4</Value>
<Modifiability>false</Modifiability>
</Setting>
<Setting>
<TypeIdentifier>(0xb0d0db45, 0x49cbc34a)</TypeIdentifier>
<Name>Script</Name>
<DefaultValue></DefaultValue>
<Value>${Player_ScenarioDirectory}/scripts/python-moving-circle.py</Value>
<Modifiability>false</Modifiability>
</Setting>
</Settings>
<Attributes>
<Attribute>
<Identifier>(0x17ee7c08, 0x94c14893)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>352</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>256</Value>
</Attribute>
<Attribute>
<Identifier>(0x30a4e5c9, 0x83502953)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0x2a651510, 0xb4fad0d4)</Value>
</Attribute>
<Attribute>
<Identifier>(0x527ad68d, 0x16d746a0)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x61d11811, 0x71e65362)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xce18836a, 0x9c0eb403)</Identifier>
<Value>2</Value>
</Attribute>
<Attribute>
<Identifier>(0xf191c1c8, 0xa0123976)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xfba64161, 0x65304e21)</Identifier>
<Value></Value>
</Attribute>
</Attributes>
</Box>
<Box>
<Identifier>(0x51f53da2, 0x789994d2)</Identifier>
<Name>Star field</Name>
<AlgorithmClassIdentifier>(0x5dc4f669, 0xd3fd4d64)</AlgorithmClassIdentifier>
<Settings>
<Setting>
<TypeIdentifier>(0x007deef9, 0x2f3e95c6)</TypeIdentifier>
<Name>Clock frequency (Hz)</Name>
<DefaultValue>60</DefaultValue>
<Value>4</Value>
<Modifiability>false</Modifiability>
</Setting>
<Setting>
<TypeIdentifier>(0xb0d0db45, 0x49cbc34a)</TypeIdentifier>
<Name>Script</Name>
<DefaultValue></DefaultValue>
<Value>${Player_ScenarioDirectory}/scripts/python-star-field.py</Value>
<Modifiability>false</Modifiability>
</Setting>
</Settings>
<Attributes>
<Attribute>
<Identifier>(0x17ee7c08, 0x94c14893)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x1fa7a38f, 0x54edbe0b)</Identifier>
<Value>416</Value>
</Attribute>
<Attribute>
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
<Value>256</Value>
</Attribute>
<Attribute>
<Identifier>(0x30a4e5c9, 0x83502953)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
<Value>(0x2a651510, 0xb4fad0d4)</Value>
</Attribute>
<Attribute>
<Identifier>(0x527ad68d, 0x16d746a0)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0x61d11811, 0x71e65362)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xce18836a, 0x9c0eb403)</Identifier>
<Value>2</Value>
</Attribute>
<Attribute>
<Identifier>(0xf191c1c8, 0xa0123976)</Identifier>
<Value></Value>
</Attribute>
<Attribute>
<Identifier>(0xfba64161, 0x65304e21)</Identifier>
<Value></Value>
</Attribute>
</Attributes>
</Box>
</Boxes>
<Links></Links>
<Comments>
<Comment>
<Identifier>(0x0ad104c8, 0x2ee0799b)</Identifier>
<Text>&lt;big&gt;Do not forget to look at the python scripts used
in all of the python boxes in this scenario.&lt;/big&gt;</Text>
<Attributes>
<Attribute>
<Identifier>(0x473d9a43, 0x97fc0a97)</Identifier>
<Value>368</Value>
</Attribute>
<Attribute>
<Identifier>(0x7234b86b, 0x2b8651a5)</Identifier>
<Value>-32</Value>
</Attribute>
</Attributes>
</Comment>
<Comment>
<Identifier>(0x4e7de8aa, 0x561bc220)</Identifier>
<Text>&lt;b&gt;Multiprocessing&lt;/b&gt;
Creates a new processus
which works in the background.</Text>
<Attributes>
<Attribute>
<Identifier>(0x473d9a43, 0x97fc0a97)</Identifier>
<Value>480</Value>
</Attribute>
<Attribute>
<Identifier>(0x7234b86b, 0x2b8651a5)</Identifier>
<Value>224</Value>
</Attribute>
</Attributes>
</Comment>
<Comment>
<Identifier>(0x6bfbf8ad, 0x3b970ba1)</Identifier>
<Text>&lt;b&gt;Moving Circle&lt;/b&gt; and &lt;b&gt;Starfield&lt;/b&gt;
These two scripts illustrate running
several instances of pygame at
the same time.</Text>
<Attributes>
<Attribute>
<Identifier>(0x473d9a43, 0x97fc0a97)</Identifier>
<Value>496</Value>
</Attribute>
<Attribute>
<Identifier>(0x7234b86b, 0x2b8651a5)</Identifier>
<Value>384</Value>
</Attribute>
</Attributes>
</Comment>
<Comment>
<Identifier>(0x704b39c7, 0x74448e12)</Identifier>
<Text>&lt;big&gt;&lt;b&gt;&lt;span color="red"&gt;Warning&lt;/span&gt;&lt;/b&gt;&lt;/big&gt;
For the time being multiprocessing and pygame only work
on &lt;b&gt;Linux&lt;/b&gt; operating system provided &lt;span color="red"&gt;you have installed &lt;i&gt;pygame&lt;/i&gt; module&lt;/span&gt; in Python.</Text>
<Attributes>
<Attribute>
<Identifier>(0x473d9a43, 0x97fc0a97)</Identifier>
<Value>368</Value>
</Attribute>
<Attribute>
<Identifier>(0x7234b86b, 0x2b8651a5)</Identifier>
<Value>80</Value>
</Attribute>
</Attributes>
</Comment>
</Comments>
<Metadata>
<Entry>
<Identifier>(0x0000775c, 0x000078ff)</Identifier>
<Type>(0x3bcce5d2, 0x43f2d968)</Type>
<Data>[{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":1,"height":1,"identifier":"(0x71777b71, 0x7d9b955c)","name":"Default window","parentIdentifier":"(0xffffffff, 0xffffffff)","type":1,"width":1},{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":1,"identifier":"(0x3587c6af, 0x788f3c37)","index":0,"name":"Default tab","parentIdentifier":"(0x71777b71, 0x7d9b955c)","type":2},{"boxIdentifier":"(0xffffffff, 0xffffffff)","childCount":0,"identifier":"(0x5aab9723, 0x14698840)","index":0,"name":"Empty","parentIdentifier":"(0x3587c6af, 0x788f3c37)","type":0}]</Data>
</Entry>
</Metadata>
</OpenViBE-Scenario>
@@ -0,0 +1,31 @@
# We construct a box instance that inherits from the basic OVBox class
class MyOVBox(OVBox):
# the constructor creates the box and initializes object variables
def __init__(self):
OVBox.__init__(self)
self.stimLabel = None
self.stimCode = None
# the initialize method reads settings and outputs the first header
def initialize(self):
# the stim label is taken from the box setting
self.stimLabel = self.setting['Stimulation']
# we get the corresponding code using the OpenViBE_stimulation dictionnary
self.stimCode = OpenViBE_stimulation[self.stimLabel]
# we append to the box output a stimulation header. This is just a header, dates are 0.
self.output[0].append(OVStimulationHeader(0., 0.))
def process(self):
# During each process call we produce a stimulation
# A stimulation set is a chunk which starts at current time and end time is the time step between two calls
stimSet = OVStimulationSet(self.getCurrentTime(), self.getCurrentTime()+1./self.getClock())
# the date of the stimulation is simply the current openvibe time when calling the box process
stimSet.append(OVStimulation(self.stimCode, self.getCurrentTime(), 0.))
self.output[0].append(stimSet)
def uninitialize(self):
# we send a stream end.
end = self.getCurrentTime()
self.output[0].append(OVStimulationEnd(end, end))
box = MyOVBox()
@@ -0,0 +1,19 @@
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
def initialize(self):
# nop
return
def process(self):
# print the string specified in the box configuration.
# 'Message' is the name of the config entry.
print(self.setting['Message'])
def uninitialize(self):
# nop
return
box = MyOVBox()
@@ -0,0 +1,80 @@
from multiprocessing import Process, Event
import time
import pygame
from pygame.locals import *
import math
from random import randint, randrange
import sys
sys.argv = ['openvibe']
class OVProcess(Process):
def __init__(self):
Process.__init__(self)
self.initialized = Event()
self.stop_asked = Event()
def initialize(self):
pass
def process(self):
pass
def uninitialize(self):
pass
def stop(self):
self.stop_asked.set()
def run(self):
self.initialize()
self.initialized.set()
while not self.stop_asked.is_set():
self.process()
self.uninitialize()
class MovingCircle(OVProcess):
def __init__(self):
OVProcess.__init__(self)
self.screen = None
self.pos = [320,240]
self.speed = 5
self.dirx = -self.speed
self.diry = -self.speed
def initialize(self):
pygame.init()
pygame.display.set_caption(self.name)
self.screen = pygame.display.set_mode((640,480),0,32)
def process(self):
begining = time.time()
self.pos[0] += self.dirx
self.pos[1] += self.diry
if self.pos[0] > 640 or self.pos[0] < 0:
self.dirx = -self.dirx
if self.pos[1] > 480 or self.pos[1] < 0:
self.diry = -self.diry
self.screen.fill((255,255,255))
pygame.draw.circle(self.screen, (0,0,0), self.pos, 25, 0)
pygame.display.update()
while (time.time() - begining) < (1.0/60.0):
pass
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
self.p = None
def initialize(self):
self.p = MovingCircle()
self.p.start()
def process(self):
pass
def uninitialize(self):
self.p.stop()
self.p.join()
if __name__ == '__main__':
box = MyOVBox()
@@ -0,0 +1,31 @@
from multiprocessing import Process, Queue
import time
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
self.p = None
self.q = None
def f(self, queue):
while True:
queue.put('hello')
time.sleep(1)
def initialize(self):
print "process initialize!"
self.q = Queue()
self.p = Process(target=self.f, args=(self.q,))
self.p.start()
def process(self):
for i in range(self.q.qsize()):
print self.q.get()
def uninitialize(self):
print "process uninitialize!"
self.p.terminate()
self.p.join()
if __name__ == '__main__':
box = MyOVBox()
@@ -0,0 +1,25 @@
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
def initialize(self):
# nop
return
def process(self):
for chunkIdx in range( len(self.input[0]) ):
chunk = self.input[0].pop()
if(type(chunk) == OVStimulationSet):
for stimIdx in range(len(chunk)):
stim=chunk.pop();
print 'Received stim', stim.identifier, 'stamped at', stim.date, 's'
#else:
# print 'Received chunk of type ', type(chunk), " looking for StimulationSet"
return
def uninitialize(self):
# nop
return
box = MyOVBox()
@@ -0,0 +1,27 @@
import numpy
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
self.signalHeader = None
def process(self):
for chunkIdx in range( len(self.input[0]) ):
if(type(self.input[0][chunkIdx]) == OVSignalHeader):
self.signalHeader = self.input[0].pop()
outputHeader = OVSignalHeader(self.signalHeader.startTime, self.signalHeader.endTime, [1, self.signalHeader.dimensionSizes[1]], ['Mean']+self.signalHeader.dimensionSizes[1]*[''], self.signalHeader.samplingRate)
self.output[0].append(outputHeader)
elif(type(self.input[0][chunkIdx]) == OVSignalBuffer):
chunk = self.input[0].pop()
numpyBuffer = numpy.array(chunk).reshape(tuple(self.signalHeader.dimensionSizes))
numpyBuffer = numpyBuffer.mean(axis=0)
chunk = OVSignalBuffer(chunk.startTime, chunk.endTime, numpyBuffer.tolist())
self.output[0].append(chunk)
elif(type(self.input[0][chunkIdx]) == OVSignalEnd):
self.output[0].append(self.input[0].pop())
box = MyOVBox()
@@ -0,0 +1,76 @@
from math import *
import random, time
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
self.nChannel = 0
self.sampling = 0
self.epochSampleCount = 0
self.startTime = 0
self.endTime = 0
self.dimensionSizes = list()
self.dimensionLabels = list()
self.timeBuffer = list()
self.signalBuffer = list()
self.signalHeader = None
def initialize(self):
random.seed(time.time())
self.nChannel = int(self.setting['Channel count'])
self.sampling = int(self.setting['Sampling frequency'])
self.epochSampleCount = int(self.setting['Generated epoch sample count'])
#creation of the signal header
for i in range(self.nChannel):
self.dimensionLabels.append( 'Sinus'+str(i) )
self.dimensionLabels += self.epochSampleCount*['']
self.dimensionSizes = [self.nChannel, self.epochSampleCount]
self.signalHeader = OVSignalHeader(0., 0., self.dimensionSizes, self.dimensionLabels, self.sampling)
self.output[0].append(self.signalHeader)
#creation of the first signal chunk
self.endTime = self.epochSampleCount
self.signalBuffer = [0.]*self.nChannel*self.epochSampleCount
self.update_timeBuffer()
self.update_signalBuffer()
def updateStartTime(self):
self.startTime += self.epochSampleCount
def updateEndTime(self):
self.endTime += self.epochSampleCount
def updateTimeBuffer(self):
self.timeBuffer = range(self.startTime, self.endTime)
for instant_index, instant in enumerate(self.timeBuffer):
self.timeBuffer[instant_index] = float(instant)/self.sampling
def updateSignalBuffer(self):
for channel in range(self.nChannel):
for instantIndex, instant in enumerate(self.timeBuffer):
newSample = 100.*sin(2.*pi*float(channel+1)*instant) + (1000.*random.random()-500.)
self.signalBuffer[channel*self.epochSampleCount+instantIndex] = newSample
def sendSignalBufferToOpenvibe(self):
start = self.timeBuffer[0]
end = self.timeBuffer[-1] + 1.0/self.sampling
self.output[0].append( OVSignalBuffer(start, end, self.signalBuffer) )
def process(self):
start = self.timeBuffer[0]
end = self.timeBuffer[-1]
if self.getCurrentTime() >= end:
self.sendSignalBufferToOpenvibe()
self.updateStartTime()
self.updateEndTime()
self.updateTimeBuffer()
self.updateSignalBuffer()
def uninitialize(self):
end = self.timeBuffer[-1]
self.output[0].append(OVSignalEnd(end, end))
box = MyOVBox()
@@ -0,0 +1,69 @@
import numpy
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
self.nChannel = 0
self.sampling = 0
self.epochSampleCount = 0
self.startTime = 0.
self.endTime = 0.
self.dimensionSizes = list()
self.dimensionLabels = list()
self.timeBuffer = list()
self.signalBuffer = None
self.signalHeader = None
def initialize(self):
self.nChannel = int(self.setting['Channel count'])
self.sampling = int(self.setting['Sampling frequency'])
self.epochSampleCount = int(self.setting['Generated epoch sample count'])
#creation of the signal header
for i in range(self.nChannel):
self.dimensionLabels.append( 'Sinus'+str(i) )
self.dimensionLabels += self.epochSampleCount*['']
self.dimensionSizes = [self.nChannel, self.epochSampleCount]
self.signalHeader = OVSignalHeader(0., 0., self.dimensionSizes, self.dimensionLabels, self.sampling)
self.output[0].append(self.signalHeader)
#creation of the first signal chunk
self.endTime = 1.*self.epochSampleCount/self.sampling
self.signalBuffer = numpy.zeros((self.nChannel, self.epochSampleCount))
self.updateTimeBuffer()
self.updateSignalBuffer()
def updateStartTime(self):
self.startTime += 1.*self.epochSampleCount/self.sampling
def updateEndTime(self):
self.endTime = float(self.startTime + 1.*self.epochSampleCount/self.sampling)
def updateTimeBuffer(self):
self.timeBuffer = numpy.arange(self.startTime, self.endTime, 1./self.sampling)
def updateSignalBuffer(self):
for rowIndex, row in enumerate(self.signalBuffer):
self.signalBuffer[rowIndex,:] = 100.*numpy.sin( 2.*numpy.pi*(rowIndex+1.)*self.timeBuffer )
def sendSignalBufferToOpenvibe(self):
start = self.timeBuffer[0]
end = self.timeBuffer[-1] + 1./self.sampling
bufferElements = self.signalBuffer.reshape(self.nChannel*self.epochSampleCount).tolist()
self.output[0].append( OVSignalBuffer(start, end, bufferElements) )
def process(self):
start = self.timeBuffer[0]
end = self.timeBuffer[-1]
if self.getCurrentTime() >= end:
self.sendSignalBufferToOpenvibe()
self.updateStartTime()
self.updateEndTime()
self.updateTimeBuffer()
self.updateSignalBuffer()
def uninitialize(self):
end = self.timeBuffer[-1]
self.output[0].append(OVSignalEnd(end, end))
box = MyOVBox()
@@ -0,0 +1,106 @@
from multiprocessing import Process, Event
import time
import pygame
from pygame.locals import *
import math
from random import randint, randrange
import sys
sys.argv = ['openvibe']
class OVProcess(Process):
def __init__(self):
Process.__init__(self)
self.initialized = Event()
self.stop_asked = Event()
def initialize(self):
pass
def process(self):
pass
def uninitialize(self):
pass
def stop(self):
self.stop_asked.set()
def run(self):
self.initialize()
self.initialized.set()
while not self.stop_asked.is_set():
self.process()
self.uninitialize()
class StarField(OVProcess):
def __init__(self, num_stars, max_depth):
OVProcess.__init__(self)
self.pygame_is_running = False
self.screen = None
self.clock = None
self.num_stars = num_stars
self.max_depth = max_depth
self.stars = []
for i in range(self.num_stars):
star = [randrange(-25,25), randrange(-25,25), randrange(1, self.max_depth)]
self.stars.append(star)
def initialize(self):
pygame.init()
self.pygame_is_running = True
self.screen = pygame.display.set_mode((640, 480))
pygame.display.set_caption("3D Starfield Simulation")
self.clock = pygame.time.Clock()
def move_and_draw_stars(self):
origin_x = self.screen.get_width() / 2
origin_y = self.screen.get_height() / 2
for star in self.stars:
star[2] -= 0.19
if star[2] <= 0:
star[0] = randrange(-25,25)
star[1] = randrange(-25,25)
star[2] = self.max_depth
k = 128.0 / star[2]
x = int(star[0] * k + origin_x)
y = int(star[1] * k + origin_y)
if 0 <= x < self.screen.get_width() and 0 <= y < self.screen.get_height():
size = (1 - float(star[2]) / self.max_depth) * 5
shade = (1 - float(star[2]) / self.max_depth) * 255
self.screen.fill((shade,shade,shade),(x,y,size,size))
def process(self):
if self.pygame_is_running:
self.clock.tick(50)
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
self.pygame_is_running = False
return
self.screen.fill((0,0,0))
self.move_and_draw_stars()
pygame.display.flip()
def uninitialize(self):
if self.pygame_is_running:
pygame.quit()
self.pygame_is_running = False
class MyOVBox(OVBox):
def __init__(self):
OVBox.__init__(self)
self.p = None
def initialize(self):
self.p = StarField(512, 32)
self.p.start()
def process(self):
pass
def uninitialize(self):
self.p.stop()
self.p.join()
if __name__ == '__main__':
box = MyOVBox()
@@ -0,0 +1,50 @@
/**
* \page BoxAlgorithm_Python2Scripting Python 2 scripting
__________________________________________________________________
Detailed description
__________________________________________________________________
* |OVP_DocBegin_BoxAlgorithm_Python2Scripting_Description|
This box can process data from and to OpenViBE using Python script.
Available IO types are Streamed Matrix, Signal and Stimulations.
The user Python Script must define a new class that inherits from OVBox,
and implements the initialize, process and uninitialize methods.
User script must end with : box = MyOVBox() where MyOVBox is the new class.
Please look at <a href="http://openvibe.inria.fr/tutorial-using-python-with-openvibe">the documentation page</a> for more details.
* |OVP_DocEnd_BoxAlgorithm_Python2Scripting_Description|
__________________________________________________________________
Settings description
__________________________________________________________________
* |OVP_DocBegin_BoxAlgorithm_Python2Scripting_Settings|
* |OVP_DocEnd_BoxAlgorithm_Python2Scripting_Settings|
* |OVP_DocBegin_BoxAlgorithm_Python2Scripting_Setting1|
The box clock frequency. The Python process function is called at each tick.
* |OVP_DocEnd_BoxAlgorithm_Python2Scripting_Setting1|
* |OVP_DocBegin_BoxAlgorithm_Python2Scripting_Setting2|
The Python script file.
* |OVP_DocEnd_BoxAlgorithm_Python2Scripting_Setting2|
__________________________________________________________________
Examples description
__________________________________________________________________
* |OVP_DocBegin_BoxAlgorithm_Python2Scripting_Examples|
See <a href="http://openvibe.inria.fr/tutorial-using-python-with-openvibe">this page</a> for commented examples.
* |OVP_DocEnd_BoxAlgorithm_Python2Scripting_Examples|
__________________________________________________________________
Miscellaneous description
__________________________________________________________________
* |OVP_DocBegin_BoxAlgorithm_Python2Scripting_Miscellaneous|
* |OVP_DocEnd_BoxAlgorithm_Python2Scripting_Miscellaneous|
*/
@@ -0,0 +1,227 @@
# -*- coding: utf-8 -*-
#File Name : StimulationsCodes.py
#Created By : Aurelien Van Langhenhove
## Stimulation codes
## Originally from openvibe-toolkit/ovtk_defines.h
OpenViBE_stimulation = {
'OVTK_StimulationId_ExperimentStart' : 0x00008001,
'OVTK_StimulationId_ExperimentStop' : 0x00008002,
'OVTK_StimulationId_SegmentStart' : 0x00008003,
'OVTK_StimulationId_SegmentStop' : 0x00008004,
'OVTK_StimulationId_TrialStart' : 0x00008005,
'OVTK_StimulationId_TrialStop' : 0x00008006,
'OVTK_StimulationId_BaselineStart' : 0x00008007,
'OVTK_StimulationId_BaselineStop' : 0x00008008,
'OVTK_StimulationId_RestStart' : 0x00008009,
'OVTK_StimulationId_RestStop' : 0x0000800a,
'OVTK_StimulationId_VisualStimulationStart' : 0x0000800b,
'OVTK_StimulationId_VisualStimulationStop' : 0x0000800c,
'OVTK_StimulationId_VisualSteadyStateStimulationStart' : 0x00008010,
'OVTK_StimulationId_VisualSteadyStateStimulationStop' : 0x00008011,
'OVTK_StimulationId_RemovedSamples' : 0x00008310,
'OVTK_StimulationId_AddedSamplesBegin' : 0x00008311,
'OVTK_StimulationId_AddedSamplesEnd' : 0x00008312,
'OVTK_StimulationId_LabelStart' : 0x00008100,
'OVTK_StimulationId_Label_00' : 0x00008100,
'OVTK_StimulationId_Label_01' : 0x00008101,
'OVTK_StimulationId_Label_02' : 0x00008102,
'OVTK_StimulationId_Label_03' : 0x00008103,
'OVTK_StimulationId_Label_04' : 0x00008104,
'OVTK_StimulationId_Label_05' : 0x00008105,
'OVTK_StimulationId_Label_06' : 0x00008106,
'OVTK_StimulationId_Label_07' : 0x00008107,
'OVTK_StimulationId_Label_08' : 0x00008108,
'OVTK_StimulationId_Label_09' : 0x00008109,
'OVTK_StimulationId_Label_0A' : 0x0000810a,
'OVTK_StimulationId_Label_0B' : 0x0000810b,
'OVTK_StimulationId_Label_0C' : 0x0000810c,
'OVTK_StimulationId_Label_0D' : 0x0000810d,
'OVTK_StimulationId_Label_0E' : 0x0000810e,
'OVTK_StimulationId_Label_0F' : 0x0000810f,
'OVTK_StimulationId_Label_10' : 0x00008110,
'OVTK_StimulationId_Label_11' : 0x00008111,
'OVTK_StimulationId_Label_12' : 0x00008112,
'OVTK_StimulationId_Label_13' : 0x00008113,
'OVTK_StimulationId_Label_14' : 0x00008114,
'OVTK_StimulationId_Label_15' : 0x00008115,
'OVTK_StimulationId_Label_16' : 0x00008116,
'OVTK_StimulationId_Label_17' : 0x00008117,
'OVTK_StimulationId_Label_18' : 0x00008118,
'OVTK_StimulationId_Label_19' : 0x00008119,
'OVTK_StimulationId_Label_1A' : 0x0000811a,
'OVTK_StimulationId_Label_1B' : 0x0000811b,
'OVTK_StimulationId_Label_1C' : 0x0000811c,
'OVTK_StimulationId_Label_1D' : 0x0000811d,
'OVTK_StimulationId_Label_1E' : 0x0000811e,
'OVTK_StimulationId_Label_1F' : 0x0000811f,
'OVTK_StimulationId_LabelEnd' : 0x000081ff,
'OVTK_StimulationId_NumberStart' : 0x00000000,
'OVTK_StimulationId_Number_00' : 0x00000000,
'OVTK_StimulationId_Number_01' : 0x00000001,
'OVTK_StimulationId_Number_02' : 0x00000002,
'OVTK_StimulationId_Number_03' : 0x00000003,
'OVTK_StimulationId_Number_04' : 0x00000004,
'OVTK_StimulationId_Number_05' : 0x00000005,
'OVTK_StimulationId_Number_06' : 0x00000006,
'OVTK_StimulationId_Number_07' : 0x00000007,
'OVTK_StimulationId_Number_08' : 0x00000008,
'OVTK_StimulationId_Number_09' : 0x00000009,
'OVTK_StimulationId_Number_0A' : 0x0000000a,
'OVTK_StimulationId_Number_0B' : 0x0000000b,
'OVTK_StimulationId_Number_0C' : 0x0000000c,
'OVTK_StimulationId_Number_0D' : 0x0000000d,
'OVTK_StimulationId_Number_0E' : 0x0000000e,
'OVTK_StimulationId_Number_0F' : 0x0000000f,
'OVTK_StimulationId_Number_10' : 0x00000010,
'OVTK_StimulationId_Number_11' : 0x00000011,
'OVTK_StimulationId_Number_12' : 0x00000012,
'OVTK_StimulationId_Number_13' : 0x00000013,
'OVTK_StimulationId_Number_14' : 0x00000014,
'OVTK_StimulationId_Number_15' : 0x00000015,
'OVTK_StimulationId_Number_16' : 0x00000016,
'OVTK_StimulationId_Number_17' : 0x00000017,
'OVTK_StimulationId_Number_18' : 0x00000018,
'OVTK_StimulationId_Number_19' : 0x00000019,
'OVTK_StimulationId_Number_1A' : 0x0000001a,
'OVTK_StimulationId_Number_1B' : 0x0000001b,
'OVTK_StimulationId_Number_1C' : 0x0000001c,
'OVTK_StimulationId_Number_1D' : 0x0000001d,
'OVTK_StimulationId_Number_1E' : 0x0000001e,
'OVTK_StimulationId_Number_1F' : 0x0000001f,
'OVTK_StimulationId_NumberEnd' : 0x000000ff,
'OVTK_StimulationId_Train' : 0x00008201,
'OVTK_StimulationId_Beep' : 0x00008202,
'OVTK_StimulationId_DoubleBeep' : 0x00008203,
'OVTK_StimulationId_EndOfFile' : 0x00008204,
'OVTK_StimulationId_Target' : 0x00008205,
'OVTK_StimulationId_NonTarget' : 0x00008206,
'OVTK_GDF_Artifact_EOG_Large' : 0x101,
'OVTK_GDF_Artifact_ECG' : 0x102,
'OVTK_GDF_Artifact_EMG' : 0x103,
'OVTK_GDF_Artifact_Movement' : 0x104,
'OVTK_GDF_Artifact_Failing_Electrode' : 0x105,
'OVTK_GDF_Artifact_Sweat' : 0x106,
'OVTK_GDF_Artifact_50_60_Hz_Interference' : 0x107,
'OVTK_GDF_Artifact_Breathing' : 0x108,
'OVTK_GDF_Artifact_Pulse' : 0x109,
'OVTK_GDF_Artifact_EOG_Small' : 0x10A,
'OVTK_GDF_Calibration' : 0x10F,
'OVTK_GDF_EEG_Sleep_Splindles' : 0x111,
'OVTK_GDF_EEG_K_Complexes' : 0x112,
'OVTK_GDF_EEG_Saw_Tooth_Waves' : 0x113,
'OVTK_GDF_EEG_Idling_EEG_Eyes_Open' : 0x114,
'OVTK_GDF_EEG_Idling_EEG_Eyes_Closed' : 0x115,
'OVTK_GDF_EEG_Spike' : 0x116,
'OVTK_GDF_EEG_Seizure' : 0x117,
'OVTK_GDF_VEP' : 0x121,
'OVTK_GDF_AEP' : 0x122,
'OVTK_GDF_SEP' : 0x123,
'OVTK_GDF_TMS' : 0x12F,
'OVTK_GDF_SSVEP' : 0x131,
'OVTK_GDF_SSAEP' : 0x132,
'OVTK_GDF_SSSEP' : 0x133,
'OVTK_GDF_Start_Of_Trial' : 0x300,
'OVTK_GDF_Left' : 0x301,
'OVTK_GDF_Right' : 0x302,
'OVTK_GDF_Foot' : 0x303,
'OVTK_GDF_Tongue' : 0x304,
'OVTK_GDF_class5' : 0x305,
'OVTK_GDF_Down' : 0x306,
'OVTK_GDF_class7' : 0x307,
'OVTK_GDF_class8' : 0x308,
'OVTK_GDF_class9' : 0x309,
'OVTK_GDF_class10' : 0x30A,
'OVTK_GDF_class11' : 0x30B,
'OVTK_GDF_Up' : 0x30C,
'OVTK_GDF_Feedback_Continuous' : 0x30D,
'OVTK_GDF_Feedback_Discrete' : 0x30E,
'OVTK_GDF_Cue_Unknown_Undefined' : 0x30F,
'OVTK_GDF_Beep' : 0x311,
'OVTK_GDF_Cross_On_Screen' : 0x312,
'OVTK_GDF_Flashing_Light' : 0x313,
'OVTK_GDF_End_Of_Trial' : 0x320,
'OVTK_GDF_Correct' : 0x381,
'OVTK_GDF_Incorrect' : 0x382,
'OVTK_GDF_End_Of_Session' : 0x3F2,
'OVTK_GDF_Rejection' : 0x3FF,
'OVTK_GDF_OAHE' : 0x401,
'OVTK_GDF_RERA' : 0x402,
'OVTK_GDF_CAHE' : 0x403,
'OVTK_GDF_CSB' : 0x404,
'OVTK_GDF_Sleep_Hypoventilation' : 0x405,
'OVTK_GDF_Maximum_Inspiration' : 0x40E,
'OVTK_GDF_Start_Of_Inspiration' : 0x40F,
'OVTK_GDF_Wake' : 0x410,
'OVTK_GDF_Stage_1' : 0x411,
'OVTK_GDF_Stage_2' : 0x412,
'OVTK_GDF_Stage_3' : 0x413,
'OVTK_GDF_Stage_4' : 0x414,
'OVTK_GDF_REM' : 0x415,
'OVTK_GDF_Lights_On' : 0x420,
'OVTK_GDF_Lights_Off' : 0x8420,
'OVTK_GDF_Eyes_Left' : 0x431,
'OVTK_GDF_Eyes_Right' : 0x432,
'OVTK_GDF_Eyes_Up' : 0x433,
'OVTK_GDF_Eyes_Down' : 0x434,
'OVTK_GDF_Horizontal_Eye_Movement' : 0x435,
'OVTK_GDF_Vertical_Eye_Movement' : 0x436,
'OVTK_GDF_Rotation_Clockwise' : 0x437,
'OVTK_GDF_Rotation_Counterclockwise' : 0x438,
'OVTK_GDF_Eye_Blink' : 0x439,
'OVTK_GDF_Left_Hand_Movement' : 0x441,
'OVTK_GDF_Right_Hand_Movement' : 0x442,
'OVTK_GDF_Head_Movement' : 0x443,
'OVTK_GDF_Tongue_Movement' : 0x444,
'OVTK_GDF_Swallowing' : 0x445,
'OVTK_GDF_Biting' : 0x446,
'OVTK_GDF_Foot_Movement' : 0x447,
'OVTK_GDF_Foot_Right_Movement' : 0x448,
'OVTK_GDF_Arm_Movement' : 0x449,
'OVTK_GDF_Arm_Right_Movement' : 0x44A,
'OVTK_GDF_ECG_Fiducial_Point_QRS_Complex' : 0x501,
'OVTK_GDF_ECG_P_Wave' : 0x502,
'OVTK_GDF_ECG_QRS_Complex' : 0x503,
'OVTK_GDF_ECG_R_Point' : 0x504,
'OVTK_GDF_ECG_T_Wave' : 0x506,
'OVTK_GDF_ECG_U_Wave' : 0x507,
'OVTK_GDF_Start' : 0x580,
'OVTK_GDF_25_Watt' : 0x581,
'OVTK_GDF_50_Watt' : 0x582,
'OVTK_GDF_75_Watt' : 0x583,
'OVTK_GDF_100_Watt' : 0x584,
'OVTK_GDF_125_Watt' : 0x585,
'OVTK_GDF_150_Watt' : 0x586,
'OVTK_GDF_175_Watt' : 0x587,
'OVTK_GDF_200_Watt' : 0x588,
'OVTK_GDF_225_Watt' : 0x589,
'OVTK_GDF_250_Watt' : 0x58A,
'OVTK_GDF_275_Watt' : 0x58B,
'OVTK_GDF_300_Watt' : 0x58C,
'OVTK_GDF_325_Watt' : 0x58D,
'OVTK_GDF_350_Watt' : 0x58E,
'OVTK_GDF_Start_Of_New_Segment' : 0x7FFE,
'OVTK_GDF_Non_Equidistant_Sampling_Value' : 0x7FFF
}
@@ -0,0 +1,180 @@
# -*- coding: utf-8 -*-
#File Name : openvibe.py
#Created By : Aurelien Van Langhenhove
from StimulationsCodes import *
import sys, traceback, collections
from StringIO import StringIO
class NewStd(StringIO):
def __init__(self):
StringIO.__init__(self)
def flush(self):
self.buf = str()
def isempty(self):
if len(self.buf) == 0:
return True
else:
return False
sys.stdout = NewStd()
sys.stderr = NewStd()
def execfileHandlingException(filename, maindictionary):
print "executing script file"
try:
maindictionary['box'] = OVBox(default=True) # on en cree une au cas ou
#print globals()
execfile(filename, maindictionary)
return 0
except:
print "error"
print traceback.format_exc()
return -1
def decoratorFunction(target):
""" add a try except block to protect openvibe box in case of exception """
def wrapper(self):
try :
print "using decorator"
print 'Calling function "%s"' % target.__name__
return target(self)
except:
print traceback.format_exc()
return wrapper
class OVChunk(object):
def __init__(self, startTime, endTime):
self.startTime = startTime
self.endTime = endTime
class OVStreamedMatrixHeader(OVChunk):
def __init__(self, startTime, endTime, dimensionSizes, dimensionLabels):
OVChunk.__init__(self, startTime, endTime)
self.dimensionSizes = list(dimensionSizes)
self.dimensionLabels = list(dimensionLabels)
def getDimensionCount(self):
return len(self.dimensionSizes)
def getBufferElementCount(self):
elementCount = 0
for dimension, size in enumerate(self.dimensionSizes):
if dimension == 0:
elementCount = int(size)
else:
elementCount *= int(size)
return elementCount
class OVStreamedMatrixBuffer(OVChunk, list):
def __init__(self, startTime, endTime, bufferElements):
OVChunk.__init__(self, startTime, endTime)
list.__init__(self, bufferElements)
class OVStreamedMatrixEnd(OVChunk):
pass
class OVSignalHeader(OVStreamedMatrixHeader):
def __init__(self, startTime, endTime, dimensionSizes, dimensionLabels, samplingRate):
OVStreamedMatrixHeader.__init__(self, startTime, endTime, dimensionSizes, dimensionLabels)
self.samplingRate = int(samplingRate)
class OVSignalBuffer(OVStreamedMatrixBuffer):
pass
class OVSignalEnd(OVChunk):
pass
class OVStimulation(object):
def __init__(self, identifier, date, duration):
self.identifier = identifier
self.date = date
self.duration = duration
class OVStimulationHeader(OVChunk):
pass
class OVStimulationSet(OVChunk, list):
def __init__(self, startTime, endTime):
list.__init__(self)
OVChunk.__init__(self, startTime, endTime)
def append(self, item):
if isinstance(item, OVStimulation):
list.append(self, item)
else:
raise TypeError("The item must be an OVStimulation")
class OVStimulationEnd(OVChunk):
pass
class OVBuffer(object):
def __init__(self, inputType):
self.__deque = collections.deque()
self.__type = inputType
def __len__(self):
return len(self.__deque)
def __getitem__(self, key):
return self.__deque[key]
def __setitem__(self, key, item):
self.__deque[key] = item
def __delitem__(self, key):
del self.__deque[key]
def append(self, toAppend):
self.__deque.appendleft(toAppend)
def pop(self):
return self.__deque.pop()
def type(self):
return self.__type
class OVBox(object):
def __init__(self, default=False):
self.input = list()
self.output = list()
self.setting = dict()
self.var = dict()
self._clock = 0
self._currentTime = 0.
self.default= default
def addInput(self, inputType):
self.input.append(OVBuffer(inputType))
def addOutput(self, outputType):
self.output.append(OVBuffer(outputType))
def getClock(self):
return self._clock
def getCurrentTime(self):
return self._currentTime
def initialize(self):
if self.default == True:
print "The box instance has not been created by user script, using default one from openvibe.py (dummy box)."
pass
def process(self):
pass
def uninitialize(self):
pass
def realInitialize(self):
try :
self.initialize()
except:
print traceback.format_exc()
def realProcess(self):
try :
self.process()
except:
print traceback.format_exc()
def realUninitialize(self):
try :
self.uninitialize()
except:
print traceback.format_exc()
@@ -0,0 +1,146 @@
#pragma once
#if defined TARGET_HAS_ThirdPartyPython2
#include <Python.h>
#if defined(PY_MAJOR_VERSION) && (PY_MAJOR_VERSION == 2)
#include "../ovp_defines.h"
#include <openvibe/ov_all.h>
#include <toolkit/ovtk_all.h>
#include <string>
#include <vector>
//#include <map>
namespace OpenViBE
{
namespace Plugins
{
namespace Python
{
class CBoxAlgorithmPython2 final : virtual public Toolkit::TBoxAlgorithm<IBoxAlgorithm>
{
public:
void release() override { delete this; }
uint64_t getClockFrequency() override;
bool initialize() override;
bool uninitialize() override;
bool processClock(Kernel::CMessageClock& msg) override;
bool processInput(const size_t index) override;
bool process() override;
_IsDerivedFromClass_Final_(Toolkit::TBoxAlgorithm<IBoxAlgorithm>, OVP_ClassId_BoxAlgorithm_Python2)
protected:
uint64_t m_clockFrequency = 0;
CString m_scriptFilename;
std::vector<Toolkit::TDecoder<CBoxAlgorithmPython2>*> m_decoders;
std::vector<Toolkit::TEncoder<CBoxAlgorithmPython2>*> m_encoders;
//std::map<char,PyObject *> m_PyObjectMap;
PyObject *m_box = nullptr, *m_boxInput = nullptr, *m_boxOutput = nullptr, *m_boxSetting = nullptr,
*m_boxCurrentTime = nullptr, *m_boxInitialize = nullptr, *m_boxProcess = nullptr, *m_boxUninitialize = nullptr;
bool m_initializeSucceeded = false;
bool logSysStd(const bool out);
bool logSysStdout() { return logSysStd(true); }
bool logSysStderr() { return logSysStd(false); }
void buildPythonSettings();
bool initializePythonSafely();
//bool clearPyObjectMap();
bool transferStreamedMatrixInputChunksToPython(const size_t index);
bool transferStreamedMatrixOutputChunksFromPython(const size_t index);
bool transferSignalInputChunksToPython(const size_t index);
bool transferSignalOutputChunksFromPython(const size_t index);
bool transferStimulationInputChunksToPython(const size_t index);
bool transferStimulationOutputChunksFromPython(const size_t index);
static bool m_isPythonInitialized;
// These are all borrowed references in python v2.7. Do not free them.
static PyObject *m_mainModule, *m_mainDictionnary;
static PyObject *m_matrixHeader, *m_matrixBuffer, *m_matrixEnd;
static PyObject *m_signalHeader, *m_signalBuffer, *m_signalEnd;
static PyObject *m_stimulationHeader, *m_stimulation, *m_stimulationSet, *m_stimulationEnd;
static PyObject* m_buffer;
static PyObject* m_execFileFunction;
static PyObject *m_stdout, *m_stderr;
};
class CBoxAlgorithmPython2Listener final : public Toolkit::TBoxListener<IBoxListener>
{
public:
bool onInputAdded(Kernel::IBox& box, const size_t index) override
{
box.setInputType(index, OV_TypeId_StreamedMatrix);
return true;
}
bool onOutputAdded(Kernel::IBox& box, const size_t index) override
{
box.setOutputType(index, OV_TypeId_StreamedMatrix);
return true;
}
_IsDerivedFromClass_Final_(Toolkit::TBoxListener<IBoxListener>, CIdentifier::undefined())
};
class CBoxAlgorithmPython2Desc final : virtual public IBoxAlgorithmDesc
{
public:
void release() override { }
CString getName() const override { return CString("Python 2 scripting"); }
CString getAuthorName() const override { return CString("Aurelien Van Langhenhove and Laurent George"); }
CString getAuthorCompanyName() const override { return CString("CICIT Garches, Inria"); }
CString getShortDescription() const override { return CString("This box executes a python script."); }
CString getDetailedDescription() const override { return CString(""); }
CString getCategory() const override { return CString("Scripting"); }
CString getVersion() const override { return CString("0.1"); }
CString getStockItemName() const override { return CString("gtk-convert"); }
CIdentifier getCreatedClass() const override { return OVP_ClassId_BoxAlgorithm_Python2; }
IPluginObject* create() override { return new CBoxAlgorithmPython2; }
IBoxListener* createBoxListener() const override { return new CBoxAlgorithmPython2Listener; }
void releaseBoxListener(IBoxListener* listener) const override { delete listener; }
bool getBoxPrototype(Kernel::IBoxProto& prototype) const override
{
prototype.addSetting("Clock frequency (Hz)", OV_TypeId_Integer, "64");
prototype.addSetting("Script", OV_TypeId_Script, "");
prototype.addFlag(Kernel::BoxFlag_CanAddInput);
prototype.addFlag(Kernel::BoxFlag_CanModifyInput);
prototype.addFlag(Kernel::BoxFlag_CanAddOutput);
prototype.addFlag(Kernel::BoxFlag_CanModifyOutput);
prototype.addFlag(Kernel::BoxFlag_CanAddSetting);
prototype.addFlag(Kernel::BoxFlag_CanModifySetting);
prototype.addInputSupport(OV_TypeId_Signal);
prototype.addInputSupport(OV_TypeId_Stimulations);
prototype.addInputSupport(OV_TypeId_StreamedMatrix);
prototype.addOutputSupport(OV_TypeId_Signal);
prototype.addOutputSupport(OV_TypeId_Stimulations);
prototype.addOutputSupport(OV_TypeId_StreamedMatrix);
return true;
}
_IsDerivedFromClass_Final_(IBoxAlgorithmDesc, OVP_ClassId_BoxAlgorithm_Python2Desc)
};
} // namespace Python
} // namespace Plugins
} // namespace OpenViBE
#endif // #if defined(PY_MAJOR_VERSION) && (PY_MAJOR_VERSION == 2)
#endif // TARGET_HAS_ThirdPartyPython2
@@ -0,0 +1,6 @@
#pragma once
// Boxes
//---------------------------------------------------------------------------------------------------
#define OVP_ClassId_BoxAlgorithm_Python2 OpenViBE::CIdentifier(0x5DC4F669, 0xD3FD4D64)
#define OVP_ClassId_BoxAlgorithm_Python2Desc OpenViBE::CIdentifier(0x404B6FFD, 0x12BDD429)
@@ -0,0 +1,104 @@
#if defined TARGET_HAS_ThirdPartyPython2 && !(defined(WIN32) && defined(TARGET_BUILDTYPE_Debug))
// Windows debug build doesn't typically link as most people don't have the python debug library.
#include "box-algorithms/ovpCBoxAlgorithmPython2.h"
#if defined(PY_MAJOR_VERSION) && (PY_MAJOR_VERSION == 2)
#ifdef TARGET_OS_Windows
#include "windows.h"
#endif
#include <string>
#include <iostream>
//-------------------------------------------------------------------------------------------------
class CPython2Initializer
{
public:
CPython2Initializer();
~CPython2Initializer();
bool isPython2Available() const { return m_pythonAvailable; }
private:
#ifdef TARGET_OS_Windows
static bool checkPython2Path();
#endif
// PyThreadState *m_pMainPyThreadState;
bool m_pythonAvailable;
};
#ifdef TARGET_OS_Windows
bool CPython2Initializer::checkPython2Path()
{
std::string path = Py_GetPath();
size_t found = path.find_first_of(';');
while (found != std::string::npos)
{
if (found > 0)
{
std::string filename = path.substr(0, found);
const bool exists = (_access(filename.c_str(), 0) == 0);
if (exists) { return true; }
}
path = path.substr(found + 1);
found = path.find_first_of(';');
}
std::cout << "Python directory not found. You probably have a corrupted python installation!" << std::endl;
std::cout << "The tried path from Py_GetPath() was [" << Py_GetPath() << "]\n";
return false;
}
#endif
CPython2Initializer::CPython2Initializer() : m_pythonAvailable(false)
{
#ifdef TARGET_OS_Windows
__try
{
// We do not care about the last file, since it is the OpenViBE runtime path
if (!Py_IsInitialized() && checkPython2Path())
{
Py_Initialize();
m_pythonAvailable = true;
}
}
__except (EXCEPTION_EXECUTE_HANDLER) { }
#else
if (!Py_IsInitialized())
{
Py_Initialize();
m_pythonAvailable = true;
}
#endif
}
CPython2Initializer::~CPython2Initializer()
{
if (m_pythonAvailable)
{
m_pythonAvailable = false;
Py_Finalize();
}
}
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
namespace OpenViBE {
namespace Plugins {
namespace Python {
OVP_Declare_Begin()
static CPython2Initializer python2Init;
if (python2Init.isPython2Available()) { OVP_Declare_New(CBoxAlgorithmPython2Desc); }
OVP_Declare_End()
} // namespace Python
} // namespace Plugins
} // namespace OpenViBE
//-------------------------------------------------------------------------------------------------
#else
#pragma message ("WARNING: Python 2.x headers are required to build the Python plugin, different includes found, skipped")
#endif // #if defined(PY_MAJOR_VERSION) && (PY_MAJOR_VERSION == 2)
#endif // TARGET_HAS_ThirdPartyPython2