Compare commits

...

8 Commits
v0.1.0 ... main

15 changed files with 2622 additions and 31 deletions

41
.github/ISSUE_TEMPLATE/bug_report.md vendored Normal file
View File

@ -0,0 +1,41 @@
---
name: Bug report
about: Create a report to help us improve
title: ''
labels: ''
assignees: ''
---
**Describe the bug**
A clear and concise description of what the bug is.
**To Reproduce**
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
**Expected behavior**
A clear and concise description of what you expected to happen.
**Screenshots**
If applicable, add screenshots to help explain your problem.
**Development Environment**:
- OS: [e.g. Windows 11, Ubuntu 23.04]
- Architecture: [e.g. x86_64, ARM64]
- Runtime: [e.g. Godot 4.1, .NET 6]
- Library version: [e.g. v0.1.0]
**Cross-OS/Architecture Desktop Builds:**
- OS: [e.g. Windows 11, Ubuntu 23.04]
- Architecture: [e.g. x86_64, ARM64]
**Smartphone Builds:**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
**Additional context**
Add any other context about the problem here.

View File

@ -0,0 +1,20 @@
---
name: Feature request
about: Suggest an idea for this project
title: ''
labels: ''
assignees: ''
---
**Is your feature request related to a problem? Please describe.**
A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
**Describe the solution you'd like**
A clear and concise description of what you want to happen.
**Describe alternatives you've considered**
A clear and concise description of any alternative solutions or features you've considered.
**Additional context**
Add any other context or screenshots about the feature request here.

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
node_modules
.husky

128
CODE_OF_CONDUCT.md Normal file
View File

