private object ParseObject(string value, IFormatProvider provider)
        {
            string name = ReadObjectNameToken();

            if (name.Length == 0)
            {
                throw new Exception(@"Malformed object missing type name");
            }

            string nameLower = name.ToLowerInvariant();

            switch (nameLower)
            {
            case "midi":
            case "m":
                return(OscMidiMessage.Parse(ref this, provider));

            case "time":
            case "t":
                return(OscTimeTag.Parse(ref this, provider));

            case "color":
            case "c":
                return(OscColor.Parse(ref this, provider));

            case "blob":
            case "b":
            case "data":
            case "d":
                return(ParseBlob(provider));

            default:
                throw new Exception($@"Unknown object type '{name}'");
            }
        }
        public void OscColorConstructorTest()
        {
            int value = unchecked ((int)0xFFFFFFFF);

            OscColor target = new OscColor(value);

            Assert.AreEqual(value, target.ARGB);

            Assert.AreEqual(255, target.A);
            Assert.AreEqual(255, target.R);
            Assert.AreEqual(255, target.G);
            Assert.AreEqual(255, target.B);
        }
Exemple #3
0
        public void WriteColor(ref OscColor value)
        {
            CheckWriterState(WriterState.Arguments);

            int intValue = (value.R << 24) |
                           (value.G << 16) |
                           (value.B << 8) |
                           (value.A << 0);

            Write(intValue);

            Flush();
        }
Exemple #4
0
        public OscColor ReadDirectColor()
        {
            CheckForPacketEnd(OscError.ErrorParsingColor, 4);

            uint value = unchecked ((uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(buffer.Array, buffer.Offset + Position)));

            byte a, r, g, b;

            r = (byte)((value & 0xFF000000) >> 24);
            g = (byte)((value & 0x00FF0000) >> 16);
            b = (byte)((value & 0x0000FF00) >> 8);
            a = (byte)(value & 0x000000FF);

            return(OscColor.FromArgb(a, r, g, b));
        }
Exemple #5
0
        public OscColor ReadColor(ref OscTypeTag typeTag)
        {
            CheckToken(OscToken.Color);

            CheckForPacketEnd(OscError.ErrorParsingColor, 4);

            uint value = unchecked ((uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(buffer.Array, buffer.Offset + Position)));

            byte a, r, g, b;

            r = (byte)((value & 0xFF000000) >> 24);
            g = (byte)((value & 0x00FF0000) >> 16);
            b = (byte)((value & 0x0000FF00) >> 8);
            a = (byte)(value & 0x000000FF);

            Position    += 4;
            currentToken = typeTag.NextToken();

            return(OscColor.FromArgb(a, r, g, b));
        }
        public void FromArgbTest_R()
        {
            byte alpha = 255;
            byte red   = 255;
            byte green = 0;
            byte blue  = 0;
            int  argb  = unchecked ((int)0xFFFF0000);

            OscColor expected = new OscColor(argb);
            OscColor actual;

            actual = OscColor.FromArgb(alpha, red, green, blue);

            Assert.AreEqual(expected, actual);

            Assert.AreEqual(argb, actual.ARGB);

            Assert.AreEqual(alpha, actual.A);
            Assert.AreEqual(red, actual.R);
            Assert.AreEqual(green, actual.G);
            Assert.AreEqual(blue, actual.B);
        }
        internal static void AreEqual(object[] expected, object[] actual)
        {
            Assert.AreEqual(expected.Length, actual.Length, "Number of arguments do not match");

            for (int i = 0; i < actual.Length; i++)
            {
                Assert.AreEqual(expected[i].GetType(), actual[i].GetType(), "Argument types at index {0} do not match", i);

                if (expected[i] is object[])
                {
                    object[] expectedArg = (object[])expected[i];
                    object[] actualArg   = (object[])actual[i];

                    AreEqual(expectedArg, actualArg);
                }
                else if (expected[i] is byte[])
                {
                    byte[] expectedArg = (byte[])expected[i];
                    byte[] actualArg   = (byte[])actual[i];

                    AreEqual(expectedArg, actualArg);
                }
                else if (expected[i] is OscColor)
                {
                    OscColor expectedArg = (OscColor)expected[i];
                    OscColor actualArg   = (OscColor)actual[i];

                    Assert.AreEqual(expectedArg.R, actualArg.R, "Color arguments at index {0} Red componets do not match", i);
                    Assert.AreEqual(expectedArg.G, actualArg.G, "Color arguments at index {0} Green componets do not match", i);
                    Assert.AreEqual(expectedArg.B, actualArg.B, "Color arguments at index {0} Blue componets do not match", i);
                    Assert.AreEqual(expectedArg.A, actualArg.A, "Color arguments at index {0} Alpha componets do not match", i);
                }
                else
                {
                    Assert.AreEqual(expected[i], actual[i], "Arguments at index {0} do not match", i);
                }
            }
        }
