public HotkeyEditAudioInputOutputForm(Hotkey hotkey, bool setupBulkEditMode = false) { InitializeComponent(); cbCommand.DataSource = Enum.GetValues(typeof(HotkeyTypeEnum)); cbModifier.DataSource = Enum.GetValues(typeof(KeyModifier)); cbKey.DataSource = Enum.GetValues(typeof(Keys)); foreach (HotkeyAudioDevice currentDevice in MainAudio.Instance.AudioInputDevices) { cbInputDeviceOne.Items.Add(currentDevice.AudioDeviceName); } foreach (HotkeyAudioDevice currentDevice in MainAudio.Instance.AudioOutputDevices) { cbOutputDeviceOne.Items.Add(currentDevice.AudioDeviceName); cbOutputDeviceTwo.Items.Add(currentDevice.AudioDeviceName); } ChangeLabels(hotkey); ChangeEnabled(hotkey); ChangeDefaults(hotkey); cbCommand.SelectedItem = (HotkeyTypeEnum)hotkey.Command; cbCommand.Enabled = false; cbModifier.SelectedItem = (KeyModifier)hotkey.Modifier; cbKey.SelectedItem = (Keys)hotkey.Key; cbInputDeviceOne.SelectedItem = hotkey.ExtraData1; cbOutputDeviceOne.SelectedItem = hotkey.ExtraData2; cbOutputDeviceTwo.SelectedItem = hotkey.ExtraData3; string extraData4 = hotkey.GetAdditionalData(HotkeyAdditionalDataType.ExtraData4); if (extraData4 != null) { tbExtraData4.Text = extraData4; } SetupBulkEditControls(setupBulkEditMode); }
public HotkeyEditAudioAutoTunePassthroughForm(Hotkey hotkey) { InitializeComponent(); AutoTuneViewModel = new AutoTuneViewModel(); cbCommand.DataSource = Enum.GetValues(typeof(HotkeyTypeEnum)); cbModifier.DataSource = Enum.GetValues(typeof(KeyModifier)); cbKey.DataSource = Enum.GetValues(typeof(Keys)); foreach (HotkeyAudioDevice currentDevice in MainAudio.Instance.AudioInputDevices) { cbInputDeviceOne.Items.Add(currentDevice.AudioDeviceName); } foreach (HotkeyAudioDevice currentDevice in MainAudio.Instance.AudioOutputDevices) { cbOutputDeviceOne.Items.Add(currentDevice.AudioDeviceName); } foreach (string currentScale in AutoTuneViewModel.Scales) { cbScale.Items.Add(currentScale); } string trbAttackValue = hotkey.GetAdditionalData(HotkeyAdditionalDataType.AutoTuneAttack); if (trbAttackValue != null) { trBAttack.Value = int.Parse(trbAttackValue); lblAttackVal.Text = trbAttackValue + "ms"; } string vibratoRate = hotkey.GetAdditionalData(HotkeyAdditionalDataType.AutoTuneVibratoRate); if (vibratoRate != null) { tbVibratoRate.Text = vibratoRate; } foreach (NoteViewModel pitch in AutoTuneViewModel.Pitches) { HotkeyAdditionalDataType pitchAddtDataType = GetAddtDataTypeFromPitch(pitch); string pitchAddt = hotkey.GetAdditionalData(pitchAddtDataType); CheckBox pitchCb = GetCheckboxFromPitch(pitch); if (pitchAddt != null && pitchCb != null) { pitchCb.Checked = bool.Parse(pitchAddt); pitch.Selected = bool.Parse(pitchAddt); } } string selectedScale = AutoTuneViewModel.GetScaleFromSelectedPitches(); if (!String.IsNullOrWhiteSpace(selectedScale)) { cbScale.SelectedItem = selectedScale; } cbCommand.SelectedItem = (HotkeyTypeEnum)hotkey.Command; cbCommand.Enabled = false; cbModifier.SelectedItem = (KeyModifier)hotkey.Modifier; cbKey.SelectedItem = (Keys)hotkey.Key; cbInputDeviceOne.SelectedItem = hotkey.ExtraData1; cbOutputDeviceOne.SelectedItem = hotkey.ExtraData2; }
public ValidationResult Validate(Hotkey hotkey) { ValidationResult result = new ValidationResult(); result.Status = ValidationResultStatus.Success; // success until error try { if (hotkey.KeyEnum == System.Windows.Forms.Keys.None) { result.Errors.Add(new ValidationException("Need to choose a key for the hotkey")); result.Status = ValidationResultStatus.Error; } switch (hotkey.CommandEnum) { case HotkeyTypeEnum.ChangeAudioVolume: case HotkeyTypeEnum.StepUpAudioVolume: case HotkeyTypeEnum.StepDownAudioVolume: if (!String.IsNullOrWhiteSpace(hotkey.ExtraData2)) { ValidateStringIsDeviceName(hotkey.ExtraData2, result, AudioDeviceType.Output); } if (!String.IsNullOrWhiteSpace(hotkey.ExtraData3)) { ValidateStringIsDeviceName(hotkey.ExtraData3, result, AudioDeviceType.Output); } ValidateAudioVolumeHotkeys(hotkey, result); break; case HotkeyTypeEnum.DownloadYouTubeVideo: case HotkeyTypeEnum.StopAudioAllDevices: ValidateHotkeysWithNoData(hotkey, result); break; case HotkeyTypeEnum.PlayAudio: case HotkeyTypeEnum.ToggleAudio: if (String.IsNullOrWhiteSpace(hotkey.ExtraData1) || !File.Exists(hotkey.ExtraData1)) { result.Errors.Add(new ValidationException("Need to have a valid file as the audio file")); result.Status = ValidationResultStatus.Error; } else { if (new System.IO.FileInfo(hotkey.ExtraData1).Length > 10485760) { result.Errors.Add(new ValidationException("File sizes for audio cannot exceed 10mb")); result.Status = ValidationResultStatus.Error; } } if (String.IsNullOrWhiteSpace(hotkey.ExtraData2)) { result.Errors.Add(new ValidationException("Need to enter at least the first audio device")); result.Status = ValidationResultStatus.Error; } if (!String.IsNullOrWhiteSpace(hotkey.ExtraData2)) { ValidateStringIsDeviceName(hotkey.ExtraData2, result, AudioDeviceType.Output); } if (!String.IsNullOrWhiteSpace(hotkey.ExtraData3)) { ValidateStringIsDeviceName(hotkey.ExtraData3, result, AudioDeviceType.Output); } if (hotkey.AdditionalExtraData != null && hotkey.AdditionalExtraData.ContainsKey((int)HotkeyAdditionalDataType.DeviceThree) && !String.IsNullOrWhiteSpace(hotkey.AdditionalExtraData[(int)HotkeyAdditionalDataType.DeviceThree])) { ValidateStringIsDeviceName(hotkey.AdditionalExtraData[(int)HotkeyAdditionalDataType.DeviceThree], result, AudioDeviceType.Output); } break; case HotkeyTypeEnum.ESpeak: if (String.IsNullOrWhiteSpace(hotkey.ExtraData2)) { result.Errors.Add(new ValidationException("Need to enter at least the first audio device")); result.Status = ValidationResultStatus.Error; } if (!String.IsNullOrWhiteSpace(hotkey.ExtraData2)) { ValidateStringIsDeviceName(hotkey.ExtraData2, result, AudioDeviceType.Output); } if (!String.IsNullOrWhiteSpace(hotkey.ExtraData3)) { ValidateStringIsDeviceName(hotkey.ExtraData3, result, AudioDeviceType.Output); } if (hotkey.AdditionalExtraData != null && hotkey.AdditionalExtraData.ContainsKey((int)HotkeyAdditionalDataType.DeviceThree) && !String.IsNullOrWhiteSpace(hotkey.AdditionalExtraData[(int)HotkeyAdditionalDataType.DeviceThree])) { ValidateStringIsDeviceName(hotkey.AdditionalExtraData[(int)HotkeyAdditionalDataType.DeviceThree], result, AudioDeviceType.Output); } break; case HotkeyTypeEnum.RunBatchSilently: if (String.IsNullOrWhiteSpace(hotkey.ExtraData1) || !File.Exists(hotkey.ExtraData1)) { result.Errors.Add(new ValidationException("Need to have a valid file as the batch file")); result.Status = ValidationResultStatus.Error; } break; case HotkeyTypeEnum.RunFile: if (String.IsNullOrWhiteSpace(hotkey.ExtraData1) || !File.Exists(hotkey.ExtraData1)) { result.Errors.Add(new ValidationException("Need to have a valid file as the file to run")); result.Status = ValidationResultStatus.Error; } break; case HotkeyTypeEnum.StopAudioDevice: if (String.IsNullOrWhiteSpace(hotkey.ExtraData2)) { result.Errors.Add(new ValidationException("Need to enter the primary audio device")); result.Status = ValidationResultStatus.Error; } else { ValidateStringIsDeviceName(hotkey.ExtraData2, result, AudioDeviceType.Output); } break; case HotkeyTypeEnum.StartRecordingInputDevice: if (!String.IsNullOrWhiteSpace(hotkey.ExtraData1)) { result.Errors.Add(new ValidationException("No need to enter the data for ExtraData1")); result.Status = ValidationResultStatus.Error; } if (String.IsNullOrWhiteSpace(hotkey.ExtraData2)) { result.Errors.Add(new ValidationException("Need to enter the primary audio device")); result.Status = ValidationResultStatus.Error; } else { ValidateStringIsDeviceName(hotkey.ExtraData2, result, AudioDeviceType.Input); } if (!String.IsNullOrWhiteSpace(hotkey.ExtraData3)) { int temp = 0; if (!int.TryParse(hotkey.ExtraData3, out temp)) { result.Errors.Add(new ValidationException("You must enter a number in the seconds to record")); result.Status = ValidationResultStatus.Error; break; } if (temp < 2) { result.Errors.Add(new ValidationException("You must record at least 2 seconds")); result.Status = ValidationResultStatus.Error; } } break; case HotkeyTypeEnum.StopRecordingInputDevice: if (!String.IsNullOrWhiteSpace(hotkey.ExtraData1)) { result.Errors.Add(new ValidationException("No need to enter the data for ExtraData1")); result.Status = ValidationResultStatus.Error; } if (String.IsNullOrWhiteSpace(hotkey.ExtraData2)) { result.Errors.Add(new ValidationException("Need to enter the primary audio device")); result.Status = ValidationResultStatus.Error; } else { ValidateStringIsDeviceName(hotkey.ExtraData2, result, AudioDeviceType.Input); } if (!String.IsNullOrWhiteSpace(hotkey.ExtraData3)) { result.Errors.Add(new ValidationException("No need to enter the data for ExtraData3")); result.Status = ValidationResultStatus.Error; } break; case HotkeyTypeEnum.SaveInputDeviceRecordingToFile: if (String.IsNullOrWhiteSpace(hotkey.ExtraData1)) { result.Errors.Add(new ValidationException("Need to enter in the path for the wav file to save to")); result.Status = ValidationResultStatus.Error; } else { if (!Directory.Exists(Path.GetDirectoryName(hotkey.ExtraData1))) { result.Errors.Add(new ValidationException("Invalid directory to save the wav file to")); result.Status = ValidationResultStatus.Error; } if (Path.GetExtension(hotkey.ExtraData1).ToLower() != ".wav") { result.Errors.Add(new ValidationException("Must save the file as a wav file")); result.Status = ValidationResultStatus.Error; } } if (String.IsNullOrWhiteSpace(hotkey.ExtraData2)) { result.Errors.Add(new ValidationException("Need to enter the primary audio device")); result.Status = ValidationResultStatus.Error; } else { ValidateStringIsDeviceName(hotkey.ExtraData2, result, AudioDeviceType.Input); } if (!String.IsNullOrWhiteSpace(hotkey.ExtraData3)) { result.Errors.Add(new ValidationException("No need to enter the data for ExtraData3")); result.Status = ValidationResultStatus.Error; } break; case HotkeyTypeEnum.SaveInputDeviceRecordingToMemory: if (!String.IsNullOrWhiteSpace(hotkey.ExtraData1)) { result.Errors.Add(new ValidationException("No need to enter data in for ExtraData1")); result.Status = ValidationResultStatus.Error; } if (!String.IsNullOrWhiteSpace(hotkey.ExtraData3)) { result.Errors.Add(new ValidationException("No need to enter data in for ExtraData3")); result.Status = ValidationResultStatus.Error; } if (String.IsNullOrWhiteSpace(hotkey.ExtraData2)) { result.Errors.Add(new ValidationException("Need to enter the primary input audio device")); result.Status = ValidationResultStatus.Error; } else { ValidateStringIsDeviceName(hotkey.ExtraData2, result, AudioDeviceType.Input); } break; case HotkeyTypeEnum.PlayInputDeviceRecordingFromMemory: if (String.IsNullOrWhiteSpace(hotkey.ExtraData1)) { result.Errors.Add(new ValidationException("Need to enter the primary input audio device")); result.Status = ValidationResultStatus.Error; } else { ValidateStringIsDeviceName(hotkey.ExtraData1, result, AudioDeviceType.Input); } if (String.IsNullOrWhiteSpace(hotkey.ExtraData2)) { result.Errors.Add(new ValidationException("Need to enter the primary output audio device")); result.Status = ValidationResultStatus.Error; } else { ValidateStringIsDeviceName(hotkey.ExtraData2, result, AudioDeviceType.Output); } if (!String.IsNullOrWhiteSpace(hotkey.ExtraData3)) { ValidateStringIsDeviceName(hotkey.ExtraData3, result, AudioDeviceType.Output); } break; case HotkeyTypeEnum.DevicePassthrough: if (String.IsNullOrWhiteSpace(hotkey.ExtraData1)) { result.Errors.Add(new ValidationException("Need to enter the primary input audio device")); result.Status = ValidationResultStatus.Error; } else { ValidateStringIsDeviceName(hotkey.ExtraData1, result, AudioDeviceType.Input); } if (String.IsNullOrWhiteSpace(hotkey.ExtraData2)) { result.Errors.Add(new ValidationException("Need to enter the primary output audio device")); result.Status = ValidationResultStatus.Error; } else { ValidateStringIsDeviceName(hotkey.ExtraData2, result, AudioDeviceType.Output); } string startOnText = hotkey.GetAdditionalData(HotkeyAdditionalDataType.ExtraData4); if (String.IsNullOrWhiteSpace(startOnText)) { result.Errors.Add(new ValidationException("Need to enter true or false for if it should start on")); result.Status = ValidationResultStatus.Error; } if (startOnText != "true" && startOnText != "false") { result.Errors.Add(new ValidationException("Need to enter either true or false in lowercase for whether it should start on")); result.Status = ValidationResultStatus.Error; } break; } } catch (Exception e) { result.Status = ValidationResultStatus.Error; ValidationException ex = new ValidationException(e.Message); result.Errors.Add(ex); } return(result); }