Esempio n. 1
0
        public void Execute()
        {
            _psaiProject.AddPsaiMusicEntity(_entityToAdd, _targetIndex);

            EventArgs_PsaiEntityAdded e = new EventArgs_PsaiEntityAdded(_entityToAdd);
            EditorModel.Instance.RaiseEvent_PsaiEntityAdded(e);
        }
Esempio n. 2
0
        public void Execute()
        {
#if DEBUG
            Console.WriteLine("CommandAddSegments::Execute()");
#endif

            if (_newSegments.Count == 0)
            {
                foreach (string path in _filenames)
                {
                    int       segmentId = EditorModel.Instance.GetNextFreeSnippetIdBasedOnGroup(_parentGroup);
                    AudioData audioData = EditorModel.Instance.CreateAudioData(path);
                    Segment   segment   = new Segment(segmentId, audioData);

                    string filename = EditorModel.Instance.GetPathRelativeToProjectFileBasedOnAbsolutePath(path);

                    segment.ThemeId = _parentGroup.Theme.Id;
                    segment.Id      = EditorModel.Instance.GetNextFreeSnippetIdBasedOnGroup(_parentGroup);
                    segment.Group   = _parentGroup;

                    System.Diagnostics.Debug.Assert(_parentGroup != null, "_parentGroup is NULL");

                    //System.Diagnostics.Debug.Assert(snippetId < 0, "snippetId=" + snippetId);
                    segment.AudioData.FilePathRelativeToProjectDir            = filename;
                    segment.AudioData._prebeatLengthInSamplesEnteredManually  = EditorModel.Instance.Project.Properties.DefaultPrebeatLengthInSamples;
                    segment.AudioData._postbeatLengthInSamplesEnteredManually = EditorModel.Instance.Project.Properties.DefaultPostbeatLengthInSamples;
                    segment.AudioData.Bpm       = EditorModel.Instance.Project.Properties.DefaultBpm;
                    segment.AudioData.PreBeats  = EditorModel.Instance.Project.Properties.DefaultPrebeats;
                    segment.AudioData.PostBeats = EditorModel.Instance.Project.Properties.DefaultPostbeats;
                    segment.AudioData.CalculatePostAndPrebeatLengthBasedOnBeats = EditorModel.Instance.Project.Properties.DefaultCalculatePostAndPrebeatLengthBasedOnBeats;
                    segment.SetStartMiddleEndPropertiesFromBitfield(EditorModel.Instance.Project.Properties.DefaultSegmentSuitabilites);

                    _newSegments.Add(segment);
                }
            }

            foreach (Segment segment in _newSegments)
            {
                #if DEBUG
                Console.WriteLine("...adding Segment " + segment.Name + "  " + segment.GetHashCode() + "  to Group " + segment.Group.Name + "   " + segment.Group.GetHashCode());
                #endif
                _psaiProject.AddPsaiMusicEntity(segment);
                EventArgs_PsaiEntityAdded e = new EventArgs_PsaiEntityAdded(segment);
                EditorModel.Instance.RaiseEvent_PsaiEntityAdded(e);
            }
        }
Esempio n. 3
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;
        }
Esempio n. 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);
        }