public Rectangle GetCurrentRect(TrackEditor editor)
        {
            var rect = editor.GetScreenRectFromMessage(Chord);

            return new Rectangle(CurrentPoint,
                new Size(Utility.SelectorWidth,
                     rect.Height));
        }
        public NoteGrid(TrackEditor editor)
        {
            timeUnits = new TimeUnit[] { TimeUnit.Whole, TimeUnit.Half, TimeUnit.Quarter, TimeUnit.Eight, TimeUnit.Sixteenth, TimeUnit.ThirtySecond, TimeUnit.SixtyFourth, TimeUnit.OneTwentyEigth };

            this.editor = editor;
            Points = new List<GridPoint>();
            Build(GetTimeUnitFromGridScalar(editor.GridScalar));
        }
        public void SetControl(Control ctrl, TrackEditor editorPro)
        {
            this.EditorPro = editorPro;
            if (currentControl != null)
            {
                if (Controls.Contains(currentControl))
                {
                    Controls.Remove(currentControl);
                }
                currentControl = null;
            }

            currentControl = ctrl;

            Controls.Add(currentControl);
            ctrl.Parent = this;
            this.ClientSize = new Size(currentControl.Width, currentControl.Height);
        }
 void TrackEditor_OnLoadTrack(TrackEditor editor, Sequence seq, Track t)
 {
     editor.Refresh();
     //LogDebugEvent("onloadtrack " + (t == null ? "" : t.Name));
 }
        public bool OnTrackEditorProClick(TrackEditor editor, MouseEventArgs e)
        {
            if (DesignMode)
                return false;
            try
            {

                if (tabContainerMain.SelectedTab == tabNoteEditor)
                {

                    if (editor.CreationState == TrackEditor.EditorCreationState.CreatingNote)
                    {
                        if (DoCreateChordFromScreenPoint(editor, e))
                            return true;
                    }
                    else if (editor.CreationState == TrackEditor.EditorCreationState.CopyingPattern)
                    {
                        var gc = editor.GetChordFromPoint(e.Location);

                        if (gc != null && DoCopyPatternSelection(gc, editor, e))
                            return true;
                    }
                }
                else if (tabContainerMain.SelectedTab == tabModifierEditor)
                {
                    var gc = editor.GetChordFromPoint(e.Location);

                    if (editor.CreationState == TrackEditor.EditorCreationState.CreatingSolo)
                    {
                        if (gc != null && DoSoloCreation(gc, editor, e))
                            return true;
                    }
                    else if (editor.CreationState == TrackEditor.EditorCreationState.CreatingPowerup)
                    {
                        if (gc != null && DoPowerupCreation(gc, editor, e))
                            return true;
                    }
                    else if (editor.CreationState == TrackEditor.EditorCreationState.CreatingMultiTremelo)
                    {
                        if (gc != null && DoMultiStringTremeloCreation(gc, editor, e))
                            return true;
                    }
                    else if (editor.CreationState == TrackEditor.EditorCreationState.CreatingSingleTremelo)
                    {
                        if (gc != null && DoSingleStringTremeloCreation(gc, editor, e))
                            return true;
                    }
                    else if (editor.CreationState == TrackEditor.EditorCreationState.CreatingArpeggio)
                    {
                        if (gc != null && DoArpeggioCreation(gc, editor, e))
                            return true;
                    }
                }
                else if (tabContainerMain.SelectedTab == tabPageEvents)
                {
                    var gc = editor.GetChordFromPoint(e.Location);

                    if (editor.CreationState == TrackEditor.EditorCreationState.CreatingProGuitarTrainer)
                    {
                        if (gc != null && DoTrainerCreation(gc, editor, e))
                            return true;
                    }
                    else if (editor.CreationState == TrackEditor.EditorCreationState.CreatingProBassTrainer)
                    {
                        if (gc != null && DoTrainerCreation(gc, editor, e))
                            return true;
                    }
                    else
                    {
                        var tick = editor.GetTickFromClientPoint(editor.MousePositionSnapped.X);

                        textBoxEventTick.Text = SnapTickToMessagesPro(tick).ToStringEx();
                        return true;
                    }
                }
            }
            catch { }

            return false;
        }
        void RefreshTrackList(TrackEditor ed)
        {
            try
            {
                if (ed == EditorPro)
                {
                    midiTrackEditorPro.SetTrack(ed.MidiTrack, ed.CurrentDifficulty);

                    midiTrackEditorPro.Invalidate();
                }
                else
                {
                    midiTrackEditorG5.SetTrack(ed.MidiTrack, ed.CurrentDifficulty);
                    midiTrackEditorG5.Invalidate();
                }
            }
            catch { }
        }
        public bool DoTrainerCreation(GuitarChord gc, TrackEditor editor, MouseEventArgs e)
        {
            bool ret = false;
            try
            {
                if (statusItem != null && statusItem == labelProGuitarTrainerStatus)
                {
                    ret = true;
                    if (statusItem.Text == "Select Start Note")
                    {
                        statusItemStartTick = gc.UpTick;
                        statusItem.Text = "Select End Note " + gc.DownTick.ToStringEx();
                    }
                    else if (statusItem.Text.StartsWith("Select End Note "))
                    {
                        int downTick = (statusItem.Text.Substring(16)).ToInt();
                        if (gc.UpTick > downTick)
                        {
                            CreateTrainer(EditorPro.Messages, GuitarTrainerType.ProGuitar, new TickPair(downTick, gc.UpTick),
                                checkTrainerLoopableProGuitar.Checked);

                        }
                    }
                }
                if (statusItem != null && statusItem == labelProBassTrainerStatus)
                {
                    ret = true;
                    if (statusItem.Text == "Select Start Note")
                    {
                        statusItemStartTick = gc.UpTick;
                        statusItem.Text = "Select End Note " + gc.DownTick.ToStringEx();
                    }
                    else if (statusItem.Text.StartsWith("Select End Note "))
                    {
                        int downTick = (statusItem.Text.Substring(16)).ToInt();
                        if (gc.UpTick > downTick)
                        {
                            CreateTrainer(EditorPro.Messages, GuitarTrainerType.ProBass, new TickPair(downTick, gc.UpTick),
                                checkTrainerLoopableProBass.Checked);

                        }
                    }
                }

            }
            catch
            {

            }
            return ret;
        }
        public bool DoSoloCreation(GuitarChord gc, TrackEditor editor, MouseEventArgs e)
        {
            bool ret = false;
            try
            {
                if (statusItem != null && statusItem == label11)
                {
                    ret = true;
                    if (label11.Text == "Select Start Note")
                    {
                        statusItemStartTick = gc.UpTick;
                        label11.Text = "Select End Note " + gc.DownTick.ToStringEx();
                    }
                    else if (label11.Text.StartsWith("Select End Note "))
                    {
                        EditorPro.BackupSequence();

                        int time = label11.Text.Substring(16).ToInt();
                        if (gc.UpTick > time)
                        {

                            var overlap = ProGuitarTrack.Messages.Solos.GetBetweenTick(
                                new TickPair(time, gc.UpTick))
                                .Where(x => x.Data1 == Utility.SoloData1).ToArray();

                            if (overlap.Length > 0)
                            {
                                MessageBox.Show("Overlapping");
                            }
                            else
                            {
                                GuitarSolo.CreateSolo(EditorPro.Messages, new TickPair(time, gc.UpTick));
                            }
                            EditorPro.SetSelectionStateIdle();

                        }
                    }
                }
            }
            catch { }
            return ret;
        }
        public bool DoCreateChordFromScreenPoint(TrackEditor editor, MouseEventArgs e)
        {
            bool ret = false;
            try
            {

                ret = true;
                var mouseP = EditorPro.PointToClient(MousePosition);

                if (label17.Text == "Select Start")
                {
                    statusItemStartTick = EditorPro.GetTickFromScreenPoint(mouseP.X);
                    label17.Text = "Select End Note " + statusItemStartTick.ToString();
                }
                else if (label17.Text.StartsWith("Select End Note "))
                {
                    EditorPro.SetCreationStateIdle();

                    var mouseTick = EditorPro.GetTickFromScreenPoint(mouseP.X);

                    if (statusItemStartTick < mouseTick && !Utility.IsCloseTick(statusItemStartTick, mouseTick))
                    {

                        var ticks = new TickPair(statusItemStartTick, mouseTick);

                        var chordsAtTick = ProGuitarTrack.Messages.Chords.GetBetweenTick(ticks).ToList();

                        chordsAtTick.ToList().ForEach(x =>
                        {
                            if (Utility.IsCloseTick(x.UpTick, ticks.Down))
                            {
                                ticks.Down = x.UpTick;
                                chordsAtTick.Remove(x);
                            }
                            else if (Utility.IsCloseTick(x.DownTick, ticks.Up))
                            {
                                ticks.Up = x.DownTick;
                                chordsAtTick.Remove(x);
                            }
                        });

                        if (Utility.IsCloseTick(ticks.Down, ticks.Up) || (ticks.Down >= ticks.Up))
                        {
                            return ret;
                        }

                        if (chordsAtTick.Any() && checkBoxAllowOverwriteChord.Checked == false)
                        {
                            MessageBox.Show("Note Over-write not enabled");
                            return ret;
                        }
                        else
                        {
                            chordsAtTick.ToList().ForEach(x => x.DeleteAll());

                        }

                        if (checkBoxUseCurrentChord.Checked)
                        {
                            GuitarChord.CreateChord(EditorPro.Messages,
                                ProGuitarTrack.CurrentDifficulty,
                                EditorPro.SnapTickPairPro(ticks),
                                new GuitarChordConfig(ScreenFrets, ScreenChannels,
                                    checkIsSlide.Checked, checkIsSlideReversed.Checked,
                                    checkIsHammeron.Checked, GetChordStrumFromScreen(),
                                    GetChordRootNoteConfigFromScreen()));
                        }
                        else
                        {
                            var y = 5 - EditorPro.SnapToString(mouseP.Y);
                            if (y >= 0 && y < 6)
                            {
                                var frets = Utility.Null6;
                                var channels = Utility.Null6;

                                frets[y] = textBoxPlaceNoteFret.Text.ToInt(0);
                                channels[y] = Utility.ChannelDefault;

                                GuitarChord.CreateChord(EditorPro.Messages,
                                    ProGuitarTrack.CurrentDifficulty,
                                    EditorPro.SnapTickPairPro(ticks),
                                    new GuitarChordConfig(ScreenFrets, ScreenChannels,
                                        false, false, false, ChordStrum.Normal,
                                        GetChordRootNoteConfigFromScreen()));
                            }
                        }
                    }

                }

            }
            catch { }
            return ret;
        }
        public bool DoCopyPatternSelection(GuitarChord gc, TrackEditor editor, MouseEventArgs e)
        {
            bool ret = false;

            try
            {

                if (statusItem != null && statusItem == label20)
                {
                    ret = true;
                    if (label20.Text == "Select Start Note" || !EditorPro.SelectedChords.Any())
                    {
                        EditorPro.SetSelectedChord(gc, true);
                        label20.Text = "Select End Note";
                    }
                    else if (label20.Text.StartsWith("Select End Note"))
                    {
                        gc.Selected = true;
                        EditorPro.SetSelected(
                            EditorPro.Messages.Chords.GetBetweenTick(
                                EditorPro.SelectedChords.GetTickPair()));
                    }
                }
            }
            catch { }
            return ret;
        }
        public bool DoArpeggioCreation(GuitarChord gc, TrackEditor editor, MouseEventArgs e)
        {
            bool ret = false;
            try
            {
                if (statusItem != null && statusItem == label13)
                {
                    ret = true;
                    if (label13.Text == "Select Start Note")
                    {
                        statusItemStartTick = gc.UpTick;
                        label13.Text = "Select End Note " + gc.DownTick.ToStringEx();
                    }
                    else if (label13.Text.StartsWith("Select End Note "))
                    {
                        int time = (label13.Text.Substring(16)).ToInt();
                        if (gc.UpTick > time)
                        {
                            CreateArpeggio(time, statusItemStartTick, gc.UpTick, checkBoxCreateArpeggioHelperNotes.Checked);

                            EditorPro.SetCreationStateIdle();

                        }

                    }
                }
            }
            catch
            {
                UndoLast();
            }
            return ret;
        }