Example #1
0
 private void Chop(TrackEvent clip, Timecode offset)
 {
     while (clip.Length.FrameCount > 1)
     {
         clip = clip.Split(offset);
     }
 }
        private void SplitEvent()
        {
            List <TrackEvent> Events = myVegas.Project.GetSelectedEvents();

            if (Events.Count == 0)
            {
                return;
            }

            using (var undo = new UndoBlock("Split Events by MetaTakes"))
            {
                foreach (TrackEvent ev in Events)
                {
                    TrackEvent curEv = ev;
                    foreach (MediaMarker mk in ev.ActiveTake.Media.Markers)
                    {
                        if (curEv == null)
                        {
                            break;                             // dun goofed
                        }
                        var mmk = new MetaMarker(mk, curEv);

                        if (!mmk.IsWithinEventBounds)
                        {
                            continue;
                        }
                        curEv = curEv.Split(mmk.GlobalMarkerOffset);
                    }
                }
            }
        }
Example #3
0
        //Splits track event at a global timecode, keeps the right piece, discards the left piece
        public void SplitAndKeepRight(ref TrackEvent trackEvent, Timecode globalLocation)
        {
            TrackEvent rightVideoEvent = trackEvent.Split(globalLocation - trackEvent.Start);
            TrackEvent leftVideoEvent  = trackEvent;

            if (leftVideoEvent != null)
            {
                trackEvent.Track.Events.Remove(leftVideoEvent);
            }
            trackEvent = rightVideoEvent;
        }
Example #4
0
        //Split a track event at a global location, and creating new groups if splitGroups = true
        public TrackEvent Split(TrackEvent trackEvent, Timecode splitLocation, bool splitGroups)
        {
            TrackEventGroup trackEventGroup = trackEvent.Group;

            //If not splitting groups or not in a group, then perform split on event and return
            if (!splitGroups || trackEventGroup == null)
            {
                return(trackEvent.Split(splitLocation - trackEvent.Start));
            }

            //Create new group to hold split events
            TrackEventGroup splitGroup = new TrackEventGroup();

            vegas.Project.Groups.Add(splitGroup);

            //Reference to splitEvent of trackEvent
            TrackEvent returnSplitEvent = null;

            //Split every track event in the group
            foreach (TrackEvent trackEventInGroup in trackEventGroup)
            {
                //If splitLocation splits the track, then split it
                if (IsTimecodeInTrackEvent(trackEventInGroup, splitLocation))
                {
                    TrackEvent splitEvent = trackEventInGroup.Split(splitLocation - trackEventInGroup.Start);

                    //remove the splitEvent from group, and add it to splitGroup
                    trackEventGroup.Remove(splitEvent);
                    splitGroup.Add(splitEvent);

                    //if this track is the trackEvent in the parameter, then return it's split event
                    if (trackEventInGroup == trackEvent)
                    {
                        returnSplitEvent = splitEvent;
                    }
                }
                //If splitLocation comes before the track, then move the track to splitGroup
                else if (IsTimecodeBeforeTrackEvent(trackEventInGroup, splitLocation))
                {
                    //remove the trackEventInGroup from group, and add it to splitGroup
                    trackEventGroup.Remove(trackEventInGroup);
                    splitGroup.Add(trackEventInGroup);
                }
            }

            return(returnSplitEvent);
        }
        // Adds media event to track at specified start
        TrackEvent AddMedia(Project project, string mediaPath, int trackIndex, Timecode start, Timecode length)
        {
            Media      media             = Media.CreateInstance(project, mediaPath);
            Track      track             = project.Tracks[trackIndex];
            TrackEvent currentTrackEvent = null;

            if (track.MediaType == MediaType.Video)
            {
                // If cursor isn't over an event on the track, simply add it to track
                if ((currentTrackEvent = FindTrack(project, start, trackIndex)) is null)
                {
                    ;
                }
                // If cursor is over an event on the track, remove the portion of that event from where
                // the cursor is to where the next event starts
                else
                {
                    // When an event is split, the left half is the original event, the right split is a new event
                    TrackEvent rightSplit = currentTrackEvent.Split(start - currentTrackEvent.Start); // offset from start
                    // rightSplit is null when you try the split right where a track begins, this if
                    // statement handles that
                    if (rightSplit is null)
                    {
                        length = currentTrackEvent.Length;
                        track.Events.Remove(currentTrackEvent);
                    }
                    else
                    {
                        length = rightSplit.Length; // set new length so new video track will fill in old tracks place
                        track.Events.Remove(rightSplit);
                    }
                }
                VideoTrack videoTrack = (VideoTrack)track;
                VideoEvent videoEvent = videoTrack.AddVideoEvent(start, length);
                Take       take       = videoEvent.AddTake(media.GetVideoStreamByIndex(0));
                return(videoEvent);
            }
            else
            {
                return(null);
            }
        }