init
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
PROJECT(openvibe-plugins-contrib-python3)
|
||||
|
||||
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("FindThirdPartyPython3")
|
||||
|
||||
# -----------------------------
|
||||
# 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/python3)
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
<OpenViBE-Scenario>
|
||||
<FormatVersion>2</FormatVersion>
|
||||
<Creator>OpenViBE Designer</Creator>
|
||||
<CreatorVersion>2.2.0</CreatorVersion>
|
||||
<Settings></Settings>
|
||||
<Inputs></Inputs>
|
||||
<Outputs></Outputs>
|
||||
<Boxes>
|
||||
<Box>
|
||||
<Identifier>(0x00003a96, 0x00003a53)</Identifier>
|
||||
<Name>Hello World!</Name>
|
||||
<AlgorithmClassIdentifier>(0x5dc4f669, 0xd3fd4d63)</AlgorithmClassIdentifier>
|
||||
<Settings>
|
||||
<Setting>
|
||||
<TypeIdentifier>(0x007deef9, 0x2f3e95c6)</TypeIdentifier>
|
||||
<Name>Clock frequency (Hz)</Name>
|
||||
<DefaultValue>64</DefaultValue>
|
||||
<Value>2</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>
|
||||
<Identifier>(0x78b47164, 0x584420aa)</Identifier>
|
||||
<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>(0x207c9054, 0x3c841b63)</Identifier>
|
||||
<Value>112</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>(0x000047c8, 0x000050cf)</Identifier>
|
||||
<Text><b>Hello World!</b>
|
||||
|
||||
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)","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>
|
||||
+177
@@ -0,0 +1,177 @@
|
||||
<OpenViBE-Scenario>
|
||||
<FormatVersion>2</FormatVersion>
|
||||
<Creator>OpenViBE Designer</Creator>
|
||||
<CreatorVersion>2.2.0</CreatorVersion>
|
||||
<Settings></Settings>
|
||||
<Inputs></Inputs>
|
||||
<Outputs></Outputs>
|
||||
<Boxes>
|
||||
<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</Value>
|
||||
</Attribute>
|
||||
<Attribute>
|
||||
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
|
||||
<Value>400</Value>
|
||||
</Attribute>
|
||||
<Attribute>
|
||||
<Identifier>(0x4e7b798a, 0x183beafb)</Identifier>
|
||||
<Value>(0x27b3ee3c, 0xc50527e6)</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>
|
||||
<Box>
|
||||
<Identifier>(0x00006593, 0x00001e93)</Identifier>
|
||||
<Name>Python 3 scripting</Name>
|
||||
<AlgorithmClassIdentifier>(0x5dc4f669, 0xd3fd4d63)</AlgorithmClassIdentifier>
|
||||
<Inputs>
|
||||
<Input>
|
||||
<Identifier>(0xed15d980, 0xc7e2bbc3)</Identifier>
|
||||
<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>112</Value>
|
||||
</Attribute>
|
||||
<Attribute>
|
||||
<Identifier>(0x207c9054, 0x3c841b63)</Identifier>
|
||||
<Value>400</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>
|
||||
<Link>
|
||||
<Identifier>(0x000061b9, 0x00000505)</Identifier>
|
||||
<Source>
|
||||
<BoxIdentifier>(0x00005777, 0x00006c19)</BoxIdentifier>
|
||||
<BoxOutputIndex>0</BoxOutputIndex>
|
||||
</Source>
|
||||
<Target>
|
||||
<BoxIdentifier>(0x00006593, 0x00001e93)</BoxIdentifier>
|
||||
<BoxInputIdentifier>(0xed15d980, 0xc7e2bbc3)</BoxInputIdentifier>
|
||||
</Target>
|
||||
</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)","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>
|
||||
+1183
File diff suppressed because it is too large
Load Diff
+31
@@ -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()
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
|
||||
class MyOVBox(OVBox):
|
||||
def __init__(self):
|
||||
OVBox.__init__(self)
|
||||
|
||||
def initialize(self):
|
||||
print('Initialize Hello World Script')
|
||||
# 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):
|
||||
print('Uninitialize Hello World Script')
|
||||
# nop
|
||||
return
|
||||
|
||||
box = MyOVBox()
|
||||
+25
@@ -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()
|
||||
+27
@@ -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()
|
||||
+69
@@ -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()
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
/**
|
||||
* \page BoxAlgorithm_Python3Scripting Python 3 scripting
|
||||
__________________________________________________________________
|
||||
|
||||
Detailed description
|
||||
__________________________________________________________________
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_Python3Scripting_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.
|
||||
|
||||
After version 2.2.0, Python 3 is used by default (Python 2 is no longer officially supported since January 1, 2020). To convert your previous scripts, python 3 has a script called <a href="https://docs.python.org/fr/3/library/2to3.html">2to3</a>.
|
||||
|
||||
* |OVP_DocEnd_BoxAlgorithm_Python3Scripting_Description|
|
||||
__________________________________________________________________
|
||||
|
||||
Settings description
|
||||
__________________________________________________________________
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_Python3Scripting_Settings|
|
||||
* |OVP_DocEnd_BoxAlgorithm_Python3Scripting_Settings|
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_Python3Scripting_Setting1|
|
||||
The box clock frequency. The Python process function is called at each tick.
|
||||
* |OVP_DocEnd_BoxAlgorithm_Python3Scripting_Setting1|
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_Python3Scripting_Setting2|
|
||||
The Python script file.
|
||||
* |OVP_DocEnd_BoxAlgorithm_Python3Scripting_Setting2|
|
||||
__________________________________________________________________
|
||||
|
||||
Examples description
|
||||
__________________________________________________________________
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_Python3Scripting_Examples|
|
||||
See <a href="http://openvibe.inria.fr/tutorial-using-python-with-openvibe">this page</a> for commented examples.
|
||||
* |OVP_DocEnd_BoxAlgorithm_Python3Scripting_Examples|
|
||||
__________________________________________________________________
|
||||
|
||||
Miscellaneous description
|
||||
__________________________________________________________________
|
||||
|
||||
* |OVP_DocBegin_BoxAlgorithm_Python3Scripting_Miscellaneous|
|
||||
* |OVP_DocEnd_BoxAlgorithm_Python3Scripting_Miscellaneous|
|
||||
*/
|
||||
+227
@@ -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
|
||||
}
|
||||
+179
@@ -0,0 +1,179 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
#File Name : openvibe.py
|
||||
#Created By : Aurelien Van Langhenhove
|
||||
|
||||
from StimulationsCodes import *
|
||||
import sys, traceback, collections
|
||||
from io import StringIO
|
||||
|
||||
class NewStd(StringIO):
|
||||
def __init__(self):
|
||||
StringIO.__init__(self)
|
||||
def flush(self):
|
||||
self.truncate(0)
|
||||
self.seek(0)
|
||||
def isempty(self):
|
||||
if len(self.len) == 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())
|
||||
exec(compile(open(filename, "rb").read(), filename, 'exec'), 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())
|
||||
+1613
File diff suppressed because it is too large
Load Diff
+143
@@ -0,0 +1,143 @@
|
||||
#pragma once
|
||||
|
||||
#if defined TARGET_HAS_ThirdPartyPython3
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#if defined(PY_MAJOR_VERSION) && (PY_MAJOR_VERSION == 3)
|
||||
|
||||
#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 CBoxAlgorithmPython3 final : virtual public Toolkit::TBoxAlgorithm<IBoxAlgorithm>
|
||||
{
|
||||
public:
|
||||
void release() override { delete this; }
|
||||
|
||||
uint64_t getClockFrequency() override { return m_clockFrequency << 32; }
|
||||
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_Python3)
|
||||
|
||||
protected:
|
||||
|
||||
uint64_t m_clockFrequency = 0;
|
||||
CString m_scriptFilename;
|
||||
|
||||
std::vector<Toolkit::TDecoder<CBoxAlgorithmPython3>*> m_decoders;
|
||||
std::vector<Toolkit::TEncoder<CBoxAlgorithmPython3>*> 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 v3.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 CBoxAlgorithmPython3Listener 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 CBoxAlgorithmPython3Desc final : virtual public IBoxAlgorithmDesc
|
||||
{
|
||||
public:
|
||||
|
||||
void release() override { }
|
||||
|
||||
CString getName() const override { return CString("Python 3 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_Python3; }
|
||||
IPluginObject* create() override { return new CBoxAlgorithmPython3; }
|
||||
IBoxListener* createBoxListener() const override { return new CBoxAlgorithmPython3Listener; }
|
||||
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_Python3Desc)
|
||||
};
|
||||
} // namespace Python
|
||||
} // namespace Plugins
|
||||
} // namespace OpenViBE
|
||||
|
||||
#endif // #if defined(PY_MAJOR_VERSION) && (PY_MAJOR_VERSION == 3)
|
||||
|
||||
#endif // TARGET_HAS_ThirdPartyPython3
|
||||
+6
@@ -0,0 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
// Boxes
|
||||
//---------------------------------------------------------------------------------------------------
|
||||
#define OVP_ClassId_BoxAlgorithm_Python3 OpenViBE::CIdentifier(0x5DC4F669, 0xD3FD4D63)
|
||||
#define OVP_ClassId_BoxAlgorithm_Python3Desc OpenViBE::CIdentifier(0x404B6FFD, 0x12BDD423)
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
#if defined TARGET_HAS_ThirdPartyPython3 && !(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/ovpCBoxAlgorithmPython3.h"
|
||||
|
||||
#if defined(PY_MAJOR_VERSION) && (PY_MAJOR_VERSION == 3)
|
||||
|
||||
#ifdef TARGET_OS_Windows
|
||||
#include "windows.h"
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
class CPython3Initializer
|
||||
{
|
||||
public:
|
||||
CPython3Initializer();
|
||||
~CPython3Initializer();
|
||||
bool isPython3Available() const { return m_pythonAvailable; }
|
||||
private:
|
||||
#ifdef TARGET_OS_Windows
|
||||
static bool checkPython3Path();
|
||||
#endif
|
||||
// PyThreadState *m_pMainPyThreadState;
|
||||
bool m_pythonAvailable;
|
||||
};
|
||||
|
||||
#ifdef TARGET_OS_Windows
|
||||
bool CPython3Initializer::checkPython3Path()
|
||||
{
|
||||
std::wstring ws(Py_GetPath());
|
||||
std::string path(ws.begin(), ws.end());
|
||||
|
||||
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
|
||||
|
||||
CPython3Initializer::CPython3Initializer() : 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() && checkPython3Path())
|
||||
{
|
||||
Py_Initialize();
|
||||
m_pythonAvailable = true;
|
||||
}
|
||||
}
|
||||
__except (EXCEPTION_EXECUTE_HANDLER) { }
|
||||
#else
|
||||
if (!Py_IsInitialized())
|
||||
{
|
||||
Py_Initialize();
|
||||
m_pythonAvailable = true;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
CPython3Initializer::~CPython3Initializer()
|
||||
{
|
||||
if (m_pythonAvailable)
|
||||
{
|
||||
m_pythonAvailable = false;
|
||||
Py_Finalize();
|
||||
}
|
||||
}
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
namespace OpenViBE {
|
||||
namespace Plugins {
|
||||
namespace Python {
|
||||
|
||||
OVP_Declare_Begin()
|
||||
static CPython3Initializer python3Init;
|
||||
if (python3Init.isPython3Available()) { OVP_Declare_New(CBoxAlgorithmPython3Desc); }
|
||||
OVP_Declare_End()
|
||||
|
||||
} // namespace Python
|
||||
} // namespace Plugins
|
||||
} // namespace OpenViBE
|
||||
//-------------------------------------------------------------------------------------------------
|
||||
|
||||
#else
|
||||
#pragma message ("WARNING: Python 3.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_ThirdPartyPython3
|
||||
Reference in New Issue
Block a user