コード例 #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);
        }
コード例 #2
0
    public void FromVegas(Vegas vegas)
    {
        TrackEvent[] tes = FindSelectedEvents(vegas.Project);
        VideoEvent[] ves = GetVideoEvents(tes);

        if (ves.Length != 2)
        {
            MessageBox.Show("You have to select exactly 2 video events (in no particular order) in order for this script to work.\nOne of the events must contain the \"" + MOTION_TRACKING_FX_NAME + "\" effect with at least one mask enabled and populated with motion tracking data, the second event must contain the \"" + PIP_FX_NAME + "\" effect with the mode set to \"" + PIP_FX_MODE_NAME + "\".\nThen after clicking on this script you can select the mask and corner to use. The script will copy the location values of the mask to the location values of the pip corner (beginning from the cursor position till the end of the motion tracked clip, or within the selection range).\n\nTerminating...", "Not enough selections", 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...", "Not enough selections", 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);

        VideoEvent ve2 = GetEventContainingEffect(ves, PIP_FX_NAME);

        if (ve2 == null)
        {
            MessageBox.Show("No selected event with the \"" + PIP_FX_NAME + "\" plugin found which is the target for the motion tracking data!\n\nTerminating...", "Not enough selections", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }

        OFXEffect fx2 = GetOFXFromEvent(ve2, PIP_FX_NAME);

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

        OFXChoiceParameter param = fx2.FindParameterByName("KeepProportions") as OFXChoiceParameter;

        OFXChoice choice = param.Value;

        if (!param.Value.Name.Equals(PIP_FX_MODE_NAME))
        {
            MessageBox.Show("The Mode of the \"" + PIP_FX_NAME + "\" effect has to be set to \"" + PIP_FX_MODE_NAME + "\"!\n\nTerminating...", "Wrong effect mode", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }

        bool          goOn           = false;
        List <int>    masks_to_use   = new List <int>();
        List <string> corners_to_use = new List <string>();

        while (!goOn)
        {
            int mask_to_use = PromptForMaskNumber();

            if (mask_to_use == -1)
            {
                MessageBox.Show("Something went wrong during the mask choosing process!\n\nTerminating...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            // show_fx_parameters(fx2);

            string corner_to_use = PromptForCorner();

            if (corner_to_use == null)
            {
                MessageBox.Show("Something went wrong during the corner choosing process!\n\nTerminating...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            masks_to_use.Add(mask_to_use);
            corners_to_use.Add(corner_to_use);

            if (MASK_BITMASK == 0 || CORNER_BITMASK == 0)
            {
                goOn = true;
                continue;
            }

            DialogResult continueResult = MessageBox.Show("Do you want to choose another mask-corner pair?", "Another one?", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

            if (continueResult == DialogResult.Cancel)
            {
                return;
            }
            else if (continueResult == DialogResult.No)
            {
                goOn = true;
            }
        }

        if (masks_to_use.Count != corners_to_use.Count)
        {
            MessageBox.Show("Something went wrong during the mask-corner choosing process!\nMask-count differs from Corner-count!\n\nMaybe you have selected the same Mask or corner twice?\n\nTerminating...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
        }

        Timecode startingTime = null;
        Timecode endingTime   = null;

        DialogResult dialogResult = MessageBox.Show("You have two methods to copy the keyframes:\nOne option is to copy from the current cursor position onwards, till the script runs into the ending of one of the events (yes).\nThe other option is to use the current selection. Note however that this produces unexpected behaviour, if no selection is currently active! (no).\n\nCopy from the cursor onwards?", "Processing Method", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

        if (dialogResult == DialogResult.Cancel)
        {
            return;
        }
        else
        {
            Double motionStart = ve.Start.ToMilliseconds();
            Double motionEnd   = ve.End.ToMilliseconds();

            Double cornerStart = ve2.Start.ToMilliseconds();
            Double cornerEnd   = ve2.End.ToMilliseconds();

            if (dialogResult == DialogResult.Yes)
            {
                Double cursorStart = vegas.Transport.CursorPosition.ToMilliseconds();

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

                if (max != cursorStart || min != cursorStart)
                {
                    MessageBox.Show("The cursor must be placed at a position where it covers both selected events!\n\nTerminating...", "Invalid cursor position", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                startingTime = new Timecode(cursorStart);
                endingTime   = new Timecode(Math.Min(motionEnd, cornerEnd));
            }
            else if (dialogResult == DialogResult.No)
            {
                Double selectionStart = vegas.Transport.SelectionStart.ToMilliseconds();
                Double selectionEnd   = selectionStart + vegas.Transport.SelectionLength.ToMilliseconds();

                Double max = Math.Max(motionStart, Math.Max(cornerStart, selectionStart));
                Double min = Math.Min(motionEnd, Math.Min(cornerEnd, selectionEnd));

                if (max != selectionStart || min != selectionEnd)
                {
                    MessageBox.Show("The selection must be placed in a range where it covers both selected events!\n\nTerminating...", "Invalid selection", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }

                startingTime = new Timecode(selectionStart);
                endingTime   = new Timecode(selectionEnd);
            }
        }

        // MessageBox.Show("Current time: " + fx2.CurrentTime.ToString() + "\nCursor pos: " + vegas.Transport.CursorPosition.ToString() + "\nCalculated current time: " + (fx2.CurrentTime + ve2.Start).ToString());

        if (startingTime == null || endingTime == null)
        {
            MessageBox.Show("Something went wrong as the script tried to use the method you decided...\n\nTerminating...", "Error", MessageBoxButtons.OK, MessageBoxIcon.Stop);
            return;
        }

        PopulateMaskBitmask(fx);
        CORNER_BITMASK = MASK_0 + MASK_1 + MASK_2 + MASK_3;

        for (int i = 0; i < masks_to_use.Count; ++i)
        {
            OFXDouble2DParameter motionParam = fx.FindParameterByName("Location_" + masks_to_use[i].ToString()) as OFXDouble2DParameter;

            OFXDouble2DParameter cornerParam = fx2.FindParameterByName(corners_to_use[i]) as OFXDouble2DParameter;

            foreach (OFXDouble2DKeyframe motionKeyframe in motionParam.Keyframes)
            {
                Timecode keyframeTime = motionKeyframe.Time + ve.Start;
                if (startingTime <= keyframeTime && keyframeTime <= endingTime)
                {
                    cornerParam.SetValueAtTime((keyframeTime - ve2.Start), motionKeyframe.Value);
                }
            }

            cornerParam.ParameterChanged();
        }

        // dialogResult = MessageBox.Show("Do you also want to copy the interpolation data?", "Copy interpolation data?", MessageBoxButtons.YesNo);

        // if (dialogResult == DialogResult.Yes)
        // {
        //     int curr = 0;
        //     int end = cornerParam.Keyframes.Count;

        //     foreach (OFXDouble2DKeyframe motionKeyframe in motionParam.Keyframes)
        //     {
        //         Timecode keyframeTime = motionKeyframe.Time + ve.Start;
        //         if (curr < end && startingTime <= keyframeTime && keyframeTime <= endingTime)
        //         {
        //             Timecode calculatedTime = (keyframeTime - ve2.Start);

        //             OFXDouble2DKeyframe cornerKeyframe = cornerParam.Keyframes[curr] as OFXDouble2DKeyframe;
        //             if (cornerKeyframe.Time == calculatedTime)
        //             {
        //                 cornerKeyframe.Interpolation = motionKeyframe.Interpolation;
        //             }
        //             else if (cornerKeyframe.Time < calculatedTime)
        //             {
        //                 ++curr;
        //             }
        //         }
        //     }
        // }

        // cornerParam.ParameterChanged();
    }