Example #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            if (radioSuma.Checked) tOps = "+";
            else tOps = "-";

            string s = timeText.Text;

            if (radioFrames.Checked)
            {
                int f;
                try
                {
                    f = int.Parse(numericFrames.Text);
                    if (mW.videoInfo.FrameRate == 0) throw new Exception();
                }
                catch
                {
                    mW.errorMsg("Introduce un valor de frames válido y vuélvelo a intentar.");
                    return;
                }
                double sd = (double)Math.Round(f * ((double)1/(double)mW.videoInfo.FrameRate),2);
                Tiempo t = new Tiempo(sd);
                s = t.ToString();
            }

            if (radioSeleccionadas.Checked)
            {
                mW.doShift(tOps + s, ShiftStyle.Selected);
                mW.updateReplaceConfigFile("shiftW_style", "sel");
            }
            else if (radioTodas.Checked)
            {
                mW.doShift(tOps + s, ShiftStyle.Normal);
                mW.updateReplaceConfigFile("shiftW_style", "all");
            }
            else if (radioAnteriores.Checked)
            {
                mW.doShift(tOps + s, ShiftStyle.BeforeSelected);
                mW.updateReplaceConfigFile("shiftW_style", "bef");
            }
            else if (radioPosteriores.Checked)
            {
                mW.doShift(tOps + s, ShiftStyle.AfterSelected);
                mW.updateReplaceConfigFile("shiftW_style", "aft");
            }

            mW.updateConcatenateConfigFile("shiftW_old", tOps + s);

            this.Dispose();
        }
Example #2
0
        public void LoadFromFile(string filename)
        {
            FileName = filename;
            FileInfo info = new FileInfo(FileName);
            if (!info.Exists)
                throw new FileNotFoundException();
            ScriptFileType type = ScriptFileType.Unknown;

            switch (info.Extension.ToLower())
            {
                case ".ass":
                case ".ssa":
                case ".autosave":
                    type = ScriptFileType.ASS_SSA;
                    break;
                case ".srt":
                    type = ScriptFileType.SRT;
                    break;
                case ".txt":
                    type = ScriptFileType.TXT;
                    break;
                default:
                    type = ScriptFileType.Unknown;
                    break;
            }

            if (type == ScriptFileType.Unknown)
                throw new PerrySubException("Tipo de archivo desconocido");

            ResetScript();

            StreamReader sr = FileAccessWrapper.OpenTextFile(FileName);

            ArrayList head = Header.GetHeaderList();

            bool reachEOH = false;
            Tiempo ianterior = null;
            Tiempo fanterior = null;

            string linea = "";
            string pj = "";
            int i = 0;

            bool isGraphic = false;
            bool isFont = false;
            string gfx = ""; string gfx_name = "";
            string fnt = ""; string fnt_name = "";

            while ((linea = sr.ReadLine()) != null)
            {
                switch (type)
                {
                    case ScriptFileType.ASS_SSA:
                        if (linea.ToLower().StartsWith("[v4")) reachEOH = true;
                        if (!linea.ToLower().Equals("[script info]") && !reachEOH)
                        {
                            if (!linea.StartsWith("; "))
                                if (linea.IndexOf(": ") != -1)
                                    head.Add(linea);
                        }

                        if (linea.ToLower().StartsWith("style:"))
                            Styles.Add(new estiloV4(linea));

                        if (linea.ToLower().StartsWith("dialogue") || linea.ToLower().StartsWith("comment"))
                        {
                            try
                            {
                                Lines.Add(new lineaASS(linea));
                            }
                            catch (LineException le)
                            {
                                System.Windows.Forms.MessageBox.Show("Detectada excepción en una línea\n" + le.Message, mainW.appTitle, System.Windows.Forms.MessageBoxButtons.OK, System.Windows.Forms.MessageBoxIcon.Error);
                            }
                        }

                        // aqui tenemos que ver si hay attachments, y cargarlos si toca

                        if (isGraphic)
                        {
                            if (linea.Equals(""))
                            {
                                Attachments.InsertGraphic(gfx_name, gfx);
                                isGraphic = false;
                                gfx = "";
                                break;
                            }
                            gfx += linea+"\r\n";
                        }

                        if (isFont)
                        {
                            if (linea.Equals(""))
                            {
                                Attachments.InsertFont(fnt_name, fnt);
                                isFont = false;
                                fnt = "";
                                break;
                            }
                            fnt += linea+"\r\n";
                        }

                        if (linea.ToLower().StartsWith("filename:")) // [Graphics]
                        {
                            isGraphic = true;
                            gfx_name = linea.Substring(linea.IndexOf(':') + 1).Trim();
                        }

                        if (linea.ToLower().StartsWith("fontname:")) // [Fonts]
                        {
                            isFont = true;
                            fnt_name = linea.Substring(linea.IndexOf(':') + 1).Trim();
                        }

                        break;

                    case ScriptFileType.TXT:

                        // 1- nueva cabecera (luego)
                        // 2- estilo default (luego)
                        // 3- lineas

                        linea = linea.Replace("\t", "");
                        int idx = linea.IndexOf(":");
                        if (idx > 0)
                        {
                            pj = linea.Substring(0, idx).Trim();
                            linea = linea.Substring(idx + 1, linea.Length - (idx + 1)).Trim();
                        }
                        lineaASS telameto = new lineaASS();
                        telameto.texto = linea;
                        telameto.personaje = pj;
                        Lines.Add(telameto);
                        break;

                    case ScriptFileType.SRT:
                        //int moddy = i % 4;

                        if (i == 1)
                        {
                            string[] tiempos = linea.Split(new string[] { "-->" }, StringSplitOptions.None);
                            ianterior = new Tiempo(tiempos[0].Replace(',', '.').Trim());
                            fanterior = new Tiempo(tiempos[1].Replace(',', '.').Trim());
                        }
                        else if (i == 2)
                        {
                            Lines.Add(new lineaASS(ianterior.ToString(), fanterior.ToString(), "Default", linea));
                        }
                        else if (i > 2 && !linea.Equals(""))
                        {
                            lineaASS lass_ultima = (lineaASS)Lines.GetLines()[Lines.Count - 1];
                            lass_ultima.texto = lass_ultima.texto+"\\N"+linea;
                        }

                        if (linea.Equals("")) i = 0;
                        else i++;
                        break;
                }
            }

            Lines.Trim();
            sr.Close();

            if (isFont)
                Attachments.InsertFont(fnt_name, fnt); // por si acaso llegamos a EOF antes de \r\n
            if (isGraphic)
                Attachments.InsertFont(gfx_name, gfx);

            if (type == ScriptFileType.TXT || type == ScriptFileType.SRT)
            {
                Header.SetHeaderDefaults();
                Styles.Add(new estiloV4());
            }

            GC.Collect();
        }
