Beispiel #1
0
        private void HandleHotkeyPress(object sender, WindowsAPIAdapter.KeyPressedEventArgs e)
        {
            using (AppLogger.Log.DebugCall())
            {
                if (e.HotKeys != AppConfigs.Configuration.PlaybackHotKeys && e.HotKeys != AppConfigs.Configuration.RecordingHotKeys)
                {
                    AppLogger.Log.Debug("Not the registered Hotkeys", e.HotKeys);
                    return;
                }

                try
                {
                    if (e.HotKeys == AppConfigs.Configuration.PlaybackHotKeys)
                    {
                        CycleActiveDevice(AudioDeviceType.Playback);
                    }
                    else if (e.HotKeys == AppConfigs.Configuration.RecordingHotKeys)
                    {
                        CycleActiveDevice(AudioDeviceType.Recording);
                    }
                }
                catch (Exception ex)
                {
                    ErrorTriggered?.Invoke(this, new ExceptionEvent(ex));
                }
            }
        }
Beispiel #2
0
        public bool SetHotkeyCombination(HotKeys hotkeys, AudioDeviceType deviceType)
        {
            using (AppLogger.Log.InfoCall())
            {
                HotKeys confHotKeys = null;
                switch (deviceType)
                {
                case AudioDeviceType.Playback:
                    confHotKeys = AppConfigs.Configuration.PlaybackHotKeys;
                    break;

                case AudioDeviceType.Recording:
                    confHotKeys = AppConfigs.Configuration.RecordingHotKeys;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null);
                }
                using (AppLogger.Log.InfoCall())
                {
                    AppLogger.Log.Info("Unregister previous hotkeys", confHotKeys);
                    WindowsAPIAdapter.UnRegisterHotKey(confHotKeys);
                    AppLogger.Log.Info("Unregistered previous hotkeys", confHotKeys);

                    if (hotkeys.Enabled && !WindowsAPIAdapter.RegisterHotKey(hotkeys))
                    {
                        AppLogger.Log.Warn("Can't register new hotkeys", hotkeys);
                        ErrorTriggered?.Invoke(this,
                                               new ExceptionEvent(new Exception("Impossible to register HotKey: " + hotkeys)));
                        return(false);
                    }

                    AppLogger.Log.Info("New Hotkeys registered", hotkeys);
                }
                switch (deviceType)
                {
                case AudioDeviceType.Playback:
                    AppConfigs.Configuration.PlaybackHotKeys = hotkeys;
                    break;

                case AudioDeviceType.Recording:
                    AppConfigs.Configuration.RecordingHotKeys = hotkeys;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(deviceType), deviceType, null);
                }
                AppConfigs.Configuration.Save();
                return(true);
            }
        }
Beispiel #3
0
 /// <summary>
 ///     Cycles the active device to the next device. Returns true if succesfully switched (at least
 ///     as far as we can tell), returns false if could not successfully switch. Throws NoDevicesException
 ///     if there are no devices configured.
 /// </summary>
 public bool CycleActiveDevice(AudioDeviceType type)
 {
     using (AppLogger.Log.InfoCall())
     {
         try
         {
             return(_deviceCyclerManager.CycleDevice(type));
         }
         catch (Exception exception)
         {
             ErrorTriggered?.Invoke(this, new ExceptionEvent(exception));
         }
         return(false);
     }
 }
Beispiel #4
0
 /// <summary>
 ///     Attempts to set active device to the specified name
 /// </summary>
 /// <param name="device"></param>
 public bool SetActiveDevice(IAudioDevice device)
 {
     using (AppLogger.Log.InfoCall())
     {
         try
         {
             return(_deviceCyclerManager.SetAsDefault(device));
         }
         catch (Exception ex)
         {
             ErrorTriggered?.Invoke(this, new ExceptionEvent(ex));
         }
         return(false);
     }
 }
Beispiel #5
0
        /// <summary>
        ///     Attempts to set active device to the specified name
        /// </summary>
        /// <param name="device"></param>
        public bool SetActiveDevice(IAudioDevice device)
        {
            using (AppLogger.Log.InfoCall())
            {
                try
                {
                    AppLogger.Log.Info("Set Default device", device);
                    if (!SetCommunications)
                    {
                        device.SetAsDefault(Role.Console);
                        device.SetAsDefault(Role.Multimedia);
                    }
                    else
                    {
                        AppLogger.Log.Info("Set Default Communication device", device);
                        device.SetAsDefault(Role.All);
                    }
                    switch (device.Type)
                    {
                    case AudioDeviceType.Playback:
                        AppConfigs.Configuration.LastPlaybackActiveId = device.Id;
                        break;

                    case AudioDeviceType.Recording:
                        AppConfigs.Configuration.LastRecordingActiveId = device.Id;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                    AppConfigs.Configuration.Save();
                    return(true);
                }
                catch (Exception ex)
                {
                    ErrorTriggered?.Invoke(this, new ExceptionEvent(ex));
                }
                return(false);
            }
        }
Beispiel #6
0
        /// <summary>
        ///     Cycles the active device to the next device. Returns true if succesfully switched (at least
        ///     as far as we can tell), returns false if could not successfully switch. Throws NoDevicesException
        ///     if there are no devices configured.
        /// </summary>
        public bool CycleActiveDevice(AudioDeviceType type)
        {
            using (AppLogger.Log.InfoCall())
            {
                ICollection <IAudioDevice> list = null;
                string lastActive = null;
                switch (type)
                {
                case AudioDeviceType.Playback:
                    list       = AvailablePlaybackDevices;
                    lastActive = AppConfigs.Configuration.LastPlaybackActive;
                    break;

                case AudioDeviceType.Recording:
                    list       = AvailableRecordingDevices;
                    lastActive = AppConfigs.Configuration.LastRecordingActive;
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(type), type, null);
                }

                switch (list.Count)
                {
                case 0:
                    ErrorTriggered?.Invoke(this, new ExceptionEvent(new NoDevicesException()));
                    return(false);

                case 1:
                    return(false);
                }
                AppLogger.Log.Info("Cycle Audio Devices", list);
                var defaultDev = list.FirstOrDefault(device => device.FriendlyName == lastActive) ?? list.FirstOrDefault(device => device.IsDefault(Role.Console)) ?? list.ElementAt(0);
                var next       = list.SkipWhile((device, i) => device != defaultDev).Skip(1).FirstOrDefault() ?? list.ElementAt(0);
                AppLogger.Log.Info("Select AudioDevice", next);
                return(SetActiveDevice(next));
            }
        }