Пример #1
0
        static void Main(string[] args)
        {
            m_Listener = new OscAddressManager();

            m_Listener.Attach("/testA", TestMethodA);
            m_Listener.Attach("/testB", TestMethodB);

            m_Receiver = new OscReceiver(IPAddress.IPv6Any, IPAddress.Parse("FF02::2"), 12345);

            m_Sender = new OscSender(IPAddress.Parse("FF02::2"), 12345);

            m_Thread = new Thread(new ThreadStart(ListenLoop));

            Console.WriteLine("Connecting");
            m_Receiver.Connect();
            m_Sender.Connect();
            m_Thread.Start();

            Console.WriteLine();
            Console.WriteLine("Sending message to A");
            Console.WriteLine();

            m_Sender.Send(new OscMessage("/testA", "Hello from sender (test1)"));

            Thread.CurrentThread.Join(100);
            Console.WriteLine();
            Console.WriteLine("Press any key to send the next message");
            Console.ReadKey(true);



            Console.WriteLine();
            Console.WriteLine("Sending message to B");
            Console.WriteLine();

            m_Sender.Send(new OscMessage("/testB", "Hello from sender (test2)"));

            Thread.CurrentThread.Join(100);
            Console.WriteLine();
            Console.WriteLine("Press any key to send the next message");
            Console.ReadKey(true);



            Console.WriteLine();
            Console.WriteLine("Sending message to A and B");
            Console.WriteLine();

            m_Sender.Send(new OscMessage("/*", "Hello from sender (test3)"));

            Thread.CurrentThread.Join(100);
            Console.WriteLine();
            Console.WriteLine("Press any key to exit");
            Console.ReadKey(true);

            Console.WriteLine("Shutting down");
            m_Receiver.Close();
            m_Thread.Join();
            m_Sender.Close();
        }
        private void AddEvent(string address)
        {
            try
            {
                int methodID = m_MethodID++;

                m_Manager.Attach(address, new OscMessageEvent((OscMessage message) =>
                {
                    DataRow[] row = m_Data.Select("MethodID='" + methodID + "'");

                    if (row.Length > 0)
                    {
                        int count = (int)row[0]["Count"];

                        count += 1;

                        row[0]["Count"] = count;
                    }
                }));

                m_Data.Rows.Add(methodID, address, 0);
            }
            catch (Exception ex)
            {
                // explicitly tell the user why the address failed to parse
                MessageBox.Show(ex.Message, "Error parsing osc address");
            }
        }
Пример #3
0
        static StaticObjects()
        {
            #region Parsed_Addresses

            Parsed_Addresses = new OscAddress[StaticObjects.Good_AddressPatterns.Length];

            for (int i = 0; i < Parsed_Addresses.Length; i++)
            {
                Parsed_Addresses[i] = new OscAddress(StaticObjects.Good_AddressPatterns[i]);
            }

            #endregion

            #region Parsed_AddressPatternMatches

            Parsed_AddressPatternMatches = new OscAddress[StaticObjects.Good_AddressPatternMatches.Length];

            for (int i = 0; i < Parsed_AddressPatternMatches.Length; i++)
            {
                Parsed_AddressPatternMatches[i] = new OscAddress(StaticObjects.Good_AddressPatternMatches[i]);
            }

            #endregion

            All_Addresses = new string[StaticObjects.Good_AddressPatterns.Length + StaticObjects.Good_AddressPatternMatches.Length];

            for (int i = 0; i < Good_AddressPatterns.Length; i++)
            {
                All_Addresses[i] = StaticObjects.Good_AddressPatterns[i];
            }

            for (int i = 0; i < Good_AddressPatternMatches.Length; i++)
            {
                All_Addresses[StaticObjects.Good_AddressPatterns.Length + i] = StaticObjects.Good_AddressPatternMatches[i];
            }

            Parsed_Messages = new OscMessage[All_Addresses.Length];

            for (int i = 0; i < All_Addresses.Length; i++)
            {
                Parsed_Messages[i] = new OscMessage(StaticObjects.All_Addresses[i]);
            }

            Mananger = new OscAddressManager();

            for (int i = 0; i < Good_AddressPatterns.Length; i++)
            {
                Mananger.Attach(StaticObjects.Good_AddressPatterns[i], DummyMethod);
            }
        }
Пример #4
0
        public void AttachTest()
        {
            try
            {
                using (OscAddressManager target = new OscAddressManager())
                {
                    string address = "/test";

                    OscMessageEvent @event = new OscMessageEvent((OscMessage message) => { Debug.WriteLine(message.ToString()); });

                    target.Attach(address, @event);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Пример #5
0
        public void InvokeTest1_Bad()
        {
            try
            {
                using (OscAddressManager target = new OscAddressManager())
                {
                    string          address = "/test";
                    OscMessageEvent @event  = new OscMessageEvent((OscMessage msg) => { Debug.WriteLine(msg.ToString()); });
                    target.Attach(address, @event);

                    OscBundle bundle   = new OscBundle(DateTime.Now, new OscMessage("/foo"));
                    bool      expected = false;
                    bool      actual;

                    actual = target.Invoke(bundle);

                    Assert.AreEqual(expected, actual);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
Пример #6
0
        public void InvokeTest_Good()
        {
            try
            {
                using (OscAddressManager target = new OscAddressManager())
                {
                    string          address = "/test";
                    OscMessageEvent @event  = new OscMessageEvent((OscMessage msg) => { Debug.WriteLine(msg.ToString()); });
                    target.Attach(address, @event);

                    OscMessage message  = new OscMessage("/test");
                    bool       expected = true;
                    bool       actual;

                    actual = target.Invoke(message);

                    Assert.AreEqual(expected, actual);
                }
            }
            catch (Exception ex)
            {
                Assert.Fail(ex.Message);
            }
        }
        public void Load(string filePath, IReporter reporter = null)
        {
            lock (readWriteLock)
            {
                using (OscFileReader fileReader = new OscFileReader(Helper.ResolvePath(filePath), OscPacketFormat.String))
                    using (OscAddressManager manager = new OscAddressManager())
                    {
                        foreach (ISettingValue value in AllValues)
                        {
                            if (value.IsReadOnly == true)
                            {
                                continue;
                            }

                            manager.Attach(value.OscAddress, value.OnLocalMessage);
                        }

                        fileReader.PacketRecived += delegate(OscPacket packet)
                        {
                            if (packet.Error != OscPacketError.None)
                            {
                                if (reporter != null)
                                {
                                    reporter.OnError(this, new MessageEventArgs(packet.ErrorMessage));
                                }

                                return;
                            }

                            manager.Invoke(packet);
                        };

                        fileReader.ReadToEnd();
                    }
            }
        }
    void Start()
    {
        reciever = new OscReceiver(port);
        reciever.Connect();

        listener = new OscAddressManager();
        foreach(OscRecieveData data in recieveDatas)
        {
            data.value = OscNull.Value;
            data.valueString = data.value.ToString();
            listener.Attach(data.address, OnRecieved);
        }

        thread = new Thread(new ThreadStart(ListenLoop));
        thread.Start();
    }
Пример #9
0
 public void Attach(string address, OscMessageEvent @event)
 {
     OscAddressManager.Attach(address, @event);
 }