コード例 #1
0
ファイル: ScannerItem.cs プロジェクト: Raimusoft/FoxTunes
        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);
        }
コード例 #2
0
 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();
 }
コード例 #3
0
        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);
        }
コード例 #4
0
        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());
        }
コード例 #5
0
        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;
            }
        }
コード例 #6
0
 public BassScannerMonitorEventArgs(ScannerItem scannerItem)
 {
     this.ScannerItem = scannerItem;
 }
コード例 #7
0
 public ReportRow(Guid id, IFileData fileData, ScannerItem scannerItem)
 {
     this.Id          = id;
     this.FileData    = fileData;
     this.ScannerItem = scannerItem;
 }
コード例 #8
0
 protected virtual IFileData GetFileData(ScannerItem scannerItem)
 {
     return(this.FileDatas.FirstOrDefault(fileData => string.Equals(fileData.FileName, scannerItem.FileName, StringComparison.OrdinalIgnoreCase)));
 }
コード例 #9
0
ファイル: ChannelMonitor.cs プロジェクト: Raimusoft/FoxTunes
 public ChannelMonitor(ScannerItem scannerItem, IBassStream stream)
 {
     this.ScannerItem = scannerItem;
     this.Stream      = stream;
 }