Example #1
0
        private void OnProfileChanged()
        {
            foreach (var audioEncodingViewModel in this.audioEncodings.Items)
            {
                audioEncodingViewModel.Dispose();
            }

            this.audioEncodings.Edit(audioEncodingsInnerList =>
            {
                audioEncodingsInnerList.Clear();
                foreach (AudioEncoding audioEncoding in this.Profile.AudioEncodings)
                {
                    audioEncodingsInnerList.Add(new AudioEncodingViewModel(audioEncoding, this.MainViewModel.SelectedTitle?.Title, this.MainViewModel.GetChosenAudioTracks(), this));
                }
            });

            this.RefreshAudioPreview();
            this.RefreshFallbackEncoderChoices();
            this.RefreshCopyMaskChoices();

            this.audioEncoderFallback = this.FallbackEncoderChoices.SingleOrDefault(e => e.Encoder.ShortName == this.Profile.AudioEncoderFallback);
            if (this.audioEncoderFallback == null)
            {
                this.audioEncoderFallback = this.FallbackEncoderChoices[0];
            }
        }
Example #2
0
        /// <summary>
        /// Gets the audio encoder to use, given the main encoder choice and the passthrough choice. The generic "Passthrough" choice
        /// on the main encoder picker is split out into the specific types via the "scope" dropdown.
        /// </summary>
        /// <param name="audioEncoderViewModel">The chosen audio encoder.</param>
        /// <param name="passthrough">The short encoder id of the passthrough option.</param>
        /// <returns></returns>
        private static HBAudioEncoder GetHBAudioEncoder(AudioEncoderViewModel audioEncoderViewModel, string passthrough)
        {
            if (audioEncoderViewModel == null)
            {
                return(null);
            }

            if (audioEncoderViewModel.IsPassthrough)
            {
                return(HandBrakeEncoderHelpers.GetAudioEncoder(passthrough));
            }

            return(audioEncoderViewModel.Encoder);
        }
Example #3
0
        public void NotifyProfileChanged()
        {
            this.audioEncodings.Clear();
            foreach (AudioEncoding audioEncoding in this.Profile.AudioEncodings)
            {
                this.audioEncodings.Add(new AudioEncodingViewModel(audioEncoding, this.MainViewModel.SelectedTitle, this.MainViewModel.GetChosenAudioTracks(), this.Profile.ContainerName, this));
            }

            this.audioOutputPreviews.Clear();
            this.RefreshAudioPreview();
            this.UpdateAudioEncodings();
            this.RefreshFallbackEncoderChoices();

            this.selectedFallbackEncoder = this.FallbackEncoderChoices.SingleOrDefault(e => e.Encoder.ShortName == this.Profile.AudioEncoderFallback);
            if (this.selectedFallbackEncoder == null)
            {
                this.selectedFallbackEncoder = this.FallbackEncoderChoices[0];
            }
        }
Example #4
0
        private void RefreshFallbackEncoderChoices()
        {
            if (this.EncodingWindowViewModel.Profile == null)
            {
                return;
            }

            HBContainer    container  = HandBrakeEncoderHelpers.GetContainer(this.EncodingWindowViewModel.Profile.ContainerName);
            HBAudioEncoder oldEncoder = null;

            if (this.audioEncoderFallback != null)
            {
                oldEncoder = this.audioEncoderFallback.Encoder;
            }

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

            this.FallbackEncoderChoices.Add(new AudioEncoderViewModel {
                Encoder = HandBrakeEncoderHelpers.GetAudioEncoder("none")
            });

            foreach (HBAudioEncoder encoder in HandBrakeEncoderHelpers.AudioEncoders)
            {
                if ((encoder.CompatibleContainers & container.Id) > 0 && !encoder.IsPassthrough)
                {
                    this.FallbackEncoderChoices.Add(new AudioEncoderViewModel {
                        Encoder = encoder
                    });
                }
            }

            this.RaisePropertyChanged(nameof(this.FallbackEncoderChoices));

            this.audioEncoderFallback = this.FallbackEncoderChoices.FirstOrDefault(e => e.Encoder == oldEncoder);

            if (this.audioEncoderFallback == null)
            {
                this.audioEncoderFallback = this.FallbackEncoderChoices[1];
            }

            this.RaisePropertyChanged(nameof(this.AudioEncoderFallback));
        }
