public Paragraph Constructor(TimeCode startTime, TimeCode endTime, string text)
        {
            Paragraph target = new Paragraph(startTime, endTime, text);
            return target;

            // TODO: add assertions to method ParagraphTest.Constructor(TimeCode, TimeCode, String)
        }
Beispiel #2
0
 public Paragraph(TimeCode startTime, TimeCode endTime, string text)
 {
     StartTime = startTime;
     EndTime = endTime;
     Text = text;
     ID = Guid.NewGuid().ToString();
 }
        public void TimeCodeAddTime2()
        {
            var tc = new TimeCode(1000);
            tc.AddTime(-1000);

            Assert.AreEqual(tc.TotalMilliseconds, 0);
        }
        public void TimeCodeAddTime5()
        {
            var tc = new TimeCode(1000);
            tc.AddTime(0, 1, 0, 0);

            Assert.AreEqual(tc.TotalMilliseconds, 60000 + 1000);
        }
 public Paragraph(string text, double startTotalMilliseconds, double endTotalMilliseconds)
 {
     StartTime = new TimeCode(startTotalMilliseconds);
     EndTime = new TimeCode(endTotalMilliseconds);
     Text = text;
     Id = GenerateId();
 }
Beispiel #6
0
 public Paragraph(string text, double startTotalMilliseconds, double endTotalMilliseconds)
 {
     StartTime = new TimeCode(startTotalMilliseconds);
     EndTime = new TimeCode(endTotalMilliseconds);
     Text = text;
     ID = Guid.NewGuid().ToString();
 }
        public void TimeCodeGetTotalMilliseconds()
        {
            var tc = new TimeCode(1, 2, 3, 4);

            Assert.AreEqual(tc.TotalMilliseconds, 3723004);
            Assert.IsTrue(Math.Abs(tc.TotalMilliseconds -  (tc.TotalSeconds * 1000.0)) < 0.001);
        }
 public Paragraph(TimeCode startTime, TimeCode endTime, string text)
 {
     StartTime = startTime;
     EndTime = endTime;
     Text = text;
     Id = GenerateId();
 }
Beispiel #9
0
 public Paragraph()
 {
     StartTime = new TimeCode(TimeSpan.FromSeconds(0));
     EndTime = new TimeCode(TimeSpan.FromSeconds(0));
     Text = string.Empty;
     ID = Guid.NewGuid().ToString();
 }
        public void TimeCodeAddTime6()
        {
            var tc = new TimeCode(1000);
            tc.AddTime(TimeSpan.FromMilliseconds(1000));

            Assert.AreEqual(tc.TotalMilliseconds, 2000);
        }
 public Paragraph(int startFrame, int endFrame, string text)
 {
     StartTime = new TimeCode(0, 0, 0, 0);
     EndTime = new TimeCode(0, 0, 0, 0);
     StartFrame = startFrame;
     EndFrame = endFrame;
     Text = text;
     Id = GenerateId();
 }
Beispiel #12
0
 public Paragraph(int startFrame, int endFrame, string text)
 {
     StartTime = new TimeCode(0, 0, 0, 0);
     EndTime = new TimeCode(0, 0, 0, 0);
     StartFrame = startFrame;
     EndFrame = endFrame;
     Text = text;
     ID = Guid.NewGuid().ToString();
 }
Beispiel #13
0
 public Paragraph(Paragraph paragraph)
 {
     Number = paragraph.Number;
     Text = paragraph.Text;
     StartTime = new TimeCode(paragraph.StartTime.TimeSpan);
     EndTime = new TimeCode(paragraph.EndTime.TimeSpan);
     StartFrame = paragraph.StartFrame;
     EndFrame = paragraph.EndFrame;
     Forced = paragraph.Forced;
     Extra = paragraph.Extra;
     IsComment = paragraph.IsComment;
     Actor = paragraph.Actor;
     Effect = paragraph.Effect;
     Layer = paragraph.Layer;
     ID = paragraph.ID;
     Language = paragraph.Language;
     Style = paragraph.Style;
 }
 public Paragraph(Paragraph paragraph)
 {
     Number = paragraph.Number;
     Text = paragraph.Text;
     StartTime = new TimeCode(paragraph.StartTime.TotalMilliseconds);
     EndTime = new TimeCode(paragraph.EndTime.TotalMilliseconds);
     StartFrame = paragraph.StartFrame;
     EndFrame = paragraph.EndFrame;
     Forced = paragraph.Forced;
     Extra = paragraph.Extra;
     IsComment = paragraph.IsComment;
     Actor = paragraph.Actor;
     Effect = paragraph.Effect;
     Layer = paragraph.Layer;
     Id = GenerateId(); // Do not reuse unique ID
     Language = paragraph.Language;
     Style = paragraph.Style;
     NewSection = paragraph.NewSection;
 }
        private void listBoxTracks_SelectedIndexChanged(object sender, EventArgs e)
        {
            int idx = listBoxTracks.SelectedIndex;
            if (idx < 0)
                return;

            listBoxSubtitles.Items.Clear();
            int pid = _tsParser.SubtitlePacketIds[idx];
            var list = _tsParser.GetDvbSubtitles(pid);
            int i = 0;
            foreach (var sub in list)
            {
                i++;
                var start = new TimeCode(sub.StartMilliseconds);
                var end = new TimeCode(sub.EndMilliseconds);
                listBoxSubtitles.Items.Add(string.Format(Configuration.Settings.Language.TransportStreamSubtitleChooser.SubLine, i, start, end, sub.NumberOfImages));
            }
            if (list.Count > 0)
                listBoxSubtitles.SelectedIndex = 0;
        }
