コード例 #1
0
        private void t_Tick(object sender, EventArgs e)
        {
            ((Timer)sender).Stop();
            if (DoubleClickHappened)
            {
                return;
            }

            if (ConfigurationSettings.EnableQuickSwitch)
            {
                if (FavouriteDeviceManager.FavouriteDeviceCount > 0)
                {
                    string devid = FavouriteDeviceManager.GetNextFavouritePlaybackDevice();

                    AudioDeviceManager.GetAudioDevice(devid).SetAsDefaultDevice();

                    RefreshPlaybackDevices();
                }
            }
            else
            {
                RefreshNotifyIconItems();
                MethodInfo mi = typeof(NotifyIcon).GetMethod("ShowContextMenu",
                                                             BindingFlags.Instance | BindingFlags.NonPublic);
                mi.Invoke(notifyIcon1, null);
            }
        }
コード例 #2
0
        private void RefreshRecordingDropDownButton()
        {
            if (SelectedRecordingDevice == null)
            {
                btnSetRecordingDefault.Enabled = false;
                return;
            }

            if (SelectedRecordingDevice.ID == AudioDeviceManager.DefaultRecordingDevice.ID)
            {
                mnuSetRecordingDefault.CheckState = CheckState.Checked;
            }
            else
            {
                mnuSetRecordingDefault.CheckState = CheckState.Unchecked;
            }

            if (SelectedRecordingDevice.ID == AudioDeviceManager.DefaultRecordingCommDevice.ID)
            {
                mnuSetRecordingCommunicationDefault.CheckState = CheckState.Checked;
            }
            else
            {
                mnuSetRecordingCommunicationDefault.CheckState = CheckState.Unchecked;
            }

            if (FavouriteDeviceManager.IsFavouriteDevice(SelectedRecordingDevice.ID))
            {
                mnuFavouriteRecordingDevice.CheckState = CheckState.Checked;
            }
            else
            {
                mnuFavouriteRecordingDevice.CheckState = CheckState.Unchecked;
            }

            if (ConfigurationSettings.StartupRecordingDeviceID == SelectedRecordingDevice.ID)
            {
                mnuSetRecordingStartupDevice.CheckState = CheckState.Checked;
            }
            else
            {
                mnuSetRecordingStartupDevice.CheckState = CheckState.Unchecked;
            }

            if (SelectedRecordingDevice.State == AudioDeviceState.Unplugged)
            {
                btnSetRecordingDefault.Enabled      = false;
                mnuFavouriteRecordingDevice.Enabled = false;
            }
            else
            {
                btnSetRecordingDefault.Enabled      = true;
                mnuFavouriteRecordingDevice.Enabled = true;
            }
        }
コード例 #3
0
        private void RefreshNotifyIconItems()
        {
            notifyIconStrip.Items.Clear();

            int playbackCount  = 0;
            int recordingCount = 0;

            ReadOnlyCollection <AudioDevice> list = AudioDeviceManager.PlayBackDevices;

            foreach (AudioDevice ad in list)
            {
                if (FavouriteDeviceManager.FavouriteDeviceCount > 0 && !FavouriteDeviceManager.IsFavouriteDevice(ad))
                {
                    continue;
                }

                var item = new ToolStripMenuItem(ad.FullName);
                item.Tag     = ad;
                item.Checked = ad.ID == AudioDeviceManager.DefaultPlaybackDevice.ID;
                notifyIconStrip.Items.Add(item);
                playbackCount++;
            }

            if (playbackCount > 0)
            {
                notifyIconStrip.Items.Add(new ToolStripSeparator());
            }

            list = AudioDeviceManager.RecordingDevices;

            foreach (AudioDevice ad in AudioDeviceManager.RecordingDevices)
            {
                if (FavouriteDeviceManager.FavouriteDeviceCount > 0 && !FavouriteDeviceManager.IsFavouriteDevice(ad))
                {
                    continue;
                }

                var item = new ToolStripMenuItem(ad.FullName);
                item.Tag     = ad;
                item.Checked = ad.ID == AudioDeviceManager.DefaultRecordingDevice.ID;
                notifyIconStrip.Items.Add(item);
                recordingCount++;
            }

            if (recordingCount > 0)
            {
                notifyIconStrip.Items.Add(new ToolStripSeparator());
            }

            notifyIconStrip.Items.Add(exitToolStripMenuItem);

            notifyIcon1.Text = AudioDeviceManager.DefaultPlaybackDevice.FullName;
        }
