// DoTaskForFile protected override void DoTaskForFile(string pPath, IVgmtWorkerStruct pPosFileCreatorStruct, DoWorkEventArgs e) { PosFileCreatorStruct posStruct = (PosFileCreatorStruct)pPosFileCreatorStruct; WorkingItemStruct currentItem = new WorkingItemStruct(); long loopStartValue = DEFAULT_LOOP_VALUE; long loopEndValue = DEFAULT_LOOP_VALUE; string outputFileMask; string[] outputFileList; outputFileMask = posStruct.OutputFileMask.Replace(FILEMASK_BASE_NAME, Path.GetFileNameWithoutExtension(pPath)); outputFileMask = outputFileMask.Replace(FILEMASK_EXTENSION, Path.GetExtension(pPath).Remove(0, 1)); #region LOOP POINTS using (FileStream fs = File.OpenRead(pPath)) { currentItem.Initialize(); try { //---------------- // Get Loop Start //---------------- if (posStruct.DoLoopStartStatic) { loopStartValue = ByteConversion.GetLongValueFromString(posStruct.LoopStartStaticValue); } else if (posStruct.DoLoopStartOffset) { loopStartValue = ParseFile.GetCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopStartCalculatingOffset, true); } else if (posStruct.DoLoopStartRiffOffset) { try { loopStartValue = ParseFile.GetRiffCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopStartRiffCalculatingOffset, true); } catch (IndexOutOfRangeException iorEx) { this.progressStruct.Clear(); this.progressStruct.GenericMessage = String.Format("Error processing RIFF Loop Start for <{0}>: {1}{2}", Path.GetFileName(pPath), iorEx.Message, Environment.NewLine); ReportProgress(Constants.ProgressMessageOnly, this.progressStruct); } } else if (posStruct.DoLoopStartByteStringOffset) { loopStartValue = ParseFile.GetByteSearchCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopStartByteSearchCalculatingOffset, true); } if ((loopStartValue != DEFAULT_LOOP_VALUE) && ((int)loopStartValue >= 0)) { //---------------- // Get Loop End //---------------- if (posStruct.DoLoopEndStatic) { loopEndValue = ByteConversion.GetLongValueFromString(posStruct.LoopEndStaticValue); } else if (posStruct.DoLoopEndOffset) { loopEndValue = ParseFile.GetCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopEndCalculatingOffset, true); } else if (posStruct.DoLoopEndRiffOffset) { try { loopEndValue = ParseFile.GetRiffCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopEndRiffCalculatingOffset, true); } catch (IndexOutOfRangeException iorEx) { this.progressStruct.Clear(); this.progressStruct.GenericMessage = String.Format("Error processing RIFF Loop End for <{0}>: {1}{2}", Path.GetFileName(pPath), iorEx.Message, Environment.NewLine); ReportProgress(Constants.ProgressMessageOnly, this.progressStruct); } } else if (posStruct.DoLoopEndByteStringOffset) { loopEndValue = ParseFile.GetByteSearchCalculatedVaryingByteValueAtAbsoluteOffset(fs, posStruct.LoopEndByteSearchCalculatingOffset, true); } if ((loopEndValue != DEFAULT_LOOP_VALUE) && (loopEndValue >= 0)) { // Calculate Loop End if Needed if (posStruct.LoopEndIsLoopLength) { loopEndValue += loopStartValue; } if (loopStartValue < loopEndValue) { // update working item currentItem.LoopStart = loopStartValue; currentItem.LoopEnd = loopEndValue; } else { throw new Exception(String.Format("Loop Start Value greater than or equal Loop End Value: {0}", pPath)); } } else { throw new IndexOutOfRangeException(String.Format("Loop End Value not Found or Loop End is Less than 0: {0}", pPath)); } } else { throw new IndexOutOfRangeException(String.Format("Loop Start Value not Found or Loop Start is Less than 0: {0}", pPath)); } } catch (Exception ex) { this.progressStruct.Clear(); this.progressStruct.GenericMessage = String.Format("Cannot find loop points for <{0}>: {1}{2}", Path.GetFileName(pPath), ex.Message, Environment.NewLine); ReportProgress(Constants.ProgressMessageOnly, this.progressStruct); } } #endregion #region LOOP SHIFT // get list of matching WAV files outputFileList = Directory.GetFiles(Path.GetDirectoryName(pPath), outputFileMask, SearchOption.TopDirectoryOnly); // loop over list and add each item to the dictionary foreach (string outputFile in outputFileList) { // only shift valid values if ((loopStartValue != DEFAULT_LOOP_VALUE) && (loopEndValue != DEFAULT_LOOP_VALUE)) { // Static Loop Shift if (posStruct.DoStaticLoopShift) { // update shift currentItem.LoopShift = ByteConversion.GetLongValueFromString(posStruct.StaticLoopShiftValue); } else if (posStruct.DoLoopShiftWavCompare) // Wav Compare { // get samplecount for this file currentItem.WavSamples = GetSampleCountForRiffHeaderedFile(outputFile); currentItem.SampleDifference = currentItem.WavSamples - currentItem.LoopEnd; // update shift currentItem.LoopShift = currentItem.SampleDifference; } } this.WorkingList.Add(outputFile, currentItem); } #endregion }