示例#1
0
        public static void Main()
        {
            using (MMDeviceEnumerator enumerator = new MMDeviceEnumerator())
                using (MMDevice device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console))
                    using (AudioEndpointVolume endpointVolume = AudioEndpointVolume.FromDevice(device))
                        using (AudioSessionManager2 sessionManager2 = AudioSessionManager2.FromMMDevice(device))
                            using (AudioSessionEnumerator sessionEnumerator = sessionManager2.GetSessionEnumerator())
                            {
                                Console.WriteLine("Default Render Device: " + device.FriendlyName);
                                Console.WriteLine("Master Volume Scalar: " + endpointVolume.GetMasterVolumeLevelScalar());
                                Console.WriteLine("\nGetting audio sessions...");

                                foreach (AudioSessionControl sessionControl in sessionEnumerator)
                                {
                                    PrintSessionName(sessionControl);
                                    Console.WriteLine("\t- State: " + sessionControl.SessionState.ToString());

                                    using (SimpleAudioVolume sessionSimpleVolume = sessionControl.QueryInterface <SimpleAudioVolume>())
                                    {
                                        Console.WriteLine("\t- Volume: " + sessionSimpleVolume.MasterVolume);
                                        sessionSimpleVolume.MasterVolume = 1.0f;
                                    }

                                    sessionControl.Dispose();
                                }
                            }
            Console.WriteLine("\nVolumes reset!");
            Console.ReadLine();
        }
        public override void Update()
        {
            if (!Settings.IsEnabled)
            {
                return;
            }

            var dataModel = (OverlayProfileDataModel)DataModel;

            dataModel.Keyboard.NumLock    = ((ushort)GeneralProfileModel.GetKeyState(0x90) & 0xffff) != 0;
            dataModel.Keyboard.CapsLock   = ((ushort)GeneralProfileModel.GetKeyState(0x14) & 0xffff) != 0;
            dataModel.Keyboard.ScrollLock = ((ushort)GeneralProfileModel.GetKeyState(0x91) & 0xffff) != 0;

            if (_endPointVolume != null)
            {
                dataModel.Audio.Volume = _endPointVolume.GetMasterVolumeLevelScalar();
            }
        }
 public void Update(AudioEndpointVolume audioEndpointVolume)
 {
     this.decibels = audioEndpointVolume.GetMasterVolumeLevel();
     this.scalar   = audioEndpointVolume.GetMasterVolumeLevelScalar();
 }
