예제 #1
0
 public static bool verifyDouble(string message, string text, out double value)
 {
     try
     {
         value = ParseUtils.GetDouble(text);
         return(true);
     }
     catch (FormatException)
     {
         value = -1;
         showErrorMessage(message);
         return(false);
     }
 }
예제 #2
0
 public static bool verifyRangeFromString(string message,
                                          string text,
                                          double min,
                                          double max,
                                          out double value,
                                          bool acceptBlankText = false)
 {
     if (!acceptBlankText || !string.IsNullOrEmpty(text))
     {
         try
         {
             double number = ParseUtils.GetDouble(text);
             if (verifyRange(min, max, number))
             {
                 value = number;
                 return(true);
             }
             else
             {
                 value = -1;
                 showErrorMessage(message);
                 return(false);
             }
         }
         catch (FormatException)
         {
             value = -1;
             showErrorMessage(message);
             return(false);
         }
     }
     else
     {
         value = 0;
         return(true);
     }
 }
        // Checks the values and sets them on the fly.
        //
        private bool checkValues()
        {
            bool check = true;

            // Check the SV increase mode first.
            check = VerifyUtils.verifyRange("You need to select a SV increase mode.",
                                            0, increaseModeComboBox.Items.Count, increaseModeComboBox.SelectedIndex) &&

                    // Check the necessary textboxes afterwards.
                    VerifyUtils.verifyTextBoxes("You need to fill necessary fields.",
                                                increaseModeComboBox.SelectedIndex != 0 ? increaseMultiplierTextBox : null,
                                                firstTimeTextBox,
                                                lastTimeTextBox,
                                                firstSvTextBox,
                                                lastSvTextBox) &&

                    // Check if grid snap is entered if "Put points by note snaps"
                    // is not enabled.
                    (putPointsByNotesCheckBox.Checked || VerifyUtils.verifyTextBoxes(
                         "You need to fill the \"Grid Snap\" value if you don\'t check\n" +
                         "\"Put points by note snaps\" checkbox."));

            // If anything was wrong here, don't check the rest.
            if (!check)
            {
                return(false);
            }

            // Set the sv increase mode.
            SvIncreaseMode = increaseModeComboBox.SelectedIndex;

            // Starting from here, check the values themselves.
            // Start with the extracted times.
            check = VerifyUtils.verifyOffsetFormat("First entered time format is wrong.",
                                                   firstTimeTextBox.Text, out FirstOffset);

            if (!check)
            {
                return(false);
            }

            // Check the last time text box if time mode checkbox is checked.
            // Otherwise, try to parse the integer as count.
            if (activateTimeModeCheckBox.Checked)
            {
                check = VerifyUtils.verifyOffsetFormat("Last entered time format is wrong.",
                                                       lastTimeTextBox.Text, out LastOffset);

                if (!check)
                {
                    return(false);
                }
                else if (LastOffset <= FirstOffset)
                {
                    MessageBoxUtils.showError("You cannot use the last time point before the first time point.");
                    return(false);
                }
            }
            else
            {
                check = VerifyUtils.verifyRangeFromString("Count text is wrong, value must be higher than 0.", lastTimeTextBox.Text,
                                                          0, int.MaxValue, out Count);

                if (!check)
                {
                    return(false);
                }
            }

            check = ParseUtils.GetDouble(firstSvTextBox.Text, out FirstSv);
            if (!check)
            {
                MessageBoxUtils.showError("Entered first SV value is wrong.");
                return(false);
            }

            check = ParseUtils.GetDouble(lastSvTextBox.Text, out LastSv);
            if (!check)
            {
                MessageBoxUtils.showError("Entered last SV value is wrong.");
                return(false);
            }

            if (SvIncreaseMode != 0)
            {
                check = VerifyUtils.verifyRangeFromString("Sv increase multiplier text is wrong, value must be higher than 0.", increaseMultiplierTextBox.Text,
                                                          0, int.MaxValue, out SvIncreaseMultiplier);

                if (!check)
                {
                    return(false);
                }
            }

            // If "Put points by notes" is not checked,
            // the grid snap value has to be defined.
            // Check that there.
            if (putPointsByNotesCheckBox.Checked)
            {
                GridSnap         = 0;
                PutPointsByNotes = true;
                check            = true;
            }
            else
            {
                check = VerifyUtils.verifyGridSnap("Grid snap value is wrong. Example: 1/4",
                                                   gridSnapTextBox.Text, out GridSnap);

                if (!check)
                {
                    return(false);
                }
            }

            // Check the target BPM and SV offset here. These fields are optional,
            // so accept blank text, but if it cannot parse, warn the user.
            check = VerifyUtils.verifyRangeFromString("Target BPM is wrong, example: 200.\nThis field is optional, so you can keep it blank.",
                                                      targetBpmTextBox.Text, 0, double.MaxValue, out TargetBpm, true);

            if (!check)
            {
                return(false);
            }

            check = VerifyUtils.verifyRangeFromString("SV offset is wrong, it should be between -10 and 0.\nThis field is optional, so you can keep it blank.",
                                                      svOffsetTextBox.Text, -10, 0, out SvOffset, true);

            // Finally, return true or false if checks are done.
            return(check);
        }