Esempio n. 1
0
 private void showFilterIndexCallback(frmIndex fi)
 {
     if (fi.NoData)
     {
         Controller.ShowMessage(Localization.Get(UI_Key.Message_No_Index_Items_Available));
     }
     else
     {
         if (fi.Char != '\0')
         {
             bool wasOff = fi.Button.ValueType == FilterValueType.None;
             if (fi.Char == frmIndex.CLEAR_CHAR)
             {
                 fi.Button.ValueType = FilterValueType.None;
             }
             else
             {
                 fi.Button.StartChar = fi.Char;
                 fi.Button.ValueType = FilterValueType.StartChar;
             }
             filterChanged(fi.Button, wasOff);
             fi.Button.Invalidate();
         }
         RemoveFilterIndex();
     }
 }
Esempio n. 2
0
 private static void refreshFiles()
 {
     try
     {
         IEnumerable <Track> all = Database.LibrarySnapshot;
         foreach (Track t in all)
         {
             if (t.ConfirmExists)
             {
                 t.ForceLoad();
                 Controller.ShowMessage("Updating: " + t.ToString());
             }
             Database.IncrementDatabaseVersion(false);
             if (cancel)
             {
                 break;
             }
         }
         tryCallback();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.ToString());
     }
 }
Esempio n. 3
0
        private static void getLibrary()
        {
            iTunesApp app = new iTunesApp();

            app.ForceToForegroundOnDialog = true;

            IITTrackCollection tc = app.LibraryPlaylist.Tracks;

            Controller.ShowMessage(tc.Count.ToString() + " tracks found...");

            List <string> tracks = new List <string>();

            foreach (IITTrack t in tc)
            {
                if (Cancel)
                {
                    break;
                }

                if (t.Kind == ITTrackKind.ITTrackKindFile)
                {
                    string l = (t as IITFileOrCDTrack).Location;
                    Controller.ShowMessage(t.Name);
                    tracks.Add(l);
                }
            }
            if (!Cancel)
            {
                FileAdder.AddItemsToLibrary(tracks, String.Empty, true, Controller.GetInstance().RefreshAll);
            }
        }
Esempio n. 4
0
 private void MyDownloadProc(IntPtr buffer, int length, IntPtr user)
 {
     if (buffer != IntPtr.Zero && length == 0)
     {
         Controller.ShowMessage(Marshal.PtrToStringAnsi(buffer));
     }
 }
Esempio n. 5
0
        private bool setup(int Frequency)
        {
            frequency     = Frequency;
            callback      = callback24;
            twentyFourBit = true;

            if (setupChannel(Frequency, BASSASIOFormat.BASS_ASIO_FORMAT_24BIT) &&
                BassAsio.BASS_ASIO_ChannelGetFormat(false, 0) == BASSASIOFormat.BASS_ASIO_FORMAT_24BIT)
            {
                Controller.ShowMessage("24-bit ASIO");
            }
            else
            {
                System.Diagnostics.Debug.WriteLine(BassAsio.BASS_ASIO_ErrorGetCode());

                callback      = callback16;
                twentyFourBit = false;

                if (setupChannel(Frequency, BASSASIOFormat.BASS_ASIO_FORMAT_16BIT))
                {
                    Controller.ShowMessage("16-bit ASIO");
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine(BassAsio.BASS_ASIO_ErrorGetCode());
                    return(false);
                }
            }
            return(true);
        }
Esempio n. 6
0
 private static void removeGhosts()
 {
     try
     {
         List <Track> toRemove = Database.FindAllTracks(t => !t.ConfirmExists);
         Controller.ShowMessage("Removing " + toRemove.Count + " tracks from library...");
         Database.RemoveFromLibrary(toRemove);
         tryCallback();
     }
     catch (Exception ex)
     {
         System.Diagnostics.Debug.WriteLine(ex.ToString());
     }
 }
Esempio n. 7
0
        protected override void OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            Item i = Item.MouseMove(e.Location);

            if (i == null)
            {
                this.Cursor = Cursors.Default;
            }
            else
            {
                this.Cursor = Cursors.Hand;
                Controller.ShowMessage(i.ToString());
            }
        }