コード例 #4
0
        private void LoadSettings()
        {
            //Fix to stop the registry thing being removed and not re-added
            Program.Settings.AutoStartWithWindows = Program.Settings.AutoStartWithWindows;

            chkCloseToTray.Checked          = Program.Settings.CloseToTray;
            chkStartMinimized.Checked       = Program.Settings.StartMinimized;
            chkAutoStartWithWindows.Checked = Program.Settings.AutoStartWithWindows;
            chkDisableHotKeys.Checked       = Program.Settings.DisableHotKeys;
            chkQuickSwitch.Checked          = Program.Settings.EnableQuickSwitch;
            chkDualSwitchMode.Checked       = Program.Settings.DualSwitchMode;
            chkNotifyUpdates.Checked        = Program.Settings.UpdateNotificationsEnabled;

            chkShowDiabledDevices.Checked      = Program.Settings.ShowDisabledDevices;
            chkShowDisconnectedDevices.Checked = Program.Settings.ShowDisconnectedDevices;
            chkShowDPDeviceIconInTray.Checked  = Program.Settings.ShowDPDeviceIconInTray;

            Width  = Program.Settings.WindowWidth;
            Height = Program.Settings.WindowHeight;

            FavouriteDeviceManager.FavouriteDevicesChanged += AudioDeviceManger_FavouriteDevicesChanged;

            var favDeviceStr = Program.Settings.FavouriteDevices.Split(new[] { ",", "[", "]" },
                                                                       StringSplitOptions.RemoveEmptyEntries);

            FavouriteDeviceManager.LoadFavouriteDevices(Array.ConvertAll(favDeviceStr, x =>
            {
                var r = new Regex(ConfigurationSettings.GUID_REGEX);
                foreach (var match in r.Matches(x))
                {
                    return(new Guid(match.ToString()));
                }

                return(Guid.Empty);
            }));

            //Ensure to delete the key if it's not set
            Program.Settings.AutoStartWithWindows = Program.Settings.AutoStartWithWindows;

            if (Program.Settings.ShowDisabledDevices)
            {
                _deviceStateFilter |= DeviceState.Disabled;
            }


            if (Program.Settings.ShowDisconnectedDevices)
            {
                _deviceStateFilter |= DeviceState.Unplugged;
            }
        }
コード例 #5
0
        private void mnuFavouriteRecordingDevice_Click(object sender, EventArgs e)
        {
            string id = SelectedRecordingDevice.ID;

            if (mnuFavouriteRecordingDevice.Checked)
            {
                FavouriteDeviceManager.RemoveFavouriteDevice(SelectedRecordingDevice.ID);
            }
            else
            {
                FavouriteDeviceManager.AddFavouriteDevice(SelectedRecordingDevice.ID);
            }

            PostRecordingMenuClick(id);
        }
コード例 #6
0
        private void mnuFavouritePlaybackDevice_Click(object sender, EventArgs e)
        {
            string id = SelectedPlaybackDevice.ID;

            //if checked then we need to remove

            if (mnuFavouritePlaybackDevice.Checked)
            {
                FavouriteDeviceManager.RemoveFavouriteDevice(SelectedPlaybackDevice.ID);
            }
            else
            {
                FavouriteDeviceManager.AddFavouriteDevice(SelectedPlaybackDevice.ID);
            }

            PostPlaybackMenuClick(id);
        }
コード例 #7
0
        private void LoadSettings()
        {
            //Fix to stop the registry thing being removed and not re-added
            ConfigurationSettings.AutoStartWithWindows = ConfigurationSettings.AutoStartWithWindows;

            chkCloseToTray.Checked          = ConfigurationSettings.CloseToTray;
            chkStartMinimized.Checked       = ConfigurationSettings.StartMinimized;
            chkAutoStartWithWindows.Checked = ConfigurationSettings.AutoStartWithWindows;
            chkDisableHotKeys.Checked       = ConfigurationSettings.DisableHotKeys;
            chkQuickSwitch.Checked          = ConfigurationSettings.EnableQuickSwitch;
            //chkNotifyUpdates.Checked = ConfigurationSettings.CheckForUpdatesOnStartup;
            chkPollForUpdates.Checked = ConfigurationSettings.PollForUpdates >= 1;
            spinPollMinutes.Enabled   = chkPollForUpdates.Checked;

            Width  = ConfigurationSettings.WindowWidth;
            Height = ConfigurationSettings.WindowHeight;

            FavouriteDeviceManager.FavouriteDevicesChanged += AudioDeviceManger_FavouriteDevicesChanged;
            FavouriteDeviceManager.LoadFavouriteDevices(
                ConfigurationSettings.FavouriteDevices.Split(new[] { ",", "[", "]" },
                                                             StringSplitOptions.RemoveEmptyEntries));


            //Ensure the registry key is added/removed
            if (ConfigurationSettings.AutoStartWithWindows)
            {
                RegistryKey add = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
                                                                  true);
                add.SetValue("AudioSwitcher", "\"" + Application.ExecutablePath + "\"");
            }
            else
            {
                RegistryKey key = Registry.CurrentUser.OpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
                                                                  true);
                try
                {
                    key.DeleteValue("AudioSwitcher");
                }
                catch
                {
                } //Don't care as it isn't found
            }
        }
