Beispiel #1
0
        // This method will create the HashSet of compatibleSnippets based on the ManuallyBlocked / ManuallyLinked entities.
        // The CompatibleSnippets HashSet is only needed for import, or to build the .pcb file.
        public void BuildCompatibleSegmentsSet(PsaiProject project)
        {
            HashSet <Segment> allSegments = project.GetSegmentsOfAllThemes();

            CompatibleSnippetsIds.Clear();
            foreach (Segment targetSegment in allSegments)
            {
                bool compatible                       = false;
                CompatibilityReason reason            = CompatibilityReason.not_set;
                CompatibilityType   compatibilityType = this.GetCompatibilityType(targetSegment, out reason);

                switch (compatibilityType)
                {
                /*
                 * case CompatibilityType.allowed_always:
                 *  compatible = true;
                 *  break;
                 */

                case CompatibilityType.allowed_implicitly:
                    compatible = true;
                    break;

                case CompatibilityType.allowed_manually:
                    compatible = true;
                    break;

                default:
                    compatible = false;
                    break;
                }

                if (compatible)
                {
                    float compatibility;
                    if (targetSegment.Group == this.Group)
                    {
                        compatibility = COMPATIBILITY_PERCENTAGE_SAME_GROUP;
                    }
                    else
                    {
                        compatibility = COMPATIBILITY_PERCENTAGE_OTHER_GROUP;
                    }

                    this.AddCompatibleSnippet(targetSegment, compatibility);
                }
            }
        }
