Exemplo n.º 1
0
        public IDeviceManualTriggerContext ManualTrigger(DeviceManualTriggerContextOption Option = null)
        {
            if (Option != null)
            {
                DeviceAddedEventHandler threadSafeEventHandler = DeviceAdded;
                SixtyBeatAudioDevice    device = SixtyBeatAudioDevice.Create(Option.Tag as string);
                if (device != null)
                {
                    threadSafeEventHandler?.Invoke(this, device);
                }
                return(null);
            }

            SixtyBeatAudioDeviceManualTriggerContext ResponseData = new SixtyBeatAudioDeviceManualTriggerContext();

            ResponseData.Options = new List <DeviceManualTriggerContextOption>();

            var enumerator = new NAudio.CoreAudioApi.MMDeviceEnumerator();

            //cycle through all audio devices
            for (int i = 0; i < WaveIn.DeviceCount; i++)
            {
                // these happen to enumate the same order
                NAudio.CoreAudioApi.MMDevice dev = enumerator.EnumerateAudioEndPoints(NAudio.CoreAudioApi.DataFlow.Capture, NAudio.CoreAudioApi.DeviceState.Active)[i];

                string DeviceID = dev.Properties[new NAudio.CoreAudioApi.PropertyKey(DevPKey.Native.PnpDevicePropertyAPINative.DEVPKEY_Audio_InstanceId.fmtid, (int)DevPKey.Native.PnpDevicePropertyAPINative.DEVPKEY_Audio_InstanceId.pid)].Value.ToString();
                if (!SixtyBeatAudioDevice.DeviceKnown(DeviceID))
                {
                    ResponseData.Options.Add(new DeviceManualTriggerContextOption(dev.FriendlyName, DeviceID));
                }
            }
            enumerator.Dispose();

            return(ResponseData);
        }
Exemplo n.º 2
0
        public void ScanNow()
        {
            lock (lock_device_list)
            {
                try
                {
                    for (byte i = 0; i < MAX_SLOT; i++)
                    {
                        XInputNative.XInputCapabilities data = new XInputNative.XInputCapabilities();

                        if (DeviceCache[i] == null)
                        {
                            if (XInputNative.XInputGetCapabilities(i + 1, 0, ref data) == 0)
                            {
                                if (DeviceCache[i] == null)
                                {
                                    DeviceCache[i] = new XInputDevice(i);
                                }
                                DeviceAddedEventHandler threadSafeEventHandler = DeviceAdded;
                                threadSafeEventHandler?.Invoke(this, DeviceCache[i]);
                            }
                        }
                        else
                        {
                            bool connected = XInputNative.XInputGetCapabilities(i + 1, 0, ref data) == 0;
                            if (!connected)
                            {
                                DeviceRemovedEventHandler threadSafeEventHandler = DeviceRemoved;
                                threadSafeEventHandler?.Invoke(this, DeviceCache[i].UniqueKey);
                                DeviceCache[i] = null;
                            }
                        }
                    }
                }
                catch { }
            }
        }