public int CreateSegmentSuitabilityBitfield(PsaiProject parentProject) { int bitfield = 0; if (this.IsAutomaticBridgeSegment || this.IsBridgeSnippetToAnyGroup(parentProject)) { SetSegmentSuitabilityFlag(ref bitfield, SegmentSuitability.bridge); } if (this.IsUsableAtStart) { SetSegmentSuitabilityFlag(ref bitfield, SegmentSuitability.start); } if (this.IsUsableInMiddle) { SetSegmentSuitabilityFlag(ref bitfield, SegmentSuitability.middle); } if (this.IsUsableAtEnd) { SetSegmentSuitabilityFlag(ref bitfield, SegmentSuitability.end); } return(bitfield); }
internal psai.net.Soundtrack CreatePsaiDotNetVersion(PsaiProject parentProject) { psai.net.Soundtrack netSoundtrack = new psai.net.Soundtrack(); foreach (Theme theme in Themes) netSoundtrack.m_themes.Add(theme.Id, theme.CreatePsaiDotNetVersion()); foreach (Segment segment in Segments) netSoundtrack.m_snippets.Add(segment.Id, segment.CreatePsaiDotNetVersion(parentProject)); return netSoundtrack; }
internal ProtoBuf_PsaiCoreSoundtrack CreateProtoBuf(PsaiProject parentProject) { ProtoBuf_PsaiCoreSoundtrack pbSoundtrack = new ProtoBuf_PsaiCoreSoundtrack(); pbSoundtrack.audioformat = AudioFormat; foreach (Theme theme in Themes) pbSoundtrack.themes.Add(theme.CreateProtoBuf()); foreach (Segment segment in Segments) pbSoundtrack.snippets.Add(segment.CreateProtoBuf(parentProject)); return pbSoundtrack; }
// 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); } } }
internal psai.net.Soundtrack CreatePsaiDotNetVersion(PsaiProject parentProject) { psai.net.Soundtrack netSoundtrack = new psai.net.Soundtrack(); foreach (Theme theme in Themes) { netSoundtrack.m_themes.Add(theme.Id, theme.CreatePsaiDotNetVersion()); } foreach (Segment segment in Segments) { netSoundtrack.m_snippets.Add(segment.Id, segment.CreatePsaiDotNetVersion(parentProject)); } return(netSoundtrack); }
internal ProtoBuf_PsaiCoreSoundtrack CreateProtoBuf(PsaiProject parentProject) { ProtoBuf_PsaiCoreSoundtrack pbSoundtrack = new ProtoBuf_PsaiCoreSoundtrack(); pbSoundtrack.audioformat = AudioFormat; foreach (Theme theme in Themes) { pbSoundtrack.themes.Add(theme.CreateProtoBuf()); } foreach (Segment segment in Segments) { pbSoundtrack.snippets.Add(segment.CreateProtoBuf(parentProject)); } return(pbSoundtrack); }
public static PsaiProject LoadProjectFromStream(Stream stream) { PsaiProject project = null; try { TextReader reader = new StreamReader(stream); XmlSerializer serializer = new XmlSerializer(typeof(PsaiProject)); project = (PsaiProject)serializer.Deserialize(reader); reader.Close(); } catch (System.Exception ex) { throw ex; } project.ReconstructReferencesAfterXmlDeserialization(); return(project); }
public psai.net.Segment CreatePsaiDotNetVersion(PsaiProject parentProject) { psai.net.Segment netSegment = new psai.net.Segment(); netSegment.audioData = this.AudioData.CreatePsaiDotNetVersion(); netSegment.Id = this.Id; netSegment.Intensity = this.Intensity; netSegment.SnippetTypeBitfield = this.CreateSegmentSuitabilityBitfield(parentProject); netSegment.ThemeId = this.ThemeId; netSegment.Name = this.Name; for (int i = 0; i < this.CompatibleSnippetsIds.Count; i++) { int snippetId = this.CompatibleSnippetsIds.Keys.ElementAt(i); netSegment.Followers.Add(new Follower(snippetId, CompatibleSnippetsIds[snippetId])); } return(netSegment); }
public ProtoBuf_Snippet CreateProtoBuf(PsaiProject parentProject) { ProtoBuf_Snippet pbSnippet = new ProtoBuf_Snippet(); pbSnippet.audio_data = this.AudioData.CreateProtoBuf(); pbSnippet.id = this.Id; pbSnippet.intensity = this.Intensity; pbSnippet.snippet_type = this.CreateSegmentSuitabilityBitfield(parentProject); pbSnippet.theme_id = this.ThemeId; pbSnippet.name = this.Name; for (int i = 0; i < this.CompatibleSnippetsIds.Count; i++) { int snippetId = this.CompatibleSnippetsIds.Keys.ElementAt(i); pbSnippet.follower_id.Add(snippetId); pbSnippet.follower_compatibility.Add(this.CompatibleSnippetsIds[snippetId]); } return(pbSnippet); }
void OnClose() { this._project = null; }
private void HandleEvent_ProjectLoaded(object sender, System.EventArgs e) { _project = null; }
public bool IsManualBridgeSnippetForAnyGroup(PsaiProject project) { List<Group> groups = null; return project.CheckIfSnippetIsManualBridgeSnippetToAnyGroup(this, false, out groups); }
public bool IsManualBridgeSnippetForAnyGroup(PsaiProject project) { List <Group> groups = null; return(project.CheckIfSnippetIsManualBridgeSnippetToAnyGroup(this, false, out groups)); }
public CommandAddSegments(PsaiProject psaiProject, string[] filenames, Group parentGroup) { _psaiProject = psaiProject; _filenames = filenames; _parentGroup = parentGroup; }
public override int GetIndexPositionWithinParentEntity(PsaiProject parentProject) { return parentProject.Themes.IndexOf(this); }
internal CommandDeleteSegment(PsaiProject project, Segment segmentToDelete) { _psaiProject = project; _entityToDelete = segmentToDelete; _segmentToDelete = segmentToDelete; }
internal CommandDeleteTheme(PsaiProject psaiProject, Theme themeToDelete) { _psaiProject = psaiProject; _entityToDelete = themeToDelete; _themeToDelete = themeToDelete; }
internal CommandDeleteGroup(PsaiProject project, Group groupToDelete) { _psaiProject = project; _entityToDelete = groupToDelete; _groupToDelete = groupToDelete; }
/* * public void ToggleSnippetTypeFlag(SegmentSuitability snippetType) * { * #if DEBUG * Console.WriteLine("ToggleSnippetTypeFlag() " + snippetType); * Console.WriteLine("before: start=" + IsUsableAtStart + " middle=" + IsUsableInMiddle + " end=" + IsUsableAtEnd); #endif * * if (this.IsUsableAs(snippetType)) * { * // remove the flag * this.ClearSnippetTypeFlag(snippetType); * } * else * { * //set the flag * this.SetSnippetTypeFlag(snippetType); * } * #if DEBUG * Console.WriteLine("after: start=" + IsUsableAtStart + " middle=" + IsUsableInMiddle + " end=" + IsUsableAtEnd); #endif * } */ public bool IsBridgeSnippetToAnyGroup(PsaiProject project) { List <Group> groups = null; return(this.IsAutomaticBridgeSegment || project.CheckIfSnippetIsManualBridgeSnippetToAnyGroup(this, false, out groups)); }
public abstract int GetIndexPositionWithinParentEntity(PsaiProject parentProject);
// 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); } } }
private int _targetIndex = 0; // the index position (within the Group / Theme / Project) #endregion Fields #region Constructors public CommandAddPsaiEntity(PsaiProject psaiProject, PsaiMusicEntity entityToAdd, int targetIndex) { _psaiProject = psaiProject; _entityToAdd = entityToAdd; _targetIndex = targetIndex; }
public psai.net.Segment CreatePsaiDotNetVersion(PsaiProject parentProject) { psai.net.Segment netSegment = new psai.net.Segment(); netSegment.audioData = this.AudioData.CreatePsaiDotNetVersion(); netSegment.Id = this.Id; netSegment.Intensity = this.Intensity; netSegment.SnippetTypeBitfield = this.CreateSegmentSuitabilityBitfield(parentProject); netSegment.ThemeId = this.ThemeId; netSegment.Name = this.Name; for (int i = 0; i < this.CompatibleSnippetsIds.Count; i++) { int snippetId = this.CompatibleSnippetsIds.Keys.ElementAt(i); netSegment.Followers.Add(new Follower(snippetId, CompatibleSnippetsIds[snippetId])); } return netSegment; }
// 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); }
public override int GetIndexPositionWithinParentEntity(PsaiProject parentProject) { return this.Group.Segments.IndexOf(this); }
// 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; }
public override int GetIndexPositionWithinParentEntity(PsaiProject parentProject) { return(this.Group.Segments.IndexOf(this)); }
public override int GetIndexPositionWithinParentEntity(PsaiProject parentProject) { return(parentProject.Themes.IndexOf(this)); }
private int _targetIndex = 0; // the index position (within the Group / Theme / Project) public CommandAddPsaiEntity(PsaiProject psaiProject, PsaiMusicEntity entityToAdd, int targetIndex) { _psaiProject = psaiProject; _entityToAdd = entityToAdd; _targetIndex = targetIndex; }
public ProtoBuf_Snippet CreateProtoBuf(PsaiProject parentProject) { ProtoBuf_Snippet pbSnippet = new ProtoBuf_Snippet(); pbSnippet.audio_data = this.AudioData.CreateProtoBuf(); pbSnippet.id = this.Id; pbSnippet.intensity = this.Intensity; pbSnippet.snippet_type = this.CreateSegmentSuitabilityBitfield(parentProject); pbSnippet.theme_id = this.ThemeId; pbSnippet.name = this.Name; for (int i = 0; i < this.CompatibleSnippetsIds.Count; i++) { int snippetId = this.CompatibleSnippetsIds.Keys.ElementAt(i); pbSnippet.follower_id.Add(snippetId); pbSnippet.follower_compatibility.Add(this.CompatibleSnippetsIds[snippetId]); } return pbSnippet; }
public int CreateSegmentSuitabilityBitfield(PsaiProject parentProject) { int bitfield = 0; if (this.IsAutomaticBridgeSegment || this.IsBridgeSnippetToAnyGroup(parentProject)) { SetSegmentSuitabilityFlag(ref bitfield, SegmentSuitability.bridge); } if (this.IsUsableAtStart) { SetSegmentSuitabilityFlag(ref bitfield, SegmentSuitability.start); } if (this.IsUsableInMiddle) { SetSegmentSuitabilityFlag(ref bitfield, SegmentSuitability.middle); } if (this.IsUsableAtEnd) { SetSegmentSuitabilityFlag(ref bitfield, SegmentSuitability.end); } return bitfield; }
/* public void ToggleSnippetTypeFlag(SegmentSuitability snippetType) { #if DEBUG Console.WriteLine("ToggleSnippetTypeFlag() " + snippetType); Console.WriteLine("before: start=" + IsUsableAtStart + " middle=" + IsUsableInMiddle + " end=" + IsUsableAtEnd); #endif if (this.IsUsableAs(snippetType)) { // remove the flag this.ClearSnippetTypeFlag(snippetType); } else { //set the flag this.SetSnippetTypeFlag(snippetType); } #if DEBUG Console.WriteLine("after: start=" + IsUsableAtStart + " middle=" + IsUsableInMiddle + " end=" + IsUsableAtEnd); #endif } */ public bool IsBridgeSnippetToAnyGroup(PsaiProject project) { List<Group> groups = null; return (this.IsAutomaticBridgeSegment || project.CheckIfSnippetIsManualBridgeSnippetToAnyGroup(this, false, out groups)); }