Exemplo n.º 1
0
        /**
         * Resets all reduced applications to the stored volume level
         */
        public void RemoveReduction()
        {
            if (!this._ReductionApplied)
            {
                return;
            }

            this._WriteIfDebugging("Restoring volume levels");
            foreach (AppVolume appVolume in this.GetStoredVolumeLevels())
            {
                if (!this._IsWhitelisted(appVolume))
                {
                    VolumeMixer.SetApplicationVolume(appVolume.ProcessID, appVolume.Volume);
                }
            }

            this._ReductionApplied = false;
        }
Exemplo n.º 2
0
        /**
         * Stores the current volume level of all applications and reduces their volumes by the reduction percent
         */
        public void ApplyReduction()
        {
            this._LastReductionAttemptMicroTime = DateTimeOffset.Now.ToUnixTimeMilliseconds();

            if (this._ReductionApplied)
            {
                this._WriteIfDebugging("Already reduced volume levels");
                return;
            }

            this._ReductionApplied = true;
            this.StoreCurrentVolumeLevels();
            this._WriteIfDebugging("Reducing volume levels");

            foreach (AppVolume appVolume in this.GetStoredVolumeLevels())
            {
                if (!this._IsWhitelisted(appVolume))
                {
                    double newVolume = appVolume.Volume - (appVolume.Volume * this._Reduction);
                    this._WriteIfDebugging("Setting " + appVolume.Name + " from " + appVolume.Volume + " to " + newVolume);

                    if (!this._Debug)
                    {
                        VolumeMixer.SetApplicationVolume(appVolume.ProcessID, (float)newVolume);
                    }
                }
            }

            //Wait for X to reset the timers
            var resetTimer = new Timer();

            resetTimer.Interval  = 100;
            resetTimer.AutoReset = true;
            resetTimer.Elapsed  += (object sender, ElapsedEventArgs e) =>
            {
                if (DateTimeOffset.Now.ToUnixTimeMilliseconds() - this._LastReductionAttemptMicroTime >= 1000 * this._RestoreVolumeAfter)
                {
                    this.RemoveReduction();
                    resetTimer.Stop();
                    resetTimer.Dispose();
                }
            };
            resetTimer.Start();
        }