From 82b8e808041454052dd9032aa4e3d2e6e2f66b4d Mon Sep 17 00:00:00 2001
From: Thibaut Monseigne <thibaut.monseigne@inria.fr>
Date: Thu, 20 May 2021 14:41:11 +0200
Subject: [PATCH] :memo: Remove log

---
 OV/OVInlets.cs | 282 +++++++++++++++++++++++++------------------------
 1 file changed, 143 insertions(+), 139 deletions(-)

diff --git a/OV/OVInlets.cs b/OV/OVInlets.cs
index 8f9d562..4a7aea8 100644
--- a/OV/OVInlets.cs
+++ b/OV/OVInlets.cs
@@ -4,185 +4,189 @@ using UnityEngine;
 
 namespace LSL4Unity.OV
 {
-	/// <summary> Base Inlet for OpenViBE Link. </summary>
-	/// <seealso cref="MonoBehaviour" />
-	public abstract class OVInlet<T> : MonoBehaviour
-	{
-		private enum UpdateMoment { FixedUpdate, Update, OnDemand }
-
-		[SerializeField] private UpdateMoment moment     = UpdateMoment.Update;
-		[SerializeField] private string       streamName = "ovSignal";
-		[SerializeField] private bool         waitStream = true;
+/// <summary> Base Inlet for OpenViBE Link. </summary>
+/// <seealso cref="MonoBehaviour" />
+public abstract class OVInlet<T> : MonoBehaviour
+{
+	private enum UpdateMoment { FixedUpdate, Update, OnDemand }
 
-		public string StreamName => streamName;
+	[SerializeField] private UpdateMoment moment     = UpdateMoment.Update;
+	[SerializeField] private string       streamName = "ovSignal";
+	[SerializeField] private bool         waitStream = true;
 
-		protected liblsl.StreamInlet        inlet;
-		private   liblsl.ContinuousResolver resolver;
+	public string StreamName   => streamName;
+	public int    ChannelCount => expectedChannels;
 
-		private   bool readyToResolve   = true;
-		protected int  expectedChannels = 0;
-		protected T[]  samples;
+	protected liblsl.StreamInlet        inlet;
+	private   liblsl.ContinuousResolver resolver;
 
+	private   bool readyToResolve   = true;
+	protected int  expectedChannels = 0;
+	protected T[]  samples          = null;
 
-		/// <summary> Start is called before the first frame update. </summary>
-		private void Start()
-		{
-			bool hasAName = streamName.Length != 0;
-
-			if (!hasAName)
-			{
-				Debug.LogError("Inlet has to specify a name or a type before it is able to lookup a stream.");
-				enabled = false;
-				return;
-			}
 
-			Debug.Log("Creating LSL resolver for stream " + streamName);
-			resolver = new liblsl.ContinuousResolver("name", streamName);
-			ResolveStream();
-		}
+	/// <summary> Start is called before the first frame update. </summary>
+	private void Start()
+	{
+		bool hasAName = streamName.Length != 0;
 
-		/// <summary> Fixupdate is called once per physics framerate. </summary>
-		private void FixedUpdate()
+		if (!hasAName)
 		{
-			if (moment == UpdateMoment.FixedUpdate && inlet != null) { PullSamples(); }
+			Debug.LogError("Inlet has to specify a name or a type before it is able to lookup a stream.");
+			enabled = false;
+			return;
 		}
 
-		/// <summary> Update is called once per frame. </summary>
-		private void Update()
-		{
-			if (moment == UpdateMoment.Update && inlet != null) { PullSamples(); }
-		}
+		Debug.Log("Creating LSL resolver for stream " + streamName);
+		resolver = new liblsl.ContinuousResolver("name", streamName);
+		ResolveStream();
+	}
 
-		/// <summary> ForceUpdate is called when it's needed. </summary>
-		public void ForceUpdate() { PullSamples(); }
+	/// <summary> Fixupdate is called once per physics framerate. </summary>
+	private void FixedUpdate()
+	{
+		if (moment == UpdateMoment.FixedUpdate && inlet != null) { PullSamples(); }
+	}
 
-		/// <summary> Start coroutine to resolve stream. </summary>
-		public void ResolveStream()
-		{
-			if (inlet == null) { StartCoroutine(ResolveExpectedStream()); }
-		}
+	/// <summary> Update is called once per frame. </summary>
+	private void Update()
+	{
+		if (moment == UpdateMoment.Update && inlet != null) { PullSamples(); }
+	}
 
-		/// <summary> Check if inlet is created. </summary>
-		public bool IsSolved() { return (inlet != null); }
+	/// <summary> ForceUpdate is called when it's needed. </summary>
+	public void ForceUpdate() { PullSamples(); }
 
-		private void CreateInlet(liblsl.StreamInfo result)
-		{
-			Debug.Log($"Resolving Stream : Name = {streamName}, Steam Info Name = {result.Name()}, Stream Info Type = ({result.Type()}");
-			inlet            = new liblsl.StreamInlet(result);
-			expectedChannels = inlet.Info().ChannelCount();
-		}
+	/// <summary> Start coroutine to resolve stream. </summary>
+	public void ResolveStream()
+	{
+		if (inlet == null) { StartCoroutine(ResolveExpectedStream()); }
+	}
 
-		/// <summary> Resolves the stream. </summary>
-		/// <returns></returns>
-		private IEnumerator ResolveExpectedStream()
-		{
-			Debug.Log($"private IEnumerator ResolveExpectedStream()");
-			yield return new WaitUntil(() => readyToResolve); // False mutex to wait Found Stream before search an other
-			readyToResolve = false;                           // Avoïd double resolver
-
-			liblsl.StreamInfo[] results = resolver.Results();
-			if (waitStream) { yield return new WaitUntil(() => results.Length > 0); }
-			if (results.Length > 0) { CreateInlet(results[0]); }
-			readyToResolve = true;
-			yield return null;
-		}
+	/// <summary> Check if inlet is created. </summary>
+	public bool IsSolved() { return (inlet != null); }
 
-		/// <summary> Pull the samples. </summary>
-		protected abstract void PullSamples();
+	public void PopSamples() { samples = null; }
 
-		/// <summary> Override this method in the subclass to specify what should happen when samples are available. </summary>
-		/// <param name="input"> The Incomming Sample. </param>
-		/// <param name="time"> The current Time. </param>
-		protected abstract void Process(T[] input, double time);
+
+	private void CreateInlet(liblsl.StreamInfo result)
+	{
+		Debug.Log($"Resolving Stream : Name = {streamName}, Steam Info Name = {result.Name()}, Stream Info Type = ({result.Type()}");
+		inlet            = new liblsl.StreamInlet(result);
+		expectedChannels = inlet.Info().ChannelCount();
 	}
 
-	/// <summary> Float Inlet for OpenViBE Link. </summary>
-	/// <seealso cref="OVInlet{T}" />
-	public abstract class OVFloatInlet : OVInlet<float>
+	/// <summary> Resolves the stream. </summary>
+	/// <returns></returns>
+	private IEnumerator ResolveExpectedStream()
 	{
-		/// <inheritdoc cref="OVInlet{T}.PullSamples"/>
-		protected override void PullSamples()
+		//Debug.Log($"private IEnumerator ResolveExpectedStream()");
+		yield return new WaitUntil(() => readyToResolve); // False mutex to wait Found Stream before search an other
+		readyToResolve = false;                           // Avoïd double resolver
+
+		liblsl.StreamInfo[] results = resolver.Results();
+		if (waitStream) { yield return new WaitUntil(() => results.Length > 0); }
+		if (results.Length > 0) { CreateInlet(results[0]); }
+		readyToResolve = true;
+		yield return null;
+	}
+
+	/// <summary> Pull the samples. </summary>
+	protected abstract void PullSamples();
+
+	/// <summary> Override this method in the subclass to specify what should happen when samples are available. </summary>
+	/// <param name="input"> The Incomming Sample. </param>
+	/// <param name="time"> The current Time. </param>
+	protected abstract void Process(T[] input, double time);
+}
+
+/// <summary> Float Inlet for OpenViBE Link. </summary>
+/// <seealso cref="OVInlet{T}" />
+public abstract class OVFloatInlet : OVInlet<float>
+{
+	/// <inheritdoc cref="OVInlet{T}.PullSamples"/>
+	protected override void PullSamples()
+	{
+		samples = new float[expectedChannels];
+
+		try
 		{
-			samples = new float[expectedChannels];
+			double lastTimeStamp = inlet.PullSample(samples, 0.0f);
 
-			try
+			if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE)
 			{
-				double lastTimeStamp = inlet.PullSample(samples, 0.0f);
-
-				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);
+				// 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);
+		}
 	}
+}
 
-	/// <summary> Double Inlet for OpenViBE Link. </summary>
-	/// <seealso cref="OVInlet{T}" />
-	public abstract class OVDoubleInlet : OVInlet<double>
+/// <summary> Double Inlet for OpenViBE Link. </summary>
+/// <seealso cref="OVInlet{T}" />
+public abstract class OVDoubleInlet : OVInlet<double>
+{
+	/// <inheritdoc cref="OVInlet{T}.PullSamples"/>
+	protected override void PullSamples()
 	{
-		/// <inheritdoc cref="OVInlet{T}.PullSamples"/>
-		protected override void PullSamples()
+		samples = new double[expectedChannels];
+
+		try
 		{
-			samples = new double[expectedChannels];
+			double lastTimeStamp = inlet.PullSample(samples, 0.0f);
 
-			try
-			{
-				double lastTimeStamp = inlet.PullSample(samples, 0.0f);
-
-				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)
+			if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE)
 			{
-				Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this);
-				enabled = false;
-				Debug.LogException(e, this);
+				// 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);
+		}
 	}
+}
 
-	/// <summary> Int Inlet for OpenViBE Link. </summary>
-	/// <seealso cref="OVInlet{T}" />
-	public abstract class OVIntInlet : OVInlet<int>
+/// <summary> Int Inlet for OpenViBE Link. </summary>
+/// <seealso cref="OVInlet{T}" />
+public abstract class OVIntInlet : OVInlet<int>
+{
+	/// <inheritdoc cref="OVInlet{T}.PullSamples"/>
+	protected override void PullSamples()
 	{
-		/// <inheritdoc cref="OVInlet{T}.PullSamples"/>
-		protected override void PullSamples()
+		samples = new int[expectedChannels];
+
+		try
 		{
-			samples = new int[expectedChannels];
+			double lastTimeStamp = inlet.PullSample(samples, 0.0f);
 
-			try
-			{
-				double lastTimeStamp = inlet.PullSample(samples, 0.0f);
-
-				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)
+			if (Math.Abs(lastTimeStamp) > Constants.TOLERANCE)
 			{
-				Debug.LogError("An Error on pulling samples deactivating LSL inlet on...", this);
-				enabled = false;
-				Debug.LogException(e, this);
+				// 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);
+		}
 	}
 }
+}
-- 
GitLab