public void FramesToMilliseconds()
        {
            Configuration.Settings.General.CurrentFrameRate = 30;
            var fr = SubtitleFormat.FramesToMilliseconds(1);

            Assert.AreEqual(33, fr);
            fr = SubtitleFormat.FramesToMilliseconds(30);
            Assert.AreEqual(1000, fr);

            fr = SubtitleFormat.FramesToMillisecondsMax999(30);
            Assert.AreEqual(999, fr);
        }
Exemplo n.º 2
0
        public static double ParseHHMMSSFFToMilliseconds(string text)
        {
            var parts = text.Split(TimeSplitChars, StringSplitOptions.RemoveEmptyEntries);

            if (parts.Length == 4)
            {
                if (int.TryParse(parts[0], out var hours) && int.TryParse(parts[1], out var minutes) && int.TryParse(parts[2], out var seconds) && int.TryParse(parts[3], out var frames))
                {
                    return(new TimeCode(hours, minutes, seconds, SubtitleFormat.FramesToMillisecondsMax999(frames)).TotalMilliseconds);
                }
            }
            return(0);
        }
Exemplo n.º 3
0
 public static double ParseHHMMSSFFToMilliseconds(string text)
 {
     string[] parts = text.Split(new[] { ':', ',', '.' }, StringSplitOptions.RemoveEmptyEntries);
     if (parts.Length == 4)
     {
         int hours;
         int minutes;
         int seconds;
         int frames;
         if (int.TryParse(parts[0], out hours) && int.TryParse(parts[1], out minutes) && int.TryParse(parts[2], out seconds) && int.TryParse(parts[3], out frames))
         {
             return(new TimeCode(hours, minutes, seconds, SubtitleFormat.FramesToMillisecondsMax999(frames)).TotalMilliseconds);
         }
     }
     return(0);
 }
Exemplo n.º 4
0
 public static double ParseHHMMSSFFToMilliseconds(string text)
 {
     string[] parts = text.Split(":,.".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
     if (parts.Length == 4)
     {
         int hours;
         int minutes;
         int seconds;
         int frames;
         if (int.TryParse(parts[0], out hours) && int.TryParse(parts[1], out minutes) && int.TryParse(parts[2], out seconds) && int.TryParse(parts[3], out frames))
         {
             TimeSpan ts = new TimeSpan(0, hours, minutes, seconds, SubtitleFormat.FramesToMillisecondsMax999(frames));
             return(ts.TotalMilliseconds);
         }
     }
     return(0);
 }
Exemplo n.º 5
0
        private static TimeCode DecodeTime(string[] parts)
        {
            try
            {
                string hour    = parts[0];
                string minutes = parts[1];
                string seconds = parts[2];
                string frames;
                if (parts.Length < 4)
                {
                    frames  = seconds;
                    seconds = minutes;
                    minutes = hour;
                    hour    = "0";
                }
                else
                {
                    frames = parts[3];
                }

                if (frames.Length < 3)
                {
                    return(new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), SubtitleFormat.FramesToMillisecondsMax999(int.Parse(frames))));
                }

                return(new TimeCode(int.Parse(hour), int.Parse(minutes), int.Parse(seconds), int.Parse(frames)));
            }
            catch
            {
                return(new TimeCode());
            }
        }
