Example #1
0
    public void FromVegas(Vegas vegas)
    {
        myVegas = vegas;
        if (UseProjectRulerFormatForTimecodes)
        {
            myTimecodeFormat = myVegas.Project.Ruler.Format;
        }

        String outputFile = myVegas.Project.FilePath;

        if (!String.IsNullOrEmpty(outputFile))
        {
            String fileNameWOExt = Path.GetFileNameWithoutExtension(outputFile);
            String directoryName = Path.GetDirectoryName(outputFile);
            outputFile = Path.Combine(directoryName, fileNameWOExt + ".xml");
        }

        outputFile = ShowSaveFileDialog("XML Files (*.xml)|*.xml", "XML Output File", outputFile);
        myVegas.UpdateUI();

        if (null != outputFile)
        {
            ExportXml(outputFile);
        }
    }
Example #2
0
        private void PerformReplace()
        {
            if (SearchResults.Count == 0)
            {
                PerformSearch();
            }

            if (SearchResults.Count == 0)
            {
                return;
            }

            string ReplaceString = tbReplace.Text;

            using (var undo = new UndoBlock("Search / replace"))
            {
                foreach (SearchReplaceResult rslt in SearchResults)
                {
                    if (!rslt.Include)
                    {
                        continue;
                    }
                    rslt.Replace(ReplaceString);
                }
            }
            MyVegas.UpdateUI();

            // a bit dirty, but we want to update the search results.
            PerformSearch();
        }
        public bool RenderFile(FileInfo fiVeg, FileInfo fiRendered, RenderTemplate renderTemplate, RenderStatusManager rsm, object dr)
        {
            DateTime renderStart = DateTime.Now;
            DateTime renderEnd;
            TimeSpan renderTime;

            rsm.Dialog.Hide(); // Temporarily hide because during load the UX kills it.
            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderStart, renderStart);
            if (myVegas.Project != null)
            {
                // No close method so create a clean new project without the ability to prompt for save of existing
                // and then open after that.
                myVegas.NewProject(false, false);
            }
            myVegas.UpdateUI();
            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderStatus, "Loading");
            myVegas.OpenFile(fiVeg.FullName);
            myVegas.UpdateUI();
            myVegas.WaitForIdle();
            rsm.Dialog.Show();

            // Render
            RenderArgs ra = new RenderArgs();

            ra.OutputFile     = fiRendered.FullName;
            ra.RenderTemplate = renderTemplate;
            Timecode projectLength = GetProjectLength();

            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.ProjectLength, projectLength);
            ra.Length     = projectLength;
            ra.StartNanos = 0;

            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderStatus, "Rendering");
            RenderStatus status = myVegas.Render(ra);

            renderEnd  = DateTime.Now;
            renderTime = renderEnd - renderStart;
            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderEnd, renderEnd);
            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderTime, renderTime);
            rsm.UpdateField(dr, RenderStatusManager.Fields.Names.RenderStatus, status.ToString());
            return(status == RenderStatus.Complete);
        }
        public void FromVegas(Vegas vegas)
        {
            try
            {
                _vegas = vegas;

                ScriptArgs args = Script.Args;
                if (args.Count > 0)
                {
                    _closeonfinish = System.Convert.ToBoolean(args.ValueOf("closeonfinish") ?? "false");
                    _savewhendone  = System.Convert.ToBoolean(args.ValueOf("savewhendone") ?? "false");
                    _makeveg       = System.Convert.ToBoolean(args.ValueOf("makeveg") ?? "false");
                    _file          = args.ValueOf("file");
                }
                else
                {
                    var dialog = new OpenFileDialog {
                        Filter = ".srt files (*.srt)|*.srt", CheckPathExists = true, InitialDirectory = vegas.Project.FilePath
                    };
                    DialogResult result = dialog.ShowDialog();
                    vegas.UpdateUI();

                    if (result == DialogResult.OK)
                    {
                        _file = Path.GetFullPath(dialog.FileName);
                    }
                    else
                    {
                        return;
                    }
                }

                if (_makeveg)
                {
                    Media media = vegas.Project.MediaPool.AddMedia(Script.Args.ValueOf("media"));

                    foreach (MediaStream stream in media.Streams)
                    {
                        if (stream is VideoStream)
                        {
                            VideoTrack t = vegas.Project.AddVideoTrack();
                            VideoEvent e = t.AddVideoEvent(new Timecode(), media.Length);
                            e.ResampleMode = VideoResampleMode.Disable;
                            e.AddTake(stream);
                        }
                        else if (stream is AudioStream)
                        {
                            AudioTrack t = vegas.Project.AddAudioTrack();
                            AudioEvent e = t.AddAudioEvent(new Timecode(), media.Length);
                            e.AddTake(stream);
                        }
                    }

                    vegas.SaveProject(Script.Args.ValueOf("output"));
                }

                using (FileStream fs = new FileStream(_file, FileMode.Open, FileAccess.Read))
                    using (StreamReader stream = new StreamReader(fs))
                    {
                        while (!stream.EndOfStream)
                        {
                            string line = stream.ReadLine();

                            if (Regex.IsMatch(line, "^[0-9]+$"))
                            {
                                line = stream.ReadLine();

                                if (Regex.IsMatch(line, "^" + SRT_TIME_PATTERN + " --> " + SRT_TIME_PATTERN + "$"))
                                {
                                    MatchCollection stamps = Regex.Matches(line, SRT_TIME_PATTERN);

                                    TimeSpan s = TimeSpan.ParseExact(stamps[0].Value, SRT_TIME_FORMAT, null);
                                    TimeSpan e = TimeSpan.ParseExact(stamps[1].Value, SRT_TIME_FORMAT, null);
                                    string   t = string.Empty;

                                    while (!stream.EndOfStream)
                                    {
                                        line = stream.ReadLine();
                                        if (!string.IsNullOrEmpty(line))
                                        {
                                            if (!string.IsNullOrEmpty(t))
                                            {
                                                t += "[br]";
                                            }

                                            t += line;
                                        }
                                        else
                                        {
                                            break;
                                        }
                                    }

                                    Region r = Convert(s, e, t);
                                    if (r != null)
                                    {
                                        vegas.Project.Regions.Add(r);
                                    }
                                }
                            }
                        }
                    }

                if (_savewhendone)
                {
                    vegas.SaveProject();
                }
                if (_closeonfinish)
                {
                    vegas.Exit();
                }
            }
            catch (VegasException e)
            {
                Vegas.COM.ShowError(e.Title, e.Message);
            }
        }
