/// <summary> /// checks if wav file or mp3 file has already been converted in the same session, if it is already converted, returns file path of converted file /// else convert to wav file with default project format and stores it in data directory of project. /// </summary> /// <param name="sourceFilePath"></param> /// <returns> full path of converted file if conversion is successful </returns> public string ConvertAudioFileFormat(string sourceFilePath) { if (!File.Exists(sourceFilePath)) { throw new FileNotFoundException(); } string str; m_FilePathsMap.TryGetValue(sourceFilePath, out str); if (!string.IsNullOrEmpty(str)) //m_FilePathsMap.ContainsKey(sourceFilePath)) { string fullPath = str; // m_FilePathsMap[sourceFilePath]; if (File.Exists(fullPath)) { return(fullPath); // this should always be the case, unless the files have been removed from "outside" (i.e. user deleting the audio temporary directory while a session is alive) } #if DEBUG Debugger.Break(); #endif //DEBUG m_FilePathsMap.Remove(sourceFilePath); } string convertedFilePath = ConvertToDefaultFormat(sourceFilePath, m_destinationDirectory, m_destinationFormatInfo == null ? null : m_destinationFormatInfo.Copy(), m_SkipACM); if (RequestCancellation) { return(null); } if (File.Exists(convertedFilePath)) { m_FilePathsMap.Add(sourceFilePath, convertedFilePath); return(convertedFilePath); } throw new System.Exception("Operation failed"); }
private void checkAndAddDeferredRecordingDataItems() { if (m_DeferredRecordingDataItems == null) { return; } IsAutoPlay = false; bool needsRefresh = false; bool skipDrawing = Settings.Default.AudioWaveForm_DisableDraw; Settings.Default.AudioWaveForm_DisableDraw = true; //#if !DISABLE_SINGLE_RECORD_FILE string previousRecordedFile = null; FileDataProvider currentFileDataProvider = null; AudioLibPCMFormat currentPcmFormat = null; long currentPcmDataLength = -1; long previousBytePosEnd = 0; //#endif foreach (var deferredRecordingDataItem in m_DeferredRecordingDataItems) { Tuple <TreeNode, TreeNode> treeNodeSelection = m_UrakawaSession.PerformTreeNodeSelection(deferredRecordingDataItem.TreeNode1, false, deferredRecordingDataItem.TreeNode2); if (treeNodeSelection.Item1 != deferredRecordingDataItem.TreeNode1 || treeNodeSelection.Item2 != deferredRecordingDataItem.TreeNode2) { #if DEBUG Debugger.Break(); #endif continue; } if (IsWaveFormLoading && View != null) { View.CancelWaveFormLoad(true); } if (deferredRecordingDataItem.PlayBytePosition >= 0) { PlayBytePosition = deferredRecordingDataItem.PlayBytePosition; } else { m_LastSetPlayBytePosition = deferredRecordingDataItem.PlayBytePosition; } if (PlayBytePosition != deferredRecordingDataItem.PlayBytePosition) { #if DEBUG Debugger.Break(); #endif continue; } if (deferredRecordingDataItem.SelectionBeginBytePosition >= 0 && deferredRecordingDataItem.SelectionEndBytePosition > 0) { State.Selection.SetSelectionBytes(deferredRecordingDataItem.SelectionBeginBytePosition, deferredRecordingDataItem.SelectionEndBytePosition); } else { State.Selection.ClearSelection(); } if (State.Selection.SelectionBeginBytePosition != deferredRecordingDataItem.SelectionBeginBytePosition || State.Selection.SelectionEndBytePosition != deferredRecordingDataItem.SelectionEndBytePosition) { #if DEBUG Debugger.Break(); #endif continue; } if (!Settings.Default.Audio_DisableSingleWavFileRecord) { TreeNode treeNode = deferredRecordingDataItem.TreeNode1 ?? deferredRecordingDataItem.TreeNode2; if (string.IsNullOrEmpty(previousRecordedFile) || previousRecordedFile != deferredRecordingDataItem.RecordedFilePath) { PCMFormatInfo pcmInfo = State.Audio.PcmFormatRecordingMonitoring; currentPcmFormat = (pcmInfo != null ? pcmInfo.Copy().Data : null); if (currentPcmFormat == null) { Stream fileStream = File.Open(deferredRecordingDataItem.RecordedFilePath, FileMode.Open, FileAccess.Read, FileShare.Read); try { uint dataLength; currentPcmFormat = AudioLibPCMFormat.RiffHeaderParse(fileStream, out dataLength); currentPcmDataLength = dataLength; } finally { fileStream.Close(); } } currentFileDataProvider = (FileDataProvider)treeNode.Presentation.DataProviderFactory.Create(DataProviderFactory.AUDIO_WAV_MIME_TYPE); currentFileDataProvider.InitByMovingExistingFile(deferredRecordingDataItem.RecordedFilePath); if (File.Exists(deferredRecordingDataItem.RecordedFilePath)) //check exist just in case file adopted by DataProviderManager { File.Delete(deferredRecordingDataItem.RecordedFilePath); } } //Time duration = new Time(currentPcmFormat.ConvertBytesToTime(currentPcmDataLength)); if (previousBytePosEnd < 0) { previousBytePosEnd = 0; } long bytePosEnd = deferredRecordingDataItem.RecordAndContinue_StopBytePos; openFile(treeNode, currentFileDataProvider, previousBytePosEnd, bytePosEnd, currentPcmFormat, currentPcmDataLength); } else { openFile(deferredRecordingDataItem.RecordedFilePath, true, true, State.Audio.PcmFormatRecordingMonitoring); } needsRefresh = true; //m_viewModel.CommandRefresh.Execute(); //if (m_viewModel.View != null) //{ // m_viewModel.View.CancelWaveFormLoad(true); //} if (!Settings.Default.Audio_DisableSingleWavFileRecord) { previousRecordedFile = deferredRecordingDataItem.RecordedFilePath; previousBytePosEnd = deferredRecordingDataItem.RecordAndContinue_StopBytePos; } } m_DeferredRecordingDataItems = null; Settings.Default.AudioWaveForm_DisableDraw = skipDrawing; if (needsRefresh) { CommandRefresh.Execute(); } }