public static void HandleMidiSetup(Midi.Pitch pitch) { //This is run when a key is pressed in setup mode. //Check if we're waiting for a key, or if the user is just pressing keys because they feel like it if (waitingForKeyInput) { //Check if that key already exists. if (FindItemByMidiPitch(pitch) != null) { //It exists! Ignore. return; } waitingForKeyInput = false; //Okay. Deal with it. MidiProfileItem item = new MidiProfileItem(pitch, midiSetupBufferKey); activeKeys.Add(item); bool ok = false; bool cont = false; while (!ok) { Console.Clear(); Console.WriteLine("Done!\r\nWould you like to continue? [Y/N]\r\n"); string input = Console.ReadLine(); if (input.ToLower() == "y") { ok = true; cont = true; } if (input.ToLower() == "n") { ok = true; cont = false; } } //Check if we should continue if (!cont) { //Just change the status to good and continue Console.Clear(); Console.WriteLine("Ready!"); Console.WriteLine("Saved config to " + SaveProfile() + "!"); state = ProgramState.Ready; //Also reverse the last key to be pressed because jank activeKeys[activeKeys.Count - 1].isDown = true; return; } //Ask again PromptForKey(); } }
public static MidiProfileItem FindItemByMidiPitch(Midi.Pitch pitch) { //Search for this foreach (MidiProfileItem p in activeKeys) { //Check if (pitch == p.pitch) { return(p); } } //Not valid. Just ignore it return(null); }
private Joint rightHandToPitch(Joint rightHand) { float yAxis = rightHand.Position.Y; int midiValueY = Math.Abs((int)(yAxis * 50)) % 50 + 50; //Pitch pitchSend = (Pitch)(positionY); Clock clock = new Clock(120); // beatsPerMinute=120 clock.Start(); Midi.Pitch midiPitch = (Midi.Pitch)midiValueY; clock.Schedule(new NoteOnOffMessage(currentOutputDevice, midiChannel, midiPitch, 50, 0, clock, 1)); return(rightHand); }
public static void HandleMidi(Midi.Pitch pitch) { //Handles ALL incoming requests. //Check if we're okay to run the commands. if (state == ProgramState.Setup) { //Change to the setup function HandleMidiSetup(pitch); return; } if (state != ProgramState.Ready) { return; } //Look up the key MidiProfileItem item = FindItemByMidiPitch(pitch); //Check if it's real if (item == null) { //Invalid Console.ForegroundColor = ConsoleColor.Blue; Console.WriteLine("Key " + pitch.ToString() + " pressed, but no valid key was found!"); Console.ForegroundColor = ConsoleColor.White; return; } //Valid key! Toggle it if (item.isDown) { //Pressed. Release it StopKey(item.key); } else { //Not pressed. Press it SendKey(item.key); } //Print Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("Key " + pitch.ToString() + " changed. Key " + item.key + " is toggled. Key is now down? " + (!item.isDown).ToString()); //Toggle it item.isDown = !item.isDown; }
private ICollection percussionToMidiOutput(Skeleton skeleton, DrawingContext dc, Joint hittingJoint, Joint referenceJoint, int midiOffset, ref List <SkeletonPoint> posHist, ref bool frshHt) { Joint hitHand = hittingJoint; Joint leftHand = skeleton.Joints[JointType.HandLeft]; Joint bodyCenter = referenceJoint; bool isInPercRadius = Distance2D(hitHand.Position.X, hitHand.Position.Y, bodyCenter.Position.X, bodyCenter.Position.Y) > PERCUSSION_RADIUS; if (isInPercRadius) { if (isHighVelocity(hitHand.Position, dc, posHist) && frshHt) { int midiValue; if (hitHand.Position.Y - bodyCenter.Position.Y < 0) { if (hitHand.Position.Y - bodyCenter.Position.Y < -PERCUSSION_RADIUS / 2) { midiValue = 1 + midiOffset; dc.DrawEllipse(Brushes.Yellow, new Pen(Brushes.Yellow, 20), mainWindow.SkeletonPointToScreen(hittingJoint.Position), 20, 20); } else { midiValue = 2 + midiOffset; dc.DrawEllipse(Brushes.Red, new Pen(Brushes.Red, 20), mainWindow.SkeletonPointToScreen(hittingJoint.Position), 20, 20); } } else { if (hitHand.Position.Y - bodyCenter.Position.Y < PERCUSSION_RADIUS / 2) { midiValue = 3 + midiOffset; dc.DrawEllipse(Brushes.Blue, new Pen(Brushes.Blue, 20), mainWindow.SkeletonPointToScreen(hittingJoint.Position), 20, 20); } else { midiValue = 4 + midiOffset; dc.DrawEllipse(Brushes.Green, new Pen(Brushes.Green, 20), mainWindow.SkeletonPointToScreen(hittingJoint.Position), 20, 20); } } Clock clock = new Clock(120); // beatsPerMinute=120 clock.Start(); Midi.Pitch midiPitch = (Midi.Pitch)midiValue; clock.Schedule(new NoteOnOffMessage(currentOutputDevice, midiChannel, midiPitch, 50, 0, clock, 3)); frshHt = false; // Console.WriteLine("Bang!" + bodyCenter.Position.X); drawToScreen(dc, Distance2D(hitHand.Position.X, hitHand.Position.Y, bodyCenter.Position.X, bodyCenter.Position.Y), 6); } } else { frshHt = true; } ArrayList newValues = new ArrayList(); return(newValues); }
//private class NoteBackgroundRenderScaleTransform //{ //} public void PlayNote(int key, double duration) { Midi.Pitch Note = ((Midi.Pitch[])Enum.GetValues(typeof(Midi.Pitch)))[key + 21]; outputDevice.SendNoteOn(Channel.Channel1, Note, 80); Thread.Sleep((int)duration); }