Пример #1
0
        public AudioBalancer()
        {
            _inputHook = Hook.GlobalEvents();

            Console.WriteLine("Welcome!\n");
            Console.WriteLine("The following applications were found via your default playback device: ");

            var entries = VolumeMixer.GetPresentableMixerEntries();

            for (var i = 0; i < entries.Length; i++)
            {
                Console.WriteLine(i + " - " + entries[i].Id);
            }

            Console.WriteLine(
                "\nPlease enter the number of the application you would like to balance against the rest.");

            int?choice = null;

            while (choice == null)
            {
                var userInput = Console.ReadLine();

                try
                {
                    choice = entries.ToList().IndexOf(entries[int.Parse(userInput)]);
                }
                catch (Exception)
                {
                    Console.WriteLine("Sorry, your input did not match a device. Please try again.");
                }
            }

            Console.Clear();

            var selected          = entries[choice.Value];
            var selectedShortName = selected.Id.Split('\\')[1];

            entries = VolumeMixer.GetDefaultMixerEntries();

            var currentBalance = new ReactiveProperty <int>();

            _inputHook.KeyDown += (sender, args) =>
            {
                if (args.KeyCode == Keys.F10 && args.Control && currentBalance.Value < 50)
                {
                    currentBalance.Value++;
                }

                if (args.KeyCode == Keys.F11 && args.Control && currentBalance.Value > -50)
                {
                    currentBalance.Value--;
                }
            };

            currentBalance.Subscribe(i =>
            {
                VolumeMixer.SetApplicationVolume(selected.PId, 50 + i);

                foreach (var entry in entries)
                {
                    if (entry.PId == selected.PId)
                    {
                        continue;
                    }

                    VolumeMixer.SetApplicationVolume(entry.PId, 50 - i);
                }

                Console.Clear();
                Console.WriteLine("Balancing!");
                Console.WriteLine("\n");
                Console.WriteLine("Press ctrl-f10 to move focus towards " + selectedShortName);
                Console.WriteLine("Press ctrl-f11 to move focus towards the non selected apps");
                Console.WriteLine("\n");
                Console.WriteLine(selectedShortName + ": " + (50 + i) + "\t" + "Other apps: " + (50 - i));
                Console.WriteLine("\n");
                Console.WriteLine("Press ctrl-c or just close the window to exit");
            });
        }