/// ------------------------------------------------------------------------------------ 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 Save(string mediaFileName, TierCollection collection) { var helper = GetOrCreateFile(null, mediaFileName); helper.SaveFromTierCollection(collection); helper.Save(); return(helper.AnnotationFileName); }
/// ------------------------------------------------------------------------------------ public static bool Generate(TierCollection tierCollection, Control parentControlForDialog, bool justClearFileContents) { var timeTier = tierCollection.GetTimeTier(); if (!CanGenerate(timeTier)) { return(false); } try { Program.SuspendBackgroundProcesses(); if (justClearFileContents) { var oralAnnotationFile = timeTier.MediaFileName + Settings.Default.OralAnnotationGeneratedFileSuffix; // SP-699: The process cannot access the file because it is being used by another process if (File.Exists(oralAnnotationFile)) { FileSystemUtils.WaitForFileRelease(oralAnnotationFile); } File.Create(oralAnnotationFile).Dispose(); return(false); } Analytics.Track("Generating Oral Annotation File"); using (var generator = new OralAnnotationFileGenerator(timeTier, tierCollection.GetIsSegmentIgnored, parentControlForDialog)) using (var dlg = new LoadingDlg(GetGeneratingMsg())) { dlg.GenericErrorMessage = GetGenericErrorMsg(); var worker = new BackgroundWorker(); worker.DoWork += generator.CreateInterleavedAudioFile; worker.WorkerSupportsCancellation = true; dlg.BackgroundWorker = worker; dlg.Show(parentControlForDialog); return(dlg.DialogResult == DialogResult.OK); } } catch (Exception error) { ErrorReport.NotifyUserOfProblem(error, GetGenericErrorMsg()); return(false); } finally { Program.ResumeBackgroundProcesses(true); } }
/// ------------------------------------------------------------------------------------ public TierCollection Copy() { var copy = new TierCollection(); copy.AnnotatedMediaFile = AnnotatedMediaFile; foreach (var tier in this) { copy.Add(tier.Copy()); } return(copy); }
/// ------------------------------------------------------------------------------------ public TierCollection GetTierCollection() { var collection = new TierCollection(); var timeSlots = GetTimeSlots(); var transcriptionAnnotations = GetTranscriptionTierAnnotations(); if (transcriptionAnnotations.Count == 0) { return(collection); } var freeTransAnnotations = GetFreeTranslationTierAnnotations(); EnsureMediaFileIsCorrect(); var timeOrderTier = new TimeTier(GetFullPathToMediaFile()); var transcriptionTier = new TextTier(TextTier.ElanTranscriptionTierId); var freeTransTier = new TextTier(TextTier.ElanTranslationTierId); foreach (var kvp in transcriptionAnnotations) { var start = timeSlots[kvp.Value.Attribute("TIME_SLOT_REF1").Value]; var stop = timeSlots[kvp.Value.Attribute("TIME_SLOT_REF2").Value]; timeOrderTier.AddSegment(start, stop); transcriptionTier.AddSegment(kvp.Value.Value); string freeTransValue; freeTransTier.AddSegment(freeTransAnnotations.TryGetValue(kvp.Key, out freeTransValue) ? freeTransValue : string.Empty); } // Add the time and transcription tiers to the collection. collection.Add(timeOrderTier); collection.Add(transcriptionTier); collection.Add(freeTransTier); timeOrderTier.ReadOnlyTimeRanges = GetDoesTranscriptionTierHaveDepedentTimeSubdivisionTier(); return(collection); }
/// ------------------------------------------------------------------------------------ private void SaveFromTierCollection(TierCollection collection) { RemoveTimeSlots(); RemoveAnnotationsFromTier(TextTier.ElanTranscriptionTierId); RemoveAnnotationsFromTier(TextTier.ElanTranslationTierId); var timeTier = collection.GetTimeTier(); if (timeTier == null) { return; } var timeSegments = timeTier.Segments.ToArray(); if (timeSegments.Length == 0) { return; } var transcriptionSegments = collection.GetTranscriptionTier(true).Segments.ToArray(); var freeTranslationSegments = collection.GetFreeTranslationTier(true).Segments.ToArray(); for (int i = 0; i < timeSegments.Length; i++) { var annotationId = CreateTranscriptionAnnotationElement(new AnnotationSegment { Start = timeSegments[i].Start, End = timeSegments[i].End, Text = (i < transcriptionSegments.Length ? transcriptionSegments[i].Text : string.Empty) }); var text = (i < freeTranslationSegments.Length ? freeTranslationSegments[i].Text : string.Empty); CreateFreeTranslationAnnotationElement(annotationId, text); } }