Esempio 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);
        }
    public void FromVegas(Vegas vegas)
    {
        myVegas = vegas;

        System.Collections.Generic.List <OFXDouble2DKeyframe> locations = new System.Collections.Generic.List <OFXDouble2DKeyframe>();
        Tuple <Timecode, Timecode> durationTrackEvent;

        VideoEvent trackEvent = (VideoEvent)FindFirstSelectedEventUnderCursor();

        if (trackEvent == null)
        {
            MessageBox.Show("Please select the video event on which VEGAS Bezier Masking has been applied.", "No selected event", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }
        else
        {
            durationTrackEvent = new Tuple <Timecode, Timecode>(trackEvent.Start, trackEvent.End);
            Effects fxs            = trackEvent.Effects;
            bool    bezierWasFound = false;
            foreach (Effect fx in fxs)
            {
                bezierWasFound = fx.PlugIn.UniqueID == "{Svfx:com.sonycreativesoftware:bzmasking}";
                if (bezierWasFound)
                {
                    OFXParameters parameter = fx.OFXEffect.Parameters;
                    foreach (OFXParameter param in parameter)
                    {
                        if (param.Name == "Location_0")
                        {
                            OFXDouble2DParameter locationTracking = (OFXDouble2DParameter)param;
                            locations = new List <OFXDouble2DKeyframe>(locationTracking.Keyframes);
                            break;
                        }
                    }

                    break;
                }
            }
            if (!bezierWasFound)
            {
                MessageBox.Show("Please apply VEGAS Bezier Masking to the video event", "VEGAS Bezier Masking not applied", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
        }

        if (locations.Count == 0)
        {
            MessageBox.Show("Please add Motion Tracking to the VEGAS Bezier Masking FX", "No tracking data", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            return;
        }
        else
        {
            using (OffsetDialog offsetPrompt = new OffsetDialog())
            {
                DialogResult result = offsetPrompt.ShowDialog();
                if (result == DialogResult.OK)
                {
                    VideoTrack titleTrack    = myVegas.Project.AddVideoTrack();
                    PlugInNode textAndTitles = myVegas.Generators.GetChildByUniqueID("{Svfx:com.sonycreativesoftware:titlesandtext}"); // GetChildByName("VEGAS Titles & Text");//
                    Timecode   lengthEvent   = durationTrackEvent.Item2 - durationTrackEvent.Item1;
                    Media      media         = new Media(textAndTitles, "Placeholder");
                    media.Length = lengthEvent;
                    VideoEvent vEvent = titleTrack.AddVideoEvent(durationTrackEvent.Item1, lengthEvent);
                    Take       take   = new Take(media.Streams[0]);
                    vEvent.Takes.Add(take);

                    Effect        fxText    = media.Generator;
                    OFXParameters parameter = fxText.OFXEffect.Parameters;
                    foreach (OFXParameter param in parameter)
                    {
                        if (param.Name == "Location")
                        {
                            OFXDouble2DParameter locationText = (OFXDouble2DParameter)param;
                            locationText.Keyframes.Clear();
                            foreach (OFXDouble2DKeyframe location in locations)
                            {
                                OFXDouble2D tmpValue = location.Value;
                                tmpValue.X += offsetPrompt.X;
                                tmpValue.Y += offsetPrompt.Y;
                                locationText.SetValueAtTime(location.Time, tmpValue);
                            }

                            break;
                        }
                    }
                }
            }
        }
    }
Esempio n. 3
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();
    }
    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();
    }
Esempio n. 5
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 != 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 is the target event, where the pan and crop center will be populated with the motion track data. Then after clicking on this script you can select the mask to use. The script will copy the location values of the mask to the location values of the pan and crop setting (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);

        int mask_to_use = PromptForMaskNumber();

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

        VideoEvent ve2 = GetEventDifferentFrom(ves, ve);

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

        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());

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

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

        double deltaX         = 0;
        double deltaY         = 0;
        double lastX          = 0;
        double lastY          = 0;
        bool   deltaPopulated = false;

        VideoMotion ve2vm = ve2.VideoMotion;

        VideoMotionKeyframe prevKeyframe = new VideoMotionKeyframe(currProject, (startingTime - ve2.Start));

        ve2vm.Keyframes.Add(prevKeyframe);

        foreach (OFXDouble2DKeyframe motionKeyframe in motionParam.Keyframes)
        {
            Timecode keyframeTime = motionKeyframe.Time + ve.Start;

            if (startingTime <= keyframeTime && keyframeTime <= endingTime)
            {
                if (!deltaPopulated)
                {
                    lastX = motionKeyframe.Value.X;
                    lastY = motionKeyframe.Value.Y;

                    deltaPopulated = true;
                }
                else
                {
                    deltaX = motionKeyframe.Value.X - lastX;
                    deltaY = motionKeyframe.Value.Y - lastY;

                    lastX = motionKeyframe.Value.X;
                    lastY = motionKeyframe.Value.Y;

                    // TODO: Delete
                    // MessageBox.Show("Delta X: " + deltaX.ToString()
                    //         + "\nDelta Y: " + deltaY.ToString()
                    //         + "\nLast X: " + lastX.ToString()
                    //         + "\nLast Y: " + lastY.ToString());

                    VideoMotionKeyframe vmKeyframe = new VideoMotionKeyframe(currProject, keyframeTime - ve2.Start);
                    ve2vm.Keyframes.Add(vmKeyframe);

                    // TODO: Delete
                    // MessageBox.Show("Current Bounds: " + vmKeyframe.Bounds.ToString()
                    //         + "\nCurrent Rotation: " + vmKeyframe.Rotation.ToString()
                    //         + "\nCurrent Type: " + vmKeyframe.Type.ToString()
                    //         + "\nCurrent Smoothness: " + vmKeyframe.Smoothness.ToString()
                    //         + "\n\nPrevious Bounds: " + prevKeyframe.Bounds.ToString()
                    //         + "\nPrevious Rotation: " + prevKeyframe.Rotation.ToString()
                    //         + "\nPrevious Type: " + prevKeyframe.Type.ToString()
                    //         + "\nPrevious Smoothness: " + prevKeyframe.Smoothness.ToString());

                    // Duplicate previous keyframe values
                    // vmKeyframe.Bounds = prevKeyframe.Bounds;
                    // vmKeyframe.Rotation = prevKeyframe.Rotation;
                    // vmKeyframe.Type = prevKeyframe.Type;
                    // vmKeyframe.Smoothness = prevKeyframe.Smoothness;

                    // bool kfGrabbed = false;
                    // foreach (VideoMotionKeyframe kf in ve2vm.Keyframes)
                    // {
                    //     if (kf.Position.Equals(vmKeyframe.Position))
                    //     {
                    //         vmKeyframe = kf;
                    //         kfGrabbed = true;
                    //         break;
                    //     }
                    // }

                    // if (!kfGrabbed)
                    // {
                    //     MessageBox.Show("Something went wrong as the script tried to regrab a created keyframe with the Timecode " + vmKeyframe.Position.ToString() + " ...\n\nTerminating...", "Error regrabbing keyframe", MessageBoxButtons.OK, MessageBoxIcon.Stop);
                    //     return;
                    // }

                    double convertedX = deltaX * videoWidth;
                    double convertedY = -1 * (deltaY * videoHeight);

                    vmKeyframe.MoveBy(new VideoMotionVertex(Convert.ToSingle(convertedX), Convert.ToSingle(convertedY)));

                    // MessageBox.Show("Next Bounds: " + vmKeyframe.Bounds.ToString()
                    //         + "\nNext Rotation: " + vmKeyframe.Rotation.ToString()
                    //         + "\nNext Type: " + vmKeyframe.Type.ToString()
                    //         + "\nNext Smoothness: " + vmKeyframe.Smoothness.ToString());

                    prevKeyframe = vmKeyframe;
                }
            }
        }

        // TODO: Bother with interpolation shit?
        // 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();
    }