Example #1
0
        public AbstractBeatCodeAction(Row row, string headerText)
        {
            Row = row;

            if (!row.BeatCodeIsCurrent)
            {
                row.UpdateBeatCode();
            }
            BeforeBeatCode = row.BeatCode;
            BeforeOffset   = row.OffsetValue;
            HeaderText     = headerText;

            // Find the right index
            CellTree selectedCells = EditorViewController.Instance.DView.SelectedCells;

            // get current selection range if it's in this row
            //int selectionStart = -1;
            //int rowLengthBefore = Row.Cells.Count;

            // get selection indexes if there is a selection in the action's row
            if (selectedCells.Root != null && selectedCells.Root.Cell.Row == Row)
            {
                // find index of first selected cell
                //selectionStart = 0;
                //foreach (Cell c in Row.Cells)
                //{
                //	if (c.IsSelected) break;
                //	selectionStart++;
                //}

                RightIndexBoundOfTransform = selectedCells.Min.Cell.Index + selectedCells.Count - 1;
            }
        }
Example #2
0
        public virtual void Undo()
        {
            // if no change, don't do anything
            if (AfterBeatCode == BeforeBeatCode)
            {
                return;
            }

            CellTree selectedCells = EditorViewController.Instance.DView.SelectedCells;

            // get current selection range if it's in this row
            int selectionStart = -1;
            int selectionEnd   = -1;

            // get selection indexes if there is a selection in the action's row
            if (selectedCells.Root != null && selectedCells.Root.Cell.Row == Row)
            {
                // find index of first selected cell
                selectionStart = selectedCells.Min.Cell.Index;

                selectionEnd = selectedCells.Max.Cell.Index;
            }

            bool selectFromBack = selectionEnd > RightIndexBoundOfTransform;

            if (selectFromBack)
            {
                // get index from back of list
                selectionStart = Row.Cells.Count - selectionStart;
                selectionEnd   = Row.Cells.Count - selectionEnd;
            }

            Row.FillFromBeatCode(BeforeBeatCode);
            if (BeforeOffset != AfterOffset)
            {
                Row.OffsetValue = BeforeOffset;
                Row.Offset      = BeatCell.Parse(BeforeOffset);
            }

            if (ChangesViewWidth)
            {
                double maxDur = DrawingView.Instance.Rows.Max(x => x.Duration);

                DrawingView.Instance.ResizeFrame(maxDur, false);
            }
            else
            {
                EditorViewController.Instance.DView.QueueRowToDraw(Row);

                RedrawReferencers();
            }

            EditorViewController.Instance.DView.ChangesApplied = false;

            // would be nice to only draw individual rows, but seems to be a problem
            //DrawingView.Instance.NeedsDisplay = true;


            if (selectionStart > -1)
            {
                if (selectFromBack)
                {
                    // convert back to forward indexed
                    selectionStart = Row.Cells.Count - selectionStart;
                    selectionEnd   = Row.Cells.Count - selectionEnd;
                }

                if (selectionStart < 0)
                {
                    selectionStart = 0;
                }
                if (selectionEnd >= Row.Cells.Count)
                {
                    selectionEnd = Row.Cells.Count - 1;
                }

                // make new selection
                CellTreeNode startNode = Row.Cells.LookupIndex(selectionStart);
                CellTreeNode endNode   = Row.Cells.LookupIndex(selectionEnd);

                EditorViewController.Instance.DView.SelectCell(startNode.Cell);

                if (startNode != endNode)
                {
                    EditorViewController.Instance.DView.SelectCell(endNode.Cell, true);
                }
            }
        }
Example #3
0
        public virtual void Redo()
        {
            CellTree selectedCells = EditorViewController.Instance.DView.SelectedCells;

            // get current selection range if it's in this row
            int selectionStart  = -1;
            int selectionEnd    = -1;
            int rowLengthBefore = Row.Cells.Count;

            // get selection indexes if there is a selection in the action's row
            if (selectedCells.Root != null && selectedCells.Root.Cell.Row == Row)
            {
                // find index of first selected cell

                selectionStart = selectedCells.Min.Cell.Index;

                selectionEnd = selectedCells.Max.Cell.Index;
            }

            if (string.IsNullOrEmpty(AfterBeatCode))
            {
                // perform the transform and get the new beat code
                Transformation();

                AfterBeatCode = Row.Stringify();
                AfterOffset   = Row.OffsetValue;
            }

            bool selectFromBack = selectionEnd > RightIndexBoundOfTransform;

            if (selectFromBack)
            {
                // get index from back of list
                selectionStart = rowLengthBefore - selectionStart;
                selectionEnd   = rowLengthBefore - selectionEnd;
            }

            Row.FillFromBeatCode(AfterBeatCode);
            if (BeforeOffset != AfterOffset)
            {
                Row.OffsetValue = AfterOffset;
                Row.Offset      = BeatCell.Parse(AfterOffset);
            }

            if (ChangesViewWidth)
            {
                double maxDur = DrawingView.Instance.Rows.Max(x => x.Duration);

                // change the view's width
                //var curFrame = DrawingView.Instance.Frame;
                //curFrame.Width = (System.nfloat)(maxDur * DrawingView.ScalingFactor + 550);
                //DrawingView.Instance.Frame = curFrame;

                // need to draw the end portion of other rows
                if (maxDur == Row.Duration)
                {
                    DrawingView.Instance.ResizeFrame(maxDur);
                }
                else
                {
                    ChangesViewWidth = false;
                }
            }

            DrawingView.Instance.QueueRowToDraw(Row);

            DrawingView.Instance.ChangesApplied = false;
            RedrawReferencers();

            if (selectionStart > -1)
            {
                if (selectFromBack)
                {
                    // convert back to forward indexed
                    selectionStart = Row.Cells.Count - selectionStart;
                    selectionEnd   = Row.Cells.Count - selectionEnd;
                }

                if (selectionStart < 0)
                {
                    selectionStart = 0;
                }
                if (selectionEnd >= Row.Cells.Count)
                {
                    selectionEnd = Row.Cells.Count - 1;
                }

                // make new selection

                CellTreeNode startNode = Row.Cells.LookupIndex(selectionStart);
                CellTreeNode endNode   = Row.Cells.LookupIndex(selectionEnd);

                if (startNode != null && endNode != null)
                {
                    EditorViewController.Instance.DView.SelectCell(startNode.Cell);
                    if (startNode != endNode)
                    {
                        EditorViewController.Instance.DView.SelectCell(endNode.Cell, true);
                    }
                }
            }
        }