//protected override void CreateProjectFileAndDirectory() //{ //if (!Directory.Exists(m_outDirectory)) //{ //Directory.CreateDirectory(m_outDirectory); //} //m_Xuk_FilePath = m_Session.Path; //} protected override void initializeProject(string path) { //m_Project = new Project(); m_Project = m_Session.Presentation.Project; #if false //(DEBUG) m_Project.PrettyFormat = true; #else m_Project.PrettyFormat = false; #endif //Presentation presentation = m_Project.AddNewPresentation(new Uri(m_outDirectory), Path.GetFileName(m_Book_FilePath)); m_Presentation = m_Session.Presentation; PCMFormatInfo pcmFormat = m_Presentation.MediaDataManager.DefaultPCMFormat.Copy(); pcmFormat.Data.SampleRate = (ushort)m_audioProjectSampleRate; m_Presentation.MediaDataManager.DefaultPCMFormat = pcmFormat; m_Presentation.MediaDataManager.EnforceSinglePCMFormat = true; //m_textChannel = m_Presentation.ChannelFactory.CreateTextChannel(); //m_textChannel.Name = "The Text Channel"; m_textChannel = m_Presentation.ChannelsManager.GetOrCreateTextChannel(); //m_audioChannel = m_Presentation.ChannelFactory.CreateAudioChannel(); //m_audioChannel.Name = "The Audio Channel"; m_audioChannel = m_Presentation.ChannelsManager.GetOrCreateAudioChannel(); m_TitleMetadata = m_Presentation.GetFirstMetadataItem(Metadata.DC_TITLE); m_IdentifierMetadata = m_Presentation.GetFirstMetadataItem(Metadata.DC_IDENTIFIER); m_XmlIdToSectionNodeMap = new Dictionary <string, SectionNode>(); m_XmlIdToPageNodeMap = new Dictionary <string, EmptyNode>(); }
public bool ImportFromCSVFile(string CSVFullPath, ObiPresentation presentation, Obi.ProjectView.ProjectView projectView = null) { List <string> nameList = new List <string>(); List <string> content = new List <string>(); bool result = ReadListsFromCSVFile(nameList, content, CSVFullPath, presentation, projectView); return(result); }
public MegaVoiceExport(ObiPresentation presentation, string exportDirectory, List <string> navListElementNamesList, bool encodeToMp3, double mp3BitRate, SampleRate sampleRate, bool stereo, bool skipACM, int audioFileSectionLevel, string megaVoiceExportPath) : base(presentation, exportDirectory, navListElementNamesList, encodeToMp3, mp3BitRate, sampleRate, stereo, skipACM, audioFileSectionLevel) { m_Filename_Content = null; m_AudioFileSectionLevel = audioFileSectionLevel; GeneratorName = "Obi"; m_MegaVoiceExportPath = megaVoiceExportPath; }
public DAISY202Import(string nccPath, ObiPresentation presentation, Settings settings) { m_NccPath = nccPath; m_NccBaseDirectory = Path.GetDirectoryName(nccPath); m_OpenSectionNodes = new System.Collections.Generic.Stack <Obi.SectionNode>(); m_Presentation = presentation; m_SectionNodesToSmilReferenceMap = new Dictionary <SectionNode, string>(); m_AudioConversionSession = new AudioFormatConvertorSession(m_Presentation.DataProviderManager.DataFileDirectoryFullPath, m_Presentation.MediaDataManager.DefaultPCMFormat, false, false); m_Settings = settings; m_Counter_FrontPageCorection = 0; }
// Update the label when the role of the node changes private void Node_ChangedKind(object sender, ChangedRoleEventArgs e) { UpdateColors(); UpdateLabel(); if (e.PreviousRole == EmptyNode.Role.Anchor && e.Node.Role_ != EmptyNode.Role.Anchor) { ObiPresentation pres = (ObiPresentation)mNode.Presentation; pres.ListOfAnchorNodes_Remove(e.Node); } else if (e.Node.Role_ == EmptyNode.Role.Anchor && e.PreviousRole != EmptyNode.Role.Anchor) { ObiPresentation pres = (ObiPresentation)mNode.Presentation; pres.ListOfAnchorNodes_Add(e.Node); } }
public void ImportFromCSVFile(string CSVFullPath, ObiPresentation presentation) { m_Presentation = presentation; List <int> levelsList = new List <int> (); List <string> sectionNames = new List <string>(); List <int> pagesPerSection = new List <int>(); //levelsList.Add(1); //levelsList.Add(2); //sectionNames.Add("first"); //sectionNames.Add("second"); //pagesPerSection.Add(0); //pagesPerSection.Add(2); ReadListsFromCSVFile(levelsList, sectionNames, pagesPerSection, CSVFullPath); CreateStructure(levelsList, sectionNames, pagesPerSection); }
private Dictionary <string, string> PopulateSmilMetadataDictionary() { Dictionary <string, string> metadataItems = new Dictionary <string, string> (); /* * List<urakawa.metadata.Metadata> items = m_Presentation.getListOfMetadata (); * items.Sort ( delegate ( urakawa.metadata.Metadata a, urakawa.metadata.Metadata b ) * { * int names = a.getName ().CompareTo ( b.getName () ); * return names == 0 ? a.getContent ().CompareTo ( b.getContent () ) : names; * } ); * * * XmlNode headNode = nccDocument.GetElementsByTagName ( "head" )[0]; * // add existing metadata items to ncc * foreach (urakawa.metadata.Metadata m in items) * { * if ( metadataMap.ContainsKey(m.getName () )) * { */ ObiPresentation presentation = (ObiPresentation)m_Presentation; urakawa.metadata.Metadata identifier = presentation.GetFirstMetadataItem("dc:Identifier"); if (identifier != null) { metadataItems.Add(m_MetadataMap[identifier.NameContentAttribute.Name], identifier.NameContentAttribute.Value); } urakawa.metadata.Metadata format = presentation.GetFirstMetadataItem("dc:Format"); if (format != null) { metadataItems.Add(m_MetadataMap[format.NameContentAttribute.Name], format.NameContentAttribute.Value); } urakawa.metadata.Metadata generator = presentation.GetFirstMetadataItem("generator"); if (generator != null) { metadataItems.Add(m_MetadataMap[generator.NameContentAttribute.Name], generator.NameContentAttribute.Value); } return(metadataItems); }
//private bool m_EncodeToMP3; //private int m_BitRate_Mp3; public DAISY202Export(ObiPresentation presentation, string exportDirectory, bool encodeToMp3, double mp3BitRate, AudioLib.SampleRate sampleRate, bool stereo, int audioFileSectionLevel) : base(presentation, exportDirectory, null, encodeToMp3, mp3BitRate, sampleRate, stereo, true, false, true) { m_Presentation = presentation; m_ExportDirectory = exportDirectory; m_MetadataMap = CreateDAISY3To2MetadataMap(); m_SmilFile_TitleMap = new Dictionary <string, string> (); m_NextSectionPageAdjustmentDictionary = new Dictionary <SectionNode, EmptyNode>(); m_AudioFileSectionLevel = audioFileSectionLevel; m_FilesList = new List <string>(); //m_EncodeToMP3 = encodeToMP3; }
public EditRoles(ObiPresentation presentation, ProjectView.ProjectView projectView) { if (presentation == null) { throw new Exception("Invalid presentation for custom types dialog"); } if (projectView == null) { throw new Exception("Invalid project view for custom types dialog"); } InitializeComponent(); mNumberOfCommandsSinceOpened = 0; mPresentation = presentation; mProjectView = projectView; helpProvider1.HelpNamespace = Localizer.Message("CHMhelp_file_name"); helpProvider1.SetHelpNavigator(this, HelpNavigator.Topic); helpProvider1.SetHelpKeyword(this, "HTML Files/Creating a DTB/Working with Phrases/Editing Custom Roles.htm"); }
private void CreateNCCMetadata(XmlDocument nccDocument, string tocItems) { List <urakawa.metadata.Metadata> items = m_Presentation.Metadatas.ContentsAs_ListCopy; items.Sort(delegate(urakawa.metadata.Metadata a, urakawa.metadata.Metadata b) { int names = a.NameContentAttribute.Name.CompareTo(b.NameContentAttribute.Name); return(names == 0 ? a.NameContentAttribute.Value.CompareTo(b.NameContentAttribute.Value) : names); }); XmlNode headNode = nccDocument.GetElementsByTagName("head")[0]; // create first meta node XmlNode firstMetaNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(firstMetaNode); CreateAppendXmlAttribute(nccDocument, firstMetaNode, "content", "text/html; charset=utf-8"); CreateAppendXmlAttribute(nccDocument, firstMetaNode, "http-equiv", "Content-type"); //<meta content="text/html; charset=utf-8" http-equiv="Content-type"/> ObiPresentation presentation = (ObiPresentation)m_Presentation; urakawa.metadata.Metadata titleMetadata = presentation.GetFirstMetadataItem("dc:Title"); if (titleMetadata != null) { XmlNode titleMetadataNode = nccDocument.CreateElement(null, "title", headNode.NamespaceURI); headNode.AppendChild(titleMetadataNode); titleMetadataNode.AppendChild( nccDocument.CreateTextNode(titleMetadata.NameContentAttribute.Value)); } // add dc:date from produced date in case dc:date do not exists urakawa.metadata.Metadata producedDateMetadata = presentation.GetFirstMetadataItem(Metadata.DTB_PRODUCED_DATE); if (presentation.GetFirstMetadataItem(Metadata.DC_DATE) == null && producedDateMetadata != null) { XmlNode dateMetadataNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(dateMetadataNode); CreateAppendXmlAttribute(nccDocument, dateMetadataNode, "name", "dc:date"); CreateAppendXmlAttribute(nccDocument, dateMetadataNode, "content", producedDateMetadata.NameContentAttribute.Value); } // add existing metadata items to nccn foreach (urakawa.metadata.Metadata m in items) { if (m_MetadataMap.ContainsKey(m.NameContentAttribute.Name)) { XmlNode metaNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(metaNode); CreateAppendXmlAttribute(nccDocument, metaNode, "name", m_MetadataMap[m.NameContentAttribute.Name]); CreateAppendXmlAttribute(nccDocument, metaNode, "content", m.NameContentAttribute.Value); } } // to do add more metadata items. // add dc:format XmlNode formatNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(formatNode); CreateAppendXmlAttribute(nccDocument, formatNode, "name", "dc:format"); CreateAppendXmlAttribute(nccDocument, formatNode, "content", "Daisy 2.02"); // ncc:charset XmlNode charsetNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(charsetNode); CreateAppendXmlAttribute(nccDocument, charsetNode, "name", "ncc:charset"); CreateAppendXmlAttribute(nccDocument, charsetNode, "content", "utf-8"); XmlNode pageMetaNode = null; // ncc:pageFront pageMetaNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(pageMetaNode); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "name", "ncc:pageFront"); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "content", m_PageFrontCount.ToString()); // ncc:maxPageNormal and pageNormal pageMetaNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(pageMetaNode); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "name", "ncc:maxPageNormal"); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "content", m_MaxPageNormal.ToString()); // ncc:pageNormal pageMetaNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(pageMetaNode); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "name", "ncc:pageNormal"); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "content", m_PageNormalCount.ToString()); // ncc:pageSpecial pageMetaNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(pageMetaNode); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "name", "ncc:pageSpecial"); CreateAppendXmlAttribute(nccDocument, pageMetaNode, "content", m_PageSpecialCount.ToString()); // ncc:prodNotes // ncc:tocItems XmlNode tocItemNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(tocItemNode); CreateAppendXmlAttribute(nccDocument, tocItemNode, "name", "ncc:tocItems"); CreateAppendXmlAttribute(nccDocument, tocItemNode, "content", tocItems); // ncc:totalTime XmlNode totalTimeNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(totalTimeNode); CreateAppendXmlAttribute(nccDocument, totalTimeNode, "name", "ncc:totalTime"); //CreateAppendXmlAttribute ( nccDocument, totalTimeNode, "content", m_SmilElapseTime.ToString ().Split ( '.' )[0] ); CreateAppendXmlAttribute(nccDocument, totalTimeNode, "content", GetStringTotalTimeRoundedOff(new TimeSpan(m_SmilElapseTime.AsTimeSpanTicks))); XmlNode multimediaType = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(multimediaType); CreateAppendXmlAttribute(nccDocument, multimediaType, "name", "ncc:multimediaType"); CreateAppendXmlAttribute(nccDocument, multimediaType, "content", "audioNcc"); // ncc:depth XmlNode depthNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(depthNode); CreateAppendXmlAttribute(nccDocument, depthNode, "name", "ncc:depth"); CreateAppendXmlAttribute(nccDocument, depthNode, "content", m_MaxDepth.ToString()); // ncc:files int filesCount = m_FilesList.Count + 2; XmlNode filesCountNode = nccDocument.CreateElement(null, "meta", headNode.NamespaceURI); headNode.AppendChild(filesCountNode); CreateAppendXmlAttribute(nccDocument, filesCountNode, "name", "ncc:files"); CreateAppendXmlAttribute(nccDocument, filesCountNode, "content", filesCount.ToString()); }
private ManagedAudioMedia addAudioWav(FileDataProvider dataProv, XmlNode audioAttrClipBegin, XmlNode audioAttrClipEnd, TreeNode treeNode) { //if (m_autoDetectPcmFormat //&& m_AudioConversionSession.FirstDiscoveredPCMFormat != null //&& !m_AudioConversionSession.FirstDiscoveredPCMFormat.IsCompatibleWith(treeNode.Presentation.MediaDataManager.DefaultPCMFormat.Data)) //{ //PCMFormatInfo pcmFormat = treeNode.Presentation.MediaDataManager.DefaultPCMFormat; //.Copy(); //pcmFormat.Data.CopyFrom(m_AudioConversionSession.FirstDiscoveredPCMFormat); // //treeNode.Presentation.MediaDataManager.DefaultPCMFormat = pcmFormat; //} //if (RequestCancellation) return null; Time clipB = Time.Zero; Time clipE = Time.MaxValue; if (audioAttrClipBegin != null && !string.IsNullOrEmpty(audioAttrClipBegin.Value)) { string strBeginValue = audioAttrClipBegin.Value.Replace("npt=", ""); try { clipB = new Time(strBeginValue); } catch (Exception ex) { clipB = new Time(0); string str = "CLIP BEGIN TIME PARSE FAIL: " + audioAttrClipBegin.Value; Console.WriteLine(str); Debug.Fail(str); } } if (audioAttrClipEnd != null && !string.IsNullOrEmpty(audioAttrClipEnd.Value)) { try { string strEndValue = audioAttrClipEnd.Value.Replace("npt=", ""); clipE = new Time(strEndValue); } catch (Exception ex) { clipE = new Time(0); string str = "CLIP END TIME PARSE FAIL: " + audioAttrClipEnd.Value; Console.WriteLine(str); Debug.Fail(str); } } ManagedAudioMedia media = null; ObiPresentation presentation = m_Presentation; WavAudioMediaData mediaData = (WavAudioMediaData) presentation.MediaDataFactory.CreateAudioMediaData(); // mediaData.AudioDuration DOES NOT WORK BECAUSE DEPENDS ON WAVCLIPS LIST!!! WavClip wavClip = new WavClip(dataProv); Time newClipE = clipE.Copy(); if (Math.Abs(newClipE.AsMilliseconds) > Math.Abs(wavClip.MediaDuration.AsMilliseconds)) { Console.WriteLine("clip adjusted. file size: " + wavClip.MediaDuration.AsMilliseconds + "; clip end: " + newClipE.AsMilliseconds); clipEndAdjustedToNull(clipB, newClipE, wavClip.MediaDuration, treeNode); //newClipE = wavClip.MediaDuration; newClipE = null; } try { mediaData.AppendPcmData(dataProv, clipB, newClipE); } catch (Exception ex) { #if DEBUG Debugger.Break(); #endif //DEBUG Console.WriteLine("CLIP TIME ERROR1 (end < begin ?): " + clipB + " (" + (audioAttrClipBegin != null ? audioAttrClipBegin.Value : "N/A") + ") / " + clipE + " (" + (audioAttrClipEnd != null ? audioAttrClipEnd.Value : "N/A") + ") === " + wavClip.MediaDuration); } //if (RequestCancellation) return null; media = presentation.MediaFactory.CreateManagedAudioMedia(); media.AudioMediaData = mediaData; return(media); }
private void addAudio(TreeNode treeNode, XmlNode xmlNode, bool isSequence) { //if (RequestCancellation) return; string dirPath = m_NccBaseDirectory; XmlAttributeCollection audioAttrs = xmlNode.Attributes; if (audioAttrs == null || audioAttrs.Count == 0) { return; } XmlNode audioAttrSrc = audioAttrs.GetNamedItem("src"); if (audioAttrSrc == null || String.IsNullOrEmpty(audioAttrSrc.Value)) { return; } string src = FileDataProvider.UriDecode(audioAttrSrc.Value); XmlNode audioAttrClipBegin = audioAttrs.GetNamedItem("clip-begin"); XmlNode audioAttrClipEnd = audioAttrs.GetNamedItem("clip-end"); ObiPresentation presentation = m_Presentation; ManagedAudioMedia media = null; string fullPath = Path.Combine(dirPath, src); fullPath = FileDataProvider.NormaliseFullFilePath(fullPath).Replace('/', '\\'); //addOPF_GlobalAssetPath(fullPath); if (src.EndsWith("wav", StringComparison.OrdinalIgnoreCase)) { FileDataProvider dataProv = null; if (!File.Exists(fullPath)) { Debug.Fail("File not found: {0}", fullPath); media = null; } else { //bool deleteSrcAfterCompletion = false; string fullWavPath = fullPath; FileDataProvider obj; m_OriginalAudioFile_FileDataProviderMap.TryGetValue(fullWavPath, out obj); if (obj != null) //m_OriginalAudioFile_FileDataProviderMap.ContainsKey(fullWavPath)) { if (m_AudioConversionSession.FirstDiscoveredPCMFormat == null) { DebugFix.Assert(obj.Presentation != presentation); Object appData = obj.AppData; DebugFix.Assert(appData != null); if (appData != null && appData is WavClip.PcmFormatAndTime) { m_AudioConversionSession.FirstDiscoveredPCMFormat = new AudioLibPCMFormat(); m_AudioConversionSession.FirstDiscoveredPCMFormat.CopyFrom(((WavClip.PcmFormatAndTime)appData).mFormat); } } if (obj.Presentation != presentation) { dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE); //reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.CopyingAudio, Path.GetFileName(obj.DataFileFullPath))); dataProv.InitByCopyingExistingFile(obj.DataFileFullPath); m_OriginalAudioFile_FileDataProviderMap.Remove(fullWavPath); m_OriginalAudioFile_FileDataProviderMap.Add(fullWavPath, dataProv); Object appData = obj.AppData; DebugFix.Assert(appData != null); if (appData != null && appData is WavClip.PcmFormatAndTime) { dataProv.AppData = new WavClip.PcmFormatAndTime(((WavClip.PcmFormatAndTime)appData).mFormat, ((WavClip.PcmFormatAndTime)appData).mTime); } } else { dataProv = obj; // m_OriginalAudioFile_FileDataProviderMap[fullWavPath]; } } else // create FileDataProvider { Stream wavStream = null; try { wavStream = File.Open(fullWavPath, FileMode.Open, FileAccess.Read, FileShare.Read); uint dataLength; AudioLibPCMFormat pcmInfo = null; pcmInfo = AudioLibPCMFormat.RiffHeaderParse(wavStream, out dataLength); if (m_AudioConversionSession.FirstDiscoveredPCMFormat == null) { m_AudioConversionSession.FirstDiscoveredPCMFormat = new AudioLibPCMFormat(); m_AudioConversionSession.FirstDiscoveredPCMFormat.CopyFrom(pcmInfo); } //if (RequestCancellation) return; if (!presentation.MediaDataManager.DefaultPCMFormat.Data.IsCompatibleWith(pcmInfo)) { wavStream.Close(); wavStream = null; //reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.ConvertingAudio, Path.GetFileName(fullWavPath))); string newfullWavPath = m_AudioConversionSession.ConvertAudioFileFormat(fullWavPath); //if (RequestCancellation) return; dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE); //Console.WriteLine("Source audio file to SDK audio file map (before creating SDK audio file): " + Path.GetFileName(fullWavPath) + " = " + dataProv.DataFileRelativePath); dataProv.InitByMovingExistingFile(newfullWavPath); m_AudioConversionSession.RelocateDestinationFilePath(newfullWavPath, dataProv.DataFileFullPath); m_OriginalAudioFile_FileDataProviderMap.Add(fullWavPath, dataProv); //if (RequestCancellation) return; } else // use original wav file by copying it to data directory { dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE); //Console.WriteLine("Source audio file to SDK audio file map (before creating SDK audio file): " + Path.GetFileName(fullWavPath) + " = " + dataProv.DataFileRelativePath); //reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.CopyingAudio, Path.GetFileName(fullWavPath))); dataProv.InitByCopyingExistingFile(fullWavPath); m_OriginalAudioFile_FileDataProviderMap.Add(fullWavPath, dataProv); //if (RequestCancellation) return; } } finally { if (wavStream != null) { wavStream.Close(); } } } } // FileDataProvider key check ends //if (RequestCancellation) return; media = addAudioWav(dataProv, audioAttrClipBegin, audioAttrClipEnd, treeNode); } else if (src.EndsWith("mp3", StringComparison.OrdinalIgnoreCase) || src.EndsWith("mp4", StringComparison.OrdinalIgnoreCase)) { if (!File.Exists(fullPath)) { Debug.Fail("File not found: {0}", fullPath); return; } //if (RequestCancellation) return; //reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.DecodingAudio, Path.GetFileName(fullPath))); //if (RequestCancellation) return; string fullMp34PathOriginal = fullPath; FileDataProvider obj; m_OriginalAudioFile_FileDataProviderMap.TryGetValue(fullMp34PathOriginal, out obj); FileDataProvider dataProv = null; if (obj != null) //m_OriginalAudioFile_FileDataProviderMap.ContainsKey(fullMp3PathOriginal)) { if (m_AudioConversionSession.FirstDiscoveredPCMFormat == null) { DebugFix.Assert(obj.Presentation != presentation); Object appData = obj.AppData; DebugFix.Assert(appData != null); if (appData != null && appData is WavClip.PcmFormatAndTime) { m_AudioConversionSession.FirstDiscoveredPCMFormat = new AudioLibPCMFormat(); m_AudioConversionSession.FirstDiscoveredPCMFormat.CopyFrom(((WavClip.PcmFormatAndTime)appData).mFormat); } } if (obj.Presentation != presentation) { dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE); //reportProgress(-1, String.Format(UrakawaSDK_daisy_Lang.CopyingAudio, Path.GetFileName(obj.DataFileFullPath))); dataProv.InitByCopyingExistingFile(obj.DataFileFullPath); m_OriginalAudioFile_FileDataProviderMap.Remove(fullMp34PathOriginal); m_OriginalAudioFile_FileDataProviderMap.Add(fullMp34PathOriginal, dataProv); Object appData = obj.AppData; DebugFix.Assert(appData != null); if (appData != null && appData is WavClip.PcmFormatAndTime) { dataProv.AppData = new WavClip.PcmFormatAndTime(((WavClip.PcmFormatAndTime)appData).mFormat, ((WavClip.PcmFormatAndTime)appData).mTime); } } else { dataProv = obj; // m_OriginalAudioFile_FileDataProviderMap[fullMp3PathOriginal]; } } else { string newfullWavPath = m_AudioConversionSession.ConvertAudioFileFormat(fullMp34PathOriginal); dataProv = (FileDataProvider)presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE); //Console.WriteLine("Source audio file to SDK audio file map (before creating SDK audio file): " + Path.GetFileName(fullMp34PathOriginal) + " = " + dataProv.DataFileRelativePath); dataProv.InitByMovingExistingFile(newfullWavPath); m_AudioConversionSession.RelocateDestinationFilePath(newfullWavPath, dataProv.DataFileFullPath); m_OriginalAudioFile_FileDataProviderMap.Add(fullMp34PathOriginal, dataProv); //if (RequestCancellation) return; } if (dataProv != null) { //if (RequestCancellation) return; //media = addAudioWav(newfullWavPath, true, audioAttrClipBegin, audioAttrClipEnd); media = addAudioWav(dataProv, audioAttrClipBegin, audioAttrClipEnd, treeNode); if (media == null) { Debugger.Break(); } } } //if (RequestCancellation) return; if (media == null) { if (!TreenodesWithoutManagedAudioMediaData.Contains(treeNode)) { //{ TreenodesWithoutManagedAudioMediaData.Add(treeNode); } //} Debug.Fail("Creating ExternalAudioMedia ??"); Time timeClipBegin = null; ExternalAudioMedia exmedia = presentation.MediaFactory.CreateExternalAudioMedia(); exmedia.Src = src; if (audioAttrClipBegin != null && !string.IsNullOrEmpty(audioAttrClipBegin.Value)) { timeClipBegin = new Time(0); try { timeClipBegin = new Time(audioAttrClipBegin.Value); } catch (Exception ex) { string str = "CLIP BEGIN TIME PARSE FAIL: " + audioAttrClipBegin.Value; Console.WriteLine(str); Debug.Fail(str); } exmedia.ClipBegin = timeClipBegin; } if (audioAttrClipEnd != null && !string.IsNullOrEmpty(audioAttrClipEnd.Value)) { Time timeClipEnd = null; try { timeClipEnd = new Time(audioAttrClipEnd.Value); } catch (Exception ex) { string str = "CLIP END TIME PARSE FAIL: " + audioAttrClipEnd.Value; Console.WriteLine(str); Debug.Fail(str); } if (timeClipEnd != null) { try { exmedia.ClipEnd = timeClipEnd; } catch (Exception ex) { string str = "CLIP TIME ERROR (end < begin): " + timeClipBegin + " (" + (audioAttrClipBegin != null ? audioAttrClipBegin.Value : "N/A") + ") / " + timeClipEnd + " (" + audioAttrClipEnd.Value + ")"; Console.WriteLine(str); //Debug.Fail(str); } } } } //if (RequestCancellation) return; if (media != null) { ChannelsProperty chProp = treeNode.GetChannelsProperty(); if (chProp == null) { chProp = presentation.PropertyFactory.CreateChannelsProperty(); treeNode.AddProperty(chProp); } if (isSequence) { #if ENABLE_SEQ_MEDIA SequenceMedia mediaSeq = chProp.GetMedia(m_audioChannel) as SequenceMedia; if (mediaSeq == null) { mediaSeq = presentation.MediaFactory.CreateSequenceMedia(); mediaSeq.AllowMultipleTypes = false; chProp.SetMedia(m_audioChannel, mediaSeq); } mediaSeq.ChildMedias.Insert(mediaSeq.ChildMedias.Count, media); #else ManagedAudioMedia existingMedia = chProp.GetMedia(presentation.ChannelsManager.GetOrCreateAudioChannel()) as ManagedAudioMedia; if (existingMedia == null) { chProp.SetMedia(presentation.ChannelsManager.GetOrCreateAudioChannel(), media); } else { // WARNING: WavAudioMediaData implementation differs from AudioMediaData: // the latter is naive and performs a stream binary copy, the latter is optimized and re-uses existing WavClips. // WARNING 2: The audio data from the given parameter gets emptied ! existingMedia.AudioMediaData.MergeWith(media.AudioMediaData); } #endif //ENABLE_SEQ_MEDIA } else { chProp.SetMedia(presentation.ChannelsManager.GetOrCreateAudioChannel(), media); } } else { Debug.Fail("Media could not be created !"); } }
/// <summary> /// Create the phrase detection command. /// </summary> public static CompositeCommand GetPhraseDetectionCommand(ProjectView.ProjectView view, ObiNode node, long threshold, double gap, double before, bool mergeFirstTwoPhrases, ObiPresentation presentation = null) { List <PhraseNode> phraseNodesList = new List <PhraseNode> (); if (node is PhraseNode) { phraseNodesList.Add((PhraseNode)node); } else if (node is SectionNode) { SectionNode section = (SectionNode)node; for (int i = 0; i < section.PhraseChildCount; i++) { if (section.PhraseChild(i) is PhraseNode && ((PhraseNode)section.PhraseChild(i)).Role_ != EmptyNode.Role.Silence) { phraseNodesList.Add((PhraseNode)section.PhraseChild(i)); } } } List <List <PhraseNode> > phrasesToMerge = new List <List <PhraseNode> >(); CompositeCommand command = null; if (view.Presentation == null && presentation != null) { command = presentation.CreateCompositeCommand(Localizer.Message("phrase_detection")); } else { command = view.Presentation.CreateCompositeCommand(Localizer.Message("phrase_detection")); } // if phrase is selected but phrase detection node is section,select section if (node is SectionNode && view.GetSelectedPhraseSection != null && view.GetSelectedPhraseSection == node) { command.ChildCommands.Insert(command.ChildCommands.Count, new UpdateSelection(view, new NodeSelection(node, view.Selection.Control))); } ObiNode parent = node is SectionNode ? node : node.ParentAs <ObiNode> (); int index = 0; if (phraseNodesList.Count > 0) { view.TriggerProgressChangedEvent(Localizer.Message("phrase_detection"), 0); } for (int j = 0; j < phraseNodesList.Count; j++) { PhraseNode phrase = phraseNodesList[j]; if (j == 0) { index = phrase.Index + 1; } System.Collections.Generic.List <PhraseNode> phrases = null; if (view.Presentation == null && presentation != null) { phrases = presentation.CreatePhraseNodesFromAudioAssetList( Obi.Audio.PhraseDetection.Apply(phrase.Audio.Copy(), threshold, gap, before)); } else { phrases = view.Presentation.CreatePhraseNodesFromAudioAssetList( Obi.Audio.PhraseDetection.Apply(phrase.Audio.Copy(), threshold, gap, before)); } for (int i = 0; i < phrases.Count; ++i) { // Copy page/heading role for the first phrase only if (i == 0 || (phrase.Role_ != EmptyNode.Role.Page && phrase.Role_ != EmptyNode.Role.Heading)) { phrases[i].CopyAttributes(phrase); } phrases[i].Used = phrase.Used; phrases[i].TODO = phrase.TODO; if (i == 0 && phrase.TODO && (phrase as EmptyNode).CommentText != null) { (phrases[i] as EmptyNode).CommentText = (phrase as EmptyNode).CommentText; } if (phrases[i].Role_ == EmptyNode.Role.Heading && i > 0) { phrases[i].Role_ = EmptyNode.Role.Plain; } // in following add node constructor, update selection is made false, to improve performance (19 may, 2010) command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.AddNode(view, phrases[i], parent, index, false)); index++; } // add first 2 phrases to the list if the merge flag is true if (phrases.Count >= 2 && mergeFirstTwoPhrases && phrases[0] is PhraseNode && phrases [1] is PhraseNode) { List <PhraseNode> mergeList = new List <PhraseNode>(); mergeList.Add(phrases[0]); mergeList.Add(phrases[1]); phrasesToMerge.Add(mergeList); } if (node is PhraseNode && phrases.Count > 0 && view.Selection != null) { //command.append ( new UpdateSelection ( view, new NodeSelection ( node, view.Selection.Control ) ) ); command.ChildCommands.Insert(command.ChildCommands.Count, new UpdateSelection(view, new NodeSelection(phrases[0], view.Selection.Control))); //uncommenting this because unexecute for update selection can handle null unexecute now } Commands.Node.Delete deleteCmd = new Commands.Node.Delete(view, phrase, false); command.ChildCommands.Insert(command.ChildCommands.Count, deleteCmd);//@singleSection: moved delete command last for improve undo selection if (Obi.Audio.PhraseDetection.CancelOperation) { break; } // skip to next indexes if the two consequtive phrases in phrase list are not consequitive according to phrase index in the parent section if (j < phraseNodesList.Count - 1 && phrase.Index + 1 < phraseNodesList[j + 1].Index) { EmptyNode empty = null; for (int i = phrase.Index + 1; i < phraseNodesList[j + 1].Index; ++i) { empty = phrase.ParentAs <SectionNode>().PhraseChild(i); command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.Delete(view, empty, false)); command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Node.AddNode(view, empty, parent, index, false)); index++; } //index = index + (phraseNodesList[j + 1].Index - (phrase.Index + 1)); } view.TriggerProgressChangedEvent(Localizer.Message("phrase_detection"), (100 * j) / phraseNodesList.Count); } if (phrasesToMerge.Count > 0) { for (int i = 0; i < phrasesToMerge.Count; i++) { List <PhraseNode> mergeList = phrasesToMerge[i]; Commands.Node.MergeAudio mergeCmd = new MergeAudio(view, mergeList[0], mergeList[1]); mergeCmd.UpdateSelection = false; command.ChildCommands.Insert(command.ChildCommands.Count, mergeCmd); } } return(command); }
private bool ReadListsFromCSVFile(List <string> nameList, List <string> content, string CSVFullPath, ObiPresentation presentation, Obi.ProjectView.ProjectView projectView) { string[] linesInFiles; try { linesInFiles = File.ReadAllLines(CSVFullPath, Encoding.Default); } catch (IOException e) { MessageBox.Show(Localizer.Message("FileInUse"), Localizer.Message("Caption_Error"), MessageBoxButtons.OK, MessageBoxIcon.Error); return(false); } catch (Exception e) { return(false); } CompositeCommand command = presentation.CreateCompositeCommand(Localizer.Message("modify_metadata_entry")); List <string> entryHavingWrongDateFormat = new List <string>(); foreach (string line in linesInFiles) { string[] cellsInLineArray = null; if (Path.GetExtension(CSVFullPath).ToLower() == ".csv") { cellsInLineArray = line.Split(','); } else { cellsInLineArray = line.Split('\t'); } if (cellsInLineArray.Length >= 2 && !string.IsNullOrWhiteSpace(cellsInLineArray[0]) && !string.IsNullOrWhiteSpace(cellsInLineArray[1])) { if (projectView == null) { if (Metadata.DAISY3MetadataNames.Contains(cellsInLineArray[0], StringComparer.OrdinalIgnoreCase)) { foreach (string metadataName in Metadata.DAISY3MetadataNames) { if (metadataName.IndexOf(cellsInLineArray[0], StringComparison.OrdinalIgnoreCase) >= 0) { cellsInLineArray[0] = metadataName; } } cellsInLineArray[0] = Metadata.DAISY3MetadataNames.ElementAt(Metadata.DAISY3MetadataNames.IndexOf(cellsInLineArray[0])); } if (cellsInLineArray[0].ToLower() == "dtb:produceddate" || cellsInLineArray[0].ToLower() == "dtb:revisiondate" || cellsInLineArray[0].ToLower() == "dc:date" || cellsInLineArray[0].ToLower() == "dtb:sourcedate") { string dateFormat = GetDate(cellsInLineArray[0], cellsInLineArray[1], entryHavingWrongDateFormat); cellsInLineArray[1] = dateFormat; } if (cellsInLineArray[0].ToLower() == "custom") { if (!entryHavingWrongDateFormat.Contains(cellsInLineArray[0], StringComparer.OrdinalIgnoreCase)) { m_metadataFieldsNotImported += "\n\n" + "-> " + cellsInLineArray[0] + " " + Localizer.Message("Metadata_NameCannotBeCustom"); entryHavingWrongDateFormat.Add(cellsInLineArray[0]); } } else { presentation.SetSingleMetadataItem(cellsInLineArray[0], cellsInLineArray[1]); } } else if (projectView != null) { if (projectView.CanAddMetadataEntry()) { bool entryModified = false; foreach (urakawa.metadata.Metadata entry in presentation.GetMetadata(cellsInLineArray[0])) { if (cellsInLineArray[0].ToLower() == "dtb:produceddate" || cellsInLineArray[0].ToLower() == "dtb:revisiondate" || cellsInLineArray[0].ToLower() == "dc:date" || cellsInLineArray[0].ToLower() == "dtb:sourcedate") { string dateFormat = GetDate(cellsInLineArray[0], cellsInLineArray[1], entryHavingWrongDateFormat); cellsInLineArray[1] = dateFormat; } if (cellsInLineArray[0].ToLower() == "custom") { if (!entryHavingWrongDateFormat.Contains(cellsInLineArray[0], StringComparer.OrdinalIgnoreCase)) { m_metadataFieldsNotImported += "\n\n" + "-> " + cellsInLineArray[0] + " " + Localizer.Message("Metadata_NameCannotBeCustom"); entryHavingWrongDateFormat.Add(cellsInLineArray[0]); } } else { command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Metadata.ModifyContent(projectView, entry, cellsInLineArray[1])); } entryModified = true; } if (!entryModified) { if (Metadata.DAISY3MetadataNames.Contains(cellsInLineArray[0], StringComparer.OrdinalIgnoreCase)) { foreach (string metadataName in Metadata.DAISY3MetadataNames) { if (metadataName.IndexOf(cellsInLineArray[0], StringComparison.OrdinalIgnoreCase) >= 0) { cellsInLineArray[0] = metadataName; } } cellsInLineArray[0] = Metadata.DAISY3MetadataNames.ElementAt(Metadata.DAISY3MetadataNames.IndexOf(cellsInLineArray[0])); } if (cellsInLineArray[0].ToLower() == "custom") { if (!entryHavingWrongDateFormat.Contains(cellsInLineArray[0], StringComparer.OrdinalIgnoreCase)) { m_metadataFieldsNotImported += "\n\n" + "-> " + cellsInLineArray[0] + " " + Localizer.Message("Metadata_NameCannotBeCustom"); entryHavingWrongDateFormat.Add(cellsInLineArray[0]); } } else { Commands.Metadata.AddEntry cmd = new Commands.Metadata.AddEntry(projectView, cellsInLineArray[0]); command.ChildCommands.Insert(command.ChildCommands.Count, cmd); if (cellsInLineArray[0] == "dtb:producedDate" || cellsInLineArray[0] == "dtb:revisionDate" || cellsInLineArray[0] == "dc:Date" || cellsInLineArray[0] == "dtb:sourceDate") { cellsInLineArray[1] = GetDate(cellsInLineArray[0], cellsInLineArray[1], entryHavingWrongDateFormat); } command.ChildCommands.Insert(command.ChildCommands.Count, new Commands.Metadata.ModifyContent(projectView, cmd.Entry, cellsInLineArray[1])); } } } } } } if (command.ChildCommands.Count > 0) { presentation.UndoRedoManager.Execute(command); } if (m_metadataFieldsNotImported != string.Empty) { MessageBox.Show(String.Format(Localizer.Message("Metadata_NotImported"), m_metadataFieldsNotImported), Localizer.Message("Metadata_Imported"), MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show(String.Format(Localizer.Message("Metadata_ImportedSuccessfully"), m_metadataFieldsNotImported), Localizer.Message("Metadata_Imported"), MessageBoxButtons.OK, MessageBoxIcon.Information); } return(true); }
public ExportStructure(ObiPresentation presentation, string exportDirectory) { m_Presentation = presentation; m_ExportDirectory = exportDirectory; }
/// <summary> /// Populate the presentation from an XHTML file. /// </summary> public void ImportFromXHTMLFile(string xhtml_path, ObiPresentation presentation) { mOpenSectionNodes = new System.Collections.Generic.Stack <Obi.SectionNode>(); mPresentation = presentation; LoadFromXHTML(new Uri(xhtml_path)); }
public RemoveCustomType(ProjectView.ProjectView view, ObiPresentation presentation, string customType) : base(view) { mPresentation = presentation; mCustomType = customType; }