Esempio n. 8
0
        public static void GetLibrary()
        {
            ITDETECTORLib.iTunesDetector iDetect = new ITDETECTORLib.iTunesDetector();
            if (iDetect.IsiTunesAvailable)
            {
                Controller.ShowMessage("Initializing iTunes...");

                Cancel = false;
                Busy   = true;

                Clock.DoOnNewThread(getLibrary, 200);
            }
            else
            {
                ShowError();
            }
        }
Esempio n. 9
0
        private void doBulkUpdate()
        {
            int i       = newPath.Length - 1;
            int lenDiff = newPath.Length - oldPath.Length;

            while (i >= lenDiff && newPath[i] == oldPath[i - lenDiff])
            {
                i--;
            }
            i++;
            string oldStart       = oldPath.Substring(0, i - lenDiff);
            string newStart       = newPath.Substring(0, i);
            int    oldStartLength = oldStart.Length;

            int count    = 0;
            int badCount = 0;

            List <Track> tracks = Database.LibrarySnapshot;

            for (int j = 0; j < tracks.Count; j++)
            {
                Track tt = tracks[j];

                if (tt.Exists != true && tt.FilePath.StartsWith(oldStart, StringComparison.OrdinalIgnoreCase) && !tt.ConfirmExists)
                {
                    string s = newStart + tt.FilePath.Substring(oldStartLength);
                    if (File.Exists(s))
                    {
                        tt.FilePath      = s;
                        tt.ConfirmExists = true;
                        count++;
                        Controller.ShowMessage(Localization.Get(UI_Key.Find_File_Message_Updating, count.ToString(), tt.ToShortString()));
                        Controller.GetInstance().Invalidate();
                    }
                    else
                    {
                        badCount++;
                    }
                }
                else
                {
                    badCount++;
                }
            }
            Database.IncrementDatabaseVersion(true);
        }
Esempio n. 10
0
 public void TempDisplayTrackInfo(Track t)
 {
     if (t != null)
     {
         if (Setting.ShowAlbumArtOnMainScreen)
         {
             if (controller.Playing)
             {
                 artwork.TemporaryTrack = t;
             }
             else
             {
                 artwork.CurrentTrack = t;
             }
         }
         updateFilterHint(t);
         Controller.ShowMessage(t.ToString());
     }
 }
Esempio n. 11
0
        public static void CreatePlaylist(string Name, List <Track> Tracks)
        {
            ITDETECTORLib.iTunesDetector iDetect = new ITDETECTORLib.iTunesDetector();
            if (iDetect.IsiTunesAvailable)
            {
                Controller.ShowMessage("Initializing iTunes...");

                Cancel = false;
                Busy   = true;

                playlistName = Name;
                tracks       = Tracks.ToList();
                Clock.DoOnNewThread(createPlaylist, 200);
            }
            else
            {
                ShowError();
            }
        }
Esempio n. 12
0
        public static Output GetOutput(string Name, int Frequency, Form ParentForm, GetSampleDelegate Callback16, GetSampleDelegate Callback24, Player Player)
        {
            try
            {
                if (OutputASIO.DeviceExists(Name))
                {
                    Output o = new OutputASIO(Name, Frequency, Callback24, Callback16, Player);

                    if (o != null && o.Playing)
                    {
                        return(o);
                    }
                    else
                    {
                        Controller.ShowMessage("ASIO output failed; using default output device.");
                        return(new OutputDX(String.Empty, Frequency, Callback16, ParentForm, Player));
                    }
                }
            }
            catch { }

            return(new OutputDX(Name, Frequency, Callback16, ParentForm, Player));
        }
Esempio n. 13
0
        public static void AddItemsToLibrary(IEnumerable <string> FilePaths, string PlaylistTarget, bool AllowDuplicates, Callback Callback)
        {
            callback = Callback;

            lock (addItemLock)
            {
                foreach (string s in FilePaths)
                {
                    itemsToAdd.Add(new ItemToAdd(s, PlaylistTarget, AllowDuplicates));
                }
            }

            if (!running)
            {
                Controller.ShowMessage(Localization.Get(UI_Key.Background_Cataloging_Tracks));
                addCount = 0;

                Thread t = new Thread(addItems);
                t.Name         = "Add Items";
                t.Priority     = ThreadPriority.Normal;
                t.IsBackground = true;
                t.Start();
            }
        }
Esempio n. 14
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();
        }
