diff --git a/Demos/CubeRotation.cs b/Demos/CubeRotation.cs index a565a644cad3c038e2a3254ffcd42f916d8edd95..4ba189433cce6200019ee1df1489dccb39e4bdca 100644 --- a/Demos/CubeRotation.cs +++ b/Demos/CubeRotation.cs @@ -1,25 +1,25 @@ -using UnityEngine; +using UnityEngine; namespace LSL4Unity.Demos { public class CubeRotation : MonoBehaviour { - private float _yawSpeed = 1.0f; - private float _pitchSpeed = 1.0f; - private float _rollSpeed = 1.0f; + private float yawSpeed = 1.0f; + private float pitchSpeed = 1.0f; + private float rollSpeed = 1.0f; private void Update() { - if (Input.GetKey("a")) { _yawSpeed += 1; } - if (Input.GetKey("d") && _yawSpeed > 0) { _yawSpeed -= 1; } + if (Input.GetKey("a")) { yawSpeed += 1; } + if (Input.GetKey("d") && yawSpeed > 0) { yawSpeed -= 1; } - if (Input.GetKey("w")) { _pitchSpeed += 1; } - if (Input.GetKey("s") && _pitchSpeed > 0) { _pitchSpeed -= 1; } + if (Input.GetKey("w")) { pitchSpeed += 1; } + if (Input.GetKey("s") && pitchSpeed > 0) { pitchSpeed -= 1; } - if (Input.GetKey("e")) { _rollSpeed += 1; } - if (Input.GetKey("q") && _rollSpeed > 0) { _rollSpeed -= 1; } + if (Input.GetKey("e")) { rollSpeed += 1; } + if (Input.GetKey("q") && rollSpeed > 0) { rollSpeed -= 1; } - transform.rotation *= Quaternion.Euler(_yawSpeed * Time.deltaTime, _pitchSpeed * Time.deltaTime, _rollSpeed * Time.deltaTime); + transform.rotation *= Quaternion.Euler(yawSpeed * Time.deltaTime, pitchSpeed * Time.deltaTime, rollSpeed * Time.deltaTime); } } } diff --git a/Demos/LSLTransformDemoOutlet.cs b/Demos/LSLTransformDemoOutlet.cs index 82883fe6a77478c13c4be0a28137eda754a1af48..aa6b38edbab9be016189a89079d50df6d6547a20 100644 --- a/Demos/LSLTransformDemoOutlet.cs +++ b/Demos/LSLTransformDemoOutlet.cs @@ -1,71 +1,67 @@ -using LSL4Unity.Scripts; using UnityEngine; namespace LSL4Unity.Demos { - /// <summary> - /// An reusable example of an outlet which provides the orientation of an entity to LSL - /// </summary> + /// <summary> An reusable example of an outlet which provides the orientation of an entity to LSL. </summary> public class LSLTransformDemoOutlet : MonoBehaviour { private const string UNIQUE_SOURCE_ID = "D256CFBDBA3145978CFA641403219531"; - private liblsl.StreamOutlet _outlet; - private liblsl.StreamInfo _streamInfo; - public liblsl.StreamInfo GetStreamInfo() { return _streamInfo; } + private liblsl.StreamOutlet outlet; + private liblsl.StreamInfo info; + //public liblsl.StreamInfo GetStreamInfo() { return info; } - /// <summary> Use a array to reduce allocation costs. </summary> - private float[] _currentSample; - - private double _dataRate; + public string streamName = "BeMoBI.Unity.Orientation.<Add_a_entity_id_here>"; + public string streamType = "Unity.Quaternion"; + public int channelCount = 4; - public double GetDataRate() { return _dataRate; } - public bool HasConsumer() { return _outlet != null && _outlet.HaveConsumers(); } + public MomentForSampling sampling; + public Transform sampleSource; - public string StreamName = "BeMoBI.Unity.Orientation.<Add_a_entity_id_here>"; - public string StreamType = "Unity.Quaternion"; - public int ChannelCount = 4; + /// <summary> Use a array to reduce allocation costs. </summary> + private float[] sample; - public MomentForSampling Sampling; + private double dataRate; - public Transform SampleSource; + public double GetDataRate() { return dataRate; } + public bool HasConsumer() { return outlet != null && outlet.HaveConsumers(); } private void Start() { // initialize the array once - _currentSample = new float[ChannelCount]; - _dataRate = LSLUtils.GetSamplingRateFor(Sampling); - _streamInfo = new liblsl.StreamInfo(StreamName, StreamType, ChannelCount, _dataRate, liblsl.channel_format_t.cf_float32, UNIQUE_SOURCE_ID); - _outlet = new liblsl.StreamOutlet(_streamInfo); + sample = new float[channelCount]; + dataRate = LSLUtils.GetSamplingRateFor(sampling); + info = new liblsl.StreamInfo(streamName, streamType, channelCount, dataRate, liblsl.channel_format_t.cf_float32, UNIQUE_SOURCE_ID); + outlet = new liblsl.StreamOutlet(info); } private void PushSample() { - if (_outlet == null) { return; } - var rotation = SampleSource.rotation; + if (outlet == null) { return; } + var rotation = sampleSource.rotation; // reuse the array for each sample to reduce allocation costs - _currentSample[0] = rotation.x; - _currentSample[1] = rotation.y; - _currentSample[2] = rotation.z; - _currentSample[3] = rotation.w; + sample[0] = rotation.x; + sample[1] = rotation.y; + sample[2] = rotation.z; + sample[3] = rotation.w; - _outlet.PushSample(_currentSample, liblsl.LocalClock()); + outlet.PushSample(sample, liblsl.LocalClock()); } private void FixedUpdate() { - if (Sampling == MomentForSampling.FixedUpdate) { PushSample(); } + if (sampling == MomentForSampling.FixedUpdate) { PushSample(); } } private void Update() { - if (Sampling == MomentForSampling.Update) { PushSample(); } + if (sampling == MomentForSampling.Update) { PushSample(); } } private void LateUpdate() { - if (Sampling == MomentForSampling.LateUpdate) { PushSample(); } + if (sampling == MomentForSampling.LateUpdate) { PushSample(); } } } } diff --git a/Demos/RandomMarker.cs b/Demos/RandomMarker.cs index 344917171c28c4c8c8852dedaaf2e9e81c480cad..4532f941fe48708cfd93a6e6f34264d677e1094c 100644 --- a/Demos/RandomMarker.cs +++ b/Demos/RandomMarker.cs @@ -1,5 +1,4 @@ -using System.Collections; -using LSL4Unity.Scripts; +using System.Collections; using UnityEngine; using UnityEngine.Assertions; @@ -7,13 +6,13 @@ namespace LSL4Unity.Demos { public class RandomMarker : MonoBehaviour { - public LSLMarkerStream MarkerStream; + public LSLMarkerStream stream; private void Start() { - Assert.IsNotNull(MarkerStream, "You forgot to assign the reference to a marker stream implementation!"); + Assert.IsNotNull(stream, "You forgot to assign the reference to a marker stream implementation!"); - if (MarkerStream != null) { StartCoroutine(WriteContinouslyMarkerEachSecond()); } + if (stream != null) { StartCoroutine(WriteContinouslyMarkerEachSecond()); } } private IEnumerator WriteContinouslyMarkerEachSecond() @@ -21,8 +20,8 @@ namespace LSL4Unity.Demos while (true) { // an example for demonstrating the usage of marker stream - var currentMarker = GetARandomMarker(); - MarkerStream.Write(currentMarker); + string currentMarker = GetARandomMarker(); + stream.Write(currentMarker); yield return new WaitForSecondsRealtime(1f); } } diff --git a/Demos/StreamInfo.cs b/Demos/StreamInfo.cs index ebad639366cd750d25cc27f7244955bac9f5a3bd..e0e195c75e39c6d658db50a2a74a180eae9ffe4b 100644 --- a/Demos/StreamInfo.cs +++ b/Demos/StreamInfo.cs @@ -1,38 +1,38 @@ -using UnityEngine; +using UnityEngine; using UnityEngine.UI; namespace LSL4Unity.Demos { public class StreamInfo : MonoBehaviour { - public LSLTransformDemoOutlet Outlet; + public LSLTransformDemoOutlet outlet; - public Text StreamNameLabel; - public Text StreamTypeLabel; - public Text DataRate; - public Text HasConsumerLabel; + public Text streamNameLabel; + public Text streamTypeLabel; + public Text dataRate; + public Text hasConsumerLabel; // Use this for initialization private void Start() { - StreamNameLabel.text = Outlet.StreamName; - StreamTypeLabel.text = Outlet.StreamType; - DataRate.text = $"Data Rate: {Outlet.GetDataRate()}"; - HasConsumerLabel.text = "Has no consumers"; + streamNameLabel.text = outlet.streamName; + streamTypeLabel.text = outlet.streamType; + dataRate.text = $"Data Rate: {outlet.GetDataRate()}"; + hasConsumerLabel.text = "Has no consumers"; } // Update is called once per frame private void Update() { - if (Outlet.HasConsumer()) + if (outlet.HasConsumer()) { - HasConsumerLabel.text = "Has consumers"; - HasConsumerLabel.color = Color.green; + hasConsumerLabel.text = "Has consumers"; + hasConsumerLabel.color = Color.green; } else { - HasConsumerLabel.text = "No Consumers"; - HasConsumerLabel.color = Color.black; + hasConsumerLabel.text = "No Consumers"; + hasConsumerLabel.color = Color.black; } } } diff --git a/Editor/BuildHooks.cs b/Editor/BuildHooks.cs index f0fc520377b9147316bd3ecc62d663e69bb3733f..ed9f26691a66d46b0df371c16515aaad5faec5dd 100644 --- a/Editor/BuildHooks.cs +++ b/Editor/BuildHooks.cs @@ -1,4 +1,3 @@ -using System; using System.IO; using UnityEditor; using UnityEditor.Callbacks; @@ -14,48 +13,39 @@ namespace LSL4Unity.Editor [PostProcessBuild(1)] public static void OnPostprocessBuild(BuildTarget target, string pathToBuiltProject) { - var buildName = Path.GetFileNameWithoutExtension(pathToBuiltProject); - - var buildHostDirectory = pathToBuiltProject.Replace(Path.GetFileName(pathToBuiltProject), ""); - - var dataDirectoryName = buildName + "_Data"; - - var pathToDataDirectory = Path.Combine(buildHostDirectory, dataDirectoryName); - - var pluginDirectory = Path.Combine(pathToDataDirectory, PLUGIN_DIR); + var buildDir = Path.GetFileNameWithoutExtension(pathToBuiltProject); + var buildHostDir = pathToBuiltProject.Replace(Path.GetFileName(pathToBuiltProject), ""); + var dataDir = buildDir + "_Data"; + var pathToDataDir = Path.Combine(buildHostDir, dataDir); + var pluginDir = Path.Combine(pathToDataDir, PLUGIN_DIR); switch (target) { case BuildTarget.StandaloneWindows: - RenameLibFile(pluginDirectory, LSLEditorIntegration.LIB32_NAME, LSLEditorIntegration.LIB64_NAME, LSLEditorIntegration.DLL_ENDING); + RenameLibFile(pluginDir, LSLEditorIntegration.LIB32_NAME, LSLEditorIntegration.LIB64_NAME, LSLEditorIntegration.DLL_ENDING); break; case BuildTarget.StandaloneWindows64: - RenameLibFile(pluginDirectory, LSLEditorIntegration.LIB64_NAME, LSLEditorIntegration.LIB32_NAME, LSLEditorIntegration.DLL_ENDING); + RenameLibFile(pluginDir, LSLEditorIntegration.LIB64_NAME, LSLEditorIntegration.LIB32_NAME, LSLEditorIntegration.DLL_ENDING); break; case BuildTarget.StandaloneLinux64: - RenameLibFile(pluginDirectory, LSLEditorIntegration.LIB64_NAME, LSLEditorIntegration.LIB32_NAME, LSLEditorIntegration.SO_ENDING); + RenameLibFile(pluginDir, LSLEditorIntegration.LIB64_NAME, LSLEditorIntegration.LIB32_NAME, LSLEditorIntegration.SO_ENDING); break; case BuildTarget.StandaloneOSX: - RenameLibFile(pluginDirectory, LSLEditorIntegration.LIB64_NAME, LSLEditorIntegration.LIB32_NAME, LSLEditorIntegration.BUNDLE_ENDING); + RenameLibFile(pluginDir, LSLEditorIntegration.LIB64_NAME, LSLEditorIntegration.LIB32_NAME, LSLEditorIntegration.BUNDLE_ENDING); break; } } - private static void RenameLibFile(string pluginDirectory, string sourceName, string nameOfObsoleteFile, string fileEnding) + private static void RenameLibFile(string pluginDir, string srcName, string oldName, string extension) { - var obsoleteFile = Path.Combine(pluginDirectory, nameOfObsoleteFile + fileEnding); - - Debug.Log("[LSL BUILD Hook] Delete obsolete file: " + obsoleteFile); - - File.Delete(obsoleteFile); - - var sourceFile = Path.Combine(pluginDirectory, sourceName + fileEnding); - - var targetFile = Path.Combine(pluginDirectory, LIB_LSL_NAME + fileEnding); - - Debug.Log($"[LSL BUILD Hook] Renaming: {sourceFile} to {targetFile}"); - - File.Move(sourceFile, targetFile); + var oldFile = Path.Combine(pluginDir, oldName + extension); + Debug.Log("[LSL BUILD Hook] Delete obsolete file: " + oldFile); + File.Delete(oldFile); + + var srcFile = Path.Combine(pluginDir, srcName + extension); + var dstFile = Path.Combine(pluginDir, LIB_LSL_NAME + extension); + Debug.Log($"[LSL BUILD Hook] Renaming: {srcFile} to {dstFile}"); + File.Move(srcFile, dstFile); } } } diff --git a/Editor/LSLEditorIntegration.cs b/Editor/LSLEditorIntegration.cs index bf3a2ce148bf79ece6a2c793975653c7d1679a67..80a58fdcc95f7970cd7a38c516c9fcf6216a1955 100644 --- a/Editor/LSLEditorIntegration.cs +++ b/Editor/LSLEditorIntegration.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using System.Linq; using UnityEditor; using UnityEngine; @@ -8,12 +8,11 @@ namespace LSL4Unity.Editor { public class LSLEditorIntegration { - public const string LIB64_NAME = "liblsl64"; - public const string LIB32_NAME = "liblsl32"; - public const string DLL_ENDING = ".dll"; - public const string SO_ENDING = ".so"; - public const string BUNDLE_ENDING = ".bundle"; - + public const string LIB64_NAME = "liblsl64"; + public const string LIB32_NAME = "liblsl32"; + public const string DLL_ENDING = ".dll"; + public const string SO_ENDING = ".so"; + public const string BUNDLE_ENDING = ".bundle"; private const string WIKI_URL = "https://github.com/xfleckx/LSL4Unity/wiki"; private const string WRAPPER_FILENAME = "LSL.cs"; private const string ASSET_SUB_FOLDER = "LSL4Unity"; diff --git a/Editor/LSLEditorWindow.cs b/Editor/LSLEditorWindow.cs index 17f7ae6e23d4babdbaa1ef3dbf5968c7a6296a1e..6a0f11d715b8adcdaa3cd80dbe5a92cd2314e454 100644 --- a/Editor/LSLEditorWindow.cs +++ b/Editor/LSLEditorWindow.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using UnityEditor; using UnityEngine; @@ -13,27 +13,27 @@ namespace LSL4Unity.Editor //private const string CLICK_LOOK_UP_FIRST = "Click lookup first"; - private readonly List<string> _listNamesOfStreams = new List<string>(); + private readonly List<string> namesOfStreams = new List<string>(); - private Vector2 _scrollVector; - private string _streamLookUpResult; + private Vector2 scrollVector; + private string streamLookUpResult; - private liblsl.ContinuousResolver _resolver; - private string _lslVersionInfos; + private liblsl.ContinuousResolver resolver; + private string lslVersionInfos; public void Init() { - _resolver = new liblsl.ContinuousResolver(); + resolver = new liblsl.ContinuousResolver(); - var libVersion = liblsl.LibraryVersion(); - var protocolVersion = liblsl.ProtocolVersion(); + int libVersion = liblsl.LibraryVersion(); + int protocolVersion = liblsl.ProtocolVersion(); - var libMajor = libVersion / 100; - var libMinor = libVersion % 100; - var protMajor = protocolVersion / 100; - var protMinor = protocolVersion % 100; + int libMajor = libVersion / 100; + int libMinor = libVersion % 100; + int protMajor = protocolVersion / 100; + int protMinor = protocolVersion % 100; - _lslVersionInfos = $"You are using LSL library: {libMajor}.{libMinor} implementing protocol version: {protMajor}.{protMinor}"; + lslVersionInfos = $"You are using LSL library: {libMajor}.{libMinor} implementing protocol version: {protMajor}.{protMinor}"; titleContent = new GUIContent("LSL Utility"); } @@ -42,20 +42,20 @@ namespace LSL4Unity.Editor private void OnGUI() { - if (_resolver == null) { Init(); } + if (resolver == null) { Init(); } UpdateStreams(); EditorGUILayout.BeginVertical(); EditorGUILayout.Space(); - EditorGUILayout.LabelField(_lslVersionInfos, EditorStyles.miniLabel); + EditorGUILayout.LabelField(lslVersionInfos, EditorStyles.miniLabel); EditorGUILayout.BeginHorizontal(); - EditorGUILayout.LabelField(_streamLookUpResult, EditorStyles.boldLabel); + EditorGUILayout.LabelField(streamLookUpResult, EditorStyles.boldLabel); EditorGUILayout.EndHorizontal(); EditorGUILayout.Space(); EditorGUILayout.Separator(); - _scrollVector = EditorGUILayout.BeginScrollView(_scrollVector, GUILayout.Width(EditorGUIUtility.currentViewWidth)); + scrollVector = EditorGUILayout.BeginScrollView(scrollVector, GUILayout.Width(EditorGUIUtility.currentViewWidth)); GUILayoutOption fieldWidth = GUILayout.Width(EditorGUIUtility.currentViewWidth / 4.3f); EditorGUILayout.BeginHorizontal(); @@ -66,7 +66,7 @@ namespace LSL4Unity.Editor EditorGUILayout.LabelField("Data Rate", EditorStyles.boldLabel, fieldWidth); EditorGUILayout.EndHorizontal(); - foreach (var item in _listNamesOfStreams) + foreach (string item in namesOfStreams) { string[] s = item.Split(' '); @@ -83,14 +83,14 @@ namespace LSL4Unity.Editor private void UpdateStreams() { - _listNamesOfStreams.Clear(); - _streamInfos = _resolver.Results(); + namesOfStreams.Clear(); + _streamInfos = resolver.Results(); - if (_streamInfos.Length == 0) { _streamLookUpResult = NO_STREAMS_FOUND; } + if (_streamInfos.Length == 0) { streamLookUpResult = NO_STREAMS_FOUND; } else { - foreach (var item in _streamInfos) { _listNamesOfStreams.Add($"{item.Name()} {item.Type()} {item.Hostname()} {item.Sampling()}"); } - _streamLookUpResult = _listNamesOfStreams.Count + N_STREAMS_FOUND; + foreach (liblsl.StreamInfo item in _streamInfos) { namesOfStreams.Add($"{item.Name()} {item.Type()} {item.Hostname()} {item.Sampling()}"); } + streamLookUpResult = namesOfStreams.Count + N_STREAMS_FOUND; } } } diff --git a/Editor/ScriptOrderManagement.cs b/Editor/ScriptOrderManagement.cs index a5a510e271a35e0e29a51043e57c6703b6155be8..2c2153fe1cd25f519625041d93624ab2e15fda8b 100644 --- a/Editor/ScriptOrderManagement.cs +++ b/Editor/ScriptOrderManagement.cs @@ -1,5 +1,4 @@ -using System; -using LSL4Unity.Scripts; +using System; using UnityEditor; namespace LSL4Unity.Editor @@ -13,10 +12,10 @@ namespace LSL4Unity.Editor { if (monoScript.GetClass() != null) { - foreach (var a in Attribute.GetCustomAttributes(monoScript.GetClass(), typeof(ScriptOrder))) + foreach (Attribute a in Attribute.GetCustomAttributes(monoScript.GetClass(), typeof(ScriptOrder))) { - var currentOrder = MonoImporter.GetExecutionOrder(monoScript); - var newOrder = ((ScriptOrder) a).Order; + int currentOrder = MonoImporter.GetExecutionOrder(monoScript); + int newOrder = ((ScriptOrder)a).order; if (currentOrder != newOrder) { MonoImporter.SetExecutionOrder(monoScript, newOrder); } } } diff --git a/Editor/TimeSyncEditor.cs b/Editor/TimeSyncEditor.cs index 1c311f75ab6c0d307f7a9a572ff7742ec1da589f..e8e8da5b370fa67d77192ac8260d4392cf7a81cc 100644 --- a/Editor/TimeSyncEditor.cs +++ b/Editor/TimeSyncEditor.cs @@ -1,4 +1,3 @@ -using LSL4Unity.Scripts; using UnityEditor; namespace LSL4Unity.Editor diff --git a/LSL.cs b/LSL.cs index db07b643076abf17bd8eff4486519d426effa9fa..4f349ea470e9ed1f36797970398945b68ca12943 100644 --- a/LSL.cs +++ b/LSL.cs @@ -29,7 +29,7 @@ namespace LSL4Unity public const double DEDUCED_TIMESTAMP = -1.0; /// <summary> A very large time duration (> 1 year) for timeout values. </summary> - /// <remarks>Note that significantly larger numbers can cause the timeout to be invalid on some operating systems (e.g., 32-bit UNIX).</remarks> + /// <remarks> Note that significantly larger numbers can cause the timeout to be invalid on some operating systems (e.g., 32-bit UNIX). </remarks> public const double FOREVER = 32000000.0; /// <summary> Data format of a channel (each transmitted sample holds an array of channels). </summary> diff --git a/Scripts/AInlet.cs b/Scripts/AInlet.cs index d0e827862290c8a26a67ed82f18cadb0571316ad..b1930dfe506848c2675117c603739b03e7aaa533 100644 --- a/Scripts/AInlet.cs +++ b/Scripts/AInlet.cs @@ -1,11 +1,11 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; -using LSL4Unity.Scripts.OV; +using LSL4Unity.OV; using UnityEngine; -namespace LSL4Unity.Scripts +namespace LSL4Unity { /// <summary> Float Inlet. </summary> /// <seealso cref="UnityEngine.MonoBehaviour" /> @@ -13,23 +13,22 @@ namespace LSL4Unity.Scripts { public enum UpdateMoment { FixedUpdate, Update } - public UpdateMoment Moment; + public UpdateMoment moment; - public string StreamName; - public string StreamType; + public string streamName; + public string streamType; - private liblsl.StreamInfo[] _results; - private liblsl.StreamInlet _inlet; - private liblsl.ContinuousResolver _resolver; + private liblsl.StreamInlet inlet; + private liblsl.ContinuousResolver resolver; - private int _expectedChannels = 0; + private int expectedChannels = 0; - private float[] _sample; + private float[] sample; private void Start() { - var hasAName = StreamName.Length != 0; - var hasAType = StreamType.Length != 0; + bool hasAName = streamName.Length != 0; + bool hasAType = streamType.Length != 0; if (!hasAName && !hasAType) { @@ -40,13 +39,13 @@ namespace LSL4Unity.Scripts if (hasAName) { - 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); } - else // if (expectedStreamHasAType) // Useless with the first if + else // if (hasAType) // Useless with the first if { - Debug.Log("Creating LSL resolver for stream with type " + StreamType); - _resolver = new liblsl.ContinuousResolver("type ", StreamType); + Debug.Log("Creating LSL resolver for stream with type " + streamType); + resolver = new liblsl.ContinuousResolver("type ", streamType); } StartCoroutine(ResolveExpectedStream()); @@ -59,40 +58,40 @@ namespace LSL4Unity.Scripts private IEnumerator ResolveExpectedStream() { - var results = _resolver.Results(); + var results = resolver.Results(); yield return new WaitUntil(() => results.Length > 0); - Debug.Log($"Resolving Stream: {StreamName}"); + Debug.Log($"Resolving Stream: {streamName}"); - _inlet = new liblsl.StreamInlet(results[0]); + inlet = new liblsl.StreamInlet(results[0]); - _expectedChannels = _inlet.Info().ChannelCount(); + expectedChannels = inlet.Info().ChannelCount(); yield return null; } protected void PullSamples() { - _sample = new float[_expectedChannels]; + sample = new float[expectedChannels]; try { - double lastTimeStamp = _inlet.PullSample(_sample, 0.0f); + double lastTimeStamp = inlet.PullSample(sample, 0.0f); if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE) { // do not miss the first one found - Process(_sample, lastTimeStamp); + Process(sample, lastTimeStamp); // pull as long samples are available - while (Math.Abs(lastTimeStamp = _inlet.PullSample(_sample, 0.0f)) > Constants.TOLERANCE) { Process(_sample, lastTimeStamp); } + while (Math.Abs(lastTimeStamp = inlet.PullSample(sample, 0.0f)) > Constants.TOLERANCE) { Process(sample, lastTimeStamp); } } } - catch (ArgumentException aex) + catch (ArgumentException e) { Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this); enabled = false; - Debug.LogException(aex, this); + Debug.LogException(e, this); } } @@ -103,12 +102,12 @@ namespace LSL4Unity.Scripts private void FixedUpdate() { - if (Moment == UpdateMoment.FixedUpdate && _inlet != null) { PullSamples(); } + if (moment == UpdateMoment.FixedUpdate && inlet != null) { PullSamples(); } } private void Update() { - if (Moment == UpdateMoment.Update && _inlet != null) { PullSamples(); } + if (moment == UpdateMoment.Update && inlet != null) { PullSamples(); } } } @@ -118,40 +117,39 @@ namespace LSL4Unity.Scripts { public enum UpdateMoment { FixedUpdate, Update } - public UpdateMoment Moment; + public UpdateMoment moment; - public string StreamName; - public string StreamType; + public string streamName; + public string streamType; - private liblsl.StreamInfo[] _results; - private liblsl.StreamInlet _inlet; - private liblsl.ContinuousResolver _resolver; + private liblsl.StreamInlet inlet; + private liblsl.ContinuousResolver resolver; - private int _expectedChannels = 0; + private int expectedChannels = 0; - private double[] _sample; + private double[] sample; private void Start() { - var expectedStreamHasAName = !StreamName.Equals(""); - var expectedStreamHasAType = !StreamType.Equals(""); + bool hasAName = streamName.Length != 0; + bool hasAType = streamType.Length != 0; - if (!expectedStreamHasAName && !expectedStreamHasAType) + if (!hasAName && !hasAType) { Debug.LogError("Inlet has to specify a name or a type before it is able to lookup a stream."); enabled = false; return; } - if (expectedStreamHasAName) + if (hasAName) { - 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); } - else // if (expectedStreamHasAType) // Useless with the first if + else // if (hasAType) // Useless with the first if { - Debug.Log("Creating LSL resolver for stream with type " + StreamType); - _resolver = new liblsl.ContinuousResolver("type", StreamType); + Debug.Log("Creating LSL resolver for stream with type " + streamType); + resolver = new liblsl.ContinuousResolver("type", streamType); } StartCoroutine(ResolveExpectedStream()); @@ -164,15 +162,15 @@ namespace LSL4Unity.Scripts private IEnumerator ResolveExpectedStream() { - var results = _resolver.Results(); + var results = resolver.Results(); - while (_inlet == null) + while (inlet == null) { yield return new WaitUntil(() => results.Length > 0); - _inlet = new liblsl.StreamInlet(GetStreamInfoFrom(results)); + inlet = new liblsl.StreamInlet(GetStreamInfoFrom(results)); - _expectedChannels = _inlet.Info().ChannelCount(); + expectedChannels = inlet.Info().ChannelCount(); } yield return null; @@ -180,31 +178,31 @@ namespace LSL4Unity.Scripts private liblsl.StreamInfo GetStreamInfoFrom(IEnumerable<liblsl.StreamInfo> results) { - var targetInfo = results.First(r => r.Name().Equals(StreamName)); + var targetInfo = results.First(r => r.Name().Equals(streamName)); return targetInfo; } protected void PullSamples() { - _sample = new double[_expectedChannels]; + sample = new double[expectedChannels]; try { - double lastTimeStamp = _inlet.PullSample(_sample, 0.0f); + double lastTimeStamp = inlet.PullSample(sample, 0.0f); if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE) { // do not miss the first one found - Process(_sample, lastTimeStamp); + Process(sample, lastTimeStamp); // pull as long samples are available - while (Math.Abs(lastTimeStamp = _inlet.PullSample(_sample, 0.0f)) > Constants.TOLERANCE) { Process(_sample, lastTimeStamp); } + while (Math.Abs(lastTimeStamp = inlet.PullSample(sample, 0.0f)) > Constants.TOLERANCE) { Process(sample, lastTimeStamp); } } } - catch (ArgumentException aex) + catch (ArgumentException e) { Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this); enabled = false; - Debug.LogException(aex, this); + Debug.LogException(e, this); } } @@ -213,12 +211,12 @@ namespace LSL4Unity.Scripts private void FixedUpdate() { - if (Moment == UpdateMoment.FixedUpdate && _inlet != null) { PullSamples(); } + if (moment == UpdateMoment.FixedUpdate && inlet != null) { PullSamples(); } } private void Update() { - if (Moment == UpdateMoment.Update && _inlet != null) { PullSamples(); } + if (moment == UpdateMoment.Update && inlet != null) { PullSamples(); } } } @@ -228,40 +226,39 @@ namespace LSL4Unity.Scripts { public enum UpdateMoment { FixedUpdate, Update } - public UpdateMoment Moment; + public UpdateMoment moment; - public string StreamName; - public string StreamType; + public string streamName; + public string streamType; - private liblsl.StreamInfo[] _results; - private liblsl.StreamInlet _inlet; - private liblsl.ContinuousResolver _resolver; + private liblsl.StreamInlet inlet; + private liblsl.ContinuousResolver resolver; - private int _expectedChannels = 0; + private int expectedChannels = 0; - private char[] _sample; + private char[] sample; private void Start() { - var expectedStreamHasAName = !StreamName.Equals(""); - var expectedStreamHasAType = !StreamType.Equals(""); + bool hasAName = streamName.Length != 0; + bool hasAType = streamType.Length != 0; - if (!expectedStreamHasAName && !expectedStreamHasAType) + if (!hasAName && !hasAType) { Debug.LogError("Inlet has to specify a name or a type before it is able to lookup a stream."); enabled = false; return; } - if (expectedStreamHasAName) + if (hasAName) { - 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); } - else // if (expectedStreamHasAType) // Useless with the first if + else // if (hasAType) // Useless with the first if { - Debug.Log("Creating LSL resolver for stream with type " + StreamType); - _resolver = new liblsl.ContinuousResolver("type", StreamType); + Debug.Log("Creating LSL resolver for stream with type " + streamType); + resolver = new liblsl.ContinuousResolver("type", streamType); } StartCoroutine(ResolveExpectedStream()); @@ -275,38 +272,38 @@ namespace LSL4Unity.Scripts private IEnumerator ResolveExpectedStream() { - var results = _resolver.Results(); + var results = resolver.Results(); yield return new WaitUntil(() => results.Length > 0); - _inlet = new liblsl.StreamInlet(results[0]); + inlet = new liblsl.StreamInlet(results[0]); - _expectedChannels = _inlet.Info().ChannelCount(); + expectedChannels = inlet.Info().ChannelCount(); yield return null; } protected void PullSamples() { - _sample = new char[_expectedChannels]; + sample = new char[expectedChannels]; try { - double lastTimeStamp = _inlet.PullSample(_sample, 0.0f); + double lastTimeStamp = inlet.PullSample(sample, 0.0f); if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE) { // do not miss the first one found - Process(_sample, lastTimeStamp); + Process(sample, lastTimeStamp); // pull as long samples are available - while (Math.Abs(lastTimeStamp = _inlet.PullSample(_sample, 0.0f)) > Constants.TOLERANCE) { Process(_sample, lastTimeStamp); } + while (Math.Abs(lastTimeStamp = inlet.PullSample(sample, 0.0f)) > Constants.TOLERANCE) { Process(sample, lastTimeStamp); } } } - catch (ArgumentException aex) + catch (ArgumentException e) { Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this); enabled = false; - Debug.LogException(aex, this); + Debug.LogException(e, this); } } @@ -315,12 +312,12 @@ namespace LSL4Unity.Scripts private void FixedUpdate() { - if (Moment == UpdateMoment.FixedUpdate && _inlet != null) { PullSamples(); } + if (moment == UpdateMoment.FixedUpdate && inlet != null) { PullSamples(); } } private void Update() { - if (Moment == UpdateMoment.Update && _inlet != null) { PullSamples(); } + if (moment == UpdateMoment.Update && inlet != null) { PullSamples(); } } } @@ -330,40 +327,39 @@ namespace LSL4Unity.Scripts { public enum UpdateMoment { FixedUpdate, Update } - public UpdateMoment Moment; + public UpdateMoment moment; - public string StreamName; - public string StreamType; + public string streamName; + public string streamType; - private liblsl.StreamInfo[] _results; - private liblsl.StreamInlet _inlet; - private liblsl.ContinuousResolver _resolver; + private liblsl.StreamInlet inlet; + private liblsl.ContinuousResolver resolver; - private int _expectedChannels = 0; + private int expectedChannels = 0; - private short[] _sample; + private short[] sample; private void Start() { - var expectedStreamHasAName = !StreamName.Equals(""); - var expectedStreamHasAType = !StreamType.Equals(""); + bool hasAName = streamName.Length != 0; + bool hasAType = streamType.Length != 0; - if (!expectedStreamHasAName && !expectedStreamHasAType) + if (!hasAName && !hasAType) { Debug.LogError("Inlet has to specify a name or a type before it is able to lookup a stream."); enabled = false; return; } - if (expectedStreamHasAName) + if (hasAName) { - 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); } - else // if (expectedStreamHasAType) // Useless with the first if + else // if (hasAType) // Useless with the first if { - Debug.Log("Creating LSL resolver for stream with type " + StreamType); - _resolver = new liblsl.ContinuousResolver("type", StreamType); + Debug.Log("Creating LSL resolver for stream with type " + streamType); + resolver = new liblsl.ContinuousResolver("type", streamType); } StartCoroutine(ResolveExpectedStream()); @@ -376,38 +372,38 @@ namespace LSL4Unity.Scripts private IEnumerator ResolveExpectedStream() { - var results = _resolver.Results(); + var results = resolver.Results(); yield return new WaitUntil(() => results.Length > 0); - _inlet = new liblsl.StreamInlet(results[0]); + inlet = new liblsl.StreamInlet(results[0]); - _expectedChannels = _inlet.Info().ChannelCount(); + expectedChannels = inlet.Info().ChannelCount(); yield return null; } protected void PullSamples() { - _sample = new short[_expectedChannels]; + sample = new short[expectedChannels]; try { - double lastTimeStamp = _inlet.PullSample(_sample, 0.0f); + double lastTimeStamp = inlet.PullSample(sample, 0.0f); if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE) { // do not miss the first one found - Process(_sample, lastTimeStamp); + Process(sample, lastTimeStamp); // pull as long samples are available - while (Math.Abs(lastTimeStamp = _inlet.PullSample(_sample, 0.0f)) > Constants.TOLERANCE) { Process(_sample, lastTimeStamp); } + while (Math.Abs(lastTimeStamp = inlet.PullSample(sample, 0.0f)) > Constants.TOLERANCE) { Process(sample, lastTimeStamp); } } } - catch (ArgumentException aex) + catch (ArgumentException e) { Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this); enabled = false; - Debug.LogException(aex, this); + Debug.LogException(e, this); } } @@ -416,12 +412,12 @@ namespace LSL4Unity.Scripts private void FixedUpdate() { - if (Moment == UpdateMoment.FixedUpdate && _inlet != null) { PullSamples(); } + if (moment == UpdateMoment.FixedUpdate && inlet != null) { PullSamples(); } } private void Update() { - if (Moment == UpdateMoment.Update && _inlet != null) { PullSamples(); } + if (moment == UpdateMoment.Update && inlet != null) { PullSamples(); } } } @@ -431,40 +427,39 @@ namespace LSL4Unity.Scripts { public enum UpdateMoment { FixedUpdate, Update } - public UpdateMoment Moment; + public UpdateMoment moment; - public string StreamName; - public string StreamType; + public string streamName; + public string streamType; - private liblsl.StreamInfo[] _results; - private liblsl.StreamInlet _inlet; - private liblsl.ContinuousResolver _resolver; + private liblsl.StreamInlet inlet; + private liblsl.ContinuousResolver resolver; - private int _expectedChannels = 0; + private int expectedChannels = 0; - private int[] _sample; + private int[] sample; private void Start() { - var expectedStreamHasAName = !StreamName.Equals(""); - var expectedStreamHasAType = !StreamType.Equals(""); + bool hasAName = streamName.Length != 0; + bool hasAType = streamType.Length != 0; - if (!expectedStreamHasAName && !expectedStreamHasAType) + if (!hasAName && !hasAType) { Debug.LogError("Inlet has to specify a name or a type before it is able to lookup a stream."); enabled = false; return; } - if (expectedStreamHasAName) + if (hasAName) { - 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); } - else // if (expectedStreamHasAType) // Useless with the first if + else // if (hasAType) // Useless with the first if { - Debug.Log("Creating LSL resolver for stream with type " + StreamType); - _resolver = new liblsl.ContinuousResolver("type", StreamType); + Debug.Log("Creating LSL resolver for stream with type " + streamType); + resolver = new liblsl.ContinuousResolver("type", streamType); } StartCoroutine(ResolveExpectedStream()); @@ -477,38 +472,37 @@ namespace LSL4Unity.Scripts private IEnumerator ResolveExpectedStream() { - var results = _resolver.Results(); + var results = resolver.Results(); yield return new WaitUntil(() => results.Length > 0); - _inlet = new liblsl.StreamInlet(results[0]); - - _expectedChannels = _inlet.Info().ChannelCount(); + inlet = new liblsl.StreamInlet(results[0]); + expectedChannels = inlet.Info().ChannelCount(); yield return null; } protected void PullSamples() { - _sample = new int[_expectedChannels]; + sample = new int[expectedChannels]; try { - double lastTimeStamp = _inlet.PullSample(_sample, 0.0f); + double lastTimeStamp = inlet.PullSample(sample, 0.0f); if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE) { // do not miss the first one found - Process(_sample, lastTimeStamp); + Process(sample, lastTimeStamp); // pull as long samples are available - while (Math.Abs(lastTimeStamp = _inlet.PullSample(_sample, 0.0f)) > Constants.TOLERANCE) { Process(_sample, lastTimeStamp); } + while (Math.Abs(lastTimeStamp = inlet.PullSample(sample, 0.0f)) > Constants.TOLERANCE) { Process(sample, lastTimeStamp); } } } - catch (ArgumentException aex) + catch (ArgumentException e) { Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this); enabled = false; - Debug.LogException(aex, this); + Debug.LogException(e, this); } } @@ -517,12 +511,12 @@ namespace LSL4Unity.Scripts private void FixedUpdate() { - if (Moment == UpdateMoment.FixedUpdate && _inlet != null) { PullSamples(); } + if (moment == UpdateMoment.FixedUpdate && inlet != null) { PullSamples(); } } private void Update() { - if (Moment == UpdateMoment.Update && _inlet != null) { PullSamples(); } + if (moment == UpdateMoment.Update && inlet != null) { PullSamples(); } } } @@ -532,40 +526,39 @@ namespace LSL4Unity.Scripts { public enum UpdateMoment { FixedUpdate, Update } - public UpdateMoment Moment; + public UpdateMoment moment; - public string StreamName; - public string StreamType; + public string streamName; + public string streamType; - private liblsl.StreamInfo[] _results; - private liblsl.StreamInlet _inlet; - private liblsl.ContinuousResolver _resolver; + private liblsl.StreamInlet inlet; + private liblsl.ContinuousResolver resolver; - private int _expectedChannels = 0; + private int expectedChannels = 0; - private string[] _sample; + private string[] sample; private void Start() { - var expectedStreamHasAName = !StreamName.Equals(""); - var expectedStreamHasAType = !StreamType.Equals(""); + bool hasAName = streamName.Length != 0; + bool hasAType = streamType.Length != 0; - if (!expectedStreamHasAName && !expectedStreamHasAType) + if (!hasAName && !hasAType) { Debug.LogError("Inlet has to specify a name or a type before it is able to lookup a stream."); enabled = false; return; } - if (expectedStreamHasAName) + if (hasAName) { - 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); } - else // if (expectedStreamHasAType) // Useless with the first if + else // if (hasAType) // Useless with the first if { - Debug.Log("Creating LSL resolver for stream with type " + StreamType); - _resolver = new liblsl.ContinuousResolver("type", StreamType); + Debug.Log("Creating LSL resolver for stream with type " + streamType); + resolver = new liblsl.ContinuousResolver("type", streamType); } StartCoroutine(ResolveExpectedStream()); @@ -578,38 +571,38 @@ namespace LSL4Unity.Scripts private IEnumerator ResolveExpectedStream() { - var results = _resolver.Results(); + var results = resolver.Results(); yield return new WaitUntil(() => results.Length > 0); - _inlet = new liblsl.StreamInlet(results[0]); + inlet = new liblsl.StreamInlet(results[0]); - _expectedChannels = _inlet.Info().ChannelCount(); + expectedChannels = inlet.Info().ChannelCount(); yield return null; } protected void PullSamples() { - _sample = new string[_expectedChannels]; + sample = new string[expectedChannels]; try { - double lastTimeStamp = _inlet.PullSample(_sample, 0.0f); + double lastTimeStamp = inlet.PullSample(sample, 0.0f); if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE) { // do not miss the first one found - Process(_sample, lastTimeStamp); + Process(sample, lastTimeStamp); // pull as long samples are available - while (Math.Abs(lastTimeStamp = _inlet.PullSample(_sample, 0.0f)) > Constants.TOLERANCE) { Process(_sample, lastTimeStamp); } + while (Math.Abs(lastTimeStamp = inlet.PullSample(sample, 0.0f)) > Constants.TOLERANCE) { Process(sample, lastTimeStamp); } } } - catch (ArgumentException aex) + catch (ArgumentException e) { Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this); enabled = false; - Debug.LogException(aex, this); + Debug.LogException(e, this); } } @@ -618,12 +611,12 @@ namespace LSL4Unity.Scripts private void FixedUpdate() { - if (Moment == UpdateMoment.FixedUpdate && _inlet != null) { PullSamples(); } + if (moment == UpdateMoment.FixedUpdate && inlet != null) { PullSamples(); } } private void Update() { - if (Moment == UpdateMoment.Update && _inlet != null) { PullSamples(); } + if (moment == UpdateMoment.Update && inlet != null) { PullSamples(); } } } } diff --git a/Scripts/BaseInlet.cs b/Scripts/BaseInlet.cs index 79d87566f6acd8af1dd774c04143879541c0375a..5b330008d20e8e04ff334bf112d6aa5249a189fd 100644 --- a/Scripts/BaseInlet.cs +++ b/Scripts/BaseInlet.cs @@ -1,34 +1,34 @@ -using System; +using System; using System.Linq; -using LSL4Unity.Scripts.OV; +using LSL4Unity.OV; using UnityEngine; -namespace LSL4Unity.Scripts +namespace LSL4Unity { public abstract class ABaseInlet : MonoBehaviour { - public string StreamName; - public string StreamType; + public string streamName; + public string streamType; - protected liblsl.StreamInlet Inlet; + protected liblsl.StreamInlet inlet; - protected int ExpectedChannels; + protected int expectedChannels; - protected Resolver Resolver; + protected Resolver resolver; /// <summary> Call this method when your inlet implementation got created at runtime. </summary> protected virtual void RegisterAndLookUpStream() { - Resolver = FindObjectOfType<Resolver>(); + resolver = FindObjectOfType<Resolver>(); //Resolver.OnStreamFound.AddListener(new UnityAction<LSLStreamInfoWrapper>(AStreamIsFound)); // Redundant to explicit delegate creation //Resolver.OnStreamLost.AddListener(new UnityAction<LSLStreamInfoWrapper>(AStreamGotLost)); // Redundant to explicit delegate creation - Resolver.OnStreamFound.AddListener(AStreamIsFound); - Resolver.OnStreamLost.AddListener(AStreamGotLost); + resolver.onStreamFound.AddListener(AStreamIsFound); + resolver.onStreamLost.AddListener(AStreamGotLost); - if (Resolver.KnownStreams.Any(IsTheExpected)) + if (resolver.streams.Any(IsTheExpected)) { - var stream = Resolver.KnownStreams.First(IsTheExpected); + var stream = resolver.streams.First(IsTheExpected); AStreamIsFound(stream); } } @@ -39,10 +39,10 @@ namespace LSL4Unity.Scripts { if (!IsTheExpected(stream)) { return; } - Debug.Log($"LSL Stream {stream.Name} found for {name}"); + Debug.Log($"LSL Stream {stream.name} found for {name}"); - Inlet = new liblsl.StreamInlet(stream.Item); - ExpectedChannels = stream.ChannelCount; + inlet = new liblsl.StreamInlet(stream.Item); + expectedChannels = stream.ChannelCount; OnStreamAvailable(); } @@ -53,7 +53,7 @@ namespace LSL4Unity.Scripts { if (!IsTheExpected(stream)) { return; } - Debug.Log($"LSL Stream {stream.Name} Lost for {name}"); + Debug.Log($"LSL Stream {stream.name} Lost for {name}"); OnStreamLost(); } @@ -63,8 +63,8 @@ namespace LSL4Unity.Scripts /// <returns> <c>true</c> if if the specified stream is the expected stream; otherwise, <c>false</c>. </returns> protected virtual bool IsTheExpected(LSLStreamInfoWrapper stream) { - bool predicate = StreamName.Equals(stream.Name); - predicate &= StreamType.Equals(stream.Type); + bool predicate = streamName.Equals(stream.name); + predicate &= streamType.Equals(stream.type); return predicate; } @@ -97,29 +97,29 @@ namespace LSL4Unity.Scripts /// <param name="time"> The current Time. </param> protected abstract void Process(float[] sample, double time); - protected float[] Sample; + protected float[] sample; protected override void PullSamples() { - Sample = new float[ExpectedChannels]; + sample = new float[expectedChannels]; try { - double time = Inlet.PullSample(Sample, 0.0f); + double time = inlet.PullSample(sample, 0.0f); if (Math.Abs(time) > Constants.TOLERANCE) { // do not miss the first one found - Process(Sample, time); + Process(sample, time); // pull as long samples are available - while (Math.Abs(time = Inlet.PullSample(Sample, 0.0f)) > Constants.TOLERANCE) { Process(Sample, time); } + while (Math.Abs(time = inlet.PullSample(sample, 0.0f)) > Constants.TOLERANCE) { Process(sample, time); } } } - catch (ArgumentException aex) + catch (ArgumentException e) { Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this); enabled = false; - Debug.LogException(aex, this); + Debug.LogException(e, this); } } } @@ -130,29 +130,29 @@ namespace LSL4Unity.Scripts /// <inheritdoc cref="InletFloatSamples.Process"/> protected abstract void Process(double[] sample, double time); - protected double[] Sample; + protected double[] sample; protected override void PullSamples() { - Sample = new double[ExpectedChannels]; + sample = new double[expectedChannels]; try { - double lastTimeStamp = Inlet.PullSample(Sample, 0.0f); + double lastTimeStamp = inlet.PullSample(sample, 0.0f); if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE) { // do not miss the first one found - Process(Sample, lastTimeStamp); + Process(sample, lastTimeStamp); // pull as long samples are available - while (Math.Abs(lastTimeStamp = Inlet.PullSample(Sample, 0.0f)) > Constants.TOLERANCE) { Process(Sample, lastTimeStamp); } + while (Math.Abs(lastTimeStamp = inlet.PullSample(sample, 0.0f)) > Constants.TOLERANCE) { Process(sample, lastTimeStamp); } } } - catch (ArgumentException aex) + catch (ArgumentException e) { Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this); enabled = false; - Debug.LogException(aex, this); + Debug.LogException(e, this); } } } @@ -163,29 +163,29 @@ namespace LSL4Unity.Scripts /// <inheritdoc cref="InletFloatSamples.Process"/> protected abstract void Process(int[] sample, double time); - protected int[] Sample; + protected int[] sample; protected override void PullSamples() { - Sample = new int[ExpectedChannels]; + sample = new int[expectedChannels]; try { - double lastTimeStamp = Inlet.PullSample(Sample, 0.0f); + double lastTimeStamp = inlet.PullSample(sample, 0.0f); if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE) { // do not miss the first one found - Process(Sample, lastTimeStamp); + Process(sample, lastTimeStamp); // pull as long samples are available - while (Math.Abs(lastTimeStamp = Inlet.PullSample(Sample, 0.0f)) > Constants.TOLERANCE) { Process(Sample, lastTimeStamp); } + while (Math.Abs(lastTimeStamp = inlet.PullSample(sample, 0.0f)) > Constants.TOLERANCE) { Process(sample, lastTimeStamp); } } } - catch (ArgumentException aex) + catch (ArgumentException e) { Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this); enabled = false; - Debug.LogException(aex, this); + Debug.LogException(e, this); } } } @@ -196,29 +196,29 @@ namespace LSL4Unity.Scripts /// <inheritdoc cref="InletFloatSamples.Process"/> protected abstract void Process(char[] sample, double time); - protected char[] Sample; + protected char[] sample; protected override void PullSamples() { - Sample = new char[ExpectedChannels]; + sample = new char[expectedChannels]; try { - double lastTimeStamp = Inlet.PullSample(Sample, 0.0f); + double lastTimeStamp = inlet.PullSample(sample, 0.0f); if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE) { // do not miss the first one found - Process(Sample, lastTimeStamp); + Process(sample, lastTimeStamp); // pull as long samples are available - while (Math.Abs(lastTimeStamp = Inlet.PullSample(Sample, 0.0f)) > Constants.TOLERANCE) { Process(Sample, lastTimeStamp); } + while (Math.Abs(lastTimeStamp = inlet.PullSample(sample, 0.0f)) > Constants.TOLERANCE) { Process(sample, lastTimeStamp); } } } - catch (ArgumentException aex) + catch (ArgumentException e) { Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this); enabled = false; - Debug.LogException(aex, this); + Debug.LogException(e, this); } } } @@ -229,29 +229,29 @@ namespace LSL4Unity.Scripts /// <inheritdoc cref="InletFloatSamples.Process"/> protected abstract void Process(string[] sample, double time); - protected string[] Sample; + protected string[] sample; protected override void PullSamples() { - Sample = new string[ExpectedChannels]; + sample = new string[expectedChannels]; try { - double lastTimeStamp = Inlet.PullSample(Sample, 0.0f); + double lastTimeStamp = inlet.PullSample(sample, 0.0f); if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE) { // do not miss the first one found - Process(Sample, lastTimeStamp); + Process(sample, lastTimeStamp); // pull as long samples are available - while (Math.Abs(lastTimeStamp = Inlet.PullSample(Sample, 0.0f)) > Constants.TOLERANCE) { Process(Sample, lastTimeStamp); } + while (Math.Abs(lastTimeStamp = inlet.PullSample(sample, 0.0f)) > Constants.TOLERANCE) { Process(sample, lastTimeStamp); } } } - catch (ArgumentException aex) + catch (ArgumentException e) { Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this); enabled = false; - Debug.LogException(aex, this); + Debug.LogException(e, this); } } } @@ -262,29 +262,29 @@ namespace LSL4Unity.Scripts /// <inheritdoc cref="InletFloatSamples.Process"/> protected abstract void Process(short[] sample, double time); - protected short[] Sample; + protected short[] sample; protected override void PullSamples() { - Sample = new short[ExpectedChannels]; + sample = new short[expectedChannels]; try { - double lastTimeStamp = Inlet.PullSample(Sample, 0.0f); + double lastTimeStamp = inlet.PullSample(sample, 0.0f); if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE) { // do not miss the first one found - Process(Sample, lastTimeStamp); + Process(sample, lastTimeStamp); // pull as long samples are available - while (Math.Abs(lastTimeStamp = Inlet.PullSample(Sample, 0.0f)) > Constants.TOLERANCE) { Process(Sample, lastTimeStamp); } + while (Math.Abs(lastTimeStamp = inlet.PullSample(sample, 0.0f)) > Constants.TOLERANCE) { Process(sample, lastTimeStamp); } } } - catch (ArgumentException aex) + catch (ArgumentException e) { Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this); enabled = false; - Debug.LogException(aex, this); + Debug.LogException(e, this); } } } diff --git a/Scripts/Examples/DemoInletForFloatSamples.cs b/Scripts/Examples/DemoInletForFloatSamples.cs index 4565f838b0cfa8671a6b20db3d5a01b8bb6b4da1..19876bd8968c45b4e2b167df7db91a3372903767 100644 --- a/Scripts/Examples/DemoInletForFloatSamples.cs +++ b/Scripts/Examples/DemoInletForFloatSamples.cs @@ -1,6 +1,6 @@ -using UnityEngine; +using UnityEngine; -namespace LSL4Unity.Scripts.Examples +namespace LSL4Unity.Examples { /// <summary> /// Example that works with the Resolver component. @@ -13,13 +13,9 @@ namespace LSL4Unity.Scripts.Examples /// </summary> public class DemoInletForFloatSamples : InletFloatSamples { - public Transform TargetTransform; - - public bool UseX; - public bool UseY; - public bool UseZ; - - private bool _pullSamplesContinuously = false; + public Transform targetTransform; + public bool useX, useY, useZ; + private bool pullContinuously = false; //void Start() //{ @@ -31,7 +27,7 @@ namespace LSL4Unity.Scripts.Examples protected override bool IsTheExpected(LSLStreamInfoWrapper stream) { // the base implementation just checks for stream name and type - var predicate = base.IsTheExpected(stream); + bool predicate = base.IsTheExpected(stream); // add a more specific description for your stream here specifying hostname etc. //predicate &= stream.HostName.Equals("Expected Hostname"); return predicate; @@ -48,24 +44,24 @@ namespace LSL4Unity.Scripts.Examples protected override void Process(float[] sample, double time) { //Assuming that a samples contains at least 3 values for x,y,z - float x = UseX ? sample[0] : 1; - float y = UseY ? sample[1] : 1; - float z = UseZ ? sample[2] : 1; + float x = useX ? sample[0] : 1; + float y = useY ? sample[1] : 1; + float z = useZ ? sample[2] : 1; // we map the data to the scale factors - var targetScale = new Vector3(x, y, z); + Vector3 targetScale = new Vector3(x, y, z); // apply the rotation to the target transform - TargetTransform.localScale = targetScale; + targetTransform.localScale = targetScale; } - protected override void OnStreamAvailable() { _pullSamplesContinuously = true; } + protected override void OnStreamAvailable() { pullContinuously = true; } - protected override void OnStreamLost() { _pullSamplesContinuously = false; } + protected override void OnStreamLost() { pullContinuously = false; } private void Update() { - if (_pullSamplesContinuously) { PullSamples(); } + if (pullContinuously) { PullSamples(); } } } } diff --git a/Scripts/Examples/ExampleFloatInlet.cs b/Scripts/Examples/ExampleFloatInlet.cs index 8d3c42f67bc784181db652724de29526578925cc..f31fb23a0d1c831ed02ecea8315e09affa7b8988 100644 --- a/Scripts/Examples/ExampleFloatInlet.cs +++ b/Scripts/Examples/ExampleFloatInlet.cs @@ -1,15 +1,15 @@ -using UnityEngine; +using UnityEngine; -namespace LSL4Unity.Scripts.Examples +namespace LSL4Unity.Examples { /// <summary> Just an example implementation for a Inlet recieving float values. </summary> public class ExampleFloatInlet : AFloatInlet { - public float[] LastSample; + public float[] lastSample; protected override void Process(float[] sample, double time) { - LastSample = sample; + lastSample = sample; Debug.Log($"Got {sample.Length} samples at {time}"); } } diff --git a/Scripts/Examples/ScaleMapping.cs b/Scripts/Examples/ScaleMapping.cs index 89803bacbc940672ff6a7f964d77d208d78f01b3..e93049c46ec60251626d54b8e42fde2b615abc95 100644 --- a/Scripts/Examples/ScaleMapping.cs +++ b/Scripts/Examples/ScaleMapping.cs @@ -1,25 +1,24 @@ using UnityEngine; -namespace LSL4Unity.Scripts.Examples +namespace LSL4Unity.Examples { public class ScaleMapping : AFloatInlet { - public Transform TargetTransform; - - public bool UseX, UseY, UseZ; + public Transform targetTransform; + public bool useX, useY, useZ; protected override void Process(float[] sample, double time) { //Assuming that a sample contains at least 3 values for x,y,z - float x = UseX ? sample[0] : 1; - float y = UseY ? sample[1] : 1; - float z = UseZ ? sample[2] : 1; + float x = useX ? sample[0] : 1; + float y = useY ? sample[1] : 1; + float z = useZ ? sample[2] : 1; // we map the data to the scale factors var targetScale = new Vector3(x, y, z); // apply the rotation to the target transform - TargetTransform.localScale = targetScale; + targetTransform.localScale = targetScale; } } } diff --git a/Scripts/Examples/TransformMapping.cs b/Scripts/Examples/TransformMapping.cs index 2ae00ea054586e36af9690f3ababe4089bc71701..440c93b77bfdba1dcdf3d3d3582c15415a06237a 100644 --- a/Scripts/Examples/TransformMapping.cs +++ b/Scripts/Examples/TransformMapping.cs @@ -1,10 +1,10 @@ using UnityEngine; -namespace LSL4Unity.Scripts.Examples +namespace LSL4Unity.Examples { public class TransformMapping : AFloatInlet { - public Transform TargetTransform; + public Transform targetTransform; protected override void Process(float[] sample, double time) { @@ -17,7 +17,7 @@ namespace LSL4Unity.Scripts.Examples var targetRotation = Quaternion.Euler(x, y, z); // apply the rotation to the target transform - TargetTransform.rotation = targetRotation; + targetTransform.rotation = targetRotation; } } } diff --git a/Scripts/LSLCommon.cs b/Scripts/LSLCommon.cs index 33e77cf8938c0b9ee8b548bd2b6023af9e093254..917da8a7c9f4552050b2ca63294cb69fbfe77dc0 100644 --- a/Scripts/LSLCommon.cs +++ b/Scripts/LSLCommon.cs @@ -1,7 +1,7 @@ using System; using UnityEngine; -namespace LSL4Unity.Scripts +namespace LSL4Unity { public static class LSLUtils { @@ -41,10 +41,10 @@ namespace LSL4Unity.Scripts /// A support class to construct channel definitions automatically. /// See Transform Outlet as an example. /// </summary> - public struct ChannelDefinition + internal struct ChannelDefinition { - public string Label; - public string Unit; - public string Type; + public string label; + public string unit; + public string type; } } diff --git a/Scripts/LSLMarkerStream.cs b/Scripts/LSLMarkerStream.cs index b5dae5fe26af102258ca5cfd4369d9f8a4742d84..09084de7b63edb375c1b0bcc869a9232225463a1 100644 --- a/Scripts/LSLMarkerStream.cs +++ b/Scripts/LSLMarkerStream.cs @@ -1,13 +1,13 @@ -using System.Collections; +using System.Collections; using UnityEngine; -namespace LSL4Unity.Scripts +namespace LSL4Unity { [HelpURL("https://github.com/xfleckx/LSL4Unity/wiki#using-a-marker-stream")] public class LSLMarkerStream : MonoBehaviour { - public string LSLStreamName = "Unity_<Paradigma_Name_here>"; - public string LSLStreamType = "LSL_Marker_Strings"; + public string streamName = "Unity_<Paradigma_Name_here>"; + public string streamType = "LSL_Marker_Strings"; private const string UNIQUE_SOURCE_ID = "D3F83BB699EB49AB94A9FA44B88882AB"; private const int LSL_CHANNEL_COUNT = 1; @@ -15,35 +15,23 @@ namespace LSL4Unity.Scripts private const liblsl.channel_format_t LSL_CHANNEL_FORMAT = liblsl.channel_format_t.cf_string; - private liblsl.StreamInfo _lslStreamInfo; - private liblsl.StreamOutlet _lslOutlet; + private liblsl.StreamInfo info; + private liblsl.StreamOutlet outlet; //Assuming that markers are never send in regular intervalls - private string[] _sample; + private string[] sample; private void Awake() { - _sample = new string[LSL_CHANNEL_COUNT]; - _lslStreamInfo = new liblsl.StreamInfo(LSLStreamName, LSLStreamType, LSL_CHANNEL_COUNT, NOMINAL_SRATE, LSL_CHANNEL_FORMAT, UNIQUE_SOURCE_ID); - _lslOutlet = new liblsl.StreamOutlet(_lslStreamInfo); + sample = new string[LSL_CHANNEL_COUNT]; + info = new liblsl.StreamInfo(streamName, streamType, LSL_CHANNEL_COUNT, NOMINAL_SRATE, LSL_CHANNEL_FORMAT, UNIQUE_SOURCE_ID); + outlet = new liblsl.StreamOutlet(info); } - public void Write(string marker) + public void Write(string marker, double timeStamp = 0) { - _sample[0] = marker; - _lslOutlet.PushSample(_sample); - } - - public void Write(string marker, double customTimeStamp) - { - _sample[0] = marker; - _lslOutlet.PushSample(_sample, customTimeStamp); - } - - public void Write(string marker, float customTimeStamp) - { - _sample[0] = marker; - _lslOutlet.PushSample(_sample, customTimeStamp); + sample[0] = marker; + outlet.PushSample(sample, timeStamp); } public void WriteBeforeFrameIsDisplayed(string marker) { StartCoroutine(WriteMarkerAfterImageIsRendered(marker)); } diff --git a/Scripts/LSLOutlet.cs b/Scripts/LSLOutlet.cs index b6181db1d20f46337a124733905a33f40a540b4e..53b695781014152a9ef17d517c332ed297f82f10 100644 --- a/Scripts/LSLOutlet.cs +++ b/Scripts/LSLOutlet.cs @@ -1,45 +1,45 @@ -using System.Diagnostics; +using System.Diagnostics; using UnityEngine; -namespace LSL4Unity.Scripts +namespace LSL4Unity { public enum MomentForSampling { Update, FixedUpdate, LateUpdate } public class LSLOutlet : MonoBehaviour { - private liblsl.StreamOutlet _outlet; - private liblsl.StreamInfo _streamInfo; - private float[] _currentSample; + private liblsl.StreamOutlet outlet; + private liblsl.StreamInfo info; + private float[] sample; - public string StreamName = "Unity.ExampleStream"; - public string StreamType = "Unity.FixedUpdateTime"; - public int ChannelCount = 1; + public string streamName = "Unity.ExampleStream"; + public string streamType = "Unity.FixedUpdateTime"; + public int channelCount = 1; - private Stopwatch _watch; + private Stopwatch watch; /// <summary> Use this for initialization. </summary> private void Start() { - _watch = new Stopwatch(); - _watch.Start(); + watch = new Stopwatch(); + watch.Start(); - _currentSample = new float[ChannelCount]; - _streamInfo = new liblsl.StreamInfo(StreamName, StreamType, ChannelCount, Time.fixedDeltaTime * 1000); - _outlet = new liblsl.StreamOutlet(_streamInfo); + sample = new float[channelCount]; + info = new liblsl.StreamInfo(streamName, streamType, channelCount, Time.fixedDeltaTime * 1000); + outlet = new liblsl.StreamOutlet(info); } public void FixedUpdate() { - if (_watch == null) { return; } + if (watch == null) { return; } - _watch.Stop(); + watch.Stop(); - _currentSample[0] = _watch.ElapsedMilliseconds; + sample[0] = watch.ElapsedMilliseconds; - _watch.Reset(); - _watch.Start(); + watch.Reset(); + watch.Start(); - _outlet.PushSample(_currentSample); + outlet.PushSample(sample); } } } diff --git a/Scripts/LSLTimeSync.cs b/Scripts/LSLTimeSync.cs index 5260cde63c7921d43172e486bc4e1cba63443fee..f23f969758ec1dde57721933e25653dfb505fe37 100644 --- a/Scripts/LSLTimeSync.cs +++ b/Scripts/LSLTimeSync.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace LSL4Unity.Scripts +namespace LSL4Unity { /// <summary> /// This singleton should provide an dedicated timestamp for each update call or fixed update LSL sample! @@ -16,12 +16,9 @@ namespace LSL4Unity.Scripts public double UpdateTimeStamp { get; private set; } public double LateUpdateTimeStamp { get; private set; } - private void Awake() { Instance = this; } - + private void Awake() { Instance = this; } private void FixedUpdate() { FixedUpdateTimeStamp = liblsl.LocalClock(); } - - private void Update() { UpdateTimeStamp = liblsl.LocalClock(); } - - private void LateUpdate() { LateUpdateTimeStamp = liblsl.LocalClock(); } + private void Update() { UpdateTimeStamp = liblsl.LocalClock(); } + private void LateUpdate() { LateUpdateTimeStamp = liblsl.LocalClock(); } } } diff --git a/Scripts/LSLTransformOutlet.cs b/Scripts/LSLTransformOutlet.cs index 88f13cb86decc9138d4b6f007b22fdacde9d7c59..0cf2a0bd3efe13ed76c50ebb7d9cfa9c1e169f18 100644 --- a/Scripts/LSLTransformOutlet.cs +++ b/Scripts/LSLTransformOutlet.cs @@ -1,32 +1,29 @@ -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using UnityEngine; -namespace LSL4Unity.Scripts +namespace LSL4Unity { /// <summary> An reusable example of an outlet which provides the orientation and world position of an entity of an Unity Scene to LSL. </summary> public class LSLTransformOutlet : MonoBehaviour { private const string UNIQUE_SOURCE_ID_SUFFIX = "63CE5B03731944F6AC30DBB04B451A94"; + private string uniqueSourceId; + private int channelCount = 0; - private string _uniqueSourceId; - - private liblsl.StreamOutlet _outlet; - private liblsl.StreamInfo _streamInfo; - - private int _channelCount = 0; + private liblsl.StreamOutlet outlet; + private liblsl.StreamInfo streamInfo; /// <summary> Use a array to reduce allocation costs and reuse it for each sampling call. </summary> - private float[] _currentSample; + private float[] sample; - public Transform SampleSource; - public string StreamName = "BeMoBI.Unity.Orientation.<Add_a_entity_id_here>"; - public string StreamType = "Unity.Quaternion"; - - public bool StreamRotationAsQuaternion = true; - public bool StreamRotationAsEuler = true; - public bool StreamPosition = true; + public string streamName = "BeMoBI.Unity.Orientation.<Add_a_entity_id_here>"; + public string streamType = "Unity.Quaternion"; + public bool rotationAsQuaternion = true; + public bool rotationAsEuler = true; + public bool position = true; + public Transform sampleSource; /// <summary> Due to an instable framerate we assume a irregular data rate. </summary> private const double DATA_RATE = liblsl.IRREGULAR_RATE; @@ -35,26 +32,26 @@ namespace LSL4Unity.Scripts { // assigning a unique source id as a combination of a the instance ID for the case that // multiple LSLTransformOutlet are used and a guid identifing the script itself. - _uniqueSourceId = $"{GetInstanceID()}_{UNIQUE_SOURCE_ID_SUFFIX}"; + uniqueSourceId = $"{GetInstanceID()}_{UNIQUE_SOURCE_ID_SUFFIX}"; } private void Start() { var channelDefinitions = SetupChannels(); // initialize the array once - _channelCount = channelDefinitions.Count; - _currentSample = new float[_channelCount]; - _streamInfo = new liblsl.StreamInfo(StreamName, StreamType, _channelCount, DATA_RATE, liblsl.channel_format_t.cf_float32, _uniqueSourceId); + channelCount = channelDefinitions.Count; + sample = new float[channelCount]; + streamInfo = new liblsl.StreamInfo(streamName, streamType, channelCount, DATA_RATE, liblsl.channel_format_t.cf_float32, uniqueSourceId); // it's not possible to create a XMLElement before and append it. - liblsl.XMLElement chns = _streamInfo.Desc().AppendChild("channels"); + var chns = streamInfo.Desc().AppendChild("channels"); // so this workaround has been introduced. foreach (var def in channelDefinitions) { - chns.AppendChild("channel").AppendChildValue("label", def.Label).AppendChildValue("unit", def.Unit).AppendChildValue("type", def.Type); + chns.AppendChild("channel").AppendChildValue("label", def.label).AppendChildValue("unit", def.unit).AppendChildValue("type", def.type); } - _outlet = new liblsl.StreamOutlet(_streamInfo); + outlet = new liblsl.StreamOutlet(streamInfo); } /// <summary> @@ -62,8 +59,7 @@ namespace LSL4Unity.Scripts /// </summary> private void LateUpdate() { - if (_outlet == null) { return; } - + if (outlet == null) { return; } Sample(); } @@ -71,33 +67,33 @@ namespace LSL4Unity.Scripts { int offset = -1; - if (StreamRotationAsQuaternion) + if (rotationAsQuaternion) { - var rotation = SampleSource.rotation; + var rotation = sampleSource.rotation; - _currentSample[++offset] = rotation.x; - _currentSample[++offset] = rotation.y; - _currentSample[++offset] = rotation.z; - _currentSample[++offset] = rotation.w; + sample[++offset] = rotation.x; + sample[++offset] = rotation.y; + sample[++offset] = rotation.z; + sample[++offset] = rotation.w; } - if (StreamRotationAsEuler) + if (rotationAsEuler) { - var rotation = SampleSource.rotation.eulerAngles; + var rotation = sampleSource.rotation.eulerAngles; - _currentSample[++offset] = rotation.x; - _currentSample[++offset] = rotation.y; - _currentSample[++offset] = rotation.z; + sample[++offset] = rotation.x; + sample[++offset] = rotation.y; + sample[++offset] = rotation.z; } - if (StreamPosition) + if (position) { - var position = SampleSource.position; + var pos = sampleSource.position; - _currentSample[++offset] = position.x; - _currentSample[++offset] = position.y; - _currentSample[++offset] = position.z; + sample[++offset] = pos.x; + sample[++offset] = pos.y; + sample[++offset] = pos.z; } - _outlet.PushSample(_currentSample, liblsl.LocalClock()); + outlet.PushSample(sample, liblsl.LocalClock()); } @@ -107,26 +103,26 @@ namespace LSL4Unity.Scripts { var list = new List<ChannelDefinition>(); - if (StreamRotationAsQuaternion) + if (rotationAsQuaternion) { string[] quatlabels = { "x", "y", "z", "w" }; - list.AddRange(quatlabels.Select(item => new ChannelDefinition { Label = item, Unit = "unit quaternion", Type = "quaternion component" })); + list.AddRange(quatlabels.Select(item => new ChannelDefinition { label = item, unit = "unit quaternion", type = "quaternion component" })); } - if (StreamRotationAsEuler) + if (rotationAsEuler) { string[] eulerLabels = { "x", "y", "z" }; - list.AddRange(eulerLabels.Select(item => new ChannelDefinition { Label = item, Unit = "degree", Type = "axis angle" })); + list.AddRange(eulerLabels.Select(item => new ChannelDefinition { label = item, unit = "degree", type = "axis angle" })); } - if (StreamPosition) + if (position) { string[] eulerLabels = { "x", "y", "z" }; - list.AddRange(eulerLabels.Select(item => new ChannelDefinition { Label = item, Unit = "meter", Type = "position in world space" })); + list.AddRange(eulerLabels.Select(item => new ChannelDefinition { label = item, unit = "meter", type = "position in world space" })); } return list; diff --git a/Scripts/OV/Defines.cs b/Scripts/OV/Defines.cs index 503484a24dcdd35ffe6157155dd84c5623e78d26..d6925897d6ab21cf754bdb7a5a992b487821e213 100644 --- a/Scripts/OV/Defines.cs +++ b/Scripts/OV/Defines.cs @@ -1,11 +1,14 @@ -namespace LSL4Unity.Scripts.OV +namespace LSL4Unity.OV { - internal static class Constants + public static class Constants { public const double TOLERANCE = 1e-6; } - internal static class GDFStimulations + /// <summary> List of GDF Stimulations. </summary> + /// <remarks> You cna use nameof operator to see the name instead of the value of the staimulation in log or other. </remarks> + /// <seealso cref="https://docs.microsoft.com/dotnet/csharp/language-reference/operators/nameof"/> + public static class GDFStimulations { public const int GDF_ARTIFACT_EOG_LARGE = 00257; public const int GDF_ARTIFACT_ECG = 00258; @@ -122,7 +125,10 @@ public const int GDF_NON_EQUIDISTANT_SAMPLING_VALUE = 32767; } - internal static class Stimulations + /// <summary> List of OpenViBE Stimulations. </summary> + /// <remarks> You cna use nameof operator to see the name instead of the value of the staimulation in log or other. </remarks> + /// <seealso cref="https://docs.microsoft.com/dotnet/csharp/language-reference/operators/nameof"/> + public static class Stimulations { public const int NUMBER_00 = 00000; public const int NUMBER_01 = 00001; diff --git a/Scripts/OV/OVInlets.cs b/Scripts/OV/OVInlets.cs index b79f135381d791ae200e6df901e8fcafd2f93973..ba10bc08e15a8d96aa40cecf586b8952b8e568aa 100644 --- a/Scripts/OV/OVInlets.cs +++ b/Scripts/OV/OVInlets.cs @@ -2,7 +2,7 @@ using System; using System.Collections; using UnityEngine; -namespace LSL4Unity.Scripts.OV +namespace LSL4Unity.OV { /// <summary> Base Inlet for OpenViBE Link. </summary> /// <seealso cref="MonoBehaviour" /> diff --git a/Scripts/OV/Template/DoubleInlet.cs b/Scripts/OV/Template/DoubleInlet.cs index e8290d89724330058b7e20a381a08023c1ae8524..1261ad3d1835dbe4423446cdadb81dfe1b4a4528 100644 --- a/Scripts/OV/Template/DoubleInlet.cs +++ b/Scripts/OV/Template/DoubleInlet.cs @@ -1,7 +1,4 @@ -using System; -using UnityEngine; - -namespace LSL4Unity.Scripts.OV.Template +namespace LSL4Unity.OV.Template { /// <summary> Just an example implementation for a Inlet receiving double values for OpenViBE Link. </summary> /// <seealso cref="OVFloatInlet" /> diff --git a/Scripts/OV/Template/FloatInlet.cs b/Scripts/OV/Template/FloatInlet.cs index 9b583593ca0f272328c232a9cd07c23a55a72fd0..da9c55d4f58e770005cdbd14fc5b89bf307480bc 100644 --- a/Scripts/OV/Template/FloatInlet.cs +++ b/Scripts/OV/Template/FloatInlet.cs @@ -1,7 +1,4 @@ -using System; -using UnityEngine; - -namespace LSL4Unity.Scripts.OV.Template +namespace LSL4Unity.OV.Template { /// <summary> Just an example implementation for a Inlet receiving Float values for OpenViBE Link. </summary> /// <seealso cref="OVFloatInlet" /> diff --git a/Scripts/OV/Template/MatrixInlet.cs b/Scripts/OV/Template/MatrixInlet.cs index af5b5e501be079f7e9dfb80f3432b66da7865c32..ee4d9fc5b23ff98f318fdf287ffc1d22b08411ed 100644 --- a/Scripts/OV/Template/MatrixInlet.cs +++ b/Scripts/OV/Template/MatrixInlet.cs @@ -1,6 +1,4 @@ -using System; - -namespace LSL4Unity.Scripts.OV.Template +namespace LSL4Unity.OV.Template { /// <summary> Implementation for a Inlet receiving Matrix (double) from OpenViBE. </summary> /// <seealso cref="OVDoubleInlet" /> @@ -27,10 +25,10 @@ namespace LSL4Unity.Scripts.OV.Template protected override void Process(double[] input, double time) { - if (NChannel == -1) { NChannel = (int) (input[0]); } + if (NChannel == -1) { NChannel = (int) input[0]; } else if (NSample == -1) { - NSample = (int) (input[0]); + NSample = (int) input[0]; Matrix = new double[NChannel, NSample]; ResetMatrix(); } diff --git a/Scripts/OV/Template/StimulationInlet.cs b/Scripts/OV/Template/StimulationInlet.cs index ea0f6df2f2c923a1629ed7adefc94355649e2f99..0e366e13d61a90d952244640db12571c8e3372f2 100644 --- a/Scripts/OV/Template/StimulationInlet.cs +++ b/Scripts/OV/Template/StimulationInlet.cs @@ -1,6 +1,6 @@ using UnityEngine; -namespace LSL4Unity.Scripts.OV.Template +namespace LSL4Unity.OV.Template { /// <summary> Implementation for a Inlet receiving Stimulations (int) from OpenViBE. </summary> /// <seealso cref="OVFloatInlet" /> diff --git a/Scripts/Resolver.cs b/Scripts/Resolver.cs index b27210840a3a7c3d939a230a4f0dda585177996b..0a6114d4abcde70b1e8db0517a25a48f9cdfe922 100644 --- a/Scripts/Resolver.cs +++ b/Scripts/Resolver.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Collections.Generic; using System.Linq; @@ -6,29 +6,29 @@ using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; -namespace LSL4Unity.Scripts +namespace LSL4Unity { /// <summary> Encapsulates the lookup logic for LSL streams with an event based appraoch your custom stream inlet implementations could be subscribed to the On. </summary> public class Resolver : MonoBehaviour, IEventSystemHandler { - public StreamEvent OnStreamFound = new StreamEvent(); - public StreamEvent OnStreamLost = new StreamEvent(); - public float ForgetStreamAfter = 1.0f; + public StreamEvent onStreamFound = new StreamEvent(); + public StreamEvent onStreamLost = new StreamEvent(); + public float forgetStreamAfter = 1.0f; - public List<LSLStreamInfoWrapper> KnownStreams; - private liblsl.ContinuousResolver _resolver; + public List<LSLStreamInfoWrapper> streams; + private liblsl.ContinuousResolver resolver; /// <summary> Use this for initialization. </summary> private void Start() { - _resolver = new liblsl.ContinuousResolver(ForgetStreamAfter); + resolver = new liblsl.ContinuousResolver(forgetStreamAfter); StartCoroutine(ResolveContinuously()); } public bool IsStreamAvailable(out LSLStreamInfoWrapper info, string streamName = "", string streamType = "", string hostName = "") { - var result = KnownStreams.Where(i => (streamName.Length == 0 || i.Name.Equals(streamName)) && (streamType.Length == 0 || i.Type.Equals(streamType)) - && (hostName.Length == 0 || i.Type.Equals(hostName))) + var result = streams.Where(i => (streamName.Length == 0 || i.name.Equals(streamName)) && (streamType.Length == 0 || i.type.Equals(streamType)) + && (hostName.Length == 0 || i.type.Equals(hostName))) .ToList(); if (result.Any()) @@ -44,30 +44,30 @@ namespace LSL4Unity.Scripts { while (true) { - var results = _resolver.Results(); + var results = resolver.Results(); - foreach (var item in KnownStreams) + foreach (var item in streams) { - if (!results.Any(r => r.Name().Equals(item.Name))) + if (!results.Any(r => r.Name().Equals(item.name))) { - if (OnStreamLost.GetPersistentEventCount() > 0) { OnStreamLost.Invoke(item); } + if (onStreamLost.GetPersistentEventCount() > 0) { onStreamLost.Invoke(item); } } } // remove lost streams from cache - KnownStreams.RemoveAll(s => !results.Any(r => r.Name().Equals(s.Name))); + streams.RemoveAll(s => !results.Any(r => r.Name().Equals(s.name))); // add new found streams to the cache foreach (var item in results) { - if (!KnownStreams.Any(s => s.Name == item.Name() && s.Type == item.Type())) + if (!streams.Any(s => s.name == item.Name() && s.type == item.Type())) { Debug.Log($"Found new Stream {item.Name()}"); var newStreamInfo = new LSLStreamInfoWrapper(item); - KnownStreams.Add(newStreamInfo); + streams.Add(newStreamInfo); - if (OnStreamFound.GetPersistentEventCount() > 0) { OnStreamFound.Invoke(newStreamInfo); } + if (onStreamFound.GetPersistentEventCount() > 0) { onStreamFound.Invoke(newStreamInfo); } } } yield return new WaitForSecondsRealtime(0.1f); @@ -78,8 +78,8 @@ namespace LSL4Unity.Scripts [Serializable] public class LSLStreamInfoWrapper { - public string Name; - public string Type; + public string name; + public string type; public liblsl.StreamInfo Item { get; } @@ -94,8 +94,8 @@ namespace LSL4Unity.Scripts public LSLStreamInfoWrapper(liblsl.StreamInfo item) { Item = item; - Name = item.Name(); - Type = item.Type(); + name = item.Name(); + type = item.Type(); ChannelCount = item.ChannelCount(); StreamUid = item.Uid(); SessionId = item.SessionId(); diff --git a/Scripts/ScriptOrder.cs b/Scripts/ScriptOrder.cs index f6f6ab63a70eea3514a04d2b0f57b026b2264bcb..e29736e0df56d7d9a7d6a25e51e896efb9b6493c 100644 --- a/Scripts/ScriptOrder.cs +++ b/Scripts/ScriptOrder.cs @@ -1,6 +1,6 @@ -using System; +using System; -namespace LSL4Unity.Scripts +namespace LSL4Unity { /// <summary> /// This attribute is used to define specific script execution orders when necessary! @@ -9,8 +9,8 @@ namespace LSL4Unity.Scripts /// </summary> public class ScriptOrder : Attribute { - public readonly int Order; + public readonly int order; - public ScriptOrder(int order) { Order = order; } + public ScriptOrder(int order) { this.order = order; } } }