public static void OnRemoveNoteFlag(Note note) { if (!NoteController.IsRest(note)) { note.Vector_Id = 8; } }
public static Note Clone(Guid parentId, Chord chord, Repository.DataService.Measure measure, int x, int y, Note source, Collaborator collaborator) { Note obj = null; try { obj = Create(chord, measure, x, y); obj.Accidental_Id = source.Accidental_Id; obj.Duration = source.Duration; obj.Instrument_Id = source.Instrument_Id; obj.Chord_Id = parentId; obj.IsDotted = source.IsDotted; obj.IsSpanned = source.IsSpanned; obj.Location_X = source.Location_X; obj.Location_Y = source.Location_Y; obj.Key_Id = source.Key_Id; obj.Orientation = source.Orientation; obj.Slot = source.Slot; obj.Pitch = source.Pitch; obj.Type = source.Type; obj.Vector_Id = source.Vector_Id; obj.StartTime = source.StartTime; obj.Status = source.Status; obj.Audit = GetAudit(); Cache.Notes.Add(obj); } catch (Exception ex) { Exceptions.HandleException(ex); } return obj; }
public static void AddDispositionChangeItem(Note clonedNote, Note cloneSource, _Enum.Disposition disposition) { if (Collaborations.DispositionChanges == null) { Collaborations.DispositionChanges = new List<DispositionChangeItem>(); } Collaborations.DispositionChanges.Add(new DispositionChangeItem(clonedNote.Id, cloneSource.Id, disposition)); }
public static void AddToCloneMap(Note clonedNote, Note cloneSource) { if (Collaborations.DispositionChanges == null) { Collaborations.DispositionChanges = new List<DispositionChangeItem>(); } Collaborations.DispositionChanges.Add(new DispositionChangeItem(clonedNote.Id, cloneSource.Id)); }
public static void AddNote(Note n) { var l = Notes; if (!l.Contains(n)) { l.Add(n); } Notes = l; }
public static Notegroup GetNotegroup(Note note) { Notegroup noteGroup = null; var b = (from a in ChordNotegroups where a.Duration == note.Duration select a); var notegroups = b as List<Notegroup> ?? b.ToList(); if (notegroups.Any()) { noteGroup = notegroups.First(); } return noteGroup; }
public static Chord GetChordFromNote(Note n) { try { var b = (from a in Cache.Chords where a.Id == n.Chord_Id select a); var e = b as List<Chord> ?? b.ToList(); return e.Any() ? e.First() : null; } catch (Exception ex) { Exceptions.HandleException(ex); } return null; }
public static void Select(Note note) { if (note != null) { //TODO: Isn't there a method to accomplish this conditional evaluation? what is this conditional about? if (Collaborations.GetStatus(note) == (int) _Enum.Status.AuthorOriginal || Collaborations.GetStatus(note) == (int) _Enum.Status.ContributorAdded || Collaborations.GetStatus(note) == (int) _Enum.Status.AuthorAdded) { if (EditorState.DoubleClick) { EditorState.DoubleClick = false; var notegroup = NotegroupManager.ParseChord(ViewModel.Chord, note); foreach (var n in notegroup.Notes) { _ea.GetEvent<SelectNote>().Publish(n.Id); } } } } }
private static int GetYCoordThreshold(Note note1, Note note2) { //the vertical distance between 2 notes is part of the determination whether 2 notes can be spanned. //the threshold is the max distance between 2 notes that will allow them to be spanned. //TODO: threshhold is never used. var threshhold = 0; var d = (int)((note1.Duration + note2.Duration) * 1000); switch (d) { case 250: threshhold = Preferences.MediumOkToSpanThreshhold; break; case 375: threshhold = Preferences.MediumOkToSpanThreshhold; break; case 500: threshhold = Preferences.MediumOkToSpanThreshhold; break; case 625: threshhold = Preferences.MediumOkToSpanThreshhold; break; case 750: threshhold = Preferences.MediumOkToSpanThreshhold; break; case 875: threshhold = Preferences.MediumOkToSpanThreshhold; break; case 1000: threshhold = Preferences.LargeOkToSpanThreshhold; break; default: threshhold = Preferences.MediumOkToSpanThreshhold; break; } return Preferences.MediumOkToSpanThreshhold; }
public void OnUpdateNote(Note note) { if (note.Id == Note.Id) { Note = note; } }
private static bool IsPurgeable(Note note) { //a note that is purgeable (pending for all collaborations) can be deleted from db instead of setting its status to purged bool result = true; //if the author of this composition is logged in, and is the note owner... if (EditorState.EditContext == _Enum.EditContext.Authoring && note.Audit.CollaboratorIndex == 0) { string status = note.Status; string[] arr = status.Split(','); //if none of the collaborators have acted on this note, then the status will be AuthorAdded for all of them. //otherwise it's not purgeable. for (var i = 1; i <= arr.Length - 1; i++) { if (arr[i] != ((int)_Enum.Status.AuthorAdded).ToString(CultureInfo.InvariantCulture)) { result = false; break; } } } else { //NOT if a contributor to this composition is logged in, and is the note owner, and the author has taken no action... if (!(EditorState.EditContext == _Enum.EditContext.Contributing && note.Audit.CollaboratorIndex == Collaborations.Index && note.Status == string.Format("{0},{1}", (int)_Enum.Status.PendingAuthorAction, (int)_Enum.Status.ContributorAdded))) { result = false; } } //set EditorState.IsPurgeable so that, if true, later in this same note Deletion flow, //the deleted note can be purged, instead of retained with a purged status. EditorState.Purgable = result; return result; }
public static Notegroup ParseChord(Chord chord, Note note) { Notegroup noteGroup = null; try { foreach (var n in chord.Notes.Where(_note => CollaborationManager.IsActive(_note)).Where(_note => _note.Duration == note.Duration)) { if (noteGroup == null) { if (chord.StartTime != null && n.Orientation != null) { noteGroup = new Notegroup(n.Duration, (Double)chord.StartTime, (short)n.Orientation) { IsRest = n.Pitch.Trim().ToUpper() == Infrastructure.Constants.Defaults.RestSymbol }; noteGroup.Notes.Add(n); } } else { noteGroup.Notes.Add(n); } } } catch (Exception ex) { Exceptions.HandleException(ex); } return noteGroup; }
private static short GetOrientation(Note note) { short orientation; if (note.Pitch == Infrastructure.Constants.Defaults.RestSymbol) { orientation = (short)_Enum.Orientation.Rest; } else if (_previousOrientation == null && note.Orientation != null) { orientation = (short)note.Orientation; } else { orientation = (_previousOrientation == (short)_Enum.Orientation.Up) ? (short)_Enum.Orientation.Down : (short)_Enum.Orientation.Up; } _previousOrientation = orientation; return orientation; }
private static bool IsActiveForContributor(Note n, int idx) { //USED IN: CollaborationManager.IsActionable() x 2 var s = Collaborations.GetStatus(n, idx); return ( s == (int)_Enum.Status.ContributorAccepted || s == (int)_Enum.Status.ContributorRejectedDelete || s == (int)_Enum.Status.AuthorOriginal || s == (int)_Enum.Status.AuthorDeleted); }
private static bool IsInactiveForContributor(Note n, int idx) { //USED IN: CollaborationManager.IsActionable() x 2 var s = Collaborations.GetStatus(n, idx); return ( s == (int)_Enum.Status.ContributorDeleted || s == (int)_Enum.Status.NotApplicable || s == (int)_Enum.Status.Purged); }
public static bool IsActive(Note n) { return IsActionable(n, null); }
public void OnSetOverlay(Note note) { if (note.Id == Note.Id) { if (CollaborationManager.IsPendingDelete(Collaborations.GetStatus(note))) { if (Collaborations.CurrentCollaborator != null) { if (note.Audit.CollaboratorIndex == -1 || note.Audit.CollaboratorIndex == Collaborations.CurrentCollaborator.Index) { Overlay = "X"; OverlayFontSize = Preferences.AddOverlayFontSize; OverlayMargin = "1,25,0,0"; OverlayVisibility = Visibility.Visible; EA.GetEvent<ShowDispositionButtons>().Publish(Note.Id); note.Foreground = Preferences.DeletedColor; } } } else { if ((CollaborationManager.IsPendingAdd(Collaborations.GetStatus(note)))) { Overlay = "+"; OverlayFontSize = Preferences.DeleteOverlayFontSize; OverlayMargin = "-1,22,0,0"; OverlayVisibility = Visibility.Visible; EA.GetEvent<ShowDispositionButtons>().Publish(Note.Id); note.Foreground = Preferences.AddedColor; } else { OverlayVisibility = Visibility.Collapsed; EA.GetEvent<HideDispositionButtons>().Publish(string.Empty); note.Foreground = Preferences.NoteForeground; } } } }
public void OnReverse(Note note) { if (!NoteController.IsRest(note)) { if (Note.Id == note.Id) { Note.Orientation = (Note.Orientation == (short)_Enum.Orientation.Up) ? (short)_Enum.Orientation.Down : (short)_Enum.Orientation.Up; } } }
public void OnRemoveOverlay(Note note) { if (note.Id != Note.Id) return; Overlay = ""; OverlayFontSize = 16; OverlayMargin = "-1000,0,0,0"; OverlayVisibility = Visibility.Collapsed; }
private bool ContainsStatus(Note note, _Enum.Status status) { return Collaborations.GetStatus(note) == (short)status; }
private static bool IsActiveForAuthor(Note n, int idx) { //USAG: CollaborationManager.IsActionable() x 2 //the ouput of this function is meaningless unless.... //...note.Audit.Author_Id != CompositionManager.Composition.Audit.Author_Id (ie: when the author of the note is a contributor.) because //this function is only called as part of a boolean expression that also contains the boolean expression... //...note.Audit.Author_Id != CompositionManager.Composition.Audit.Author_Id //this function is only called in boolean expressions containing the expression... //...note.Audit.Author_Id != CompositionManager.Composition.Audit.Author_Id var s = Collaborations.GetStatus(n, idx); return ( s == (int)_Enum.Status.AuthorAccepted || s == (int)_Enum.Status.AuthorOriginal //should this be here? status = AuthorOriginal signifies //the note author is the composition author. || s == (int)_Enum.Status.ContributorDeleted); //should this be here? status = ContributorDeleted signifies the //note author is the composition author. }
public static Repository.DataService.Measure GetMeasureFromNote(Note n) { try { var c = GetChordFromNote(n); if (c != null) { var b = (from a in Cache.Measures where a.Id == c.Measure_Id select a); var e = b as List<Repository.DataService.Measure> ?? b.ToList(); return e.Any() ? e.First() : null; } } catch (Exception ex) { Exceptions.HandleException(ex); } return null; }
private static bool IsInactiveForAuthor(Note n) { //USED IN: CollaborationManager.IsActionable() x 2 //the ouput of this function is meaningless unless.... //...note.Audit.Author_Id == CompositionManager.Composition.Audit.Author_Id (ie: when the author of the note = composition author.) because //this function is only called as part of a boolean expression that also contains the boolean expression... //...note.Audit.Author_Id == CompositionManager.Composition.Audit.Author_Id var s = Collaborations.GetStatus(n); return ( s == (int)_Enum.Status.AuthorDeleted || s == (int)_Enum.Status.NotApplicable || s == (int)_Enum.Status.Purged); }
public static Boolean HasFlag(Note note) { return note.Duration < 1; }
//is this note actionable based on its status, note authorship, composition authorship? //and the currently logged on user. this function answers that question. public static bool IsActionable(Note n, Collaborator collaborator) { var result = false; //usually we are interested in the current collaborator, but sometimes we need //to specify a collaborater, by passing in a currentCollaborator. if currentCollaborator is null then //use the usual Collaborations.CurrentCollaborator. if (collaborator == null && Collaborations.CurrentCollaborator != null) { collaborator = Collaborations.CurrentCollaborator; } var noteIsAuthoredByAuthor = n.Audit.Author_Id == CompositionManager.Composition.Audit.Author_Id; var noteIsAuthoredByContributor = n.Audit.Author_Id != CompositionManager.Composition.Audit.Author_Id; var noteIsAuthoredBySpecifiedContributor = (collaborator != null) && n.Audit.Author_Id == collaborator.Author_Id; var noteIsAuthoredByCurrentUser = n.Audit.Author_Id == Current.User.Id; try { int idx; bool noteIsInactiveForAuthor; bool noteIsActiveForAuthor; bool noteIsInactiveForContributor; bool noteIsActiveForContributor; if (collaborator != null) { //only allow packed measures to display contributor submissions var isPackedMeasure = true; if (!_checkingPackedState) { //IsPackedMeasure calls this function, so we need a mechanism to avoid circularity. _checkingPackedState = true; isPackedMeasure = MeasureManager.IsPackedMeasure(NoteController.GetMeasureFromNote(n)); _checkingPackedState = false; isPackedMeasure = true; } if (EditorState.IsAuthor) { //the currently logged on user is the author, and there is a collaborator selected in the collaboration panel. idx = GetUserCollaboratorIndex(n.Audit.Author_Id.ToString(CultureInfo.InvariantCulture)); if (n.StartTime > 4 && ! _checkingPackedState && idx==1) { } noteIsInactiveForAuthor = IsInactiveForAuthor(n); noteIsActiveForAuthor = IsActiveForAuthor(n, idx); var isContributorAdded = Collaborations.GetStatus(n, collaborator.Index) == (int)_Enum.Status.ContributorAdded; result = (noteIsAuthoredByAuthor && !noteIsInactiveForAuthor || noteIsAuthoredByContributor && noteIsActiveForAuthor || isPackedMeasure && noteIsAuthoredBySpecifiedContributor && isContributorAdded); //ie: note is pending } else { //the currently logged on user is a contributor, and the composition author is selected in the collaboration panel. idx = GetUserCollaboratorIndex(Current.User.Id); noteIsInactiveForContributor = IsInactiveForContributor(n, idx); noteIsActiveForContributor = IsActiveForContributor(n, idx); var isAuthorAdded = Collaborations.GetStatus(n, idx) == (int)_Enum.Status.AuthorAdded; result = (noteIsAuthoredByCurrentUser && !noteIsInactiveForContributor || noteIsAuthoredByAuthor && noteIsActiveForContributor || isPackedMeasure && noteIsAuthoredByAuthor && isAuthorAdded); //ie: note is pending } } else { //is the currently logged in user the composition author? if (EditorState.IsAuthor) { idx = GetUserCollaboratorIndex(n.Audit.Author_Id.ToString(CultureInfo.InvariantCulture)); //arriving here means that the currently logged on user is the author of the composition, and there //isn't a target contributor selected in the collaboration panel //even though the currently logged in user is the composition author, notes authored by the composition //author may not be active, and notes authored by a contributor may be inactive. noteIsInactiveForAuthor = IsInactiveForAuthor(n); noteIsActiveForAuthor = IsActiveForAuthor(n, idx); result = (noteIsAuthoredByAuthor && !noteIsInactiveForAuthor || noteIsAuthoredByContributor && noteIsActiveForAuthor); } else { //arriving here means that the currently logged on user is a contributor to the composition, and the //author isn't selected in the collaboration panel. idx = GetUserCollaboratorIndex(Current.User.Id); //even though the currently logged in user is a contributor, notes authored by the contributor //may not be active, and notes authored by the composition author may be inactive. noteIsInactiveForContributor = IsInactiveForContributor(n, idx); noteIsActiveForContributor = IsActiveForContributor(n, idx); result = (noteIsAuthoredByCurrentUser && !noteIsInactiveForContributor || noteIsAuthoredByAuthor && noteIsActiveForContributor); } } } catch (Exception ex) { Exceptions.HandleException(ex, "class = CollaborationManager method = IsActionable(Repository.DataService.Note n, Collaborator currentCollaborator)"); } return result; }
public static Boolean IsRest(Note n) { return n.Orientation == (int)_Enum.Orientation.Rest; }
private static Notegroup CreateNotegroup(Note note, Chord chord) { if (chord.StartTime != null) { return new Notegroup(note.Duration, (Double)chord.StartTime, GetOrientation(note), Collaborations.GetStatus(note), note, chord); } return null; }
public static void OnDeleteNote(Note n) { Chord chord = (from a in Cache.Chords where a.Id == n.Chord_Id select a).First(); //notes that are purgeable are author notes added by the author that have not been acted on by any collaborator (and the converse of this). //such notes can be truly deleted instead of retained with a purged status. var isPurgeable = IsPurgeable(n); var isRest = IsRest(n); if (isRest) { DeleteRest(n); } else { if (!EditorState.IsCollaboration || isPurgeable) { chord.Notes.Remove(n); Repository.Delete(n); Cache.Notes.Remove(n); } else { switch (EditorState.EditContext) { case _Enum.EditContext.Authoring: //the logged on user is the composition author n.Audit.CollaboratorIndex = Defaults.AuthorCollaboratorIndex; //TODO: why is this here? //contributed deletions/additions are accepted or rejected by the composition author, but never deleted. So, //AuthorDeleted can only be applied to notes owned by the author. That means that collaboration index is always 0. //So, hardcoded constant AuthorCollaboratorIndex is OK here. n.Status = Collaborations.SetStatus(n, (int)_Enum.Status.AuthorDeleted, /* index */ Defaults.AuthorCollaboratorIndex); break; case _Enum.EditContext.Contributing: //the logged on user is NOT the composition author n.Audit.CollaboratorIndex = (short)Collaborations.Index; //TODO: why is this here? n.Status = Collaborations.SetStatus(n, (int)_Enum.Status.ContributorDeleted); break; } n.Audit.ModifyDate = DateTime.Now; Repository.Update(n); Ea.GetEvent<UpdateNote>().Publish(n); //notify viewModel of change } Ea.GetEvent<DeleteChord>().Publish(chord); } }
private static void DeleteRest(Note note) { var parentChord = (from a in Cache.Chords where a.Id == note.Chord_Id select a).First(); var parentMeasure = (from a in Cache.Measures where a.Id == parentChord.Measure_Id select a).First(); Ea.GetEvent<DeleteEntireChord>().Publish(new Tuple<Guid, Guid>(parentMeasure.Id, note.Id)); Ea.GetEvent<MeasureLoaded>().Publish(parentMeasure.Id); }
public static void RemoveNote(Note n) { var l = Notes; if (l.Contains(n)) { l.Remove(n); } Notes = l; }