コード例 #8
0
        private void mnuFavouriteRecordingDevice_Click(object sender, EventArgs e)
        {
            if (SelectedRecordingDevice == null)
            {
                return;
            }

            var id = SelectedRecordingDevice.Id;

            if (mnuFavouriteRecordingDevice.Checked)
            {
                FavouriteDeviceManager.RemoveFavouriteDevice(SelectedRecordingDevice.Id);
            }
            else
            {
                FavouriteDeviceManager.AddFavouriteDevice(SelectedRecordingDevice.Id);
            }

            PostRecordingMenuClick(id);
        }
コード例 #9
0
        private void t_Tick(object sender, EventArgs e)
        {
            ((Timer)sender).Stop();
            if (_doubleClickHappened)
            {
                return;
            }

            if (Program.Settings.EnableQuickSwitch)
            {
                if (FavouriteDeviceManager.FavouriteDeviceCount > 0)
                {
                    var changed = false;
                    var currentDefaultDevice = AudioDeviceManager.Controller.DefaultPlaybackDevice;
                    var candidate            = FavouriteDeviceManager.GetNextFavouritePlaybackDevice(currentDefaultDevice);
                    var attemptsCount        = FavouriteDeviceManager.FavouritePlaybackDeviceCount;
                    for (var i = 0; !changed && i < attemptsCount; i++)
                    {
                        changed = candidate.SetAsDefault();

                        if (changed && Program.Settings.DualSwitchMode)
                        {
                            candidate.SetAsDefaultCommunications();
                        }

                        if (!changed)
                        {
                            candidate = FavouriteDeviceManager.GetNextFavouritePlaybackDevice(candidate);
                        }
                    }
                }
            }
            else
            {
                RefreshNotifyIconItems();
                var mi = typeof(NotifyIcon).GetMethod("ShowContextMenu",
                                                      BindingFlags.Instance | BindingFlags.NonPublic);
                mi.Invoke(notifyIcon1, null);
            }
        }
コード例 #10
0
        private void RefreshRecordingDropDownButton()
        {
            if (SelectedRecordingDevice == null)
            {
                btnSetRecordingDefault.Enabled = false;
                return;
            }

            mnuSetRecordingDefault.CheckState = SelectedRecordingDevice.IsDefaultDevice
                ? CheckState.Checked
                : CheckState.Unchecked;

            mnuSetRecordingCommunicationDefault.CheckState = SelectedRecordingDevice.IsDefaultCommunicationsDevice
                ? CheckState.Checked
                : CheckState.Unchecked;

            mnuFavouriteRecordingDevice.CheckState = FavouriteDeviceManager.IsFavouriteDevice(SelectedRecordingDevice.Id)
                ? CheckState.Checked
                : CheckState.Unchecked;

            mnuSetRecordingStartupDevice.CheckState = Program.Settings.StartupRecordingDeviceID ==
                                                      SelectedRecordingDevice.Id
                ? CheckState.Checked
                : CheckState.Unchecked;

            if (SelectedRecordingDevice.State == DeviceState.Unplugged)
            {
                btnSetRecordingDefault.Enabled      = false;
                mnuFavouriteRecordingDevice.Enabled = false;
            }
            else
            {
                btnSetRecordingDefault.Enabled      = true;
                mnuFavouriteRecordingDevice.Enabled = true;
            }
        }
