Example #1
0
        // Get Midi input from PD
        public void GetPDInput()
        {
            // Clear any previous Midi input
            CMidiInput.Instance().cMidiInfoList.Clear();

            try
            {
                // Get any PD messages that might have been sent
                Ventuz.OSC.OscBundle cOSCBundle = mcUDPReader.ReceiveBundle();

                // If there are no messages to retrieve
                if (cOSCBundle == null || cOSCBundle.Elements == null || cOSCBundle.Elements.Count <= 0)
                {
                    // Exit the function
                    return;
                }

                // Read in and Store all of the OSC Bundles contents
                while (cOSCBundle != null)
                {
                    // Read in and Store the Contents of the OSC Bundle
                    ReadAndStoreOSCBundleContents(cOSCBundle);

                    // Get the next OSC Bundle from the queue
                    cOSCBundle = mcUDPReader.ReceiveBundle();
                }
            }
            // Catch all exceptions
            catch (Exception e)
            {
                // Display the error message
                MessageBox.Show(e.ToString(), "ERROR");
            }
        }
Example #2
0
        // Get input from the player
        public void GetPDInput(bool bKeepPitchInRange)
        {
            // Clear any previous sound input, but save the Pitch from the last frame
            float fPreviousPitch = CSoundInput.Instance().fPitch;

            CSoundInput.Instance().Reset();
            CSoundInput.Instance().fPitchLastFrame = fPreviousPitch;

            try
            {
                // Get any PD messages that might have been sent
                Ventuz.OSC.OscBundle cOSCBundle = mcUDPReader.ReceiveBundle();

                // If there are no messages to retrieve
                if (cOSCBundle == null || cOSCBundle.Elements == null || cOSCBundle.Elements.Count <= 0)
                {
                    // Exit the function
                    return;
                }

                // If valid pitch input was not received yet AND there are more OSC Bundles to read
                while (cOSCBundle != null && !CSoundInput.mcInstance.bInputReceived)
                {
                    // Read in and Store this OSC Bundles Contents
                    ReadAndStoreOSCBundleContents(cOSCBundle, bKeepPitchInRange);

                    // Get the next OSC Bundle in the queue
                    cOSCBundle = mcUDPReader.ReceiveBundle();
                }

                // Read in the any remaining Bundles to empty the queue
                while (cOSCBundle != null)
                {
                    cOSCBundle = mcUDPReader.ReceiveBundle();
                }
            }
            // Catch all exceptions
            catch (Exception e)
            {
                // Display the error message
                MessageBox.Show(e.ToString(), "ERROR");
            }

            // Calculate how much the Pitch changed between frames
            CSoundInput.Instance().fPitchChange = CSoundInput.Instance().fPitch - CSoundInput.Instance().fPitchLastFrame;
        }
Example #3
0
        // Function to Read and Store the OSC Bundles Contents
        private void ReadAndStoreOSCBundleContents(Ventuz.OSC.OscBundle cOSCBundle)
        {
            string    sInfo     = "";               // Temp variable to display read in values
            CMidiInfo cMidiInfo = new CMidiInfo();  // Temp variable to hold the read in Midi Info

            // Initialize the variables used to hold the Notes Time
            int iHour = 0, iMinute = 0, iSecond = 0, iMillisecond = 0;

            try
            {
                // Get the Elements from the PD Bundle
                System.Collections.ArrayList cElementList = (System.Collections.ArrayList)cOSCBundle.Elements;

                // Loop through all Elements recieved from PD
                foreach (Ventuz.OSC.OscElement cElement in cElementList)
                {
                    // Loop through each of the Elements Arguments
                    foreach (object cObject in cElement.Args)
                    {
                        // Check which type of message this is and store its value appropriately
                        switch (cElement.Address.ToString())
                        {
                        case "/Hour":
                            // Read in and store the Hour
                            iHour = int.Parse(cObject.ToString());
                            break;

                        case "/Minute":
                            // Read in and store the Hour
                            iMinute = int.Parse(cObject.ToString());
                            break;

                        case "/Second":
                            // Read in and store the Hour
                            iSecond = int.Parse(cObject.ToString());
                            break;

                        case "/Millisecond":
                            // Read in and store the Hour
                            iMillisecond = int.Parse(cObject.ToString());
                            break;

                        case "/Velocity":
                            // Read in and store the Velocity
                            cMidiInfo.iVelocity = int.Parse(cObject.ToString());
                            break;

                        case "/Note":
                            // Read in and store the Note value
                            cMidiInfo.iNote = int.Parse(cObject.ToString());
                            break;

                        case "/Channel":
                            // Read in and store the Channel value
                            cMidiInfo.iChannel = int.Parse(cObject.ToString());
                            break;

                        default:
                            MessageBox.Show("Unknown PD Address: " + cElement.Address.ToString(), "ERROR");
                            break;
                        }
                        sInfo += cElement.Address.ToString() + ":" + cObject.ToString() + "   ";
                    }
                }
            }
            // Catch all exceptions
            catch (Exception e)
            {
                // Display the error message
                MessageBox.Show(e.ToString(), "ERROR");
            }

            // If this was not a Note Off message
            if (cMidiInfo.iVelocity > 0)
            {
                // Set the Time of this Midi Note
                DateTime cTempDate = DateTime.Now;
                cMidiInfo.cTime = new DateTime(cTempDate.Year, cTempDate.Month, cTempDate.Day, iHour, iMinute, iSecond, iMillisecond);

                // Store the read in Midi Info
                cMidiInfoList.Add(cMidiInfo);

                // Output the found values for debugging purposes
                //                int iRow = listBox1.Items.Add(sInfo);
                //                listBox1.SetSelected(iRow, true);
                Console.WriteLine(sInfo);
            }
        }
