// 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); }
// 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); } } } } }
private void PopulateMaskBitmask(OFXEffect fx) { string[] paramNames = { "Enable_0", "Enable_1", "Enable_2", "Enable_3", "Enable_4" }; for (int i = 0; i < paramNames.Length; ++i) { int BITMASK_NUMBER = (int)Math.Pow(2, i); OFXBooleanParameter param = fx.FindParameterByName(paramNames[i]) as OFXBooleanParameter; if (param.Value) { MASK_BITMASK += BITMASK_NUMBER; } } }
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); } }
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) { 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(); }
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 != 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(); }