Example #3
0
 public lineaASS(String t_i, String t_f, String est, String text)
 {
     this.clase = "Dialogue"; this.colision = 0; this.t_inicial = new Tiempo(t_i); this.t_final = new Tiempo(t_f);
     this.estilo = est; this.personaje = est; this.izquierda = 0; this.derecha = 0;
     this.vertical = 0; this.tipo = ""; this.texto = text;
 }
Example #4
0
        private string Personaje; //

        #endregion Fields

        #region Constructors

        /*
        public lineaASS(String c, int col, String t_i, String t_f, String est, String pj, int iz, int dc, int vt, String tipo, String text)
        {
            this.clase = c; this.colision = col; this.t_inicial = new Tiempo(t_i); this.t_final = new Tiempo(t_f);
            this.estilo = est; this.personaje = pj; this.izquierda = iz; this.derecha = dc;
            this.vertical = vt; this.tipo = tipo; this.texto = text;
        }
        */
        public lineaASS()
        {
            this.clase = "Dialogue"; this.colision = 0; this.t_inicial = new Tiempo(); this.t_final = new Tiempo();
            this.estilo = "Default"; this.personaje = ""; this.izquierda = 0; this.derecha = 0;
            this.vertical = 0; this.tipo = ""; this.texto = "";
        }
Example #5
0
        /* ASS
         * Dialogue: 0,00:00:12.48,00:00:13.38,Default,,0000,0000,0000,,meeeemb
         * SSA
         * Dialogue: Marked=0,0:00:12.99,0:00:13.51,T_Varios,o,0000,0000,0000,,Azul...
         */
        public void loadLine(String linea)
        {
            try
            {
                int posIn = linea.IndexOf(": ") + 2;
                String brau = linea.Substring(posIn);
                String cl = linea.Substring(0, (linea.IndexOf(": ")));
                String[] la = brau.Split(new Char[] { ',' }, 10);

                int col = 0;
                if (la[0].StartsWith("Marked=")) col = Convert.ToInt32(la[0].Remove(0, 7));
                else col = Convert.ToInt32(la[0]);

                int iz_ = Convert.ToInt32(la[5]);
                int dc_ = Convert.ToInt32(la[6]);
                int vt_ = Convert.ToInt32(la[7]);
                clase = cl; colision = col;

                t_inicial = new Tiempo(la[1]); t_final = new Tiempo(la[2]);

                estilo = la[3]; personaje = la[4];
                izquierda = iz_; derecha = dc_; vertical = vt_; tipo = la[8]; texto = la[9];
            }
            catch { throw new LineException("Excepción de SSA/ASS - Comprueba sintaxis en la línea:\n" + linea); }
        }
Example #6
0
        private void PreTiming(bool isStart)
        {
            Tiempo actual = new Tiempo();
            int nframe = VideoUnitConversion.getCurPos(mediaSeeking, videoInfo.FrameRate);
            double s = ((double)nframe / videoInfo.FrameRate);
            actual.setTiempo(s);
            lineaASS lass = (lineaASS)al[actualEdit];

            if (isStart)
            {
                tiempoInicio_.Text = Tiempo.SecondToTimeString(s);
                lass.t_inicial.setTiempo(s);
                tiempoFin_.Text = Tiempo.SecondToTimeString(s+2.00);
                lass.t_final.setTiempo(s+2.00);
            }
            else
            {
                tiempoFin_.Text = Tiempo.SecondToTimeString(s);
                lass.t_final.setTiempo(s);
            }
        }