コード例 #1
0
        public AudioPanelViewModel(EncodingWindowViewModel encodingWindowViewModel)
            : base(encodingWindowViewModel)
        {
            this.fallbackEncoderChoices = new List <AudioEncoderViewModel>();

            IObservable <IChangeSet <AudioEncodingViewModel> > audioEncodingsObservable = this.audioEncodings.Connect();

            audioEncodingsObservable.Bind(this.AudioEncodingsBindable).Subscribe();

            IObservable <IChangeSet <AudioOutputPreview> > audioOutputPreviewObservable = this.audioOutputPreviews.Connect();

            audioOutputPreviewObservable.Bind(this.AudioOutputPreviewsBindable).Subscribe();

            // HasAudioTracks
            audioOutputPreviewObservable
            .Count()
            .StartWith(this.audioOutputPreviews.Count)
            .Select(c => c > 0)
            .ToProperty(this, x => x.HasAudioTracks, out this.hasAudioTracks);

            this.main.WhenAnyValue(x => x.SelectedTitle)
            .Skip(1)
            .Subscribe(_ =>
            {
                this.NotifyAudioInputChanged();
            });

            this.main.AudioTracks
            .Connect()
            .WhenAnyPropertyChanged()
            .Subscribe(_ =>
            {
                this.NotifyAudioInputChanged();
            });

            this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.ContainerName)
            .Skip(1)
            .Subscribe(_ =>
            {
                this.RefreshFallbackEncoderChoices();
                this.RefreshCopyMaskChoices();
            });

            this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile)
            .Subscribe(Observer.Create((VCProfile _) =>
            {
                this.OnProfileChanged();
            }));

            // AutoPassthroughSettingsVisible
            audioEncodingsObservable
            .WhenAnyPropertyChanged(nameof(AudioEncodingViewModel.SelectedAudioEncoder), nameof(AudioEncodingViewModel.SelectedPassthrough))
            .Subscribe(_ =>
            {
                this.RaisePropertyChanged(nameof(this.AutoPassthroughSettingsVisible));
            });

            audioEncodingsObservable.Subscribe(changeSet =>
            {
                if (changeSet.Adds > 0 || changeSet.Removes > 0)
                {
                    this.RaisePropertyChanged(nameof(this.AutoPassthroughSettingsVisible));
                }
            });

            this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.AudioEncoderFallback)
            .Subscribe(audioEncoderFallback =>
            {
                if (!this.userUpdatingFallbackEncoder)
                {
                    this.audioEncoderFallback = this.fallbackEncoderChoices.FirstOrDefault(c => c.Encoder.ShortName == audioEncoderFallback);
                    if (this.audioEncoderFallback == null)
                    {
                        this.audioEncoderFallback = this.fallbackEncoderChoices[0];
                    }

                    this.RaisePropertyChanged(nameof(this.AudioEncoderFallback));
                }
            });

            // Make user updates change the profile
            IObservable <IChangeSet <CopyMaskChoiceViewModel> > copyMaskChoicesObservable = this.copyMaskChoices.Connect();

            copyMaskChoicesObservable.Bind(this.CopyMaskChoicesBindable).Subscribe();
            copyMaskChoicesObservable.WhenValueChanged(choice => choice.Enabled, notifyOnInitialValue: false).Subscribe(_ =>
            {
                this.userUpdatingCopyMask = true;
                this.SaveCopyMasksToProfile();
                this.userUpdatingCopyMask = false;

                this.RefreshAudioPreview();
            });

            // Make profile changes update the local mask choices
            this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.AudioCopyMask)
            .Subscribe(audioCopyMask =>
            {
                if (this.userUpdatingCopyMask)
                {
                    return;
                }

                this.copyMaskChoices.Edit(copyMaskChoicesInnerList =>
                {
                    copyMaskChoicesInnerList.Clear();

                    HBContainer container = HandBrakeEncoderHelpers.GetContainer(this.EncodingWindowViewModel.Profile.ContainerName);
                    foreach (HBAudioEncoder encoder in HandBrakeEncoderHelpers.AudioEncoders)
                    {
                        if ((encoder.CompatibleContainers & container.Id) > 0 && encoder.IsPassthrough && encoder.ShortName != AudioEncodingViewModel.AutoPassthroughEncoder)
                        {
                            bool enabled = true;
                            string codec = encoder.ShortName.Substring(5);

                            if (audioCopyMask != null)
                            {
                                CopyMaskChoice profileMaskChoice = audioCopyMask.FirstOrDefault(choice => choice.Codec == codec);
                                if (profileMaskChoice != null)
                                {
                                    enabled = profileMaskChoice.Enabled;
                                }
                            }

                            copyMaskChoicesInnerList.Add(new CopyMaskChoiceViewModel(codec, enabled));
                        }
                    }
                });

                this.RefreshAudioPreview();
            });

            this.RegisterProfileProperties();
        }