Esempio n. 15
0
 private void checkForNewEpisodes(PodcastSubscription PS)
 {
     Controller.ShowMessage("Checking for podcast updates...");
     Clock.DoOnNewThread(PS.UpdateEpisodeInfo);
 }
Esempio n. 16
0
 private void stopDownloads()
 {
     PodcastSubscription.StopDownloads();
     InvalidateAll();
     Controller.ShowMessage("Podcast downloads stopped.");
 }
Esempio n. 17
0
        protected override void OnKeyDown(KeyEventArgs e)
        {
            normal.RemoveFilterIndex();

            if (Locked && e.KeyCode != KeyDefs.AdvanceScreen)
            {
                base.OnKeyDown(e);
                return;
            }
            if (e.Alt)
            {
                if (e.KeyCode == KeyDefs.Enter)
                {
                    if (Lib.FullScreen)
                    {
                        controller.RequestAction(QActionType.ReleaseFullScreen);
                    }
                    else
                    {
                        controller.RequestAction(QActionType.SetFullScreen);
                    }
                    e.Handled = true;
                }
            }
            else
            {
                e.Handled = true;
                switch (e.KeyCode)
                {
                case KeyDefs.Enter:
                    if (e.Shift)
                    {
                        if (controller.AllowTagEditing)
                        {
                            controller.RequestAction(QActionType.EditTags);
                        }
                    }
                    else
                    {
                        controller.RequestAction(QActionType.PlaySelectedTracks);
                    }
                    break;

                case KeyDefs.Play:
                case KeyDefs.Play2:
                    controller.RequestAction(QActionType.Play);
                    break;

                case KeyDefs.Pause:
                    controller.RequestAction(QActionType.Pause);
                    break;

                case KeyDefs.PlayPause:
                    controller.RequestAction(QActionType.TogglePlayPause);
                    break;

                case KeyDefs.Stop:
                case KeyDefs.Stop2:
                    if (e.Shift)
                    {
                        controller.RequestAction(QActionType.StopAfterThisTrack);
                    }
                    else
                    {
                        controller.RequestAction(QActionType.Stop);
                    }
                    break;

                case KeyDefs.Next:
                case KeyDefs.Next2:
                    controller.RequestAction(QActionType.Next);
                    break;

                case KeyDefs.Previous:
                case KeyDefs.Previous2:
                    controller.RequestAction(QActionType.Previous);
                    break;

                case KeyDefs.ScanFwd:
                    controller.RequestAction(QActionType.ScanFwd);
                    break;

                case KeyDefs.ScanBack:
                    controller.RequestAction(QActionType.ScanBack);
                    break;

                case KeyDefs.PlayThisAlbum:
                    if (e.Shift)
                    {
                        controller.RequestAction(QActionType.AddAlbumToNowPlaying);
                    }
                    else
                    {
                        controller.RequestAction(QActionType.PlayThisAlbum);
                    }
                    break;

                case KeyDefs.FocusSearchBox:
                    controller.RequestAction(QActionType.FocusSearchBox);
                    break;

                case KeyDefs.ShowPlayingTrack:
                    controller.RequestAction(QActionType.FindPlayingTrack);
                    break;

                case KeyDefs.Podcasts:
                    controller.RequestAction(QActionType.TogglePodcastView);
                    break;

                case KeyDefs.Delete:
                    controller.RequestAction(QActionType.Delete);
                    break;

                case KeyDefs.SelectAllOrNone:
                    if (e.Control)
                    {
                        if (e.Shift)
                        {
                            controller.RequestAction(QActionType.SelectNone);
                        }
                        else
                        {
                            controller.RequestAction(QActionType.SelectAll);
                        }
                    }
                    else
                    {
                        e.Handled = false;
                    }
                    break;

                case KeyDefs.Shuffle:
                    if (e.Shift)
                    {
                        Lib.DoEvents();
                        controller.RequestAction(QActionType.PlayRandomAlbum);
                    }
                    else
                    {
                        controller.RequestAction(QActionType.Shuffle);
                    }
                    break;

                case KeyDefs.AutoPlaylistAction:
                    if (e.Shift)
                    {
                        controller.RequestAction(QActionType.ConvertToStandardPlaylist);
                    }
                    else
                    {
                        controller.RequestAction(QActionType.EditAutoPlaylist);
                    }
                    break;

                case KeyDefs.ClearAllFilters:
                    controller.RequestAction(QActionType.ReleaseAllFilters);
                    break;

                case KeyDefs.FilterSelected:
                    if (e.Shift)
                    {
                        controller.RequestAction(QActionType.FilterSelectedAlbum);
                    }
                    else if (e.Control)
                    {
                        controller.RequestAction(QActionType.FilterSelectedGenre);
                    }
                    else
                    {
                        controller.RequestAction(QActionType.FilterSelectedArtist);
                    }
                    break;

                case KeyDefs.ShowInfoFromInternet:
                    if (e.Control)
                    {
                        controller.RequestAction(QActionType.LastFMShowAlbum);
                    }
                    else if (e.Shift)
                    {
                        controller.RequestAction(QActionType.LastFMShowArtist);
                    }
                    else
                    {
                        controller.RequestAction(QActionType.ShowTrackAndAlbumDetails);
                    }
                    break;

                case KeyDefs.PlaySelectedNext:
                    controller.RequestAction(QActionType.PlaySelectedTrackNext);
                    break;

                case KeyDefs.PlaylistAction:
                    if (e.Shift)
                    {
                        controller.RequestAction(QActionType.ViewNowPlaying);
                    }
                    else if (e.Control)
                    {
                        if (controller.PlaylistExists(controller.TargetPlaylistName) && normal.HasSelectedTracks)
                        {
                            if (normal.SelectedTracks.Count == 1)
                            {
                                controller.RequestAction(QActionType.AddToTargetPlaylistAndAdvance);
                            }
                            else
                            {
                                controller.RequestAction(QActionType.AddToTargetPlaylist);
                            }
                        }
                    }
                    else
                    {
                        controller.RequestAction(QActionType.AddToNowPlayingAndAdvance);
                    }
                    break;

                case KeyDefs.FileInfo:
                    if (e.Shift)
                    {
                        controller.RequestAction(QActionType.RefreshSelectedTracks);
                    }
                    else
                    {
                        controller.RequestAction(QActionType.ShowFileDetails);
                    }
                    break;

                case KeyDefs.ShowEqualizer:
                    if (e.Control)
                    {
                        controller.RequestAction(QActionType.ShowEqualizer);
                    }
                    else if (e.Shift)
                    {
                        controller.RequestAction(QActionType.SelectNextEqualizer);
                    }
                    else
                    {
                        controller.RequestAction(QActionType.ToggleEqualizer);
                    }
                    break;

                case KeyDefs.MiniPlayer:
                    controller.RequestAction(QActionType.ShowMiniPlayer);
                    break;

                case KeyDefs.HTPCMode:
                    if (e.Shift)
                    {
                        controller.RequestAction(QActionType.ShowTagCloud);
                    }
                    else
                    {
                        controller.RequestAction(QActionType.HTPCMode);
                    }
                    break;

                case KeyDefs.AdvanceScreen:
                    controller.RequestAction(QActionType.AdvanceScreenWithoutMouse);
                    break;

                case KeyDefs.GainUp:
                    controller.RequestAction(QActionType.SpectrumViewGainUp);
                    break;

                case KeyDefs.GainDown:
                    controller.RequestAction(QActionType.SpectrumViewGainDown);
                    break;

                case KeyDefs.VolUp:
                case KeyDefs.VolUp2:
                    controller.RequestAction(QActionType.VolumeUp);
                    break;

                case KeyDefs.VolDown:
                case KeyDefs.VolDown2:
                    controller.RequestAction(QActionType.VolumeDown);
                    break;

                case KeyDefs.Mute:
                    controller.RequestAction(QActionType.Mute);
                    break;

                case KeyDefs.Radio:
                    if (e.Shift)
                    {
                        controller.RequestAction(QActionType.RepeatToggle);
                    }
                    else
                    {
                        controller.RequestAction(QActionType.ToggleRadioMode);
                    }
                    break;

                case KeyDefs.Gain:
                    if (e.Shift)
                    {
                        controller.RequestAction(QActionType.ReplayGainAnalyzeSelectedTracks);
                    }
                    break;

                case KeyDefs.Exit:
                    if (e.Shift)
                    {
                        Controller.ShowMessage(Localization.Get(UI_Key.General_Exit));
                        controller.RequestAction(QActionType.Exit);
                    }
                    break;

                case KeyDefs.Cancel:
                    controller.RequestAction(QActionType.Cancel);
                    break;

                case KeyDefs.PreviousFilter:
                    controller.RequestAction(QActionType.PreviousFilter);
                    break;

                case KeyDefs.NextFilter:
                    controller.RequestAction(QActionType.NextFilter);
                    break;

                case KeyDefs.ReleaseCurrentFilter:
                    controller.RequestAction(QActionType.ReleaseCurrentFilter);
                    break;

                case KeyDefs.ReleaseAllFilters:
                    controller.RequestAction(QActionType.ReleaseAllFilters);
                    break;

                case KeyDefs.ShowFilterIndex:
                    controller.RequestAction(QActionType.ShowFilterIndex);
                    break;

                case KeyDefs.PageUp:
                    controller.RequestAction(QActionType.PageUp);
                    break;

                case KeyDefs.PageDown:
                    controller.RequestAction(QActionType.PageDown);
                    break;

                case KeyDefs.Home:
                    controller.RequestAction(QActionType.Home);
                    break;

                case KeyDefs.End:
                    controller.RequestAction(QActionType.End);
                    break;

                case KeyDefs.Playlists:
                    if (e.Shift)
                    {
                        System.Diagnostics.Debug.Assert(e.KeyCode == KeyDefs.One);
                        controller.SetRatingOfSelectedTracks(1);
                    }
                    else
                    {
                        normal.CurrentFilterType = FilterType.Playlist;
                    }
                    break;

                case KeyDefs.Genres:
                    if (e.Shift)
                    {
                        System.Diagnostics.Debug.Assert(e.KeyCode == KeyDefs.Two);
                        controller.SetRatingOfSelectedTracks(2);
                    }
                    else
                    {
                        normal.CurrentFilterType = FilterType.Genre;
                    }
                    break;

                case KeyDefs.Artists:
                    if (e.Shift)
                    {
                        System.Diagnostics.Debug.Assert(e.KeyCode == KeyDefs.Three);
                        controller.SetRatingOfSelectedTracks(3);
                    }
                    else
                    {
                        normal.CurrentFilterType = FilterType.Artist;
                    }
                    break;

                case KeyDefs.Albums:
                    if (e.Shift)
                    {
                        System.Diagnostics.Debug.Assert(e.KeyCode == KeyDefs.Four);
                        controller.SetRatingOfSelectedTracks(4);
                    }
                    else
                    {
                        normal.CurrentFilterType = FilterType.Album;
                    }
                    break;

                case KeyDefs.Years:
                    if (e.Shift)
                    {
                        System.Diagnostics.Debug.Assert(e.KeyCode == KeyDefs.Five);
                        controller.SetRatingOfSelectedTracks(5);
                    }
                    else
                    {
                        normal.CurrentFilterType = FilterType.Year;
                    }
                    break;

                case KeyDefs.Zero:
                    if (e.Shift)
                    {
                        controller.SetRatingOfSelectedTracks(0);
                    }
                    break;

                case KeyDefs.Groupings:
                    normal.CurrentFilterType = FilterType.Grouping;
                    break;

                default:
                    e.Handled = false;
                    break;
                }
            }
            base.OnKeyDown(e);
        }
