private void AddSession(IAudioDeviceSession session) { Trace.WriteLine($"AudioDeviceSessionCollection AddSession {session.ExeName} {session.Id}"); session.PropertyChanged += Session_PropertyChanged; foreach (AudioDeviceSessionGroup appGroup in _sessions) { if (appGroup.ExeName == session.ExeName) { foreach (AudioDeviceSessionGroup appSessionGroup in appGroup.Sessions) { if (appSessionGroup.GroupingParam == session.GroupingParam) { // If there is a session in the same process, inherit safely. // (Avoids a minesweeper ad playing at max volume when app should be muted) session.IsMuted = session.IsMuted || appSessionGroup.IsMuted; appSessionGroup.AddSession(session); return; } } session.IsMuted = session.IsMuted || appGroup.IsMuted; appGroup.AddSession(new AudioDeviceSessionGroup(session)); return; } } _sessions.Add(new AudioDeviceSessionGroup(new AudioDeviceSessionGroup(session))); }
internal AppItemViewModel(IAudioDeviceSession session, bool isChild = false) : base(session) { IsExpanded = isChild; _session = session; _session.PropertyChanged += Session_PropertyChanged; if (_session.Children != null) { _session.Children.CollectionChanged += Children_CollectionChanged; ChildApps = new ObservableCollection <IAppItemViewModel>(_session.Children.Select(t => new AppItemViewModel(t, isChild: true))); } Background = new SolidColorBrush(session.IsDesktopApp ? Colors.Transparent : session.BackgroundColor.ToABGRColor()); try { if (session.IsDesktopApp) { Icon = System.Drawing.Icon.ExtractAssociatedIcon(session.IconPath).ToImageSource(); } else { Icon = new BitmapImage(new Uri(session.IconPath)); } } catch (Exception ex) { Trace.TraceError($"Failed to load icon: {ex}"); } }
private void RemoveSession(IAudioDeviceSession session) { Trace.WriteLine($"AudioDeviceSessionCollection RemoveSession {session.ExeName} {session.Id}"); session.PropertyChanged -= Session_PropertyChanged; foreach (AudioDeviceSessionGroup appGroup in _sessions) { foreach (AudioDeviceSessionGroup appSessionGroup in appGroup.Sessions) { if (appSessionGroup.Sessions.Contains(session)) { appSessionGroup.RemoveSession(session); // Delete the now-empty app session group. if (!appSessionGroup.Sessions.Any()) { appGroup.RemoveSession(appSessionGroup); break; } } } // Delete the now-empty app. if (!appGroup.Sessions.Any()) { _sessions.Remove(appGroup); break; } } }
static string DumpSession(string indent, IAudioDeviceSession session) { string flags = session.IsDesktopApp ? "Desktop " : "Modern "; if (session.IsSystemSoundsSession) { flags += "SystemSounds "; } bool isAlive = false; try { using (Process.GetProcessById(session.ProcessId)) { } isAlive = true; } catch (Exception) { } StringBuilder sb = new StringBuilder(); sb.AppendLine(indent + $"{session.SessionDisplayName}"); sb.AppendLine(indent + $" [{session.State}]: {session.Volume.ToVolumeInt()}%{(session.IsMuted ? " (Muted)" : "")} {flags}pid:{session.ProcessId} {(!isAlive ? "(dead)" : "")}"); sb.AppendLine(indent + $" AppId: {session.AppId} id={session.Id}"); sb.AppendLine(indent + $" IconPath: {session.IconPath}"); sb.AppendLine(indent + $" GroupingParam: {session.GroupingParam}"); var persisted = session.PersistedDefaultEndPointId; if (!string.IsNullOrWhiteSpace(persisted)) { sb.AppendLine(indent + $" Persisted Endpoint: {persisted}"); } return(sb.ToString()); }
private void OnAppPropertyChanged(IAudioDeviceSession session, string propertyName) { if (propertyName == nameof(session.Volume) || propertyName == nameof(session.IsMuted)) { // Trace.WriteLine($"{session.DisplayName}: {session.Volume} {session.IsMuted}"); TriggerOSDForApp(session.Parent.Id, session.AppId); } }
public void RefreshStream(bool forced = false, INamedStreamWithVolumeControl newStream = null) { if (Id == null) { return; } if (_stream != null && !forced) { return; } IStreamWithVolumeControl old = _stream; _stream = newStream != null ? newStream : SharedManager.GetStreamById(Id); if (old == _stream) { return; } if (old != null) { INotifyPropertyChanged notifiable = (INotifyPropertyChanged)old; notifiable.PropertyChanged -= this.Stream_PropertyChanged; } if (_stream != null) { INotifyPropertyChanged notifiable = (INotifyPropertyChanged)_stream; notifiable.PropertyChanged += this.Stream_PropertyChanged; _streamName = _stream.DisplayName; if (_stream is IAudioDeviceSession) { IAudioDeviceSession session = (IAudioDeviceSession)_stream; if (session.Parent != null) { _parent = session.Parent; ParentName = session.Parent.DisplayName; } } IconPath = _stream.IconPath; IsDesktopApp = _stream.IsDesktopApp; } RaisePropertyChanged("Stream"); RaisePropertyChanged("StreamName"); RaisePropertyChanged("Disabled"); RaisePropertyChanged("QualifiedStreamName"); }
internal AppItemViewModel(DeviceViewModel parent, IAudioDeviceSession session, bool isChild = false) : base(session) { IsExpanded = isChild; _session = session; _session.PropertyChanged += Session_PropertyChanged; _parent = new WeakReference <DeviceViewModel>(parent); Background = session.IsDesktopApp ? Colors.Transparent : session.BackgroundColor.ToABGRColor(); if (_session.Children != null) { _session.Children.CollectionChanged += Children_CollectionChanged; ChildApps = new ObservableCollection <IAppItemViewModel>(_session.Children.Select(t => new AppItemViewModel(parent, t, true))); } }
private void AddSession(IAudioDeviceSession session) { var newSession = new AppItemViewModel(session); foreach (var a in Apps) { if (a.DoesGroupWith(newSession)) { // Remove the fake app entry after copying any changes the user did. newSession.Volume = a.Volume; newSession.IsMuted = a.IsMuted; Apps.Remove(a); break; } } Apps.AddSorted(newSession, AppItemViewModel.CompareByExeName); }
private void OnAppAddOrRemove(IAudioDeviceSession app, AudioAppEventKind option) { foreach (var trigger in _appTriggers) { if (trigger.Option == option) { var device = app.Parent; if ((trigger.Device?.Id == null && device == _playbackManager.DeviceManager.Default) || trigger.Device?.Id == device.Id) { if (trigger.App.Id == app.AppId) { Triggered?.Invoke(trigger); } } } } }
private void OnAppPropertyChanged(IAudioDeviceSession app, string propertyName) { foreach (var trigger in _appTriggers) { var device = app.Parent; if ((trigger.Device?.Id == null && device == _playbackManager.DeviceManager.Default) || trigger.Device?.Id == device.Id) { if (trigger.App.Id == app.AppId) { switch (trigger.Option) { case AudioAppEventKind.Muted: if (propertyName == nameof(app.IsMuted) && app.IsMuted) { Triggered?.Invoke(trigger); } break; case AudioAppEventKind.Unmuted: if (propertyName == nameof(app.IsMuted) && !app.IsMuted) { Triggered?.Invoke(trigger); } break; case AudioAppEventKind.PlayingSound: if (propertyName == nameof(app.State) && app.State == SessionState.Active) { Triggered?.Invoke(trigger); } break; case AudioAppEventKind.NotPlayingSound: if (propertyName == nameof(app.State) && app.State != SessionState.Active) { Triggered?.Invoke(trigger); } break; } } } } }
private void FreeApp(IAudioDeviceSession app) { app.PropertyChanged -= App_PropertyChanged; AppRemoved?.Invoke(app); }
private void ListenToApp(IAudioDeviceSession app) { app.PropertyChanged += App_PropertyChanged; AppAdded?.Invoke(app); }