// // // private async void MidiInputDevicesListBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { DeviceInformation di = midiInputDevicesCollection.ElementAt(MidiInputDevicesListBox.SelectedIndex); await mdiEngine.setMidiInputPortId(di); }
/// <summary> /// Initializes the MediaCapture, registers events, gets camera device information for mirroring and rotating, and starts preview /// </summary> /// <returns></returns> private async Task InitializeCameraAsync() { Debug.WriteLine("InitializeCameraAsync"); if (_mediaCapture == null) { // Fujimaki Add カメラデバイスの選択処理 DeviceInformationCollection cameraDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); DeviceInformation cameraDevice = null; for (int i = 0; i < cameraDevices.Count(); i++) { if (cameraDevices.ElementAt(i).Name == _cameraDeviceNames[_cameraID]) { cameraDevice = cameraDevices.ElementAt(i); break; } } // Fujimaki Add End カメラデバイスの選択処理 if (cameraDevice == null) { Debug.WriteLine("No camera device found!"); return; } // Create MediaCapture and its settings _mediaCapture = new MediaCapture(); // Register for a notification when something goes wrong _mediaCapture.Failed += MediaCapture_Failed; var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id }; // Initialize MediaCapture try { await _mediaCapture.InitializeAsync(settings); _isInitialized = true; } catch (UnauthorizedAccessException) { Debug.WriteLine("The app was denied access to the camera"); } catch (Exception excep) { int a = 0; } // If initialization succeeded, start the preview if (_isInitialized) { // Figure out where the camera is located if (cameraDevice.EnclosureLocation == null || cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Unknown) { // No information on the location of the camera, assume it's an external camera, not integrated on the device _externalCamera = true; } else { // Camera is fixed on the device _externalCamera = false; // Only mirror the preview if the camera is on the front panel _mirroringPreview = (cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front); } await SetResolution(); await StartPreviewAsync(); var picturesLibrary = await StorageLibrary.GetLibraryAsync(KnownLibraryId.Pictures); // Fall back to the local app storage if the Pictures Library is not available _captureFolder = picturesLibrary.SaveFolder ?? ApplicationData.Current.LocalFolder; } } }
internal async Task <int> ImediateEnum() { // Create a selector that gets a HID device using VID/PID and a // VendorDefined usage. var selector = HidDevice.GetDeviceSelector(usagePage, usageId); // Enumerate devices using the selector. DeviceInformationCollection devices = await DeviceInformation.FindAllAsync(selector); foreach (YUSBDevice yusbDevice in _usableDevices) { yusbDevice.MarkForUnplug = true; } if (devices.Count > 0) { for (var i = 0; i < devices.Count; i++) { var devinfo = devices.ElementAt(i); if (!devinfo.IsEnabled) { _hub._yctx._Log(devinfo.Name + " is disabled (skip)\n"); continue; } bool found = false; foreach (YUSBDevice yusbDevice in _usableDevices) { if (yusbDevice.Info.Id == devinfo.Id && yusbDevice.imm_isWorking()) { yusbDevice.MarkForUnplug = false; found = true; break; } } if (found) { continue; } // Open the target HID device at index 0. var device = await HidDevice.FromIdAsync(devinfo.Id, FileAccessMode.ReadWrite); if (device == null) { // allready opened continue; } if (device.VendorId == 0x24e0) { YUSBDevice yusbDevice = new YUSBDevice(this, _hub, device, devinfo); //Debug.WriteLine("setup yusbDevice=s " + yusbDevice.GetHashCode() + " device=" + device.GetHashCode()); await yusbDevice.Setup(YUSBPkt.YPKT_USB_VERSION_BCD); _allDevice.Add(yusbDevice); _usableDevices.Add(yusbDevice); } else { Debug.WriteLine("drop" + device.VendorId + ":" + device.ProductId); device.Dispose(); } } } _usableDevices.RemoveAll(item => item.MarkForUnplug); return(_usableDevices.Count); }
/// <summary> /// Initializes the MediaCapture, registers events, gets camera device information for mirroring and rotating, starts preview and unlocks the UI /// </summary> /// <returns></returns> private async Task InitializeCameraAsync() { Debug.WriteLine("InitializeCameraAsync"); if (_mediaCapture == null) { // Attempt to get the back camera if one is available, but use any camera device if not // var cameraDevice = await FindCameraDeviceByPanelAsync(Windows.Devices.Enumeration.Panel.Back); DeviceInformationCollection cameraDevices = await DeviceInformation.FindAllAsync(DeviceClass.VideoCapture); DeviceInformation cameraDevice = null; for (int i = 0; i < 3; i++) { if (cameraDevices.ElementAt(i).Name != "USB 2.0 Camera") { continue; } cameraDevice = cameraDevices.ElementAt(i); } if (cameraDevice == null) { Debug.WriteLine("No camera device found!"); return; } // Create MediaCapture and its settings _mediaCapture = new MediaCapture(); // Register for a notification when video recording has reached the maximum time and when something goes wrong _mediaCapture.RecordLimitationExceeded += MediaCapture_RecordLimitationExceeded; _mediaCapture.Failed += MediaCapture_Failed; var settings = new MediaCaptureInitializationSettings { VideoDeviceId = cameraDevice.Id }; // Initialize MediaCapture try { await _mediaCapture.InitializeAsync(settings); _isInitialized = true; } catch (UnauthorizedAccessException) { Debug.WriteLine("The app was denied access to the camera"); } // If initialization succeeded, start the preview if (_isInitialized) { // Figure out where the camera is located if (cameraDevice.EnclosureLocation == null || cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Unknown) { // No information on the location of the camera, assume it's an external camera, not integrated on the device _externalCamera = true; } else { // Camera is fixed on the device _externalCamera = false; // Only mirror the preview if the camera is on the front panel _mirroringPreview = (cameraDevice.EnclosureLocation.Panel == Windows.Devices.Enumeration.Panel.Front); } // Initialize rotationHelper _rotationHelper = new CameraRotationHelper(cameraDevice.EnclosureLocation); _rotationHelper.OrientationChanged += RotationHelper_OrientationChanged; await StartPreviewAsync(); UpdateCaptureControls(); } } }