Esempio n. 18
0
        public void Download()
        {
            cancelAllDownloads = false;
            cancelThisDownload = false;
            if (this.FileExists)
            {
                if (this.DownloadStatus != PodcastDownloadStatus.Played)
                {
                    this.DownloadStatus = PodcastDownloadStatus.Unplayed;
                }
            }
            else
            {
                using (WebClient client = new WebClient())
                {
                    this.DownloadStatus = PodcastDownloadStatus.DownloadInProgress;
                    updateDownloadStatusString();

                    Stream          localStream   = null;
                    Stream          resposeStream = null;
                    HttpWebRequest  webRequest    = null;
                    HttpWebResponse webResponse   = null;

                    try
                    {
                        long totalSize = 1;

                        string localTempFile = Path.GetTempFileName();

                        webRequest             = (HttpWebRequest)WebRequest.Create(this.URL);
                        webRequest.Credentials = CredentialCache.DefaultCredentials;
                        webRequest.ServicePoint.Expect100Continue = false;
                        webResponse   = (HttpWebResponse)webRequest.GetResponse();
                        totalSize     = webResponse.ContentLength;
                        resposeStream = client.OpenRead(this.URL);
                        localStream   = new FileStream(localTempFile,
                                                       FileMode.Create,
                                                       FileAccess.Write,
                                                       FileShare.None);

                        bool   showProgress  = totalSize > 100000;
                        int    chunkSize     = 0;
                        long   bytesRecd     = 0;
                        long   nextThreshold = 0;
                        byte[] downBuffer    = new byte[2048];

                        while ((chunkSize = resposeStream.Read(downBuffer, 0, downBuffer.Length)) > 0)
                        {
                            if (cancelAllDownloads || cancelThisDownload)
                            {
                                this.DownloadStatus = PodcastDownloadStatus.DownloadCanceled;
                                return;
                            }
                            if (showProgress)
                            {
                                bytesRecd += chunkSize;
                                if (bytesRecd > nextThreshold)
                                {
                                    nextThreshold += totalSize / NUM_DOWNLOAD_UPDATES;
                                    updateDownloadStatusString("Downloading: " + (bytesRecd * 100L / totalSize).ToString() + "%");
                                }
                            }
                            localStream.Write(downBuffer, 0, chunkSize);
                        }

                        localStream.Close();
                        localStream = null;

                        if (!Directory.Exists(Setting.PodcastDownloadDirectory))
                        {
                            try
                            {
                                Directory.CreateDirectory(Setting.PodcastDownloadDirectory);
                            }
                            catch
                            {
                            }
                            if (!Directory.Exists(Setting.PodcastDownloadDirectory))
                            {
                                Setting.PodcastDownloadDirectory = Environment.GetFolderPath(Environment.SpecialFolder.MyMusic);
                                if (!Directory.Exists(Setting.PodcastDownloadDirectory))
                                {
                                    Directory.CreateDirectory(Setting.PodcastDownloadDirectory);
                                }
                            }
                        }
                        if (!Directory.Exists(Setting.PodcastDownloadDirectory))
                        {
                            throw new Exception("failed2");
                        }
                        string fileName    = Lib.ReplaceBadFilenameChars(this.Subscription.Name + " - " + this.Title);
                        string newPathRoot = Path.Combine(Setting.PodcastDownloadDirectory, fileName);
                        string ext         = Path.GetExtension(this.URL);

                        string newPath = newPathRoot + ext;
                        if (File.Exists(newPath))
                        {
                            int i = 1;
                            do
                            {
                                newPath = newPathRoot + (i++).ToString() + ext;
                            }while (File.Exists(newPath));
                        }

                        File.Copy(localTempFile, newPath);
                        TrackWriter.AddToDeleteList(localTempFile);
                        TrackWriter.DeleteItems();

                        AddToLibrary(newPath);

                        fileExists = null;

                        this.DownloadStatus = PodcastDownloadStatus.Unplayed;
                        this.DownloadDate   = DateTime.Now;
                        if (this.DownloadDate > this.Subscription.LastDownloadDate)
                        {
                            this.Subscription.LastDownloadDate = this.DownloadDate;
                        }
                    }
                    catch (Exception ex)
                    {
                        System.Diagnostics.Debug.WriteLine(ex.ToString());
                        this.DownloadStatus = PodcastDownloadStatus.Error;
                        Controller.ShowMessage("Download of " + this.Title + " failed.");
                    }
                    finally
                    {
                        if (localStream != null)
                        {
                            localStream.Close();
                        }
                        if (resposeStream != null)
                        {
                            resposeStream.Close();
                        }
                        if (webResponse != null)
                        {
                            webResponse.Close();
                        }

                        updateDownloadStatusString();
                    }
                }
            }
            System.Diagnostics.Debug.Assert(!this.IsDownloading);
            if (DataChanged != null)
            {
                DataChanged(this);
            }
        }
