コード例 #1
0
        internal static void AreEqual(OscMessage target, string address, int sizeInBytes, params object[] values)
        {
            Assert.AreEqual(target.Error, OscPacketError.None, "Error state is not None");
            Assert.AreEqual(target.ErrorMessage, String.Empty, "Error message is not empty");
            Assert.AreEqual(target.Address, address, "Addresses do not match");
            Assert.IsNotNull(target.ToArray(), "Arguments are null");

            if (values.Length == 0)
            {
                Assert.IsTrue(target.IsEmpty, "Arguments are not empty");
            }
            else
            {
                Assert.IsFalse(target.IsEmpty, "Arguments are empty");

                Assert.AreEqual(target.Count, values.Length, "Does not have {0} argument", values.Length);

                for (int i = 0; i < values.Length; i++)
                {
                    Assert.AreEqual(target[i], values[i], "Argument at index {0} value does not match", i);
                }
            }

            Assert.AreEqual(target.SizeInBytes, sizeInBytes, "Message size is not correct");
        }
コード例 #2
0
        public void OnMessage(Connection connection, OscMessage message)
        {
            string address;

            if (prefixOscWithName == true)
            {
                string unsanitizedName = connection.Settings.DeviceName.Value;

                if (namesLookup.TryGetValue(unsanitizedName, out string sainName) == false)
                {
                    sainName = SanitizeName(unsanitizedName);

                    lock (namesLock)
                    {
                        namesLookup[unsanitizedName] = sainName;
                    }
                }

                address = "/" + sainName + message.Address;
            }
            else
            {
                address = "/" + connection.Settings.SerialNumber.Value + message.Address;
            }

            sender?.Send(new OscMessage(address, message.ToArray()));
        }
コード例 #3
0
        internal static void AreEqual(OscMessage expected, OscMessage actual)
        {
            Assert.AreEqual(expected.Error, actual.Error, "Error states do not match");
            Assert.AreEqual(expected.ErrorMessage, actual.ErrorMessage, "Error messages do not match");
            Assert.AreEqual(expected.Address, actual.Address, "Message addresses do not match");

            AreEqual(expected.ToArray(), actual.ToArray());
        }
コード例 #4
0
        private static object ExtractArgumentFromMessage(OscMessage message)
        {
            var arguments = message.ToArray();

            if (arguments.Length != 1)
            {
                throw new InvalidOperationException($"Only 1 argument per message is supported, {message.Address} contained {arguments.Length}.");
            }
            return(arguments[0]);
        }
コード例 #5
0
        /// <summary>
        ///     Are 2 messages equivalent
        /// </summary>
        /// <param name="message1">A message</param>
        /// <param name="message2">A message</param>
        /// <returns>true if the objects are equivalent</returns>
        public static bool MessagesAreEqual(OscMessage message1, OscMessage message2)
        {
            // ensure the address is the same
            if (message1.Address != message2.Address)
            {
                return(false);
            }

            // ensure the argument arrays are the same
            return(ArgumentsAreEqual(message1.ToArray(), message2.ToArray()));
        }
コード例 #6
0
ファイル: UnitTestHelper.cs プロジェクト: tilde-love/osc-core
        internal static void AreEqual(OscMessage target, string address, int sizeInBytes, params object[] values)
        {
            Assert.Equal(target.Address, address);        // , "Addresses do not match");
            Assert.NotNull(target.ToArray());             // , "Arguments are null");

            if (values.Length == 0)
            {
                Assert.True(target.IsEmpty, "Arguments are not empty");
            }
            else
            {
                Assert.False(target.IsEmpty, "Arguments are empty");

                Assert.Equal(target.Count, values.Length);                 // , "Does not have {0} argument", values.Length);

                for (int i = 0; i < values.Length; i++)
                {
                    Assert.True(target[i].Equals(values[i]), $"Argument at index {i} value does not match");
                }
            }

            Assert.Equal(target.SizeInBytes, sizeInBytes);             // , "Message size is not correct");
        }
コード例 #7
0
ファイル: UnitTestHelper.cs プロジェクト: tilde-love/osc-core
        internal static void AreEqual(OscMessage expected, OscMessage actual)
        {
            Assert.Equal(expected.Address, actual.Address);             // , "Message addresses do not match");

            AreEqual(expected.ToArray(), actual.ToArray());
        }
コード例 #8
0
        /// <summary>
        /// Starts the synchronisation service.
        /// </summary>
        public void Start()
        {
            shouldExit = false;

            threadExited.Reset();

            sender.Connect();

            Thread thread = new Thread(delegate()
            {
                try
                {
                    // get the frequency of the stopwatch
                    double stopwatchFrequency = Stopwatch.Frequency;

                    // calculate the stopwatch ticks to milliseconds
                    double stopwatchFrequencyToMilliseconds = stopwatchFrequency / 1000;

                    long waitThreshold   = (long)(stopwatchFrequencyToMilliseconds * 20);
                    long expectedLatency = (long)(stopwatchFrequencyToMilliseconds * 10);

                    long normalisedInterval = (long)(stopwatchFrequencyToMilliseconds * Interval);
                    long previousTimeStamp  = Stopwatch.GetTimestamp();

                    OscMessage syncOscCommand = new OscMessage("/sync", OscTimeTag.Now);

                    while (shouldExit == false)
                    {
                        long currentTimeStamp = Stopwatch.GetTimestamp();

                        if (previousTimeStamp > currentTimeStamp - normalisedInterval)
                        {
                            long deltaTimeStamp = currentTimeStamp - previousTimeStamp;

                            long timeUntilNextSend = normalisedInterval - deltaTimeStamp;

                            // if there is enough time to use the thread join mechanism then do it.
                            if (timeUntilNextSend > waitThreshold)
                            {
                                Thread.CurrentThread.Join((int)((timeUntilNextSend - expectedLatency) / stopwatchFrequencyToMilliseconds));
                            }

                            continue;
                        }

                        previousTimeStamp = currentTimeStamp;

                        syncOscCommand.ToArray()[0] = OscTimeTag.Now;

                        sender.Send(syncOscCommand);
                    }
                }
                finally
                {
                    threadExited.Set();
                }
            });

            thread.Priority = ThreadPriority.Highest;
            thread.Name     = "Synchronisation Master";

            thread.Start();
        }