コード例 #11
0
        private void RefreshNotifyIconItems()
        {
            notifyIconStrip.Items.Clear();
            var playbackCount  = 0;
            var recordingCount = 0;

            checkBoxDisabledDevices.Checked = Program.Settings.ShowDisabledDevices;
            if (Program.Settings.ShowDisabledDevices)
            {
                _deviceStateFilter |= DeviceState.Disabled;
            }

            IEnumerable <IDevice> list = AudioDeviceManager.Controller.GetPlaybackDevices(_deviceStateFilter).ToList();

            foreach (var ad in list)
            {
                if (FavouriteDeviceManager.FavouriteDeviceCount > 0 && !FavouriteDeviceManager.IsFavouriteDevice(ad))
                {
                    continue;
                }

                var item = new ToolStripMenuItem
                {
                    Text    = ad.FullName,
                    Tag     = ad,
                    Checked = false
                };
                if (itemsToToggle.Contains(ad.Id))
                {
                    item.Checked = true;
                }
                notifyIconStrip.Items.Add(item);
                playbackCount++;
            }

            if (playbackCount > 0)
            {
                notifyIconStrip.Items.Add(new ToolStripSeparator());
            }

            list = AudioDeviceManager.Controller.GetCaptureDevices(_deviceStateFilter).ToList();

            foreach (var ad in list)
            {
                if (FavouriteDeviceManager.FavouriteDeviceCount > 0 && !FavouriteDeviceManager.IsFavouriteDevice(ad))
                {
                    continue;
                }

                var item = new ToolStripMenuItem
                {
                    Text    = ad.FullName,
                    Tag     = ad,
                    Checked = false
                };
                if (itemsToToggle.Contains(ad.Id))
                {
                    item.Checked = true;
                }
                notifyIconStrip.Items.Add(item);
                recordingCount++;
            }

            if (recordingCount > 0)
            {
                notifyIconStrip.Items.Add(new ToolStripSeparator());
            }

            notifyIconStrip.Items.Add(preferencesToolStripMenuItem);

            notifyIconStrip.Items.Add(exitToolStripMenuItem);

            var defaultDevice = AudioDeviceManager.Controller.DefaultPlaybackDevice;
            var notifyText    = "Audio Switcher";

            //The maximum length of the noitfy text is 64 characters. This keeps it under
            if (defaultDevice != null)
            {
                var devName = defaultDevice.FullName ?? defaultDevice.Name ?? notifyText;

                if (devName.Length >= 64)
                {
                    notifyText = devName.Substring(0, 60) + "...";
                }
                else
                {
                    notifyText = devName;
                }
            }

            notifyIcon1.Text = notifyText;
        }
コード例 #12
0
        private void RefreshRecordingDevices()
        {
            listBoxRecording.SuspendLayout();
            listBoxRecording.Items.Clear();

            foreach (AudioDevice ad in AudioDeviceManager.RecordingDevices)
            {
                var li = new ListViewItem();
                li.Text = ad.DeviceDescription;
                li.Tag  = ad;
                li.SubItems.Add(new ListViewItem.ListViewSubItem(li, ad.DeviceName));
                try
                {
                    string imageKey = ad.Icon;
                    if (AudioDeviceManager.DefaultRecordingDevice.ID == ad.ID)
                    {
                        li.SubItems.Add(new ListViewItem.ListViewSubItem(li, "Default Device"));
                        li.EnsureVisible();
                    }
                    else if (AudioDeviceManager.DefaultRecordingCommDevice.ID == ad.ID)
                    {
                        li.SubItems.Add(new ListViewItem.ListViewSubItem(li, "Default Communications Device"));
                        li.EnsureVisible();
                    }
                    else
                    {
                        string caption = "";
                        switch (ad.State)
                        {
                        case AudioDeviceState.Active:
                            caption = "Ready";
                            break;

                        case AudioDeviceState.Disabled:
                            caption   = "Disabled";
                            imageKey += "d";
                            break;

                        case AudioDeviceState.Unplugged:
                            caption   = "Not Plugged In";
                            imageKey += "d";
                            break;
                        }
                        li.SubItems.Add(new ListViewItem.ListViewSubItem(li, caption));
                    }

                    string imageMod = "";

                    if (ad.State != AudioDeviceState.Unplugged && FavouriteDeviceManager.IsFavouriteDevice(ad))
                    {
                        imageMod += "f";
                    }

                    if (AudioDeviceManager.DefaultPlaybackDevice.ID == ad.ID ||
                        AudioDeviceManager.DefaultRecordingDevice.ID == ad.ID)
                    {
                        imageMod += "e";
                    }
                    else if (AudioDeviceManager.DefaultPlaybackCommDevice.ID == ad.ID ||
                             AudioDeviceManager.DefaultRecordingCommDevice.ID == ad.ID)
                    {
                        imageMod += "c";
                    }

                    string imageToGen = imageKey + imageMod + ".png";

                    if (!imageList1.Images.Keys.Contains(imageToGen) &&
                        imageList1.Images.IndexOfKey(imageKey + ".png") >= 0)
                    {
                        Image    i = imageList1.Images[imageList1.Images.IndexOfKey(imageKey + ".png")];
                        Graphics g = Graphics.FromImage(i);
                        if (imageMod.Contains("f"))
                        {
                            g.DrawImage(Resources.f, i.Width - 12, 0);
                        }

                        if (imageMod.Contains("c"))
                        {
                            g.DrawImage(Resources.c, i.Width - 12, i.Height - 12);
                        }

                        if (imageMod.Contains("e"))
                        {
                            g.DrawImage(Resources.e, i.Width - 12, i.Height - 12);
                        }

                        imageList1.Images.Add(imageToGen, i);
                    }

                    if (imageList1.Images.IndexOfKey(imageToGen) >= 0)
                    {
                        li.ImageKey = imageToGen;
                    }
                }
                catch
                {
                    li.ImageKey = "unknown.png";
                }

                listBoxRecording.Items.Add(li);
            }

            RefreshNotifyIconItems();
            listBoxRecording.ResumeLayout();
        }