Example #5
0
        private void RefreshFallbackEncoderChoices()
        {
            if (this.EncodingViewModel.EncodingProfile == null)
            {
                return;
            }

            HBContainer    container  = Encoders.GetContainer(this.EncodingViewModel.EncodingProfile.ContainerName);
            HBAudioEncoder oldEncoder = null;

            if (this.selectedFallbackEncoder != null)
            {
                oldEncoder = this.selectedFallbackEncoder.Encoder;
            }

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

            foreach (HBAudioEncoder encoder in Encoders.AudioEncoders)
            {
                if ((encoder.CompatibleContainers & container.Id) > 0 && !encoder.IsPassthrough)
                {
                    this.FallbackEncoderChoices.Add(new AudioEncoderViewModel {
                        Encoder = encoder
                    });
                }
            }

            this.RaisePropertyChanged(() => this.FallbackEncoderChoices);

            this.selectedFallbackEncoder = this.FallbackEncoderChoices.FirstOrDefault(e => e.Encoder == oldEncoder);

            if (this.selectedFallbackEncoder == null)
            {
                this.selectedFallbackEncoder = this.FallbackEncoderChoices[0];
            }

            this.RaisePropertyChanged(() => this.SelectedFallbackEncoder);
        }
Example #6
0
		private void RefreshEncoderChoices()
		{
			HBContainer container = Encoders.GetContainer(this.containerName);
			AudioEncoderViewModel oldEncoder = null;
			string oldPassthrough = null;
			if (this.selectedAudioEncoder != null)
			{
				oldEncoder = this.selectedAudioEncoder;
				oldPassthrough = this.selectedPassthrough;
			}

			var resourceManager = new ResourceManager(typeof(EncodingRes));

			this.audioEncoders = new List<AudioEncoderViewModel>();
			this.audioEncoders.Add(new AudioEncoderViewModel { IsPassthrough = true });

			this.passthroughChoices = new List<ComboChoice>();
			this.passthroughChoices.Add(new ComboChoice("copy", EncodingRes.Passthrough_any));

			foreach (HBAudioEncoder encoder in Encoders.AudioEncoders)
			{
				if ((encoder.CompatibleContainers & container.Id) > 0)
				{
					if (encoder.IsPassthrough)
					{
						if (encoder.ShortName.Contains(":"))
						{
							string inputCodec = encoder.ShortName.Split(':')[1];
							string display = resourceManager.GetString("Passthrough_" + inputCodec);

							this.passthroughChoices.Add(new ComboChoice(encoder.ShortName, display));
						}
					}
					else
					{
						this.AudioEncoders.Add(new AudioEncoderViewModel { Encoder = encoder });
					}
				}
			}

			this.RaisePropertyChanged(() => this.AudioEncoders);
			this.RaisePropertyChanged(() => this.PassthroughChoices);

			if (oldEncoder == null)
			{
				this.selectedAudioEncoder = this.audioEncoders[1];
			}
			else
			{
				if (oldEncoder.IsPassthrough)
				{
					this.selectedAudioEncoder = this.audioEncoders[0];
					this.selectedPassthrough = oldPassthrough;
				}
				else
				{
					this.selectedAudioEncoder = this.audioEncoders.Skip(1).FirstOrDefault(e => e.Encoder == oldEncoder.Encoder);
					this.selectedPassthrough = "copy";
				}
			}

			if (this.selectedAudioEncoder == null)
			{
				this.selectedAudioEncoder = this.audioEncoders[1];
			}

			this.RaisePropertyChanged(() => this.SelectedAudioEncoder);
			this.RaisePropertyChanged(() => this.SelectedPassthrough);
			this.RaisePropertyChanged(() => this.AutoPassthroughSettingsVisible);
		}
