Giter Site home page Giter Site logo

sharposc's Introduction

SharpOSC - OSC Library for .NET 3.5

SharpOSC is a small library designed to make interacting with Open Sound Control easy (OSC). It provides the following features:

  • Produce an OSC Packet (messages and bundles) from .NET values.
  • Translate an OSC message (consisting of a sequence of bytes) into a .NET object.
  • Transmit OSC packets via UDP.
  • Receive OSC packets via UDP.

Download

If you don't want to build SharpOSC from source you can download compiled versions.

Download Binaries Here

Supported Types

The following OSC types are supported:

  • i - int32 (System.Int32)
  • f - float32 (System.Single)
  • s - OSC-string (System.String)
  • b - OSC-blob (System.Byte[])
  • h - 64 bit big-endian two's complement integer (System.Int64)
  • t - OSC-timetag (System.UInt64 / SharpOSC.Timetag)
  • d - 64 bit ("double") IEEE 754 floating point number (System.Double)
  • S - Alternate type represented as an OSC-string (for example, for systems that differentiate "symbols" from "strings") (SharpOSC.Symbol)
  • c - an ascii character, sent as 32 bits (System.Char)
  • r - 32 bit RGBA color (SharpOSC.RGBA)
  • m - 4 byte MIDI message. Bytes from MSB to LSB are: port id, status byte, data1, data2 (SharpOSC.Midi)
  • T - True. No bytes are allocated in the argument data. (System.Boolean)
  • F - False. No bytes are allocated in the argument data. (System.Boolean)
  • N - Nil. No bytes are allocated in the argument data. (null)
  • I - Infinitum. No bytes are allocated in the argument data. (Double.PositiveInfinity)
  • [ - Indicates the beginning of an array. The tags following are for data in the Array until a close brace tag is reached. (System.Object[] / List<object>)
  • ] - Indicates the end of an array.

(Note that nested arrays (arrays within arrays) are not supported, the OSC specification is unclear about whether that it is even allowed)

License

SharpOSC is licensed under the MIT license.

See License.txt

Using The Library

To use the library add a reference to SharpOSC.dll in your .NET project. SharpOSC should now be available to use in your code under that namespace "SharpOSC".

Example: Sending a message

class Program
{
	static void Main(string[] args)
	{
		var message = new SharpOSC.OscMessage("/test/1", 23, 42.01f, "hello world");
		var sender = new SharpOSC.UDPSender("127.0.0.1", 55555);
		sender.Send(message);
	}
}

This example sends an OSC message to the local machine on port 55555 containing 3 arguments: an integer with a value of 23, a floating point number with the value 42.01 and the string "hello world". If another program is listening to port 55555 it will receive the message and be able to use the data sent.

Example: Receiving a Message (Synchronous)

class Program
{
	static void Main(string[] args)
	{
		var listener = new UDPListener(55555);
		OscMessage messageReceived = null;
		while (messageReceived == null)
		{
			messageReceived = (OscMessage)listener.Receive();
			Thread.Sleep(1);
		}
		Console.WriteLine("Received a message!");
	}
}

This shows a very simple way of waiting for incoming messages. The listener.Receive() method will check if the listener has received any new messages since it was last called. It will poll for a message every millisecond. If there is a new message that has not been returned it will assign messageReceived to point to that message. If no message has been received since the last call to Receive it will return null.

Example: Receiving a Message (Asynchronous)

class Program
{
	public void Main(string[] args)
	{
		// The cabllback function
		HandleOscPacket callback = delegate(OscPacket packet)
		{
			var messageReceived = (OscMessage)packet;
			Console.WriteLine("Received a message!");
		};

		var listener = new UDPListener(55555, callback);

		Console.WriteLine("Press enter to stop");
		Console.ReadLine();
		listener.Close();
	}
}

By giving UDPListener a callback you don't have to periodically check for incoming messages. The listener will simply invoke the callback whenever a message is received. You are free to implement any code you need inside the callback.

Contribute

I would love to get some feedback. Use the Issue tracker on Github to send bug reports and feature requests, or just if you have something to say about the project. If you have code changes that you would like to have integrated into the main repository, send me a pull request or a patch. I will try my best to integrate them and make sure SharpOSC improves and matures.

sharposc's People

Contributors

valdemarorn avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.