예제 #1
0
 public static void MuteProcess(int pId)
 {
     if (!IsMuted(pId))
     {
         VolumeMixer.SetApplicationMute(pId, true);
     }
 }
예제 #2
0
 void MainMixer_OnVolumeChanged(VolumeMixer Sender, int TotalVolume)
 {
     if (GlobalVolumeChanged != null)
     {
         GlobalVolumeChanged(TotalVolume);
     }
 }
예제 #3
0
        public static bool IsMuted(int pId)
        {
            var applicationMute = VolumeMixer.GetApplicationMute(pId);
            var isMuted         = applicationMute != null && (bool)applicationMute;

            return(isMuted);
        }
예제 #4
0
        private static void ToggleMute(HashSet <int> appProcessIdCollection)
        {
            // Get all the processes that are an audio session
            var defaultAudioDevice       = VolumeMixer.GetOutputDevice();
            var sessionManager           = VolumeMixer.GetAudioSessionManager2(defaultAudioDevice);
            var sessions                 = VolumeMixer.GetAudioSessionEnumerator(sessionManager);
            var audioControls            = VolumeMixer.GetAudioContols(sessions);
            var audioProcessIdCollection = audioControls.Keys.ToHashSet();

            // Get all the processes that are audio sessions of the focused application
            var commonProcessIdCollection = appProcessIdCollection.Intersect(audioProcessIdCollection);

            // Change the volume of all the audio processes of the focused application
            foreach (int processId in commonProcessIdCollection)
            {
                var volumeControl = audioControls[processId] as ISimpleAudioVolume;
                var currentMute   = VolumeMixer.GetApplicationMute(volumeControl);
                VolumeMixer.SetApplicationMute(volumeControl, !currentMute ?? false);
                Marshal.ReleaseComObject(volumeControl);
            }

            Marshal.ReleaseComObject(defaultAudioDevice);
            Marshal.ReleaseComObject(sessionManager);
            Marshal.ReleaseComObject(sessions);
        }
예제 #5
0
        private static void WriteCurrentAudioProcessesToFile()
        {
            // Get all the process Ids
            Process[] appProcessCollection   = Process.GetProcesses();
            var       appProcessIdCollection = getProcessIds(appProcessCollection).ToHashSet();

            // Get all the processes that are an audio session
            var defaultAudioDevice       = VolumeMixer.GetOutputDevice();
            var sessionManager           = VolumeMixer.GetAudioSessionManager2(defaultAudioDevice);
            var sessions                 = VolumeMixer.GetAudioSessionEnumerator(sessionManager);
            var audioControls            = VolumeMixer.GetAudioContols(sessions);
            var audioProcessIdCollection = audioControls.Keys.ToHashSet();

            // Get all the processes that are audio sessions of the focused application
            var commonProcessIdCollection = appProcessIdCollection.Intersect(audioProcessIdCollection);

            using (System.IO.StreamWriter file =
                       new System.IO.StreamWriter(@".\AudioProcessNames.txt"))
            {
                foreach (int pid in commonProcessIdCollection)
                {
                    Process p = Process.GetProcessById(pid);
                    file.WriteLine(p.ProcessName);
                }
            }
        }
예제 #6
0
        // Change the focused apps volume by the amount specified
        private static void ChangeAppVolume(HashSet <int> appProcessIdCollection, float volumeAmount)
        {
            // Get all the processes that are an audio session
            var defaultAudioDevice       = VolumeMixer.GetOutputDevice();
            var sessionManager           = VolumeMixer.GetAudioSessionManager2(defaultAudioDevice);
            var sessions                 = VolumeMixer.GetAudioSessionEnumerator(sessionManager);
            var audioControls            = VolumeMixer.GetAudioContols(sessions);
            var audioProcessIdCollection = audioControls.Keys.ToHashSet();

            // Get all the processes that are audio sessions of the focused application
            var commonProcessIdCollection = appProcessIdCollection.Intersect(audioProcessIdCollection);

            // Change the volume of all the audio processes of the focused application
            foreach (int processId in commonProcessIdCollection)
            {
                var volumeControl  = audioControls[processId] as ISimpleAudioVolume;
                var newVolumeLevel = VolumeMixer.GetApplicationVolume(volumeControl) + volumeAmount;
                VolumeMixer.SetApplicationVolume(volumeControl, Math.Min(100, Math.Max(0, newVolumeLevel ?? 30f)));
                Marshal.ReleaseComObject(volumeControl);
            }

            Marshal.ReleaseComObject(defaultAudioDevice);
            Marshal.ReleaseComObject(sessionManager);
            Marshal.ReleaseComObject(sessions);
        }
