protected virtual void Start() { // Register receive callback. Receiver.Bind(_address, MessageReceived); // Create message var message = OSCMessage.Create(_address); // Create array var array = OSCValue.Array(); array.AddValue(OSCValue.Int(1)); // You can use AddValue(OSCValue) method only with OSCValue what stored Array type. array.AddValue(OSCValue.Float(2.5f)); array.AddValue(OSCValue.Color(Color.red)); // You can store another array inside array. // Warning! OSCValue with "Array" type cannot store itself. It can do infinite loop. var secondArray = OSCValue.Array(); secondArray.AddValue(OSCValue.String("This array...")); secondArray.AddValue(OSCValue.String("...inside another array!")); array.AddValue(secondArray); // Add array in message message.AddValue(array); // Send message Transmitter.Send(message); }
private static OSCMessage UnpackMessage(byte[] bytes, ref int start) { OSCMessage message = null; var address = (string)UnpackValue(OSCValueType.String, bytes, ref start); var typeTags = (string)UnpackValue(OSCValueType.String, bytes, ref start); var valuesArray = (Dictionary <int, OSCValue>)null; message = new OSCMessage(address); foreach (var valueTag in typeTags) { if (valueTag == ',') { continue; } OSCValue value = null; // START ARRAY if (valueTag == '[') { if (valuesArray == null) { valuesArray = new Dictionary <int, OSCValue>(); } valuesArray.Add(valuesArray.Count, OSCValue.Array()); continue; } // STOP ARRAY if (valueTag == ']') { if (valuesArray != null && valuesArray.Count > 0) { value = valuesArray[valuesArray.Count - 1]; valuesArray.Remove(valuesArray.Count - 1); } } else { // DEFAULT VALUE value = UnpackValue(valueTag, bytes, ref start); } if (valuesArray != null && valuesArray.Count > 0) { valuesArray[valuesArray.Count - 1].ArrayValue.Add(value); continue; } message.AddValue(value); } return(message); }
public static OSCValue CreateOSCValue(OSCValueType valueType) { switch (valueType) { case OSCValueType.Unknown: return(null); case OSCValueType.Int: return(OSCValue.Int(0)); case OSCValueType.Long: return(OSCValue.Long(0)); case OSCValueType.True: return(OSCValue.Bool(true)); case OSCValueType.False: return(OSCValue.Bool(false)); case OSCValueType.Float: return(OSCValue.Float(0)); case OSCValueType.Double: return(OSCValue.Double(0)); case OSCValueType.String: return(OSCValue.String("")); case OSCValueType.Null: return(OSCValue.Null()); case OSCValueType.Impulse: return(OSCValue.Impulse()); case OSCValueType.Blob: return(OSCValue.Blob(new byte[0])); case OSCValueType.Char: return(OSCValue.Char(' ')); case OSCValueType.Color: return(OSCValue.Color(Color.white)); case OSCValueType.TimeTag: return(OSCValue.TimeTag(DateTime.Now)); case OSCValueType.Midi: return(OSCValue.Midi(new OSCMidi(0, 0, 0, 0))); case OSCValueType.Array: return(OSCValue.Array()); default: throw new ArgumentOutOfRangeException(); } }
public void SendSamples(List <Point> samplePoints, string separatorString) { OSCValue[] messageStrings = new OSCValue[samplePoints.Count]; for (int index = 0; index < samplePoints.Count; index++) { messageStrings[index] = OSCValue.String(samplePoints[index].audiokey); } OSCMessage message = new OSCMessage(samplesFilter); message.AddValue(OSCValue.Array(messageStrings)); Debug.Log("Sent: " + message.ToString()); transmitter.Send(message); }