コード例 #1
0
 /// <summary>
 /// Connects specific launchpad or auto connect or only refresh list
 /// </summary>
 /// <param name="id">Midi device Id. leave empty to only refresh device list</param>
 private void ConnectLaunchpad(string id = "")
 {
     if (id == "" || devices == null)
     {
         devices = Launchpad.Engines.Winmm.WinmmMidiDevices.GetLaunchpads();
     }
     if (devices.Count == 0)
     {
         MessageBox.Show("Launchpad not found. Please try again", "Error", MessageBoxButtons.OK);
         return;
     }
     // disconnect if necessary
     if (connectingDevice != null && connectingDevice.Id != id && id != "")
     {
         connectingDevice.Stop();
         connectingDevice = null;
     }
     // if device not yet connected for whatever reason
     if (connectingDevice == null)
     {
         if (id == "")
         {
             connectingDevice = new LaunchpadDevice(devices[devices.Count - 1]);
         }
         else
         {
             foreach (var device in devices)
             {
                 if (device.Id == id)
                 {
                     connectingDevice = new LaunchpadDevice(device);
                     break;
                 }
             }
         }
         if (connectingDevice != null)
         {
             connectingDevice.Start(140, 0);
         }
         else
         {
             MessageBox.Show("Selected device not found", "Error", MessageBoxButtons.OK);
         }
     }
 }
コード例 #2
0
 private void Form1_Load(object sender, EventArgs e)
 {
     FormClosing += (object a, FormClosingEventArgs b) => connectingDevice?.Stop();
     RefreshDeviceList();
 }