Beispiel #16
0
        internal void InitializeBatch(List<Nikse.SubtitleEdit.Logic.BluRaySup.BluRaySupParser.PcsData> subtitles, VobSubOcrSettings vobSubOcrSettings, string fileName)
        {
            Initialize(subtitles, vobSubOcrSettings, fileName);
            FormVobSubOcr_Shown(null, null);
            checkBoxPromptForUnknownWords.Checked = false;

            int max = GetSubtitleCount();
            if (comboBoxOcrMethod.SelectedIndex == 0 && _tesseractAsyncStrings == null)
            {
                _tesseractAsyncStrings = new string[max];
                _tesseractAsyncIndex = (int)numericUpDownStartNumber.Value + 5;
                _tesseractThread = new BackgroundWorker();
                _tesseractThread.DoWork += TesseractThreadDoWork;
                _tesseractThread.RunWorkerCompleted += TesseractThreadRunWorkerCompleted;
                _tesseractThread.WorkerSupportsCancellation = true;
                if (_tesseractAsyncIndex >= 0 && _tesseractAsyncIndex < max)
                    _tesseractThread.RunWorkerAsync(GetSubtitleBitmap(_tesseractAsyncIndex));
            }
            System.Threading.Thread.Sleep(1000);
            subtitleListView1.SelectedIndexChanged -= SubtitleListView1SelectedIndexChanged;
            for (int i = 0; i < max; i++)
            {
                var startTime = new TimeCode(TimeSpan.FromMilliseconds(GetSubtitleStartTimeMilliseconds(i)));
                var endTime = new TimeCode(TimeSpan.FromMilliseconds(GetSubtitleEndTimeMilliseconds(i)));
                Application.DoEvents();
                if (_abort)
                {
                    SetButtonsEnabledAfterOcrDone();
                    return;
                }

                subtitleListView1.SelectIndexAndEnsureVisible(i);
                string text = OcrViaTesseract(GetSubtitleBitmap(i), i);

                _lastLine = text;

                text = text.Replace("<i>-</i>", "-");
                text = text.Replace("<i>a</i>", "a");
                text = text.Replace("  ", " ");
                text = text.Trim();

                text = text.Replace(" " + Environment.NewLine, Environment.NewLine);
                text = text.Replace(Environment.NewLine + " ", Environment.NewLine);

                // max allow 2 lines
                if (checkBoxAutoBreakLines.Checked && text.Replace(Environment.NewLine, "*").Length + 2 <= text.Length)
                {
                    text = text.Replace(" " + Environment.NewLine, Environment.NewLine);
                    text = text.Replace(Environment.NewLine + " ", Environment.NewLine);
                    while (text.Contains(Environment.NewLine + Environment.NewLine))
                        text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);

                    if (text.Replace(Environment.NewLine, "*").Length + 2 <= text.Length)
                        text = Utilities.AutoBreakLine(text);
                }

                Application.DoEvents();
                if (_abort)
                {
                    textBoxCurrentText.Text = text;
                    SetButtonsEnabledAfterOcrDone();
                    return;
                }

                text = text.Trim();
                text = text.Replace("  ", " ");
                text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
                text = text.Replace("  ", " ");
                text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);

                Paragraph p = _subtitle.GetParagraphOrDefault(i);
                if (p != null)
                    p.Text = text;
                if (subtitleListView1.SelectedItems.Count == 1 && subtitleListView1.SelectedItems[0].Index == i)
                    textBoxCurrentText.Text = text;
                else
                    subtitleListView1.SetText(i, text);
            }
            SetButtonsEnabledAfterOcrDone();
        }
Beispiel #17
0
        private void LoadBluRaySubFromMatroska(MatroskaSubtitleInfo matroskaSubtitleInfo, string fileName)
        {
            if (matroskaSubtitleInfo.ContentEncodingType == 1)
            {
                MessageBox.Show("Encrypted vobsub content not supported");
            }

            bool isValid;
            var matroska = new Matroska();

            ShowStatus(_language.ParsingMatroskaFile);
            Refresh();
            Cursor.Current = Cursors.WaitCursor;
            List<SubtitleSequence> sub = matroska.GetMatroskaSubtitle(fileName, (int)matroskaSubtitleInfo.TrackNumber, out isValid, MatroskaProgress);
            Cursor.Current = Cursors.Default;
            int noOfErrors = 0;
            string lastError = string.Empty;

            if (isValid)
            {
                MakeHistoryForUndo(_language.BeforeImportFromMatroskaFile);
                _subtitleListViewIndex = -1;
                _subtitle.Paragraphs.Clear();
                var subtitles = new List<Nikse.SubtitleEdit.Logic.BluRaySup.BluRaySupParser.PcsData>();
                StringBuilder log = new StringBuilder();
                foreach (SubtitleSequence p in sub)
                {
                    byte[] buffer = null;
                    if (matroskaSubtitleInfo.ContentEncodingType == 0) // compressed with zlib
                    {
                        MemoryStream outStream = new MemoryStream();
                        ComponentAce.Compression.Libs.zlib.ZOutputStream outZStream = new ComponentAce.Compression.Libs.zlib.ZOutputStream(outStream);
                        MemoryStream inStream = new MemoryStream(p.BinaryData);
                        try
                        {
                            CopyStream(inStream, outZStream);
                            buffer = new byte[outZStream.TotalOut];
                            outStream.Position = 0;
                            outStream.Read(buffer, 0, buffer.Length);
                        }
                        catch (Exception exception)
                        {
                            TimeCode tc = new TimeCode(TimeSpan.FromMilliseconds(p.StartMilliseconds));
                            lastError = tc.ToString() + ": " + exception.Message + ": " + exception.StackTrace;
                            noOfErrors++;
                        }
                        finally
                        {
                            outStream.Close();
                            outZStream.Close();
                            inStream.Close();
                        }
                    }
                    else
                    {
                        buffer = p.BinaryData;
                    }
                    if (buffer != null && buffer.Length > 100)
                    {
                        MemoryStream ms = new MemoryStream(buffer);
                        var list = BluRaySupParser.ParseBluRaySup(ms, log, true);
                        foreach (var sup in list)
                        {
                            sup.StartTime = (long)((p.StartMilliseconds - 45) * 90.0);
                            sup.EndTime = (long)((p.EndMilliseconds - 45) * 90.0);
                            subtitles.Add(sup);

                            // fix overlapping
                            if (subtitles.Count > 1 && sub[subtitles.Count - 2].EndMilliseconds > sub[subtitles.Count - 1].StartMilliseconds)
                                subtitles[subtitles.Count - 2].EndTime = subtitles[subtitles.Count - 1].StartTime - 1;
                        }
                        ms.Close();
                    }
                }

                if (noOfErrors > 0)
                {
                    MessageBox.Show(string.Format("{0} errror(s) occured during extraction of bdsup\r\n\r\n{1}", noOfErrors, lastError));
                }

                var formSubOcr = new VobSubOcr();
                _formPositionsAndSizes.SetPositionAndSize(formSubOcr);
                formSubOcr.Initialize(subtitles, Configuration.Settings.VobSubOcr, fileName);
                if (_loading)
                {
                    formSubOcr.Icon = (Icon)this.Icon.Clone();
                    formSubOcr.ShowInTaskbar = true;
                    formSubOcr.ShowIcon = true;
                }
                if (formSubOcr.ShowDialog(this) == DialogResult.OK)
                {
                    MakeHistoryForUndo(_language.BeforeImportingDvdSubtitle);

                    _subtitle.Paragraphs.Clear();
                    SetCurrentFormat(Configuration.Settings.General.DefaultSubtitleFormat);
                    _subtitle.WasLoadedWithFrameNumbers = false;
                    _subtitle.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                    foreach (Paragraph p in formSubOcr.SubtitleFromOcr.Paragraphs)
                    {
                        _subtitle.Paragraphs.Add(p);
                    }

                    ShowSource();
                    SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
                    _subtitleListViewIndex = -1;
                    SubtitleListview1.FirstVisibleIndex = -1;
                    SubtitleListview1.SelectIndexAndEnsureVisible(0);

                    _fileName = string.Empty;
                    Text = Title;

                    Configuration.Settings.Save();
                }
                _formPositionsAndSizes.SavePositionAndSize(formSubOcr);
            }
        }