Exemplo n.º 6
0
        private void FillFromHeader(Ebu.EbuGeneralSubtitleInformation header)
        {
            textBoxCodePageNumber.Text = header.CodePageNumber;

            comboBoxFrameRate.Items.Clear();
            comboBoxFrameRate.Items.Add(23.976);
            comboBoxFrameRate.Items.Add(24.0);
            comboBoxFrameRate.Items.Add(25.0);
            comboBoxFrameRate.Items.Add(29.97);
            comboBoxFrameRate.Items.Add(30.0);

            if (header.DiskFormatCode == "STL30.01")
            {
                comboBoxDiscFormatCode.SelectedIndex = 4;
                comboBoxFrameRate.Text = (30).ToString(CultureInfo.CurrentCulture);
            }
            else if (header.DiskFormatCode == "STL23.01")
            {
                comboBoxDiscFormatCode.SelectedIndex = 0;
                comboBoxFrameRate.Text = (23.976).ToString(CultureInfo.CurrentCulture);
            }
            else if (header.DiskFormatCode == "STL24.01")
            {
                comboBoxDiscFormatCode.SelectedIndex = 1;
                comboBoxFrameRate.Text = (24).ToString(CultureInfo.CurrentCulture);
            }
            else if (header.DiskFormatCode == "STL29.01")
            {
                comboBoxDiscFormatCode.SelectedIndex = 3;
                comboBoxFrameRate.Text = (25).ToString(CultureInfo.CurrentCulture);
            }
            else
            {
                comboBoxDiscFormatCode.SelectedIndex = 2;
                comboBoxFrameRate.Text = (25).ToString(CultureInfo.CurrentCulture);
            }

            if (header.FrameRateFromSaveDialog > 20 && header.FrameRateFromSaveDialog < 200)
            {
                comboBoxFrameRate.Text = header.FrameRateFromSaveDialog.ToString(CultureInfo.CurrentCulture);
            }

            if (header.DisplayStandardCode == "0")
            {
                comboBoxDisplayStandardCode.SelectedIndex = 0;
            }
            else if (header.DisplayStandardCode == "1")
            {
                comboBoxDisplayStandardCode.SelectedIndex = 1;
            }
            else if (header.DisplayStandardCode == "2")
            {
                comboBoxDisplayStandardCode.SelectedIndex = 2;
            }
            else
            {
                comboBoxDisplayStandardCode.SelectedIndex = 3;
            }

            comboBoxCharacterCodeTable.SelectedIndex = int.Parse(header.CharacterCodeTableNumber);
            textBoxLanguageCode.Text              = header.LanguageCode;
            textBoxOriginalProgramTitle.Text      = header.OriginalProgrammeTitle.TrimEnd();
            textBoxOriginalEpisodeTitle.Text      = header.OriginalEpisodeTitle.TrimEnd();
            textBoxTranslatedProgramTitle.Text    = header.TranslatedProgrammeTitle.TrimEnd();
            textBoxTranslatedEpisodeTitle.Text    = header.TranslatedEpisodeTitle.TrimEnd();
            textBoxTranslatorsName.Text           = header.TranslatorsName.TrimEnd();
            textBoxSubtitleListReferenceCode.Text = header.SubtitleListReferenceCode.TrimEnd();
            textBoxCountryOfOrigin.Text           = header.CountryOfOrigin;

            comboBoxTimeCodeStatus.SelectedIndex = 1;
            if (header.TimeCodeStatus == "0")
            {
                comboBoxTimeCodeStatus.SelectedIndex = 0; // 1 == intended for use, 0 == not intended for use
            }

            try
            {
                // HHMMSSFF
                int hh = int.Parse(header.TimeCodeStartOfProgramme.Substring(0, 2));
                int mm = int.Parse(header.TimeCodeStartOfProgramme.Substring(2, 2));
                int ss = int.Parse(header.TimeCodeStartOfProgramme.Substring(4, 2));
                int ff = int.Parse(header.TimeCodeStartOfProgramme.Substring(6, 2));
                timeUpDownStartTime.TimeCode = new TimeCode(hh, mm, ss, SubtitleFormat.FramesToMillisecondsMax999(ff));
            }
            catch (Exception)
            {
                timeUpDownStartTime.TimeCode = new TimeCode();
            }

            int number;

            if (int.TryParse(header.RevisionNumber, out number))
            {
                numericUpDownRevisionNumber.Value = number;
            }
            else
            {
                numericUpDownRevisionNumber.Value = 1;
            }

            if (int.TryParse(header.MaximumNumberOfDisplayableCharactersInAnyTextRow, out number))
            {
                numericUpDownMaxCharacters.Value = number;
            }

            numericUpDownMaxRows.Value = 23;
            if (int.TryParse(header.MaximumNumberOfDisplayableRows, out number))
            {
                numericUpDownMaxRows.Value = number;
            }

            if (int.TryParse(header.DiskSequenceNumber, out number))
            {
                numericUpDownDiskSequenceNumber.Value = number;
            }
            else
            {
                numericUpDownDiskSequenceNumber.Value = 1;
            }

            if (int.TryParse(header.TotalNumberOfDisks, out number))
            {
                numericUpDownTotalNumberOfDiscs.Value = number;
            }
            else
            {
                numericUpDownTotalNumberOfDiscs.Value = 1;
            }
        }
