Exemplo n.º 1
1
        public MainForm()
        {
            library = Library.Load();
            if (library == null)
            {
                library = new Library();
                library.Save();
            }
            library.LibraryChanged += library_LibraryChanged;

            settings = Settings.Load(SETTINGSPATH);
            if (settings == null)
                settings = new Settings();

            MMDeviceEnumerator enumerator = new MMDeviceEnumerator();
            defaultAudioDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
            this.musicPlayer.OpenCompleted += equalizerSettings_ShouldSet;

            this.equalizerSettings = EqualizerSettings.Load(EQUALIZERPATH);
            if (this.equalizerSettings == null)
            {
                this.equalizerSettings = new EqualizerSettings();
                this.equalizerSettings.Save(EQUALIZERPATH);
            }
            this.equalizerSettings.ValueChanged += equalizerSettings_ShouldSet;

            SetUpGlobalHotkeys();

            InitializeComponent();
        }
Exemplo n.º 2
1
        private void RefreshDevices()
        {
            deviceList.Items.Clear();

            using (var deviceEnumerator = new MMDeviceEnumerator())
            using (var deviceCollection = deviceEnumerator.EnumAudioEndpoints(
                CaptureMode == CaptureMode.Capture ? DataFlow.Capture : DataFlow.Render, DeviceState.Active))
            {
                foreach (var device in deviceCollection)
                {
                    var deviceFormat = WaveFormatFromBlob(device.PropertyStore[
                        new PropertyKey(new Guid(0xf19f064d, 0x82c, 0x4e27, 0xbc, 0x73, 0x68, 0x82, 0xa1, 0xbb, 0x8e, 0x4c), 0)].BlobValue);

                    var item = new ListViewItem(device.FriendlyName) {Tag = device};
                    item.SubItems.Add(deviceFormat.Channels.ToString(CultureInfo.InvariantCulture));

                    deviceList.Items.Add(item);
                }
            }
        }
Exemplo n.º 3
1
 private static MMDevice GetDefaultDevice()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         try
         {
             return enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
         }
         catch (CoreAudioAPIException)
         {
             return null;
         }
     }
 }
 public void InitManager()
 {
     deviceEnum = new MMDeviceEnumerator();
     deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
     device = deviceEnum.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
     sessionManager = AudioSessionManager2.FromMMDevice(device);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Generates a collection of audio endpoint devices that meet the specified criteria.
 /// </summary>
 /// <param name="dataFlow">The data-flow direction for the endpoint device.</param>
 /// <param name="stateMask">The state or states of the endpoints that are to be included in the collection.</param>
 /// <returns><see cref="MMDeviceCollection"/> which contains the enumerated devices.</returns>
 public static MMDeviceCollection EnumerateDevices(DataFlow dataFlow, DeviceState stateMask)
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         return enumerator.EnumAudioEndpoints(dataFlow, stateMask);
     }
 }
Exemplo n.º 6
0
 public IEnumerable<MMDevice> EnumerateWasapiDevices()
 {
     using (MMDeviceEnumerator enumerator = new MMDeviceEnumerator())
     {
         return enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active);
     }
 }
Exemplo n.º 7
0
        public MMNotificationClient(MMDeviceEnumerator enumerator)
        {
            if (enumerator == null)
                throw new ArgumentNullException("enumerator");

            Initialize(enumerator);
        }
Exemplo n.º 8
0
 public MMNotificationClient()
 {
     using (var e = new MMDeviceEnumerator())
     {
         Initialize(e);
     }
 }
Exemplo n.º 9
0
 public static MMDevice GetDefaultSoundDevice()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         return enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
     }
 }
Exemplo n.º 10
0
 /// <summary>
 /// Returns the default audio endpoint for the specified data-flow direction and role.
 /// </summary>
 /// <param name="dataFlow">The data-flow direction for the endpoint device.</param>
 /// <param name="role">The role of the endpoint device.</param>
 /// <returns><see cref="MMDevice"/> instance of the endpoint object for the default audio endpoint device.</returns>
 public static MMDevice DefaultAudioEndpoint(DataFlow dataFlow, Role role)
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         return enumerator.GetDefaultAudioEndpoint(dataFlow, role);
     }
 }
        private static AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
        {
            using CSCore.CoreAudioAPI.MMDeviceEnumerator enumerator = new CSCore.CoreAudioAPI.MMDeviceEnumerator();
            using var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia);
            var sessionManager = AudioSessionManager2.FromMMDevice(device);

            return(sessionManager);
        }
