Пример #1
0
        private void validateBytesToSamplesCheckbox(CheckBox chk)
        {
            DataRowView drv      = (DataRowView)this.comboFormat.SelectedItem;
            UInt16      formatId = Convert.ToUInt16(drv.Row.ItemArray[0]);

            if (chk.Checked)
            {
                if (!GenhUtil.CanConvertBytesToSamples(formatId))
                {
                    MessageBox.Show("Cannot convert bytes to samples for the following formats: MPEG, XMA, XMA2, FFMPEG.", "Error");
                    chk.Checked = false;
                }
            }
        }
Пример #2
0
        public static bool ValidateInputs(GenhCreatorStruct pGenhCreatorStruct,
                                          out string pErrorMessages)
        {
            bool          isValid = true;
            long          dummy;
            StringBuilder errorBuffer = new StringBuilder();

            // Paths
            if (pGenhCreatorStruct.SourcePaths.GetLength(0) < 1)
            {
                isValid = false;
                errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageNoInputs"]);
                errorBuffer.Append(Environment.NewLine);
            }

            // Header Skip
            if (String.IsNullOrEmpty(pGenhCreatorStruct.HeaderSkip.Trim()))
            {
                isValid = false;
                errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageHeaderSkip"]);
                errorBuffer.Append(Environment.NewLine);
            }

            // Raw Data Size
            if (!String.IsNullOrWhiteSpace(pGenhCreatorStruct.RawDataSize))
            {
                dummy = ByteConversion.GetLongValueFromString(pGenhCreatorStruct.RawDataSize);

                if (dummy < 1)
                {
                    isValid = false;
                    errorBuffer.Append("Raw Data Size must be greater than zero.");
                    errorBuffer.Append(Environment.NewLine);
                }
            }

            // Interleave
            if (String.IsNullOrEmpty(pGenhCreatorStruct.Interleave.Trim()))
            {
                isValid = false;
                errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageInterleave"]);
                errorBuffer.Append(Environment.NewLine);
            }

            // Channels
            if (String.IsNullOrEmpty(pGenhCreatorStruct.Channels.Trim()))
            {
                isValid = false;
                errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageChannels"]);
                errorBuffer.Append(Environment.NewLine);
            }

            // Frequency
            if (String.IsNullOrEmpty(pGenhCreatorStruct.Frequency.Trim()) &&
                String.IsNullOrEmpty(pGenhCreatorStruct.FrequencyOffsetDescription.OffsetValue))
            {
                isValid = false;
                errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageFrequency"]);
                errorBuffer.Append(Environment.NewLine);
            }

            // Loop Start
            if (!pGenhCreatorStruct.NoLoops &&
                !pGenhCreatorStruct.FindLoop &&
                String.IsNullOrEmpty(pGenhCreatorStruct.LoopStart.Trim()) &&
                String.IsNullOrEmpty(pGenhCreatorStruct.LoopStartOffsetDescription.OffsetValue))
            {
                isValid = false;
                errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageLoopStart1"]);
                errorBuffer.Append(Environment.NewLine);
            }
            else if (!pGenhCreatorStruct.NoLoops &&
                     !pGenhCreatorStruct.FindLoop &&
                     !String.IsNullOrEmpty(pGenhCreatorStruct.LoopStart) &&
                     VGMToolbox.util.ByteConversion.GetLongValueFromString(pGenhCreatorStruct.LoopStart.Trim()) < 0)
            {
                isValid = false;
                errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageLoopStart2"]);
                errorBuffer.Append(Environment.NewLine);
            }

            // Loop End
            if (!pGenhCreatorStruct.NoLoops &&
                !pGenhCreatorStruct.UseFileEnd &&
                !pGenhCreatorStruct.FindLoop &&
                String.IsNullOrEmpty(pGenhCreatorStruct.LoopEnd.Trim()) &&
                String.IsNullOrEmpty(pGenhCreatorStruct.LoopEndOffsetDescription.OffsetValue))
            {
                isValid = false;
                errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageLoopEnd"]);
                errorBuffer.Append(Environment.NewLine);
            }

            // Total Samples
            if (pGenhCreatorStruct.NoLoops &&
                ((String.IsNullOrWhiteSpace(pGenhCreatorStruct.TotalSamples) &&
                  String.IsNullOrWhiteSpace(pGenhCreatorStruct.TotalSamplesOffsetDescription.OffsetValue)) ||
                 ByteConversion.GetLongValueFromString(pGenhCreatorStruct.TotalSamples) < 1) &&
                !GenhUtil.CanConvertBytesToSamples(pGenhCreatorStruct.Format))
            {
                isValid = false;
                errorBuffer.Append("The following formats require a value greater than 0 (or Offset) for 'Total Samples' if no 'Loop End' is identified: MPEG, XMA, XMA2, FFMPEG.");
                errorBuffer.Append(Environment.NewLine);
            }

            // Skip Samples
            if (pGenhCreatorStruct.SkipSamplesMode == Genh.SKIP_SAMPLES_MODE_FORCE &&
                String.IsNullOrWhiteSpace(pGenhCreatorStruct.SkipSamples))
            {
                isValid = false;
                errorBuffer.Append("Skip Samples cannot be empty if 'Force Skip Samples' is checked.");
                errorBuffer.Append(Environment.NewLine);
            }

            // Right Coef
            if (pGenhCreatorStruct.Format.Equals("12") &&
                String.IsNullOrEmpty(pGenhCreatorStruct.CoefRightChannel.Trim()))
            {
                isValid = false;
                errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageCoefRight"]);
                errorBuffer.Append(Environment.NewLine);
            }

            // Left Coef
            if (pGenhCreatorStruct.Format.Equals("12") &&
                String.IsNullOrEmpty(pGenhCreatorStruct.CoefLeftChannel.Trim()))
            {
                isValid = false;
                errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageCoefLeft"]);
                errorBuffer.Append(Environment.NewLine);
            }

            // Find Loop End
            if (pGenhCreatorStruct.UseFileEnd && pGenhCreatorStruct.Format.Equals("8"))
            {
                isValid = false;
                errorBuffer.Append(ConfigurationManager.AppSettings["Form_GenhCreator_MessageFileEnd"]);
                errorBuffer.Append(Environment.NewLine);
            }

            pErrorMessages = errorBuffer.ToString();
            return(isValid);
        }