Beispiel #18
0
        private void TabControlSubtitleSelectedIndexChanged(object sender, EventArgs e)
        {
            var format = GetCurrentSubtitleFormat();
            if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
            {
                ShowSource();
                ShowSourceLineNumber();
                if (textBoxSource.CanFocus)
                    textBoxSource.Focus();

                // go to correct line in source view
                if (SubtitleListview1.SelectedItems.Count > 0)
                {
                    if (format.GetType() == typeof(SubRip))
                    {
                        Paragraph p = _subtitle.GetParagraphOrDefault(FirstSelectedIndex);
                        if (p != null)
                        {
                            string tc = p.StartTime.ToString() + " --> " + p.EndTime.ToString();
                            int start = textBoxSource.Text.IndexOf(tc);
                            if (start > 0)
                            {
                                textBoxSource.SelectionStart = start + tc.Length + Environment.NewLine.Length;
                                textBoxSource.SelectionLength = 0;
                                textBoxSource.ScrollToCaret();
                            }
                        }
                    }
                    else if (format.GetType() == typeof(SubStationAlpha) || format.GetType() == typeof(AdvancedSubStationAlpha))
                    {
                        Paragraph p = _subtitle.GetParagraphOrDefault(FirstSelectedIndex);
                        if (p != null)
                        {
                            const string timeCodeFormat = "{0}:{1:00}:{2:00}.{3:00}"; // h:mm:ss.cc
                            string startTC = string.Format(timeCodeFormat, p.StartTime.Hours, p.StartTime.Minutes, p.StartTime.Seconds, p.StartTime.Milliseconds / 10);
                            string endTC = string.Format(timeCodeFormat, p.EndTime.Hours, p.EndTime.Minutes, p.EndTime.Seconds, p.EndTime.Milliseconds / 10);
                            string tc = startTC + "," + endTC;
                            int start = textBoxSource.Text.IndexOf(tc);
                            if (start > 0)
                            {
                                int start2 = textBoxSource.Text.LastIndexOf("Dialogue:", start);
                                if (start2 > 0)
                                    start2 = (textBoxSource.Text + Environment.NewLine).IndexOf(Environment.NewLine, start2);
                                if (start2 > 0)
                                    start = start2;
                                textBoxSource.SelectionStart = start;
                                textBoxSource.SelectionLength = 0;
                                textBoxSource.ScrollToCaret();
                            }
                        }
                    }
                }
            }
            else
            {
                ReloadFromSourceView();
                ShowLineInformationListView();
                if (SubtitleListview1.CanFocus)
                    SubtitleListview1.Focus();

                // go to (select + focus) correct line in list view
                if (textBoxSource.SelectionStart > 0 && textBoxSource.TextLength > 30)
                {
                    if (format.GetType() == typeof(SubRip))
                    {
                        int pos = textBoxSource.SelectionStart;
                        if (pos + 35 < textBoxSource.TextLength)
                            pos += 35;
                        string s = textBoxSource.Text.Substring(0, pos);
                        int lastTimeCode = s.LastIndexOf(" --> "); // 00:02:26,407 --> 00:02:31,356
                        if (lastTimeCode > 14 && lastTimeCode + 16 >= s.Length)
                        {
                            s = s.Substring(0, lastTimeCode - 5);
                            lastTimeCode = s.LastIndexOf(" --> ");
                        }

                        if (lastTimeCode > 14 && lastTimeCode + 16 < s.Length)
                        {
                            string tc = s.Substring(lastTimeCode - 13, 30).Trim();
                            int index = 0;
                            foreach (Paragraph p in _subtitle.Paragraphs)
                            {
                                if (tc == p.StartTime.ToString() + " --> " + p.EndTime.ToString())
                                {
                                    SubtitleListview1.SelectIndexAndEnsureVisible(index, true);
                                    break;
                                }
                                index++;
                            }
                        }
                    }
                    else if (format.GetType() == typeof(SubStationAlpha) || format.GetType() == typeof(AdvancedSubStationAlpha))
                    {
                        int pos = textBoxSource.SelectionStart;
                        string s = textBoxSource.Text;
                        if (pos > 0)
                            pos--;
                        while (pos > 0 && pos + 3 < s.Length && !s.Substring(pos, 3).StartsWith(Environment.NewLine))
                            pos--;
                        s = s.Substring(pos).Trim();
                        int lastTimeCode = s.IndexOf("Dialogue:");


                        if (lastTimeCode >= 0)
                        {
                            string tc = s.Substring(lastTimeCode).Trim();
                            while (tc.Length > 0 && !Utilities.IsInteger(tc.Substring(0, 1)))
                                tc = tc.Remove(0, 1);
                            if (tc.Length > 12)
                            {
                                tc = tc.Substring(0, 13);
                                string[] timeCode = tc.Split(":.,".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
                                TimeCode realTC = new TimeCode(0, 0, 0, 0);
                                try
                                {
                                    realTC = new TimeCode(int.Parse(timeCode[1]), int.Parse(timeCode[2]), int.Parse(timeCode[3]), int.Parse(timeCode[4]) * 10);
                                }
                                catch
                                {
                                    SubtitleListview1.SelectIndexAndEnsureVisible(0, true);
                                    return;
                                }

                                int index = 0;
                                foreach (Paragraph p in _subtitle.Paragraphs)
                                {
                                    if (Math.Abs(realTC.TotalMilliseconds - p.StartTime.TotalMilliseconds) < 50)
                                    {
                                        SubtitleListview1.SelectIndexAndEnsureVisible(index, true);
                                        break;
                                    }
                                    index++;
                                }
                            }
                        }
                    }
                }
                else if (textBoxSource.SelectionStart == 0 && textBoxSource.TextLength > 30)
                {
                    SubtitleListview1.SelectIndexAndEnsureVisible(0, true);
                }
            }
        }
Beispiel #19
0
        private void UpdateOverlapErrors(TimeCode startTime)
        {
            labelStartTimeWarning.Text = string.Empty;
            labelDurationWarning.Text = string.Empty;
            if (_subtitle.Paragraphs.Count > 0 && SubtitleListview1.SelectedItems.Count > 0 && startTime != null)
            {

                int firstSelectedIndex = SubtitleListview1.SelectedItems[0].Index;

                Paragraph prevParagraph = _subtitle.GetParagraphOrDefault(firstSelectedIndex - 1);
                if (prevParagraph != null && prevParagraph.EndTime.TotalMilliseconds > startTime.TotalMilliseconds && Configuration.Settings.Tools.ListViewSyntaxColorOverlap)
                    labelStartTimeWarning.Text = string.Format(_languageGeneral.OverlapPreviousLineX, prevParagraph.EndTime.TotalSeconds - startTime.TotalSeconds);

                Paragraph nextParagraph = _subtitle.GetParagraphOrDefault(firstSelectedIndex + 1);
                if (nextParagraph != null)
                {
                    double durationMilliSeconds = GetDurationInMilliseconds();
                    if (startTime.TotalMilliseconds + durationMilliSeconds > nextParagraph.StartTime.TotalMilliseconds && Configuration.Settings.Tools.ListViewSyntaxColorOverlap)
                    {
                        labelDurationWarning.Text = string.Format(_languageGeneral.OverlapX, ((startTime.TotalMilliseconds + durationMilliSeconds) - nextParagraph.StartTime.TotalMilliseconds) / 1000.0);
                    }

                    if (labelStartTimeWarning.Text.Length == 0 &&
                        startTime.TotalMilliseconds > nextParagraph.StartTime.TotalMilliseconds && Configuration.Settings.Tools.ListViewSyntaxColorOverlap)
                    {
                        double di = (startTime.TotalMilliseconds - nextParagraph.StartTime.TotalMilliseconds) / 1000.0;
                        labelStartTimeWarning.Text = string.Format(_languageGeneral.OverlapNextX, di);
                    }
                    else if (numericUpDownDuration.Value < 0)
                    {
                        labelDurationWarning.Text = _languageGeneral.Negative;
                    }
                }
            }
        }
Beispiel #20
0
        private void UpdateStartTimeInfo(TimeCode startTime)
        {
            if (_subtitle.Paragraphs.Count > 0 && SubtitleListview1.SelectedItems.Count > 0 && startTime != null)
            {
                UpdateOverlapErrors(startTime);

                // update _subtitle + listview
                Paragraph p = _subtitle.Paragraphs[_subtitleListViewIndex];
                p.EndTime.TotalMilliseconds += (startTime.TotalMilliseconds - p.StartTime.TotalMilliseconds);
                p.StartTime = startTime;
                SubtitleListview1.SetStartTime(_subtitleListViewIndex, p);
                if (GetCurrentSubtitleFormat().IsFrameBased)
                {
                    p.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                    p.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
                }

                StartUpdateListSyntaxColoring();
            }
        }
Beispiel #21
0
        public void SetCurrentViaEndPositionAndGotoNext(int index)
        {
            Paragraph p = _subtitle.GetParagraphOrDefault(index);
            if (p == null)
                return;

            if (mediaPlayer.VideoPlayer == null || string.IsNullOrEmpty(_videoFileName))
            {
                MessageBox.Show(Configuration.Settings.Language.General.NoVideoLoaded);
                return;
            }

            //if (autoDuration)
            //{
            //    //TODO: auto duration
            //    //TODO: search for start via wave file (must only be minor adjustment)
            //}

            // current movie pos
            double durationTotalMilliseconds = p.Duration.TotalMilliseconds;
            double totalMillisecondsEnd = mediaPlayer.CurrentPosition * 1000.0;

            var tc = new TimeCode(TimeSpan.FromMilliseconds(totalMillisecondsEnd - durationTotalMilliseconds));
            MakeHistoryForUndo(_language.BeforeSetEndAndVideoPosition + "  " + tc.ToString());
            _makeHistoryPaused = true;

            if (p.StartTime.IsMaxTime)
            {
                p.EndTime.TotalSeconds = mediaPlayer.CurrentPosition;
                p.StartTime.TotalMilliseconds = p.EndTime.TotalMilliseconds - Utilities.GetOptimalDisplayMilliseconds(p.Text);
            }
            else
            {
                p.StartTime.TotalMilliseconds = totalMillisecondsEnd - durationTotalMilliseconds;
                p.EndTime.TotalMilliseconds = totalMillisecondsEnd;
            }

            timeUpDownStartTime.TimeCode = p.StartTime;
            var durationInSeconds = (decimal)(p.Duration.TotalSeconds);
            if (durationInSeconds >= numericUpDownDuration.Minimum && durationInSeconds <= numericUpDownDuration.Maximum)
                SetDurationInSeconds((double)durationInSeconds);

            SubtitleListview1.SelectIndexAndEnsureVisible(index+1);
            ShowStatus(string.Format(_language.VideoControls.AdjustedViaEndTime, p.StartTime.ToShortString()));
            audioVisualizer.Invalidate();
            _makeHistoryPaused = false;
        }
Beispiel #22
0
        private void ButtonSetStartAndOffsetRestClick(object sender, EventArgs e)
        {
            if (SubtitleListview1.SelectedItems.Count == 1)
            {
                bool oldSync = checkBoxSyncListViewWithVideoWhilePlaying.Checked;
                checkBoxSyncListViewWithVideoWhilePlaying.Checked = false;

                timeUpDownStartTime.MaskedTextBox.TextChanged -= MaskedTextBoxTextChanged;
                int index = SubtitleListview1.SelectedItems[0].Index;
                double videoPosition = mediaPlayer.CurrentPosition;
                if (!mediaPlayer.IsPaused)
                    videoPosition -= Configuration.Settings.General.SetStartEndHumanDelay / 1000.0;
                var tc = new TimeCode(TimeSpan.FromSeconds(videoPosition));
                timeUpDownStartTime.TimeCode = tc;

                MakeHistoryForUndo(_language.BeforeSetStartTimeAndOffsetTheRest + "  " +_subtitle.Paragraphs[index].Number.ToString() + " - " + tc.ToString());

                double offset = _subtitle.Paragraphs[index].StartTime.TotalMilliseconds - tc.TotalMilliseconds;

                if (_subtitle.Paragraphs[index].StartTime.IsMaxTime)
                {
                    _subtitle.Paragraphs[index].StartTime.TotalSeconds = videoPosition;
                    _subtitle.Paragraphs[index].EndTime.TotalMilliseconds = _subtitle.Paragraphs[index].StartTime.TotalMilliseconds + Utilities.GetOptimalDisplayMilliseconds(_subtitle.Paragraphs[index].Text);
                    SubtitleListview1.SetStartTime(index, _subtitle.Paragraphs[index]);
                    checkBoxSyncListViewWithVideoWhilePlaying.Checked = oldSync;
                    timeUpDownStartTime.MaskedTextBox.TextChanged += MaskedTextBoxTextChanged;
                    return;
                }

                _subtitle.Paragraphs[index].StartTime = new TimeCode(TimeSpan.FromMilliseconds(_subtitle.Paragraphs[index].StartTime.TotalMilliseconds - offset));
                _subtitle.Paragraphs[index].EndTime = new TimeCode(TimeSpan.FromMilliseconds(_subtitle.Paragraphs[index].EndTime.TotalMilliseconds - offset));
                SubtitleListview1.SetStartTime(index, _subtitle.Paragraphs[index]);

                for (int i = index+1; i < SubtitleListview1.Items.Count; i++)
                {
                    if (!_subtitle.Paragraphs[i].StartTime.IsMaxTime)
                    {
                        _subtitle.Paragraphs[i].StartTime = new TimeCode(TimeSpan.FromMilliseconds(_subtitle.Paragraphs[i].StartTime.TotalMilliseconds - offset));
                        _subtitle.Paragraphs[i].EndTime = new TimeCode(TimeSpan.FromMilliseconds(_subtitle.Paragraphs[i].EndTime.TotalMilliseconds - offset));
                        SubtitleListview1.SetStartTime(i, _subtitle.Paragraphs[i]);
                    }
                }

                if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
                {
                    Paragraph original = Utilities.GetOriginalParagraph(index, _subtitle.Paragraphs[index], _subtitleAlternate.Paragraphs);
                    if (original != null)
                    {
                        index = _subtitleAlternate.GetIndex(original);
                        for (int i = index; i < _subtitleAlternate.Paragraphs.Count; i++)
                        {
                            if (!_subtitleAlternate.Paragraphs[i].StartTime.IsMaxTime)
                            {
                                _subtitleAlternate.Paragraphs[i].StartTime = new TimeCode(TimeSpan.FromMilliseconds(_subtitleAlternate.Paragraphs[i].StartTime.TotalMilliseconds - offset));
                                _subtitleAlternate.Paragraphs[i].EndTime = new TimeCode(TimeSpan.FromMilliseconds(_subtitleAlternate.Paragraphs[i].EndTime.TotalMilliseconds - offset));
                            }
                        }
                    }
                }
                if (IsFramesRelevant && CurrentFrameRate > 0)
                {
                    _subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate);
                    if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
                        ShowSource();
                }

                checkBoxSyncListViewWithVideoWhilePlaying.Checked = oldSync;
                timeUpDownStartTime.MaskedTextBox.TextChanged += MaskedTextBoxTextChanged;
            }
        }