예제 #7
0
 public static void UnMuteProcess(int pId)
 {
     if (IsMuted(pId))
     {
         VolumeMixer.SetApplicationMute(pId, false);
     }
 }
예제 #8
0
        private void Llkl_OnKeyPressed(object sender, LowLevelKeyboardListener.KeyPressedArgs e)
        {
            if (e.KeyPressed == (int)Keys.Add)
            {
                IntPtr handle = GetForegroundWindow();
                uint   pid;
                GetWindowThreadProcessId(handle, out pid);

                var vol = VolumeMixer.GetApplicationVolume((int)pid);
                if (vol.HasValue)
                {
                    VolumeMixer.SetApplicationVolume((int)pid, (float)vol + 2);
                }
            }
            if (e.KeyPressed == (int)Keys.Subtract)
            {
                IntPtr handle = GetForegroundWindow();
                uint   pid;
                GetWindowThreadProcessId(handle, out pid);

                var vol = VolumeMixer.GetApplicationVolume((int)pid);
                if (vol.HasValue)
                {
                    VolumeMixer.SetApplicationVolume((int)pid, (float)vol - 2);
                }
            }
        }
 private void RefreshActiveApps()
 {
     _runningAudioApps.Clear();
     foreach (var audioProcess in VolumeMixer.GetAudioProcesses())
     {
         _runningAudioApps.Add(audioProcess);
     }
 }
예제 #10
0
 void Mixer_OnVolumeChanged(VolumeMixer Sender, int TotalVolume)
 {
     if (ChannelVolumeChanged != null)
     {
         int idx = TrackMixer.IndexOf(Sender);
         ChannelVolumeChanged(idx, TotalVolume);
     }
 }
        public MainWindow()
        {
            InitializeComponent();

            VolumeMixer.SetApplicationMute("Idle", true);

            _dele = WinEventProc;
            SetWinEventHook(EventSystemForeground, EventSystemForeground, IntPtr.Zero, _dele, 0, 0,
                            WineventOutofcontext);

            Apps.ItemsSource  = _runningAudioApps;
            Muted.ItemsSource = MutedWindowStorage.Instance.Binding();
            RefreshActiveApps();
        }
        /// <summary>
        /// Called whenever the active window changes
        /// </summary>
        private void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject,
                                  int idChild,
                                  uint dwEventThread, uint dwmsEventTime)
        {
            // Refresh List of Active Audio Apps
            RefreshActiveApps();

            // Mute apps
            var focused = WindowUtil.GetActiveProcessName();

            foreach (var app in MutedWindowStorage.Instance.Binding())
            {
                VolumeMixer.SetApplicationMute(app, !app.Equals(focused));
            }
        }
예제 #13
0
 void InitVolume(ref VolumeMixer VMix, int Volume)
 {
     VMix.Volume        = Volume % 100;
     VMix.Magnification = Volume / 100;
     if (VMix.Volume == 0)
     {
         if (VMix.Magnification > 0)
         {
             VMix.Magnification = VMix.Magnification - 1;
             VMix.Volume        = 100;
         }
         else
         {
             VMix.Mute = true;
         }
     }
 }
 private async Task MuteCodIntermittently(Process process)
 {
     while (!StopMuting)
     {
         if (VolumeMixer.GetApplicationVolume(process.Id) == 100f)
         {
             if (codLaunchedTime == default)
             {
                 codLaunchedTime = DateTime.Now;
                 DelayedUnmute();
             }
         }
         VolumeMixer.SetApplicationMute(process.Id, true);
         await Task.Delay(50);
     }
     codLaunchedTime = default;
     VolumeMixer.SetApplicationMute(process.Id, false);
 }
예제 #15
0
        private float?GetVolume(IntPtr hWnd)
        {
            hWnd = FindWindow("MozillaWindowClass", null);
            if (hWnd == IntPtr.Zero)
            {
                return(null);
            }

            uint pID;

            GetWindowThreadProcessId(hWnd, out pID);
            if (pID == 0)
            {
                return(null);
            }

            return(VolumeMixer.GetApplicationVolume((int)pID));
        }
