Ejemplo n.º 1
0
 public static Boolean IsRest(Notegroup notegroup)
 {
     return notegroup.Orientation == (int)_Enum.Orientation.Rest;
 }
Ejemplo n.º 2
0
 public static Boolean HasFlag(Notegroup notegroup)
 {
     return notegroup.Duration < 1;
 }
Ejemplo n.º 3
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.º 4
0
 private static bool Spannable(Notegroup notegroup)
 {
     Func<Notegroup, bool> isSpannable =
         ng => !notegroup.IsRest &&
               !notegroup.IsSpanned &&
               notegroup.Duration < 1 &&
               notegroup.Orientation < 2 && //if orientation = 2, it's a rest. 2 is equivalent to null (orientation has no meaning in this context)
               CollaborationManager.IsActionable(notegroup.Root, null);
     return isSpannable(notegroup);
 }
Ejemplo n.º 5
0
        private static void Render(Notegroup notegroup1, Notegroup notegroup2)
        {
            notegroup1.IsSpanned = true;
            notegroup2.IsSpanned = true;
            var span = new LocalSpan();
            var sb = new StringBuilder();

            var c = (from obj in Cache.Chords where obj.Id == notegroup1.Root.Chord_Id select obj);
            var enumerable = c as List<Chord> ?? c.ToList();
            if (!enumerable.Any()) return;
            var chord = enumerable.First();

            span.Location_X = chord.Location_X + 19;
            span.Location_Y = notegroup1.Root.Location_Y + 25;
            span.MeasureIndex = Measure.Index;
            span.Measure_Id = Measure.Id;
            var dX = notegroup2.GroupX - notegroup1.GroupX - 1;
            var dY = (notegroup2.GroupY - notegroup1.GroupY);
            var dy = Math.Abs(dY);
            Decimal dur1 = notegroup1.Root.Duration;
            Decimal dur2 = notegroup2.Root.Duration;

            if (notegroup1.Root.Orientation != null) span.Orientation = (short)notegroup1.Root.Orientation;

            #region span logic

            //here we handle full spanners
            var spanWidth = 5;
            const int lineWidth = 2;
            var step = 0;

            sb.AppendFormat(SpanFormatter, spanWidth * step, spanWidth * step - lineWidth, dX, (dY + spanWidth * step), (dY - spanWidth * step - lineWidth), 0);

            if (dur1 <= .25M && dur2 <= .25M)
            {
                step = 1;
                switch (span.Orientation)
                {
                    case (short)_Enum.Orientation.Up:
                        sb.AppendFormat(SpanFormatter, spanWidth * step, spanWidth * step - lineWidth, dX, (dY + spanWidth * step), (dY + spanWidth * step - lineWidth), 0);
                        break;
                    case (short)_Enum.Orientation.Down:
                        sb.AppendFormat(SpanFormatter, -spanWidth * step, -(spanWidth * step + lineWidth), dX, (dY - spanWidth * step), (dY - spanWidth * step - lineWidth), 0);
                        break;
                }
            }
            if (dur1 + dur2 == .25M)
            {
                step = 2;
                switch (span.Orientation)
                {
                    case (short)_Enum.Orientation.Up:
                        sb.AppendFormat(SpanFormatter, spanWidth * step, spanWidth * step - lineWidth, dX, (dY + spanWidth * step), (dY + spanWidth * step - lineWidth), 0);
                        break;
                    case (short)_Enum.Orientation.Down:
                        sb.AppendFormat(SpanFormatter, -spanWidth * step, -(spanWidth * step + lineWidth), dX, (dY - spanWidth * step), (dY - spanWidth * step - lineWidth), 0);
                        break;
                }
            }

            step = dy / 2;
            //here we handle partial spans
            if (dur1 == .5M && dur2 == .25M)
            {
                if (notegroup1.GroupY >= notegroup2.GroupY)
                {
                    string result = string.Format("M {5} {0} L {5} {1} L {2} {4} L {2} {3} L {5} {0} Z", spanWidth - step, spanWidth - step - lineWidth, dX, dY + spanWidth, dY + spanWidth - lineWidth, dX / 2);
                    spanWidth = ((short)_Enum.Orientation.Up == span.Orientation) ? Math.Abs(spanWidth) : -Math.Abs(spanWidth);
                    sb.AppendFormat(SpanFormatter, spanWidth - step, spanWidth - step - lineWidth, dX, dY + spanWidth, dY + spanWidth - lineWidth, dX / 2);
                }
                else
                {
                    spanWidth = ((short)_Enum.Orientation.Up == span.Orientation) ? Math.Abs(spanWidth) : -Math.Abs(spanWidth);
                    sb.AppendFormat(SpanFormatter, spanWidth + step, spanWidth + step - lineWidth, dX, dY + spanWidth, dY + spanWidth - lineWidth, dX / 2);
                }
            }
            else if (dur1 == .25M && dur2 == .5M)
            {
                if (notegroup1.GroupY >= notegroup2.GroupY)
                {
                    spanWidth = ((short)_Enum.Orientation.Up == span.Orientation) ? Math.Abs(spanWidth) : -Math.Abs(spanWidth);
                    sb.AppendFormat(SpanFormatter, spanWidth, spanWidth - lineWidth, dX / 2, dY + spanWidth + step, dY + spanWidth + step - lineWidth, 0);
                }
                else
                {
                    spanWidth = ((short)_Enum.Orientation.Up == span.Orientation) ? Math.Abs(spanWidth) : -Math.Abs(spanWidth);
                    sb.AppendFormat(SpanFormatter, spanWidth, spanWidth - lineWidth, dX / 2, dY + spanWidth - step, dY + spanWidth - step - lineWidth, 0);
                }
            }

            if (dur1 == .5M && dur2 == .125M)
            {
                if (notegroup1.GroupY >= notegroup2.GroupY)
                {
                    switch (span.Orientation)
                    {
                        case (short)_Enum.Orientation.Up:
                            spanWidth = Math.Abs(spanWidth);
                            sb.AppendFormat(SpanFormatter, spanWidth - step, spanWidth - step - lineWidth, dX, dY + spanWidth, dY + spanWidth - lineWidth, dX / 2);
                            sb.AppendFormat(SpanFormatter, spanWidth * 2 - step, spanWidth * 2 - step - lineWidth, dX, dY + spanWidth * 2, dY + spanWidth * 2 - lineWidth, dX / 2);
                            break;
                        case (short)_Enum.Orientation.Down:
                            spanWidth = -Math.Abs(spanWidth);
                            sb.AppendFormat(SpanFormatter, spanWidth - step, spanWidth - step - lineWidth, dX, dY + spanWidth, dY + spanWidth - lineWidth, dX / 2);
                            sb.AppendFormat(SpanFormatter, spanWidth * 2 - step, spanWidth * 2 - step - lineWidth, dX, dY + spanWidth * 2, dY + spanWidth * 2 - lineWidth, dX / 2);
                            break;
                    }
                }
                else
                {
                    switch (span.Orientation)
                    {
                        case (short)_Enum.Orientation.Up:
                            spanWidth = Math.Abs(spanWidth);
                            sb.AppendFormat(SpanFormatter, spanWidth + step, spanWidth + step - lineWidth, dX, dY + spanWidth, dY + spanWidth - lineWidth, dX / 2);
                            sb.AppendFormat(SpanFormatter, spanWidth * 2 + step, spanWidth * 2 + step - lineWidth, dX, dY + spanWidth * 2, dY + spanWidth * 2 - lineWidth, dX / 2);
                            break;
                        case (short)_Enum.Orientation.Down:
                            spanWidth = -Math.Abs(spanWidth);
                            sb.AppendFormat(SpanFormatter, spanWidth + step, spanWidth + step - lineWidth, dX, dY + spanWidth, dY + spanWidth - lineWidth, dX / 2);
                            sb.AppendFormat(SpanFormatter, spanWidth * 2 + step, spanWidth * 2 + step - lineWidth, dX, dY + spanWidth * 2, dY + spanWidth * 2 - lineWidth, dX / 2);
                            break;
                    }
                }
            }

            else if (dur1 == .125M && dur2 == .5M)
            {
                if (notegroup1.GroupY >= notegroup2.GroupY)
                {
                    spanWidth = ((short)_Enum.Orientation.Up == span.Orientation) ? Math.Abs(spanWidth) : -Math.Abs(spanWidth);
                    sb.AppendFormat(SpanFormatter, spanWidth, spanWidth - lineWidth, dX / 2, dY + spanWidth + step, dY + spanWidth + step - lineWidth, 0);
                    sb.AppendFormat(SpanFormatter, spanWidth * 2, spanWidth * 2 - lineWidth, dX / 2, dY + spanWidth * 2 + step, dY + spanWidth * 2 + step - lineWidth, 0);
                }
                else
                {
                    spanWidth = ((short)_Enum.Orientation.Up == span.Orientation) ? Math.Abs(spanWidth) : -Math.Abs(spanWidth);
                    sb.AppendFormat(SpanFormatter, spanWidth, spanWidth - lineWidth, dX / 2, dY + spanWidth - step, dY + spanWidth - step - lineWidth, 0);
                    sb.AppendFormat(SpanFormatter, spanWidth * 2, spanWidth * 2 - lineWidth, dX / 2, dY + spanWidth * 2 - step, dY + spanWidth * 2 - step - lineWidth, 0);
                }
            }

            if (dur1 == .25M && dur2 == .125M)
            {
                if (notegroup1.GroupY >= notegroup2.GroupY)
                {
                    spanWidth = ((short)_Enum.Orientation.Up == span.Orientation) ? Math.Abs(spanWidth) : -Math.Abs(spanWidth);
                    sb.AppendFormat(SpanFormatter, spanWidth * 2 - step, spanWidth * 2 - step - lineWidth, dX, dY + spanWidth * 2, dY + spanWidth * 2 - lineWidth, dX / 2);
                }
                else
                {
                    spanWidth = ((short)_Enum.Orientation.Up == span.Orientation) ? Math.Abs(spanWidth) : -Math.Abs(spanWidth);
                    sb.AppendFormat(SpanFormatter, spanWidth * 2 + step, spanWidth * 2 + step - lineWidth, dX, dY + spanWidth * 2, dY + spanWidth * 2 - lineWidth, dX / 2);
                }
            }

            else if (dur1 == .125M && dur2 == .25M)
            {
                if (notegroup1.GroupY >= notegroup2.GroupY)
                {
                    spanWidth = ((short)_Enum.Orientation.Up == span.Orientation) ? Math.Abs(spanWidth) : -Math.Abs(spanWidth);
                    sb.AppendFormat(SpanFormatter, spanWidth * 2, spanWidth * 2 - lineWidth, dX / 2, dY + spanWidth * 2 + step, dY + spanWidth * 2 + step - lineWidth, 0);
                }
                else
                {
                    spanWidth = ((short)_Enum.Orientation.Up == span.Orientation) ? Math.Abs(spanWidth) : -Math.Abs(spanWidth);
                    sb.AppendFormat(SpanFormatter, spanWidth * 2, spanWidth * 2 - lineWidth, dX / 2, dY + spanWidth * 2 - step, dY + spanWidth * 2 - step - lineWidth, 0);
                }
            }

            #endregion span logic

            span.Path = sb.ToString();
            if (LocalSpans == null)
                LocalSpans = new ObservableCollection<LocalSpan>();
            LocalSpans.Add(span);
            Cache.Spans.Add(span);
        }
Ejemplo n.º 6
0
 private static void FlagNotegroup(Notegroup notegroup)
 {
     if (!notegroup.IsSpanned)
     {
         _ea.GetEvent<FlagNotegroup>().Publish(notegroup);
         //added 4 lines on 1/27/2013
         foreach (Repository.DataService.Note note in notegroup.Notes)
         {
             note.IsSpanned = false;
         }
     }
 }