Example #4
0
        // Function to Read in and Store an OSC Bundles Contents
        private void ReadAndStoreOSCBundleContents(Ventuz.OSC.OscBundle cOSCBundle, bool bKeepPitchInRange)
        {
            string sInfo = "";  // Temp variable

            try
            {
                // Get the Elements from the PD Bundle
                System.Collections.ArrayList cElementList = (System.Collections.ArrayList)cOSCBundle.Elements;

                // Loop through all Elements recieved from PD
                foreach (Ventuz.OSC.OscElement cElement in cElementList)
                {
                    // Loop through each of the Elements Arguments
                    foreach (object cObject in cElement.Args)
                    {
                        // Check which type of message this is and store its value appropriately
                        switch (cElement.Address.ToString())
                        {
                        case "/Pitch":
                            // Read in the Pitch
                            float fPitch = float.Parse(cObject.ToString());

                            // If the Pitch is valid
                            if (fPitch > 1.0f)
                            {
                                // Save that some input was received
                                CSoundInput.Instance().bInputReceived = true;

                                // If the Pitch should be kept in range
                                if (bKeepPitchInRange)
                                {
                                    // Make sure the given Pitch is within range
                                    if (fPitch < CSoundInput.Instance().iLowerPitchRange)
                                    {
                                        fPitch = CSoundInput.Instance().iLowerPitchRange;
                                    }
                                    else if (fPitch > CSoundInput.Instance().iUpperPitchRange)
                                    {
                                        fPitch = CSoundInput.Instance().iUpperPitchRange;
                                    }
                                }

                                // Save the Pitch value
                                CSoundInput.Instance().fPitch = fPitch;
                            }
                            break;

                        case "/Amplitude":
                            // If this Elements Pitch was valid
                            if (CSoundInput.Instance().bInputReceived)
                            {
                                // Read in and save the Amplitude value
                                CSoundInput.Instance().fAmplitude = float.Parse(cObject.ToString());
                            }
                            break;

                        case "/Attack":
                            // If this Elements Pitch was valid
                            if (CSoundInput.Instance().bInputReceived)
                            {
                                // Read in and save the Attack value
                                CSoundInput.Instance().bAttack = (int.Parse(cObject.ToString()) == 1) ? true : false;
                            }
                            break;

                        default:
                            MessageBox.Show("Unknown PD Address: " + cElement.Address.ToString(), "ERROR");
                            break;
                        }
                        sInfo += cElement.Address.ToString() + ":" + cObject.ToString() + "   ";
                    }
                }
            }
            // Catch all exceptions
            catch (Exception e)
            {
                // Display the error message
                MessageBox.Show(e.ToString(), "ERROR");
            }

            // If valid pitch input was received
            if (CSoundInput.mcInstance.bInputReceived)
            {
                // Output the found values for debugging purposes
                //                int iRow = listBox1.Items.Add(sInfo);
                //                listBox1.SetSelected(iRow, true);
                Console.WriteLine(sInfo);
            }
        }
        /*private Ventuz.OSC.OscElement JointElement(int UserIndex, JointID id)
        {
            Ventuz.OSC.OscElement element = new Ventuz.OSC.OscElement(
                "/skeleton/" + UserIndex + "/" + joint.ToString(),
                skeleton.Joints[id].Position.X,
                skeleton.Joints[id].Position.Y,
                skeleton.Joints[id].Position.Z);
        }*/
        private void SendSkeletonOSC(SkeletonData skeleton)
        {
            Ventuz.OSC.OscBundle bundle = new Ventuz.OSC.OscBundle();

            foreach (Joint joint in skeleton.Joints)
            {
                String jointName = joint.ID.ToString();
                Ventuz.OSC.OscElement element = new Ventuz.OSC.OscElement(
                    "/skeleton/" + skeleton.UserIndex + "/" + jointName,
                    skeleton.Joints[joint.ID].Position.X,
                    skeleton.Joints[joint.ID].Position.Y,
                    skeleton.Joints[joint.ID].Position.Z);
                bundle.AddElement(element);

            }

            bundle.DateTime = DateTime.Now;

            udpWriter.Send(bundle);

            //            System.Console.WriteLine("sent bundle " + bundle.DateTime.ToString());
        }
Example #6
0
File: Form1.cs Project: sbst/code
 public static void Send(string addr, params object[] param)
 {
     Ventuz.OSC.OscBundle d = new Ventuz.OSC.OscBundle(0, new Ventuz.OSC.OscElement(addr, param));
     oscManager1.Send(d);
 }