예제 #16
0
        private void SetVolume(IntPtr hWnd, float volume)
        {
            hWnd = FindWindow("MozillaWindowClass", null);
            if (hWnd == IntPtr.Zero)
            {
                return;
            }

            uint pID;

            GetWindowThreadProcessId(hWnd, out pID);
            if (pID == 0)
            {
                return;
            }

            VolumeMixer.SetApplicationVolume((int)pID, volume);
        }
예제 #17
0
        public void UpdateWin()
        {
            //Update全局
            MainMixer = new VolumeMixer();
            TrackMixer.Clear();

            MainMixer.TrackName = "全局";
            InitVolume(ref MainMixer, ProjectBinder.AllocedSource.GlobalVolume);
            MainMixer.OnVolumeChanged += MainMixer_OnVolumeChanged;

            for (int i = 0; i < ProjectBinder.AllocedSource.TrackerList.Count; i++)
            {
                VolumeMixer cmixer = new VolumeMixer();
                cmixer.Volume           = (int)(ProjectBinder.AllocedSource.TrackerList[i].getVolume() * 100.0);
                cmixer.TrackName        = "[T]" + ProjectBinder.AllocedSource.TrackerList[i].getName();
                cmixer.OnVolumeChanged += Mixer_OnVolumeChanged;
                if (cmixer.TrackName == "[T]")
                {
                    cmixer.TrackName = "[T]#" + TrackMixer.Count;
                }
                TrackMixer.Add(cmixer);
            }

            for (int i = 0; i < ProjectBinder.AllocedSource.BackerList.Count; i++)
            {
                VolumeMixer cmixer = new VolumeMixer();
                cmixer.Volume           = (int)(ProjectBinder.AllocedSource.BackerList[i].getVolume() * 100.0);
                cmixer.TrackName        = "[B]" + ProjectBinder.AllocedSource.BackerList[i].getName();
                cmixer.OnVolumeChanged += Mixer_OnVolumeChanged;
                if (cmixer.TrackName == "[B]")
                {
                    cmixer.TrackName = "[B]#" + TrackMixer.Count;
                }
                TrackMixer.Add(cmixer);
            }

            flowLayoutPanelMain.Controls.Clear();
            flowLayoutPanelMain.Controls.Add(MainMixer);

            flowLayoutPanelTrack.Controls.Clear();
            flowLayoutPanelTrack.Controls.AddRange(TrackMixer.ToArray());
        }
예제 #18
0
        private bool FadingVolumeGauge()
        {
            if (isAwaitVolumeGaugeRunning)
            {
                _volumeGauge.Abort();
                isAwaitVolumeGaugeRunning = false;
            }

            if (VolumeMixer.Visibility == Visibility.Collapsed)
            {
                VolumeMixer.Visibility = Visibility.Visible;
                DoubleAnimation fadeIn = new DoubleAnimation(0, 1, TimeSpan.FromSeconds(0.1), FillBehavior.Stop);
                fadeIn.Completed += (object senderr, EventArgs ee) => { VolumeMixer.Opacity = 1; };
                VolumeMixer.BeginAnimation(OpacityProperty, fadeIn);
                CountDownFadeOutVolume();
                _volumeGauge.Start();
                isAwaitVolumeGaugeRunning = true;
                return(false);
            }

            return(true);
        }
