public IAudioSource GetAudioSource()
 {
     IAudioSource fullFileSource = AudioHelper.GetAudioSourceForFile(this.targetFilename);
     AudioSourcePart partSource = new AudioSourcePart(fullFileSource);
     partSource.SetLengthFrames(
         this.cueSheet.GetTrackStartFrame(this.trackIndex),
         this.cueSheet.GetTrackEndFrame(this.trackIndex));
     return partSource;
 }
        private void WorkerTask()
        {
            while (true)
            {
                string item;
                if (this.shouldCancel || !this.tasks.TryTake(out item, -1))
                {
                    break;
                }

                try
                {
                    if (AudioHelper.IsSupportedAudioSource(item))
                    {
                        this.ProcessAudio(AudioHelper.GetAudioSourceForFile(item), Path.GetDirectoryName(item), Path.GetFileName(item));
                    }
                    else if (item.ToLower().EndsWith(".cue"))
                    {
                        CueSheet sheet = new CueSheet(item);

                        bool isOriginal;
                        string target = sheet.DiscoverTarget(out isOriginal);
                        if (target == null)
                        {
                            Dialogs.Error("Cue target not found.");
                            continue;
                        }
                        for (int i = 0; i < sheet.Tracks.Length; ++i)
                        {
                            IAudioSource fullFileSource = AudioHelper.GetAudioSourceForFile(target);
                            AudioSourcePart sourcePart = new AudioSourcePart(fullFileSource);
                            sourcePart.SetLengthFrames(
                                sheet.GetTrackStartFrame(i),
                                sheet.GetTrackEndFrame(i));
                            this.ProcessAudio(sourcePart, target, (i + 1).ToString("00") + ". " + sheet.Tracks[i].Title);
                        }
                    }
                }
                catch (Exception e)
                {
                    Utility.WriteToErrorLog(e.ToString());
                    Dialogs.Error("Error processing file " + item + ": " + e.Message);
                }
            }
        }