Ejemplo n.º 1
0
        public AudioSessionKeeper(IAudioSession session, AudioSessionVolumeListener volumeListener, AudioSessionMuteListener muteListener)
        {
            m_id = session.Id;

            m_volumeSubscription = session.VolumeChanged.Subscribe(volumeListener);
            m_muteSubscription   = session.MuteChanged.Subscribe(muteListener);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Registers the session with the service so it's aware
        /// of events and they're handled properly.
        /// Sessions are always groupped regardless if they belong to a parent process or not.
        /// In the case that they don't have a parent process, the group will contain just one session.
        /// </summary>
        /// <param name="session">The audio session to register.</param>
        private void RegisterSession(IAudioSession session)
        {
            //AppLogging.DebugLog(nameof(RegisterSession), session.SessionIdentifier, session.DisplayName, session.Id.ToString());
            if (_sessionGoups.TryGetValue(session.Id, out var group))
            {
                var sessionGroup = group as AudioSessionGroup;
                if (!sessionGroup.ContainsSession(session))
                {
                    sessionGroup.AddSession(session);
                }
                else
                {
                    session.Dispose();
                }
            }
            else
            {
                var sessionGroup = new AudioSessionGroup(session.Id, session.DisplayName, session.IsDefault);
                sessionGroup.AddSession(session);

                _sessionGoups.Add(sessionGroup.Id, sessionGroup);
                sessionGroup.SessionEnded  += OnSessionGroupEnded;
                sessionGroup.VolumeChanged += OnSessionGroupVolumeChanged;

                RaiseSessionCreated(sessionGroup.Id, sessionGroup.DisplayName, sessionGroup.Volume, sessionGroup.IsMuted);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="TextPlaceholder"/> class.
        /// </summary>
        /// <param name="parameters">The parameters passed to the text format.</param>
        /// <param name="audioSession">The audio session to use for the placeholder value.</param>
        protected TextPlaceholder(IEnumerable <TextPlaceholderParameter> parameters, IAudioSession audioSession)
        {
            Session = audioSession;
            Session.PropertyChanged += AudioSessionOnPropertyChanged;

            // TODO parameters
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Registers the session with the service so it's aware
        /// of events and they're handled properly.
        /// Sessions are always groupped regardless if they belong to a parent process or not.
        /// In the case that they don't have a parent process, the group will contain just one session.
        /// </summary>
        /// <param name="session">The audio session to register.</param>
        private void RegisterSession(IAudioSession session)
        {
            var groupId = GetSessionGroupId(session);

            if (_sessionGoups.TryGetValue(groupId, out var group))
            {
                var sessionGroup = group as AudioSessionGroup;
                if (!sessionGroup.ContainsSession(session))
                {
                    sessionGroup.AddSession(session);
                }
                else
                {
                    session.Dispose();
                }
            }
            else
            {
                var sessionGroup = new AudioSessionGroup(groupId, session.DisplayName);
                sessionGroup.AddSession(session);

                _sessionGoups.Add(groupId, sessionGroup);
                sessionGroup.SessionEnded  += OnSessionGroupEnded;
                sessionGroup.VolumeChanged += OnSessionGroupVolumeChanged;

                RaiseSessionCreated(groupId, sessionGroup.DisplayName, sessionGroup.Volume, sessionGroup.IsMuted);
            }
        }
Ejemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PreviousButtonViewModel"/> class.
 /// </summary>
 /// <param name="appSettings">The app settings.</param>
 /// <param name="dialogService">The dialog service.</param>
 /// <param name="audioSession">The audio session.</param>
 /// <param name="messageBus">The message bus.</param>
 public PreviousButtonViewModel(IAppSettings appSettings, IDialogService dialogService, IAudioSession audioSession, IMessageBus messageBus)
     : base(appSettings.PreviousButton, dialogService, messageBus)
 {
     _appSettings  = appSettings;
     _audioSession = audioSession;
     _appSettings.ProfileChanged += AppsSettingsOnProfileChanged;
     PreviousTrackCommand         = new AsyncRelayCommand <object>(PreviousTrackCommandOnExecute);
     Content = new ButtonContentViewModel(Model.Content, new PreviousButton().Content, dialogService);
     TrackContentViewModel(Content);
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ProgressBarViewModel"/> class.
        /// </summary>
        /// <param name="appsettings">The app settings.</param>
        /// <param name="dialogService">The dialog service.</param>
        /// <param name="audioSession">The audio session.</param>
        /// <param name="messageBus">The message bus.</param>
        public ProgressBarViewModel(IAppSettings appsettings, IDialogService dialogService, IAudioSession audioSession, IMessageBus messageBus)
            : base(messageBus, appsettings.ProgressBar)
        {
            _appsettings  = appsettings;
            _audioSession = audioSession;
            _audioSession.PropertyChanged += AudioSessionOnPropertyChanged;
            DialogService = dialogService;

            _appsettings.ProfileChanged += AppsettingsOnProfileChanged;
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AlbumArtViewModel"/> class.
        /// </summary>
        /// <param name="appsettings">The app settings.</param>
        /// <param name="dialogService">The dialog service.</param>
        /// <param name="audioSession">The audio session.</param>
        /// <param name="messageBus">The message bus.</param>
        public AlbumArtViewModel(IAppSettings appsettings, IDialogService dialogService, IAudioSession audioSession, IMessageBus messageBus)
            : base(messageBus, appsettings.AlbumArt)
        {
            DialogService = dialogService;
            _appsettings  = appsettings;
            _audioSession = audioSession;

            appsettings.ProfileChanged   += AppsettingsOnProfileChanged;
            audioSession.PropertyChanged += AudioSessionOnPropertyChanged;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomLabelViewModel"/> class.
        /// </summary>
        /// <param name="source">The custom label.</param>
        /// <param name="dialogService">The dialog service.</param>
        /// <param name="audioSession">The audio session.</param>
        /// <param name="messageBus">The message bus.</param>
        public CustomLabelViewModel(CustomLabel source, IDialogService dialogService, IAudioSession audioSession, IMessageBus messageBus)
            : base(messageBus, source)
        {
            _audioSession = audioSession;
            _audioSession.PropertyChanged += AudioSessionOnPropertyChanged;

            DialogService = dialogService;
            TextSegments  = FormattedTextParser.ParseFormattedString(FormatString, Color, audioSession);
            IsPlaying     = _audioSession.IsPlaying;
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Unregisters the session from the service so events
        /// are not responded to anymore.
        /// </summary>
        /// <param name="sessionGroup"></param>
        private void UnregisterSessionGroup(IAudioSession sessionGroup)
        {
            sessionGroup.SessionEnded  -= OnSessionGroupEnded;
            sessionGroup.VolumeChanged -= OnSessionGroupVolumeChanged;
            if (_sessionGoups.Remove(sessionGroup.Id))
            {
                RaiseSessionRemoved(sessionGroup.Id);
            }

            sessionGroup.Dispose();
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Unregisters the session from the service so events
        /// are not responded to anymore.
        /// </summary>
        /// <param name="session">The audio session to unregister.</param>
        private void UnregisterSessionGroup(IAudioSession session)
        {
            //AppLogging.DebugLog(nameof(UnregisterSessionGroup), session.SessionIdentifier, session.DisplayName);
            session.SessionEnded  -= OnSessionGroupEnded;
            session.VolumeChanged -= OnSessionGroupVolumeChanged;
            if (_sessionGoups.Remove(session.Id))
            {
                RaiseSessionRemoved(session.Id);
            }

            session.Dispose();
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CustomLabelsViewModel"/> class
        /// with the list of custom labels and a label host.
        /// </summary>
        /// <param name="appsettings">The app setings.</param>
        /// <param name="dialogService">The dialog service.</param>
        /// <param name="audioSession">The audio session.</param>
        /// <param name="messageBus">The message bus.</param>
        public CustomLabelsViewModel(IAppSettings appsettings, IDialogService dialogService, IAudioSession audioSession, IMessageBus messageBus)
        {
            _appsettings   = appsettings;
            _dialogService = dialogService;
            _audioSession  = audioSession;
            UseMessageBus(messageBus);
            SetupLabels();

            AddLabelCommand              = new RelayCommand(AddLabelCommandOnExecute);
            RemoveLabelCommand           = new RelayCommand <CustomLabelViewModel>(RemoveLabelCommandOnExecute);
            _appsettings.ProfileChanged += AppsettingsOnProfileChanged;
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Initializes a new instance of the <see cref="AudioBandToolbarViewModel"/> class.
        /// </summary>
        /// <param name="viewModels">The view models.</param>
        /// <param name="appSettings">The app settings.</param>
        /// <param name="audioSourceManager">The audio source mananger.</param>
        /// <param name="messageBus">The message bus.</param>
        /// <param name="audioSession">The audio session.</param>
        public AudioBandToolbarViewModel(IViewModelContainer viewModels, IAppSettings appSettings, IAudioSourceManager audioSourceManager, IMessageBus messageBus, IAudioSession audioSession)
        {
            _appSettings        = appSettings;
            _audioSourceManager = audioSourceManager;
            _messageBus         = messageBus;
            _audioSession       = audioSession;
            ViewModels          = viewModels;

            ShowSettingsWindowCommand = new RelayCommand(ShowSettingsWindowCommandOnExecute);
            LoadCommand = new AsyncRelayCommand <object>(LoadCommandOnExecute);
            SelectAudioSourceCommand = new AsyncRelayCommand <IInternalAudioSource>(SelectAudioSourceCommandOnExecute);
        }
Ejemplo n.º 13
0
        private void OnSessionEnded(IAudioSession session)
        {
            if (!_sessions.Remove(session.ID))
            {
                return;
            }

            session.SessionEnded  -= OnSessionEnded;
            session.VolumeChanged -= OnSessionVolumeChanged;
            session.Dispose();

            SessionEnded?.Invoke(session);
        }
Ejemplo n.º 14
0
        private void OnSessionRemoved(IAudioSession session)
        {
            if (_devices.Remove(session.ID))
            {
                var deviceSession = session as AudioDevice;
                deviceSession.SessionCreated -= OnSessionCreated;
                deviceSession.SessionEnded   -= OnSessionRemoved;
                deviceSession.VolumeChanged  -= OnSessionVolumeChanged;
                session.Dispose();
            }

            RaiseSessionRemoved(session.ID);
        }
Ejemplo n.º 15
0
        private void Read()
        {
            while (_continue)
            {
                try
                {
                    if (_serialPort.BytesToRead < 8)
                    {
                        continue;
                    }

                    byte[] buffer = new byte[8];
                    _serialPort.Read(buffer, 0, 8);

                    VMPacket packet = new VMPacket(buffer);

                    if (packet.isPing || packet.knobId - 1 < 0 || packet.knobId - 1 >= _dialViewHolders.Count)
                    {
                        continue;
                    }

                    _dispatcher.Invoke(() =>
                    {
                        try
                        {
                            Debug.WriteLineIf(packet.knobId == 1, packet.value);
                            DialViewHolder view    = _dialViewHolders[packet.knobId - 1];
                            view.progressbar.Value = packet.value;
                            IAudioSession a        = (IAudioSession)view.combobox.SelectedItem;

                            if (a == null)
                            {
                                return;
                            }

                            Debug.WriteLineIf(packet.knobId == 1, a.ToString());
                            a.Volume = (float)packet.value / (float)127;
                            Debug.WriteLineIf(packet.knobId == 1, a.Volume.ToString() + " " + packet.value);
                        }
                        catch (Exception)
                        {
                        }
                    });
                }
                catch (IOException e) {
                    MessageBox.Show(e.Message);
                    MessageBox.Show(e.InnerException.Message);
                }
            }
        }
Ejemplo n.º 16
0
        void cmb_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBox      cmb = sender as ComboBox;
            IAudioSession a   = (IAudioSession)cmb.SelectedItem;

            if (a == null)
            {
                return;
            }

            DialViewHolder view = dialViewHolders.Single(s => s.combobox == cmb); // Get viewholder of correct dial

            view.image.Source = a.imageSource;
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Initializes a new instance of the <see cref="PlayPauseButtonViewModel"/> class.
        /// </summary>
        /// <param name="appSettings">App settings.</param>
        /// <param name="dialogService">The dialog service.</param>
        /// <param name="audioSession">The audio session.</param>
        /// <param name="messageBus">The message bus.</param>
        public PlayPauseButtonViewModel(IAppSettings appSettings, IDialogService dialogService, IAudioSession audioSession, IMessageBus messageBus)
            : base(appSettings.CurrentProfile.PlayPauseButton, dialogService, messageBus)
        {
            _appSettings  = appSettings;
            _audioSession = audioSession;
            _audioSession.PropertyChanged += AudioSessionOnPropertyChanged;
            _appSettings.ProfileChanged   += AppSettingsOnProfileChanged;
            PlayPauseTrackCommand          = new AsyncRelayCommand <object>(PlayPauseTrackCommandOnExecute);

            var resetBase = new PlayPauseButton();

            PlayContent  = new ButtonContentViewModel(Model.PlayContent, resetBase.PlayContent, dialogService);
            PauseContent = new ButtonContentViewModel(Model.PauseContent, resetBase.PauseContent, dialogService);
            TrackContentViewModel(PlayContent);
            TrackContentViewModel(PauseContent);
        }
Ejemplo n.º 18
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ShuffleModeButtonViewModel"/> class.
        /// </summary>
        /// <param name="appSettings">The app settings.</param>
        /// <param name="dialogService">The dialog service.</param>
        /// <param name="audioSession">The audio session.</param>
        /// <param name="messageBus">The message bus.</param>
        public ShuffleModeButtonViewModel(IAppSettings appSettings, IDialogService dialogService, IAudioSession audioSession, IMessageBus messageBus)
            : base(appSettings.ShuffleModeButton, dialogService, messageBus)
        {
            _appSettings  = appSettings;
            _audioSession = audioSession;
            _audioSession.PropertyChanged += AudioSessionOnPropertyChanged;
            _appSettings.ProfileChanged   += AppSettingsOnProfileChanged;

            ToggleShuffleCommand = new AsyncRelayCommand <object>(ToggleShuffleCommandOnExecute);
            var resetBase = new ShuffleModeButton();

            ShuffleOnContent  = new ButtonContentViewModel(Model.ShuffleOnContent, resetBase.ShuffleOnContent, dialogService);
            ShuffleOffContent = new ButtonContentViewModel(Model.ShuffleOffContent, resetBase.ShuffleOffContent, dialogService);
            TrackContentViewModel(ShuffleOnContent);
            TrackContentViewModel(ShuffleOffContent);
        }
Ejemplo n.º 19
0
        /// <summary>
        /// Retrives the id of the group that this session belongs to.
        /// </summary>
        /// <param name="session">The session to get the id for.</param>
        /// <returns>The id used for the group of this session.</returns>
        private int GetSessionGroupId(IAudioSession session)
        {
            var audioSession = session as AudioSession;

            if (audioSession.IsSystemSound)
            {
                return(audioSession.ProcessID);
            }

            var fileName = audioSession.Process.GetMainModuleFileName();

            if (!string.IsNullOrEmpty(fileName))
            {
                return(fileName.GetHashCode());
            }

            return(audioSession.ProcessID);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RepeatModeButtonViewModel"/> class.
        /// </summary>
        /// <param name="appSettings">The app settings.</param>
        /// <param name="dialogService">The dialog service.</param>
        /// <param name="audioSession">The audio session.</param>
        /// <param name="messageBus">The message bus.</param>
        public RepeatModeButtonViewModel(IAppSettings appSettings, IDialogService dialogService, IAudioSession audioSession, IMessageBus messageBus)
            : base(appSettings.RepeatModeButton, dialogService, messageBus)
        {
            _appSettings  = appSettings;
            _audioSession = audioSession;
            _audioSession.PropertyChanged += AudioSessionOnPropertyChanged;
            _appSettings.ProfileChanged   += AppSettingsOnProfileChanged;

            var resetState = new RepeatModeButton();

            RepeatOffContent       = new ButtonContentViewModel(Model.RepeatOffContent, resetState.RepeatOffContent, dialogService);
            RepeatContextContent   = new ButtonContentViewModel(Model.RepeatContextContent, resetState.RepeatContextContent, dialogService);
            RepeatTrackContent     = new ButtonContentViewModel(Model.RepeatTrackContent, resetState.RepeatTrackContent, dialogService);
            CycleRepeatModeCommand = new AsyncRelayCommand <object>(CycleRepeatModeCommandOnExecute);

            TrackContentViewModel(RepeatOffContent);
            TrackContentViewModel(RepeatContextContent);
            TrackContentViewModel(RepeatTrackContent);
        }
Ejemplo n.º 21
0
        private void RegisterSession(IAudioSession session)
        {
            if (!_visibleSystemSounds && session.IsSystemSound)
            {
                session.Dispose();
                return;
            }

            var audioSession = session as AudioSession;
            var fileName     = audioSession.Process.GetMainModuleFileName(); // QUESTION: Should we use session.GroupingParam instead?

            // If we are able to grab the fileName for the process, group it with sessions from the same fileName
            if (!string.IsNullOrEmpty(fileName))
            {
                var groupID = fileName.GetHashCode();

                AudioSessionGroup sessionGroup;
                if (_sessions.TryGetValue(groupID, out var group))
                {
                    // We have a previously constrcuted group, so just add this session to that group and early out.
                    sessionGroup = group as AudioSessionGroup;
                    sessionGroup.AddSession(session);
                    return;
                }

                // Need to create a new group for this session and register it
                sessionGroup = new AudioSessionGroup(groupID, session.DisplayName);
                sessionGroup.AddSession(session);
                session = sessionGroup;
            }

            _sessions.Add(session.ID, session);
            session.SessionEnded  += OnSessionEnded;
            session.VolumeChanged += OnSessionVolumeChanged;

            SessionCreated?.Invoke(session);
        }
Ejemplo n.º 22
0
 public SessionMuteChangedArgs(IAudioSession session, bool isMuted)
 {
     Session = session;
     IsMuted = isMuted;
 }
Ejemplo n.º 23
0
        private static void AddSegment(List <TextSegment> segments, StringBuilder text, bool isPlaceholder, Color defaultColor, IAudioSession session)
        {
            if (text.Length == 0)
            {
                return;
            }

            if (isPlaceholder)
            {
                if (TryParsePlaceholder(text.ToString(), defaultColor, session, out TextPlaceholder placeholder, out FormattedTextFlags flags, out Color c))
                {
                    segments.Add(new PlaceholderTextSegment(placeholder, flags, c));
                }
                else
                {
                    segments.Add(new StaticTextSegment("!Invalid format!", FormattedTextFlags.Normal, Colors.Red));
                }
            }
Ejemplo n.º 24
0
 private void OnSessionVolumeChanged(IAudioSession session)
 {
     VolumeChanged?.Invoke(session);
 }
Ejemplo n.º 25
0
 /// <summary>
 /// Initializes a new instance of the <see cref="AlbumNamePlaceholder"/> class.
 /// </summary>
 /// <param name="parameters">The placeholder parameters.</param>
 /// <param name="audioSession">The audio session.</param>
 public AlbumNamePlaceholder(IEnumerable <TextPlaceholderParameter> parameters, IAudioSession audioSession)
     : base(parameters, audioSession)
 {
     AddSessionPropertyFilter(nameof(IAudioSession.AlbumName));
 }
Ejemplo n.º 26
0
 public SessionPeakValueChangedArgs(IAudioSession session, double peakValue)
 {
     Session   = session;
     PeakValue = peakValue;
 }
Ejemplo n.º 27
0
 public SessionDisconnectedArgs(IAudioSession session)
 {
     Session = session;
 }
Ejemplo n.º 28
0
 /// <summary>
 /// Handles changes and notifications required when the volume
 /// of a device or it's mute state has changed.
 /// </summary>
 /// <param name="session"></param>
 private void OnSessionGroupVolumeChanged(IAudioSession session)
 {
     RaiseSessionVolumeChanged(session.Id, session.Volume, session.IsMuted);
 }
Ejemplo n.º 29
0
 /// <summary>
 /// Handles the removal and notification of the session from the service.
 /// </summary>
 /// <param name="session"></param>
 private void OnSessionGroupEnded(IAudioSession session)
 {
     UnregisterSessionGroup(session);
 }
Ejemplo n.º 30
0
 /// <summary>
 /// Initializes a new instance of the <see cref="SongArtistPlaceholder"/> class.
 /// </summary>
 /// <param name="parameters">The placeholder parameter.</param>
 /// <param name="audioSession">The audio session.</param>
 public SongArtistPlaceholder(IEnumerable <TextPlaceholderParameter> parameters, IAudioSession audioSession)
     : base(parameters, audioSession)
 {
     AddSessionPropertyFilter(nameof(IAudioSession.SongArtist));
 }