/// ------------------------------------------------------------------------------------ public SegmenterDlgBaseViewModel(ComponentFile file) { ComponentFile = file; OrigWaveStream = new WaveFileReader(ComponentFile.PathToAnnotatedFile); Tiers = file.GetAnnotationFile() != null? file.GetAnnotationFile().Tiers.Copy() : new TierCollection(ComponentFile.PathToAnnotatedFile); TimeTier = Tiers.GetTimeTier(); if (TimeTier == null) { TimeTier = new TimeTier(ComponentFile.PathToAnnotatedFile); Tiers.Insert(0, TimeTier); } OralAnnotationsFolder = ComponentFile.PathToAnnotatedFile + Settings.Default.OralAnnotationsFolderSuffix; TempOralAnnotationsFolder = Path.Combine(Path.GetTempPath(), "SayMoreOralAnnotations"); if (Directory.Exists(TempOralAnnotationsFolder)) { foreach (var tempFile in Directory.EnumerateFiles(TempOralAnnotationsFolder)) { File.Delete(tempFile); } } _oralAnnotationFilesBeforeChanges = GetListOfOralAnnotationSegmentFilesBeforeChanges().ToList(); TimeTier.BackupOralAnnotationSegmentFileAction = BackupOralAnnotationSegmentFile; }
/// ------------------------------------------------------------------------------------ public string Run() { if (_file.GetAnnotationFile() != null) { return(_file.GetAnnotationFile().FileName); // REVIEW: This probably shouldn't happen. Maybe throw an exception. } WaitCursor.Show(); var tiers = new TierCollection(_file.PathToAnnotatedFile); var timeTier = tiers.GetTimeTier(); if (timeTier == null) { timeTier = new TimeTier(_file.PathToAnnotatedFile); tiers.Insert(0, timeTier); } foreach (var segment in GetNaturalBreaks()) { timeTier.AppendSegment((float)segment.TotalSeconds); } StreamReader.Close(); WaitCursor.Hide(); return(tiers.Save()); }
/// ------------------------------------------------------------------------------------ public static string ShowDialog(ComponentFile file, EditorBase parent, int segmentToHighlight) { Exception error; string msg; using (var viewModel = new ManualSegmenterDlgViewModel(file)) using (var dlg = new ManualSegmenterDlg(viewModel, segmentToHighlight)) { try { if (dlg.ShowDialog(parent) != DialogResult.OK || !viewModel.WereChangesMade) { viewModel.DiscardChanges(); return(null); } Analytics.Track("Changes made using Manual Segmentation"); var annotationFile = file.GetAnnotationFile(); if (!viewModel.TimeTier.Segments.Any()) { if (annotationFile != null) { annotationFile.Delete(); parent.RefreshComponentFiles(file.FileName, null); } return(null); } var eafFile = AnnotationFileHelper.Save(file.PathToAnnotatedFile, viewModel.Tiers); if (annotationFile == null) { return(eafFile); } error = annotationFile.TryLoadAndReturnException(); if (error == null) { WaitCursor.Show(); try { annotationFile.AssociatedComponentFile.GenerateOralAnnotationFile(viewModel.Tiers, parent, ComponentFile.GenerateOption.ClearAndRegenerateOnDemand); } finally { WaitCursor.Hide(); } return(eafFile); } msg = LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.SavingSegmentsErrorMsg", "There was an error while trying to save segments for the file '{0}'."); } catch (Exception e) { error = e; msg = LocalizationManager.GetString( "DialogBoxes.Transcription.ManualSegmenterDlg.GeneralSegmentingErrorMsg", "There was an error segmenting the file '{0}'."); } } ErrorReport.NotifyUserOfProblem(error, msg, file.PathToAnnotatedFile); return(null); }