C# Class Osc, wekinator_examples

The Osc class provides the methods required to send, receive, and manipulate OSC messages. Several of the helper methods are static since a running Osc instance is not required for their use. When instanciated, the Osc class opens the PacketIO instance that's handed to it and begins to run a reader thread. The instance is then ready to service Send OscMessage requests and to start supplying OscMessages as received back. The Osc class can be called to Send either individual messages or collections of messages in an Osc Bundle. Receiving is done by delegate. There are two ways: either submit a method to receive all incoming messages or submit a method to handle only one particular address. Messages can be encoded and decoded from Strings via the static methods on this class, or can be hand assembled / disassembled since they're just a string (the address) and a list of other parameters in Object form.
Inheritance: MonoBehaviour
Mostrar archivo Open project: fiebrink1/wekinator_examples Class Usage Examples

Public Methods

Method Description
Cancel ( ) : void
OscMessageToPacket ( OscMessage, oscM, byte packet, int length ) : int

Creates a packet (an array of bytes) from a single OscMessage.

A convenience method, not requiring a start index.

OscMessageToString ( OscMessage, message ) : string

General static helper that returns a string suitable for printing representing the supplied OscMessage.

OscMessagesToPacket ( ArrayList messages, byte packet, int length ) : int

Puts an array of OscMessages into a packet (byte[]).

PacketToOscMessages ( byte packet, int length ) : ArrayList

Takes a packet (byte[]) and turns it into a list of OscMessages.

Send ( ArrayList oms ) : void

Sends a list of OSC Messages. Internally takes the OscMessage objects and serializes them into a byte[] suitable for sending to the PacketExchange.

Send ( OscMessage, oscMessage ) : void

Send an individual OSC message. Internally takes the OscMessage object and serializes it into a byte[] suitable for sending to the PacketIO.

SetAddressHandler ( string key, OscMessageHandler ah ) : void

Set the method to call back on when a message with the specified address is received. The method needs to have the OscMessageHandler signature - i.e. void amh( OscMessage oscM )

SetAllMessageHandler ( OscMessageHandler amh ) : void

Set the method to call back on when any message is received. The method needs to have the OscMessageHandler signature - i.e. void amh( OscMessage oscM )

StringToOscMessage ( string message ) : OscMessage,

Creates an OscMessage from a string - extracts the address and determines each of the values.

init ( UDPPacketIO, oscPacketIO ) : void

Private Methods

Method Description
Dump ( byte packet, int start, int length ) : string
ExtractMessage ( ArrayList messages, byte packet, int start, int length ) : int

Extracts a messages from a packet.

ExtractMessages ( ArrayList messages, byte packet, int start, int length ) : int

Receive a raw packet of bytes and extract OscMessages from it. Used internally.

The packet may contain a OSC message or a bundle of messages.

ExtractString ( byte packet, int start, int length ) : string

Removes a string from a packet. Used internally.

InsertString ( string s, byte packet, int start, int length ) : int

Inserts a string, correctly padded into a packet. Used internally.

OscMessageToPacket ( OscMessage, oscM, byte packet, int start, int length ) : int

Creates an array of bytes from a single OscMessage. Used internally.

Can specify where in the array of bytes the OscMessage should be put.

PadSize ( int rawSize ) : int

Takes a length and returns what it would be if padded to the nearest 4 bytes.

Read ( ) : void

Read Thread. Loops waiting for packets. When a packet is received, it is dispatched to any waiting All Message Handler. Also, the address is looked up and any matching handler is called.

Start ( ) : void

Method Details

Cancel() public method

public Cancel ( ) : void
return void

OscMessageToPacket() public static method

Creates a packet (an array of bytes) from a single OscMessage.
A convenience method, not requiring a start index.
public static OscMessageToPacket ( OscMessage, oscM, byte packet, int length ) : int
oscM OscMessage, The OscMessage to be returned as a packet.
packet byte The packet to be populated with the OscMessage.
length int The usable size of the array of bytes.
return int

OscMessageToString() public static method

General static helper that returns a string suitable for printing representing the supplied OscMessage.
public static OscMessageToString ( OscMessage, message ) : string
message OscMessage, The OscMessage to be stringified.
return string

OscMessagesToPacket() public static method

Puts an array of OscMessages into a packet (byte[]).
public static OscMessagesToPacket ( ArrayList messages, byte packet, int length ) : int
messages ArrayList An ArrayList of OscMessages.
packet byte An array of bytes to be populated with the OscMessages.
length int The size of the array of bytes.
return int

PacketToOscMessages() public static method

Takes a packet (byte[]) and turns it into a list of OscMessages.
public static PacketToOscMessages ( byte packet, int length ) : ArrayList
packet byte The packet to be parsed.
length int The length of the packet.
return ArrayList

Send() public method

Sends a list of OSC Messages. Internally takes the OscMessage objects and serializes them into a byte[] suitable for sending to the PacketExchange.
public Send ( ArrayList oms ) : void
oms ArrayList The OSC Message to send.
return void

Send() public method

Send an individual OSC message. Internally takes the OscMessage object and serializes it into a byte[] suitable for sending to the PacketIO.
public Send ( OscMessage, oscMessage ) : void
oscMessage OscMessage, The OSC Message to send.
return void

SetAddressHandler() public method

Set the method to call back on when a message with the specified address is received. The method needs to have the OscMessageHandler signature - i.e. void amh( OscMessage oscM )
public SetAddressHandler ( string key, OscMessageHandler ah ) : void
key string Address string to be matched
ah OscMessageHandler The method to call back on.
return void

SetAllMessageHandler() public method

Set the method to call back on when any message is received. The method needs to have the OscMessageHandler signature - i.e. void amh( OscMessage oscM )
public SetAllMessageHandler ( OscMessageHandler amh ) : void
amh OscMessageHandler The method to call back on.
return void

StringToOscMessage() public static method

Creates an OscMessage from a string - extracts the address and determines each of the values.
public static StringToOscMessage ( string message ) : OscMessage,
message string The string to be turned into an OscMessage
return OscMessage,

init() public method

public init ( UDPPacketIO, oscPacketIO ) : void
oscPacketIO UDPPacketIO,
return void