private void BDBGCForm_Load(object sender, EventArgs eload) { BDBGlovesClient.CreateMidiPort(); //Open "BDB_MIDI" port //If BLEHandlingDiscovery Class has been Instantiated, Look for Devices if (bleDevice != null) { try { bleDevice.StartBLEDeviceWatcher(); } catch { MessageBox.Show("Glove One is Disconnected!"); } } if (bleDevice_2 != null) { try { bleDevice_2.StartBLEDeviceWatcher(); } catch { MessageBox.Show("Glove Two Is Disconnected!"); } } Debug.WriteLine("Form Load"); //Fill Camera Combo Boxes with Camera Index, Disable Start Buttons FillCaptureComboBoxes(); captureOneStartButton.Enabled = false; captureTwoStartButton.Enabled = false; }
private void sendMidiNoteButton_Click(object sender, EventArgs e) { BDBGlovesClient.SendNextMidiOutMessage(0x91, 60, 127); }
public void MIDINoteTriggering() { int note = 60; //MIDI Note C5 int velocity_1 = 127; //Max Velocity int velocity_2 = 127; int command = 0x90; //Send Note over BDB_MIDI Channel 1 int command_2 = 0x91; //Send Note over BDB_MIDI Channel 2 int curstate = 0; //Marks when hand is rising int curstate_2 = 0; float accX; float gyroY; float accX_2; float gyroY_2; _MidiTriggeringBackgroundWorker = new BackgroundWorker(); _MidiTriggeringBackgroundWorker.WorkerSupportsCancellation = true; _MidiTriggeringBackgroundWorker.RunWorkerAsync(); _MidiTriggeringBackgroundWorker.DoWork += new DoWorkEventHandler(async(state, args) => { do { if (_MidiTriggeringBackgroundWorker.CancellationPending) { break; } while (StartIMUCheckBox.Checked) { bleDevice.UpdateAllData(); //Grab IMU Data bleDevice_2.UpdateAllData(); //Grab IMU Data accX = bleDevice.accAngleX; gyroY = bleDevice.gyroAngleY; //Use Angular Velocity to determine dynamic quality (scaled between 0 and 127) velocity_1 = (int)((Math.Abs(gyroY) / 2.0) * 127); Debug.WriteLine($"Velocity 1: {velocity_1}"); //Note Triggered if enough motion is detected and the hand is accelerating downard if (MotionCountOne > 3) //Camera one represents sampler channel one { if ((accX < 0.1) && (curstate == 0)) { if (curstate == 0) { //Send MIDI Note BDBGlovesClient.SendNextMidiOutMessage(command, note, 127); Debug.WriteLine($"Acc X: {bleDevice.accAngleX}"); curstate = 1; } } } if ((bleDevice.accAngleX > 0.1) && (curstate == 1)) { curstate = 0; //reset when hand is rising } accX_2 = bleDevice_2.accAngleX; gyroY_2 = bleDevice_2.gyroAngleY; velocity_2 = (int)((Math.Abs(gyroY_2) / 2.0) * 127); Debug.WriteLine($"Velocity 2: {velocity_2}"); if (MotionCountTwo > 3) { if ((accX_2 < 0.1) && (curstate_2 == 0)) { if (curstate_2 == 0) { BDBGlovesClient.SendNextMidiOutMessage(command_2, note, 127); Debug.WriteLine($"Acc X_2: {bleDevice_2.accAngleX}"); curstate_2 = 1; } } } if ((bleDevice_2.accAngleX > 0.1) && (curstate_2 == 1)) { curstate_2 = 0; } } } while (true); }); }