Exemplo n.º 12
0
 public CsCoreEngine()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console);
     }
     endpointVolume = AudioEndpointVolume.FromDevice(device);
 }
 private AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia))
         {
             var sessionManager = AudioSessionManager2.FromMMDevice(device);
             return sessionManager;
         }
     }
 }
Exemplo n.º 14
0
        public void CanAccessPropertyStore()
        {
            using (var enumerator = new MMDeviceEnumerator())
            using (var collection = enumerator.EnumAudioEndpoints(DataFlow.All, DeviceState.All))
            {
                Utils.DumpCollection(collection);

                enumerator.Dispose();
                collection.Dispose();
            }
        }
Exemplo n.º 15
0
 public void CanCreateDeviceNotificationEvent()
 {
     using (var enumerator = new MMDeviceEnumerator())
     using (var notification = new MMNotificationClient(enumerator))
     {
         notification.DefaultDeviceChanged += (s, e) => { };
         notification.DeviceAdded += (s, e) => { };
         notification.DevicePropertyChanged += (s, e) => { };
         notification.DeviceRemoved += (s, e) => { };
         notification.DeviceStateChanged += (s, e) => { };
     }
 }
Exemplo n.º 16
0
 public static AudioClient CreateDefaultRenderClient()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console))
         {
             var audioClient = AudioClient.FromMMDevice(device);
             Assert.IsNotNull(audioClient);
             return audioClient;
         }
     }
 }
Exemplo n.º 17
0
        public MusicPlayer()
        {
            using (var enumerator = new MMDeviceEnumerator())
            {
                device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);

                using (var client = AudioClient.FromMMDevice(device))
                {
                    client.Initialize(AudioClientShareMode.Shared,
                        AudioClientStreamFlags.None, 1000, 0, client.GetMixFormat(), Guid.Empty);
                }
            }
        }
Exemplo n.º 18
0
        public void CanEnumerateCaptureDevices()
        {
            using (var enumerator = new MMDeviceEnumerator())
            using (var collection = enumerator.EnumAudioEndpoints(DataFlow.Capture, DeviceState.All))
            {
                foreach (var item in collection)
                {
                    Debug.WriteLine(item.ToString());
                    item.Dispose();
                }

                enumerator.Dispose();
                collection.Dispose();
            }
        }
Exemplo n.º 19
0
 public void CanCreateAudioSessionManager2()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var collection = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
         {
             foreach (var device in collection)
             {
                 using (var sessionManager = AudioSessionManager2.FromMMDevice(device))
                 {
                     Assert.IsNotNull(sessionManager);
                 }
             }
         }
     }
 }
Exemplo n.º 20
0
        /// <summary>
        /// Tries the get device associated with the <see cref="DeviceId"/>.
        /// </summary>
        /// <param name="device">The device associated with the <see cref="DeviceId"/>. If the return value is <c>false</c>, the <paramref name="device"/> will be null.</param>
        /// <returns><c>true</c> if the associated device be successfully retrieved; false otherwise.</returns>
        public bool TryGetDevice(out MMDevice device)
        {
            try
            {
                using (var deviceEnumerator = new MMDeviceEnumerator())
                {
                    device = deviceEnumerator.GetDevice(DeviceId);
                }
                return true;
            }
            catch (Exception)
            {
                device = null;
            }

            return false;
        }
Exemplo n.º 21
0
 public static float GetSpotifyInstaVolume()
 {
     using (var enumerator = new CSCore.CoreAudioAPI.MMDeviceEnumerator())
         using (var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia))
             using (var sessionManager = AudioSessionManager2.FromMMDevice(device))
                 using (var sessionEnumerator = sessionManager.GetSessionEnumerator())
                 {
                     foreach (var session in sessionEnumerator)
                     {
                         using (var audioMeterInformation = session.QueryInterface <AudioMeterInformation>())
                             using (var audioIdInformation = session.QueryInterface <AudioSessionControl2>())
                             {
                                 if (audioIdInformation.SessionIdentifier.Contains("Spotify"))
                                 {
                                     return(audioMeterInformation.GetPeakValue());
                                 }
                             }
                     }
                 }
     return(float.NaN);
 }
Exemplo n.º 22
0
 public void GetDefaultRenderEndpoint()
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var device = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Console))
         {
             Debug.WriteLine(device.ToString());
         }
     }
 }
Exemplo n.º 23
0
 private void Initialize(MMDeviceEnumerator enumerator)
 {
     int result = enumerator.RegisterEndpointNotificationCallbackNative(this);
     CoreAudioAPIException.Try(result, "IMMDeviceEnumerator", "RegisterEndpointNotificationCallback");
 }