Beispiel #23
0
        public void ShowEarlierOrLater(double adjustMilliseconds, SelectionChoice selection)
        {
            TimeCode tc = new TimeCode(TimeSpan.FromMilliseconds(adjustMilliseconds));
            MakeHistoryForUndo(_language.BeforeShowSelectedLinesEarlierLater  + ": " + tc.ToString());
            if (adjustMilliseconds < 0)
            {
                if (selection == SelectionChoice.AllLines)
                    ShowStatus(string.Format(_language.ShowAllLinesXSecondsLinesEarlier, adjustMilliseconds / -1000.0));
                else if (selection == SelectionChoice.SelectionOnly)
                    ShowStatus(string.Format(_language.ShowSelectedLinesXSecondsLinesEarlier, adjustMilliseconds / -1000.0));
                else if (selection == SelectionChoice.SelectionAndForward)
                    ShowStatus(string.Format(_language.ShowSelectionAndForwardXSecondsLinesEarlier, adjustMilliseconds / -1000.0));
            }
            else
            {
                if (selection == SelectionChoice.AllLines)
                    ShowStatus(string.Format(_language.ShowAllLinesXSecondsLinesLater, adjustMilliseconds / 1000.0));
                else if (selection == SelectionChoice.SelectionOnly)
                    ShowStatus(string.Format(_language.ShowSelectedLinesXSecondsLinesLater, adjustMilliseconds / 1000.0));
                else if (selection == SelectionChoice.SelectionAndForward)
                    ShowStatus(string.Format(_language.ShowSelectionAndForwardXSecondsLinesLater, adjustMilliseconds / 1000.0));
            }

            double frameRate = CurrentFrameRate;
            SubtitleListview1.BeginUpdate();

            int startFrom = 0;
            if (selection == SelectionChoice.SelectionAndForward)
            {
                if (SubtitleListview1.SelectedItems.Count > 0)
                    startFrom = SubtitleListview1.SelectedItems[0].Index;
                else
                    startFrom = _subtitle.Paragraphs.Count;
            }

            for (int i = startFrom; i < _subtitle.Paragraphs.Count; i++)
            {
                switch (selection)
                {
                    case SelectionChoice.SelectionOnly:
                        if (SubtitleListview1.Items[i].Selected)
                            ShowEarlierOrLaterParagraph(adjustMilliseconds, i);
                        break;
                    case SelectionChoice.AllLines:
                        ShowEarlierOrLaterParagraph(adjustMilliseconds, i);
                        break;
                    case SelectionChoice.SelectionAndForward:
                        ShowEarlierOrLaterParagraph(adjustMilliseconds, i);
                        break;
                }
            }

            SubtitleListview1.EndUpdate();
            if (_subtitle.WasLoadedWithFrameNumbers)
                _subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(frameRate);
            RefreshSelectedParagraph();
            UpdateSourceView();
            UpdateListSyntaxColoring();
        }