Example #7
0
		public AudioEncodingViewModel(AudioEncoding audioEncoding, Title selectedTitle, List<int> chosenAudioTracks, string containerName, AudioPanelViewModel audioPanelVM)
		{
			this.initializing = true;
			this.audioPanelVM = audioPanelVM;

			this.targetStreams = new ObservableCollection<TargetStreamViewModel>();
			this.targetStreamIndex = audioEncoding.InputNumber;

			this.SetChosenTracks(chosenAudioTracks, selectedTitle);

			this.audioEncoders = new List<AudioEncoderViewModel>();
			this.mixdownChoices = new List<MixdownViewModel>();

			this.containerName = containerName;
			this.RefreshEncoderChoices();

			HBAudioEncoder hbAudioEncoder = Encoders.GetAudioEncoder(audioEncoding.Encoder);
			if (hbAudioEncoder.IsPassthrough)
			{
				this.selectedAudioEncoder = this.audioEncoders[0];
				this.selectedPassthrough = audioEncoding.Encoder;
			}
			else
			{
				this.selectedAudioEncoder = this.audioEncoders.Skip(1).FirstOrDefault(e => e.Encoder.ShortName == audioEncoding.Encoder);
				this.selectedPassthrough = "copy";
			}

			if (this.selectedAudioEncoder == null)
			{
				this.selectedAudioEncoder = this.audioEncoders[1];
			}

			this.RefreshMixdownChoices();
			this.RefreshBitrateChoices();
			this.RefreshSampleRateChoices();

			this.SelectMixdown(Encoders.GetMixdown(audioEncoding.Mixdown));

			this.sampleRate = audioEncoding.SampleRateRaw;

			if (!this.HBAudioEncoder.SupportsQuality)
			{
				this.encodeRateType = AudioEncodeRateType.Bitrate;
			}
			else
			{
				this.encodeRateType = audioEncoding.EncodeRateType;
			}

			this.audioQuality = audioEncoding.Quality;

			if (audioEncoding.Compression >= 0)
			{
				this.audioCompression = audioEncoding.Compression;
			}
			else
			{
				this.audioCompression = this.HBAudioEncoder.DefaultCompression;
			}

			this.selectedBitrate = this.BitrateChoices.SingleOrDefault(b => b.Bitrate == audioEncoding.Bitrate);
			if (this.selectedBitrate == null)
			{
				this.selectedBitrate = this.BitrateChoices.First();
			}

			this.gain = audioEncoding.Gain;
			this.drc = audioEncoding.Drc;
			this.passthroughIfPossible = audioEncoding.PassthroughIfPossible;
			this.name = audioEncoding.Name;

			Messenger.Default.Register<SelectedTitleChangedMessage>(
				this,
				message =>
					{
						this.RefreshMixdownChoices();
						this.RefreshBitrateChoices();
						this.RefreshDrc();
					});

			Messenger.Default.Register<AudioInputChangedMessage>(
				this,
				message =>
					{
						this.RefreshMixdownChoices();
						this.RefreshBitrateChoices();
						this.RefreshDrc();
					});

			Messenger.Default.Register<OptionsChangedMessage>(
				this,
				message =>
					{
						this.RaisePropertyChanged(() => this.NameVisible);
					});

			Messenger.Default.Register<ContainerChangedMessage>(
				this,
				message =>
					{
						this.containerName = message.ContainerName;
						this.RefreshEncoderChoices();
					});

			this.initializing = false;
		}
