public MainWindow() { InitializeComponent(); // startup our midi! OutputDevice = OutputDevice.InstalledDevices[0]; OutputDevice.Open(); //OutputDevice.SilenceAllNotes(); leftChannel = Channel.Channel1; rightChannel = Channel.Channel2; // set instruments OutputDevice.SendProgramChange(leftChannel, leftInstrument); OutputDevice.SendProgramChange(rightChannel, rightInstrument); // draw a load of rectangles for the notes for (int i = 0; i < 12; i++) { // right hand NoteRectangle noteRectangle = new NoteRectangle() { OutputDevice = OutputDevice, Channel = rightChannel, //Pitch = scale.NoteSequence[i % 7].PitchInOctave(3 + (i / 7 % 2)), Rectangle = new Rectangle() }; rightNotes.Add(noteRectangle); noteRectangle.Rectangle.Height = 40; noteRectangle.Rectangle.Width = 640; noteRectangle.Rectangle.StrokeThickness = i % 7 == 0 ? 4 : 1; noteRectangle.Rectangle.Stroke = i % 7 == 0 ? Brushes.White : Brushes.Gray; //noteRectangle.Rectangle.Fill = Brushes.Green; noteRectangle.Rectangle.Opacity = 0.4; //noteRectangle.Rectangle.Stroke.Opacity = 0.5; MainCanvas.Children.Add(noteRectangle.Rectangle); Canvas.SetLeft(noteRectangle.Rectangle, 0.0); Canvas.SetTop(noteRectangle.Rectangle, 480 - 40 - i * 40); } // initially just give it the scale of C scaleNote = new Note('C'); scalePattern = Scale.Major; setScale(); // connect to our node server socket = new Client("http://127.0.0.1:8080/kinect"); // url to nodejs /*socket.Opened += SocketOpened; * socket.Message += SocketMessage; * socket.SocketConnectionClosed += SocketConnectionClosed; * socket.Error += SocketError;*/ }
void GetCameraPoint(Skeleton first, AllFramesReadyEventArgs e) { using (DepthImageFrame depth = e.OpenDepthImageFrame()) { if (depth == null || kinectSensorChooser1.Kinect == null) { return; } //Map a joint location to a point on the depth map //head /*DepthImagePoint headDepthPoint = * depth.MapFromSkeletonPoint(first.Joints[JointType.Head].Position);*/ //left hand DepthImagePoint leftDepthPoint = depth.MapFromSkeletonPoint(first.Joints[JointType.HandLeft].Position); //right hand DepthImagePoint rightDepthPoint = depth.MapFromSkeletonPoint(first.Joints[JointType.HandRight].Position); //Map a depth point to a point on the color image //head /*ColorImagePoint headColorPoint = * depth.MapToColorImagePoint(headDepthPoint.X, headDepthPoint.Y, * ColorImageFormat.RgbResolution640x480Fps30);*/ //left hand ColorImagePoint leftColorPoint = depth.MapToColorImagePoint(leftDepthPoint.X, leftDepthPoint.Y, ColorImageFormat.RgbResolution640x480Fps30); //right hand ColorImagePoint rightColorPoint = depth.MapToColorImagePoint(rightDepthPoint.X, rightDepthPoint.Y, ColorImageFormat.RgbResolution640x480Fps30); //Set location //CameraPosition(headImage, headColorPoint); CameraPosition(leftEllipse, leftColorPoint); CameraPosition(rightEllipse, rightColorPoint); // do the points bool leftValid = false; bool rightValid = false; leftEllipse = doDepthCalculation(leftEllipse, leftDepthPoint, 1250, true, out leftValid); rightEllipse = doDepthCalculation(rightEllipse, rightDepthPoint, 1250, false, out rightValid); // play / turn off the right notes // right hand if (rightValid) { int rectangleIndex = -1; NoteRectangle thisNoteRectangle = getNoteRectangleAtPoint(rightColorPoint, false, out rectangleIndex); thisNoteRectangle.PlayNote(); thisNoteRectangle.Rectangle.Fill = Brushes.Green; rightHandLabel.Content = thisNoteRectangle.Pitch.ToString(); for (int x = 0; x < rightNotes.Count; x++) { if (x != rectangleIndex) { rightNotes[x].StopNote(); rightNotes[x].Rectangle.Fill = null; } } } else { foreach (NoteRectangle x in rightNotes) { x.StopNote(); } int rectangleIndex = -1; getNoteRectangleAtPoint(rightColorPoint, false, out rectangleIndex).StopNote(); } } }