Beispiel #24
0
        private Paragraph InsertNewTextAtVideoPosition()
        {
            // current movie pos
            double videoPositionInMilliseconds = mediaPlayer.CurrentPosition * 1000.0;
            if (!mediaPlayer.IsPaused)
                videoPositionInMilliseconds -= Configuration.Settings.General.SetStartEndHumanDelay;

            var tc = new TimeCode(TimeSpan.FromMilliseconds(videoPositionInMilliseconds));
            MakeHistoryForUndo(_language.BeforeInsertSubtitleAtVideoPosition + "  " + tc.ToString());

            // find index where to insert
            int index = 0;
            foreach (Paragraph p in _subtitle.Paragraphs)
            {
                if (p.StartTime.TotalMilliseconds > videoPositionInMilliseconds)
                    break;
                index++;
            }

            // create and insert
            var newParagraph = new Paragraph("", videoPositionInMilliseconds, videoPositionInMilliseconds + Configuration.Settings.General.NewEmptyDefaultMs);
            if (GetCurrentSubtitleFormat().IsFrameBased)
            {
                newParagraph.CalculateFrameNumbersFromTimeCodes(CurrentFrameRate);
                newParagraph.CalculateTimeCodesFromFrameNumbers(CurrentFrameRate);
            }

            if (_networkSession != null)
            {
                _networkSession.TimerStop();
                NetworkGetSendUpdates(new List<int>(), index, newParagraph);
            }
            else
            {
                _subtitle.Paragraphs.Insert(index, newParagraph);

                // check if original is available - and insert new paragraph in the original too
                if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
                {
                    _subtitleAlternate.InsertParagraphInCorrectTimeOrder(new Paragraph(newParagraph));
                    _subtitleAlternate.Renumber(1);
                }

                _subtitleListViewIndex = -1;
                _subtitle.Renumber(1);
                SubtitleListview1.Fill(_subtitle, _subtitleAlternate);
            }
            SubtitleListview1.SelectIndexAndEnsureVisible(index);
            return newParagraph;
        }