Example #8
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();
        }
        private void RefreshEncoderChoices()
        {
            HBContainer           container  = Encoders.GetContainer(this.containerName);
            AudioEncoderViewModel oldEncoder = null;
            string oldPassthrough            = null;

            if (this.selectedAudioEncoder != null)
            {
                oldEncoder     = this.selectedAudioEncoder;
                oldPassthrough = this.selectedPassthrough;
            }

            var resourceManager = new ResourceManager(typeof(EncodingRes));

            this.audioEncoders = new List <AudioEncoderViewModel>();
            this.audioEncoders.Add(new AudioEncoderViewModel {
                IsPassthrough = true
            });

            this.passthroughChoices = new List <ComboChoice>();
            this.passthroughChoices.Add(new ComboChoice("copy", EncodingRes.Passthrough_any));

            foreach (HBAudioEncoder encoder in Encoders.AudioEncoders)
            {
                if ((encoder.CompatibleContainers & container.Id) > 0)
                {
                    if (encoder.IsPassthrough)
                    {
                        if (encoder.ShortName.Contains(":"))
                        {
                            string inputCodec = encoder.ShortName.Split(':')[1];
                            string display    = resourceManager.GetString("Passthrough_" + inputCodec);

                            this.passthroughChoices.Add(new ComboChoice(encoder.ShortName, display));
                        }
                    }
                    else
                    {
                        this.AudioEncoders.Add(new AudioEncoderViewModel {
                            Encoder = encoder
                        });
                    }
                }
            }

            this.RaisePropertyChanged(() => this.AudioEncoders);
            this.RaisePropertyChanged(() => this.PassthroughChoices);

            if (oldEncoder == null)
            {
                this.selectedAudioEncoder = this.audioEncoders[1];
            }
            else
            {
                if (oldEncoder.IsPassthrough)
                {
                    this.selectedAudioEncoder = this.audioEncoders[0];
                    this.selectedPassthrough  = oldPassthrough;
                }
                else
                {
                    this.selectedAudioEncoder = this.audioEncoders.Skip(1).FirstOrDefault(e => e.Encoder == oldEncoder.Encoder);
                    this.selectedPassthrough  = "copy";
                }
            }

            if (this.selectedAudioEncoder == null)
            {
                this.selectedAudioEncoder = this.audioEncoders[1];
            }

            this.RaisePropertyChanged(() => this.SelectedAudioEncoder);
            this.RaisePropertyChanged(() => this.SelectedPassthrough);
            this.RaisePropertyChanged(() => this.AutoPassthroughSettingsVisible);
        }
        public AudioEncodingViewModel(AudioEncoding audioEncoding, Title selectedTitle, List <int> chosenAudioTracks, string containerName, AudioPanelViewModel audioPanelVM)
        {
            this.initializing = true;
            this.audioPanelVM = audioPanelVM;

            this.targetStreams     = new ObservableCollection <TargetStreamViewModel>();
            this.targetStreamIndex = audioEncoding.InputNumber;

            this.SetChosenTracks(chosenAudioTracks, selectedTitle);

            this.audioEncoders  = new List <AudioEncoderViewModel>();
            this.mixdownChoices = new List <MixdownViewModel>();

            this.containerName = containerName;
            this.RefreshEncoderChoices();

            HBAudioEncoder hbAudioEncoder = Encoders.GetAudioEncoder(audioEncoding.Encoder);

            if (hbAudioEncoder.IsPassthrough)
            {
                this.selectedAudioEncoder = this.audioEncoders[0];
                this.selectedPassthrough  = audioEncoding.Encoder;
            }
            else
            {
                this.selectedAudioEncoder = this.audioEncoders.Skip(1).FirstOrDefault(e => e.Encoder.ShortName == audioEncoding.Encoder);
                this.selectedPassthrough  = "copy";
            }

            if (this.selectedAudioEncoder == null)
            {
                this.selectedAudioEncoder = this.audioEncoders[1];
            }

            this.RefreshMixdownChoices();
            this.RefreshBitrateChoices();
            this.RefreshSampleRateChoices();

            this.SelectMixdown(Encoders.GetMixdown(audioEncoding.Mixdown));

            this.sampleRate = audioEncoding.SampleRateRaw;

            if (!this.HBAudioEncoder.SupportsQuality)
            {
                this.encodeRateType = AudioEncodeRateType.Bitrate;
            }
            else
            {
                this.encodeRateType = audioEncoding.EncodeRateType;
            }

            this.audioQuality = audioEncoding.Quality;

            if (audioEncoding.Compression >= 0)
            {
                this.audioCompression = audioEncoding.Compression;
            }
            else
            {
                this.audioCompression = this.HBAudioEncoder.DefaultCompression;
            }

            this.selectedBitrate = this.BitrateChoices.SingleOrDefault(b => b.Bitrate == audioEncoding.Bitrate);
            if (this.selectedBitrate == null)
            {
                this.selectedBitrate = this.BitrateChoices.First();
            }

            this.gain = audioEncoding.Gain;
            this.drc  = audioEncoding.Drc;
            this.passthroughIfPossible = audioEncoding.PassthroughIfPossible;
            this.name = audioEncoding.Name;

            Messenger.Default.Register <SelectedTitleChangedMessage>(
                this,
                message =>
            {
                this.RefreshMixdownChoices();
                this.RefreshBitrateChoices();
                this.RefreshDrc();
            });

            Messenger.Default.Register <AudioInputChangedMessage>(
                this,
                message =>
            {
                this.RefreshMixdownChoices();
                this.RefreshBitrateChoices();
                this.RefreshDrc();
            });

            Messenger.Default.Register <OptionsChangedMessage>(
                this,
                message =>
            {
                this.RaisePropertyChanged(() => this.NameVisible);
            });

            Messenger.Default.Register <ContainerChangedMessage>(
                this,
                message =>
            {
                this.containerName = message.ContainerName;
                this.RefreshEncoderChoices();
            });

            this.initializing = false;
        }
        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();
        }