Exemple #8
0
        static void Main(string[] args)
        {
            // integer
            Console.WriteLine("Integer (Int32)");
            CheckPackets(new OscMessage("/foo", 42), "/foo, 42");
            CheckPackets(new OscMessage("/foo", 0x2A), "/foo, 0x2A");
            Console.WriteLine();

            // long
            Console.WriteLine("Long (Int64)");
            CheckPackets(new OscMessage("/foo", 12334L), "/foo, 12334L");
            CheckPackets(new OscMessage("/foo", 0x13C1DA49E6B50B0F), "/foo, 0x13C1DA49E6B50B0F");
            Console.WriteLine();

            // float
            Console.WriteLine("Float (Single)");
            CheckPackets(new OscMessage("/foo", 123.34f), "/foo, 123.34");
            CheckPackets(new OscMessage("/foo", 123.34f), "/foo, 123.34f");
            CheckPackets(new OscMessage("/foo", 123.45e+6f), "/foo, 123.45e+6");
            CheckPackets(new OscMessage("/foo", +500f), "/foo, +500f");
            CheckPackets(new OscMessage("/foo", 5e2f), "/foo, 5e2");
            CheckPackets(new OscMessage("/foo", 600.0f), "/foo, 600.");
            CheckPackets(new OscMessage("/foo", -.123f), "/foo, -.123");
            CheckPackets(new OscMessage("/foo", float.NegativeInfinity), "/foo, -Infinity");
            CheckPackets(new OscMessage("/foo", -1E-16f), "/foo, -1E-16");
            Console.WriteLine();

            // double
            Console.WriteLine("Double");
            CheckPackets(new OscMessage("/foo", 123.34d), "/foo, 123.34d");
            Console.WriteLine();

            // string
            Console.WriteLine("String");
            CheckPackets(new OscMessage("/foo", "string"), "/foo, \"string\"");
            Console.WriteLine();

            // Symbol
            Console.WriteLine("Symbol");
            CheckPackets(new OscMessage("/foo", new OscSymbol("SymbolString")), "/foo, SymbolString");
            Console.WriteLine();

            // bool
            Console.WriteLine("Bool (Boolean)");
            CheckPackets(new OscMessage("/foo", true), "/foo, true");
            CheckPackets(new OscMessage("/foo", false), "/foo, false");
            Console.WriteLine();

            // Color
            Console.WriteLine("Color");
            CheckPackets(new OscMessage("/foo", OscColor.FromArgb(255, 255, 0, 0)), "/foo, { Color: 255, 255, 0, 0 }");
            CheckPackets(new OscMessage("/foo", OscColor.FromArgb(255, 255, 255, 0)), "/foo, { Color: 255, 255, 0, 255 }");
            Console.WriteLine();

            // Osc-Null
            Console.WriteLine("Osc-Null");
            CheckPackets(new OscMessage("/foo", OscNull.Value), "/foo, null");
            CheckPackets(new OscMessage("/foo", OscNull.Value), "/foo, nil");
            Console.WriteLine();

            // Osc-Timetag
            Console.WriteLine("Osc-Timetag");
            CheckPackets(new OscMessage("/foo", OscTimeTag.Parse("00:00:34.3532Z")), "/foo, { Time: 00:00:34.3532Z }");
            CheckPackets(new OscMessage("/foo", new OscTimeTag(0x13C1DA49E6B50B0F)), "/foo, { Time: 0x13C1DA49E6B50B0F }");
            CheckPackets(new OscMessage("/foo", OscTimeTag.Parse("0")), "/foo, { Time: 1234 }");

            Console.WriteLine();

            // Osc-Impulse
            Console.WriteLine("Osc-Impulse / Infinitum");
            CheckPackets(new OscMessage("/foo", OscImpulse.Value), "/foo, infinitum");
            CheckPackets(new OscMessage("/foo", OscImpulse.Value), "/foo, impulse");
            CheckPackets(new OscMessage("/foo", OscImpulse.Value), "/foo, bang");
            Console.WriteLine();

            // char
            Console.WriteLine("Char (byte)");
            CheckPackets(new OscMessage("/foo", (byte)'Q'), "/foo, 'Q'");
            Console.WriteLine();

            // blob
            Console.WriteLine("Blob (byte array)");
            CheckPackets(new OscMessage("/foo", new byte[] { 1, 2, 3, 4 }), "/foo, { Blob: 1, 2, 3, 4 }");
            CheckPackets(new OscMessage("/foo", new byte[] { 1, 2, 3, 4 }), "/foo, { Blob: 0x01020304}");
            CheckPackets(new OscMessage("/foo", new byte[] { 1, 2, 3, 4 }), "/foo, { Blob: 64xAQIDBA==}");
            Console.WriteLine();

            // arrays
            Console.WriteLine("Array");
            CheckPackets(new OscMessage("/foo", new object[] { new object[] { 1, 2, 3, 4 } }), "/foo, [ 1, 2, 3, 4 ]");
            Console.WriteLine();

            // bundles
            Console.WriteLine("Bundles");
            CheckPackets(new OscBundle(OscTimeTag.Parse("23-08-2013 01:00:34.3530Z"), new OscMessage("/foo", 42)), "#bundle, 23-08-2013 01:00:34.3530Z, { /foo, 42 }");
            Console.WriteLine();

            Console.WriteLine("Press any key to exit");
            Console.ReadKey(true);
        }
 internal static OscMessage Message_Color_Transparent()
 {
     return(new OscMessage("/test", OscColor.FromArgb(0, 0, 0, 0)));
 }
 internal static OscMessage Message_Color_Blue()
 {
     return(new OscMessage("/test", OscColor.FromArgb(255, 0, 0, 255)));
 }
 public void Write(OscColor value)
 {
     Write(ref value);
 }
 public void Write(ref OscColor value)
 {
     builder.Append($"{{ Color: {value} }}");
 }