Beispiel #25
0
        private void SetEndAndOffsetTheRest(bool goToNext)
        {
            if (SubtitleListview1.SelectedItems.Count == 1)
            {
                bool oldSync = checkBoxSyncListViewWithVideoWhilePlaying.Checked;
                checkBoxSyncListViewWithVideoWhilePlaying.Checked = false;

                int index = SubtitleListview1.SelectedItems[0].Index;
                double videoPosition = mediaPlayer.CurrentPosition;
                if (!mediaPlayer.IsPaused)
                    videoPosition -= Configuration.Settings.General.SetStartEndHumanDelay / 1000.0;

                var tc = new TimeCode(TimeSpan.FromSeconds(videoPosition));

                double offset = tc.TotalMilliseconds - _subtitle.Paragraphs[index].EndTime.TotalMilliseconds;
                if (_subtitle.Paragraphs[index].StartTime.TotalMilliseconds + 100 > tc.TotalMilliseconds || offset > Configuration.Settings.General.SubtitleMaximumDisplayMilliseconds)
                    return;

                MakeHistoryForUndo(_language.BeforeSetEndTimeAndOffsetTheRest + "  " + _subtitle.Paragraphs[index].Number.ToString() + " - " + tc.ToString());

                numericUpDownDuration.ValueChanged -= NumericUpDownDurationValueChanged;
                _subtitle.Paragraphs[index].EndTime.TotalSeconds = videoPosition;
                SubtitleListview1.SetDuration(index, _subtitle.Paragraphs[index]);
                checkBoxSyncListViewWithVideoWhilePlaying.Checked = oldSync;
                numericUpDownDuration.Value = (decimal)_subtitle.Paragraphs[index].Duration.TotalSeconds;
                numericUpDownDuration.ValueChanged += NumericUpDownDurationValueChanged;

                for (int i = index + 1; i < SubtitleListview1.Items.Count; i++)
                {
                    if (!_subtitle.Paragraphs[i].StartTime.IsMaxTime)
                    {
                        _subtitle.Paragraphs[i].StartTime = new TimeCode(TimeSpan.FromMilliseconds(_subtitle.Paragraphs[i].StartTime.TotalMilliseconds + offset));
                        _subtitle.Paragraphs[i].EndTime = new TimeCode(TimeSpan.FromMilliseconds(_subtitle.Paragraphs[i].EndTime.TotalMilliseconds + offset));
                        SubtitleListview1.SetDuration(i, _subtitle.Paragraphs[i]);
                    }
                }

                if (Configuration.Settings.General.AllowEditOfOriginalSubtitle && _subtitleAlternate != null && _subtitleAlternate.Paragraphs.Count > 0)
                {
                    Paragraph original = Utilities.GetOriginalParagraph(index, _subtitle.Paragraphs[index], _subtitleAlternate.Paragraphs);
                    if (original != null)
                    {
                        index = _subtitleAlternate.GetIndex(original);
                        for (int i = index; i < _subtitleAlternate.Paragraphs.Count; i++)
                        {
                            if (!_subtitleAlternate.Paragraphs[i].StartTime.IsMaxTime)
                            {
                                _subtitleAlternate.Paragraphs[i].StartTime = new TimeCode(TimeSpan.FromMilliseconds(_subtitleAlternate.Paragraphs[i].StartTime.TotalMilliseconds + offset));
                                _subtitleAlternate.Paragraphs[i].EndTime = new TimeCode(TimeSpan.FromMilliseconds(_subtitleAlternate.Paragraphs[i].EndTime.TotalMilliseconds + offset));
                            }
                        }
                    }
                }
                if (IsFramesRelevant && CurrentFrameRate > 0)
                {
                    _subtitle.CalculateFrameNumbersFromTimeCodesNoCheck(CurrentFrameRate);
                    if (tabControlSubtitle.SelectedIndex == TabControlSourceView)
                        ShowSource();
                }

                checkBoxSyncListViewWithVideoWhilePlaying.Checked = oldSync;
                numericUpDownDuration.ValueChanged += NumericUpDownDurationValueChanged;

                if (goToNext)
                {
                    SubtitleListview1.SelectIndexAndEnsureVisible(index + 1);
                }
            }
        }