Example #12
0
        private void RefreshEncoderChoices(bool isContainerChange = false)
        {
            HBContainer           container  = HandBrakeEncoderHelpers.GetContainer(this.presetsService.SelectedPreset.Preset.EncodingProfile.ContainerName);
            AudioEncoderViewModel oldEncoder = null;
            string oldPassthrough            = null;

            if (this.selectedAudioEncoder != null)
            {
                oldEncoder     = this.selectedAudioEncoder;
                oldPassthrough = this.selectedPassthrough;
            }

            var resourceManager = new ResourceManager(typeof(EncodingRes));

            this.audioEncoders = new List <AudioEncoderViewModel>();
            //this.audioEncoders.Add(new AudioEncoderViewModel { IsPassthrough = true });

            this.passthroughChoices = new List <ComboChoice>();
            this.passthroughChoices.Add(new ComboChoice(AutoPassthroughEncoder, EncodingRes.Passthrough_auto));

            bool anyCodecSupportsPassthrough = false;

            foreach (HBAudioEncoder encoder in HandBrakeEncoderHelpers.AudioEncoders)
            {
                if ((encoder.CompatibleContainers & container.Id) > 0)
                {
                    if (encoder.IsPassthrough)
                    {
                        if (encoder.ShortName.Contains(":"))
                        {
                            string inputCodec = encoder.ShortName.Split(':')[1];
                            string display    = resourceManager.GetString("Passthrough_" + inputCodec);

                            if (string.IsNullOrEmpty(display))
                            {
                                display = encoder.DisplayName;
                            }

                            this.passthroughChoices.Add(new ComboChoice(encoder.ShortName, display));
                        }

                        anyCodecSupportsPassthrough = true;
                    }
                    else
                    {
                        this.AudioEncoders.Add(new AudioEncoderViewModel {
                            Encoder = encoder
                        });
                    }
                }
            }

            if (anyCodecSupportsPassthrough)
            {
                this.audioEncoders.Insert(0, new AudioEncoderViewModel {
                    IsPassthrough = true
                });
            }

            this.RaisePropertyChanged(nameof(this.PassthroughChoices));
            this.RaisePropertyChanged(nameof(this.AudioEncoders));

            if (oldEncoder == null)
            {
                this.selectedAudioEncoder = this.audioEncoders[1];
            }
            else
            {
                if (oldEncoder.IsPassthrough)
                {
                    this.selectedAudioEncoder = this.audioEncoders[0];
                    this.selectedPassthrough  = oldPassthrough;
                }
                else
                {
                    this.selectedAudioEncoder = this.audioEncoders.Skip(1).FirstOrDefault(e => e.Encoder == oldEncoder.Encoder);
                    this.selectedPassthrough  = "copy";
                }
            }

            if (this.selectedAudioEncoder == null)
            {
                this.selectedAudioEncoder = this.audioEncoders[1];
            }

            // If it's a container change we need to commit the new encoder change.
            if (isContainerChange && this.selectedAudioEncoder != oldEncoder)
            {
                this.RaiseAudioEncodingChanged();
            }

            this.RaisePropertyChanged(nameof(this.SelectedAudioEncoder));
            this.RaisePropertyChanged(nameof(this.SelectedPassthrough));
        }
