private void populateStations() { lock (@lock) { string genre = genrePanel.Value; string filter = txtFilter.Text.Trim(); if (filter.Length > 0) { if (genre.Length > 0) { filteredStations = stations.FindAll(ss => ss.Genre == genre && ss.Matches(filter)); } else { filteredStations = stations.FindAll(ss => ss.Matches(filter)); } } else { if (genre.Length > 0) { filteredStations = stations.FindAll(ss => ss.Genre == genre); } else { filteredStations = stations; } } } firstVisibleStation = Math.Max(0, Math.Min(FirstVisibleStation, filteredStations.Count - cells.Count)); int i = FirstVisibleStation; int j = 0; while (j < cells.Count) { if (filteredStations.Count > i) { cells[j++].Station = filteredStations[i++]; } else { cells[j++].Station = null; } } if (SelectedStation != null && !filteredStations.Contains(SelectedStation)) { SelectedStation = null; } scrollBar.Value = FirstVisibleStation; scrollBar.Max = Math.Max(0, filteredStations.Count - cells.Count); scrollBar.LargeChange = cells.Count - 1; Clock.DoOnMainThread(invalidateAll); }
public void AddItem(T Item, bool Select, bool Sort) { bool contains; lock (itemLock) { contains = items.Contains(Item); } if (!contains) { System.Diagnostics.Debug.Assert(Item.DisplayValues.Length == numColumns); lock (itemLock) { items.Add(Item); } if (Select) { SelectedItem = Item; } if (Sort) { this.Sort(); } Clock.DoOnMainThread(updateScrollBarMax); } }
public static void StationNameChanged() { sort(); instance.populateStations(); InvalidateInstance(); Clock.DoOnMainThread(instance.ensureSelectedStationVisible, 30); }
public void Go(float CurrentVolume) { OriginalVolumeDB = CurrentVolume; fading = false; if (!Active) { return; } Stop(); this.Active = true; if (DateTime.Now > Alarm) { doIt(); } else { nextTick = Clock.DoOnMainThread(tick, getTickDelay()); //updateDisplay(); } }
private void mnuOptionsHighResolutionSpectrum_Click(object sender, EventArgs e) { controller.RequestAction(QActionType.ToggleSpectrumResolution); if (spectrumView.Visible) { Clock.DoOnMainThread(spectrumView.Invalidate, 100); } }
private void safeInvalidate() { if (isValid) { isValid = false; Clock.DoOnMainThread(this.Invalidate); } }
protected QMessageBox(string Text, string Title, QMessageBoxButtons Buttons, QMessageBoxIcon Icon, QMessageBoxButton DefaultButton) : base(Title, (Buttons == QMessageBoxButtons.OK) ? ButtonCreateType.OKOnly : ButtonCreateType.OKAndCancel) { this.SPACING = 8; this.ClientSize = new Size(400, 300); icon = Icon; int textWidth = TextRenderer.MeasureText(Text, Styles.Font).Width; int iconWidth = (icon == QMessageBoxIcon.None) ? 0 : getIcon().Width + 5; int width; int baseWidth = textWidth + iconWidth; if (baseWidth < 300) width = Math.Max(150, baseWidth + 50); else if (baseWidth > 400) width = 400 + SPACING + iconWidth; else width = 350; lblMain = new QLabel(Text); this.Controls.Add(lblMain); lblMain.Location = new Point(SPACING + iconWidth, SPACING); lblMain.SetWidth(width - lblMain.Left - 2 * SPACING); iconTop = Math.Max(lblMain.Top, lblMain.Top + lblMain.Height / 2 - getIcon().Height); qmbButtons = Buttons; switch (qmbButtons) { case QMessageBoxButtons.OK: btn1 = btnOK; break; case QMessageBoxButtons.OKCancel: btn1 = btnCancel; btn2 = btnOK; break; case QMessageBoxButtons.YesNo: btn1 = btnCancel; btn1.Text = Localization.NO; btn2 = btnOK; btn2.Text = Localization.YES; break; } PlaceButtons(width, lblMain.Bottom + SPACING); this.ClientSize = new Size(width, btn1.Bottom + SPACING); Lib.DoEvents(); Lib.Beep(); defaultButton = DefaultButton; Clock.DoOnMainThread(doFocus); }
private frmGlobalInfoBox(ActionType Action) { this.Opacity = 0.85; action = Action; this.Click += (s, e) => { this.click(); }; this.Cursor = Cursors.Hand; Clock.DoOnMainThread(doIt, 250); }
private void resetDevice() { try { Kill(); killDXOutputBuffer(); } catch { } Clock.DoOnMainThread(createDevice, 10); }
private void showAutoManageOptions() { if (!this.Locked) { lastDownloadschedule = Setting.PodcastDownloadSchedule; pnlAutoManageOptions = new QPodcastAutoManageOptions(removePanel); this.Controls.Add(pnlAutoManageOptions); Clock.DoOnMainThread(arrangeControls); keyPreviewChange(); pnlAutoManageOptions.Focus(); } }
private static void setupSubscriptionDataChangedCallback(PodcastSubscription PS) { PS.DataChanged += (s) => { instance.lvwSubscriptions.InvalidateThreadSafe(); if (PS == instance.lvwSubscriptions.SelectedItem) { instance.lvwEpisodes.InvalidateThreadSafe(); } Clock.DoOnMainThread(instance.updateStopDownloadButtonEnable); }; }
private bool startFileStream(Track Track) { try { oldStream = Stream; if ((Track == PreloadStream.Track) || File.Exists(Track.FilePath)) { PlayingTrack = Track; totalTime = PlayingTrack.Duration; if (oldStream != null && oldStream.Frequency != Track.SampleRate && output != null) { matchFrequenciesDelayBytes = output.BufferSize * 3 / 2; // factor of 3 to prevent 24 bit meltdown } if (Track == PreloadStream.Track) { Stream = PreloadStream; System.Diagnostics.Debug.WriteLine("Preload Track Hit"); } else { Stream = new AudioStreamFile(PlayingTrack, gainDB + volumeDB, equalizer, numEqBands, equalizerOn, controller.ReplayGain); System.Diagnostics.Debug.WriteLine("Preload Track Miss"); if (Stream.Frequency < 0) { return(false); } } PreloadStream = AudioStream.NullStream; Clock.DoOnMainThread(closeOldStream, 1000); return(true); } else { return(false); } } catch { return(false); } }
private void doneEditingStation(Radio.StationEditAction SEA) { if (SEA == StationEditAction.OK) { sort(); populateStations(); populateGenres(); invalidateAll(); Clock.DoOnMainThread(instance.ensureSelectedStationVisible, 30); } this.Panel2.Controls.Remove(rep); rep = null; keyPreviewChange(); arrangeStationPanel(); controller.UnlockForPanel(); }
private void showSubscriptionEditPanel(PodcastSubscription PS) { if (!this.Locked) { if (PS != null) { this.Locked = true; pnlSubscriptionDetails = new QPodcastDetails(PS, removePanel); this.Controls.Add(pnlSubscriptionDetails); Clock.DoOnMainThread(arrangeControls); keyPreviewChange(); pnlSubscriptionDetails.Focus(); } } }
private void promoteCandidatePreload() { currentTrack = trackCandidate; if (candidatePromote != Clock.NULL_ALARM) { Clock.RemoveAlarm(ref candidatePromote); } if (temporaryCandidatePromote != Clock.NULL_ALARM) { Clock.RemoveAlarm(ref temporaryCandidatePromote); } temporaryTrack = null; TemporaryImage = null; candidatePromote = Clock.DoOnMainThread(promoteCandidate, 200); }
private static bool addIfNeeded(int Threshold) { lock (@lock) { if (newTracks.Count >= Threshold && addTracksAlarm == Clock.NULL_ALARM) { addTracksAlarm = Clock.DoOnMainThread(sendTracks, 50); return(true); } else if (newTracks.Count == 0) { return(true); } else { return(false); } } }
private void tick() { if (Active) { if (FadeActive && !fading && DateTime.Now > Fade) { fading = true; } if (fading) { controller.RequestAction(QActionType.VolumeDownForSleep); } if (DateTime.Now > Alarm) { doIt(); } nextTick = Clock.DoOnMainThread(tick, getTickDelay()); controller.RequestAction(QActionType.SetMainFormTitle); } }
public Player(System.Windows.Forms.Form OwnerForm, string OutputDeviceName, SpectrumMode SpectrumMode) { Stream = AudioStream.NullStream; PreloadStream = AudioStream.NullStream; outputDeviceName = OutputDeviceName; parentForm = OwnerForm; PlayingTrack = null; NextTrack = null; spectrumMode = SpectrumMode; createSpectrum(); System.Diagnostics.Debug.Assert(READ_BUFFER_SIZE / spectrumSampleSize >= 4); controller = Controller.GetInstance(); Clock.DoOnMainThread(createOutput, 1000); }
public static void Show(Controller Controller, ActionType Action) { controller = Controller; if (instance != null && instance.touch()) { instance.action = Action; if (Action == ActionType.VolumeDown || Action == ActionType.VolumeUp) { instance.doIt(); } else { Clock.DoOnMainThread(instance.doIt, 200); } } else { instance = new frmGlobalInfoBox(Action); } }
private void selectPanel_ValueChanged(string OldValue, string NewValue) { lock (@lock) { bool select = genrePanel.Value == OldValue; foreach (RadioStation rs in stations) { if (String.Compare(rs.Genre, OldValue, StringComparison.OrdinalIgnoreCase) == 0) { rs.Genre = NewValue; } } populateGenres(); if (select) { genrePanel.Value = NewValue; populateStations(); } } Clock.DoOnMainThread(invalidateAll); }
private void advanceTrack() { controller.RequestAction(QActionType.EndOfTrack); if (!playNextTrackNow && !StopAfterThisTrack) { controller.RequestAction(QActionType.RequestNextTrack); } if (NextTrack != null && !StopAfterThisTrack) { Track next = NextTrack; NextTrack = null; if (startFileStream(next)) { if (playNextTrackNow) { controller.RequestAction(QActionType.StartOfTrack); } else { Clock.DoOnMainThread(informNextTrackStarting, 100); } } else { killAudioStream(); controller.RequestAction(new QAction(QActionType.TrackFailed, next)); } playNextTrackNow = false; } else { this.Stop(); this.StopAfterThisTrack = false; controller.RequestAction(QActionType.EndOfAllTracks); } }
private void go() { if (lvwSubscriptions.HasItem(s => String.Compare(s.URL, txtURL.Text.Trim(), StringComparison.OrdinalIgnoreCase) == 0)) { Controller.ShowPriorityMessage("Podcast subscription already loaded."); } else { Controller.ShowPriorityMessage("Downloading podcast information..."); PodcastSubscription p = new PodcastSubscription(txtURL.Text.Trim()); if (p.Loaded) { pendingPodcastSubscription = p; Clock.DoOnMainThread(addPendingSubscription); Controller.ShowPriorityMessage("Podcast information downloaded."); } else { Controller.ShowPriorityMessage("Podcast audio information not found."); } } }
public void SetFontThreadSafe(Font Font) { base.Font = Font; Clock.DoOnMainThread(setMetrics, 30); }
private static void start() { running = true; cancel = false; try { if (directories.Count > 0) { Random r = new Random(); IOrderedEnumerable <string> dirs = directories.OrderBy(d => r.Next()); Stack <string> paths = new Stack <string>(dirs); while (paths.Count > 0 && paths.Peek() != null && !cancel) { string s = paths.Pop(); if (Directory.Exists(s)) { foreach (string ss in (Directory.GetDirectories(s)).OrderBy(x => r.Next())) { paths.Push(ss); } foreach (string ss in (Directory.GetFiles(s).Reverse())) { paths.Push(ss); } } else if (File.Exists(s)) { Track t = Track.Load(s); if (t != null) { lock (@lock) { newTracks.Add(t); } Thread.Sleep(100); if (addIfNeeded(30)) { Thread.Sleep(200); } } Thread.Sleep(50); } } while (!cancel && !addIfNeeded(0)) { Thread.Sleep(200); } ; } } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e.ToString()); } running = false; if (cancel) { newTracks.Clear(); } else { cancel = true; Clock.DoOnMainThread(sendTracks, 50); // get back to UI thread Clock.DoOnMainThread(Controller.GetInstance().RefreshAll, 500); } resetRestartAlarm(); }
private void invalidateAsync() { renderItem = null; Clock.DoOnMainThread(this.invalidate); }
public static void InvalidateAll() { Clock.DoOnMainThread(instance.invalidateAll); }
public void SetTextThreadSafe(string Text) { pendingText = Text; Clock.DoOnMainThread(setText, 10); }
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; }
public void InvalidateThreadSafe() { Clock.DoOnMainThread(this.Invalidate); }
public void RenameSelectedGenre() { genrePanel.StartItemEdit(); Clock.DoOnMainThread(genrePanel.FocusRenameBox, 30); }