Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extensibility for custom OscClient.Send() method signatures ? #37

Open
zacksettel opened this issue Nov 4, 2022 · 3 comments
Open

Extensibility for custom OscClient.Send() method signatures ? #37

zacksettel opened this issue Nov 4, 2022 · 3 comments
Assignees

Comments

@zacksettel
Copy link

It would be great to be able to extend the class OscClient in order to create additional OscClient.Send() method signatures. For example, I often need to send the following type of OSC message:

public void Send(string address, string str, float data1, float data2, float data3)

For some time now, I have used a forked version of OscJack, but it seems that if there was a way for me to extend the OscClient class (currently sealed), that would be the best (I rely several different method signatures for OscClient.Send()

Or maybe there's another approach beside the fork?

@keijiro keijiro self-assigned this Nov 4, 2022
@keijiro
Copy link
Owner

keijiro commented Nov 4, 2022

It's not extensible at the moment. At least, I should remove sealed from OscClient/OscServer.

@aaronvark
Copy link

aaronvark commented May 30, 2023

Is there some reason the signature isn't handled dynamically? Such as:

public void Send(string address, params object[] data)
{
	if (data == null)
	{
		Send(address);
		return;
	}

	_encoder.Clear();
	_encoder.Append(address);

	string format = ",";
	foreach (object o in data)
	{
		if (o is string) format += "s";
		else if (o is int) format += "i";
		else if (o is float) format += "f";
	}

	_encoder.Append(format);

	foreach (object o in data)
	{
		if (o is string) _encoder.Append((string)o);
		else if (o is int) _encoder.Append((int)o);
		else if (o is float) _encoder.Append((float)o);
    }

	_socket.Send(_encoder.Buffer, _encoder.Length, SocketFlags.None);
}

@zacksettel
Copy link
Author

Excellent idea. That would make for one less dependency on my forked version (I wrote the same method in my forked version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants