Example #1
0
        // Vegas用テキストを得る
        string GetPlainText(Media media, string file)
        {
            string plainText = "";

            if (media.Generator != null)
            {
                // OFXEffect形式に変換して、Text情報を取得
                OFXEffect          ofxEffect = media.Generator.OFXEffect;
                OFXStringParameter textParam = (OFXStringParameter)ofxEffect.FindParameterByName("Text");
                if (textParam != null)
                {
                    string rtfData = textParam.Value;   // これがテキスト

                    // まず、temp.rtfを書き出します
                    System.IO.StreamWriter writer = new System.IO.StreamWriter(file);
                    writer.WriteLine(rtfData);
                    writer.Close();

                    // 次に、temp.rtfを読み込むとプレーンテキストになっています
                    System.Windows.Forms.RichTextBox richtextBox = new System.Windows.Forms.RichTextBox();
                    richtextBox.Rtf = System.IO.File.ReadAllText(file);
                    plainText       = richtextBox.Text;

                    // temp.rtfを削除
                    if (System.IO.File.Exists(file))
                    {
                        System.IO.File.Delete(file);
                    }
                }
            }
            return(plainText);
        }
Example #2
0
        // Vegasのテキストイベントのフォントを変更する
        void ChangeTextFont(Media media, string file, string fontFamily, float fontSize)
        {
            if (media.Generator != null)
            {
                if (media.Generator.IsOFX)   // 2021.2.7 null参照で例外のバグ修正
                // OFXEffect形式に変換して、Text情報を取得
                {
                    OFXEffect          ofxEffect = media.Generator.OFXEffect;
                    OFXStringParameter textParam = (OFXStringParameter)ofxEffect.FindParameterByName("Text");
                    if (textParam != null)
                    {
                        string rtfData = textParam.Value;   // これがテキスト

                        // まず、temp.rtfを書き出します
                        System.IO.StreamWriter writer = new System.IO.StreamWriter(file);
                        writer.WriteLine(rtfData);
                        writer.Close();

                        // 次に、temp.rtfを読み込むとプレーンテキストになっています
                        RichTextBox richtextBox = new RichTextBox();
                        richtextBox.Rtf = System.IO.File.ReadAllText(file);

                        // 2021.6.12
                        // rtf形式のフォントを変更する
                        float fontSizeFinal = richtextBox.SelectionFont.Size;
                        if (fontSizeFinal > 0.0f)
                        {
                            fontSizeFinal = fontSize;
                        }
                        richtextBox.SelectAll();                                                        // 全テキストが対象
                        richtextBox.SelectionFont = new System.Drawing.Font(fontFamily, fontSizeFinal); // フォント変更
                        richtextBox.SaveFile(file);                                                     // debug. フォントが変わったか確認してみよう

                        // OFXEffectの"Text" Parameterに対して再登録する
                        // Referenced source: https://www.reddit.com/r/SonyVegas/comments/5lolln/scripting_changes_to_ofx_parameters/
                        System.Xml.XmlDocument textValDoc = new System.Xml.XmlDocument();
                        textValDoc.LoadXml("<OfxParamValue>" + textParam.Value + "</OfxParamValue>");

                        System.Xml.XmlNode textPValue = textValDoc.FirstChild;
                        textPValue.InnerText = richtextBox.Rtf; // your new rtf words.
                        textParam.Value      = textPValue.InnerText;
                        textParam.ParameterChanged();           // Apply changed.

                        // temp.rtfを削除
                        if (System.IO.File.Exists(file))
                        {
                            System.IO.File.Delete(file);
                        }
                    }
                }
            }
        }
Example #3
0
        private VideoEvent[] createText(Vegas vegas, VideoTrack track, TrackEvent[] eventsBelow, Preset preset, List <string> values)
        {
            List <VideoEvent> events = new List <VideoEvent>();
            int i = 0;

            foreach (TrackEvent subEvent in eventsBelow)
            {
                Media      media = createTextMedia(vegas, preset);
                VideoEvent txt   = createText(media, track, subEvent);
                events.Add(txt);
                OFXEffect          ofxEffect = media.Generator.OFXEffect;
                OFXStringParameter tparam    = (OFXStringParameter)ofxEffect.FindParameterByName("Text");

                string value = replaceString(tparam.Value, getDefaultString(preset), values[i++]);
                tparam.Value = value;
                //string rand = randomText();
            }


            return(events.ToArray());
        }
    public void FromVegas(Vegas vegas)
    {
        try
        {
            int      num = 1;          //number of the current song track
            Timecode curr_song_lenght; //the lenght of the current song
            Timecode start_song_start; //the start of the current song

            //The track with songs must be the first one
            AudioTrack track_with_songs = (AudioTrack)vegas.Project.Tracks[0];

            //create a new track for the numbers
            VideoTrack new_track = new VideoTrack(0, "Numerotation");
            vegas.Project.Tracks.Add(new_track);

            foreach (TrackEvent song_event in track_with_songs.Events)
            {
                curr_song_lenght = song_event.Length;
                start_song_start = song_event.Start;

                //create the video event with the corresponding number of the song
                VideoEvent new_event = new VideoEvent(start_song_start, curr_song_lenght);

                PlugInNode plugIn = vegas.Generators.FindChildByUniqueID("{Svfx:com.sonycreativesoftware:titlesandtext}");
                Media      media  = new Media(plugIn);
                new_track.Events.Add(new_event);
                MediaStream stream = media.Streams[0];
                Take        take   = new Take(stream);
                new_event.Takes.Add(take);



                //Set the text
                Effect             effect  = new_event.ActiveTake.Media.Generator;
                OFXEffect          fxo     = effect.OFXEffect;
                OFXStringParameter tparm   = (OFXStringParameter)fxo.FindParameterByName("Text");
                RichTextBox        rtfText = new RichTextBox();



                rtfText.Text = num.ToString();  //the text


                rtfText.SelectAll();
                Font font = new Font(Constants.FONT_FAMILY, Constants.TEXT_SIZE, FontStyle.Bold);  //font and size

                rtfText.SelectAll();
                rtfText.SelectionColor = Color.Cyan;//Constants.TEXT_COLOR;
                rtfText.SelectionFont  = font;

                tparm.Value = rtfText.Rtf;
                fxo.AllParametersChanged();


                num++;
            }
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }
Example #5
0
        Take GenerateTakeText(Vegas vegas, string text)
        {
            if (text.Length == 0)
            {
                return(null);
            }

            // テキストを順次追加
            PlugInNode plugin = vegas.Generators.GetChildByName("VEGAS タイトルおよびテキスト"); // 日本語版だとプラグイン名はこれです。英語版は不明
            Media      media  = new Media(plugin);                                    // これちょっと遅いです

            if (media.Generator == null)
            {
                return(null);
            }
            if (!media.Generator.IsOFX)
            {
                return(null);
            }
            // Text属性を得る。
            // 全属性を見たい場合はウォッチのOfxEffect.Parameters.Results Viewを見るとある。(多分21個)
            OFXEffect          ofxEffect = media.Generator.OFXEffect;
            OFXStringParameter textParam = (OFXStringParameter)ofxEffect.FindParameterByName("Text");

            if (textParam == null)
            {
                return(null);
            }

            // テキストをセット
            RichTextBox richtextBox1 = new RichTextBox();

            richtextBox1.Text = text;
            richtextBox1.SelectAll();                                                     // 全テキストが対象
            richtextBox1.SelectionFont = new System.Drawing.Font(_fontFamily, _fontSize); // フォント変更
            //richtextBox.SaveFile(file); // debug. フォントが変わったか確認してみよう

            // OFXEffectの"Text" Parameterに対して再登録する
            System.Xml.XmlDocument textValDoc = new System.Xml.XmlDocument();
            textValDoc.LoadXml("<OfxParamValue>" + textParam.Value + "</OfxParamValue>");
            System.Xml.XmlNode textPValue = textValDoc.FirstChild;
            textPValue.InnerText = richtextBox1.Rtf; // your new rtf words.
            textParam.Value      = textPValue.InnerText;
            textParam.ParameterChanged();            // Apply changed.

            // これらはTextが見つかれば絶対全部見つかるからnullチェックしない
            OFXRGBAParameter     textColorParam    = (OFXRGBAParameter)ofxEffect.FindParameterByName("TextColor");
            OFXDouble2DParameter locationParam     = (OFXDouble2DParameter)ofxEffect.FindParameterByName("Location");
            OFXChoiceParameter   alignmentParam    = (OFXChoiceParameter)ofxEffect.FindParameterByName("Alignment");
            OFXDoubleParameter   outlineWidthParam = (OFXDoubleParameter)ofxEffect.FindParameterByName("OutlineWidth");
            OFXRGBAParameter     outlineColorParam = (OFXRGBAParameter)ofxEffect.FindParameterByName("OutlineColor");
            OFXBooleanParameter  shadowEnableParam = (OFXBooleanParameter)ofxEffect.FindParameterByName("ShadowEnable");

            //OFXStringParameter shadowColorParam = (OFXStringParameter)ofxEffect.FindParameterByName("ShadowColor");

            // パラメータセット //
            // TextColor
            textColorParam.Value = _fontColor;// new OFXColor(50.0f / 255.0, 100.0f / 255.0f, 150.0f / 255.0f);

            // Alignment
            // alignmentParam.Choiesを確認すること
            // OFXChoiceはReadOnly型なのでなにもできません
            alignmentParam.Value = alignmentParam.Choices[_Align]; //alignmentParam.Choices[7];

            //Location
            OFXDouble2D loc;

            loc.X = _locationX;
            loc.Y = _locationY;
            locationParam.Value = loc;

            // Outline
            outlineWidthParam.Value = _outlineWidth;
            outlineColorParam.Value = _outlineColor;// new OFXColor(10 / 255.0, 10 / 255.0f, 10 / 255.0f);

            MediaStream stream = media.Streams[0];
            //VideoEvent videoEvent = new VideoEvent(Timecode.FromSeconds(_currentTime), Timecode.FromSeconds(_timeLength));
            //track.Events.Add(videoEvent);
            Take take = new Take(stream);

            //videoEvent.Takes.Add(take);

            //_currentTime += _timeLength;

            return(take);
        }