Beispiel #2
0
        // This method will create the HashSet of compatibleSnippets based on the ManuallyBlocked / ManuallyLinked entities.
        // The CompatibleSnippets HashSet is only needed for import, or to build the .pcb file.
        public void BuildCompatibleSegmentsSet(PsaiProject project)
        {
            HashSet<Segment> allSegments = project.GetSegmentsOfAllThemes();

            CompatibleSnippetsIds.Clear();
            foreach (Segment targetSegment in allSegments)
            {
                bool compatible = false;
                CompatibilityReason reason = CompatibilityReason.not_set;
                CompatibilityType compatibilityType = this.GetCompatibilityType(targetSegment, out reason);

                switch (compatibilityType)
                {
                    /*
                    case CompatibilityType.allowed_always:
                        compatible = true;
                        break;
                    */

                    case CompatibilityType.allowed_implicitly:
                        compatible = true;
                        break;

                    case CompatibilityType.allowed_manually:
                        compatible = true;
                        break;

                    default:
                        compatible = false;
                        break;
                }

                if (compatible)
                {
                    float compatibility;
                    if (targetSegment.Group == this.Group)
                        compatibility = COMPATIBILITY_PERCENTAGE_SAME_GROUP;
                    else
                        compatibility = COMPATIBILITY_PERCENTAGE_OTHER_GROUP;

                    this.AddCompatibleSnippet(targetSegment, compatibility);
                }
            }
        }
        // iterates through all entities and assigns a unique running id to each one.
        // Used to compare cloned items.
        /*
        public void AssignUniqueInteralIdForAllEntities()
        {
            int internalId = 0;

            foreach (Theme theme in this.Themes)
            {
                theme.InternalId = internalId;
                internalId++;

                foreach (Group group in theme.Groups)
                {
                    group.InternalId = internalId;
                    internalId++;

                    List<Snippet> groupSnippets = group.Snippets;
                    foreach (Snippet snippet in groupSnippets)
                    {
                        snippet.InternalId = internalId;
                        internalId++;
                    }
                }
            }
        }
        */
        /*
        public PsaiMusicEntity GetPsaiMusicEntityByInternalId(int internalId)
        {
            foreach (Theme theme in this.Themes)
            {

                if (theme.InternalId == internalId)
                    return theme;

                foreach (Group group in theme.Groups)
                {
                    if (group.InternalId == internalId)
                        return group;

                    List<Snippet> groupSnippets = group.Snippets;
                    foreach (Snippet snippet in groupSnippets)
                    {
                        if (snippet.InternalId == internalId)
                            return snippet;
                    }
                }
            }

            return null;
        }
        */
        public object Clone()
        {
            PsaiProject clone = new PsaiProject();
            clone.Properties = (ProjectProperties)this.Properties.Clone();

            //AssignUniqueInteralIdForAllEntities();

            // now we copy all the entities from the tmpTheme to this instance,
            // since the GUI holds a reference to 'this' model.
            clone.Themes.Clear();
            foreach (Theme theme in this.Themes)
            {
                Theme themeClone = (Theme)theme.Clone();
                clone.AddPsaiMusicEntity(themeClone);
            }

            // now that we are sure that each theme with group exists, add the manually blocked and linked
            // entities

            HashSet<Segment> allSnippetsSource = this.GetSegmentsOfAllThemes();
            HashSet<Segment> allSnippetsTarget = clone.GetSegmentsOfAllThemes();

            // create Dictionary that maps all source- to all target themes
            Dictionary<Theme, Theme> themeMap = new Dictionary<Theme, Theme>();
            List<Theme>.Enumerator enumThemeSource = this.Themes.GetEnumerator();
            List<Theme>.Enumerator enumThemeTarget = clone.Themes.GetEnumerator();
            while (enumThemeSource.MoveNext())
            {
                enumThemeTarget.MoveNext();
                themeMap.Add(enumThemeSource.Current, enumThemeTarget.Current);
            }

            // create a Dictionary that maps all source- to  all target snippets
            Dictionary<Segment, Segment> snippetMap = new Dictionary<Segment, Segment>();
            HashSet<Segment>.Enumerator enumSnippetsSource = allSnippetsSource.GetEnumerator();
            HashSet<Segment>.Enumerator enumSnippetsTarget = allSnippetsTarget.GetEnumerator();
            while (enumSnippetsSource.MoveNext())
            {
                enumSnippetsTarget.MoveNext();
                snippetMap.Add(enumSnippetsSource.Current, enumSnippetsTarget.Current);
            }

            Dictionary<Group, Group> groupMap = new Dictionary<Group, Group>();

            foreach (Theme sourceTheme in themeMap.Keys)
            {
                Theme targetTheme = themeMap[sourceTheme];

                // add manually blocked themes
                foreach (Theme manuallyBlockedTheme in sourceTheme.ManuallyBlockedTargetThemes)
                {
                    if (themeMap.Keys.Contains(manuallyBlockedTheme))
                        targetTheme.ManuallyBlockedTargetThemes.Add(themeMap[manuallyBlockedTheme]);
                }

                // fill groupMap
                for (int groupIndex = 0; groupIndex < sourceTheme.Groups.Count; groupIndex++)
                {
                    Group sourceGroup = sourceTheme.Groups[groupIndex];
                    Group targetGroup = targetTheme.Groups[groupIndex];

                    groupMap.Add(sourceGroup, targetGroup);
                }
            }

            // update manually linked and blocked group lists of all groups
            foreach (Group group in groupMap.Keys)
            {
                foreach (Group manuallyLinkedGroup in group.ManuallyLinkedGroups)
                {
                    // deleted groups will not appear in the groupMap, therefore we need to test. // TODO: deleting them before saving would be cleaner
                    if (groupMap.Keys.Contains(manuallyLinkedGroup))
                    {
                        groupMap[group].ManuallyLinkedGroups.Add(groupMap[manuallyLinkedGroup]);
                    }
                }
                foreach (Group manuallyBlockedGroup in group.ManuallyBlockedGroups)
                {
                    if (groupMap.Keys.Contains(manuallyBlockedGroup))
                    {
                        groupMap[group].ManuallyBlockedGroups.Add(groupMap[manuallyBlockedGroup]);
                    }
                }

                foreach (Segment bridgeSnippet in group.ManualBridgeSnippetsOfTargetGroups)
                {
                    if (snippetMap.Keys.Contains(bridgeSnippet))
                    {
                        Segment cloneBridgeSnippet = snippetMap[bridgeSnippet];
                        Group cloneGroup = groupMap[group];
                        HashSet<Segment> cloneBridgeSnippets = cloneGroup.ManualBridgeSnippetsOfTargetGroups;

                        cloneBridgeSnippets.Add(cloneBridgeSnippet);
                    }
                }
            }

            //
            foreach (Segment snippet in allSnippetsSource)
            {
                foreach (Segment blockedSnippet in snippet.ManuallyBlockedSnippets)
                {
                    // deleted snippets will not appear in the snippetMap, so we need to test   // TODO: deleting them before saving would be cleaner
                    if (snippetMap.Keys.Contains(blockedSnippet))
                        snippetMap[snippet].ManuallyBlockedSnippets.Add(snippetMap[blockedSnippet]);
                }

                foreach (Segment linkedSnippet in snippet.ManuallyLinkedSnippets)
                {
                    if (snippetMap.Keys.Contains(linkedSnippet))
                        snippetMap[snippet].ManuallyLinkedSnippets.Add(snippetMap[linkedSnippet]);
                }
            }

            return clone;
        }