Exemplo n.º 7
0
        private void FillFromHeader(Ebu.EbuGeneralSubtitleInformation header)
        {
            textBoxCodePageNumber.Text = header.CodePageNumber;

            if (header.DiskFormatCode == "STL30.01")
            {
                comboBoxDiscFormatCode.SelectedIndex = 1;
            }
            else
            {
                comboBoxDiscFormatCode.SelectedIndex = 0;
            }

            if (header.DisplayStandardCode == "0")
            {
                comboBoxDisplayStandardCode.SelectedIndex = 0;
            }
            else if (header.DisplayStandardCode == "1")
            {
                comboBoxDisplayStandardCode.SelectedIndex = 1;
            }
            else if (header.DisplayStandardCode == "2")
            {
                comboBoxDisplayStandardCode.SelectedIndex = 2;
            }
            else
            {
                comboBoxDisplayStandardCode.SelectedIndex = 3;
            }

            comboBoxCharacterCodeTable.SelectedIndex = int.Parse(header.CharacterCodeTableNumber);
            textBoxLanguageCode.Text              = header.LanguageCode;
            textBoxOriginalProgramTitle.Text      = header.OriginalProgrammeTitle.TrimEnd();
            textBoxOriginalEpisodeTitle.Text      = header.OriginalEpisodeTitle.TrimEnd();
            textBoxTranslatedProgramTitle.Text    = header.TranslatedProgrammeTitle.TrimEnd();
            textBoxTranslatedEpisodeTitle.Text    = header.TranslatedEpisodeTitle.TrimEnd();
            textBoxTranslatorsName.Text           = header.TranslatorsName.TrimEnd();
            textBoxSubtitleListReferenceCode.Text = header.SubtitleListReferenceCode.TrimEnd();
            textBoxCountryOfOrigin.Text           = header.CountryOfOrigin;

            comboBoxTimeCodeStatus.SelectedIndex = 0;
            if (header.TimeCodeStatus == "1")
            {
                comboBoxTimeCodeStatus.SelectedIndex = 1;
            }
            try
            {
                // HHMMSSFF
                int hh = int.Parse(header.TimeCodeStartOfProgramme.Substring(0, 2));
                int mm = int.Parse(header.TimeCodeStartOfProgramme.Substring(2, 2));
                int ss = int.Parse(header.TimeCodeStartOfProgramme.Substring(4, 2));
                int ff = int.Parse(header.TimeCodeStartOfProgramme.Substring(6, 2));
                timeUpDownStartTime.TimeCode = new TimeCode(hh, mm, ss, SubtitleFormat.FramesToMillisecondsMax999(ff));
            }
            catch (Exception)
            {
                timeUpDownStartTime.TimeCode = new TimeCode(0);
            }

            int number;

            if (int.TryParse(header.RevisionNumber, out number))
            {
                numericUpDownRevisionNumber.Value = number;
            }
            else
            {
                numericUpDownRevisionNumber.Value = 1;
            }

            if (int.TryParse(header.MaximumNumberOfDisplayableCharactersInAnyTextRow, out number))
            {
                numericUpDownMaxCharacters.Value = number;
            }

            numericUpDownMaxRows.Value = 23;
            if (int.TryParse(header.MaximumNumberOfDisplayableRows, out number))
            {
                numericUpDownMaxRows.Value = number;
            }

            if (int.TryParse(header.DiskSequenceNumber, out number))
            {
                numericUpDownDiskSequenceNumber.Value = number;
            }
            else
            {
                numericUpDownDiskSequenceNumber.Value = 1;
            }
            if (int.TryParse(header.TotalNumberOfDisks, out number))
            {
                numericUpDownTotalNumberOfDiscs.Value = number;
            }
            else
            {
                numericUpDownTotalNumberOfDiscs.Value = 1;
            }
        }