Пример #3
0
        private void bytesToSamplesToolStripMenuItem_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left)
            {
                try
                {
                    long loopValue   = 0;
                    long headerValue = 0;

                    if (this.selectedLabel == TOTAL_SAMPLES_LABEL_SELECTED)
                    {
                        loopValue = ByteConversion.GetLongValueFromString(this.tbTotalSamples.Text);
                    }
                    else
                    {
                        if (this.selectedLabel == LOOP_START_LABEL_SELECTED)
                        {
                            loopValue = ByteConversion.GetLongValueFromString(this.tbLoopStart.Text);
                        }
                        else if (this.selectedLabel == LOOP_END_LABEL_SELECTED)
                        {
                            loopValue = ByteConversion.GetLongValueFromString(this.tbLoopEnd.Text);
                        }

                        if (!String.IsNullOrEmpty(this.cbHeaderSkip.Text))
                        {
                            headerValue = ByteConversion.GetLongValueFromString(this.cbHeaderSkip.Text);
                            loopValue  -= headerValue;
                        }
                    }

                    if (loopValue >= 0)
                    {
                        if (!String.IsNullOrWhiteSpace(this.cbInterleave.Text) &&
                            !String.IsNullOrWhiteSpace(this.cbChannels.Text))
                        {
                            DataRowView drv      = (DataRowView)this.comboFormat.SelectedItem;
                            UInt16      formatId = Convert.ToUInt16(drv.Row.ItemArray[0]);

                            if (GenhUtil.CanConvertBytesToSamples(formatId))
                            {
                                long interleave   = ByteConversion.GetLongValueFromString(this.cbInterleave.Text);
                                long channelCount = ByteConversion.GetLongValueFromString(this.cbChannels.Text);

                                long samplesValue = GenhUtil.BytesToSamples((int)formatId, (int)loopValue, (int)channelCount, (int)interleave);

                                if (this.selectedLabel == LOOP_START_LABEL_SELECTED)
                                {
                                    this.tbLoopStart.Text = samplesValue.ToString();
                                }
                                else if (this.selectedLabel == LOOP_END_LABEL_SELECTED)
                                {
                                    this.tbLoopEnd.Text = samplesValue.ToString();
                                }
                                else if (this.selectedLabel == TOTAL_SAMPLES_LABEL_SELECTED)
                                {
                                    this.tbTotalSamples.Text = samplesValue.ToString();
                                }
                            }
                            else
                            {
                                MessageBox.Show("Cannot convert bytes to samples for the following formats: MPEG, XMA, XMA2, FFMPEG.", "Error");
                            }
                        }
                        else
                        {
                            MessageBox.Show("Cannot convert bytes to samples: Please enter values for Interleave and Channels.", "Error");
                        }
                    }
                }
                catch
                {
                }
            }
        }