Beispiel #4
0
        // iterates through all entities and assigns a unique running id to each one.
        // Used to compare cloned items.

        /*
         * public void AssignUniqueInteralIdForAllEntities()
         * {
         *  int internalId = 0;
         *
         *  foreach (Theme theme in this.Themes)
         *  {
         *      theme.InternalId = internalId;
         *      internalId++;
         *
         *      foreach (Group group in theme.Groups)
         *      {
         *          group.InternalId = internalId;
         *          internalId++;
         *
         *          List<Snippet> groupSnippets = group.Snippets;
         *          foreach (Snippet snippet in groupSnippets)
         *          {
         *              snippet.InternalId = internalId;
         *              internalId++;
         *          }
         *      }
         *  }
         * }
         */

        /*
         * public PsaiMusicEntity GetPsaiMusicEntityByInternalId(int internalId)
         * {
         *  foreach (Theme theme in this.Themes)
         *  {
         *
         *      if (theme.InternalId == internalId)
         *          return theme;
         *
         *      foreach (Group group in theme.Groups)
         *      {
         *          if (group.InternalId == internalId)
         *              return group;
         *
         *          List<Snippet> groupSnippets = group.Snippets;
         *          foreach (Snippet snippet in groupSnippets)
         *          {
         *              if (snippet.InternalId == internalId)
         *                  return snippet;
         *          }
         *      }
         *  }
         *
         *  return null;
         * }
         */


        public object Clone()
        {
            PsaiProject clone = new PsaiProject();

            clone.Properties = (ProjectProperties)this.Properties.Clone();

            //AssignUniqueInteralIdForAllEntities();

            // now we copy all the entities from the tmpTheme to this instance,
            // since the GUI holds a reference to 'this' model.
            clone.Themes.Clear();
            foreach (Theme theme in this.Themes)
            {
                Theme themeClone = (Theme)theme.Clone();
                clone.AddPsaiMusicEntity(themeClone);
            }

            // now that we are sure that each theme with group exists, add the manually blocked and linked
            // entities

            HashSet <Segment> allSnippetsSource = this.GetSegmentsOfAllThemes();
            HashSet <Segment> allSnippetsTarget = clone.GetSegmentsOfAllThemes();

            // create Dictionary that maps all source- to all target themes
            Dictionary <Theme, Theme> themeMap = new Dictionary <Theme, Theme>();

            List <Theme> .Enumerator enumThemeSource = this.Themes.GetEnumerator();
            List <Theme> .Enumerator enumThemeTarget = clone.Themes.GetEnumerator();
            while (enumThemeSource.MoveNext())
            {
                enumThemeTarget.MoveNext();
                themeMap.Add(enumThemeSource.Current, enumThemeTarget.Current);
            }

            // create a Dictionary that maps all source- to  all target snippets
            Dictionary <Segment, Segment> snippetMap = new Dictionary <Segment, Segment>();

            HashSet <Segment> .Enumerator enumSnippetsSource = allSnippetsSource.GetEnumerator();
            HashSet <Segment> .Enumerator enumSnippetsTarget = allSnippetsTarget.GetEnumerator();
            while (enumSnippetsSource.MoveNext())
            {
                enumSnippetsTarget.MoveNext();
                snippetMap.Add(enumSnippetsSource.Current, enumSnippetsTarget.Current);
            }

            Dictionary <Group, Group> groupMap = new Dictionary <Group, Group>();

            foreach (Theme sourceTheme in themeMap.Keys)
            {
                Theme targetTheme = themeMap[sourceTheme];

                // add manually blocked themes
                foreach (Theme manuallyBlockedTheme in sourceTheme.ManuallyBlockedTargetThemes)
                {
                    if (themeMap.Keys.Contains(manuallyBlockedTheme))
                    {
                        targetTheme.ManuallyBlockedTargetThemes.Add(themeMap[manuallyBlockedTheme]);
                    }
                }

                // fill groupMap
                for (int groupIndex = 0; groupIndex < sourceTheme.Groups.Count; groupIndex++)
                {
                    Group sourceGroup = sourceTheme.Groups[groupIndex];
                    Group targetGroup = targetTheme.Groups[groupIndex];

                    groupMap.Add(sourceGroup, targetGroup);
                }
            }


            // update manually linked and blocked group lists of all groups
            foreach (Group group in groupMap.Keys)
            {
                foreach (Group manuallyLinkedGroup in group.ManuallyLinkedGroups)
                {
                    // deleted groups will not appear in the groupMap, therefore we need to test. // TODO: deleting them before saving would be cleaner
                    if (groupMap.Keys.Contains(manuallyLinkedGroup))
                    {
                        groupMap[group].ManuallyLinkedGroups.Add(groupMap[manuallyLinkedGroup]);
                    }
                }
                foreach (Group manuallyBlockedGroup in group.ManuallyBlockedGroups)
                {
                    if (groupMap.Keys.Contains(manuallyBlockedGroup))
                    {
                        groupMap[group].ManuallyBlockedGroups.Add(groupMap[manuallyBlockedGroup]);
                    }
                }

                foreach (Segment bridgeSnippet in group.ManualBridgeSnippetsOfTargetGroups)
                {
                    if (snippetMap.Keys.Contains(bridgeSnippet))
                    {
                        Segment           cloneBridgeSnippet  = snippetMap[bridgeSnippet];
                        Group             cloneGroup          = groupMap[group];
                        HashSet <Segment> cloneBridgeSnippets = cloneGroup.ManualBridgeSnippetsOfTargetGroups;

                        cloneBridgeSnippets.Add(cloneBridgeSnippet);
                    }
                }
            }

            //
            foreach (Segment snippet in allSnippetsSource)
            {
                foreach (Segment blockedSnippet in snippet.ManuallyBlockedSnippets)
                {
                    // deleted snippets will not appear in the snippetMap, so we need to test   // TODO: deleting them before saving would be cleaner
                    if (snippetMap.Keys.Contains(blockedSnippet))
                    {
                        snippetMap[snippet].ManuallyBlockedSnippets.Add(snippetMap[blockedSnippet]);
                    }
                }

                foreach (Segment linkedSnippet in snippet.ManuallyLinkedSnippets)
                {
                    if (snippetMap.Keys.Contains(linkedSnippet))
                    {
                        snippetMap[snippet].ManuallyLinkedSnippets.Add(snippetMap[linkedSnippet]);
                    }
                }
            }

            return(clone);
        }