Beispiel #26
0
 public void SetTotalMilliseconds(double milliseconds)
 {
     if (Mode == TimeMode.HHMMSSMS)
     {
         if (Mode == TimeMode.HHMMSSMS && milliseconds < 0)
             maskedTextBox1.Mask = "-00:00:00.000";
         else
             maskedTextBox1.Mask = "00:00:00.000";
         maskedTextBox1.Text = new TimeCode(milliseconds).ToString();
     }
     else
     {
         var tc = new TimeCode(milliseconds);
         maskedTextBox1.Text = tc.ToString().Substring(0, 9) + string.Format("{0:00}", Logic.SubtitleFormats.SubtitleFormat.MillisecondsToFrames(tc.Milliseconds));
     }
 }
Beispiel #27
0
        private void MakeAnimation()
        {
            _animation = new List<Paragraph>();
            double duration = _paragraph.Duration.TotalMilliseconds - ((double)numericUpDownDelay.Value * 1000.0);
            double stepsLength = CalculateStepLength(_paragraph.Text, duration);

            double startMilliseconds;
            double endMilliseconds;
            TimeCode start;
            TimeCode end;
            int index = 0;
            string text = string.Empty;
            bool tagOn = false;
            string tag = string.Empty;
            int i = 0;
            string startFontTag = string.Format("<font color=\"{0}\">", Utilities.ColorToHex(panelColor.BackColor));
            const string endFontTag = "</font>";
            while (i < _paragraph.Text.Length)
            {
                if (tagOn)
                {
                    if (_paragraph.Text[i] == '>')
                        tagOn = false;
                    tag += _paragraph.Text[i];
                }
                else if (_paragraph.Text[i] == '<')
                {
                    tagOn = true;
                    tag += _paragraph.Text[i];
                }
                else
                {
                    text += tag + _paragraph.Text[i];
                    tag = string.Empty;

                    //end tag
                    if (i + 2 < _paragraph.Text.Length &&
                        _paragraph.Text[i + 1] == '<' &&
                        _paragraph.Text[i + 2] == '/')
                    {
                        while (i < _paragraph.Text.Length && _paragraph.Text[i] != '>')
                        {
                            tag += _paragraph.Text[i];
                            i++;
                        }
                        text += tag;
                    }

                    string tempText = startFontTag + text + endFontTag;
                    if (i + 1 < _paragraph.Text.Length)
                        tempText += _paragraph.Text.Substring(i + 1);

                    startMilliseconds = index * stepsLength;
                    startMilliseconds += _paragraph.StartTime.TotalMilliseconds;
                    endMilliseconds = ((index + 1) * stepsLength) - 1;
                    endMilliseconds += _paragraph.StartTime.TotalMilliseconds;
                    start = new TimeCode(startMilliseconds);
                    end = new TimeCode(endMilliseconds);
                    _animation.Add(new Paragraph(start, end, tempText));
                    index++;
                }
                i++;
            }

            if (numericUpDownDelay.Value > 0)
            {
                startMilliseconds = index * stepsLength;
                startMilliseconds += _paragraph.StartTime.TotalMilliseconds;
                endMilliseconds = _paragraph.EndTime.TotalMilliseconds;
                start = new TimeCode(startMilliseconds);
                end = new TimeCode(endMilliseconds);
                _animation.Add(new Paragraph(start, end, startFontTag + _paragraph.Text + endFontTag));
            }
            else if (_animation.Count > 0)
            {
                _animation[_animation.Count - 1].EndTime.TotalMilliseconds = _paragraph.EndTime.TotalMilliseconds;
            }
        }
