예제 #1
0
        public void Attach(IAudioPlaybackProvider audioPlayback, IEnumerable <AudioSource> sources, AudioEnginePlaybackOptions options)
        {
            if (audioPlayback == null)
            {
                throw new ArgumentNullException("audioPlayback");
            }
            if (sources == null)
            {
                throw new ArgumentNullException("sources");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            lock (playbacks)
            {
                if (!this.playbackProviders.Contains(audioPlayback))
                {
                    audioPlayback.SourceFinished += OnSourceFinished;
                    this.playbackProviders.Add(audioPlayback);
                }

                foreach (var s in sources.Where(s => !playbacks.ContainsKey(s) && s.OwnerId != Context.CurrentUser.UserId))
                {
                    audioPlayback.SetGain(s, options.Gain);
                    playbacks[s] = new AudioPlaybackEntity(audioPlayback, s, options);

                    if (mutedPlayers.Contains(audioPlayback))
                    {
                        playbacks[s].Muted = true;
                    }
                }
            }
        }
예제 #2
0
        public bool Detach(IAudioPlaybackProvider provider)
        {
            if (provider == null)
            {
                throw new ArgumentNullException("provider");
            }

            bool removed = false;

            lock (playbacks)
            {
                this.playbackProviders.Remove(provider);
                provider.SourceFinished -= OnSourceFinished;

                foreach (var entity in playbacks.Values.Where(e => e.AudioPlayback == provider).ToList())
                {
                    entity.AudioPlayback.FreeSource(entity.Source);
                    playbacks.Remove(entity.Source);
                    removed = true;
                }

                mutedPlayers.Remove(provider);
            }

            return(removed);
        }
예제 #3
0
        private void MuteCore(IAudioPlaybackProvider audioPlayback, bool mute)
        {
            if (audioPlayback == null)
            {
                throw new ArgumentNullException("audioPlayback");
            }

            lock (playbacks)
            {
                if (mute)
                {
                    mutedPlayers.Add(audioPlayback);
                }
                else
                {
                    mutedPlayers.Remove(audioPlayback);
                }

                var ps = playbacks.Values.Where(e => e.AudioPlayback == audioPlayback);

                foreach (var e in ps)
                {
                    e.Muted = mute;
                }
            }
        }
예제 #4
0
        public void Attach(IAudioPlaybackProvider audioPlayback, AudioSource source, AudioEnginePlaybackOptions options)
        {
            if (audioPlayback == null)
            {
                throw new ArgumentNullException("audioPlayback");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (options == null)
            {
                throw new ArgumentNullException("options");
            }

            lock (playbacks)
            {
                if (!this.playbackProviders.Contains(audioPlayback))
                {
                    audioPlayback.SourceFinished += OnSourceFinished;
                    this.playbackProviders.Add(audioPlayback);
                }

                audioPlayback.SetGain(source, options.Gain);
                playbacks[source] = new AudioPlaybackEntity(audioPlayback, source, options);

                if (mutedPlayers.Contains(audioPlayback))
                {
                    playbacks[source].Muted = true;
                }
            }
        }
예제 #5
0
        public AudioPlaybackSettingsViewModel()
        {
            PlaybackProviders = Modules.Playback;

            IAudioPlaybackProvider savedPlaybackProvider = Modules.Playback.FirstOrDefault(p => p.GetType().GetSimpleName() == Settings.PlaybackProvider);

            if (savedPlaybackProvider == null)
            {
                CurrentPlaybackProvider = Modules.Playback.FirstOrDefault();
            }
            else
            {
                CurrentPlaybackProvider = savedPlaybackProvider;

                if (Settings.PlaybackDevice != null)
                {
                    var setDevice = PlaybackDevices.FirstOrDefault(d => d.Device.Name == Settings.PlaybackDevice);
                    if (setDevice != null)
                    {
                        CurrentPlaybackDevice = setDevice;
                    }
                }
            }

            Volume = Settings.GlobalVolume * 100;
        }
예제 #6
0
        /// <summary>
        /// Opens the provider with <paramref name="device"/>.
        /// </summary>
        /// <param name="device">The device to play audio on.</param>
        /// <exception cref="ArgumentNullException"><paramref name="device"/> is <c>null</c>.</exception>
        public static void Open(this IAudioPlaybackProvider self, IAudioDevice device)
        {
            if (self == null)
            {
                throw new ArgumentNullException("self");
            }
            if (device == null)
            {
                throw new ArgumentNullException("device");
            }

            self.Device = device;
            self.Open();
        }
예제 #7
0
파일: MainForm.cs 프로젝트: ermau/Gablarski
        private void SetupPlayback()
        {
            DisablePlayback();

            if (!this.gablarski.IsConnected)
            {
                return;
            }

            try
            {
                if (Settings.PlaybackProvider == null)
                {
                    throw new Exception("Playback provider is not set");
                }

                this.audioPlayback = (IAudioPlaybackProvider)Activator.CreateInstance(Type.GetType(Settings.PlaybackProvider));

                if (Settings.PlaybackDevice.IsNullOrWhitespace() || Settings.PlaybackDevice == "Default")
                {
                    this.audioPlayback.Device = this.audioPlayback.DefaultDevice;
                }
                else
                {
                    this.audioPlayback.Device = this.audioPlayback.GetDevices().FirstOrDefault(d => d.Name == Settings.PlaybackDevice)
                                                ?? this.audioPlayback.DefaultDevice;
                }

                this.audioPlayback.Open();
                this.audioPlayback.Gain = Settings.GlobalVolume;

                this.gablarski.Sources.Where(s => s.OwnerId != gablarski.CurrentUser.UserId)
                .ForEach(AttachSource);

                BeginInvoke((Action)(() =>
                {
                    if (btnMute.Checked && !this.playbackDisabled)
                    {
                        return;
                    }

                    btnMute.Image = Resources.SoundMuteImage;
                    btnMute.Checked = false;
                    btnMute.Enabled = true;
                    btnMute.ToolTipText = "Mute Sound";

                    if (this.playbackDisabled)
                    {
                        btnMuteMic.Checked = false;
                    }

                    this.playbackDisabled = false;
                }));
            }
            catch (Exception ex)
            {
                Program.Raygun.Send(ex, new[] { "playback-init" }, Settings.CurrentSettings);

                if (this.audioPlayback != null)
                {
                    this.audioPlayback.Dispose();
                }

                this.audioPlayback = null;

                BeginInvoke((Action)(() =>
                {
                    this.playbackDisabled = true;
                    btnMute.Image = Resources.SoundMuteImage.ToErrorIcon();
                    btnMute.Checked = true;
                    btnMute.Enabled = false;
                    btnMute.ToolTipText = "Playback Initialization error: " + ex.Message;
                }));
            }

            if (this.audioPlayback != null && Settings.EnableNotifications)
            {
                SetupNotifications();
                this.notifications.Notify(NotificationType.Connected, "Connected");
            }
        }
예제 #8
0
        private void MuteCore(IAudioPlaybackProvider audioPlayback, bool mute)
        {
            if (audioPlayback == null)
                throw new ArgumentNullException ("audioPlayback");

            lock (playbacks)
            {
                if (mute)
                    mutedPlayers.Add (audioPlayback);
                else
                    mutedPlayers.Remove (audioPlayback);

                var ps = playbacks.Values.Where (e => e.AudioPlayback == audioPlayback);

                foreach (var e in ps)
                    e.Muted = mute;
            }
        }
예제 #9
0
 public void Unmute(IAudioPlaybackProvider audioPlayback)
 {
     MuteCore (audioPlayback, false);
 }
예제 #10
0
 public void Mute(IAudioPlaybackProvider audioPlayback)
 {
     MuteCore (audioPlayback, true);
 }
예제 #11
0
        public bool Detach(IAudioPlaybackProvider provider)
        {
            if (provider == null)
                throw new ArgumentNullException("provider");

            bool removed = false;

            lock (playbacks)
            {
                this.playbackProviders.Remove (provider);
                provider.SourceFinished -= OnSourceFinished;

                foreach (var entity in playbacks.Values.Where (e => e.AudioPlayback == provider).ToList())
                {
                    entity.AudioPlayback.FreeSource (entity.Source);
                    playbacks.Remove (entity.Source);
                    removed = true;
                }

                mutedPlayers.Remove (provider);
            }

            return removed;
        }
예제 #12
0
        public void Attach(IAudioPlaybackProvider audioPlayback, AudioSource source, AudioEnginePlaybackOptions options)
        {
            if (audioPlayback == null)
                throw new ArgumentNullException ("audioPlayback");
            if (source == null)
                throw new ArgumentNullException ("source");
            if (options == null)
                throw new ArgumentNullException ("options");

            lock (playbacks)
            {
                if (!this.playbackProviders.Contains (audioPlayback))
                {
                    audioPlayback.SourceFinished += OnSourceFinished;
                    this.playbackProviders.Add (audioPlayback);
                }

                audioPlayback.SetGain (source, options.Gain);
                playbacks[source] = new AudioPlaybackEntity (audioPlayback, source, options);

                if (mutedPlayers.Contains (audioPlayback))
                    playbacks[source].Muted = true;
            }
        }
예제 #13
0
 public AudioPlaybackEntity(IAudioPlaybackProvider audioPlayback, AudioSource source, AudioEnginePlaybackOptions options)
 {
     this.audioPlayback = audioPlayback;
     this.source        = source;
     this.options       = options;
 }
예제 #14
0
 public void Unmute(IAudioPlaybackProvider audioPlayback)
 {
     MuteCore(audioPlayback, false);
 }
예제 #15
0
 public void Mute(IAudioPlaybackProvider audioPlayback)
 {
     MuteCore(audioPlayback, true);
 }
예제 #16
0
파일: MainForm.cs 프로젝트: ermau/Gablarski
		private void SetupPlayback ()
		{
			DisablePlayback();

			if (!this.gablarski.IsConnected)
				return;

			try
			{
				if (Settings.PlaybackProvider == null)
					throw new Exception ("Playback provider is not set");

				this.audioPlayback = (IAudioPlaybackProvider) Activator.CreateInstance (Type.GetType (Settings.PlaybackProvider));

				if (Settings.PlaybackDevice.IsNullOrWhitespace() || Settings.PlaybackDevice == "Default")
					this.audioPlayback.Device = this.audioPlayback.DefaultDevice;
				else
				{
					this.audioPlayback.Device = this.audioPlayback.GetDevices().FirstOrDefault (d => d.Name == Settings.PlaybackDevice)
												?? this.audioPlayback.DefaultDevice;
				}

				this.audioPlayback.Open();
				this.audioPlayback.Gain = Settings.GlobalVolume;

				this.gablarski.Sources.Where (s => s.OwnerId != gablarski.CurrentUser.UserId)
					.ForEach (AttachSource);

				BeginInvoke ((Action)(() =>
				{
					if (btnMute.Checked && !this.playbackDisabled)
						return;

					btnMute.Image = Resources.SoundMuteImage;
					btnMute.Checked = false;
					btnMute.Enabled = true;
					btnMute.ToolTipText = "Mute Sound";

					if (this.playbackDisabled)
						btnMuteMic.Checked = false;

					this.playbackDisabled = false;
				}));
			}
			catch (Exception ex)
			{
				Program.Raygun.Send (ex, new[] { "playback-init" }, Settings.CurrentSettings);

				if (this.audioPlayback != null)
					this.audioPlayback.Dispose();

				this.audioPlayback = null;

				BeginInvoke ((Action) (() =>
				{
					this.playbackDisabled = true;
					btnMute.Image = Resources.SoundMuteImage.ToErrorIcon();
					btnMute.Checked = true;
					btnMute.Enabled = false;
					btnMute.ToolTipText = "Playback Initialization error: " + ex.Message;
				}));
			}

			if (this.audioPlayback != null && Settings.EnableNotifications)
			{
				SetupNotifications();
				this.notifications.Notify (NotificationType.Connected, "Connected");
			}
		}
예제 #17
0
        public void Attach(IAudioPlaybackProvider audioPlayback, IEnumerable<AudioSource> sources, AudioEnginePlaybackOptions options)
        {
            if (audioPlayback == null)
                throw new ArgumentNullException ("audioPlayback");
            if (sources == null)
                throw new ArgumentNullException ("sources");
            if (options == null)
                throw new ArgumentNullException ("options");

            lock (playbacks)
            {
                if (!this.playbackProviders.Contains (audioPlayback))
                {
                    audioPlayback.SourceFinished += OnSourceFinished;
                    this.playbackProviders.Add (audioPlayback);
                }

                foreach (var s in sources.Where (s => !playbacks.ContainsKey (s) && s.OwnerId != Context.CurrentUser.UserId))
                {
                    audioPlayback.SetGain (s, options.Gain);
                    playbacks[s] = new AudioPlaybackEntity (audioPlayback, s, options);

                    if (mutedPlayers.Contains (audioPlayback))
                        playbacks[s].Muted = true;
                }
            }
        }
예제 #18
0
 public AudioPlaybackEntity(IAudioPlaybackProvider audioPlayback, AudioSource source, AudioEnginePlaybackOptions options)
 {
     this.audioPlayback = audioPlayback;
     this.source = source;
     this.options = options;
 }