コード例 #13
0
        private void RefreshPlaybackDevices()
        {
            listBoxPlayback.SuspendLayout();
            listBoxPlayback.Items.Clear();
            foreach (var ad in AudioDeviceManager.Controller.GetPlaybackDevices(_deviceStateFilter).ToList())
            {
                var li = new ListViewItem();
                li.Text = ad.Name;
                li.Tag  = ad;
                li.SubItems.Add(new ListViewItem.ListViewSubItem(li, ad.InterfaceName));
                try
                {
                    var imageKey = "";
                    var imageMod = "";

                    if (ICON_MAP.ContainsKey(ad.Icon))
                    {
                        imageKey = ICON_MAP[ad.Icon];
                    }

                    if (ad.IsDefaultDevice)
                    {
                        li.SubItems.Add(new ListViewItem.ListViewSubItem(li, "Default Device"));
                        li.EnsureVisible();
                    }
                    else if (ad.IsDefaultCommunicationsDevice)
                    {
                        li.SubItems.Add(new ListViewItem.ListViewSubItem(li, "Default Communications Device"));
                        li.EnsureVisible();
                    }
                    else
                    {
                        var caption = "";
                        switch (ad.State)
                        {
                        case DeviceState.Active:
                            caption = "Ready";
                            break;

                        case DeviceState.Disabled:
                            caption   = "Disabled";
                            imageMod += "d";
                            break;

                        case DeviceState.Unplugged:
                            caption   = "Not Plugged In";
                            imageMod += "d";
                            break;
                        }
                        li.SubItems.Add(new ListViewItem.ListViewSubItem(li, caption));
                    }

                    if (ad.State != DeviceState.Unplugged && FavouriteDeviceManager.IsFavouriteDevice(ad))
                    {
                        imageMod += "f";
                    }

                    if (ad.IsDefaultDevice)
                    {
                        imageMod += "e";
                    }
                    else if (ad.IsDefaultCommunicationsDevice)
                    {
                        imageMod += "c";
                    }

                    var imageToGen = imageKey + imageMod;

                    if (!imageList1.Images.Keys.Contains(imageToGen))
                    {
                        Image i;
                        using (var icon = ExtractIconFromPath(ad.IconPath))
                        {
                            i = icon.ToBitmap();
                        }

                        if (ad.State == DeviceState.Disabled || ad.State == DeviceState.Unplugged)
                        {
                            i = ImageHelper.SetImageOpacity(i, 0.5F);
                        }

                        using (var g = Graphics.FromImage(i))
                        {
                            if (imageMod.Contains("f"))
                            {
                                g.DrawImage(Resources.f, i.Width - 12, 0);
                            }

                            if (imageMod.Contains("c"))
                            {
                                g.DrawImage(Resources.c, i.Width - 12, i.Height - 12);
                            }

                            if (imageMod.Contains("e"))
                            {
                                g.DrawImage(Resources.e, i.Width - 12, i.Height - 12);
                            }
                        }

                        imageList1.Images.Add(imageToGen, i);
                    }

                    if (imageList1.Images.IndexOfKey(imageToGen) >= 0)
                    {
                        li.ImageKey = imageToGen;
                    }
                }
                catch
                {
                    li.ImageKey = "unknown";
                }

                listBoxPlayback.Items.Add(li);
            }

            RefreshNotifyIconItems();
            listBoxPlayback.ResumeLayout();
        }