Beispiel #28
0
        private bool MainLoop(int max, int i)
        {
            if (i >= max)
            {
                SetButtonsEnabledAfterOcrDone();
                _mainOcrRunning = false;
                return true;
            }

            var bmp = ShowSubtitleImage(i);
            var startTime = new TimeCode(TimeSpan.FromMilliseconds(GetSubtitleStartTimeMilliseconds(i)));
            var endTime = new TimeCode(TimeSpan.FromMilliseconds(GetSubtitleEndTimeMilliseconds(i)));
            labelStatus.Text = string.Format("{0} / {1}: {2} - {3}", i + 1, max, startTime, endTime);
            progressBar1.Value = i + 1;
            labelStatus.Refresh();
            progressBar1.Refresh();
            if (_abort)
            {
                SetButtonsEnabledAfterOcrDone();
                _mainOcrRunning = false;
                return true;
            }

            _mainOcrBitmap = bmp;

            int j = i;
            subtitleListView1.Items[j].Selected = true;
            if (j < max -1)
                j++;
            if (j < max - 1)
                j++;
            subtitleListView1.Items[j].EnsureVisible();

            string text = string.Empty;
            if (comboBoxOcrMethod.SelectedIndex == 0)
                text = OcrViaTesseract(bmp, i);
            else if (comboBoxOcrMethod.SelectedIndex == 1)
                text = SplitAndOcrBitmapNormal(bmp, i);
            else if (comboBoxOcrMethod.SelectedIndex == 2)
                text = CallModi(i);
            else if (comboBoxOcrMethod.SelectedIndex == 3)
                text = OcrViaNOCR(bmp, i);
            else if (comboBoxOcrMethod.SelectedIndex == 4)
                text = SplitAndOcrBitmapNormalNew(bmp, i);

            _lastLine = text;

            text = text.Replace("<i>-</i>", "-");
            text = text.Replace("<i>a</i>", "a");
            text = text.Replace("<i>.</i>", ".");
            text = text.Replace("  ", " ");
            text = text.Trim();

            text = text.Replace(" " + Environment.NewLine, Environment.NewLine);
            text = text.Replace(Environment.NewLine + " ", Environment.NewLine);

            // max allow 2 lines
            if (checkBoxAutoBreakLines.Checked && text.Replace(Environment.NewLine, "*").Length + 2 <= text.Length)
            {
                text = text.Replace(" " + Environment.NewLine, Environment.NewLine);
                text = text.Replace(Environment.NewLine + " ", Environment.NewLine);
                while (text.Contains(Environment.NewLine + Environment.NewLine))
                    text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);

                if (text.Replace(Environment.NewLine, "*").Length + 2 <= text.Length)
                    text = Utilities.AutoBreakLine(text);
            }

            if (_dvbSubtitles != null && checkBoxTransportStreamGetColorAndSplit.Checked)
            {
                text = Utilities.UnbreakLine(text);
                if (_dvbSubColor != Color.Transparent)
                    text = "<font color=\"" + ColorTranslator.ToHtml(_dvbSubColor) + "\">" + text + "</font>";
            }

            if (_abort)
            {
                textBoxCurrentText.Text = text;
                _mainOcrRunning = false;
                SetButtonsEnabledAfterOcrDone();
                _nocrThreadsStop = true;
                _icThreadsStop = true;
                return true;
            }

            text = text.Trim();
            text = text.Replace("  ", " ");
            text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);
            text = text.Replace("  ", " ");
            text = text.Replace(Environment.NewLine + Environment.NewLine, Environment.NewLine);

            Paragraph p = _subtitle.GetParagraphOrDefault(i);
            if (p != null)
                p.Text = text;
            if (subtitleListView1.SelectedItems.Count == 1 && subtitleListView1.SelectedItems[0].Index == i)
                textBoxCurrentText.Text = text;
            else
                subtitleListView1.SetText(i, text);

            return false;
        }
 private void ShowTotalAdjustMent()
 {
     TimeCode tc = new TimeCode(_totalAdjustment);
     labelTotalAdjustment.Text = string.Format(Configuration.Settings.Language.ShowEarlierLater.TotalAdjustmentX, tc.ToShortString());
 }
        internal static string GetParagraph(string template, string start, string end, string text, string translation, int number, TimeCode duration, string timeCodeTemplate)
        {
            string d = duration.ToString();
            if (timeCodeTemplate == "ff" || timeCodeTemplate == "f")
                d = SubtitleFormat.MillisecondsToFrames(duration.TotalMilliseconds).ToString();
            if (timeCodeTemplate == "zzz" || timeCodeTemplate == "zz" || timeCodeTemplate == "z")
                d = duration.TotalMilliseconds.ToString();
            if (timeCodeTemplate == "sss" || timeCodeTemplate == "ss" || timeCodeTemplate == "s")
                d = duration.Seconds.ToString();
            else if (timeCodeTemplate.EndsWith("ss.ff"))
                d = string.Format("{0:00}.{1:00}", duration.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(duration.Milliseconds));
            else if (timeCodeTemplate.EndsWith("ss:ff"))
                d = string.Format("{0:00}:{1:00}", duration.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(duration.Milliseconds));
            else if (timeCodeTemplate.EndsWith("ss,ff"))
                d = string.Format("{0:00},{1:00}", duration.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(duration.Milliseconds));
            else if (timeCodeTemplate.EndsWith("ss;ff"))
                d = string.Format("{0:00};{1:00}", duration.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(duration.Milliseconds));
            else if (timeCodeTemplate.EndsWith("ss;ff"))
                d = string.Format("{0:00};{1:00}", duration.Seconds, SubtitleFormat.MillisecondsToFramesMaxFrameRate(duration.Milliseconds));
            else if (timeCodeTemplate.EndsWith("ss.zzz"))
                d = string.Format("{0:00}.{1:000}", duration.Seconds, duration.Milliseconds);
            else if (timeCodeTemplate.EndsWith("ss:zzz"))
                d = string.Format("{0:00}:{1:000}", duration.Seconds, duration.Milliseconds);
            else if (timeCodeTemplate.EndsWith("ss,zzz"))
                d = string.Format("{0:00},{1:000}", duration.Seconds, duration.Milliseconds);
            else if (timeCodeTemplate.EndsWith("ss;zzz"))
                d = string.Format("{0:00};{1:000}", duration.Seconds, duration.Milliseconds);
            else if (timeCodeTemplate.EndsWith("ss;zzz"))
                d = string.Format("{0:00};{1:000}", duration.Seconds, duration.Milliseconds);
            else if (timeCodeTemplate.EndsWith("ss.zz"))
                d = string.Format("{0:00}.{1:00}", duration.Seconds, Math.Round(duration.Milliseconds / 10.0));
            else if (timeCodeTemplate.EndsWith("ss:zz"))
                d = string.Format("{0:00}:{1:00}", duration.Seconds, Math.Round(duration.Milliseconds / 10.0));
            else if (timeCodeTemplate.EndsWith("ss,zz"))
                d = string.Format("{0:00},{1:00}", duration.Seconds, Math.Round(duration.Milliseconds / 10.0));
            else if (timeCodeTemplate.EndsWith("ss;zz"))
                d = string.Format("{0:00};{1:00}", duration.Seconds, Math.Round(duration.Milliseconds / 10.0));

            string s = template;
            s = s.Replace("{{", "@@@@_@@@{");
            s = s.Replace("}}", "}@@@_@@@@");
            s = string.Format(s, start, end, text, translation, number + 1, number, d);
            s = s.Replace("@@@@_@@@", "{");
            s = s.Replace("@@@_@@@@", "}");
            return s;
        }