Mentions légales du service
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
LSL4Unity
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Admin message
GitLab upgrade completed. Current version is 17.11.4.
Show more breadcrumbs
The Openvibe Group
Unity Apps
LSL4Unity
Commits
afc1b3e7
Commit
afc1b3e7
authored
4 years ago
by
MONSEIGNE Thibaut
Browse files
Options
Downloads
Patches
Plain Diff
Add possibilité to just search stream and quit
parent
2a783cd5
No related branches found
No related tags found
No related merge requests found
Pipeline
#217545
passed
4 years ago
Stage: documentation
Stage: deploy
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
OV/OVInlets.cs
+182
-170
182 additions, 170 deletions
OV/OVInlets.cs
with
182 additions
and
170 deletions
OV/OVInlets.cs
+
182
−
170
View file @
afc1b3e7
...
@@ -4,173 +4,185 @@ using UnityEngine;
...
@@ -4,173 +4,185 @@ using UnityEngine;
namespace
LSL4Unity.OV
namespace
LSL4Unity.OV
{
{
/// <summary> Base Inlet for OpenViBE Link. </summary>
/// <summary> Base Inlet for OpenViBE Link. </summary>
/// <seealso cref="MonoBehaviour" />
/// <seealso cref="MonoBehaviour" />
public
abstract
class
OVInlet
<
T
>
:
MonoBehaviour
public
abstract
class
OVInlet
<
T
>
:
MonoBehaviour
{
{
private
enum
UpdateMoment
{
FixedUpdate
,
Update
,
OnDemand
}
private
enum
UpdateMoment
{
FixedUpdate
,
Update
,
OnDemand
}
[
SerializeField
]
private
UpdateMoment
moment
=
UpdateMoment
.
Update
;
[
SerializeField
]
private
UpdateMoment
moment
=
UpdateMoment
.
Update
;
[
SerializeField
]
private
string
streamName
=
"ovSignal"
;
[
SerializeField
]
private
string
streamName
=
"ovSignal"
;
[
SerializeField
]
private
bool
waitStream
=
true
;
public
string
StreamName
=>
streamName
;
public
string
StreamName
=>
streamName
;
protected
liblsl
.
StreamInlet
inlet
;
private
liblsl
.
ContinuousResolver
resolver
;
protected
liblsl
.
StreamInlet
inlet
;
private
liblsl
.
ContinuousResolver
resolver
;
private
bool
readyToResolve
=
true
;
protected
int
expectedChannels
=
0
;
private
bool
readyToResolve
=
true
;
protected
T
[]
samples
;
protected
int
expectedChannels
=
0
;
protected
T
[]
samples
;
/// <summary> Start is called before the first frame update. </summary>
private
void
Start
()
/// <summary> Start is called before the first frame update. </summary>
{
private
void
Start
()
bool
hasAName
=
streamName
.
Length
!=
0
;
{
bool
hasAName
=
streamName
.
Length
!=
0
;
if
(!
hasAName
)
{
if
(!
hasAName
)
Debug
.
LogError
(
"Inlet has to specify a name or a type before it is able to lookup a stream."
);
{
enabled
=
false
;
Debug
.
LogError
(
"Inlet has to specify a name or a type before it is able to lookup a stream."
);
return
;
enabled
=
false
;
}
return
;
}
Debug
.
Log
(
"Creating LSL resolver for stream "
+
streamName
);
resolver
=
new
liblsl
.
ContinuousResolver
(
"name"
,
streamName
);
Debug
.
Log
(
"Creating LSL resolver for stream "
+
streamName
);
resolver
=
new
liblsl
.
ContinuousResolver
(
"name"
,
streamName
);
StartCoroutine
(
ResolveExpectedStream
());
ResolveStream
();
}
}
/// <summary> Fixupdate is called once per physics framerate. </summary>
/// <summary> Fixupdate is called once per physics framerate. </summary>
private
void
FixedUpdate
()
private
void
FixedUpdate
()
{
{
if
(
moment
==
UpdateMoment
.
FixedUpdate
&&
inlet
!=
null
)
{
PullSamples
();
}
if
(
moment
==
UpdateMoment
.
FixedUpdate
&&
inlet
!=
null
)
{
PullSamples
();
}
}
}
/// <summary> Update is called once per frame. </summary>
/// <summary> Update is called once per frame. </summary>
private
void
Update
()
private
void
Update
()
{
{
if
(
moment
==
UpdateMoment
.
Update
&&
inlet
!=
null
)
{
PullSamples
();
}
if
(
moment
==
UpdateMoment
.
Update
&&
inlet
!=
null
)
{
PullSamples
();
}
}
}
/// <summary> ForceUpdate is called when it's needed. </summary>
/// <summary> ForceUpdate is called when it's needed. </summary>
public
void
ForceUpdate
()
{
PullSamples
();
}
public
void
ForceUpdate
()
{
PullSamples
();
}
/// <summary> Resolves the stream. </summary>
/// <summary> Start coroutine to resolve stream. </summary>
/// <returns></returns>
public
void
ResolveStream
()
private
IEnumerator
ResolveExpectedStream
()
{
{
if
(
inlet
==
null
)
{
StartCoroutine
(
ResolveExpectedStream
());
}
yield
return
new
WaitUntil
(()
=>
readyToResolve
);
// False mutex to wait Found Stream before search an other
}
readyToResolve
=
false
;
// Avoïd double resolver
/// <summary> Check if inlet is created. </summary>
liblsl
.
StreamInfo
[]
results
=
resolver
.
Results
();
public
bool
IsSolved
()
{
return
(
inlet
!=
null
);
}
yield
return
new
WaitUntil
(()
=>
results
.
Length
>
0
);
private
void
CreateInlet
(
liblsl
.
StreamInfo
result
)
Debug
.
Log
(
$"Resolving Stream : Name =
{
streamName
}
, Steam Info Name =
{
results
[
0
].
Name
()}
, Stream Info Type = (
{
results
[
0
].
Type
()}
"
);
{
Debug
.
Log
(
$"Resolving Stream : Name =
{
streamName
}
, Steam Info Name =
{
result
.
Name
()}
, Stream Info Type = (
{
result
.
Type
()}
"
);
inlet
=
new
liblsl
.
StreamInlet
(
results
[
0
]);
inlet
=
new
liblsl
.
StreamInlet
(
result
);
expectedChannels
=
inlet
.
Info
().
ChannelCount
();
expectedChannels
=
inlet
.
Info
().
ChannelCount
();
}
readyToResolve
=
true
;
yield
return
null
;
/// <summary> Resolves the stream. </summary>
}
/// <returns></returns>
private
IEnumerator
ResolveExpectedStream
()
/// <summary> Pull the samples. </summary>
{
protected
abstract
void
PullSamples
();
Debug
.
Log
(
$"private IEnumerator ResolveExpectedStream()"
);
yield
return
new
WaitUntil
(()
=>
readyToResolve
);
// False mutex to wait Found Stream before search an other
/// <summary> Override this method in the subclass to specify what should happen when samples are available. </summary>
readyToResolve
=
false
;
// Avoïd double resolver
/// <param name="input"> The Incomming Sample. </param>
/// <param name="time"> The current Time. </param>
liblsl
.
StreamInfo
[]
results
=
resolver
.
Results
();
protected
abstract
void
Process
(
T
[]
input
,
double
time
);
if
(
waitStream
)
{
yield
return
new
WaitUntil
(()
=>
results
.
Length
>
0
);
}
}
if
(
results
.
Length
>
0
)
{
CreateInlet
(
results
[
0
]);
}
readyToResolve
=
true
;
/// <summary> Float Inlet for OpenViBE Link. </summary>
yield
return
null
;
/// <seealso cref="OVInlet{T}" />
}
public
abstract
class
OVFloatInlet
:
OVInlet
<
float
>
{
/// <summary> Pull the samples. </summary>
/// <inheritdoc cref="OVInlet{T}.PullSamples"/>
protected
abstract
void
PullSamples
();
protected
override
void
PullSamples
()
{
/// <summary> Override this method in the subclass to specify what should happen when samples are available. </summary>
samples
=
new
float
[
expectedChannels
];
/// <param name="input"> The Incomming Sample. </param>
/// <param name="time"> The current Time. </param>
try
protected
abstract
void
Process
(
T
[]
input
,
double
time
);
{
}
double
lastTimeStamp
=
inlet
.
PullSample
(
samples
,
0.0f
);
/// <summary> Float Inlet for OpenViBE Link. </summary>
if
(
Math
.
Abs
(
lastTimeStamp
)
>
Constants
.
TOLERANCE
)
/// <seealso cref="OVInlet{T}" />
{
public
abstract
class
OVFloatInlet
:
OVInlet
<
float
>
// do not miss the first one found
{
Process
(
samples
,
lastTimeStamp
);
/// <inheritdoc cref="OVInlet{T}.PullSamples"/>
// pull as long samples are available
protected
override
void
PullSamples
()
while
(
Math
.
Abs
(
lastTimeStamp
=
inlet
.
PullSample
(
samples
,
0.0f
))
>
Constants
.
TOLERANCE
)
{
Process
(
samples
,
lastTimeStamp
);
}
{
}
samples
=
new
float
[
expectedChannels
];
}
catch
(
ArgumentException
e
)
try
{
{
Debug
.
LogError
(
"An Error on pulling samples deactivating LSL inlet on..."
,
this
);
double
lastTimeStamp
=
inlet
.
PullSample
(
samples
,
0.0f
);
enabled
=
false
;
Debug
.
LogException
(
e
,
this
);
if
(
Math
.
Abs
(
lastTimeStamp
)
>
Constants
.
TOLERANCE
)
}
{
}
// do not miss the first one found
}
Process
(
samples
,
lastTimeStamp
);
// pull as long samples are available
/// <summary> Double Inlet for OpenViBE Link. </summary>
while
(
Math
.
Abs
(
lastTimeStamp
=
inlet
.
PullSample
(
samples
,
0.0f
))
>
Constants
.
TOLERANCE
)
{
Process
(
samples
,
lastTimeStamp
);
}
/// <seealso cref="OVInlet{T}" />
}
public
abstract
class
OVDoubleInlet
:
OVInlet
<
double
>
}
{
catch
(
ArgumentException
e
)
/// <inheritdoc cref="OVInlet{T}.PullSamples"/>
{
protected
override
void
PullSamples
()
Debug
.
LogError
(
"An Error on pulling samples deactivating LSL inlet on..."
,
this
);
{
enabled
=
false
;
samples
=
new
double
[
expectedChannels
];
Debug
.
LogException
(
e
,
this
);
}
try
}
{
}
double
lastTimeStamp
=
inlet
.
PullSample
(
samples
,
0.0f
);
/// <summary> Double Inlet for OpenViBE Link. </summary>
if
(
Math
.
Abs
(
lastTimeStamp
)
>
Constants
.
TOLERANCE
)
/// <seealso cref="OVInlet{T}" />
{
public
abstract
class
OVDoubleInlet
:
OVInlet
<
double
>
// do not miss the first one found
{
Process
(
samples
,
lastTimeStamp
);
/// <inheritdoc cref="OVInlet{T}.PullSamples"/>
// pull as long samples are available
protected
override
void
PullSamples
()
while
(
Math
.
Abs
(
lastTimeStamp
=
inlet
.
PullSample
(
samples
,
0.0f
))
>
Constants
.
TOLERANCE
)
{
Process
(
samples
,
lastTimeStamp
);
}
{
}
samples
=
new
double
[
expectedChannels
];
}
catch
(
ArgumentException
e
)
try
{
{
Debug
.
LogError
(
"An Error on pulling samples deactivating LSL inlet on..."
,
this
);
double
lastTimeStamp
=
inlet
.
PullSample
(
samples
,
0.0f
);
enabled
=
false
;
Debug
.
LogException
(
e
,
this
);
if
(
Math
.
Abs
(
lastTimeStamp
)
>
Constants
.
TOLERANCE
)
}
{
}
// do not miss the first one found
}
Process
(
samples
,
lastTimeStamp
);
// pull as long samples are available
/// <summary> Int Inlet for OpenViBE Link. </summary>
while
(
Math
.
Abs
(
lastTimeStamp
=
inlet
.
PullSample
(
samples
,
0.0f
))
>
Constants
.
TOLERANCE
)
{
Process
(
samples
,
lastTimeStamp
);
}
/// <seealso cref="OVInlet{T}" />
}
public
abstract
class
OVIntInlet
:
OVInlet
<
int
>
}
{
catch
(
ArgumentException
e
)
/// <inheritdoc cref="OVInlet{T}.PullSamples"/>
{
protected
override
void
PullSamples
()
Debug
.
LogError
(
"An Error on pulling samples deactivating LSL inlet on..."
,
this
);
{
enabled
=
false
;
samples
=
new
int
[
expectedChannels
];
Debug
.
LogException
(
e
,
this
);
}
try
}
{
}
double
lastTimeStamp
=
inlet
.
PullSample
(
samples
,
0.0f
);
/// <summary> Int Inlet for OpenViBE Link. </summary>
if
(
Math
.
Abs
(
lastTimeStamp
)
>
Constants
.
TOLERANCE
)
/// <seealso cref="OVInlet{T}" />
{
public
abstract
class
OVIntInlet
:
OVInlet
<
int
>
// do not miss the first one found
{
Process
(
samples
,
lastTimeStamp
);
/// <inheritdoc cref="OVInlet{T}.PullSamples"/>
// pull as long samples are available
protected
override
void
PullSamples
()
while
(
Math
.
Abs
(
lastTimeStamp
=
inlet
.
PullSample
(
samples
,
0.0f
))
>
Constants
.
TOLERANCE
)
{
Process
(
samples
,
lastTimeStamp
);
}
{
}
samples
=
new
int
[
expectedChannels
];
}
catch
(
ArgumentException
e
)
try
{
{
Debug
.
LogError
(
"An Error on pulling samples deactivating LSL inlet on..."
,
this
);
double
lastTimeStamp
=
inlet
.
PullSample
(
samples
,
0.0f
);
enabled
=
false
;
Debug
.
LogException
(
e
,
this
);
if
(
Math
.
Abs
(
lastTimeStamp
)
>
Constants
.
TOLERANCE
)
}
{
}
// do not miss the first one found
}
Process
(
samples
,
lastTimeStamp
);
}
// pull as long samples are available
while
(
Math
.
Abs
(
lastTimeStamp
=
inlet
.
PullSample
(
samples
,
0.0f
))
>
Constants
.
TOLERANCE
)
{
Process
(
samples
,
lastTimeStamp
);
}
}
}
catch
(
ArgumentException
e
)
{
Debug
.
LogError
(
"An Error on pulling samples deactivating LSL inlet on..."
,
this
);
enabled
=
false
;
Debug
.
LogException
(
e
,
this
);
}
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment