Exemple #1
0
        /// <summary>
        /// Adds the cell below row.
        /// </summary>
        protected void AddCellBelowRow()
        {
            Cell cell = new Cell(Row);

            // get the value string
            StringBuilder val = new StringBuilder();

            int ltmFactor = 1;

            CellTreeNode c = Row.Cells.Min;

            while (c != FirstSelected)
            {
                if (!string.IsNullOrEmpty(c.Cell.Reference))
                {
                    c = c.Next();
                    continue;
                }

                AddCellValueToAccumulator(c.Cell, Row.Cells.Min.Cell, FirstSelected.Cell, val, ref ltmFactor);
                c = c.Next();
            }

            val.Append('0').Append(BeatCell.MultiplyTerms(BeatCell.Invert(DrawingView.Instance.GridSpacingString), NumIntervals));

            cell.Value = BeatCell.Invert(BeatCell.SimplifyValue(val.ToString()));

            // does having negative positions like this cause problems?
            cell.Position = FirstSelected.Cell.Position - DrawingView.Instance.GridSpacing * NumIntervals;
            Row.Cells.Insert(cell);
            RightIndexBoundOfTransform = -1;
            Row.OffsetValue            = BeatCell.Subtract(Row.OffsetValue, cell.Value);  // don't mult group factor this
        }
        public override void Undo()
        {
            base.Undo();

            if (ChangeOffset)
            {
                Row.Offset     -= Duration;
                Row.OffsetValue = BeatCell.Subtract(Row.OffsetValue, BeatCodeDuration);
            }
        }
Exemple #3
0
        /// <summary>
        /// Adds the cell to row below selection.
        /// </summary>
        protected void AddCellToRowBelowSelection()
        {
            Cell         cell     = new Cell(Row);
            CellTreeNode cellNode = new CellTreeNode(cell);

            cell.Position = FirstSelected.Cell.Position - DrawingView.Instance.GridSpacing * NumIntervals;

            if (Row.Cells.Insert(cellNode))
            {
                Cell below = cellNode.Prev().Cell;
                RightIndexBoundOfTransform = below.Index;

                // add to applicable groups
                AddToGroups(cell, below);

                // see if the cell is being added to a rep group's LTM zone
                Repeat repWithLtmToMod = null;
                foreach (Repeat rg in below.RepeatGroups.Where(
                             x => x.ExclusiveCells.Last.Value == below && Position > below.Position + below.Duration))
                {
                    repWithLtmToMod = rg;
                }

                // get new value string for below
                StringBuilder val = new StringBuilder();

                var sequence = cell.RepeatGroups
                               .Where(x => !FirstSelected.Cell.RepeatGroups.Contains(x) && x.Cells.First.Value != cell)
                               .Reverse()
                               .Select(x => x.Times);
                int ltmFactor = sequence.Any() ? sequence.Aggregate((x, y) => x * y) : 1;

                CellTreeNode c = cellNode;

                while (c != FirstSelected)
                {
                    if (!string.IsNullOrEmpty(c.Cell.Reference))
                    {
                        c = c.Next();
                        continue;
                    }

                    AddCellValueToAccumulator(c.Cell, cell, FirstSelected.Cell, val, ref ltmFactor);

                    c = c.Next();
                }

                val.Append('0').Append(BeatCell.MultiplyTerms(BeatCell.Invert(DrawingView.Instance.GridSpacingString), NumIntervals));

                cell.Value = BeatCell.SimplifyValue(cell.GetValueDividedByMultFactors(BeatCell.Invert(val.ToString())));

                string newValue = BeatCell.SimplifyValue(val.ToString());

                if (repWithLtmToMod == null)
                {
                    below.Value = below.GetValueDividedByMultFactors(BeatCell.Add(below.Value, newValue));//newValue);
                    below.Value = BeatCell.SimplifyValue(below.Value);
                }
                else
                {
                    repWithLtmToMod.LastTermModifier =
                        repWithLtmToMod.GetValueDividedByMultFactor(
                            BeatCell.Subtract(repWithLtmToMod.LastTermModifier, newValue));
                    repWithLtmToMod.LastTermModifier = BeatCell.SimplifyValue(repWithLtmToMod.LastTermModifier);
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// Adds the cell to row above selection.
        /// </summary>
        protected void AddCellToRowAboveSelection()
        {
            Cell cell = new Cell(Row);

            CellTreeNode node = new CellTreeNode(cell);

            cell.Position = LastSelected.Cell.Position + NumIntervals * DrawingView.Instance.GridSpacing;

            if (Row.Cells.Insert(node))
            {
                CellTreeNode belowNode = node.Prev();
                Cell         below     = belowNode.Cell;
                RightIndexBoundOfTransform = below.Index + 1;

                // add to applicable groups
                AddToGroups(cell, below);

                // is new cell placed in the LTM zone of a rep group?
                Repeat repWithLtmToMod = null;
                foreach (Repeat rg in below.RepeatGroups.Where(
                             x => x.ExclusiveCells.Last.Value == below && Position > below.Position + below.ActualDuration))
                {
                    repWithLtmToMod = rg;
                }

                // determine new value for the below cell
                StringBuilder val = new StringBuilder();

                var sequence = LastSelected.Cell.RepeatGroups
                               .Where(x => !cell.RepeatGroups.Contains(x) && x.Cells.First.Value != LastSelected.Cell)
                               .Reverse()
                               .Select(x => x.Times);
                int ltmFactor = sequence.Any() ? sequence.Aggregate((x, y) => x * y) : 1;

                CellTreeNode c = LastSelected;

                // we subtract all values up to the "whitespace" below the new cell
                while (c != node)
                {
                    if (!string.IsNullOrEmpty(c.Cell.Reference))
                    {
                        c = c.Next();
                        continue;
                    }

                    AddCellValueToAccumulator(c.Cell, LastSelected.Cell, node.Cell, val, ref ltmFactor);

                    c = c.Next();
                }

                val.Append('0').Append(BeatCell.MultiplyTerms(BeatCell.Invert(DrawingView.Instance.GridSpacingString), NumIntervals));

                // get new cells value by subtracting old value of below cell by new value.
                string newVal = BeatCell.SimplifyValue(val.ToString());
                // placing a new cell on the beginning of a LTM is not illegal
                if (repWithLtmToMod != null && newVal == string.Empty)
                {
                    newVal = "0";
                }

                // assign the new cell's value
                cell.Value = BeatCell.SimplifyValue(cell.GetValueDividedByMultFactors(newVal));

                if (repWithLtmToMod == null)
                {
                    // change below cell's value
                    below.Value = below.GetValueDividedByMultFactors(
                        BeatCell.Subtract(below.Value, newVal));
                    below.Value = BeatCell.SimplifyValue(below.Value);

                    if (below.IsBreak)
                    {
                        below.IsBreak = false;
                        cell.IsBreak  = true;
                    }
                }
                else
                {
                    // changing a LTM value
                    repWithLtmToMod.LastTermModifier = BeatCell.SimplifyValue(
                        repWithLtmToMod.GetValueDividedByMultFactor(
                            BeatCell.Subtract(repWithLtmToMod.LastTermModifier, newVal)));
                }
            }
        }
        protected override void Transformation()
        {
            string value = BeatCell.MultiplyTerms(Increment, Math.Abs(Times));

            Cell last  = Cells[Cells.Length - 1];
            Cell first = Cells[0];

            if (Row.Cells.Min.Cell == Cells[0])
            {
                // selection is at start of row, offset will be changed
                if (ShiftingRight)
                {
                    // add to offset
                    if (string.IsNullOrEmpty(Row.OffsetValue))
                    {
                        Row.OffsetValue = "0";
                    }
                    Row.OffsetValue = BeatCell.Add(Row.OffsetValue, first.GetValueDividedByMultFactors(value));
                    // subtract from last cell's value if not last cell of row
                    if (last != Row.Cells.Max.Cell)
                    {
                        last.Value = BeatCell.Subtract(last.Value, last.GetValueDividedByMultFactors(value));
                    }
                }
                else
                {
                    // subtract from offset
                    Row.OffsetValue = BeatCell.Subtract(Row.OffsetValue, first.GetValueDividedByMultFactors(value));
                    // zero becomes an empty string, make it zero.
                    if (string.IsNullOrEmpty(Row.OffsetValue))
                    {
                        Row.OffsetValue = "0";
                    }
                    // add to last cell's value if not last cell of row
                    if (last != Row.Cells.Max.Cell)
                    {
                        last.Value = BeatCell.Add(last.Value, last.GetValueDividedByMultFactors(value));
                    }
                }
            }
            else
            {
                Cell below = Row.Cells.LookupIndex(Cells[0].Index - 1).Cell;
                // if below is last cell of a repeat group, we instead operate on that group's LTM
                Repeat leftGroup    = below.RepeatGroups.Where(x => x.ExclusiveCells.Last.Value == below).FirstOrDefault();
                bool   useLeftGroup = leftGroup != default(Repeat);
                // if last cell in selection is last of a repeat group, operate on it's LTM
                Repeat rightGroup    = last.RepeatGroups.Where(x => x.ExclusiveCells.Last.Value == last).FirstOrDefault();
                bool   useRightGroup = rightGroup != default(Repeat);

                if (ShiftingRight)
                {
                    if (Cells.Last() == Row.Cells.Max.Cell)
                    {
                        ChangesViewWidth = true;
                    }

                    if (useLeftGroup)
                    {
                        // add to LTM
                        leftGroup.LastTermModifier = BeatCell.Add(leftGroup.LastTermModifier, leftGroup.GetValueDividedByMultFactor(value));
                    }
                    else
                    {
                        // add to below cell's value
                        below.Value = BeatCell.Add(below.Value, below.GetValueDividedByMultFactors(value));
                    }
                    // subtract from last cell's value if not last of row
                    if (last != Row.Cells.Max.Cell)
                    {
                        if (useRightGroup)
                        {
                            // subtract from LTM
                            rightGroup.LastTermModifier = BeatCell.Subtract(rightGroup.LastTermModifier, rightGroup.GetValueDividedByMultFactor(value));
                        }
                        else
                        {
                            last.Value = BeatCell.Subtract(last.Value, last.GetValueDividedByMultFactors(value));
                        }
                    }
                }
                else
                {
                    if (useLeftGroup)
                    {
                        // subtract from LTM
                        leftGroup.LastTermModifier = BeatCell.Subtract(leftGroup.LastTermModifier, leftGroup.GetValueDividedByMultFactor(value));
                    }
                    else
                    {
                        // subtract from below cell's value
                        below.Value = BeatCell.Subtract(below.Value, below.GetValueDividedByMultFactors(value));
                    }
                    // add to last cell's value if not last in row
                    if (last != Row.Cells.Max.Cell)
                    {
                        if (useRightGroup)
                        {
                            rightGroup.LastTermModifier = BeatCell.Add(rightGroup.LastTermModifier, rightGroup.GetValueDividedByMultFactor(value));
                        }
                        else
                        {
                            last.Value = BeatCell.Add(last.Value, last.GetValueDividedByMultFactors(value));
                        }
                    }
                }
            }

            Cells = null;
        }