コード例 #2
0
        public AudioPanelViewModel(EncodingWindowViewModel encodingWindowViewModel)
            : base(encodingWindowViewModel)
        {
            this.audioOutputPreviews = new ReactiveList <AudioOutputPreview>();
            this.audioEncodings      = new ReactiveList <AudioEncodingViewModel>();
            this.audioEncodings.ChangeTrackingEnabled = true;

            this.fallbackEncoderChoices = new List <AudioEncoderViewModel>();

            this.audioOutputPreviews.CountChanged
            .Select(c => c > 0)
            .Subscribe(hasAudioTracks =>
            {
                this.HasAudioTracks = hasAudioTracks;
            });

            this.AddAudioEncoding = ReactiveCommand.Create();
            this.AddAudioEncoding.Subscribe(_ => this.AddAudioEncodingImpl());

            this.main.WhenAnyValue(x => x.SelectedTitle)
            .Skip(1)
            .Subscribe(_ =>
            {
                this.NotifyAudioInputChanged();
            });

            this.main.AudioChoiceChanged += (o, e) =>
            {
                this.NotifyAudioInputChanged();
            };

            this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.ContainerName)
            .Skip(1)
            .Subscribe(_ =>
            {
                this.RefreshFallbackEncoderChoices();
                this.RefreshCopyMaskChoices();
            });

            this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile)
            .Subscribe(Observer.Create((VCProfile _) =>
            {
                this.OnProfileChanged();
            }));

            // AutoPassthroughSettingsVisible
            AudioEncodingViewModel audioEncodingViewModel;

            this.audioEncodings.ItemChanged
            .Where(x => x.PropertyName == nameof(audioEncodingViewModel.SelectedAudioEncoder) || x.PropertyName == nameof(audioEncodingViewModel.SelectedPassthrough))
            .Subscribe(_ =>
            {
                this.RaisePropertyChanged(nameof(this.AutoPassthroughSettingsVisible));
            });
            this.audioEncodings.Changed
            .Subscribe(_ =>
            {
                this.RaisePropertyChanged(nameof(this.AutoPassthroughSettingsVisible));
            });

            this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.AudioEncoderFallback)
            .Subscribe(audioEncoderFallback =>
            {
                if (!this.userUpdatingFallbackEncoder)
                {
                    this.audioEncoderFallback = this.fallbackEncoderChoices.FirstOrDefault(c => c.Encoder.ShortName == audioEncoderFallback);
                    if (this.audioEncoderFallback == null)
                    {
                        this.audioEncoderFallback = this.fallbackEncoderChoices[0];
                    }

                    this.RaisePropertyChanged(nameof(this.AudioEncoderFallback));
                }
            });

            // Make user updates change the profile
            CopyMaskChoiceViewModel copyMaskChoiceViewModel;

            this.CopyMaskChoices.ChangeTrackingEnabled = true;
            this.CopyMaskChoices.ItemChanged
            .Where(x => x.PropertyName == nameof(copyMaskChoiceViewModel.Enabled))
            .Subscribe(_ =>
            {
                this.userUpdatingCopyMask = true;
                this.SaveCopyMasksToProfile();
                this.userUpdatingCopyMask = false;

                this.RefreshAudioPreview();
            });

            // Make profile changes update the local mask choices
            this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.AudioCopyMask)
            .Subscribe(audioCopyMask =>
            {
                if (this.userUpdatingCopyMask)
                {
                    return;
                }

                using (this.CopyMaskChoices.SuppressChangeNotifications())
                {
                    this.CopyMaskChoices.Clear();

                    HBContainer container = HandBrakeEncoderHelpers.GetContainer(this.EncodingWindowViewModel.Profile.ContainerName);
                    foreach (HBAudioEncoder encoder in HandBrakeEncoderHelpers.AudioEncoders)
                    {
                        if ((encoder.CompatibleContainers & container.Id) > 0 && encoder.IsPassthrough && encoder.ShortName != AudioEncodingViewModel.AutoPassthroughEncoder)
                        {
                            bool enabled = true;
                            string codec = encoder.ShortName.Substring(5);

                            if (audioCopyMask != null)
                            {
                                CopyMaskChoice profileMaskChoice = audioCopyMask.FirstOrDefault(choice => choice.Codec == codec);
                                if (profileMaskChoice != null)
                                {
                                    enabled = profileMaskChoice.Enabled;
                                }
                            }

                            this.CopyMaskChoices.Add(new CopyMaskChoiceViewModel(codec, enabled));
                        }
                    }
                }

                this.RefreshAudioPreview();
            });

            this.RegisterProfileProperties();
        }