private int GetScreenPointForString(PastePointParam param, GuitarNote note)
 {
     int noteY = TopLineOffset + LineSpacing *
         (5 - (param.MousePos.Y - param.Offset.Y + note.NoteString - param.MinNoteString)) -
         NoteHeight / 2;
     return noteY;
 }
        void DrawPasteChord(PastePointParam param, GuitarChord chord, Graphics g)
        {
            int alpha = 120;
            foreach(var note in chord.Notes)
            {
                var i = note.NoteString;

                var start = GetScreenPointFromTick(note.DownTick);
                var end = GetScreenPointFromTick(note.UpTick);

                int noteX = param.MousePos.X;

                noteX = noteX + (int)(start - param.MinChordX)
                    + param.Offset.X;

                int noteY = TopLineOffset + LineSpacing *
                    (5-(param.MousePos.Y -param.MinNoteString + note.NoteString )) -
                    NoteHeight / 2
                    + param.Offset.Y;

                var width = end - start;

                using (var p = new Pen(Color.FromArgb(alpha, Utility.noteBGBrushSel.Color)))
                {
                    g.DrawRectangle(p,
                        noteX + Utility.NoteSelectionOffsetLeft,
                        noteY + Utility.NoteSelectionOffsetUp,
                        width + Utility.NoteSelectionOffsetRight-1,
                        NoteHeight + Utility.NoteSelectionOffsetDown-1);
                }

                Color bgColor = Utility.noteBGBrush.Color;
                if (note.Channel == Utility.ChannelX)
                {
                    bgColor = Utility.noteXBrush.Color;
                }
                else if (note.Channel == Utility.ChannelTap)
                {
                    bgColor = Utility.noteTapBrush.Color;
                }
                using (var sb = new SolidBrush(Color.FromArgb(alpha, bgColor)))
                {
                    g.FillRectangle(sb,
                                noteX, noteY,
                                width, NoteHeight);
                }

                using (var rectPen = new Pen(Color.FromArgb(alpha, Utility.noteBoundPen.Color)))
                {
                    g.DrawRectangle(rectPen,
                            noteX, noteY,
                            width,
                            NoteHeight);
                }

                using (var selPen = new Pen(Color.FromArgb(alpha, Utility.selectedPen.Color)))
                {
                    g.DrawRectangle(selPen,
                            noteX, noteY,
                            width,
                            NoteHeight);
                }

                using (var fb = new SolidBrush(Color.FromArgb(alpha, Utility.fretBrush.Color)))
                {

                    string noteTxt = note.NoteFretDown.ToString();
                    if (note.Channel == Utility.ChannelX)
                    {
                        noteTxt = Utility.XNoteText;
                    }
                    g.DrawString(noteTxt,
                        Utility.fretFont,
                        fb,
                        noteX + Utility.NoteTextXOffset,
                        noteY - (int)(Utility.fontHeight / 4.0 + Utility.NoteTextYOffset));
                }

            }
        }
        public List<GuitarChord> PasteCopyBuffer(PastePointParam pastePoint)
        {
            var newChords = new List<GuitarChord>();
            try
            {
                if (CopyChords.Chords.Any())
                {
                    if (CurrentSelectionState != TrackEditor.EditorSelectionState.PastingNotes &&
                        CurrentSelectionState != TrackEditor.EditorSelectionState.MovingNotes)
                    {
                        CurrentSelectionState = TrackEditor.EditorSelectionState.PastingNotes;
                        return newChords;
                    }

                    BackupSequence();

                    var copyRange = CopyChords.Chords.GetTickPair();

                    var stringOffset = (pastePoint.MousePos.Y) - pastePoint.MinNoteString - pastePoint.Offset.Y;

                    var startTick = GetTickFromClientPoint(pastePoint.MousePos.X + pastePoint.Offset.X);// pastePoint.Offset.X + pastePoint.MousePos.X);

                    var pasteRange = new TickPair(startTick, startTick + copyRange.TickLength);

                    var copyTime = guitarTrack.TickToTime(copyRange);

                    var pasteTime = guitarTrack.TickToTime(pasteRange);

                    pasteTime.TimeLength = copyTime.TimeLength;
                    pasteRange.Up = guitarTrack.TimeToTick(pasteTime.Up);

                    pasteRange = EditorPro.SnapTickPairPro(pasteRange);

                    guitarTrack.Remove(Messages.Chords.GetBetweenTick(pasteRange.Expand(-Utility.NoteCloseWidth)).ToList());

                    foreach (var c in CopyChords.Chords)
                    {
                        var noteTime = guitarTrack.TickToTime(c.TickPair);

                        var delta = noteTime.Down - copyTime.Down;

                        var startEndTick = new TickPair(
                            guitarTrack.TimeToTick(pasteTime.Down + delta),
                            guitarTrack.TimeToTick(pasteTime.Down + delta + c.TimeLength));

                        var snappedTicks = SnapLeftRightTicks(startEndTick, new SnapConfig(true, true, true));

                        var newChord = c.CloneAtTime(Messages, snappedTicks, stringOffset);
                        if (newChord != null)
                        {
                            newChords.Add(newChord);
                        }
                    }

                    ClearSelection();

                    foreach (var c in newChords.Where(x => !x.IsDeleted)) { c.Selected = true; }

                    Invalidate();
                }
            }
            catch { RestoreBackup(); }

            return newChords;
        }
        public List<GuitarChord> PasteCopyBuffer(PastePointParam pastePoint)
        {
            var newChords = new List<GuitarChord>();
            try
            {
                if (CopyChords.Count() > 0)
                {
                    if (CurrentSelectionState != TrackEditor.EditorSelectionState.PastingNotes &&
                        CurrentSelectionState != TrackEditor.EditorSelectionState.MovingNotes)
                    {
                        CurrentSelectionState = TrackEditor.EditorSelectionState.PastingNotes;
                        return newChords;
                    }

                    BackupSequence();

                    double selectedStartTime =
                        Utility.ScaleTimeDown(HScrollValue +
                            pastePoint.Offset.X+pastePoint.MousePos.X);

                    int minTick = CopyChords.GetMinTick();
                    int maxTick = CopyChords.GetMaxTick();

                    var pasteLen = guitarTrack.TickToTime(maxTick) - guitarTrack.TickToTime(minTick);

                    int selLen = maxTick - minTick;

                    double minTime = GuitarTrack.TickToTime(minTick);
                    int testTick = Int32.MinValue;

                    var selectedEndTime = selectedStartTime + pasteLen;

                    guitarTrack.Remove(
                        guitarTrack.GetChordsAtTick(
                            guitarTrack.TimeToTick(selectedStartTime) + Utility.NoteCloseWidth,
                            guitarTrack.TimeToTick(selectedEndTime) - Utility.NoteCloseWidth));

                    foreach (var c in CopyChords)
                    {
                        var noteDown = GuitarTrack.TickToTime(c.DownTick);
                        var noteUp = GuitarTrack.TickToTime(c.UpTick);

                        var delta = noteDown - minTime;

                        var startTick = GuitarTrack.TimeToTick(selectedStartTime +
                            delta);

                        var endTick = GuitarTrack.TimeToTick(selectedStartTime +
                            delta + (noteUp - noteDown));

                        var minNoteString = pastePoint.MinNoteString;
                        var mouseString = pastePoint.MousePos.Y;
                        var offset = (mouseString) - pastePoint.MinNoteString - (pastePoint.Offset.Y / LineSpacing);

                        var st = GetTickGridSnap(startTick);
                        var et = GetTickGridSnap(endTick);

                        if (!testTick.IsNull() && st < testTick)
                        {
                            st = testTick;
                            if (Utility.IsCloseTick(et, st))
                            {
                                et = st + Utility.NoteCloseWidth;
                            }
                        }

                        var newChord = c.CloneAtTime(guitarTrack, st, et, offset, testTick);
                        if (newChord != null)
                        {
                            newChords.Add(newChord);

                            testTick = newChord.UpTick;
                        }
                    }

                    ClearSelection();
                    foreach (var c in newChords.Where(x => !x.IsDeleted)) { c.Selected = true; }
                }
            }
            catch { RestoreBackup(); }

            if (OnReloadTrack != null)
            {
                OnReloadTrack(this, SelectNextEnum.ForceKeepSelection);
            }

            return newChords;
        }