Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
    public void FromVegas(Vegas vegas)
    {
        Project currProject = vegas.Project;
        Int32   videoWidth  = currProject.Video.Width;
        Int32   videoHeight = currProject.Video.Height;

        TrackEvent[] tes = FindSelectedEvents(currProject);
        VideoEvent[] ves = GetVideoEvents(tes);

        if (ves.Length != 1)
        {
            MessageBox.Show("You have to select exactly 1 video events in order for this script to work.\nThe events must contain the \"" + MOTION_TRACKING_FX_NAME + "\" effect with at least one mask enabled. You then zoom in, using pan and crop options. Then after clicking on this script, the pan and crop option will be reset and the point moved, so that it stays on the pixel you selected.\n\nTerminating...", "Wrong selection", MessageBoxButtons.OK, MessageBoxIcon.Information);
            return;
        }

        // foreach (VideoEvent ev in ves)
        // {
        //     foreach (Effect ef in ev.Effects)
        //     {
        //         MessageBox.Show(ef.Description);
        //     }
        // }

        VideoEvent ve = GetEventContainingEffect(ves, MOTION_TRACKING_FX_NAME);

        if (ve == null)
        {
            MessageBox.Show("No selected event with the \"" + MOTION_TRACKING_FX_NAME + "\" plugin found which holds the motion tracking data!\n\nTerminating...", "Wrong selection", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }

        OFXEffect fx = GetOFXFromEvent(ve, MOTION_TRACKING_FX_NAME);

        if (fx == null)
        {
            MessageBox.Show("Can't seem to grab the \"" + MOTION_TRACKING_FX_NAME + "\" effect!\n\nTerminating...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            return;
        }

        PopulateMaskBitmask(fx);

        // show_fx_parameters(fx);

        int mask_to_use = PromptForMaskNumber();

        if (mask_to_use == -1)
        {
            return;
        }

        Timecode cursorTime = null;

        Double motionStart = ve.Start.ToMilliseconds();
        Double motionEnd   = ve.End.ToMilliseconds();

        Double cursorStart = vegas.Transport.CursorPosition.ToMilliseconds();

        Double max = Math.Max(motionStart, cursorStart);
        Double min = Math.Min(motionEnd, cursorStart);

        if (max != cursorStart || min != cursorStart)
        {
            MessageBox.Show("The cursor must be placed within the event borders!\n\nTerminating...", "Invalid cursor position", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }

        cursorTime = new Timecode(cursorStart);

        OFXDouble2DParameter motionParam = fx.FindParameterByName("Location_" + mask_to_use.ToString()) as OFXDouble2DParameter;

        if (cursorTime == null)
        {
            MessageBox.Show("Something went wrong as the script tried to determine the cursor position...\n\nTerminating...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            return;
        }

        VideoMotion vevm = ve.VideoMotion;

        VideoMotionKeyframe currKeyframe = new VideoMotionKeyframe(currProject, (cursorTime - ve.Start));

        vevm.Keyframes.Add(currKeyframe);

        Single cutoutWidth  = currKeyframe.TopRight.X - currKeyframe.TopLeft.X;
        Single cutoutHeight = currKeyframe.BottomLeft.Y - currKeyframe.TopLeft.Y;
        Single originX      = currKeyframe.TopLeft.X;
        Single originY      = currKeyframe.BottomLeft.Y;

        OFXDouble2D cursorValue = motionParam.GetValueAtTime(cursorTime - ve.Start);

        Double newCoordX = originX + (cutoutWidth * cursorValue.X);
        Double newCoordY = originY - (cutoutHeight * cursorValue.Y);

        cursorValue.X = newCoordX / videoWidth;
        cursorValue.Y = 1 - (newCoordY / videoHeight);
        motionParam.SetValueAtTime((cursorTime - ve.Start), cursorValue);

        DialogResult dialogResult = MessageBox.Show("If you choose to also adapt the mask scale, this would mean that the mask will be shrunk together with the video frame.\nIf you have zoomed in alot, it sometimes makes sense to not do this as the control handles would get so small that you can't grab them.\nIf you choose to also adjust the size, you can also later on change the width/height from the mask settings.\n\nWould you like to also adapt the mask scale?", "Also adjust mask scale?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);

        if (dialogResult == DialogResult.Yes)
        {
            OFXDoubleParameter widthParam     = fx.FindParameterByName("Width_" + mask_to_use.ToString()) as OFXDoubleParameter;
            OFXDoubleParameter heightParam    = fx.FindParameterByName("Height_" + mask_to_use.ToString()) as OFXDoubleParameter;
            Double             maskWidth      = widthParam.GetValueAtTime(cursorTime - ve.Start);
            Double             maskHeight     = heightParam.GetValueAtTime(cursorTime - ve.Start);
            Double             widthRelation  = videoWidth / cutoutWidth;
            Double             heightRelation = videoHeight / cutoutHeight;

            widthParam.SetValueAtTime((cursorTime - ve.Start), (maskWidth / widthRelation));
            heightParam.SetValueAtTime((cursorTime - ve.Start), (maskHeight / heightRelation));
        }

        VideoMotionBounds restoreBounds = new VideoMotionBounds(
            new VideoMotionVertex(0, 0),
            new VideoMotionVertex(videoWidth, 0),
            new VideoMotionVertex(videoWidth, videoHeight),
            new VideoMotionVertex(0, videoHeight)
            );

        currKeyframe.Bounds = restoreBounds;
        currKeyframe.Center = new VideoMotionVertex((videoWidth / 2), (videoHeight / 2));

        MessageBox.Show("Please select a different effect, or move the cursor to a differen event, in order to update the control handles of the mask", "Refresh control handles", MessageBoxButtons.OK, MessageBoxIcon.Information);

        fx.AllParametersChanged();
    }