public SubtitleDialogViewModel(Subtitles currentSubtitles) { this.container = Encoders.GetContainer(this.presetsViewModel.SelectedPreset.Preset.EncodingProfile.ContainerName); this.sourceSubtitles = new ObservableCollection <SourceSubtitleViewModel>(); this.srtSubtitles = new ObservableCollection <SrtSubtitleViewModel>(); if (currentSubtitles != null) { if (!currentSubtitles.SourceSubtitles.Any(s => s.TrackNumber == 0)) { this.sourceSubtitles.Add( new SourceSubtitleViewModel( this, new SourceSubtitle { TrackNumber = 0, BurnedIn = false, Forced = false, Default = false })); } foreach (SourceSubtitle subtitle in currentSubtitles.SourceSubtitles) { this.sourceSubtitles.Add(new SourceSubtitleViewModel(this, subtitle.Clone()) { Selected = true }); } foreach (SrtSubtitle subtitle in currentSubtitles.SrtSubtitles) { this.srtSubtitles.Add(new SrtSubtitleViewModel(this, subtitle.Clone())); } } // Fill in remaining unselected source subtitles foreach (Subtitle subtitle in this.mainViewModel.SelectedTitle.Subtitles) { if (!currentSubtitles.SourceSubtitles.Any(s => s.TrackNumber == subtitle.TrackNumber)) { var newSubtitle = new SourceSubtitle { TrackNumber = subtitle.TrackNumber, Default = false, Forced = false, BurnedIn = false }; this.sourceSubtitles.Add(new SourceSubtitleViewModel(this, newSubtitle)); } } this.sourceSubtitles.CollectionChanged += this.SourceCollectionChanged; this.srtSubtitles.CollectionChanged += this.SrtCollectionChanged; this.UpdateBoxes(); }
public SourceSubtitleViewModel(SubtitleDialogViewModel subtitleDialogViewModel, SourceSubtitle subtitle) { this.SubtitleDialogViewModel = subtitleDialogViewModel; this.subtitle = subtitle; MessengerInstance.Register <ContainerChangedMessage>(this, m => { this.RefreshBoxes(); }); }
public SourceSubtitleViewModel(SubtitleDialogViewModel subtitleDialogViewModel, SourceSubtitle subtitle) { this.SubtitleDialogViewModel = subtitleDialogViewModel; this.subtitle = subtitle; if (subtitle.TrackNumber != 0) { this.inputSubtitle = this.mainViewModel.SelectedTitle.SubtitleList[subtitle.TrackNumber - 1]; } // CanPass this.presetsService.WhenAnyValue(x => x.SelectedPreset.Preset.EncodingProfile.ContainerName, containerName => { if (this.TrackNumber == 0) { return(true); } return(HandBrakeEncoderHelpers.SubtitleCanPassthrough(this.inputSubtitle.Source, HandBrakeEncoderHelpers.GetContainer(containerName).Id)); }).ToProperty(this, x => x.CanPass, out this.canPass); // BurnedInEnabled this.WhenAnyValue(x => x.CanPass, canPass => { if (this.TrackNumber == 0) { return(true); } if (!canPass) { return(false); } if (!this.CanBurn) { return(false); } return(true); }).ToProperty(this, x => x.BurnedInEnabled, out this.burnedInEnabled); // When BurnedInEnabled changes, refresh to see if it should be updated to a predetermined value. this.WhenAnyValue(x => x.BurnedInEnabled).Subscribe(_ => { this.RaisePropertyChanged(nameof(this.BurnedIn)); }); this.DuplicateSubtitle = ReactiveCommand.Create(); this.DuplicateSubtitle.Subscribe(_ => this.DuplicateSubtitleImpl()); this.RemoveSubtitle = ReactiveCommand.Create(); this.RemoveSubtitle.Subscribe(_ => this.RemoveSubtitleImpl()); }
private void GeneratePreviewImpl() { this.job = this.mainViewModel.EncodeJob; this.PreviewPercentComplete = 0; this.EncodeState = PreviewEncodeState.EncodeStarting; this.cancelPending = false; this.encodeCancelled = false; this.SetPreviewFilePath(); this.job.OutputPath = this.previewFilePath; if (this.job.Subtitles?.SourceSubtitles != null) { SourceSubtitle scanTrack = this.job.Subtitles.SourceSubtitles.FirstOrDefault(s => s.TrackNumber == 0); if (scanTrack != null) { this.job.Subtitles.SourceSubtitles.Remove(scanTrack); } } this.encodeProxy = Utilities.CreateEncodeProxy(); this.encodeProxy.EncodeStarted += (o, e) => { DispatchUtilities.BeginInvoke(() => { this.EncodeState = PreviewEncodeState.Encoding; if (this.cancelPending) { this.CancelPreviewImpl(); } }); }; this.encodeProxy.EncodeProgress += (o, e) => { double totalWeight; double completeWeight; if (e.PassCount == 1) { // Single pass, no subtitle scan totalWeight = 1; completeWeight = e.FractionComplete; } else if (e.PassCount == 2 && e.PassId <= 0) { // Single pass with subtitle scan totalWeight = 1 + SubtitleScanCost; if (e.PassId == -1) { // In subtitle scan completeWeight = e.FractionComplete * SubtitleScanCost; } else { // In normal pass completeWeight = SubtitleScanCost + e.FractionComplete; } } else if (e.PassCount == 2 && e.PassId >= 1) { // Two normal passes totalWeight = 2; if (e.PassId == 1) { // First pass completeWeight = e.FractionComplete; } else { // Second pass completeWeight = 1 + e.FractionComplete; } } else { // Two normal passes with subtitle scan totalWeight = 2 + SubtitleScanCost; if (e.PassId == -1) { // In subtitle scan completeWeight = e.FractionComplete * SubtitleScanCost; } else if (e.PassId == 1) { // First normal pass completeWeight = SubtitleScanCost + e.FractionComplete; } else { // Second normal pass completeWeight = SubtitleScanCost + 1 + e.FractionComplete; } } double fractionComplete = completeWeight / totalWeight; this.PreviewPercentComplete = fractionComplete * 100; }; this.encodeProxy.EncodeCompleted += (o, e) => { DispatchUtilities.BeginInvoke(() => { this.EncodeState = PreviewEncodeState.NotEncoding; if (this.encodeCancelled) { this.logger.Log("Cancelled preview clip generation"); } else { if (e.Error) { this.logger.Log(PreviewRes.PreviewClipGenerationFailedTitle); Utilities.MessageBox.Show(PreviewRes.PreviewClipGenerationFailedMessage); } else { var previewFileInfo = new FileInfo(this.previewFilePath); this.logger.Log("Finished preview clip generation. Size: " + Utilities.FormatFileSize(previewFileInfo.Length)); this.PlayPreview(); } } }); }; this.logger.Log("Generating preview clip"); this.logger.Log(" Path: " + this.job.OutputPath); this.logger.Log(" Title: " + this.job.Title); this.logger.Log(" Preview #: " + this.SelectedPreview); this.encodeProxy.StartEncode(this.job, this.logger, true, this.SelectedPreview, this.PreviewSeconds, this.job.Length.TotalSeconds); }
public SubtitleDialogViewModel(VCSubtitles currentSubtitles) { this.container = HandBrakeEncoderHelpers.GetContainer(this.presetsService.SelectedPreset.Preset.EncodingProfile.ContainerName); this.sourceSubtitles = new ReactiveList <SourceSubtitleViewModel>(); this.srtSubtitles = new ReactiveList <SrtSubtitleViewModel>(); if (currentSubtitles != null) { if (!currentSubtitles.SourceSubtitles.Any(s => s.TrackNumber == 0)) { this.sourceSubtitles.Add( new SourceSubtitleViewModel( this, new SourceSubtitle { TrackNumber = 0, BurnedIn = false, ForcedOnly = false, Default = false })); } foreach (SourceSubtitle subtitle in currentSubtitles.SourceSubtitles) { this.sourceSubtitles.Add(new SourceSubtitleViewModel(this, subtitle.Clone()) { Selected = true }); } foreach (SrtSubtitle subtitle in currentSubtitles.SrtSubtitles) { this.srtSubtitles.Add(new SrtSubtitleViewModel(this, subtitle.Clone())); } } // Fill in remaining unselected source subtitles for (int i = 1; i <= this.mainViewModel.SelectedTitle.SubtitleList.Count; i++) { if (!currentSubtitles.SourceSubtitles.Any(s => s.TrackNumber == i)) { var newSubtitle = new SourceSubtitle { TrackNumber = i, Default = false, ForcedOnly = false, BurnedIn = false }; this.sourceSubtitles.Add(new SourceSubtitleViewModel(this, newSubtitle)); } } // HasSourceSubtitles this.sourceSubtitles.CountChanged.Select(count => count > 0) .ToProperty(this, x => x.HasSourceSubtitles, out this.hasSourceSubtitles, initialValue: this.sourceSubtitles.Count > 0); // AddSourceSubtitleToolTip this.mainViewModel .WhenAnyValue(x => x.SelectedTitle) .Select(selectedTitle => { if (selectedTitle == null || selectedTitle.SubtitleList.Count == 0) { return(SubtitleRes.AddSourceNoSubtitlesToolTip); } return(null); }) .ToProperty(this, x => x.AddSourceSubtitleToolTip, out this.addSourceSubtitleToolTip); // HasSrtSubtitles this.srtSubtitles.CountChanged.Select(count => count > 0) .ToProperty(this, x => x.HasSrtSubtitles, out this.hasSrtSubtitles, initialValue: this.srtSubtitles.Count > 0); this.AddSrtSubtitle = ReactiveCommand.Create(); this.AddSrtSubtitle.Subscribe(_ => this.AddSrtSubtitleImpl()); this.UpdateBoxes(); }