Ejemplo n.º 1
0
        public void AddToLibrary(String FilePath)
        {
            if (Track == null)
            {
                Track = Track.Load(FilePath);
            }
            if (Track == null)
            {
                this.DownloadStatus = PodcastDownloadStatus.Error;
                throw new Exception("failed");
            }
            Track.Title        = this.Title;
            Track.Album        = Subscription.Name;
            Track.Genre        = this.Subscription.DefaultGenre;
            Track.RenameFormat = TrackWriter.RenameFormat.AR_AL_TK_TI;
            TrackWriter.AddToUnsavedTracks(Track);

            Database.AddToLibrary(Track, true, false);

            TrackWriter.Start();
        }
Ejemplo n.º 2
0
        private static void addItems()
        {
            try
            {
                running = true;
                cancel  = false;
                int itemsLeft;
                lock (addItemLock)
                {
                    itemsLeft = itemsToAdd.Count;
                }

                while (!cancel && itemsLeft > 0)
                {
                    ItemToAdd ita;
                    lock (addItemLock)
                    {
                        ita = itemsToAdd[0];
                        itemsToAdd.RemoveAt(0);
                    }
                    if (Directory.Exists(ita.FilePath))
                    {
                        List <ItemToAdd> newItems = new List <ItemToAdd>();
                        DirectoryInfo    di       = new DirectoryInfo(ita.FilePath);
                        foreach (FileInfo fi in di.GetFiles())
                        {
                            newItems.Add(new ItemToAdd(fi.FullName, ita.PlaylistTarget, ita.AllowDuplicates));
                        }
                        foreach (DirectoryInfo ddi in di.GetDirectories())
                        {
                            newItems.Add(new ItemToAdd(ddi.FullName, ita.PlaylistTarget, ita.AllowDuplicates));
                        }

                        lock (addItemLock)
                        {
                            itemsToAdd = itemsToAdd.Union(newItems).ToList();
                        }
                    }
                    else
                    {
                        if (Track.IsValidExtension(Path.GetExtension(ita.FilePath)))
                        {
                            Track tt = Track.Load(ita.FilePath);
                            if (tt != null)
                            {
                                Database.AddLibraryResult alr = Database.AddToLibrary(tt, ita.AllowDuplicates, true);

                                TrackWriter.AddToUnsavedTracks(tt);

                                if (ita.PlaylistTarget.Length > 0)
                                {
                                    Database.AddToPlaylist(ita.PlaylistTarget, tt);
                                }

                                switch (alr)
                                {
                                case Database.AddLibraryResult.OK:
                                    Controller.ShowMessage("Loading: " + (++addCount).ToString() + " - " + tt.ToString());
                                    break;

                                case Database.AddLibraryResult.UpdateOnly:
                                    Controller.ShowMessage("Updating: " + (++addCount).ToString() + " - " + tt.ToString());
                                    break;
                                }
                                if (((addCount < 200) && ((addCount % 10) == 0)) || (addCount % 200 == 0))
                                {
                                    tryCallback();
                                }
                            }
                        }
                    }

                    lock (addItemLock)
                    {
                        itemsLeft = itemsToAdd.Count;
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            running = false;
            lock (addItemLock)
            {
                if (cancel)
                {
                    itemsToAdd.Clear();
                }
            }
            tryCallback();
            TrackWriter.Start();
        }
Ejemplo n.º 3
0
        public void DoReplayGainAnalysis()
        {
            try
            {
                Controller.ShowMessage("Starting volume leveling analysis...");

                List <List <Track> > albums = partitionByAlbum(tracks);

                byte[]  buffer = new byte[READ_BUFFER_SIZE];
                float[] left   = new float[READ_BUFFER_SIZE / 4];
                float[] right  = new float[READ_BUFFER_SIZE / 4];
                int     numSamples;

                foreach (List <Track> album in albums)
                {
                    try
                    {
                        if (rga.InitGainAnalysis(album[0].SampleRate))
                        {
                            foreach (Track t in album)
                            {
                                AudioStream stream = new AudioStreamFile(t, 0, new float[10], 10, false, ReplayGainMode.Off);

                                while ((numSamples = stream.Read(buffer, 0, READ_BUFFER_SIZE)) > 0)
                                {
                                    int inputBufferSize = numSamples / 4;
                                    for (int i = 0; i < inputBufferSize; i++)
                                    {
                                        left[i]  = AudioStreamBass.from16Bit(buffer[i * 4 + 1] * 0x100 + buffer[i * 4]);
                                        right[i] = AudioStreamBass.from16Bit(buffer[i * 4 + 3] * 0x100 + buffer[i * 4 + 2]);
                                    }
                                    rga.AnalyzeSamples(left, right, inputBufferSize);
                                    if (cancel)
                                    {
                                        callback();
                                        return;
                                    }
                                }
                                stream.Close();
                                t.ReplayGainTrack = rga.GetTrackGain();
                                numTracksDone++;
                                Controller.ShowMessage(String.Format("{0}/{1}: Volume analyzed for '{2}'", numTracksDone.ToString(), numTracks.ToString(), t.ToShortString()));
                            }
                            float albumGain = rga.GetAlbumGain();
                            foreach (Track t in album)
                            {
                                t.ReplayGainAlbum = albumGain;
                            }
                            if (Setting.WriteReplayGainTags)
                            {
                                foreach (Track t in album)
                                {
                                    t.ChangeType |= ChangeType.WriteTags;
                                }
                                TrackWriter.AddToUnsavedTracks(album);
                                TrackWriter.Start();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }
            callback();
        }