Exemple #13
0
        /// <summary>
        ///     Are the contents of 2 argument arrays the equivalent
        /// </summary>
        /// <param name="array1">An array containing argument objects</param>
        /// <param name="array2">An array containing argument objects</param>
        /// <returns>true if the object arrays are equivalent</returns>
        public static bool ArgumentsAreEqual(object[] array1, object[] array2)
        {
            // ensure the arrays the same length
            if (array1.Length != array2.Length)
            {
                return(false);
            }

            // iterate through the arrays
            for (int i = 0; i < array1.Length; i++)
            {
                // ensure the objects at index i of the same type?
                if (array1[i]
                    .GetType() != array2[i]
                    .GetType())
                {
                    return(false);
                }

                // is the argument an object array
                if (array1[i] is object[])
                {
                    object[] expectedArg = (object[])array1[i];
                    object[] actualArg   = (object[])array2[i];

                    // ensure the argument object arrays are the same
                    if (ArgumentsAreEqual(expectedArg, actualArg) == false)
                    {
                        return(false);
                    }
                }
                // is the argument an byte array
                else if (array1[i] is byte[])
                {
                    byte[] expectedArg = (byte[])array1[i];
                    byte[] actualArg   = (byte[])array2[i];

                    // ensure the byte arrays are the same
                    if (BytesAreEqual(expectedArg, actualArg) == false)
                    {
                        return(false);
                    }
                }
                // is the argument a color
                else if (array1[i] is OscColor)
                {
                    OscColor expectedArg = (OscColor)array1[i];
                    OscColor actualArg   = (OscColor)array2[i];

                    // check the RGBA values
                    if (expectedArg.R != actualArg.R ||
                        expectedArg.G != actualArg.G ||
                        expectedArg.B != actualArg.B ||
                        expectedArg.A != actualArg.A)
                    {
                        return(false);
                    }
                }
                // anything else
                else
                {
                    // just check the value
                    if (array1[i]
                        .Equals(array2[i]) == false)
                    {
                        return(false);
                    }
                }
            }

            // we are good
            return(true);
        }