Ejemplo n.º 1
0
 public static void OnRemoveNoteFlag(Note note)
 {
     if (!NoteController.IsRest(note))
     {
         note.Vector_Id = 8;
     }
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
 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));
 }
Ejemplo n.º 4
0
 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));
 }
Ejemplo n.º 5
0
 public static void AddNote(Note n)
 {
     var l = Notes;
     if (!l.Contains(n))
     {
         l.Add(n);
     }
     Notes = l;
 }
Ejemplo n.º 6
0
 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;
 }
Ejemplo n.º 7
0
 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;
 }
Ejemplo n.º 8
0
 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);
                 }
             }
         }
     }
 }
Ejemplo n.º 9
0
        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;
        }
Ejemplo n.º 10
0
 public void OnUpdateNote(Note note)
 {
     if (note.Id == Note.Id)
     {
         Note = note;
     }
 }
Ejemplo n.º 11
0
 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;
 }
Ejemplo n.º 12
0
 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;
 }
Ejemplo n.º 13
0
 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;
 }
Ejemplo n.º 14
0
 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);
 }
Ejemplo n.º 15
0
 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);
 }
Ejemplo n.º 16
0
 public static bool IsActive(Note n)
 {
     return IsActionable(n, null);
 }
Ejemplo n.º 17
0
 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;
             }
         }
     }
 }
Ejemplo n.º 18
0
 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;
         }
     }
 }
Ejemplo n.º 19
0
 public void OnRemoveOverlay(Note note)
 {
     if (note.Id != Note.Id) return;
     Overlay = "";
     OverlayFontSize = 16;
     OverlayMargin = "-1000,0,0,0";
     OverlayVisibility = Visibility.Collapsed;
 }
Ejemplo n.º 20
0
 private bool ContainsStatus(Note note, _Enum.Status status)
 {
     return Collaborations.GetStatus(note) == (short)status;
 }
Ejemplo n.º 21
0
        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.
        }
Ejemplo n.º 22
0
 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;
 }
Ejemplo n.º 23
0
        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);
        }
Ejemplo n.º 24
0
 public static Boolean HasFlag(Note note)
 {
     return note.Duration < 1;
 }
Ejemplo n.º 25
0
        //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;
        }
Ejemplo n.º 26
0
 public static Boolean IsRest(Note n)
 {
     return n.Orientation == (int)_Enum.Orientation.Rest;
 }
Ejemplo n.º 27
0
 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;
 }
Ejemplo n.º 28
0
        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);
            }
        }
Ejemplo n.º 29
0
 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);
 }
Ejemplo n.º 30
0
 public static void RemoveNote(Note n)
 {
     var l = Notes;
     if (l.Contains(n))
     {
         l.Remove(n);
     }
     Notes = l;
 }