public MainForm() { InitializeComponent(); var tooltip = new ToolTip(); tooltip.SetToolTip(btnReloadDevices, "Refresh sound devices"); tooltip.SetToolTip(btnReloadWindows, "Reload windows"); loadSoundDevices(); loadWindows(); XMLSettings.LoadSoundboardSettingsXML(); if (cbPlaybackDevices.Items.Contains(XMLSettings.soundboardSettings.LastPlaybackDevice)) { cbPlaybackDevices.SelectedItem = XMLSettings.soundboardSettings.LastPlaybackDevice; } if (cbLoopbackDevices.Items.Contains(XMLSettings.soundboardSettings.LastLoopbackDevice)) { cbLoopbackDevices.SelectedItem = XMLSettings.soundboardSettings.LastLoopbackDevice; } //add events after settings have been loaded cbPlaybackDevices.SelectedIndexChanged += cbPlaybackDevices_SelectedIndexChanged; cbLoopbackDevices.SelectedIndexChanged += cbLoopbackDevices_SelectedIndexChanged; }
private void cbLoopbackDevices_SelectedIndexChanged(object sender, EventArgs e) { if (cbLoopbackDevices.SelectedIndex > 0) { if (cbEnable.Checked) //start loopback on new device, or stop loopback { if ((string)cbLoopbackDevices.SelectedItem == "") { stopLoopback(); } else { startLoopback(); } } else { stopLoopback(); } } string deviceName = (string)cbLoopbackDevices.SelectedItem; XMLSettings.soundboardSettings.LastLoopbackDevice = deviceName; XMLSettings.SaveSoundboardSettingsXML(); }
private void btnOK_Click(object sender, EventArgs e) { Keys[] keysArr = null; string error = ""; if (string.IsNullOrWhiteSpace(tbStopSoundKeys.Text) || Helper.keysArrayFromString(tbStopSoundKeys.Text, out keysArr, out error)) { if (loadXMLFilesList.Count == 0 || loadXMLFilesList.All(x => x.Keys.Length > 0 && !string.IsNullOrWhiteSpace(x.XMLLocation) && File.Exists(x.XMLLocation))) { XMLSettings.soundboardSettings.StopSoundKeys = (keysArr == null ? new Keys[] { } : keysArr); XMLSettings.soundboardSettings.LoadXMLFiles = loadXMLFilesList.ToArray(); XMLSettings.soundboardSettings.MinimizeToTray = cbMinimizeToTray.Checked; XMLSettings.soundboardSettings.PlaySoundsOverEachOther = cbPlaySoundsOverEachOther.Checked; XMLSettings.SaveSoundboardSettingsXML(); this.Close(); } else { MessageBox.Show("One or more entries either have no keys added, the location is empty, or the file the location points to does not exist"); } } else if (error != "") { MessageBox.Show(error); } }
private void btnOK_Click(object sender, EventArgs e) { if (!Helper.stringToKeysArray(tbStopSoundKeys.Text, out Keyboard.Keys[] keysArray, out _)) { keysArray = new Keyboard.Keys[] { } } ; if (loadXMLFilesList.Count == 0 || loadXMLFilesList.All(x => x.Keys.Length > 0 && !string.IsNullOrWhiteSpace(x.XMLLocation) && File.Exists(x.XMLLocation))) { XMLSettings.soundboardSettings.StopSoundKeys = keysArray; XMLSettings.soundboardSettings.LoadXMLFiles = loadXMLFilesList.ToArray(); XMLSettings.soundboardSettings.StartWithWindows = cbStartWithWindows.Checked; Helper.setStartup(XMLSettings.soundboardSettings.StartWithWindows); XMLSettings.soundboardSettings.StartMinimised = cbStartMinimised.Checked; XMLSettings.soundboardSettings.MinimiseToTray = cbMinimiseToTray.Checked; XMLSettings.SaveSoundboardSettingsXML(); this.Close(); } else { MessageBox.Show("One or more entries either have no keys added, the location is empty, or the file the location points to does not exist"); } }
private void SaveHotkeys() { XMLSettings.WriteXML(new XMLSettings.Settings() { SoundHotkeys = soundHotkeys.ToArray() }, xmlLocation); XMLSettings.soundboardSettings.LastXMLFile = xmlLocation; saveSettings(); MessageBox.Show("Hotkeys saved"); }
private void cbPlaybackDevices_SelectedIndexChanged(object sender, EventArgs e) { //start loopback on new device and stop all sounds playing if (loopbackWaveOut != null && loopbackSourceStream != null && cbEnable.Checked) { startLoopback(); } stopPlayback(); string deviceName = (string)cbPlaybackDevices.SelectedItem; XMLSettings.soundboardSettings.LastPlaybackDevice = deviceName; XMLSettings.SaveSoundboardSettingsXML(); }
private void btnSave_Click(object sender, EventArgs e) { if (xmlLoc == "" || !File.Exists(xmlLoc)) { xmlLoc = Helper.userGetXMLLoc(); } if (xmlLoc != "") { XMLSettings.WriteXML(new XMLSettings.Settings() { KeysSounds = keysSounds.ToArray() }, xmlLoc); MessageBox.Show("Saved"); } }
private void btnSaveAs_Click(object sender, EventArgs e) { string last = xmlLoc; xmlLoc = Helper.userGetXMLLoc(); if (xmlLoc == "") { xmlLoc = last; } else if (last != xmlLoc) { XMLSettings.WriteXML(new XMLSettings.Settings() { KeysSounds = keysSounds.ToArray() }, xmlLoc); MessageBox.Show("Saved"); } }
private void loadXMLFile(string path) { XMLSettings.Settings s = (XMLSettings.Settings)XMLSettings.ReadXML(typeof(XMLSettings.Settings), path); if (s != null && s.KeysSounds != null && s.KeysSounds.Length > 0) { var items = new List <ListViewItem>(); string errors = ""; string sameKeys = ""; for (int i = 0; i < s.KeysSounds.Length; i++) { int kLength = s.KeysSounds[i].Keys.Length; bool keysNull = (kLength >= 1 && !s.KeysSounds[i].Keys.Any(x => x != 0)); int sLength = s.KeysSounds[i].SoundLocations.Length; bool soundsNotEmpty = s.KeysSounds[i].SoundLocations.All(x => !string.IsNullOrWhiteSpace(x)); Environment.CurrentDirectory = Path.GetDirectoryName(Application.ExecutablePath); bool filesExist = s.KeysSounds[i].SoundLocations.All(x => File.Exists(x)); if (keysNull || sLength < 1 || !soundsNotEmpty || !filesExist) //error in XML file { string tempErr = ""; if (!keysNull) { tempErr = "one or more keys are null"; } else if (sLength < 1) { tempErr = "no sounds provided"; } else if (!filesExist) { tempErr = "one or more sounds do not exist"; } errors += "Entry #" + i.ToString() + "has an error: " + tempErr + "\r\n"; } string keys = (kLength < 1 ? "" : Helper.keysToString(s.KeysSounds[i].Keys)); if (keys != "" && items.Count > 0 && items[items.Count - 1].Text == keys && !sameKeys.Contains(keys)) { sameKeys += (sameKeys != "" ? ", " : "") + keys; } var temp = new ListViewItem(keys); temp.SubItems.Add((sLength < 1 ? "" : Helper.soundLocsArrayToString(s.KeysSounds[i].SoundLocations))); items.Add(temp); //add even if there was an error, so that the user can fix within the app } if (items.Count > 0) { if (errors != "") { MessageBox.Show((errors == "" ? "" : errors)); } if (sameKeys != "") { MessageBox.Show("Multiple entries using the same keys. The keys being used multiple times are: " + sameKeys); } keysSounds.Clear(); keysSounds.AddRange(s.KeysSounds); lvKeySounds.Items.Clear(); lvKeySounds.Items.AddRange(items.ToArray()); chKeys.Width = -2; chSoundLoc.Width = -2; xmlLoc = path; } else { SystemSounds.Beep.Play(); MessageBox.Show("No entries found, or all entries had errors in them (key being None, sound location behind empty or non-existant)"); } } else { SystemSounds.Beep.Play(); MessageBox.Show("No entries found, or there was an error reading the settings file"); } }
private bool loadXMLFile(string path) { bool errorOccurred = true; try { XMLSettings.Settings s = (XMLSettings.Settings)XMLSettings.ReadXML(typeof(XMLSettings.Settings), path); if (s != null && s.SoundHotkeys != null && s.SoundHotkeys.Length > 0) { var items = new List <ListViewItem>(); string errorMessage = ""; string sameKeys = ""; for (int i = 0; i < s.SoundHotkeys.Length; i++) { int kLength = s.SoundHotkeys[i].Keys.Length; bool keysNull = (kLength > 0 && !s.SoundHotkeys[i].Keys.Any(x => x != 0)); int sLength = s.SoundHotkeys[i].SoundLocations.Length; bool soundsNotEmpty = s.SoundHotkeys[i].SoundLocations.All(x => !string.IsNullOrWhiteSpace(x)); //false if even one location is empty Environment.CurrentDirectory = Path.GetDirectoryName(Application.ExecutablePath); bool filesExist = s.SoundHotkeys[i].SoundLocations.All(x => File.Exists(x)); if (keysNull || sLength < 1 || !soundsNotEmpty || !filesExist) //error in XML file { string tempErr = ""; if (kLength == 0 && (sLength == 0 || !soundsNotEmpty)) { tempErr = "entry is empty"; } else if (!keysNull) { tempErr = "one or more keys are null"; } else if (sLength == 0) { tempErr = "no sounds provided"; } else if (!filesExist) { tempErr = "one or more sounds do not exist"; } errorMessage += "Entry #" + (i + 1).ToString() + " has an error: " + tempErr + "\r\n"; } string keys = (kLength < 1 ? "" : Helper.keysArrayToString(s.SoundHotkeys[i].Keys)); if (keys != "" && items.Count > 0 && items[items.Count - 1].Text == keys && !sameKeys.Contains(keys)) { sameKeys += (sameKeys != "" ? ", " : "") + keys; } string windowString = string.IsNullOrWhiteSpace(s.SoundHotkeys[i].WindowTitle) ? "" : s.SoundHotkeys[i].WindowTitle; string volumeString = s.SoundHotkeys[i].SoundVolume == 1 ? "" : Helper.linearVolumeToString(s.SoundHotkeys[i].SoundVolume); string soundLocations = sLength < 1 ? "" : Helper.fileLocationsArrayToString(s.SoundHotkeys[i].SoundLocations); var temp = new ListViewItem(keys); temp.SubItems.Add(volumeString); temp.SubItems.Add(windowString); temp.SubItems.Add(soundLocations); temp.ToolTipText = Helper.getFileNamesTooltip(s.SoundHotkeys[i].SoundLocations); //blank tooltips are not displayed items.Add(temp); //add even if there was an error, so that the user can fix within the app } if (items.Count > 0) { if (errorMessage != "") { MessageBox.Show((errorMessage == "" ? "" : errorMessage)); } else { errorOccurred = false; } if (sameKeys != "") { MessageBox.Show("Multiple entries using the same keys. The keys being used multiple times are: " + sameKeys); } soundHotkeys.Clear(); soundHotkeys.AddRange(s.SoundHotkeys); lvKeySounds.Items.Clear(); lvKeySounds.Items.AddRange(items.ToArray()); sortHotkeys(); xmlLocation = path; } else { SystemSounds.Beep.Play(); MessageBox.Show("No entries found, or all entries had errors in them (key being None, sound location behind empty or non-existant)"); } } else { SystemSounds.Beep.Play(); MessageBox.Show("No entries found, or there was an error reading the settings file"); } } catch { MessageBox.Show("Settings file structure is incorrect"); } return(errorOccurred); }
private void saveSettingsTimer_Tick(object sender, EventArgs e) { //only save settings after no setting changes have been made for one second saveSettingsTimer.Stop(); XMLSettings.SaveSoundboardSettingsXML(); }
public MainForm() { InitializeComponent(); var tooltip = new ToolTip(); tooltip.SetToolTip(btnReloadDevices, "Refresh sound devices"); tooltip.SetToolTip(btnReloadWindows, "Reload windows"); tooltip.SetToolTip(cbPlaybackDevices1, PLAYBACK1_TOOLTIP); tooltip.SetToolTip(cbPlaybackDevices2, PLAYBACK2_TOOLTIP); tooltip.SetToolTip(cbLoopbackDevices, LOOPBACK_TOOLTIP); tooltip.SetToolTip(lblPlayback1, PLAYBACK1_TOOLTIP); tooltip.SetToolTip(lblPlayback2, PLAYBACK2_TOOLTIP); tooltip.SetToolTip(lblLoopback, LOOPBACK_TOOLTIP); tooltip.SetToolTip(vsSoundVolume, SOUND_VOLUME_TOOLTIP); tooltip.SetToolTip(nSoundVolume, SOUND_VOLUME_TOOLTIP); XMLSettings.LoadSoundboardSettingsXML(); //Disable change events for elements that would trigger settings changes and unnecessarily write to settings.xml DisableCheckboxChangeEvents(); DisableSoundVolumeChangeEvents(); loadSoundDevices(false); //false argument keeps device change events disabled Helper.getWindows(cbWindows); Helper.selectWindow(cbWindows, XMLSettings.soundboardSettings.AutoPushToTalkWindow); if (XMLSettings.soundboardSettings.StartMinimised) { this.WindowState = FormWindowState.Minimized; if (XMLSettings.soundboardSettings.MinimiseToTray) { this.HideFormToTray(); } } Helper.setStartup(XMLSettings.soundboardSettings.StartWithWindows); cbEnableHotkeys.Checked = XMLSettings.soundboardSettings.EnableHotkeys; cbEnableLoopback.Checked = XMLSettings.soundboardSettings.EnableLoopback; soundVolume = XMLSettings.soundboardSettings.SoundVolume; vsSoundVolume.Volume = soundVolume; nSoundVolume.Value = Helper.linearVolumeToInteger(vsSoundVolume.Volume); //needed because change events are still disabled pushToTalkKey = XMLSettings.soundboardSettings.AutoPushToTalkKey; tbPushToTalkKey.Text = pushToTalkKey.ToString() == "None" ? "" : pushToTalkKey.ToString(); cbEnablePushToTalk.Checked = XMLSettings.soundboardSettings.EnableAutoPushToTalk; tbPushToTalkKey.Enabled = !cbEnablePushToTalk.Checked; clearHotkey.Enabled = !cbEnablePushToTalk.Checked; if (File.Exists(XMLSettings.soundboardSettings.LastXMLFile)) { //loadXMLFile() returns true if error occurred if (loadXMLFile(XMLSettings.soundboardSettings.LastXMLFile)) { XMLSettings.soundboardSettings.LastXMLFile = ""; XMLSettings.SaveSoundboardSettingsXML(); } } //Add events after settings have been loaded EnableCheckboxChangeEvents(); EnableSoundVolumeChangeEvents(); EnableDeviceChangeEvents(); mainTimer.Enabled = cbEnableHotkeys.Checked; initAudioPlaybackEngine1(); initAudioPlaybackEngine2(); restartLoopback(); //When sound stops, fire event which lets go of push-to-talk key. playbackEngine1.AllInputEnded += OnAllInputEnded; //Don't need to stop holding the push-to-talk key when engine2 stops playing, that's just our in-ear echo. }