Exemplo n.º 24
0
        private void Initialize(MMDeviceEnumerator enumerator)
        {
            int result = enumerator.RegisterEndpointNotificationCallbackNative(this);

            CoreAudioAPIException.Try(result, "IMMDeviceEnumerator", "RegisterEndpointNotificationCallback");
        }
Exemplo n.º 25
0
        private void LoadSoundOutModes()
        {
            SoundOutModes.Clear();
            using (var enumerator = new MMDeviceEnumerator())
            {
                MMDevice defaultDevice;
                try
                {
                    defaultDevice = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
                }
                catch (CoreAudioAPIException)
                {
                    defaultDevice = null;
                }

                if (WasapiOut.IsSupportedOnCurrentPlatform)
                {
                    var wasApiMode = new SoundOutMode("WASAPI", SoundOutType.WasApi, GetWasApiSoundOutDeviceById, GetWasApiSoundOut, new SoundOutDevice("Windows Default", WindowsDefaultId, SoundOutType.WasApi));

                    using (var devices = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
                    {
                        foreach (var device in devices.Select(x => new SoundOutDevice(x.FriendlyName, x.DeviceID, SoundOutType.WasApi, defaultDevice != null && defaultDevice.DeviceID == x.DeviceID)))
                            wasApiMode.Devices.Add(device);
                    }

                    UpdateWindowsDefault(wasApiMode);
                    SoundOutModes.Add(wasApiMode);
                }

                var directSoundMode = new SoundOutMode("DirectSound", SoundOutType.DirectSound, GetDirectSoundOutDeviceById, GetDirectSoundOut, new SoundOutDevice("Windows Default", WindowsDefaultId, SoundOutType.DirectSound));
                foreach (var device in DirectSoundDeviceEnumerator.EnumerateDevices().Select(x => new SoundOutDevice(x.Description, x.Module, SoundOutType.DirectSound, defaultDevice != null && x.Description == defaultDevice.FriendlyName)))
                   directSoundMode.Devices.Add(device);

                UpdateWindowsDefault(directSoundMode);
                SoundOutModes.Add(directSoundMode);
                CheckCurrentState();
            }
        }
Exemplo n.º 26
0
        private static ISoundOut GetWasApiSoundOut(ISoundOutDevice device)
        {
            MMDevice mmDevice = null;
            if (device.Id == WindowsDefaultId)
            {
                mmDevice = GetDefaultDevice();
            }

            if (mmDevice == null)
            {
                using (var enumerator = new MMDeviceEnumerator())
                {
                    using (var devices = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
                    {
                        if (devices == null || devices.Count == 0)
                            throw new NoDeviceFoundException();

                        mmDevice = devices.FirstOrDefault(x => x.DeviceID == device.Id) ?? GetDefaultDevice() ?? devices.First();
                    }
                }
            }

            return new WasapiOut { Device = mmDevice,UseChannelMixingMatrices = false };
        }
Exemplo n.º 27
0
        private void Form1_Load(object sender, EventArgs e)
        {
            using (var mmdeviceEnumerator = new MMDeviceEnumerator())
            {
                using (
                    var mmdeviceCollection = mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
                {
                    foreach (var device in mmdeviceCollection)
                    {
                        _devices.Add(device);
                    }
                }
            }

            comboBox1.DataSource = _devices;
            comboBox1.DisplayMember = "FriendlyName";
            comboBox1.ValueMember = "DeviceID";
        }
Exemplo n.º 28
0
 private static ISoundOutDevice GetWasApiSoundOutDeviceById(string id)
 {
     using (var mmdeviceEnumerator = new MMDeviceEnumerator())
     {
         using (var device =
             mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)
                 .FirstOrDefault(x => x.DeviceID == id))
         {
             return device == null
                 ? null
                 : new SoundOutDevice(device.FriendlyName, device.DeviceID,
                     SoundOutType.WasApi);
         }
     }
 }
Exemplo n.º 29
0
        public void Slider()
        {
            try
            {
                using (var enumerator = new CSCore.CoreAudioAPI.MMDeviceEnumerator())
                {
                    // update volume for first start dynamic icon
                    //volume = (float)(Math.Floor((potVal / 3 * 2.395)) / 100);

                    while (true)
                    {
                        if (contVal != oldContVal)
                        {
                            // update value
                            oldContVal = contVal;
                            if (appEnd != null)
                            {
                                appEnd.Dispose();
                            }
                            appEnd = getProcessAudioEndpoint(enumerator);
                            // notify editing volume on another app
                            if (settings.notifyApp)
                            {
                                nanoSliderTray.appVolume(getApp());
                            }
                        }
                        if (potVal != oldPotVal && (potVal > oldPotVal + 1 || potVal < oldPotVal - 1)) // prevents ghost slides
                        {
                            oldPotVal = potVal;
                            volume    = (float)(Math.Floor((potVal / 3 * 2.395)) / 100);
                            nanoSliderTray.DynamicIcon(volume);

                            if (contVal == defaultOutputSink)
                            {
                                ChangeOutputVolume(volume, enumerator);
                            }
                            else if (contVal == defaultInputSink)
                            {
                                ChangeInputVolume(volume, enumerator);
                            }
                            else
                            {
                                ChangeAppVolume(volume);
                            }
                        }
                        if (nanoID == -1)
                        {
                            // if nano undetected poll slower
                            NanoFind();
                            Thread.Sleep(1000);
                        }
                        else
                        {
                            NanoFind();
                            Thread.Sleep(100);
                        }
                    }
                }
            }
            catch (Exception k)
            {
                Console.WriteLine(k);
            }
        }
Exemplo n.º 30
0
        private void UpdateDefaultAudioDevice()
        {
            MMDevice defaultAudioEndpoint;
            using (var enumerator = new MMDeviceEnumerator())
            {
                defaultAudioEndpoint = enumerator.GetDefaultAudioEndpoint(DataFlow.Render, Role.Multimedia);
            }

            foreach (var soundOutMode in SoundOutModes)
            {
                foreach (var soundOutDevice in soundOutMode.Devices)
                    soundOutDevice.IsDefault = false;

                var newDefaultDevice = soundOutMode.Devices.FirstOrDefault(x => x.Id == defaultAudioEndpoint.DeviceID);
                if (newDefaultDevice != null)
                    newDefaultDevice.IsDefault = true;
            }
        }
Exemplo n.º 31
0
 private CSCore.CoreAudioAPI.AudioSessionManager2 GetDefaultAudioSessionManager2(CSCore.CoreAudioAPI.MMDeviceEnumerator enumerator, CSCore.CoreAudioAPI.DataFlow dataFlow)
 {
     using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, CSCore.CoreAudioAPI.Role.Multimedia))
     {
         var sessionManager = CSCore.CoreAudioAPI.AudioSessionManager2.FromMMDevice(device);
         return(sessionManager);
     }
 }