示例#4
0
        /// <summary>
        /// Creates the mixer channels - levels, slider, channel name, scale
        /// </summary>
        public static void CreateMixerChannels(MMDevice device)
        {
            //create arrays
            m_ChannelNames = new Label[10];
            m_Levels       = new Grid[10];
            m_LevelParents = new Grid[10];
            m_Sliders      = new Slider[10];
            m_Icons        = new System.Windows.Shapes.Rectangle[9];
            m_PeakMeters   = new AudioMeterInformation[10];

            //create mixer sliders
            for (int i = 0; i < 10; i++)
            {
                //main grid
                Grid grid = new Grid()
                {
                    Margin = Utils.ZeroMargin
                };

                //make grid child of mixer grid
                MainWindow.Instance.MixerGrid.Children.Add(grid);

                //skip the master channel
                if (i != 0)
                {
                    m_Icons[i - 1] = new System.Windows.Shapes.Rectangle()
                    {
                        Width               = 30,
                        Height              = 30,
                        VerticalAlignment   = VerticalAlignment.Top,
                        HorizontalAlignment = HorizontalAlignment.Center,
                        Margin              = Utils.ZeroMargin
                    };

                    grid.Children.Add(m_Icons[i - 1]);
                }

                //label
                Label label = new Label()
                {
                    Content                    = "",
                    Foreground                 = new SolidColorBrush(ColorPalette.Accent),
                    FontFamily                 = new System.Windows.Media.FontFamily("Bahnschrift Bold"),
                    HorizontalAlignment        = HorizontalAlignment.Stretch,
                    HorizontalContentAlignment = HorizontalAlignment.Center,
                    VerticalAlignment          = VerticalAlignment.Top,
                    Margin = Utils.ZeroMargin
                };

                //add to array
                m_ChannelNames[i] = label;

                //make label a child of grid
                grid.Children.Add(label);

                //add to array
                m_LevelParents[i] = grid;

                //slider
                Slider slider = new Slider()
                {
                    HorizontalAlignment = HorizontalAlignment.Center,
                    //modify spacing on master channel
                    Margin = new Thickness()
                    {
                        Left = -32, Top = 36, Right = 0, Bottom = 16
                    },
                    VerticalAlignment = VerticalAlignment.Stretch,
                    Background        = null,
                    Width             = 22,
                    Orientation       = Orientation.Vertical,
                    Style             = (Style)Application.Current.Resources["MixerSlider"],
                    Maximum           = 100,
                    Value             = 70
                };

                //add to array
                m_Sliders[i] = slider;

                //setup channel volume
                if (i == 0)
                {
                    //master channel
                    m_MasterVolume     = AudioEndpointVolume.FromDevice(device);
                    m_Sliders[0].Value = m_MasterVolume.GetMasterVolumeLevelScalar() * 100f;

                    //master peak meter
                    m_PeakMeters[0] = AudioMeterInformation.FromDevice(device);
                }

                //value changed event
                int index = i;
                slider.ValueChanged += (sender, e) => Slider_ValueChanged(sender, e, i == 0, index);

                //make slider child of grid
                grid.Children.Add(slider);

                //levels
                //make a parent object
                m_InitialMargin = new Thickness()
                {
                    Left = 18, Top = 36, Right = 0, Bottom = 16
                };

                Grid level = new Grid()
                {
                    Margin = m_InitialMargin,
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Stretch,
                    Width = 15
                };

                //make levels child of grid
                grid.Children.Add(level);

                //add to array
                m_Levels[i] = level;

                //levels shape
                System.Windows.Shapes.Rectangle bg = new System.Windows.Shapes.Rectangle()
                {
                    Fill = new SolidColorBrush(ColorPalette.Gray),
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Stretch,
                    Margin = Utils.ZeroMargin
                };

                System.Windows.Shapes.Rectangle line = new System.Windows.Shapes.Rectangle()
                {
                    Fill = new SolidColorBrush(ColorPalette.Accent),
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Top,
                    Margin = Utils.ZeroMargin,
                    Height = 2
                };

                //make shape child of levels grid
                level.Children.Add(bg);
                level.Children.Add(line);

                //scale grid
                UniformGrid scaleGrid = new UniformGrid()
                {
                    Columns = 1,
                    Rows    = 10,
                    //modify spacing on the master channel
                    Margin = new Thickness()
                    {
                        Left = 45, Top = 36, Right = 0, Bottom = 20
                    },
                    HorizontalAlignment = HorizontalAlignment.Center,
                    VerticalAlignment   = VerticalAlignment.Stretch,
                    Width = 5
                };

                //make scaleGrid child of grid
                grid.Children.Add(scaleGrid);

                //scale ticks
                for (int x = 0; x < 10; x++)
                {
                    System.Windows.Shapes.Rectangle tick = new System.Windows.Shapes.Rectangle()
                    {
                        Fill = new SolidColorBrush(ColorPalette.Gray),
                        HorizontalAlignment = HorizontalAlignment.Stretch,
                        VerticalAlignment   = VerticalAlignment.Center,
                        Margin = Utils.ZeroMargin,
                        Height = 2
                    };

                    //make ticks child of scale grid
                    scaleGrid.Children.Add(tick);
                }
            }


            //init channel volumes
            GetChannelVolumes();

            //set first channel
            SetChannelName(0, "Master");

            m_HasStarted = true;
        }