Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
myd7349 committed Aug 10, 2024
1 parent ea34c2f commit e219ba9
Show file tree
Hide file tree
Showing 33 changed files with 3,764 additions and 206 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
Binding/SharpLSL.Header.cs text eol=lf
Source/SharpLSL/Interop/*.g.cs text eol=lf
9 changes: 8 additions & 1 deletion Binding/generate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ ClangSharpPInvokeGenerator `
--language c++ `
--methodClassName Common `
--namespace SharpLSL.Interop `
--additional -m64 `
--output ../Source/SharpLSL/Interop

Move-Item -Path ../Source/SharpLSL/Interop/Common.cs -Destination ../Source/SharpLSL/Interop/Common.g.cs -Force
Expand All @@ -29,6 +30,7 @@ ClangSharpPInvokeGenerator `
--language c++ `
--methodClassName LSL `
--namespace SharpLSL.Interop `
--additional -m64 `
--output ../Source/SharpLSL/Interop/Common.g.cs `
--remap `
sbyte*=IntPtr `
Expand All @@ -49,6 +51,7 @@ ClangSharpPInvokeGenerator `
--language c++ `
--methodClassName LSL `
--namespace SharpLSL.Interop `
--additional -m64 `
--output ../Source/SharpLSL/Interop/Inlet.g.cs `
--remap `
lsl_inlet=IntPtr `
Expand All @@ -65,6 +68,7 @@ ClangSharpPInvokeGenerator `
--language c++ `
--methodClassName LSL `
--namespace SharpLSL.Interop `
--additional -m64 `
--output ../Source/SharpLSL/Interop/Outlet.g.cs `
--remap `
lsl_outlet=IntPtr `
Expand All @@ -81,6 +85,7 @@ ClangSharpPInvokeGenerator `
--language c++ `
--methodClassName LSL `
--namespace SharpLSL.Interop `
--additional -m64 `
--output ../Source/SharpLSL/Interop/Resolver.g.cs `
--remap `
lsl_continuous_resolver=IntPtr `
Expand All @@ -97,6 +102,7 @@ ClangSharpPInvokeGenerator `
--language c++ `
--methodClassName LSL `
--namespace SharpLSL.Interop `
--additional -m64 `
--output ../Source/SharpLSL/Interop/StreamInfo.g.cs `
--remap `
lsl_streaminfo=IntPtr `
Expand All @@ -113,7 +119,8 @@ ClangSharpPInvokeGenerator `
--language c++ `
--methodClassName LSL `
--namespace SharpLSL.Interop `
--output ../Source/SharpLSL/Interop/Xml.g.cs `
--additional -m64 `
--output ../Source/SharpLSL/Interop/XML.g.cs `
--remap `
lsl_xml_ptr=IntPtr

Expand Down
2 changes: 1 addition & 1 deletion Examples/LSLVer/LSLVer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="SharpLSL.Native.all" Version="1.16.2" />
<PackageReference Include="SharpLSL.Native.all" Version="1.16.2.1" />
</ItemGroup>

<ItemGroup>
Expand Down
7 changes: 3 additions & 4 deletions Examples/LSLVer/Program.cs
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
// Port of https://github.com/sccn/liblsl/blob/master/testing/lslver.c
using SharpLSL;
using SharpLSL.Interop;

namespace LSLVer
{
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine($"LSL version: {LSL.lsl_library_version()}");
Console.WriteLine(Lsl.GetLibraryInfo());
Console.WriteLine(Lsl.GetLocalClock());
Console.WriteLine($"LSL version: {LSL.GetLibraryVersion()}");
Console.WriteLine(LSL.GetLibraryInfo());
Console.WriteLine(LSL.GetLocalClock());
}
}
}
96 changes: 96 additions & 0 deletions Source/SharpLSL/ChannelFormat.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
using SharpLSL.Interop;

namespace SharpLSL
{
/// <summary>
/// Data format of a channel.
/// </summary>
/// <remarks>
/// This enumeration specifies the format of data transmitted for each channel.
/// Each transmitted sample contains an array of channels, and this enum describes
/// the format of the data sent over the wire.
/// </remarks>
/// <seealso cref="StreamInfo.ChannelFormat"/>
public enum ChannelFormat : int
{
/// <summary>
/// Represents a 32-bit floating-point format.
/// </summary>
/// <remarks>
/// This format is used for measurements that require up to 24-bit precision,
/// such as physical quantities measured in microvolts. Integers within the
/// range of -16,777,216 to 16,777,216 are represented accurately using this
/// format.
/// </remarks>
Float = lsl_channel_format_t.cft_float32,

/// <summary>
/// Represents a 64-bit double-precision floating-point format.
/// </summary>
/// <remarks>
/// This format is used for representing numerical data with high precision
/// for universal numeric data as long as permitted by network & disk budget.
/// The largest representable integer is 53-bit.
/// </remarks>
Double = lsl_channel_format_t.cft_double64,

/// <summary>
/// Represents variable-length ASCII strings or data blobs.
/// </summary>
/// <remarks>
/// This format is suitable for data that cannot be easily represented as
/// numeric values, such as video frames, or complex event descriptions.
/// </remarks>
String = lsl_channel_format_t.cft_string,

/// <summary>
/// Represents a 32-bit signed integer format.
/// </summary>
/// <remarks>
/// This format is used for transmitting data that requires 32-bit integer
/// precision. It is suitable for high-rate digitized formats and cases
/// where the data is represented as discrete numeric values, such as
/// application event codes or other coded data.
/// </remarks>
Int32 = lsl_channel_format_t.cft_int32,

/// <summary>
/// Represents a 16-bit signed integer format.
/// </summary>
/// <remarks>
/// This format is used for transmitting data with 16-bit integer precision.
/// It is ideal for very high-rate signals (40kHz+) or consumer-grade audio.
/// For professional audio, <see cref="Float"/> is recommended.
/// </remarks>
Int16 = lsl_channel_format_t.cft_int16,

/// <summary>
/// Represents an 8-bit signed integer format.
/// </summary>
/// <remarks>
/// This format is used for transmitting data with 8-bit integer precision.
/// It is suitable for binary signals or other coded data. It is not
/// recommended for encoding string data.
/// </remarks>
Int8 = lsl_channel_format_t.cft_int8,

/// <summary>
/// Represents a 64-bit signed integer format.
/// </summary>
/// <remarks>
/// This format is used for transmitting data that requires 64-bit integer
/// precision. Note that support for `Int64` is not yet exposed in all languages.
/// Also, some builds of liblsl will not be able to send or receive data of this type.
/// </remarks>
Int64 = lsl_channel_format_t.cft_int64,

/// <summary>
/// Represents an undefined or unsupported data format.
/// </summary>
/// <remarks>
/// This format indicates that the data format is either not defined or
/// not supported for transmission.
/// </remarks>
Undefined = lsl_channel_format_t.cft_undefined,
}
}
91 changes: 91 additions & 0 deletions Source/SharpLSL/ContinuousResolver.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
using System;

using static SharpLSL.Interop.LSL;
using static SharpLSL.LSL;

namespace SharpLSL
{
public class ContinuousResolver : LSLObject
{
public ContinuousResolver(double forgetAfter = 5.0)
: base(lsl_create_continuous_resolver(forgetAfter))
{
}

public ContinuousResolver(string property, string value, double forgetAfter = 5.0)
: base(lsl_create_continuous_resolver_byprop(property, value, forgetAfter))
{
}

public ContinuousResolver(string predicate, double forgetAfter = 5.0)
: base(lsl_create_continuous_resolver_bypred(predicate, forgetAfter))
{
}

public ContinuousResolver(IntPtr handle, bool ownsHandle = true)
: base(handle, ownsHandle)
{
}

public StreamInfo[] Resolve(int maxCount = 1024)
{
var streamInfoPointers = new IntPtr[maxCount];

var result = lsl_resolver_results(handle, streamInfoPointers, (uint)streamInfoPointers.Length);
CheckError(result);

var streamInfos = new StreamInfo[result];
for (int i = 0; i < result; ++i)
streamInfos[i] = new StreamInfo(streamInfoPointers[i], true);

return streamInfos;
}

public StreamInfo[] ResolveAll(int maxCount = 1024, double waitTime = 1.0)
{
var streamInfoPointers = new IntPtr[maxCount];

var result = lsl_resolve_all(streamInfoPointers, (uint)streamInfoPointers.Length, waitTime);
CheckError(result);

var streamInfos = new StreamInfo[result];
for (int i = 0; i < result; ++i)
streamInfos[i] = new StreamInfo(streamInfoPointers[i], true);

return streamInfos;
}

public StreamInfo[] Resolve(string property, string value, int minCount, int maxCount = 1024, double timeout = Forever)
{
var streamInfoPointers = new IntPtr[maxCount];

var result = lsl_resolve_byprop(streamInfoPointers, (uint)streamInfoPointers.Length, property, value, minCount, timeout);
CheckError(result);

var streamInfos = new StreamInfo[result];
for (int i = 0; i < result; ++i)
streamInfos[i] = new StreamInfo(streamInfoPointers[i], true);

return streamInfos;
}

public StreamInfo[] Resolve(string predicate, int minCount, int maxCount = 1024, double timeout = Forever)
{
var streamInfoPointers = new IntPtr[maxCount];

var result = lsl_resolve_bypred(streamInfoPointers, (uint)streamInfoPointers.Length, predicate, minCount, timeout);
CheckError(result);

var streamInfos = new StreamInfo[result];
for (int i = 0; i < result; ++i)
streamInfos[i] = new StreamInfo(streamInfoPointers[i], true);

return streamInfos;
}

protected override void DestroyLSLObject()
{
lsl_destroy_continuous_resolver(handle);
}
}
}
Loading

0 comments on commit e219ba9

Please sign in to comment.