/// <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); return(offset > -FrameSizeInSeconds && offset < FrameSizeInSeconds); }
/// <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) { Origin = Helper.EmptyEndPoint; this.Timestamp = new OscTimeTag(timestamp); this.packets = 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, DateTime timestamp, params OscPacket[] messages) { Origin = origin; this.Timestamp = OscTimeTag.FromDataTime(timestamp); this.packets = 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) { Origin = origin; this.Timestamp = new OscTimeTag(timestamp); this.packets = 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) { Origin = origin; this.Timestamp = timestamp; this.packets = 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) { Origin = Helper.EmptyEndPoint; this.Timestamp = OscTimeTag.FromDataTime(timestamp); this.packets = messages; }
/// <summary> /// Try to parse a OSC time tag from date-time 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 date-time 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); }
public 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 new static OscBundle Parse(string str, IFormatProvider provider) { if (Helper.IsNullOrWhiteSpace(str) == true) { throw new ArgumentNullException(nameof(str)); } int start = 0; int end = str.IndexOf(',', start); if (end <= start) { throw new Exception($"Invalid bundle ident '{""}'"); } string ident = str.Substring(start, end - start).Trim(); if (BundleIdent.Equals(ident, System.StringComparison.InvariantCulture) == false) { throw new Exception($"Invalid bundle ident '{ident}'"); } start = end + 1; end = str.IndexOf(',', start); if (end < 0) { end = str.Length; } //if (end <= start) //{ // throw new Exception($"Invalid bundle timestamp '{""}'"); //} string timeStampStr = str.Substring(start, end - start); OscTimeTag timeStamp = OscTimeTag.Parse(timeStampStr.Trim(), provider); start = end + 1; if (start >= str.Length) { return(new OscBundle(timeStamp)); } 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($"Missing '{{'. Found '{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($"Missing '{{'. Found '{gap}'"); } start = end; } return(new OscBundle(timeStamp, messages.ToArray())); }