예제 #19
0
        private void CountDownFadeOutVolume()
        {
            try
            {
                _volumeGauge = new Thread(() =>
                {
                    Thread.Sleep(1500);

                    Dispatcher.Invoke(() =>
                    {
                        DoubleAnimation fadeOut = new DoubleAnimation(1, 0, TimeSpan.FromSeconds(0.1), FillBehavior.Stop);
                        fadeOut.Completed      += (object senderr, EventArgs ee) =>
                        {
                            VolumeMixer.Opacity    = 0;
                            VolumeMixer.Visibility = Visibility.Collapsed;
                        };
                        VolumeMixer.BeginAnimation(OpacityProperty, fadeOut);
                        isAwaitVolumeGaugeRunning = false;
                    });
                });
            }
            catch { }
        }
        private async Task StartTableAsync(int mainThread)
        {
            logger.Info($"{RunMode.ToString()}: Starting table: {CurrentTable.Name}");
            RunMode = Mode.SystemRunning;
            logger.Trace($"Setting Mode to {RunMode.ToString()}");

            //Play Launch Music
            LMusicPlayer.Open(CurrentTable.LMusic);
            LMusicPlayer.Play();

            var system = Data.FindSystem(CurrentTable);                     // get system to launch
            var proc   = PinballFunctions.StartTable(system, CurrentTable); // launch system



            Stopwatch watchdog = new Stopwatch();

            watchdog.Reset();
            watchdog.Start();


            //Wait for process to start (done this way for steam games)
            logger.Info($"Starting Game Process, Name: {system.Name}");
            //proc.WaitForInputIdle();
            await Task.Run(() => { while (Process.GetProcessesByName(system.Name).Length <= 0)
                                   {
                                       ;
                                   }
                           });

            var game = Process.GetProcessesByName(system.Name).First();

            logger.Info($"Game Process Found, Handle: {game.Id}");

            //keep hiding while window is starting
            await Task.Run(() =>
            {
                do
                {
                    //WindowControl.HideAllProcessWindows(system.Name, true);
                } while (WindowControl.FindProcessWindow(system.Name, system.WindowName) == IntPtr.Zero);
                //WindowControl.HideAllProcessWindows(system.Name);
            });

            var windowHandle = WindowControl.FindProcessWindow(system.Name, system.WindowName);

            WindowControl.HideWindow(windowHandle, true);
            logger.Info($"Game Window Found, Process: {system.Name}, Name: {system.WindowName}, Handle: {windowHandle}");



            //Try and Mute System
            watchdog.Restart();
            logger.Info("Muting System");
            await Task.Run(() =>
            {
                while (VolumeMixer.GetApplicationMute(game.Id) != true)
                {
                    //Console.WriteLine("Trying to Mute");
                    VolumeMixer.SetApplicationMute(game.Id, true);
                    //WindowControl.SetFocus(ProgramName);
                    if (watchdog.ElapsedMilliseconds > 10000)
                    {
                        logger.Warn($"Can't Mute System, Process ID: {game.Id}");
                        break;
                    }
                }
            });



            //Wait for Game to load
            await Task.Run(() => Task.Delay(system.WaitTime * 1000));

            BGMusicPlayer.Pause();

            //Unmute
            watchdog.Restart();
            logger.Info("Unmuting System");
            while (VolumeMixer.GetApplicationMute(game.Id) != false)
            {
                //Console.WriteLine("Trying to Unmute");
                VolumeMixer.SetApplicationMute(game.Id, false);
                //WindowControl.SetFocus(ProgramName);
                if (watchdog.ElapsedMilliseconds > 10000)
                {
                    logger.Warn($"Can't Unmute System, Process ID: {game.Id}");
                    break;
                }
            }


            //Show Game Window
            WindowControl.ShowWindow(windowHandle, true);

            //Focus GAME
            WindowControl.SetFocusForeground(windowHandle, true);

            //Hide Selected Windows
            logger.Trace("Setting Window Visibility");
            BackglassWindow.Visibility = CurrentTable.ShowBackglass ? Visibility.Visible : Visibility.Hidden;
            DMDWindow.Visibility       = CurrentTable.ShowDMD ? Visibility.Visible : Visibility.Hidden;
            PlayfieldVisibility        = Visibility.Hidden;
        }