Esempio n. 19
0
        private void filterBarFilterValueChanged(FilterType Type, string Value, bool WasOff, bool StartsWith)
        {
            bool sort = !WasOff;

            ViewState.PreviousViewState = null;

            switch (Type)
            {
            case FilterType.Text:
                RefreshAll(sort);
                break;

            case FilterType.Playlist:
                if (StartsWith)
                {
                    RefreshAll(false);
                }
                else
                {
                    string s = ActivePlaylist;

                    PlaylistType pt = Database.GetPlaylistType(s);

                    switch (pt)
                    {
                    case PlaylistType.Auto:
                        Controller.ShowMessage(Localization.Get(UI_Key.Message_Is_Auto_Playlist, s));
                        break;

                    case PlaylistType.Standard:
                        Controller.ShowMessage(Localization.Get(UI_Key.Message_Is_Standard_Playlist, s));
                        break;

                    default:
                        Controller.ShowMessage(Localization.Get(UI_Key.Message_Is_System_Playlist, s));
                        break;
                    }

                    RefreshTrackList(sort);

                    if (pt == PlaylistType.Standard)
                    {
                        controller.TargetPlaylistName = s;
                    }

                    Queue.PlaylistBasis = s;

                    controller.UpdateNowPlaying();
                    controller.UpdateNextUpOrRadioBitrate();
                }
                break;

            default:
                if (StartsWith)
                {
                    RefreshAll(false);
                }
                else
                {
                    RefreshTrackList(sort);
                    controller.UpdateNextUpOrRadioBitrate();
                }
                break;
            }
        }
