Пример #1
0
        private void MergeSequences()
        {
            mergeTracks         = Properties.Settings.Default.MergeTracks;
            mergeTracksByName   = Properties.Settings.Default.MergeTracksByName;
            duplicateNameAction = Properties.Settings.Default.DuplicateNameAction;
            mergeEffects        = Properties.Settings.Default.MergeEffects;
            numberFormat        = Properties.Settings.Default.AddNumberFormat;

            bool matched = false;
            int  exIdx   = 0;


            List <Map> groupMap       = new List <Map>();
            List <Map> trackMap       = new List <Map>();
            List <Map> timingMap      = new List <Map>();
            int        newGroupCount  = 0;
            int        newTrackCount  = 0;
            int        newTimingCount = 0;
            bool       found          = false;



            /////////////////////
            //  TIMING GRIDS  //
            ///////////////////
            if (mergeGrids)
            {
                for (int g2Idx = 0; g2Idx < seqTwo.TimingGrids.Count; g2Idx++)
                {
                    TimingGrid sourceGrid = seqTwo.TimingGrids[g2Idx];
                    sourceGrid.timings.Sort();
                    TimingGrid destGrid = null;
                    // Grids treated like tracks.  Merge or Append?
                    if (mergeTracks)
                    {
                        found = true;                         // Reset to default
                        // Search for it, do NOT create if not found
                        destGrid = (TimingGrid)seqNew.Members.Find(sourceGrid.Name, MemberType.TimingGrid, false);
                        if (destGrid == null)                         // no match found
                        {
                            found    = false;
                            destGrid = seqNew.CreateTimingGrid(sourceGrid.Name);
                        }
                        else                         // match found!
                        {
                            // Check for conflicting types and warn user
                            if (sourceGrid.TimingGridType == TimingGridType.FixedGrid)
                            {
                                if (destGrid.TimingGridType == TimingGridType.Freeform)
                                {
                                    GridMismatchError(sourceGrid.Name);
                                }
                            }
                            if (sourceGrid.TimingGridType == TimingGridType.Freeform)
                            {
                                if (destGrid.TimingGridType == TimingGridType.FixedGrid)
                                {
                                    GridMismatchError(sourceGrid.Name);
                                }
                            }
                            // What to do if match is found?
                            if (duplicateNameAction == ACTIONkeepBoth)
                            {
                                destGrid = seqNew.CreateTimingGrid(sourceGrid.Name);
                            }
                            if (duplicateNameAction == ACTIONaddNumber)
                            {
                                destGrid = seqNew.CreateTimingGrid(sourceGrid.Name + " (2)");
                            }
                            if (duplicateNameAction == ACTIONuseSecond)
                            {
                                destGrid.timings.Clear();
                            }
                        }
                    }
                    else                     // Append
                    {
                        destGrid = seqNew.CreateTimingGrid(sourceGrid.Name);
                        destGrid.TimingGridType = sourceGrid.TimingGridType;
                    }                     // Enbd if merge or append

                    // if not found, or any action other than keep first
                    if (!found || (duplicateNameAction != ACTIONkeepFirst))
                    {
                        // Copy type, spacing and timings
                        destGrid.TimingGridType = sourceGrid.TimingGridType;
                        destGrid.spacing        = sourceGrid.spacing;
                        if (destGrid.TimingGridType == TimingGridType.Freeform)
                        {
                            destGrid.CopyTimings(sourceGrid.timings, false);
                        }
                    }
                }         // end loop thru 2nd sequence's timing grids
            }             // if Merge Grids

            ///////////////
            //  TRACKS  //
            /////////////

            if (mergeTracks)
            {
                //foreach (Track track2 in seqTwo.Tracks)
                for (int t2Idx = 0; t2Idx < seqTwo.Tracks.Count; t2Idx++)
                {
                    Track sourceTrack = seqTwo.Tracks[t2Idx];
                    Track destTrack   = null;
                    if (mergeTracksByNumber)
                    {
                        // Merge by number or name?
                        // If by number, do we even have that many in the destination?
                        if (t2Idx < seqNew.Tracks.Count)
                        {
                            destTrack = seqNew.Tracks[t2Idx];
                        }
                        else
                        {
                            // Not enough, make one
                            destTrack = seqNew.CreateTrack(sourceTrack.Name);
                        }
                    }
                    if (mergeTracksByName)
                    {
                        found     = true;                     // reset to default
                        destTrack = (Track)seqNew.Members.Find(sourceTrack.Name, MemberType.Track, false);
                        if (destTrack == null)                // no matching name found
                        {
                            found     = false;
                            destTrack = seqNew.CreateTrack(sourceTrack.Name);
                        }
                        else                         // matching name found!
                        {
                        }
                    }
                    if (appendTracks)
                    {
                        destTrack = seqNew.CreateTrack(sourceTrack.Name);
                    }
                    MergeMembers(destTrack.Members, sourceTrack.Members);

                    Console.WriteLine(destTrack.Name);
                }
            }
        }