public void FromVegas(Vegas vegas) { try { Track track = vegas.Project.Tracks[0]; float rescale = 0.9f; double new_duration; foreach (TrackEvent curr_event in track.Events) { new_duration = curr_event.Length.ToMilliseconds() * rescale; curr_event.AdjustStartLength(curr_event.Start, Timecode.FromMilliseconds(new_duration), false); } Timecode curr_event_length; Timecode curr_event_start; Timecode next_event_start = Timecode.FromSeconds(0); foreach (TrackEvent curr_event in track.Events) { curr_event_length = curr_event.End; curr_event_start = curr_event.Start; curr_event.AdjustStartLength(next_event_start, curr_event.Length, false); next_event_start = curr_event.End; } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public void FromVegas(Vegas vegas) { try { _vegas = vegas; Track track = vegas.Project.AddVideoTrack(); PlugInNode generator = vegas.Generators.GetChildByName("VEGAS Titles & Text"); foreach (var region in vegas.Project.Regions) { string text = region.Label; VideoEvent e = new VideoEvent(vegas.Project, Timecode.FromMilliseconds(region.Position.ToMilliseconds()), region.Length, null); track.Events.Add(e); e.FadeIn.Curve = CurveType.Linear; e.FadeOut.Curve = CurveType.Linear; text = HandleAegisubTags(e, text); CreateTextPreset("RegionsToTextbox", "Impress BT", 14, 0.5, 0.08, 10.0, text); Media media = new Media(generator, "RegionsToTextbox"); MediaStream stream = media.Streams[0]; Take take = new Take(stream); e.Takes.Add(take); } } catch (Exception e) { vegas.ShowError(e); } }
public void FromVegas(Vegas vegas) { myVegas = vegas; Timecode fourF = Timecode.FromMilliseconds(133); Timecode sixF = Timecode.FromMilliseconds(200); foreach (Track track in myVegas.Project.Tracks) { if (track.IsVideo()) { foreach (TrackEvent evnt in track.Events) { if (evnt.Selected) { VideoEvent videoEvent = (VideoEvent)evnt; Envelope VelEnv = new Envelope(EnvelopeType.Velocity); videoEvent.Envelopes.Add(VelEnv); Timecode t = evnt.Start - evnt.Start; EnvelopePoint a = VelEnv.Points.GetPointAtX(t); if (a != null) { a.Y = 1.5; } ; EnvelopePoint bTest = VelEnv.Points.GetPointAtX(fourF); if (bTest == null) { EnvelopePoint b = new EnvelopePoint(fourF, 0.50); VelEnv.Points.Add(b); } ; a.Curve = CurveType.Fast; EnvelopePoint cTest = VelEnv.Points.GetPointAtX(evnt.Length - sixF); if (cTest == null) { EnvelopePoint c = new EnvelopePoint(evnt.Length - fourF, 0.50); VelEnv.Points.Add(c); c.Curve = CurveType.Slow; } ; EnvelopePoint dTest = VelEnv.Points.GetPointAtX(evnt.Length); if (dTest == null) { EnvelopePoint d = new EnvelopePoint(evnt.Length, 10); VelEnv.Points.Add(d); } ; } } } } }
string GetSRTLine(int lineNumber, Timecode start, Timecode end, string text) { string line = string.Empty; line += lineNumber + Environment.NewLine; line += Timecode.FromMilliseconds(start.ToMilliseconds()).ToString(SRT_TIME_FORMAT) + " --> " + end.ToString(SRT_TIME_FORMAT) + Environment.NewLine; line += Regex.Replace(text, "\\[br\\]", Environment.NewLine); return(line); }
public static void PanFromCenterToLeft(Vegas vegas, VideoEvent videoEvent) { using (UndoBlock undo = new UndoBlock("Add pan/crop")) { VideoMotionKeyframe key0 = videoEvent.VideoMotion.Keyframes[0]; int videoWidth = vegas.Project.Video.Width; VideoMotionKeyframe key1 = new VideoMotionKeyframe(Timecode.FromMilliseconds(Config.splitOffset)); videoEvent.VideoMotion.Keyframes.Add(key1); key1.MoveBy(new VideoMotionVertex(videoWidth, 0)); } }
public void FromVegas(Vegas vegas) { List <TrackEvent> events = GetAppropriateTrackEvents(vegas.Project); int milliDelay = int.Parse(GetUserInput("Milliseconds Delay?", "10000")); int milliCross = int.Parse(GetUserInput("Milliseconds transition?", "2000")); //set first length event events[0].Length = Timecode.FromMilliseconds(milliDelay); //set remaining events for (int i = 1; i < events.Count; i++) { events[i].Start = events[i - 1].End - Timecode.FromMilliseconds(milliCross); events[i].Length = Timecode.FromMilliseconds(milliDelay); } }
public void FromVegas(Vegas vegas) { foreach (Track track in vegas.Project.Tracks) { Timecode currentTimecode = Timecode.FromMilliseconds(0); foreach (TrackEvent videoEvent in track.Events) { if (videoEvent.Selected) { Timecode newEnd = currentTimecode + Timecode.FromMilliseconds(1000); videoEvent.Start = currentTimecode; videoEvent.End = newEnd; currentTimecode = newEnd; } } } }
public void FromVegas(Vegas vegas) { List <VideoEvent> events = new List <VideoEvent>(); AddSelectedVideoEvents(vegas, events); Timecode currentTimecode = Timecode.FromMilliseconds(0); Timecode forceLength = Timecode.FromMilliseconds(40); Timecode overlapLength = Timecode.FromMilliseconds(40); foreach (VideoEvent videoEvent in events) { Timecode newEnd = currentTimecode + forceLength; videoEvent.Start = currentTimecode; videoEvent.End = newEnd; currentTimecode = currentTimecode + overlapLength; } }
public static void Execute(Vegas vegas) { var videoTracks = VegasHelper.GetTracks <VideoTrack>(vegas, 1, 1, true); var selectedTrackEvents = VegasHelper.GetTrackEvents(videoTracks); var startingPosition = selectedTrackEvents[0].Start; var trackEventInfos = new List <TrackEventInfo>(); foreach (var selectedTrackEvent in selectedTrackEvents) { trackEventInfos.Add(new TrackEventInfo(selectedTrackEvent)); } //order the list trackEventInfos.Sort((info1, info2) => info1.FileTimestamp.CompareTo(info2.FileTimestamp)); var baseTimeStamp = trackEventInfos[0].FileTimestamp; using (var undo = new UndoBlock("Order Events By Name And Time")) { //update order of the events foreach (var selectedTrackEvent in trackEventInfos) { var currentPosition = startingPosition + Timecode.FromMilliseconds( (selectedTrackEvent.FileTimestamp - baseTimeStamp).TotalMilliseconds); if (selectedTrackEvent.TrackEvent.IsGrouped) { foreach (var groupedTrackEvents in selectedTrackEvent.TrackEvent.Group) { groupedTrackEvents.Start = currentPosition; } } else { selectedTrackEvent.TrackEvent.Start = currentPosition; } } } }
private Region Convert(TimeSpan start, TimeSpan end, string text) { Timecode position = Timecode.FromMilliseconds(start.TotalMilliseconds + 360); Timecode length = Timecode.FromMilliseconds((end - start).TotalMilliseconds); TimeSpan _; if (!TimeSpan.TryParseExact(position.ToPositionString(), VEGAS_TIME_FORMAT, null, out _) && !TimeSpan.TryParseExact(position.ToPositionString(), VEGAS_TIME_FORMAT_COMMA, null, out _)) { throw new VegasException("Incorrect time format!", "Can't import subtitles because your time format is incorrect. Please change your time format to \"Time\" (hh:mm:ss.fff)."); } if (length.ToMilliseconds() > 0 && !string.IsNullOrWhiteSpace(text)) { return(new Region(position, length, text.Trim())); } else { return(null); } }
public void FromVegas(Vegas vegas) { Timecode FadeInTimecode = Timecode.FromMilliseconds(FadeInMS); Timecode FadeOutTimecode = Timecode.FromMilliseconds(FadeOutMS); foreach (Track track in vegas.Project.Tracks) { if (track.Selected) { foreach (TrackEvent evnt in track.Events) { if (evnt.Selected) { evnt.FadeIn.Length = FadeInTimecode; evnt.FadeIn.Curve = FadeInCurve; evnt.FadeOut.Length = FadeOutTimecode; evnt.FadeOut.Curve = FadeOutCurve; } } } } }
public void FromVegas(Vegas vegas) { if (vegas.Project.Length.ToMilliseconds() == 0) { return; } SetDllDirectory(VegasDir + "\\Script Depends"); string RegKey = "HKEY_CURRENT_USER\\Software\\Sony Creative Software\\Vegas Pro\\frameserver"; int AddBuffer = 1; int RenderLoop = 1; string outputDirectory = ""; try { AddBuffer = (int)Registry.GetValue(RegKey, "AddBuffer", 1); RenderLoop = (int)Registry.GetValue(RegKey, "RenderLoopRegion", 1); outputDirectory = (string)Registry.GetValue(RegKey, "TempDir", ""); } catch {} string outDirDefualt = Environment.GetEnvironmentVariable("TEMP") + "\\frameserver"; if (outputDirectory == "") { outputDirectory = outDirDefualt; } if (!Directory.Exists(outputDirectory)) { try { Directory.CreateDirectory(outputDirectory); } catch { outputDirectory = outDirDefualt; Directory.CreateDirectory(outputDirectory); } } // Start virtual file system, AviSynth and HandBrake ahktextdll(Unzip(Convert.FromBase64String(StartScriptData)), "", ""); while (!ahkReady()) { Thread.Sleep(100); } ahkassign("TempFileDir", outputDirectory); ahkassign("AddBuffer", AddBuffer.ToString()); ahkassign("RegKey", RegKey); ahkassign("VegasDir", VegasDir); ahkPause("Off"); Regex videoRendererRegexp = new Regex(@"DebugMode FrameServer", RegexOptions.Compiled | RegexOptions.IgnoreCase); Regex videoTemplateRegexp = new Regex(@"Project Default", RegexOptions.Compiled | RegexOptions.IgnoreCase); try { //Add an empty event to first video track to solve frameserver audio bug if (AddBuffer > 0) { foreach (Track CurTrack in vegas.Project.Tracks) { if (CurTrack.IsVideo()) { TargetTrack = CurTrack; emptyEvent = new VideoEvent(vegas.Project, vegas.Project.Length, Timecode.FromMilliseconds(1000), null); CurTrack.Events.Add(emptyEvent); break; } } } // Check timeline's loop-region Timecode renderStart = new Timecode(); Timecode renderLength = vegas.Project.Length; if (RenderLoop > 0) { renderStart = vegas.SelectionStart; if (AddBuffer > 0) { renderLength = vegas.SelectionLength + Timecode.FromMilliseconds(1000); } else { renderLength = vegas.SelectionLength; } } //Define export path and file name string projDir, projName, videoOutputFile; string projFile = vegas.Project.FilePath; if ((null == projFile) || (0 == projFile.Length)) { projDir = ""; projName = "Untitled"; } else { projDir = Path.GetDirectoryName(projFile) + Path.DirectorySeparatorChar; projName = Path.GetFileNameWithoutExtension(projFile); } videoOutputFile = outputDirectory + "\\" + OutFileName + ".avi"; if (null == videoOutputFile) { throw new Exception("Process terminated"); } Renderer aviRenderer = FindRenderer(videoRendererRegexp, vegas); if (null == aviRenderer) { throw new Exception("Could not find DebugMode FrameServer"); } // Start export RenderTemplate videoTemplate = FindRenderTemplate(aviRenderer, videoTemplateRegexp, vegas); if (null == videoTemplate) { throw new Exception("Could not find the render preset defined by the script"); } RenderStatus renderStatus = vegas.Render(videoOutputFile, videoTemplate, renderStart, renderLength); if (AddBuffer > 0) { TargetTrack.Events.Remove(emptyEvent); } } catch (Exception ex) { if (AddBuffer > 0) { TargetTrack.Events.Remove(emptyEvent); } MessageBox.Show(ex.ToString()); } }
public void FromVegas(Vegas vegas) { var Settings = new Settings(); // ********* Change default script parameters here Settings.FadeTime = 100; // Set fade length here Settings.TimeUnit = TimeUnit.Milliseconds; // Select fade time unit: Milliseconds or Frames Settings.ScriptMode = ScriptMode.AddFades; // AddFades, ChangeFades or RemoveFades Settings.ApplyTo = ApplyTo.Audio; // Type of events to apply the script to: Audio, Video or AudioAndVideo Settings.FadeIn = true; // Apply script to fade-ins Settings.FadeOut = true; // Apply script to fade-outs Settings.ChangeCurveType = false; // // Set to true to be able to apply curve types Settings.FadeInCurveType = CurveType.Fast; // Fade-in curve type: Fast, Linear, Sharp, Slow, Smooth. Vegas's default is Fast Settings.FadeOutCurveType = CurveType.Slow; // Fade-out curve type: Fast, Linear, Sharp, Slow, Smooth. Vegas's default is Slow Settings.ShowDialog = true; // Show dialog window or apply the above settings without user prompt // ********* Do no change anything below unless you know what you're doing Settings.Vegas = vegas; Timecode FadeAmount = new Timecode(); Timecode ZeroTime = new Timecode(); if (Settings.ShowDialog) { FaderForm form = new FaderForm(Settings); var dialogResult = form.ShowDialog(); if (dialogResult != DialogResult.OK) { return; } } if (Settings.TimeUnit == TimeUnit.Milliseconds) { FadeAmount = Timecode.FromMilliseconds(Settings.FadeTime); } if (Settings.TimeUnit == TimeUnit.Frames) { FadeAmount = Timecode.FromFrames(Settings.FadeTime); } if (Settings.FadeOut == false && Settings.FadeIn == false) { return; } Action <Fade> ApplyFade = (fade) => { if (Settings.ScriptMode == ScriptMode.AddFades) { fade.Length = FadeAmount; } if (Settings.ScriptMode == ScriptMode.RemoveFades) { fade.Length = ZeroTime; } }; try { foreach (var track in vegas.Project.Tracks) { foreach (var trackEvent in track.Events) { if (trackEvent.Selected) { if (trackEvent.IsVideo() && Settings.ApplyTo == ApplyTo.Audio) { continue; } if (trackEvent.IsAudio() && Settings.ApplyTo == ApplyTo.Video) { continue; } if (Settings.FadeIn) { ApplyFade(trackEvent.FadeIn); } if (Settings.ScriptMode != ScriptMode.RemoveFades && Settings.ChangeCurveType) { trackEvent.FadeIn.Curve = Settings.FadeInCurveType; } if (Settings.FadeOut) { ApplyFade(trackEvent.FadeOut); } if (Settings.ScriptMode != ScriptMode.RemoveFades && Settings.ChangeCurveType) { trackEvent.FadeOut.Curve = Settings.FadeOutCurveType; } } } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation); } }
public void FromVegas(Vegas vegas) { Project proj = vegas.Project; /*foreach (Track track in proj.Tracks) * { * //Audio detection for later on... * if(track.Name == "Sync"){ * //MessageBox.Show("Audio a Sync detectado"); * foreach (TrackEvent trackEvent in track.Events) * { * if(trackEvent.MediaType == MediaType.Audio){ * * } * } * } * * }*/ foreach (Track track in proj.Tracks) { foreach (TrackEvent trackEvent in track.Events) { if (trackEvent.MediaType == MediaType.Video && trackEvent.Selected) { VideoEvent vevnt = (VideoEvent)trackEvent; Envelopes vevntEnv = vevnt.Envelopes; if (!vevntEnv.HasEnvelope(EnvelopeType.Velocity)) // Comprobamos si el video tiene envolvente { Envelope envelope = new Envelope(EnvelopeType.Velocity); vevntEnv.Add(envelope); } Envelope sensitivity = vevntEnv.FindByType(EnvelopeType.Velocity); sensitivity.Points.Clear(); Timecode timeFirst = trackEvent.Start; //Inicio del clip en milisegundos. Timecode timeLast = trackEvent.End; //Fin del clip en milisegundos. sensitivity.Points.GetPointAtX(Timecode.FromMilliseconds(0)).Y = 3; //Modificamos el valor del punto inicial foreach (Marker marker in proj.Markers) //Recorremos todos los marcadores { if (marker.Position > timeFirst && marker.Position < timeLast && marker.Label == "") // Miramos si el marcador esta dentro del video { if (sensitivity.Points.GetPointAtX(marker.Position - timeFirst) == null) // Comprobamos que no exista ya un punto en dicha posicion. { EnvelopePoint point = new EnvelopePoint(marker.Position - timeFirst, 0.15); //Creamos un nuevo punto en el marcador sensitivity.Points.Add(point); } } } EnvelopePoint pointEnd = new EnvelopePoint(timeLast, 3); //Añadimos el punto final sensitivity.Points.Add(pointEnd); } } } }
private void EventPosInterDnSt_Invoke(object sender, EventArgs e) { EventPosInterChange(EventPositionModifyMethod.Adjust, Timecode.FromMilliseconds(-250)); }
private void EventPosInterChange(EventPositionModifyMethod Method) { EventPosInterChange(Method, Timecode.FromMilliseconds(0)); }
public void FromVegas(Vegas vegas) { // select a midi file MessageBox.Show("请选择一个MIDI文件。"); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "*.mid|*.mid|所有文件|*.*"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { midiName = openFileDialog.FileName; } else { return; } MidiFile midi = new MidiFile(midiName); // generate statistics of each midi track String[] trackInfo = new String[midi.Events.Tracks]; int ticksPerQuarter = midi.DeltaTicksPerQuarterNote; double msPerQuarter = 0; for (int i = 0; i < midi.Events.Tracks; i++) { String info1 = "轨道 " + i.ToString() + ": "; String info2 = ""; int notesCount = 0; String info3 = "起音 "; foreach (MidiEvent midiEvent in midi.Events[i]) { if ((midiEvent is NoteEvent) && !(midiEvent is NoteOnEvent)) { NoteEvent noteEvent = midiEvent as NoteEvent; if (notesCount == 0) { info3 = info3 + noteEvent.NoteName; } notesCount++; } if ((midiEvent is PatchChangeEvent) && info2.Length == 0) { PatchChangeEvent patchEvent = midiEvent as PatchChangeEvent; for (int j = 4; j < patchEvent.ToString().Split(' ').Length; j++) { info2 += patchEvent.ToString().Split(' ')[j]; } } if ((midiEvent is TempoEvent) && msPerQuarter == 0) { TempoEvent tempoEvent = midiEvent as TempoEvent; msPerQuarter = Convert.ToDouble(tempoEvent.MicrosecondsPerQuarterNote) / 1000; } } trackInfo[i] = info1 + info2 + "; 音符数: " + notesCount.ToString() + "; " + info3; } // select a video clip MessageBox.Show("请选择一个视频或图片素材片段。"); openFileDialog.Filter = "所有文件|*.*"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { clipName = openFileDialog.FileName; } else { return; } Media media = new Media(clipName); double mediaLength = media.Length.ToMilliseconds(); // start configuration Form2 configForm = new Form2(); for (int i = 1; i < midi.Events.Tracks; i++) { configForm.comboBox1.Items.Add(trackInfo[i]); } configForm.comboBox1.SelectedIndex = 0; Application.Run(configForm); // apply condiguration for (int i = 1; i < midi.Events.Tracks; i++) { if (trackInfo[i] == configForm.comboBox1.SelectedItem.ToString()) { midiTrack = i; } } sheetWidth = int.Parse(configForm.width); sheetPosition = int.Parse(configForm.position); sheetGap = int.Parse(configForm.gap); if (configForm.comboBox2.Text == "2/4") { sheetTempo = 2; } if (configForm.comboBox2.Text == "3/4") { sheetTempo = 3; } if (configForm.comboBox3.Text == "低音") { sheetCelf = 1; } // start processing MIDI VideoTrack[] noteTracks = new VideoTrack[100]; int trackCount = -1; int trackPointer = 0; double barStartTime = 0; double barLength = msPerQuarter * sheetTempo; foreach (MidiEvent midiEvent in midi.Events[midiTrack]) { if (midiEvent is NoteOnEvent) { NoteEvent noteEvent = midiEvent as NoteEvent; NoteOnEvent noteOnEvent = midiEvent as NoteOnEvent; double startTime = midiEvent.AbsoluteTime * msPerQuarter / ticksPerQuarter; double duration = noteOnEvent.NoteLength * msPerQuarter / ticksPerQuarter; int pitch = noteEvent.NoteNumber; // next page while (startTime >= barStartTime + barLength) { barStartTime = barStartTime + barLength; trackPointer = 0; } // generate video events if (trackPointer > trackCount) { trackCount = trackCount + 1; noteTracks[trackCount] = vegas.Project.AddVideoTrack(); } VideoEvent videoEvent = noteTracks[trackPointer].AddVideoEvent(Timecode.FromMilliseconds(startTime), Timecode.FromMilliseconds(barStartTime + barLength - startTime)); Take take = videoEvent.AddTake(media.GetVideoStreamByIndex(0)); TrackEvent trackEvent = videoEvent as TrackEvent; trackEvent.Loop = true; TrackMotionKeyframe keyFrame = noteTracks[trackPointer].TrackMotion.InsertMotionKeyframe(Timecode.FromMilliseconds(startTime)); keyFrame.Type = VideoKeyframeType.Hold; keyFrame.Width = sheetGap * 2 * vegas.Project.Video.Width / vegas.Project.Video.Height; keyFrame.Height = sheetGap * 2; keyFrame.PositionX = -sheetWidth / 2 + sheetWidth / barLength * (startTime - barStartTime); int octave = pitch / 12; int line = pitchMap[pitch % 12]; keyFrame.PositionY = sheetPosition - sheetGap * 3 + (octave - 5) * sheetGap * 3.5 + line * sheetGap * 0.5 + sheetCelf * 12; trackPointer = trackPointer + 1; } } }
public static void RemoveSelection(this Vegas vegas) { vegas.Cursor += Timecode.FromMilliseconds(1); vegas.Cursor -= Timecode.FromMilliseconds(1); vegas.Project.ForEachEvent((tEvent) => tEvent.Selected = false); }
public void FromVegas(Vegas vegas) { Settings = new Settings(); // ********* Change default script paremeters here Settings.CrossFadeLength = 500; // Set default crossfade lenght here Settings.TimeUnit = TimeUnit.Milliseconds; // Set crossfade's time unit: milliseconds or frames Settings.ScriptMode = ScriptMode.CreateNewCrossfades; Settings.ChangeCurveType = false; // Set to true to be able to change curve types Settings.LeftCurveType = CurveType.Slow; // Left curve type: Fast, Linear, Sharp, Slow, Smooth. Vegas's default is Slow for audio and Smooth for video Settings.RightCurveType = CurveType.Fast; // Right curve type: Fast, Linear, Sharp, Slow, Smooth. Vegas's default is Fast for audio and Smooth for video Settings.TransitionMode = TransitionMode.NoTransition; // Add/Remove transision to video events. Chose NoTransition, AddTransition, RemoveTransition of Scanning for available transition presets for the first time may be slow Settings.AllowLoops = false; // Allow crossfades to expand beyond clip's original length Settings.ShowDialog = true; // Show dialog window or run the script with these settings without user prompt Settings.TransitionAndPresetName = ""; //Put transition and preset names here, e.g. "VEGAS Portals\\Mondrian" if you use the script non-interactively by changing Settings.ShowDialog to true // ********* Do no change anything below unless you know what you're doing Settings.Vegas = vegas; try { if (Settings.ShowDialog) { var form = new CrossFaderForm(Settings); var dialogResult = form.ShowDialog(); if (dialogResult != DialogResult.OK) { return; } } if (Settings.TransitionMode == TransitionMode.AddTransition && Settings.ShowDialog == false && string.IsNullOrEmpty(Settings.TransitionAndPresetName)) { throw new Exception("The script needs to know what transition preset to use. To apply video transitions in silent mode edit TransitionAndPresetName settings property, for example:\n\n" + "Settings.TransitionAndPresetName = \"VEGAS Portals\\\\Mondrian\";"); } if (Settings.TransitionMode == TransitionMode.AddTransition) { FindTransition(); } Timecode CrossFade = null; Timecode HalfCrossFade = null; switch (Settings.TimeUnit) { case TimeUnit.Milliseconds: CrossFade = Timecode.FromMilliseconds(Settings.CrossFadeLength); HalfCrossFade = Timecode.FromMilliseconds(Settings.CrossFadeLength / 2); break; case TimeUnit.Frames: CrossFade = Timecode.FromFrames(Settings.CrossFadeLength); HalfCrossFade = Timecode.FromFrames(Settings.CrossFadeLength / 2); break; } foreach (Track track in vegas.Project.Tracks) { foreach (TrackEvent trackEvent in track.Events) { if (trackEvent.Selected) { switch (Settings.ScriptMode) { case ScriptMode.CreateNewCrossfades: CreateCrossFades(trackEvent, track, HalfCrossFade); break; case ScriptMode.ChangeExistingCrossfades: ChangeExistingCrossFades(trackEvent, track); break; case ScriptMode.RemoveCrossfades: RemoveCrossFades(trackEvent, track); break; } if (trackEvent.IsVideo()) { switch (Settings.TransitionMode) { case TransitionMode.AddTransition: AddTransition(trackEvent); break; case TransitionMode.RemoveTransition: trackEvent.FadeIn.RemoveTransition(); break; } } } } } } catch (Exception ex) { vegas.ShowError(ex); } }
/// /// Implementation /// internal void RegionCreateFromEvents_Invoked(object sender, EventArgs e) { var eventgroups = myVegas.Project.GetEventGroups(); var regions = (myVegas.Project.Regions.Count != 0) ? new List <ScriptPortal.Vegas.Region>(myVegas.Project.Regions) : new List <ScriptPortal.Vegas.Region>(); bool selectionSet = false; if (myVegas.SelectionLength != Timecode.FromMilliseconds(0)) { if (myVegas.Cursor == myVegas.SelectionStart || myVegas.Cursor == myVegas.SelectionStart + myVegas.SelectionLength) { selectionSet = true; } } using (var undo = new UndoBlock("Create regions")) { foreach (var egrp in eventgroups) { Timecode groupStart = null; Timecode groupEnd = null; foreach (var ev in egrp) { if (groupStart == null || ev.Start < groupStart) { groupStart = ev.Start; } if (groupEnd == null || ev.End > groupEnd) { groupEnd = ev.End; } } // skip outside seletion if (selectionSet) { if (groupEnd >= (myVegas.SelectionStart + myVegas.SelectionLength) || groupStart <= myVegas.SelectionStart) { continue; } } // don't write inside existing regions if (regions.Any(reg => reg.ContainsTime(groupStart, (groupEnd - groupStart)))) { continue; } // don't surround existing regions if (regions.HasInside(groupStart, groupEnd)) { continue; } var NewRegion = new ScriptPortal.Vegas.Region(groupStart, (groupEnd - groupStart)); myVegas.Project.Regions.Add(NewRegion); } } }
public void FromVegas(Vegas vegas) { // select a midi file MessageBox.Show("请选择一个MIDI文件。"); OpenFileDialog openFileDialog = new OpenFileDialog(); openFileDialog.Filter = "*.mid|*.mid|所有文件|*.*"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { midiName = openFileDialog.FileName; } else { return; } MidiFile midi = new MidiFile(midiName); // generate statistics of each midi track String[] trackInfo = new String[midi.Events.Tracks]; int ticksPerQuarter = midi.DeltaTicksPerQuarterNote; double msPerQuarter = 0; for (int i = 0; i < midi.Events.Tracks; i++) { String info1 = "轨道 " + i.ToString() + ": "; String info2 = ""; int notesCount = 0; String info3 = "起音 "; foreach (MidiEvent midiEvent in midi.Events[i]) { if ((midiEvent is NoteEvent) && !(midiEvent is NoteOnEvent)) { NoteEvent noteEvent = midiEvent as NoteEvent; if (notesCount == 0) { info3 = info3 + noteEvent.NoteName; } notesCount++; } if ((midiEvent is PatchChangeEvent) && info2.Length == 0) { PatchChangeEvent patchEvent = midiEvent as PatchChangeEvent; for (int j = 4; j < patchEvent.ToString().Split(' ').Length; j++) { info2 += patchEvent.ToString().Split(' ')[j]; } } if ((midiEvent is TempoEvent) && msPerQuarter == 0) { TempoEvent tempoEvent = midiEvent as TempoEvent; msPerQuarter = Convert.ToDouble(tempoEvent.MicrosecondsPerQuarterNote) / 1000; } } trackInfo[i] = info1 + info2 + "; 音符数: " + notesCount.ToString() + "; " + info3; } // select a video clip MessageBox.Show("请选择一个视频或音频素材片段。"); openFileDialog.Filter = "所有文件|*.*"; openFileDialog.RestoreDirectory = true; openFileDialog.FilterIndex = 1; if (openFileDialog.ShowDialog() == DialogResult.OK) { clipName = openFileDialog.FileName; } else { return; } Media media = new Media(clipName); double mediaLength = media.Length.ToMilliseconds(); // start configuration ConfigForm configForm = new ConfigForm(); for (int i = 0; i < midi.Events.Tracks; i++) { configForm.comboBoxTrack.Items.Add(trackInfo[i]); } configForm.comboBoxTrack.SelectedIndex = 0; Application.Run(configForm); // apply configuration aconfig = configForm.checkBoxA.Checked; aconfigNoTune = configForm.checkBoxNoTune.Checked; vconfig = configForm.checkBoxV.Checked; vconfigAutoFlip = configForm.checkBoxFlip.Checked; vconfigStartSize = configForm.hScrollBar1.Value; vconfigEndSize = configForm.hScrollBar2.Value; vconfigFadein = configForm.hScrollBar4.Value; vconfigFadeout = configForm.hScrollBar3.Value; aconfigBasePitch = pitchMap[configForm.comboBoxA1.SelectedItem.ToString() + configForm.comboBoxA2.SelectedItem.ToString()]; for (int i = 0; i < midi.Events.Tracks; i++) { if (trackInfo[i] == configForm.comboBoxTrack.SelectedItem.ToString()) { aconfigTrack = i; } } configStartTime = Convert.ToDouble(configForm.startT) * 1000; configEndTime = Convert.ToDouble(configForm.endT) * 1000; // start processing MIDI VideoTrack vTrack = vegas.Project.AddVideoTrack(); AudioTrack[] aTracks = new AudioTrack[20]; double vTrackPosition = 0; int vTrackDirection = 1; double[] aTrackPositions = new double[20]; aTracks[0] = vegas.Project.AddAudioTrack(); aTrackPositions[0] = 0; int aTrackCount = 1; foreach (MidiEvent midiEvent in midi.Events[aconfigTrack]) { if (midiEvent is NoteOnEvent) { NoteEvent noteEvent = midiEvent as NoteEvent; NoteOnEvent noteOnEvent = midiEvent as NoteOnEvent; double startTime = midiEvent.AbsoluteTime * msPerQuarter / ticksPerQuarter; double duration = noteOnEvent.NoteLength * msPerQuarter / ticksPerQuarter; int pitch = noteEvent.NoteNumber; int trackIndex = 0; if (startTime < configStartTime) { continue; } if (startTime > configEndTime) { break; } // generate audio events if (aconfig == true) { while (startTime < aTrackPositions[trackIndex]) { trackIndex++; if (trackIndex == aTrackCount) { aTrackCount++; aTracks[trackIndex] = vegas.Project.AddAudioTrack(); } } AudioEvent audioEvent = aTracks[trackIndex].AddAudioEvent(Timecode.FromMilliseconds(startTime), Timecode.FromMilliseconds(duration)); Take take = audioEvent.AddTake(media.GetAudioStreamByIndex(0)); aTrackPositions[trackIndex] = startTime + duration; TrackEvent trackEvent = audioEvent as TrackEvent; trackEvent.PlaybackRate = mediaLength / duration; trackEvent.Loop = false; // apply pitch shifting if (aconfigNoTune == false) { int pitchDelta = pitch - aconfigBasePitch; if (pitchDelta > 0) { while (pitchDelta > 12) { PlugInNode plugIn0 = vegas.AudioFX.FindChildByName("Pitch Shift"); Effect effect0 = new Effect(plugIn0); audioEvent.Effects.Add(effect0); effect0.Preset = "12"; pitchDelta -= 12; } PlugInNode plugIn = vegas.AudioFX.FindChildByName("Pitch Shift"); Effect effect = new Effect(plugIn); audioEvent.Effects.Add(effect); effect.Preset = pitchDelta.ToString(); } else { while (pitchDelta < -12) { PlugInNode plugIn0 = vegas.AudioFX.FindChildByName("Pitch Shift"); Effect effect0 = new Effect(plugIn0); audioEvent.Effects.Add(effect0); effect0.Preset = "-12"; pitchDelta += 12; } PlugInNode plugIn = vegas.AudioFX.FindChildByName("Pitch Shift"); Effect effect = new Effect(plugIn); audioEvent.Effects.Add(effect); effect.Preset = pitchDelta.ToString(); } } } // generate video events if (vconfig == true) { vTrackPosition = startTime + duration; VideoEvent videoEvent = vTrack.AddVideoEvent(Timecode.FromMilliseconds(startTime), Timecode.FromMilliseconds(duration)); Take take = videoEvent.AddTake(media.GetVideoStreamByIndex(0)); TrackEvent trackEvent = videoEvent as TrackEvent; trackEvent.PlaybackRate = mediaLength / duration; trackEvent.Loop = false; videoEvent.FadeIn.Length = Timecode.FromMilliseconds(duration * vconfigFadein / 100); videoEvent.FadeOut.Length = Timecode.FromMilliseconds(duration * vconfigFadeout / 100); VideoMotionKeyframe key0 = videoEvent.VideoMotion.Keyframes[0]; VideoMotionKeyframe key1 = new VideoMotionKeyframe(Timecode.FromMilliseconds(duration)); videoEvent.VideoMotion.Keyframes.Add(key1); key0.ScaleBy(new VideoMotionVertex((vconfigStartSize / 100) * vTrackDirection, (vconfigStartSize / 100))); key1.ScaleBy(new VideoMotionVertex((vconfigEndSize / 100) * vTrackDirection, (vconfigEndSize / 100))); if (vconfigAutoFlip == true) { vTrackDirection *= -1; } } } } }