Esempio n. 20
0
        public void UpdateEpisodeInfo()
        {
            try
            {
                XmlDocument doc = new XmlDocument();
                doc.Load(URL);

                XmlNode baseNode = doc.SelectSingleNode("rss").FirstChild;

                if (baseNode != null)
                {
                    if (this.Name == UNKNOWN_TITLE || Keyboard.Shift)
                    {
                        this.Name = getXMLField(baseNode, "title");
                    }

                    this.ReferenceURL = getXMLField(baseNode, "link");

                    CultureInfo ci = CultureInfo.InvariantCulture;

                    foreach (XmlNode xn in doc.SelectNodes("//item"))
                    {
                        try
                        {
                            string url            = xn.SelectSingleNode("enclosure").Attributes["url"].Value;
                            string date           = String.Empty;
                            string guid           = String.Empty;
                            string title          = String.Empty;
                            string description    = String.Empty;
                            string durationString = String.Empty;
                            int    duration       = 0;

                            if (url.Length > 0 && Track.IsValidExtension(Path.GetExtension(url)))
                            {
                                foreach (XmlNode n in xn.ChildNodes)
                                {
                                    switch (n.Name.ToLowerInvariant())
                                    {
                                    case "pubdate":
                                        date = n.InnerText;
                                        break;

                                    case "guid":
                                        guid = n.InnerText;
                                        break;

                                    case "title":
                                        title = n.InnerText;
                                        break;

                                    case "description":
                                        if (description.Length == 0)
                                        {
                                            description = n.InnerText;
                                        }
                                        break;

                                    case "itunes:duration":
                                        durationString = n.InnerText;
                                        break;

                                    case "itunes:summary":
                                        description = n.InnerText;
                                        break;

                                    default:
                                        System.Diagnostics.Debug.WriteLine(n.Name.ToLowerInvariant());
                                        break;
                                    }
                                }
                                DateTime dt;
                                if (!DateTime.TryParse(date, out dt))
                                {
                                    if (!DateTime.TryParseExact(date, dateParseFormats, System.Globalization.CultureInfo.InvariantCulture, System.Globalization.DateTimeStyles.AllowWhiteSpaces, out dt))
                                    {
                                        dt = extractDate(date);
                                    }
                                }

                                if (guid.Length == 0)
                                {
                                    guid = url;
                                }

                                if (durationString.Length > 0)
                                {
                                    duration = durationFromString(durationString);
                                }

                                PodcastEpisode pe = new PodcastEpisode(title,
                                                                       guid,
                                                                       clean(description),
                                                                       url,
                                                                       dt,
                                                                       duration,
                                                                       DateTime.MinValue,
                                                                       PodcastDownloadStatus.NotDownloaded,
                                                                       null,
                                                                       this);
                                addEpisode(pe);
                            }
                        }
                        catch (Exception ex)
                        {
                            System.Diagnostics.Debug.WriteLine(ex.ToString());
                        }
                    }
                    updateValues();
                    if (DataChanged != null)
                    {
                        DataChanged(this);
                    }
                    Controller.ShowMessage("Refreshed " + this.Name);
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Controller.ShowMessage("Failed to find podcast updates.");
            }
        }
Esempio n. 21
0
        private void prebuffer()
        {
            int maxBufferTime = 4000;
            int sleepTime     = 50;
            int maxCount      = maxBufferTime / sleepTime;
            int count         = 0;

            if (isWMA)
            {
                long oldLen = -10000L;

                // display buffering for WMA...
                while (count++ < maxCount)
                {
                    long len = Bass.BASS_StreamGetFilePosition(streamRef, BASSStreamFilePosition.BASS_FILEPOS_WMA_BUFFER);

                    if (len == -1L) // typical for WMA
                    {
                        break;
                    }
                    // percentage of buffer filled
                    if (len > 75L)
                    {
                        break;         // over 75% full, enough
                    }
                    if (len != oldLen) // don't slam the updates if no change
                    {
                        Controller.ShowMessage(Localization.Get(UI_Key.Radio_Buffering, len));
                        oldLen = len;
                    }
                    System.Threading.Thread.Sleep(sleepTime);
                }
            }
            else
            {
                float oldProgress = -10000F;

                while (count++ < maxCount)
                {
                    long len = Bass.BASS_StreamGetFilePosition(streamRef, BASSStreamFilePosition.BASS_FILEPOS_END);

                    if (len == -1)
                    {
                        break;
                    }

                    float progress =
                        (
                            Bass.BASS_StreamGetFilePosition(streamRef, BASSStreamFilePosition.BASS_FILEPOS_DOWNLOAD) -
                            Bass.BASS_StreamGetFilePosition(streamRef, BASSStreamFilePosition.BASS_FILEPOS_CURRENT)
                        ) * 100f / len;

                    if (progress > 75f)
                    {
                        break; // over 75% full, enough
                    }

                    if (Math.Abs(progress - oldProgress) > 0.1F)
                    {
                        Controller.ShowMessage(Localization.Get(UI_Key.Radio_Buffering, progress));
                        oldProgress = progress;
                    }
                    System.Threading.Thread.Sleep(sleepTime);
                }
            }
            Controller.ShowMessage(Localization.Get(UI_Key.Radio_Buffered));
        }
Esempio n. 22
0
        private static void createPlaylist()
        {
            try
            {
                iTunesApp app = new iTunesApp();

                app.ForceToForegroundOnDialog = true;

                //app.SetOptions(); would be nice to kill autoarrange

                IITPlaylistCollection pl       = app.LibrarySource.Playlists;
                IITUserPlaylist       playlist = null;

                playlist = findPlaylist(pl, playlist);

                if (playlist == null)
                {
                    playlist = (IITUserPlaylist)app.CreatePlaylist(playlistName);
                }
                else
                {
                    // remove tracks, how?
                    foreach (IITTrack t in playlist.Tracks)
                    {
                        //t.Delete(); <== ?
                    }
                }

                iTunesLib.IITLibraryPlaylist lp = app.LibraryPlaylist;

                IITTrackCollection itTracks = app.LibraryPlaylist.Tracks;

                Dictionary <string, int> libraryTrackDictionary = new Dictionary <string, int>(StringComparer.OrdinalIgnoreCase);
                List <string>            libraryTrackFiles      = new List <string>();

                foreach (IITTrack t in itTracks)
                {
                    if (Cancel)
                    {
                        break;
                    }

                    if (t.Kind == ITTrackKind.ITTrackKindFile)
                    {
                        string l = (t as IITFileOrCDTrack).Location;
                        if (l != null)
                        {
                            libraryTrackFiles.Add(l);
                            if (!libraryTrackDictionary.ContainsKey(l))
                            {
                                libraryTrackDictionary.Add(l, t.Index);
                            }
                        }
                    }
                }
                List <string> allTracks = new List <string>();
                foreach (Track t in tracks)
                {
                    allTracks.Add(t.FilePath);
                }

                object oo = (object)(allTracks.ToArray());
                playlist.AddFiles(ref oo);

                Controller.ShowMessage("Completed sending playlist to iTunes.");

                app.Quit();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
                Clock.DoOnMainThread(ShowError);
            }
            Busy = false;
        }
Esempio n. 23
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();
        }