Example #5
0
        private void Execute_VPython_File_PN(string filename, List <string> sysargs)
        {
            ClearMessage();
            ShowDebugMessage("File_PN");
            String  pythonfile = "";
            dynamic sys        = null; // = PythonEngine.ImportModule("sys");
            string  pyStdout   = "";
            string  pyStderr   = "";

            try
            {
                //if (File.Exists(m_filename))
                //{
                ShowDebugMessage("Start");

                // string moduleDirectory = Path.GetDirectoryName(m_filename);

                //string moduleName = Path.GetFileNameWithoutExtension(m_filename);
                string moduleName = filename; // import syntax
                Set_Path_PN(filename);

                ShowDebugMessage("PythonPath2: " + PythonEngine.PythonPath);

                myVegas.UpdateUI();

                Object pyVegas = myVegas;

                ShowDebugMessage("Py.GIL");

                using (Py.GIL())
                {
                    ShowDebugMessage("Py.CreatScope");
                    using (var scope = Py.CreateScope("VEGAS"))
                    {
                        ShowDebugMessage("PythonEngine.Initialze");
                        PythonEngine.Initialize();


                        // Redirect stdout to text box
                        ShowDebugMessage("PythonEngine.ImportModule(sys)");
                        sys = PythonEngine.ImportModule("sys");

                        string codeToRedirectOutput =
                            "import sys\n" +
                            "from io import StringIO\n" +
                            "sys.stdout = mystdout = StringIO()\n" +
                            "sys.stdout.flush()\n" +
                            "sys.stderr = mystderr = StringIO()\n" +
                            "sys.stderr.flush()\n";

                        scope.Exec(codeToRedirectOutput);

                        if ((mvpWindowForm != null) && (myVegas.ActivateDockView(vPythonModule.vPythonWindowMName)))
                        {
                            Console.SetOut(new OutBoxWriter(mvpWindowForm.vPythonOutputBox));
                        }

                        ShowMessage("Script: " + filename);

                        if (sysargs != null)
                        {
                            Py.SetArgv(sysargs);
                        }

                        if ((mVegasPythonConfigData.debugmode) && (mVegasPythonConfigData.debugprecmd != ""))
                        {
                            scope.Exec(mVegasPythonConfigData.debugprecmd);
                            ShowDebugMessage("Pre-CMD Executed:" + mVegasPythonConfigData.debugprecmd);
                        }



                        if ((mVegasPythonConfigData.debugmode) && (mVegasPythonConfigData.debugusereload) && (PythonModuleImported != null))
                        {
                            if (PythonModuleImportedName == moduleName)
                            {
                                ShowDebugMessage("Reload Module" + moduleName);
                                PythonEngine.ReloadModule(PythonModuleImported);
                            }
                            else
                            {
                                ShowDebugMessage("Import Module" + moduleName);
                                //PythonModuleImported = Py.Import(moduleName);
                                PythonModuleImported = scope.Import(moduleName);
                                //PythonModuleImported = PythonEngine.ImportModule(moduleName);
                                PythonModuleImportedName = moduleName;
                            }
                        }
                        else
                        {
                            ShowDebugMessage("Import Module" + moduleName);
                            //PythonModuleImported = Py.Import(moduleName);
                            PythonModuleImported = scope.Import(moduleName);
                            //PythonModuleImported = PythonEngine.ImportModule(moduleName);
                            PythonModuleImportedName = moduleName;
                        }

                        scope.Set("pyVEGAS", pyVegas); //declare pyVEGAS as global variable
                        scope.Set("__name__", "__main__");

                        ShowDebugMessage("module.FromVegas");

                        PythonModuleImported.FromVegas(pyVegas);

                        if ((mVegasPythonConfigData.debugmode) && (mVegasPythonConfigData.debugpostcmd != ""))
                        {
                            scope.Exec(mVegasPythonConfigData.debugpostcmd);
                            ShowDebugMessage("Post-CMD Executed:" + mVegasPythonConfigData.debugpostcmd);
                        }

                        pyStdout = sys.stdout.getvalue(); // Get stdout
                        pyStdout = pyStdout.Replace("\n", "\r\n");
                        pyStderr = sys.stderr.getvalue(); // Get stderr
                        pyStderr = pyStderr.Replace("\n", "\r\n");
                        ShowMessage(pyStdout + "\r\n" + pyStderr);

                        scope.Dispose();
                    }
                }
                //}
                // PythonEngine.Shutdown();
            }

            catch (Exception e)
            {
                string msg = "Error executing Python file \"{0}\"";
                ShowError(msg, Path.GetFileName(pythonfile), e);
            }
            finally
            {
                // PythonEngine.Shutdown();
            }
        }