Example #13
0
        public AudioEncodingViewModel(AudioEncoding audioEncoding, SourceTitle selectedTitle, List <int> chosenAudioTracks, AudioPanelViewModel audioPanelVM)
        {
            this.initializing = true;
            this.audioPanelVM = audioPanelVM;

            this.targetStreams     = new ObservableCollection <TargetStreamViewModel>();
            this.targetStreamIndex = audioEncoding.InputNumber;

            this.SetChosenTracks(chosenAudioTracks, selectedTitle);

            this.audioEncoders  = new List <AudioEncoderViewModel>();
            this.mixdownChoices = new List <MixdownViewModel>();

            this.RefreshEncoderChoices();

            this.presetChangeSubscription = this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile)
                                            .Subscribe(profile =>
            {
                this.containerSubscription?.Dispose();

                this.containerSubscription = profile.WhenAnyValue(x => x.ContainerName)
                                             .Skip(1)
                                             .Subscribe(_ =>
                {
                    this.RefreshEncoderChoices(isContainerChange: true);
                });

                this.audioPanelVM.SuppressProfileEdits = true;
                this.RefreshEncoderChoices();
                this.audioPanelVM.SuppressProfileEdits = false;
            });

            HBAudioEncoder hbAudioEncoder = HandBrakeEncoderHelpers.GetAudioEncoder(audioEncoding.Encoder);

            if (hbAudioEncoder.IsPassthrough)
            {
                this.selectedAudioEncoder = this.audioEncoders[0];
                this.selectedPassthrough  = audioEncoding.Encoder;
            }
            else
            {
                this.selectedAudioEncoder = this.audioEncoders.Skip(1).FirstOrDefault(e => e.Encoder.ShortName == audioEncoding.Encoder);
                this.selectedPassthrough  = "copy";
            }

            if (this.selectedAudioEncoder == null)
            {
                this.selectedAudioEncoder = this.audioEncoders[1];
            }

            this.RefreshMixdownChoices();
            this.RefreshBitrateChoices();
            this.RefreshSampleRateChoices();

            this.SelectMixdown(HandBrakeEncoderHelpers.GetMixdown(audioEncoding.Mixdown));

            this.sampleRate = audioEncoding.SampleRateRaw;

            if (!this.HBAudioEncoder.SupportsQuality)
            {
                this.encodeRateType = AudioEncodeRateType.Bitrate;
            }
            else
            {
                this.encodeRateType = audioEncoding.EncodeRateType;
            }

            this.audioQuality = audioEncoding.Quality;

            if (audioEncoding.Compression >= 0)
            {
                this.audioCompression = audioEncoding.Compression;
            }
            else
            {
                this.audioCompression = this.HBAudioEncoder.DefaultCompression;
            }

            this.selectedBitrate = this.BitrateChoices.SingleOrDefault(b => b.Bitrate == audioEncoding.Bitrate);
            if (this.selectedBitrate == null)
            {
                this.selectedBitrate = this.BitrateChoices.First();
            }

            this.gain = audioEncoding.Gain;
            this.drc  = audioEncoding.Drc;
            this.passthroughIfPossible = audioEncoding.PassthroughIfPossible;
            this.name = audioEncoding.Name;

            // EncoderSettingsVisible
            this.WhenAnyValue(x => x.SelectedAudioEncoder, x => x.SelectedPassthrough, (audioEncoder, passthrough) =>
            {
                if (audioEncoder == null)
                {
                    return(false);
                }

                if (passthrough == null)
                {
                    return(false);
                }

                return(!GetHBAudioEncoder(audioEncoder, passthrough).IsPassthrough);
            }).ToProperty(this, x => x.EncoderSettingsVisible, out this.encoderSettingsVisible);

            // AudioCompressionVisible
            this.WhenAnyValue(x => x.SelectedAudioEncoder, audioEncoder =>
            {
                return(!audioEncoder.IsPassthrough && audioEncoder.Encoder.SupportsCompression);
            }).ToProperty(this, x => x.AudioCompressionVisible, out this.audioCompressionVisible);

            // PassthroughIfPossibleVisible
            this.WhenAnyValue(x => x.SelectedAudioEncoder, audioEncoder =>
            {
                if (audioEncoder.IsPassthrough)
                {
                    return(false);
                }

                if (HandBrakeEncoderHelpers.AudioEncoders.Any(e => e.Id == (NativeConstants.HB_ACODEC_PASS_FLAG | audioEncoder.Encoder.Id)))
                {
                    return(true);
                }

                return(audioEncoder.Encoder.ShortName.ToLowerInvariant().Contains("aac") || audioEncoder.Encoder.ShortName.ToLowerInvariant().Contains("mp3"));
            }).ToProperty(this, x => x.PassthroughIfPossibleVisible, out this.passthroughIfPossibleVisible);

            // BitrateVisible
            this.WhenAnyValue(
                x => x.SelectedAudioEncoder,
                x => x.EncoderSettingsVisible,
                x => x.SelectedMixdown,
                x => x.EncodeRateType,
                (audioEncoder, encoderSettingsVisible, mixdown, encodeRateType) =>
            {
                if (audioEncoder.IsPassthrough)
                {
                    return(false);
                }

                if (encoderSettingsVisible && mixdown != null && encodeRateType == AudioEncodeRateType.Bitrate)
                {
                    // We only need to find out if the bitrate limits exist, so pass in some normal values for sample rate and mixdown.
                    BitrateLimits bitrateLimits = HandBrakeEncoderHelpers.GetBitrateLimits(audioEncoder.Encoder, 48000, HandBrakeEncoderHelpers.GetMixdown("dpl2"));
                    return(bitrateLimits.High > 0);
                }

                return(false);
            }).ToProperty(this, x => x.BitrateVisible, out this.bitrateVisible);

            // BitrateLabelVisible
            this.WhenAnyValue(x => x.BitrateVisible, x => x.SelectedAudioEncoder, (bitrateVisible, audioEncoder) =>
            {
                return(!audioEncoder.IsPassthrough && bitrateVisible && !audioEncoder.Encoder.SupportsQuality);
            }).ToProperty(this, x => x.BitrateLabelVisible, out this.bitrateLabelVisible);

            // AudioQualityVisible
            this.WhenAnyValue(x => x.SelectedAudioEncoder, x => x.EncodeRateType, (audioEncoder, encodeRateType) =>
            {
                return(!audioEncoder.IsPassthrough &&
                       audioEncoder.Encoder.SupportsQuality &&
                       encodeRateType == AudioEncodeRateType.Quality);
            }).ToProperty(this, x => x.AudioQualityVisible, out this.audioQualityVisible);

            // AudioQualityRadioVisible
            this.WhenAnyValue(x => x.SelectedAudioEncoder, audioEncoder =>
            {
                return(!audioEncoder.IsPassthrough && audioEncoder.Encoder.SupportsQuality);
            }).ToProperty(this, x => x.AudioQualityRadioVisible, out this.audioQualityRadioVisible);

            // AudioQualityMinimum
            this.WhenAnyValue(x => x.SelectedAudioEncoder, audioEncoder =>
            {
                if (audioEncoder.IsPassthrough)
                {
                    return(0);
                }

                return(Math.Round(audioEncoder.Encoder.QualityLimits.Low, RangeRoundDigits));
            }).ToProperty(this, x => x.AudioQualityMinimum, out this.audioQualityMinimum);

            // AudioQualityMaximum
            this.WhenAnyValue(x => x.SelectedAudioEncoder, audioEncoder =>
            {
                if (audioEncoder.IsPassthrough)
                {
                    return(0);
                }

                return(Math.Round(audioEncoder.Encoder.QualityLimits.High, RangeRoundDigits));
            }).ToProperty(this, x => x.AudioQualityMaximum, out this.audioQualityMaximum);

            // AudioQualityGranularity
            this.WhenAnyValue(x => x.SelectedAudioEncoder, audioEncoder =>
            {
                if (audioEncoder.IsPassthrough)
                {
                    return(0);
                }

                return(Math.Round(audioEncoder.Encoder.QualityLimits.Granularity, RangeRoundDigits));
            }).ToProperty(this, x => x.AudioQualityGranularity, out this.audioQualityGranularity);

            // AudioQualityToolTip
            this.WhenAnyValue(x => x.SelectedAudioEncoder, audioEncoder =>
            {
                if (audioEncoder.IsPassthrough)
                {
                    return(string.Empty);
                }

                string directionSentence;
                if (audioEncoder.Encoder.QualityLimits.Ascending)
                {
                    directionSentence = EncodingRes.AscendingQualityToolTip;
                }
                else
                {
                    directionSentence = EncodingRes.DescendingQualityToolTip;
                }

                return(string.Format(
                           EncodingRes.AudioQualityToolTip,
                           directionSentence,
                           audioEncoder.Encoder.QualityLimits.Low,
                           audioEncoder.Encoder.QualityLimits.High));
            }).ToProperty(this, x => x.AudioQualityToolTip, out this.audioQualityToolTip);

            // AudioCompressionMinimum
            this.WhenAnyValue(x => x.SelectedAudioEncoder, audioEncoder =>
            {
                if (audioEncoder.IsPassthrough)
                {
                    return(0);
                }

                return(Math.Round(audioEncoder.Encoder.CompressionLimits.Low, RangeRoundDigits));
            }).ToProperty(this, x => x.AudioCompressionMinimum, out this.audioCompressionMinimum);

            // AudioCompressionMaximum
            this.WhenAnyValue(x => x.SelectedAudioEncoder, audioEncoder =>
            {
                if (audioEncoder.IsPassthrough)
                {
                    return(0);
                }

                return(Math.Round(audioEncoder.Encoder.CompressionLimits.High, RangeRoundDigits));
            }).ToProperty(this, x => x.AudioCompressionMaximum, out this.audioCompressionMaximum);

            // AudioCompressionGranularity
            this.WhenAnyValue(x => x.SelectedAudioEncoder, audioEncoder =>
            {
                if (audioEncoder.IsPassthrough)
                {
                    return(0);
                }

                return(Math.Round(audioEncoder.Encoder.CompressionLimits.Granularity, RangeRoundDigits));
            }).ToProperty(this, x => x.AudioCompressionGranularity, out this.audioCompressionGranularity);

            // AudioCompressionToolTip
            this.WhenAnyValue(x => x.SelectedAudioEncoder, audioEncoder =>
            {
                if (audioEncoder.IsPassthrough)
                {
                    return(string.Empty);
                }

                string directionSentence;
                if (audioEncoder.Encoder.QualityLimits.Ascending)
                {
                    directionSentence = EncodingRes.AscendingCompressionToolTip;
                }
                else
                {
                    directionSentence = EncodingRes.DescendingCompressionToolTip;
                }

                return(string.Format(
                           EncodingRes.AudioCompressionToolTip,
                           directionSentence,
                           audioEncoder.Encoder.CompressionLimits.Low,
                           audioEncoder.Encoder.CompressionLimits.High));
            }).ToProperty(this, x => x.AudioCompressionToolTip, out this.audioCompressionToolTip);

            // PassthroughChoicesVisible
            this.WhenAnyValue(x => x.SelectedAudioEncoder, audioEncoder =>
            {
                return(audioEncoder.IsPassthrough);
            }).ToProperty(this, x => x.PassthroughChoicesVisible, out this.passthroughChoicesVisible);

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

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

            Config.Observables.ShowAudioTrackNameField.ToProperty(this, x => x.NameVisible, out this.nameVisible);

            this.initializing = false;
        }
