private void mEditBgButton_Click(object sender, EventArgs e) { long musicId = SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.Id; SoundPlayerInfo playerInfo = SmartVolManagerPackage.BgMusicManager.FindPlayerInfo(musicId); showEditDialog(playerInfo, true); }
public void Init(MuteFmConfig muteTunesConfig, SoundPlayerInfo[] fgMusics) { TreeNode node; Object currentTag = null; UpdateBgMusicUI(); if (mSoundTree.SelectedNode != null) currentTag = mSoundTree.SelectedNode.Tag; ImageList imageList = new ImageList(); mSoundTree.ImageList = imageList; TreeNode[] children = new TreeNode[0]; imageList.Images.Add("0", UiCommands.mPlayerForm.Icon.ToBitmap()); mSoundTree.Nodes.Clear(); //TreeNode supportedWebNode = mSoundTree.Nodes.Add("Supported Web"); _activeSoundsNode = new TreeNode("Recent Sounds", 0, 0, children); mSoundTree.Nodes.Add(_activeSoundsNode); _favoritesNode = new TreeNode("Favorites", 0, 0, children); mSoundTree.Nodes.Add(_favoritesNode); for (int i = 0; i < fgMusics.Length; i++) { string fgMusicName = fgMusics[i].ShortProcessName; if (fgMusicName.Trim() == "") fgMusicName = "System Sounds"; node = new TreeNode(fgMusicName, i+1, i+1, children); _activeSoundsNode.Nodes.Add(node); node.Tag = fgMusics[i].ShortProcessName; imageList.Images.Add((string)(node.Tag), MuteFmConfigUtil.GetImage(fgMusics[i].Id, 16)); if ((string)node.Tag == (string)currentTag) mSoundTree.SelectedNode = node; } int j = 0; for (int i = 0; i < muteTunesConfig.BgMusics.Length; i++) { #if NOAWE // Don't show web-based music in the editor if (muteTunesConfig.BgMusics[i].IsWeb) continue; #endif node = new TreeNode(muteTunesConfig.BgMusics[i].Name, j + 1 + fgMusics.Length, j + 1 + fgMusics.Length, children); node.Tag = muteTunesConfig.BgMusics[i].Id.ToString(); _favoritesNode.Nodes.Add(node); Image image = MuteFmConfigUtil.GetImage(muteTunesConfig.BgMusics[i].Id, 16); if (image != null) imageList.Images.Add((string)(node.Tag), image); if ((string)node.Tag == (string)currentTag) mSoundTree.SelectedNode = node; j++; } _activeSoundsNode.ExpandAll(); _favoritesNode.ExpandAll(); }
private SoundPlayerInfo getRecentByName(string name) { SoundPlayerInfo soundPlayerInfo = null; KeyValuePair <SoundPlayerInfo, DateTime> kvp; if (SmartVolManagerPackage.BgMusicManager.RecentMusics.TryGetValue(name, out kvp)) { soundPlayerInfo = kvp.Key; } return(soundPlayerInfo); /* * SoundPlayerInfo soundInfo = null; * * SoundPlayerInfo[] fgMusics = SmartVolManagerPackage.BgMusicManager.FgMusics; * * for (int i = 0; i < fgMusics.Length; i++) // Assumes all names are unique. If not, user cannot distinguish via UI anyway so not a bug. * { * if ((string)fgMusics[i].ShortProcessName == (string)mSoundTree.SelectedNode.Tag) * { * soundInfo = fgMusics[i]; * break; * } * } * return soundInfo;*/ }
private void UpdateBgMusicUI() { SoundPlayerInfo playerInfo = SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GetActiveBgMusic(); mBackgroundMusicName.Text = playerInfo.Name; this.mBgMusicIcon.Image = MuteFmConfigUtil.GetImage(playerInfo.Id, 16); }
private void showEditDialog(SoundPlayerInfo playerInfo, bool editable) { if (playerInfo != null) { MusicInfoEditForm form = new MusicInfoEditForm(playerInfo, editable); form.ShowDialog(); if (form.DialogResult == System.Windows.Forms.DialogResult.OK) { MuteFmConfigUtil.Save(SmartVolManagerPackage.BgMusicManager.MuteFmConfig); } } }
private void mDefaultsButton_Click(object sender, EventArgs e) { string procname = ""; if (mWebsiteRadioButton.Checked) { procname = this.mWebsiteUrlTextBox.Text.Trim().TrimEnd('/'); } else { procname = GetProcName(this.mMusicInfoFileNameTextBox.Text); } if (MuteFmConfigUtil.hasDefaults(procname)) { SoundPlayerInfo tempMusicInfo = new SoundPlayerInfo(); if (mWebsiteRadioButton.Checked) { tempMusicInfo.UrlOrCommandLine = procname; } else { tempMusicInfo.UrlOrCommandLine = mMusicInfoFileNameTextBox.Text; } if (this.mWebsiteRadioButton.Checked) { MuteFmConfigUtil.InitDefaultsWeb(tempMusicInfo); } else { MuteFmConfigUtil.InitDefaultsProcess(tempMusicInfo, procname); } _commands["OnLoad"] = tempMusicInfo.OnLoadCommand; _commands["Play"] = tempMusicInfo.PlayCommand; _commands["Pause"] = tempMusicInfo.PauseCommand; _commands["PrevTrack"] = tempMusicInfo.PrevSongCommand; _commands["NextTrack"] = tempMusicInfo.NextSongCommand; _commands["Like"] = tempMusicInfo.LikeCommand; _commands["Dislike"] = tempMusicInfo.DislikeCommand; _commands["Stop"] = tempMusicInfo.StopCommand; MessageBox.Show(this, "Defaults loaded.", Constants.ProgramName); mCommandsListbox_SelectedIndexChanged(null, null); } else { MessageBox.Show(this, "No defaults", Constants.ProgramName); // should never see this } }
private bool chooseSelected() { try { if (mSoundTree.SelectedNode == null) { return(false); } Cursor.Current = Cursors.WaitCursor; if ((mSoundTree.SelectedNode.Parent != null) && (mSoundTree.SelectedNode.Parent.Text == "Recent Sounds")) { SoundPlayerInfo soundInfo = getRecentByName((string)mSoundTree.SelectedNode.Tag); if (soundInfo.Name == "System Sounds") { MessageBox.Show("You cannot set this sound as your background music."); Cursor.Current = Cursors.Default; return(false); } soundInfo = makeSelectedAFavorite(); UiCommands.OnOperation(soundInfo.Id, Operation.ChangeMusic, "", false, true); UpdateBgMusicUI(); refresh(); } else if ((mSoundTree.SelectedNode.Parent != null) && (mSoundTree.SelectedNode.Parent.Text == "Favorites")) { long musicId = long.Parse((string)mSoundTree.SelectedNode.Tag); SoundPlayerInfo soundInfo = SmartVolManagerPackage.BgMusicManager.FindPlayerInfo(musicId); if (soundInfo.Name == "System Sounds") { MessageBox.Show("You cannot set this sound as your background music."); Cursor.Current = Cursors.Default; return(false); } UiCommands.OnOperation(musicId, Operation.ChangeMusic, "", false, true); UpdateBgMusicUI(); } } catch (Exception ex) { MuteFm.SmartVolManagerPackage.SoundEventLogger.LogException(ex); } Cursor.Current = Cursors.Default; return(true); }
private void mEditAvailableButton_Click(object sender, EventArgs e) { if ((mSoundTree.SelectedNode != null) && (mSoundTree.SelectedNode.Tag != null)) { SoundPlayerInfo playerInfo = null; bool editable = false; if (mSoundTree.SelectedNode.Parent.Text == "Recent Sounds") { playerInfo = getRecentByName((string)mSoundTree.SelectedNode.Tag); } else { long musicId = long.Parse((string)mSoundTree.SelectedNode.Tag); playerInfo = SmartVolManagerPackage.BgMusicManager.FindPlayerInfo(musicId); editable = true; } showEditDialog(playerInfo, editable); refresh(); } }
private SoundPlayerInfo makeSelectedAFavorite() { bool found = false; SoundPlayerInfo selectedSoundInfo = getRecentByName((string)mSoundTree.SelectedNode.Tag); SoundPlayerInfo playerInfo = selectedSoundInfo; if (selectedSoundInfo != null) { // Determine if a favorite already exists for this and if so select it instead of adding a new favorite. int len = _favoritesNode.Nodes.Count; for (int i = 0; i < len; i++) { long musicId = long.Parse((string)_favoritesNode.Nodes[i].Tag); playerInfo = SmartVolManagerPackage.BgMusicManager.FindPlayerInfo(musicId); if (playerInfo != null) { if (playerInfo.UrlOrCommandLine.ToLower() == selectedSoundInfo.UrlOrCommandLine.ToLower()) { this.mSoundTree.SelectedNode = _favoritesNode.Nodes[i]; found = true; break; } } } if (found) { //MessageBox.Show("Already exists as a favorite."); } else { selectedSoundInfo.Name = mSoundTree.SelectedNode.Text; MuteFmConfigUtil.AddSoundPlayerInfo(selectedSoundInfo, SmartVolManagerPackage.BgMusicManager.MuteFmConfig); } } return(playerInfo); }
private void showEditDialog(SoundPlayerInfo playerInfo, bool editable) { if (playerInfo != null) { MusicInfoEditForm form = new MusicInfoEditForm(playerInfo, editable); form.ShowDialog(); if (form.DialogResult == System.Windows.Forms.DialogResult.OK) MuteFmConfigUtil.Save(SmartVolManagerPackage.BgMusicManager.MuteFmConfig); } }
public static void OnOperation(long musicId, Operation op, string param, bool ignoreCommand, bool track) { if (Program.LicenseExpired == true) { return; } if (MuteFm.UiPackage.WinSoundServerSysTray.Instance == null) { return; } MuteFm.UiPackage.WinSoundServerSysTray.Instance.Invoke((System.Windows.Forms.MethodInvoker) delegate { if ((musicId == SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.Id) && ((op == Operation.Play) || (op == Operation.Unmute))) { MuteFm.SmartVolManagerPackage.BgMusicManager.PerformOperation(musicId, Operation.ClearHistory, "", ignoreCommand); } if (op == Operation.Show) { System.Threading.Thread.Sleep(250); // Ensure that window is shown after click sets focus to browser (if run in extension); was 750 } // Queue up background music if a foreground sound is active // If user clicked play or unmute for bgmusic and music is automuted and countdown hasn't started, then note that user wants bgmusic and smartmute it but don't show fade messages or let it make sound [i.e. queue it up] if ((musicId == SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.Id) && (((op == Operation.Play) || (op == Operation.Unmute)) && (SmartVolManagerPackage.BgMusicManager.EffectiveSilenceDateTime == DateTime.MaxValue) && (!SmartVolManagerPackage.BgMusicManager.BgMusicHeard) && (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.AutoMuteEnabled))) { MuteFm.SmartVolManagerPackage.BgMusicManager.UserWantsBgMusic = true; MuteFm.SmartVolManagerPackage.BgMusicManager.PerformOperation(musicId, Operation.AutoMutedPlay, param, ignoreCommand); return; } else { int x = 0; x++; } MuteFm.SmartVolManagerPackage.BgMusicManager.PerformOperation(musicId, op, param, ignoreCommand); if ((musicId == SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.Id) || (op == Operation.ChangeMusic)) { // Extra logic because we know user chose to perform the operation switch (op) { case Operation.Play: SmartVolManagerPackage.BgMusicManager.AutoMuted = false; // TODO MuteFm.SmartVolManagerPackage.BgMusicManager.UserWantsBgMusic = true; if (track) { TrackEvent("Play"); } break; case Operation.ChangeMusic: SoundPlayerInfo playerInfo = SmartVolManagerPackage.BgMusicManager.FindPlayerInfo(musicId); if (playerInfo != null) { SmartVolManagerPackage.BgMusicManager.UserMustClickPlay = false; // reset it if (playerInfo.Id <= 0) { MuteFmConfigUtil.AddSoundPlayerInfo(playerInfo, SmartVolManagerPackage.BgMusicManager.MuteFmConfig); //MixerWebSocketServerHelper.SendCommand("BGMUSICSITES", new GetBgMusicSiteSendData()); } SmartVolManagerPackage.BgMusicManager.AlbumArtFileName = ""; SmartVolManagerPackage.BgMusicManager.TrackName = ""; if (SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.IsWeb) // Changed 8/16/13 to only do this if web-based { OnOperation(Operation.Stop); } else { OnOperation(Operation.Pause); } SmartVolManagerPackage.BgMusicManager.ActiveBgMusic = playerInfo; SmartVolManagerPackage.BgMusicManager.BgMusicPids = new int[0]; SmartVolManagerPackage.BgMusicManager.BgMusicVolInit = false; OnOperation(Operation.Play); UiPackage.UiCommands.UpdateUiForState(); // If shows up as a fgmusic but not as a bgmusic, add to bgmusics and remove from fgmusic if (MuteFmConfigUtil.FindBgMusic(playerInfo.UrlOrCommandLine, SmartVolManagerPackage.BgMusicManager.MuteFmConfig) == null) { long tempId = playerInfo.Id; MuteFmConfigUtil.AddSoundPlayerInfo(playerInfo, SmartVolManagerPackage.BgMusicManager.MuteFmConfig); playerInfo.Id = tempId; var fgMusicList = new List <MuteFm.SoundPlayerInfo>(SmartVolManagerPackage.BgMusicManager.FgMusics); fgMusicList.Remove(playerInfo); SmartVolManagerPackage.BgMusicManager.FgMusics = fgMusicList.ToArray(); } // Save current music as new default MuteFm.SmartVolManagerPackage.BgMusicManager.MuteFmConfig.ActiveBgMusicId = musicId; MuteFmConfigUtil.Save(MuteFm.SmartVolManagerPackage.BgMusicManager.MuteFmConfig); } break; case Operation.Stop: MuteFm.SmartVolManagerPackage.BgMusicManager.UserWantsBgMusic = false; if (_autoShowAfterPlayWorker != null) { _autoShowAfterPlayWorker.CancelAsync(); _autoShowAfterPlayWorker = null; } break; case Operation.Pause: case Operation.Mute: MuteFm.SmartVolManagerPackage.BgMusicManager.UserWantsBgMusic = false; _autoShowAfterPlayWorker = new System.ComponentModel.BackgroundWorker(); _autoShowAfterPlayWorker.WorkerSupportsCancellation = true; _autoShowAfterPlayWorker.DoWork += new DoWorkEventHandler(_isPausing_DoWork); _autoShowAfterPlayWorker.RunWorkerAsync(); //MuteApp.SmartVolManagerPackage.BgMusicManager.PerformOperation(Operation.ClearHistory); break; case Operation.Unmute: MuteFm.SmartVolManagerPackage.BgMusicManager.UserWantsBgMusic = true; break; case Operation.Exit: Exit(); break; } } }); if (op == Operation.Exit) { Exit(); /*//UiPackage.UiCommands.SetTopText("Exiting mute.fm...", false); * //System.Threading.Thread.Sleep(3000); * WebBgMusicForm.Visible = false; * WebBgMusicForm.Close(); * UiPackage.WinSoundServerSysTray.Instance.Close(); * Environment.Exit(0); * //Application.Exit();*/ } }
// Must be run within UI thread public static void InitUI(bool firstTime) { #if !NOAWE WebBgMusicForm = new MuteFm.UiPackage.WebBgMusicForm(); WebBgMusicForm.FormClosing += new FormClosingEventHandler(WebBgMusicForm_FormClosing); WebBgMusicForm.Resize += new EventHandler(WebBgMusicForm_Resize); //WebBgMusicForm.Show(); #endif _notificationType = new NotificationType("MUTEFM_NOTIFICATION", "mute.fm notification"); _growl = new GrowlConnector(); _growl.NotificationCallback += new GrowlConnector.CallbackEventHandler(growl_notification_callback); _growl.EncryptionAlgorithm = Cryptography.SymmetricAlgorithmType.PlainText; // set to ease debugging // OLDNOTIFY TopForm.Instance.Show(); //UiPackage.UiCommands.SetNotification(Constants.ProgramName + " started (expires " + Constants.GetExpirationDateString() + ")", false); UiPackage.UiCommands.SetNotification(Constants.ProgramName + " started", false); if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.Hotkeys == null) { MuteFmConfigUtil.LoadDefaultHotkeys(SmartVolManagerPackage.BgMusicManager.MuteFmConfig); } if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.SoundPollIntervalInS == 0) { SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.SoundPollIntervalInS = MuteFmConfig.SoundPollIntervalDefault; } RegisterHotkeys(); UiPackage.UiCommands.UpdateUiForState(MuteFm.SmartVolManagerPackage.BgMusicManager.GetValidOperation(), false, false, true); mPlayerForm = new PlayerForm(); mPlayerForm.FormClosed += new FormClosedEventHandler(mPlayer_FormClosed); mPlayerForm.Init(false); // MuteApp.UiPackage.UiCommands.ShowPlayer(); if (firstTime) { System.ComponentModel.BackgroundWorker firstTimeWorker = new BackgroundWorker(); firstTimeWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(DoFirstTimeWork); firstTimeWorker.RunWorkerAsync(); #if !NOAWE UiPackage.UiCommands.ShowGettingStartedWizard(); #endif mPlayerForm.ToggleTopmost(true); } else { if (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.PlayMusicOnStartup) { System.ComponentModel.BackgroundWorker firstTimeWorker = new BackgroundWorker(); firstTimeWorker.DoWork += new System.ComponentModel.DoWorkEventHandler(delegate { SoundPlayerInfo playerInfo = (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GetActiveBgMusic()); System.Threading.Thread.Sleep(2000); OnOperation(Operation.Play, playerInfo.AutoPlaysOnStartup, false); if (playerInfo.AutoPlaysOnStartup == false) { System.ComponentModel.BackgroundWorker firstTimeWorker2 = new BackgroundWorker(); firstTimeWorker2.DoWork += new System.ComponentModel.DoWorkEventHandler(delegate { //System.Threading.Thread.Sleep(5000); //todo OnOperation(Operation.Play); }); firstTimeWorker2.RunWorkerAsync(); } System.Threading.Thread.Sleep(1000); OnOperation(Operation.Minimize); }); firstTimeWorker.RunWorkerAsync(); } } System.Windows.Forms.Application.Run(MuteFm.UiPackage.WinSoundServerSysTray.Instance); }
public MusicInfoEditForm(SoundPlayerInfo playerInfo, bool editable) { InitializeComponent(); this.Text = Constants.ProgramName + " - " + "Edit Sound Player Info"; #if NOAWE mWebsiteRadioButton.Text += " (Requires mute.fm+)"; #endif if (playerInfo == null) { this.Text = Constants.ProgramName + " - Add Sound Info"; _musicInfo = new SoundPlayerInfo(); #if !NOAWE _musicInfo.IsWeb = true; mWebsiteRadioButton.Checked = true; mProgramRadioButton.Enabled = true; mWebsiteRadioButton.Enabled = true; #else _musicInfo.IsWeb = false; mWebsiteRadioButton.Enabled = false; mProgramRadioButton.Enabled = true; mProgramRadioButton.Checked = true; mWebsiteRadioButton_CheckedChanged_1(null, null); #endif this.mIgnoreAutomuteCheckbox.Checked = false; this.mIgnoreAutomuteCheckbox.Visible = !_musicInfo.IsWeb; mStopIfMutedTooLongCheckbox.Checked = true; _commands["OnLoad"] = ""; _commands["Play"] = ""; _commands["Pause"] = ""; _commands["PrevTrack"] = ""; _commands["NextTrack"] = ""; _commands["Like"] = ""; _commands["Dislike"] = ""; _commands["Stop"] = ""; } else { _musicInfo = playerInfo; mWebsiteRadioButton.Checked = _musicInfo.IsWeb; mProgramRadioButton.Checked = !_musicInfo.IsWeb; mIgnoreAutomuteCheckbox.Visible = !_musicInfo.IsWeb; mWebsiteRadioButton_CheckedChanged_1(null, null); bool ignoreForAutomute = false; SmartVolManagerPackage.BgMusicManager.IgnoreProcNameForAutomuteDict.TryGetValue(GetProcName(_musicInfo.UrlOrCommandLine), out ignoreForAutomute); this.mIgnoreAutomuteCheckbox.Checked = ignoreForAutomute; mStopIfMutedTooLongCheckbox.Checked = playerInfo.KillAfterAutoMute; _commands["OnLoad"] = _musicInfo.OnLoadCommand; _commands["Play"] = _musicInfo.PlayCommand; _commands["Pause"] = _musicInfo.PauseCommand; _commands["PrevTrack"] = _musicInfo.PrevSongCommand; _commands["NextTrack"] = _musicInfo.NextSongCommand; _commands["Like"] = _musicInfo.LikeCommand; _commands["Dislike"] = _musicInfo.DislikeCommand; _commands["Stop"] = _musicInfo.StopCommand; mIcon.Image = MuteFmConfigUtil.GetImage(_musicInfo.Id, 16); } if (!editable) { foreach (Control control in this.Controls) { if ((string)control.Tag != "+") control.Enabled = false; } } }
private void mDefaultsButton_Click(object sender, EventArgs e) { string procname = ""; if (mWebsiteRadioButton.Checked) procname = this.mWebsiteUrlTextBox.Text.Trim().TrimEnd('/'); else procname = GetProcName(this.mMusicInfoFileNameTextBox.Text); if (MuteFmConfigUtil.hasDefaults(procname)) { SoundPlayerInfo tempMusicInfo = new SoundPlayerInfo(); if (mWebsiteRadioButton.Checked) tempMusicInfo.UrlOrCommandLine = procname; else tempMusicInfo.UrlOrCommandLine = mMusicInfoFileNameTextBox.Text; if (this.mWebsiteRadioButton.Checked) MuteFmConfigUtil.InitDefaultsWeb(tempMusicInfo); else MuteFmConfigUtil.InitDefaultsProcess(tempMusicInfo, procname); _commands["OnLoad"] = tempMusicInfo.OnLoadCommand; _commands["Play"] = tempMusicInfo.PlayCommand; _commands["Pause"] = tempMusicInfo.PauseCommand; _commands["PrevTrack"] = tempMusicInfo.PrevSongCommand; _commands["NextTrack"] = tempMusicInfo.NextSongCommand; _commands["Like"] = tempMusicInfo.LikeCommand; _commands["Dislike"] = tempMusicInfo.DislikeCommand; _commands["Stop"] = tempMusicInfo.StopCommand; MessageBox.Show(this, "Defaults loaded.", Constants.ProgramName); mCommandsListbox_SelectedIndexChanged(null, null); } else { MessageBox.Show(this, "No defaults", Constants.ProgramName); // should never see this } }
public MusicInfoEditForm(SoundPlayerInfo playerInfo, bool editable) { InitializeComponent(); this.Text = Constants.ProgramName + " - " + "Edit Sound Player Info"; #if NOAWE mWebsiteRadioButton.Text += " (Requires mute.fm+)"; #endif if (playerInfo == null) { this.Text = Constants.ProgramName + " - Add Sound Info"; _musicInfo = new SoundPlayerInfo(); #if !NOAWE _musicInfo.IsWeb = true; mWebsiteRadioButton.Checked = true; mProgramRadioButton.Enabled = true; mWebsiteRadioButton.Enabled = true; #else _musicInfo.IsWeb = false; mWebsiteRadioButton.Enabled = false; mProgramRadioButton.Enabled = true; mProgramRadioButton.Checked = true; mWebsiteRadioButton_CheckedChanged_1(null, null); #endif this.mIgnoreAutomuteCheckbox.Checked = false; this.mIgnoreAutomuteCheckbox.Visible = !_musicInfo.IsWeb; mStopIfMutedTooLongCheckbox.Checked = true; _commands["OnLoad"] = ""; _commands["Play"] = ""; _commands["Pause"] = ""; _commands["PrevTrack"] = ""; _commands["NextTrack"] = ""; _commands["Like"] = ""; _commands["Dislike"] = ""; _commands["Stop"] = ""; } else { _musicInfo = playerInfo; mWebsiteRadioButton.Checked = _musicInfo.IsWeb; mProgramRadioButton.Checked = !_musicInfo.IsWeb; mIgnoreAutomuteCheckbox.Visible = !_musicInfo.IsWeb; mWebsiteRadioButton_CheckedChanged_1(null, null); bool ignoreForAutomute = false; SmartVolManagerPackage.BgMusicManager.IgnoreProcNameForAutomuteDict.TryGetValue(GetProcName(_musicInfo.UrlOrCommandLine), out ignoreForAutomute); this.mIgnoreAutomuteCheckbox.Checked = ignoreForAutomute; mStopIfMutedTooLongCheckbox.Checked = playerInfo.KillAfterAutoMute; _commands["OnLoad"] = _musicInfo.OnLoadCommand; _commands["Play"] = _musicInfo.PlayCommand; _commands["Pause"] = _musicInfo.PauseCommand; _commands["PrevTrack"] = _musicInfo.PrevSongCommand; _commands["NextTrack"] = _musicInfo.NextSongCommand; _commands["Like"] = _musicInfo.LikeCommand; _commands["Dislike"] = _musicInfo.DislikeCommand; _commands["Stop"] = _musicInfo.StopCommand; mIcon.Image = MuteFmConfigUtil.GetImage(_musicInfo.Id, 16); } if (!editable) { foreach (Control control in this.Controls) { if ((string)control.Tag != "+") { control.Enabled = false; } } } }
// This gets called when an active sound has been added or removed (and every five seconds) public static void OnUpdateSoundSourceInfos(SoundSourceInfo[] soundSourceInfos) { if (Program.LicenseExpired) return; Dictionary<string, SoundPlayerInfo> prevSessionInstanceToPlayerInfoDict = SessionInstanceToSoundPlayerInfoDict; SessionInstanceToSoundPlayerInfoDict = new Dictionary<string, SoundPlayerInfo>(); Dictionary<long, List<string>> idToSessionInstanceIdsDict = new Dictionary<long, List<string>>(); Dictionary<long, long> idToPidDict = new Dictionary<long, long>(); Dictionary<long, float> fgMusicVol = new Dictionary<long, float>(); Dictionary<long, bool> fgMusicMuted = new Dictionary<long, bool>(); Dictionary<long, bool> fgMusicIsActive = new Dictionary<long, bool>(); Dictionary<long, bool> fgMusicIgnore = new Dictionary<long, bool>(); //List<SoundPlayerInfo> fgMusics = new List<SoundPlayerInfo>(); bool bgMusicHeard = false; bool nonBgMusicHeard = false; DateTime now = DateTime.Now; bool isEffectiveSound = false; bool bgIsEmmittingSound = false; SoundServer.SoundSourceInfos = soundSourceInfos; // Determine if background music and any non-background music sound is active DateTime newestActive = DateTime.MinValue; for (int i = 0; i < SoundServer.SoundSourceInfos.Length; i++) { try { SoundSourceInfo info = SoundServer.SoundSourceInfos[i]; if (info.IsEmittingSound() && !info.Muted) { bool ignore = false; IgnoreProcNameForAutomuteDict.TryGetValue(info.ProcessName, out ignore); if (!ignore) { isEffectiveSound = true; } } if (SoundSourceInfoIsBgMusic(info, ActiveBgMusic.ShortProcessName)) // background sound { List<string> temp; if (!idToSessionInstanceIdsDict.TryGetValue(SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.Id, out temp)) idToSessionInstanceIdsDict[SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.Id] = new List<string>(); idToSessionInstanceIdsDict[SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.Id].Add(info.SessionInstanceIdentifier); if (bgIsEmmittingSound == true) // For media player and Zune, there are multiple session instances for the bgmusic; if one is emitting then bgmusic is emitting and we'll use that session instance properties continue; BgMusicVolume = info.MixerVolume; BgMusicMuted = info.Muted; BgMusicVolInit = true; bgMusicHeard = !info.EffectiveVolumeIsZero(); bgIsEmmittingSound = info.IsEmittingSound(); if (IsPausing || !bgIsEmmittingSound) { if (MusicState != BgMusicState.Pause) UpdateBgMusicState(BgMusicState.Pause); // Assume it is paused if we haven't heard background music in awhile } else { if (MusicState != BgMusicState.Stop) { if (info.MixerVolumeIsZeroOrMuted() || ((FadingThreadCount > 0) && (IsMuting))) { if (MusicState != BgMusicState.Mute) UpdateBgMusicState(BgMusicState.Mute); } else { if (MusicState != BgMusicState.Play) UpdateBgMusicState(BgMusicState.Play); UserWantsBgMusic = true; } } } } else // Foreground sounds { //string effectiveProcessPath = (info.ProcessFullPath != "") ? info.ProcessFullPath : info.ProcessName; if ((info.IsEmittingSound() == true) && ((info.ProcessFullPath != "") || (info.IsSystemIsSystemSoundsSession))) { SoundPlayerInfo fgMusic; if (!prevSessionInstanceToPlayerInfoDict.TryGetValue(info.SessionInstanceIdentifier, out fgMusic)) // TODO: just changed to use sessioninstance { fgMusic = new SoundPlayerInfo(); fgMusic.Id = MuteFmConfig.NextId; MuteFmConfig.NextId++; } List<string> temp; if (!idToSessionInstanceIdsDict.TryGetValue(fgMusic.Id, out temp)) idToSessionInstanceIdsDict[fgMusic.Id] = new List<string>(); idToSessionInstanceIdsDict[fgMusic.Id].Add(info.SessionInstanceIdentifier); fgMusic.Name = (info.IsSystemIsSystemSoundsSession) ? "System Sounds" : info.WindowTitle; fgMusic.UrlOrCommandLine = info.ProcessFullPath; fgMusic.ShortProcessName = info.ProcessName; fgMusic.IsWeb = false; MuteFmConfigUtil.InitDefaultsProcess(fgMusic, info.ProcessName); MuteFmConfigUtil.GenerateIconImage(fgMusic, false); fgMusicVol[fgMusic.Id] = info.MixerVolume; fgMusicMuted[fgMusic.Id] = info.Muted; fgMusicIsActive[fgMusic.Id] = info.IsEmittingSound(); bool ignore = false; IgnoreProcNameForAutomuteDict.TryGetValue(info.ProcessName, out ignore); fgMusicIgnore[fgMusic.Id] = ignore; SessionInstanceToSoundPlayerInfoDict[info.SessionInstanceIdentifier] = fgMusic; } if ((!DisableAutomuteTemporarily) && (info.IsContinuouslyActiveForAwhile() == true)) { bool shouldIgnore = false; IgnoreProcNameForAutomuteDict.TryGetValue(info.ProcessName.ToLower(), out shouldIgnore); if (!shouldIgnore) nonBgMusicHeard = true; } } } catch (Exception ex) { MuteFm.SmartVolManagerPackage.SoundEventLogger.LogException(ex); } } if (isEffectiveSound) EffectiveSilenceDateTime = DateTime.MaxValue; else EffectiveSilenceDateTime = (EffectiveSilenceDateTime < now) ? EffectiveSilenceDateTime : now; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Update Automute ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// try { if ((UserWantsBgMusic) && (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.AutoMuteEnabled == true) && (MasterMuted == false)) { if ((nonBgMusicHeard == true) && (bgMusicHeard == true)) { AutoMuted = true; UiPackage.UiCommands.SetNotification("Music fading out...", true); UiPackage.UiCommands.TrackEvent("automute"); PerformOperation(Operation.SmartMute); } else if ((MusicState != BgMusicState.Play) && (nonBgMusicHeard == false)) { if (AutoMuted == true) { AutoMuted = false; PerformOperation(Operation.Restore); UiPackage.UiCommands.SetNotification("Music fading in...", true); } } } if (AutoMuted && UserWantsBgMusic && (SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GeneralSettings.AutoMuteEnabled == false)) { AutoMuted = false; PerformOperation(Operation.Restore); UiPackage.UiCommands.SetNotification("Music fading in...", true); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Update background-related state ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// BgMusicHeard = bgMusicHeard; ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // Update foreground-related state ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////// if (ForegroundSoundPlaying != nonBgMusicHeard) { ForegroundSoundPlaying = nonBgMusicHeard; UiPackage.UiCommands.UpdateUiForState(); } SoundPlayerInfo[] fgMusics = new SoundPlayerInfo[SessionInstanceToSoundPlayerInfoDict.Count]; SessionInstanceToSoundPlayerInfoDict.Values.CopyTo(fgMusics, 0); List<SoundPlayerInfo> fgMusicList = new List<SoundPlayerInfo>(fgMusics); fgMusicList.Sort(delegate(SoundPlayerInfo c1, SoundPlayerInfo c2) { if ((c1.ShortProcessName == "") && (c2.ShortProcessName == ""))// System always goes first return 0; if (c1.ShortProcessName == "") // System always goes first return -1; if (c2.ShortProcessName == "") return 1; bool c1Active = false; bool c2Active = false; fgMusicIsActive.TryGetValue(c1.Id, out c1Active); fgMusicIsActive.TryGetValue(c2.Id, out c2Active); if (c1Active && !c2Active) return -1; if (!c1Active && c2Active) return 1; return -1 * c1.GetName().CompareTo(c2.GetName()); }); FgMusics = fgMusicList.ToArray(); IdToPidDict = idToPidDict; FgMusicVol = fgMusicVol; FgMusicMuted = fgMusicMuted; FgMusicIsActive = fgMusicIsActive; FgMusicIgnore = fgMusicIgnore; FgInfo[] fgInfos = CollectFgInfo(); // Only update UI with fginfo if it is different if (FgInfosAreDifferent(_oldFgInfos, fgInfos)) { UpdateFgMusicState(); _oldFgInfos = fgInfos; } // Remove anything older than an hour List<string> keys = RecentMusics.Keys.Take(RecentMusics.Keys.Count).ToList(); for (int i = 0; i < keys.Count(); i++) { if (RecentMusics[keys[i]].Value.AddSeconds(60 * 60) < DateTime.Now) RecentMusics.Remove(keys[i]); } for (int i = 0; i < fgMusics.Length; i++) { KeyValuePair<SoundPlayerInfo, DateTime> kvp; if (!RecentMusics.TryGetValue(fgMusics[i].UrlOrCommandLine, out kvp)) { kvp = new KeyValuePair<SoundPlayerInfo, DateTime>(fgMusics[i], DateTime.Now); RecentMusics[fgMusics[i].ShortProcessName] = kvp; } else { kvp = new KeyValuePair<SoundPlayerInfo, DateTime>(kvp.Key, DateTime.Now); } } IdToSessionInstanceIdsDict = idToSessionInstanceIdsDict; } catch (Exception ex) { MuteFm.SmartVolManagerPackage.SoundEventLogger.LogException(ex); } }
// TODO: should be driven by playerstate here public void UpdateTrayMenu(Operation validOperation, bool isBgMusicVisible, bool isRunning, bool mixerVisible) { // Don't regenerate if state hasn't changed if ((validOperation == _validOperation) && (_isBgMusicVisible == isBgMusicVisible) && (_isRunning == isRunning) && (_mixerVisible == mixerVisible)) { return; } _validOperation = validOperation; _isBgMusicVisible = isBgMusicVisible; _isRunning = isRunning; _mixerVisible = mixerVisible; ContextMenuStrip trayMenu = new ContextMenuStrip(); trayMenu.Items.Add(validOperation.ToString(), null, OnValidOperation); // or mute/pause if already playing if (isRunning) { trayMenu.Items.Add("Stop", null, OnStop); } trayMenu.Items.Add("-", null, OnNothing); SoundPlayerInfo playerInfo = SmartVolManagerPackage.BgMusicManager.MuteFmConfig.GetActiveBgMusic(); string playerName = (playerInfo != null) ? playerInfo.Name : "Player"; if (playerName.Length > 20) { playerName = playerName.Substring(0, 20).Trim() + "..."; } trayMenu.Items.Add("Show " + playerName, null, OnShow); // Show is always an option // if (isBgMusicVisible) // TODO: used to also require isrunning here // trayMenu.Items.Add("Hide " + playerName, null, OnHide); if (validOperation != Operation.Play) { if ((SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.NextSongCommand != "") || (SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.PrevSongCommand != "") || (SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.ShuffleCommand != "") || (SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.LikeCommand != "") || (SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.DislikeCommand != "")) { trayMenu.Items.Add("-", null, OnNothing); } if (SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.NextSongCommand != "") { trayMenu.Items.Add("Next Track", null, OnNextTrack); } if (SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.PrevSongCommand != "") { trayMenu.Items.Add("Prev Track", null, OnPrevTrack); } if (SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.LikeCommand != "") { trayMenu.Items.Add("Like", null, OnLike); } if (SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.DislikeCommand != "") { trayMenu.Items.Add("Dislike", null, OnDislike); } if (SmartVolManagerPackage.BgMusicManager.ActiveBgMusic.ShuffleCommand != "") { trayMenu.Items.Add("Shuffle", null, OnShuffle); } } trayMenu.Items.Add("-", null, OnNothing); trayMenu.Items.Add("Show " + Constants.ProgramName, null, OnShowMixer); if (mixerVisible == true) { trayMenu.Items.Add("Hide " + Constants.ProgramName, null, OnHideMixer); } trayMenu.Items.Add("-", null, OnNothing); // trayMenu.MenuItems.Add("Settings", OnSettings); //TODO: not implemented yet trayMenu.Items.Add("About", null, OnAbout); trayMenu.Items.Add("-", null, OnNothing); trayMenu.Items.Add("Exit", null, OnExit); _trayIcon.ContextMenuStrip = trayMenu; trayMenu.Opening += new CancelEventHandler(trayMenu_Opening); UiCommands.TrayLoaded = true; // TODO: shouldn't go here }