public static ScannerItem FromFileData(IFileData fileData, ReplayGainMode mode) { var scannerItem = new ScannerItem() { FileName = fileData.FileName, Mode = mode }; if (mode == ReplayGainMode.Album) { var parts = new List <string>(); lock (fileData.MetaDatas) { var metaDatas = fileData.MetaDatas.ToDictionary( element => element.Name, StringComparer.OrdinalIgnoreCase ); var metaDataItem = default(MetaDataItem); if (metaDatas.TryGetValue(CommonMetaData.Year, out metaDataItem)) { parts.Add(metaDataItem.Value); } if (metaDatas.TryGetValue(CommonMetaData.Album, out metaDataItem)) { parts.Add(metaDataItem.Value); } } scannerItem.GroupName = string.Join(" - ", parts); } return(scannerItem); }
public ScanTaskBase(BassReplayGainScannerBehaviour behaviour, IFileData[] fileDatas, ReplayGainMode mode) : this() { this.Behaviour = behaviour; this.FileDatas = fileDatas; this.ScannerItems = fileDatas .OrderBy(fileData => fileData.FileName) .Select(fileData => ScannerItem.FromFileData(fileData, mode)) .ToArray(); }
protected virtual bool ScanTrack(ScannerItem scannerItem, IBassStream stream) { var info = default(ReplayGainInfo); if (!BassReplayGain.Process(stream.ChannelHandle, out info)) { return(false); } scannerItem.ItemPeak = info.peak; scannerItem.ItemGain = info.gain; return(true); }
protected virtual string GetDescription(ScannerItem scannerItem) { var builder = new StringBuilder(); builder.Append(scannerItem.FileName); if (scannerItem.Status != ScannerItemStatus.Complete && scannerItem.Errors.Any()) { builder.AppendLine(" -> Error"); foreach (var error in scannerItem.Errors) { builder.AppendLine('\t' + error); } } else { builder.AppendLine(" -> OK"); } return(builder.ToString()); }
protected virtual void ScanTrack(ScannerItem scannerItem) { var success = default(bool); var flags = BassFlags.Decode | BassFlags.Float; var stream = this.CreateStream(scannerItem.FileName, flags); if (stream.IsEmpty) { Logger.Write(this, LogLevel.Warn, "Failed to create stream for file \"{0}\": Unknown error.", scannerItem.FileName); throw new InvalidOperationException(string.Format("Failed to create stream for file \"{0}\": Unknown error.", scannerItem.FileName)); } Logger.Write(this, LogLevel.Debug, "Created stream for file \"{0}\": {1}", scannerItem.FileName, stream.ChannelHandle); var monitor = new ChannelMonitor(scannerItem, stream); try { monitor.Start(); success = this.ScanTrack(scannerItem, stream); } finally { monitor.Dispose(); Logger.Write(this, LogLevel.Debug, "Releasing stream for file \"{0}\": {1}", scannerItem.FileName, stream.ChannelHandle); Bass.StreamFree(stream.ChannelHandle); //Not checking result code as it contains an error if the application is shutting down. } if (this.CancellationToken.IsCancellationRequested) { scannerItem.Status = ScannerItemStatus.Cancelled; } else if (success) { scannerItem.Status = ScannerItemStatus.Complete; } else { Logger.Write(this, LogLevel.Warn, "Scanning file \"{0}\" failed: The format is likely not supported.", scannerItem.FileName); scannerItem.AddError("The format is likely not supported."); scannerItem.Status = ScannerItemStatus.Failed; } }
public BassScannerMonitorEventArgs(ScannerItem scannerItem) { this.ScannerItem = scannerItem; }
public ReportRow(Guid id, IFileData fileData, ScannerItem scannerItem) { this.Id = id; this.FileData = fileData; this.ScannerItem = scannerItem; }
protected virtual IFileData GetFileData(ScannerItem scannerItem) { return(this.FileDatas.FirstOrDefault(fileData => string.Equals(fileData.FileName, scannerItem.FileName, StringComparison.OrdinalIgnoreCase))); }
public ChannelMonitor(ScannerItem scannerItem, IBassStream stream) { this.ScannerItem = scannerItem; this.Stream = stream; }