Exemplo n.º 32
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MMNotificationClient"/> class.
 /// </summary>
 public MMNotificationClient()
 {
     _deviceEnumerator = new MMDeviceEnumerator();
     Initialize(_deviceEnumerator);
 }
Exemplo n.º 33
0
 private void ChooseSoundDevice()
 {
     using (MMDeviceEnumerator enumerator = new MMDeviceEnumerator())
     {
         if (soundOut is WasapiOut)
         {
             ((WasapiOut)soundOut).Device = enumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active)[0];
         }
         else
         {
             ((DirectSoundOut)soundOut).Device = DirectSoundDeviceEnumerator.EnumerateDevices().First().Guid;
         }
     }
 }
Exemplo n.º 34
0
 private AudioSessionManager2 GetDefaultAudioSessionManager2(DataFlow dataFlow)
 {
     using (var enumerator = new MMDeviceEnumerator())
     {
         using (var device = enumerator.GetDefaultAudioEndpoint(dataFlow, Role.Multimedia))
         {
             Debug.WriteLine("DefaultDevice: " + device.FriendlyName);
             var sessionManager = AudioSessionManager2.FromMMDevice(device);
             return sessionManager;
         }
     }
 }
Exemplo n.º 35
0
 /// <summary>
 /// Initializes a new instance of the <see cref="MMNotificationClient"/> class.
 /// </summary>
 public MMNotificationClient()
 {
     _deviceEnumerator = new MMDeviceEnumerator();
     Initialize(_deviceEnumerator);
 }
Exemplo n.º 36
-12
 public static List<MMDevice> GetSoundDevices()
 {
     List<MMDevice> devices = new List<MMDevice>();
     using (var mmdeviceEnumerator = new MMDeviceEnumerator())
     {
         using (var mmdeviceCollection = mmdeviceEnumerator.EnumAudioEndpoints(DataFlow.Render, DeviceState.Active))
         {
             foreach (var device in mmdeviceCollection)
             {
                 devices.Add(device);
             }
         }
     }
     return devices;
 }