/// <summary> /// Create a bundle of messages /// </summary> /// <param name="origin">the origin of the osc bundle</param> /// <param name="timestamp">timestamp</param> /// <param name="messages">messages to bundle</param> public OscBundle(IPEndPoint origin, DateTime timestamp, params OscPacket[] messages) { m_Origin = origin; m_Timestamp = OscTimeTag.FromDataTime(timestamp); m_Messages = messages; }
/// <summary> /// Create a bundle of messages /// </summary> /// <param name="origin">the origin of the osc bundle</param> /// <param name="timestamp">timestamp</param> /// <param name="messages">messages to bundle</param> public OscBundle(IPEndPoint origin, ulong timestamp, params OscPacket[] messages) { m_Origin = origin; m_Timestamp = new OscTimeTag(timestamp); m_Messages = messages; }
/// <summary> /// Create a bundle of messages /// </summary> /// <param name="origin">the origin of the osc bundle</param> /// <param name="timestamp">timestamp</param> /// <param name="messages">messages to bundle</param> public OscBundle(IPEndPoint origin, OscTimeTag timestamp, params OscPacket[] messages) { m_Origin = origin; m_Timestamp = timestamp; m_Messages = messages; }
/// <summary> /// Create a bundle of messages /// </summary> /// <param name="timestamp">timestamp</param> /// <param name="messages">messages to bundle</param> public OscBundle(DateTime timestamp, params OscPacket[] messages) { m_Origin = Helper.EmptyEndPoint; m_Timestamp = OscTimeTag.FromDataTime(timestamp); m_Messages = messages; }
/// <summary> /// Create a bundle of messages /// </summary> /// <param name="timestamp">timestamp</param> /// <param name="messages">messages to bundle</param> public OscBundle(ulong timestamp, params OscPacket[] messages) { m_Origin = Helper.EmptyEndPoint; m_Timestamp = new OscTimeTag(timestamp); m_Messages = messages; }
/// <summary> /// Is the supplied time within the current frame according to this time provider /// </summary> /// <param name="time">the time to check</param> /// <returns>true if within the frame else false</returns> public bool IsWithinTimeFrame(OscTimeTag time) { double offset = DifferenceInSeconds(time); if (offset > -FrameSizeInSeconds && offset < FrameSizeInSeconds) { return(true); } else { return(false); } }
/// <summary> /// Try to parse a osc time tag from datetime string /// </summary> /// <param name="str">string to parse</param> /// <param name="value">the parsed time tag</param> /// <returns>true if parsed else false</returns> public static bool TryParse(string str, out OscTimeTag value) { try { value = Parse(str, CultureInfo.InvariantCulture); return(true); } catch { value = default(OscTimeTag); return(false); } }
/// <summary> /// Try to parse a osc time tag from datetime string /// </summary> /// <param name="str">string to parse</param> /// <param name="provider">format provider</param> /// <param name="value">the parsed time tag</param> /// <returns>true if parsed else false</returns> public static bool TryParse(string str, IFormatProvider provider, out OscTimeTag value) { try { value = Parse(str, provider); return(true); } catch { value = default(OscTimeTag); return(false); } }
/// <summary> /// Get the difference in seconds between the current time and the suppied time /// </summary> /// <param name="time">the time to compair</param> /// <returns>the difference in seconds between the current time and the suppied time</returns> public double DifferenceInSeconds(OscTimeTag time) { TimeSpan span = DateTime.UtcNow.Subtract(time.ToDataTime()); return(span.TotalSeconds); }
internal static void Write(BinaryWriter writer, OscTimeTag value) { Write(writer, value.Value); }
/// <summary> /// parse a bundle from a string using a supplied format provider /// </summary> /// <param name="str">a string containing a bundle</param> /// <param name="provider">the format provider to use</param> /// <returns>the parsed bundle</returns> public static OscBundle Parse(string str, IFormatProvider provider) { if (Helper.IsNullOrWhiteSpace(str) == true) { throw new ArgumentNullException("str"); } int start = 0; int end = str.IndexOf(',', start); if (end <= start) { throw new Exception(String.Format(Strings.Bundle_InvalidIdent, "")); } string ident = str.Substring(start, end - start).Trim(); if (BundleIdent.Equals(ident, System.StringComparison.InvariantCulture) == false) { throw new Exception(String.Format(Strings.Bundle_InvalidIdent, ident)); } start = end + 1; end = str.IndexOf(',', start); if (end <= start) { throw new Exception(String.Format(Strings.Bundle_InvalidTimestamp, "")); } string timeStampStr = str.Substring(start, end - start); OscTimeTag timeStamp = OscTimeTag.Parse(timeStampStr.Trim(), provider); start = end + 1; end = str.IndexOf('{', start); if (end < 0) { end = str.Length; } string gap = str.Substring(start, end - start); if (Helper.IsNullOrWhiteSpace(gap) == false) { throw new Exception(String.Format(Strings.Bundle_MissingOpenBracket, gap)); } start = end; List <OscPacket> messages = new List <OscPacket>(); while (start > 0 && start < str.Length) { end = ScanForward_Object(str, start); messages.Add(OscPacket.Parse(str.Substring(start + 1, end - (start + 1)).Trim(), provider)); start = end + 1; end = str.IndexOf('{', start); if (end < 0) { end = str.Length; } gap = str.Substring(start, end - start).Trim(); if (gap.Equals(",") == false && Helper.IsNullOrWhiteSpace(gap) == false) { throw new Exception(String.Format(Strings.Bundle_MissingOpenBracket, gap)); } start = end; } return(new OscBundle(timeStamp, messages.ToArray())); }