private void LoadPlaylists() { List <string> dirs = new List <string>(System.IO.Directory.EnumerateDirectories(System.IO.Directory.GetCurrentDirectory())); foreach (var dir in dirs) { string[] dirSplit = dir.Split('\\'); string localDir = dirSplit[dirSplit.Length - 1]; string[] localDirSplit = localDir.Split('-'); if ((localDirSplit.Length == 3) && (localDirSplit[0] == "HKSR")) { SoundboardPlaylist newSoundboard = new SoundboardPlaylist(); newSoundboard.playlist = new List <string>(); newSoundboard.playlist.AddRange(System.IO.Directory.GetFiles(dir, "*.mp3")); newSoundboard.playlist.AddRange(System.IO.Directory.GetFiles(dir, "*.wav")); // initialize last played to zero newSoundboard.lastPlayedIdxList = new List <int>(); newSoundboard.lastPlayedIdxList.Add(0); // set hotkey enum newSoundboard.hotkey = Int32.Parse(localDirSplit[1]); mSoundboards.Add(newSoundboard); } } }
void gKeyboardHook_KeyDown(object sender, KeyEventArgs e) { // if this is true it blocks that key from use for everything else e.Handled = false; if (e.KeyCode == toggleMuteHK) { ToggleMute(); return; } if (e.KeyCode == stopHK) { StopMedia(); return; } if (muted) { return; } int sbInd = 0; for (; sbInd < mSoundboards.Count; ++sbInd) { if (e.KeyCode == (System.Windows.Forms.Keys)mSoundboards[sbInd].hotkey) { break; } // got to the end of the soundboards and couldn't find the // the registered hotkey, we shouldn't hit this if (sbInd == (mSoundboards.Count - 1)) { return; } } int randomIdx = mSoundboards[sbInd].lastPlayedIdxList[0]; if (mSoundboards[sbInd].playlist.Count > 1) { Random r = new Random(); while (mSoundboards[sbInd].lastPlayedIdxList.Contains(randomIdx)) { randomIdx = r.Next(0, mSoundboards[sbInd].playlist.Count); } if (mSoundboards[sbInd].playlist.Count >= gMinFileHistCount) { // leave 2 out to choose from next time so it's not cyclic if (mSoundboards[sbInd].lastPlayedIdxList.Count == (mSoundboards[sbInd].playlist.Count - gHistForgetNum)) { List <int> tempList = new List <int>(); tempList = mSoundboards[sbInd].lastPlayedIdxList.GetRange(1, (mSoundboards[sbInd].lastPlayedIdxList.Count - 1)); mSoundboards[sbInd].lastPlayedIdxList.Clear(); mSoundboards[sbInd].lastPlayedIdxList.AddRange(tempList); } mSoundboards[sbInd].lastPlayedIdxList.Add(randomIdx); } else { mSoundboards[sbInd].lastPlayedIdxList[0] = randomIdx; } } mediaElement1.Source = new System.Uri(mSoundboards[sbInd].playlist[randomIdx]); if (duckingKeys.Contains(e.KeyCode)) { DuckOtherAppsVolumes(); } mediaElement1.Play(); // there is a event handlers to RestoreOtherAppsVolumes, we don't use it to Duck // since we can override sounds so they never finish, we just want to run the Duck once else we'll overide // current volume levels with ducked volume levels // I don't like this but it works SoundboardPlaylist newSoundboard = new SoundboardPlaylist { playlist = mSoundboards[sbInd].playlist, hotkey = mSoundboards[sbInd].hotkey, lastPlayedIdxList = mSoundboards[sbInd].lastPlayedIdxList }; mSoundboards[sbInd] = newSoundboard; return; }