Example #14
0
		public void NotifyProfileChanged()
		{
			this.audioEncodings.Clear();
			foreach (AudioEncoding audioEncoding in this.Profile.AudioEncodings)
			{
				this.audioEncodings.Add(new AudioEncodingViewModel(audioEncoding, this.MainViewModel.SelectedTitle, this.MainViewModel.GetChosenAudioTracks(), this.Profile.ContainerName, this));
			}

			this.audioOutputPreviews.Clear();
			this.RefreshAudioPreview();
			this.UpdateAudioEncodings();
			this.RefreshFallbackEncoderChoices();

			this.selectedFallbackEncoder = this.FallbackEncoderChoices.SingleOrDefault(e => e.Encoder.ShortName == this.Profile.AudioEncoderFallback);
			if (this.selectedFallbackEncoder == null)
			{
				this.selectedFallbackEncoder = this.FallbackEncoderChoices[0];
			}
		}
Example #15
0
		private void RefreshFallbackEncoderChoices()
		{
			if (this.EncodingViewModel.EncodingProfile == null)
			{
				return;
			}

			HBContainer container = Encoders.GetContainer(this.EncodingViewModel.EncodingProfile.ContainerName);
			HBAudioEncoder oldEncoder = null;
			if (this.selectedFallbackEncoder != null)
			{
				oldEncoder = this.selectedFallbackEncoder.Encoder;
			}

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

			foreach (HBAudioEncoder encoder in Encoders.AudioEncoders)
			{
				if ((encoder.CompatibleContainers & container.Id) > 0 && !encoder.IsPassthrough)
				{
					this.FallbackEncoderChoices.Add(new AudioEncoderViewModel { Encoder = encoder });
				}
			}

			this.RaisePropertyChanged(() => this.FallbackEncoderChoices);

			this.selectedFallbackEncoder = this.FallbackEncoderChoices.FirstOrDefault(e => e.Encoder == oldEncoder);

			if (this.selectedFallbackEncoder == null)
			{
				this.selectedFallbackEncoder = this.FallbackEncoderChoices[0];
			}

			this.RaisePropertyChanged(() => this.SelectedFallbackEncoder);
		}