Exemplo n.º 1
0
        #pragma warning restore

        public void Evaluate(int SpreadMax)
        {
            SpreadMax = FInput.SliceCount;

            if (FInput.SliceCount == 0 || FInput[0] == null)
            {
                FOutput.SliceCount = 0;
                return;
            }

            FOutput.SliceCount = SpreadMax;


            for (int i = 0; i < SpreadMax; i++)
            {
                Message message = FInput[i];

                if (Update[i])
                {
                    for (int keyCount = 0; keyCount < FKey.SliceCount; keyCount++)
                    {
                        SpreadList attr = message[FKey[keyCount]];
                        if (attr != null)
                        {
                            var typeOld = attr[0].GetType();
                            var typeNew = FValue[keyCount][0].GetType();
                            if (!(typeOld == typeNew))
                            {
                                attr.Clear();
                                for (int j = 0; j < FValue[i].SliceCount; j++)
                                {
                                    attr.Add(Convert.ChangeType(FValue[keyCount][j], typeOld));
                                }
                            }
                            else
                            {
                                attr.Clear();
                                attr.AssignFrom(FValue[i]);
                            }
                        }
                    }
                }
                FOutput[i] = message;
            }

            FOutput.Flush();
        }
Exemplo n.º 2
0
        public static Message FromOSC(Stream stream, string messagePrefix = "OSC", int contractAddress = 1)
        {
            MemoryStream ms = new MemoryStream();

            stream.Position = 0;
            stream.CopyTo(ms);
            byte[]    bytes  = ms.ToArray();
            int       start  = 0;
            OSCBundle bundle = OSCBundle.Unpack(bytes, ref start, (int)stream.Length);

            Message message = new Message();

//			yet unsupported:
//			Message.TimeStamp = DateTime.FromFileTime(bundle.getTimeStamp());


            foreach (OSCMessage m in bundle.Values)
            {
                SpreadList sl = new SpreadList();
                sl.AssignFrom(m.Values);                 // does not clone implicitly

                string oldAddress = m.Address;
                while (oldAddress.StartsWith("/"))
                {
                    oldAddress = oldAddress.Substring(1);
                }
                while (oldAddress.EndsWith("/"))
                {
                    oldAddress = oldAddress.Substring(0, oldAddress.Length - 1);
                }

                string[] address = oldAddress.Split('/');

                contractAddress = address.Length > contractAddress ? contractAddress : address.Length - ((messagePrefix.Trim() == "")? 1 : 0);
                string attribName = "";
                for (int i = address.Length - contractAddress; i < address.Length; i++)
                {
                    attribName += ".";
                    attribName += address[i];
                    address[i]  = "";
                }
                attribName = attribName.Substring(1);


                string messageAddress = "";
                foreach (string part in address)
                {
                    if (part.Trim() != "")
                    {
                        messageAddress += "." + part;
                    }
                }
                if (messagePrefix.Trim() == "")
                {
                    message.Address = messageAddress.Substring(1);
                }
                else
                {
                    message.Address = messagePrefix + messageAddress;
                }

                message[attribName] = sl;
            }
            return(message);
        }