예제 #21
0
        public MainForm(bool devMode)
        {
            this.mp   = new MusicPlayer.MusicPlayer();
            this.loop = false;
            this.musicTrackbarScrolling = false;
            this.Running           = true;
            this.lastMouseX        = 0;
            trackNameToPathIndices = null;
            InitializeComponent();
            this.FormBorderStyle = FormBorderStyle.FixedSingle;
            this.MaximizeBox     = false;
            if (!devMode)
            {
                cmdShowGrapher.Hide();
                cmdToggleMatcher.Hide();
                cmdSaveCsv.Hide();
                cmdViewDB.Hide();
            }
            onPlayingChange          += playingChanged;
            onSongComplete           += songComplete;
            AutoPick                  = true;
            seekLabel.Text            = "";
            txtMusicProgress.Text     = "";
            updateMusicTrackbarThread = new Thread(new ThreadStart(updateMusicTrackbar));

            grapherForm = new Grapher(this);

            vm = new VolumeMixer();
            vm.OnPeakChanged += onPeakChanged;

            loweredVolume = false;
            dbAdapter     = new DatabaseAdapter(ConfigurationManager.ConnectionStrings["GamingMusicPlayer.Properties.Settings.SongsDBConnectionString"].ConnectionString);
            matcherForm   = new SongMatcher(this, dbAdapter);
            settingsForm  = new SettingsForm(this);
            overlayForm   = new OverlayForm(this, 200, 0);
            driveScanner  = null;

            ToolTip vpToggleTooltip = new ToolTip();

            vpToggleTooltip.ToolTipIcon  = ToolTipIcon.None;
            vpToggleTooltip.IsBalloon    = true;
            vpToggleTooltip.ShowAlways   = true;
            vpToggleTooltip.AutoPopDelay = 20000;
            vpToggleTooltip.SetToolTip(cmdVp, "Voice Prioritization Feature");

            ToolTip songMatchToggleTooltip = new ToolTip();

            songMatchToggleTooltip.ToolTipIcon  = ToolTipIcon.None;
            songMatchToggleTooltip.IsBalloon    = true;
            songMatchToggleTooltip.ShowAlways   = true;
            songMatchToggleTooltip.AutoPopDelay = 20000;
            songMatchToggleTooltip.SetToolTip(cmdSongMatchToggle, "Automatic Song Matching Feature");


            dbListBox.SelectionMode = SelectionMode.MultiExtended;
            songsToAdd         = new List <Track>();
            addSongsToDbThread = new Thread(delegate()
            {
                SignalProcessing.SignalProcessor sp = new SignalProcessing.SignalProcessor();
                while (true)
                {
                    int c = 0;
                    lock (songsToAdd)
                    {
                        c = songsToAdd.Count;
                    }
                    while (c > 0)
                    {
                        Track t = songsToAdd[0];
                        sp.ComputeBPM(t.Data, (t.Length / 1000), false, false);
                        t.BPM = sp.BPM;
                        sp.computeTimbre(t.Data, t.Length / 1000, false);
                        t.ZCR = sp.ZCR;
                        t.SpectralIrregularity = sp.SpectralIrregularity;
                        lock (dbAdapter)
                        {
                            dbAdapter.addTrack(t);
                        }
                        updateSettings(true);
                        sp.clearMemory();
                        lock (songsToAdd)
                        {
                            songsToAdd.RemoveAt(0);
                            c = songsToAdd.Count;
                        }
                        matcherForm.updateTrackList(mp.LoadedPlaylist.TrackList);
                    }
                    Thread.Sleep(1000);
                }
            });
            addSongsToDbThread.Start();
        }
예제 #22
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");
            });
        }
예제 #23
0
        static void Main(string[] args)
        {
            if (args.Length < 1)
            {
                return;
            }

            var hWnd = FindWindow("SpotifyMainWindow", "Spotify");

            if (hWnd == IntPtr.Zero)
            {
                hWnd = new IntPtr(int.Parse(args[0]));
            }

            uint pID;

            GetWindowThreadProcessId(hWnd, out pID);
            if (pID == 0)
            {
                return;
            }

            Console.WriteLine("appid:" + hWnd + ";");
            Console.WriteLine("userVolume:" + VolumeMixer.GetApplicationVolume(pID) + ";");

            if (args.Length > 1)
            {
                if (args.Length > 2)
                {
                    if (args[2] == "1")
                    {
                        Console.WriteLine("args[0]:" + args[0] + ";args[1]:" + args[1] + "args[2]:" + args[2] + ";");

                        var curVol = (int)VolumeMixer.GetApplicationVolume(pID);
                        var diff   = curVol - int.Parse(args[1]);
                        for (int i = 1; i <= diff; i++)
                        {
                            VolumeMixer.SetApplicationVolume(pID, curVol - i);
                            System.Threading.Thread.Sleep(10);
                        }
                    }
                    else if (args[2] == "2")
                    {
                        Console.WriteLine("args[0]:" + args[0] + ";args[1]:" + args[1] + "args[2]:" + args[2] + ";");

                        var curVol = (int)VolumeMixer.GetApplicationVolume(pID);
                        var diff   = curVol + int.Parse(args[1]);
                        for (int i = 1; i <= diff; i++)
                        {
                            VolumeMixer.SetApplicationVolume(pID, curVol + i);
                            System.Threading.Thread.Sleep(10);
                        }
                    }
                }
                else
                {
                    VolumeMixer.SetApplicationVolume(pID, float.Parse(args[1]));
                    Console.WriteLine("args[0]:" + args[0] + ";args[1]:" + args[1]);
                }

                Console.WriteLine("appVolume:" + VolumeMixer.GetApplicationVolume(pID) + ";");
            }
            else
            {
                Console.WriteLine("args[0]:" + args[0] + ";");
            }
        }