@ -0,0 +1,128 @@
# Contributor Covenant Code of Conduct
## Our Pledge
We as members, contributors, and leaders pledge to make participation in our
community a harassment-free experience for everyone, regardless of age, body
size, visible or invisible disability, ethnicity, sex characteristics, gender
identity and expression, level of experience, education, socio-economic status,
nationality, personal appearance, race, religion, or sexual identity
and orientation.
We pledge to act and interact in ways that contribute to an open, welcoming,
diverse, inclusive, and healthy community.
## Our Standards
Examples of behavior that contributes to a positive environment for our
community include:
* Demonstrating empathy and kindness toward other people
* Being respectful of differing opinions, viewpoints, and experiences
* Giving and gracefully accepting constructive feedback
* Accepting responsibility and apologizing to those affected by our mistakes,
and learning from the experience
* Focusing on what is best not just for us as individuals, but for the
overall community
Examples of unacceptable behavior include:
* The use of sexualized language or imagery, and sexual attention or
advances of any kind
* Trolling, insulting or derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or email
address, without their explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting
## Enforcement Responsibilities
Community leaders are responsible for clarifying and enforcing our standards of
acceptable behavior and will take appropriate and fair corrective action in
response to any behavior that they deem inappropriate, threatening, offensive,
or harmful.
Community leaders have the right and responsibility to remove, edit, or reject
comments, commits, code, wiki edits, issues, and other contributions that are
not aligned to this Code of Conduct, and will communicate reasons for moderation
decisions when appropriate.
## Scope
This Code of Conduct applies within all community spaces, and also applies when
an individual is officially representing the community in public spaces.
Examples of representing our community include using an official e-mail address,
posting via an official social media account, or acting as an appointed
representative at an online or offline event.
## Enforcement
Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
me@cass-dlcm.dev.
All complaints will be reviewed and investigated promptly and fairly.
All community leaders are obligated to respect the privacy and security of the
reporter of any incident.
## Enforcement Guidelines
Community leaders will follow these Community Impact Guidelines in determining
the consequences for any action they deem in violation of this Code of Conduct:
### 1. Correction
**Community Impact**: Use of inappropriate language or other behavior deemed
unprofessional or unwelcome in the community.
**Consequence**: A private, written warning from community leaders, providing
clarity around the nature of the violation and an explanation of why the
behavior was inappropriate. A public apology may be requested.
### 2. Warning
**Community Impact**: A violation through a single incident or series
of actions.
**Consequence**: A warning with consequences for continued behavior. No
interaction with the people involved, including unsolicited interaction with
those enforcing the Code of Conduct, for a specified period of time. This
includes avoiding interactions in community spaces as well as external channels
like social media. Violating these terms may lead to a temporary or
permanent ban.
### 3. Temporary Ban
**Community Impact**: A serious violation of community standards, including
sustained inappropriate behavior.
**Consequence**: A temporary ban from any sort of interaction or public
communication with the community for a specified period of time. No public or
private interaction with the people involved, including unsolicited interaction
with those enforcing the Code of Conduct, is allowed during this period.
Violating these terms may lead to a permanent ban.
### 4. Permanent Ban
**Community Impact**: Demonstrating a pattern of violation of community
standards, including sustained inappropriate behavior, harassment of an
individual, or aggression toward or disparagement of classes of individuals.
**Consequence**: A permanent ban from any sort of public interaction within
the community.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 2.0, available at
https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
Community Impact Guidelines were inspired by [Mozilla's code of conduct
enforcement ladder](https://github.com/mozilla/diversity).
[homepage]: https://www.contributor-covenant.org
For answers to common questions about this code of conduct, see the FAQ at
https://www.contributor-covenant.org/faq. Translations are available at
https://www.contributor-covenant.org/translations.

View File

@ -0,0 +1,18 @@
using System;
namespace godotOscSharp
{
public class InvalidDataTypeException : ArgumentException
{
public InvalidDataTypeException(): base() {}
public InvalidDataTypeException(String message): base(message) {}
public InvalidDataTypeException(Char expected, Char actual): base($"Invalid data type: Received '{actual}', expected '{expected}'.") {}
public InvalidDataTypeException(String expected, Char actual): base($"Invalid data type: Received '{actual}', expected '{expected}'.") {}
public InvalidDataTypeException(Char expected, Char actual, Exception inner): base($"Invalid data type: Received '{actual}', expected '{expected}'.", inner) {}
public InvalidDataTypeException(String expected, Char actual, Exception inner): base($"Invalid data type: Received '{actual}', expected '{expected}'.", inner) {}
public InvalidDataTypeException(String address, int index, String name, Char expected, Char actual): base($"{address}[{index}] {name} has invalid data type. Received '{actual}', expected '{expected}'.") {}
public InvalidDataTypeException(String address, int index, String name, Char expected, Char actual, Exception inner): base($"{address}[{index}] {name} has invalid data type. Received '{actual}', expected '{expected}'.", inner) {}
public InvalidDataTypeException(OscAddress address, int index, String name, Char expected, Char actual): base($"{address.ToString()}[{index}] {name} has invalid data type. Received '{actual}', expected '{expected}'.") {}
public InvalidDataTypeException(OscAddress address, int index, String name, Char expected, Char actual, Exception inner): base($"{address.ToString()}[{index}] {name} has invalid data type. Received '{actual}', expected '{expected}'.", inner) {}
}
}

View File

@ -21,11 +21,11 @@ using System.Text.RegularExpressions;
namespace godotOscSharp namespace godotOscSharp
{ {
public class Address public class OscAddress
{ {
public string Pattern { get; } public string Pattern { get; }
public Address(string pattern) public OscAddress(string pattern)
{ {
if (string.IsNullOrEmpty(pattern)) if (string.IsNullOrEmpty(pattern))
{ {
@ -63,7 +63,7 @@ namespace godotOscSharp
return result.ToArray(); return result.ToArray();
} }
public static Address Parse(byte[] data, ref int index) public static OscAddress Parse(byte[] data, ref int index)
{ {
var start = index; var start = index;
while (data[index] != 0) while (data[index] != 0)
@ -74,7 +74,7 @@ namespace godotOscSharp
index++; index++;
var padding = 4 - ((index - start) % 4); var padding = 4 - ((index - start) % 4);
index += padding; index += padding;
return new Address(pattern); return new OscAddress(pattern);
} }
public override string ToString() public override string ToString()

View File

@ -18,6 +18,8 @@
using System; using System;
#nullable enable
namespace godotOscSharp namespace godotOscSharp
{ {
// A class that represents a DWord // A class that represents a DWord
@ -25,10 +27,30 @@ namespace godotOscSharp
{ {
// The value of the DWord as an unsigned integer // The value of the DWord as an unsigned integer
public char Type { get; } public char Type { get; }
public object Value { get; } private object? Value { get; }
public static OscArgument CreateFromParams(object? value, char type)
{
switch (type) {
case 'i':
case 'f':
case 's':
case 'h':
case 'd':
return new OscArgument(value, type);
case 'T':
return new OscArgument(true, type);
case 'F':
return new OscArgument(false, type);
case 'N':
return new OscArgument(null, type);
default:
throw new ArgumentException($"Invalid argument type: {type}");
}
}
// The constructor that takes an unsigned integer as the value // The constructor that takes an unsigned integer as the value
public OscArgument(object value, char type) private OscArgument(object? value, char type)
{ {
Value = value; Value = value;
Type = type; Type = type;
@ -38,7 +60,7 @@ namespace godotOscSharp
public static OscArgument Parse(byte[] data, ref int index, char type) public static OscArgument Parse(byte[] data, ref int index, char type)
{ {
// Use BitConverter to get the unsigned integer from the bytes at the given index in little-endian order // Use BitConverter to get the unsigned integer from the bytes at the given index in little-endian order
object value = null; object? value = null;
var start = index; var start = index;
switch (type) { switch (type) {
case 'i': case 'i':
@ -78,23 +100,82 @@ namespace godotOscSharp
value = null; value = null;
break; break;
} }
// Increment the index by 4 bytes
// Return a new DWord instance with the value
return new OscArgument(value, type); return new OscArgument(value, type);
} }
public Int32 GetAsInt32()
{
if (Type != 'i') {
throw new InvalidDataTypeException('i', Type);
}
return (Int32)Value!;
}
public float GetAsFloat()
{
if (Type != 'f') {
throw new InvalidDataTypeException('f', Type);
}
return (float)Value!;
}
public String GetAsString() {
if (Type != 's')
{
throw new InvalidDataTypeException('s', Type);
}
return (String)Value!;
}
public Int64 GetAsInt64()
{
if (Type != 'h')
{
throw new InvalidDataTypeException('h', Type);
}
return (Int64)Value!;
}
public Double GetAsDouble()
{
if (Type != 'd')
{
throw new InvalidDataTypeException('d', Type);
}
return (Double)Value!;
}
public bool GetAsBool() {
switch (Type)
{
case 'T':
return true;
case 'F':
return false;
default:
throw new InvalidDataTypeException("{T, F}", Type);
}
}
public object? GetAsNull()
{
if (Type != 'N')
{
throw new InvalidDataTypeException('N', Type);
}
return null;
}
public byte[] ToBytes() public byte[] ToBytes()
{ {
switch (Type) { switch (Type) {
case 'i': case 'i':
return BitConverter.GetBytes((int)Value); return BitConverter.GetBytes((int)Value!);
case 'f': case 'f':
return BitConverter.GetBytes((float)Value); return BitConverter.GetBytes((float)Value!);
case 's': case 's':
var result = new System.Collections.Generic.List<byte>(); var result = new System.Collections.Generic.List<byte>();
result.AddRange(System.Text.Encoding.ASCII.GetBytes((string)Value)); result.AddRange(System.Text.Encoding.ASCII.GetBytes((string)Value!));
result.Add(0); result.Add(0);
var padding = 4 - (result.Count % 4); var padding = 4 - (result.Count % 4);
for (int i = 0; i < padding; i++) for (int i = 0; i < padding; i++)
@ -103,16 +184,16 @@ namespace godotOscSharp
} }
return result.ToArray(); return result.ToArray();
case 'h': case 'h':
return BitConverter.GetBytes((long)Value); return BitConverter.GetBytes((long)Value!);
case 'd': case 'd':
return BitConverter.GetBytes((double)Value); return BitConverter.GetBytes((double)Value!);
} }
return new byte[0]; return new byte[0];
} }
public override string ToString() public override string ToString()
{ {
return Value.ToString(); return Value?.ToString()!;
} }
} }
} }

View File

@ -20,7 +20,6 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using Godot;
namespace godotOscSharp namespace godotOscSharp
{ {

39
OscClient.cs Normal file
View File

@ -0,0 +1,39 @@
using System;
using System.Net;
namespace godotOscSharp
{
public class OscClient
{
private readonly OscReceiver receiver;
private readonly OscSender sender;
public OscClient(IPAddress host, int port)
{
receiver = new OscReceiver(port);
sender = new OscSender(host, port);
}
public void SenderConnect() {
sender.Connect();
}
public void Send(OscMessage message) {
sender.Send(message);
}
public void AddMessageReceived(EventHandler<OscMessageReceivedEventArgs> func) {
receiver.MessageReceived += func;
}
public void AddErrorReceived(EventHandler<OscErrorReceivedEventArgs> func) {
receiver.ErrorReceived += func;
}
public void Dispose()
{
receiver.Dispose();
sender.Dispose();
}
}
}

View File

@ -26,11 +26,17 @@ namespace godotOscSharp
{ {
public class OscMessage public class OscMessage
{ {
public Address Address { get; } public OscAddress Address { get; }
public List<OscArgument> Data { get; } public List<OscArgument> Data { get; }
public OscMessage(Address address, List<OscArgument> data) public OscMessage(OscAddress address)
{
Address = address;
Data = new List<OscArgument>();
}
public OscMessage(OscAddress address, List<OscArgument> data)
{ {
Address = address; Address = address;
Data = data; Data = data;
@ -39,7 +45,7 @@ namespace godotOscSharp
public static OscMessage Parse(byte[] data) public static OscMessage Parse(byte[] data)
{ {
var index = 0; var index = 0;
var address = Address.Parse(data, ref index); var address = OscAddress.Parse(data, ref index);
var start = index; var start = index;
while (data[index] != 0) while (data[index] != 0)
{ {
@ -89,4 +95,4 @@ namespace godotOscSharp
return result.ToArray(); return result.ToArray();
} }
} }
} }

View File

@ -16,22 +16,23 @@
along with this program. If not, see <https://www.gnu.org/licenses/>. along with this program. If not, see <https://www.gnu.org/licenses/>.
*/ */
using Godot;
using System; using System;
using System.Net; using System.Net;
using System.Net.Sockets; using System.Net.Sockets;
using System.Threading; using System.Threading;
#nullable enable
namespace godotOscSharp namespace godotOscSharp
{ {
// A class that represents an OSC receiver // A class that represents an OSC receiver
public class OscReceiver : IDisposable public class OscReceiver : IDisposable
{ {
// The UDP client for receiving data // The UDP client for receiving data
private UdpClient udpClient; private readonly UdpClient udpClient;
// The thread for listening to incoming messages // The thread for listening to incoming messages
private Thread listenThread; private readonly Thread listenThread;
// The flag to indicate if the receiver is running // The flag to indicate if the receiver is running
private bool running; private bool running;
@ -84,10 +85,10 @@ namespace godotOscSharp
} }
// An event that occurs when a message is received // An event that occurs when a message is received
public event EventHandler<OscMessageReceivedEventArgs> MessageReceived; public event EventHandler<OscMessageReceivedEventArgs>? MessageReceived;
// An event that occurs when an error is received // An event that occurs when an error is received
public event EventHandler<OscErrorReceivedEventArgs> ErrorReceived; public event EventHandler<OscErrorReceivedEventArgs>? ErrorReceived;
} }
// A class that contains the data for the message received event // A class that contains the data for the message received event

View File

@ -24,15 +24,15 @@ namespace godotOscSharp
{ {
public class OscSender : IDisposable public class OscSender : IDisposable
{ {
private UdpClient udpClient; private readonly UdpClient udpClient;
private IPAddress host; private readonly IPAddress host;
private int port; private readonly int port;
public OscSender(IPAddress host, int port) public OscSender(IPAddress host, int port)
{ {
udpClient = new UdpClient(0); udpClient = new UdpClient(port);
this.host = host; this.host = host;
this.port = port; this.port = port;
} }

1
commitlint.config.js Normal file
View File

@ -0,0 +1 @@
module.exports = { extends: ['@commitlint/config-conventional'] };

2248
package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

7
package.json Normal file
View File

@ -0,0 +1,7 @@
{
"devDependencies": {
"@commitlint/cli": "^17.8.0",
"@commitlint/config-conventional": "^17.8.0",
"husky": "^8.0.3"
}
}