Beispiel #1
0
        // Makes sure that there are enough tracks, starting with 'startTrack'.
        private static List <ITrack> GetOrCreateOrderedTracks(ITimeline timeline, int numTracksToFind, ITrack startTrack)
        {
            var orderedTracks = new List <ITrack>(numTracksToFind);

            if (numTracksToFind <= 0)
            {
                return(orderedTracks);
            }

            IGroup lastGroup = null;

            foreach (IGroup group in timeline.Groups)
            {
                foreach (ITrack track in group.Tracks)
                {
                    if (orderedTracks.Count > 0 || track == startTrack)
                    {
                        orderedTracks.Add(track);
                        lastGroup = group;
                    }
                    if (orderedTracks.Count == numTracksToFind)
                    {
                        return(orderedTracks);
                    }
                }
            }
            if (lastGroup == null)
            {
                lastGroup = timeline.CreateGroup();
                timeline.Groups.Add(lastGroup);
            }
            while (orderedTracks.Count < numTracksToFind)
            {
                ITrack newTrack = lastGroup.CreateTrack();
                lastGroup.Tracks.Add(newTrack);
                orderedTracks.Add(newTrack);
            }
            return(orderedTracks);
        }
Beispiel #2
0
        private void Insert(ITimelineObject droppedItem, ITimelineObject dropTarget)
        {
            if (m_timelineDocument == null)
            {
                return;
            }

            // TimelineControl maintains target group and track
            ITimeline targetTimeline = m_timelineDocument.Timeline;
            IGroup    targetGroup    = m_timelineControl.TargetGroup != null ? (IGroup)m_timelineControl.TargetGroup.Last : null;
            ITrack    targetTrack    = m_timelineControl.TargetTrack != null ? (ITrack)m_timelineControl.TargetTrack.Last : null;

            // in case of drag and drop, use drop target instead
            if (dropTarget != null)
            {
                GetTrackAndGroup(dropTarget, out targetTrack, out targetGroup);
            }

            // Work up from insertion point to get target key/interval, track, group, timeline
            ITimelineReference reference = droppedItem.As <ITimelineReference>();

            if (reference != null)
            {
                ((Timeline)targetTimeline).AddReference(reference);
                return;
            }

            IGroup group = droppedItem.As <IGroup>();

            if (group != null)
            {
                // if this is a new group, add a default track
                if (group.Tracks.Count == 0)
                {
                    ITrack emptyTrack = group.CreateTrack();
                    if (emptyTrack != null)
                    {
                        group.Tracks.Add(emptyTrack);
                    }
                }

                targetTimeline.Groups.Add(group);
                return;
            }

            IMarker marker = droppedItem.As <IMarker>();

            if (marker != null)
            {
                targetTimeline.Markers.Add(marker);
                return;
            }

            // Must be track or interval; get the target group, or create one.
            ITrack track = droppedItem.As <ITrack>();
            IEvent ev    = droppedItem.As <IEvent>();

            if (track != null ||
                ev != null)
            {
                IList <IGroup> groups = targetTimeline.Groups;
                if (targetGroup == null)
                {
                    targetGroup = targetTimeline.CreateGroup();
                    groups.Add(targetGroup);
                }

                if (track != null)
                {
                    targetGroup.Tracks.Add(track);
                }
                else //if (ev != null)
                {
                    // interval or key; get the target track or create one
                    if (targetTrack == null)
                    {
                        targetTrack = targetGroup.CreateTrack();
                        targetGroup.Tracks.Add(targetTrack);
                    }

                    IInterval interval = droppedItem.As <IInterval>();
                    if (interval != null)
                    {
                        targetTrack.Intervals.Add(interval);
                    }
                    else
                    {
                        IKey key = droppedItem.As <IKey>();
                        if (key != null)
                        {
                            targetTrack.Keys.Add(key);
                        }
                    }
                }
            }
        }