void peTrack_DifficultyItemDropped(PEMidiTrack sender, GuitarDifficulty difficulty, DragEventArgs e)
        {
            var o = e.GetDropObject <PETrackDifficulty>();

            o.IfObjectNotNull(op =>
            {
                DoRequestBackup();

                var messages = sender.Track.GetChanMessagesByDifficulty(difficulty);
                sender.Track.Remove(messages);

                var otrack = o.MidiTrack.Track;

                var clonedTrack = otrack.CloneDifficulty(o.Difficulty, difficulty, sender.Track.FileType);

                var clonedMessages = clonedTrack.GetChanMessagesByDifficulty(difficulty).ToList();

                foreach (var msg in clonedMessages)
                {
                    sender.Track.Insert(msg.AbsoluteTicks, msg.Clone());
                }

                SetSelectedItem(sender.Track, o.Difficulty);

                TrackClicked.IfObjectNotNull(x => x(this, sender.Track.Sequence, sender.Track, difficulty));
            });
        }
        private void panelTracks_DragDrop(object sender, DragEventArgs e)
        {
            var droppedPETrack = e.GetDropObject <PEMidiTrack>();

            droppedPETrack.IfObjectNotNull(xx =>
            {
                if (droppedPETrack != sender)
                {
                    DoRequestBackup();

                    Track newTrack = null;
                    if (Sequence == null)
                    {
                        var targetType = this.IsPro ? FileType.Pro : FileType.Guitar5;

                        var seq       = new Sequence(targetType, droppedPETrack.Track.Sequence.Division);
                        this.sequence = seq;
                        if (!droppedPETrack.Track.IsTempo())
                        {
                            var tempo = droppedPETrack.Track.Sequence.Tracks.Where(x => x.IsTempo());
                            if (tempo.Any())
                            {
                                seq.AddTempo(tempo.First().ConvertToPro());
                            }
                        }
                        newTrack = droppedPETrack.Track.Clone(seq.FileType);
                        seq.Add(newTrack);
                    }
                    else
                    {
                        if (this.Sequence == droppedPETrack.Track.Sequence)
                        {
                            this.Sequence.MoveTrack(droppedPETrack.Track.GetTrackIndex(), GetInsertAt());
                        }
                        else
                        {
                            newTrack = droppedPETrack.Track.Clone(Sequence.FileType);

                            sequence.Insert(GetInsertAt(), newTrack);

                            if (!sequence.Tracks.Any(x => x.IsTempo()))
                            {
                                var tempo = droppedPETrack.Track.Sequence.Tracks.Where(x => x.IsTempo());
                                if (tempo.Any())
                                {
                                    sequence.AddTempo(tempo.First().ConvertToPro());
                                }
                            }
                        }
                    }

                    CreatePanelTracks(this.sequence);
                    TrackAdded.IfObjectNotNull(tc => tc(this, this.sequence, newTrack, SelectedDifficulty));
                }
            });
            dragItem = null;
        }
        void t_TrackDifficultyChanged(object sender, Track track, GuitarDifficulty difficulty)
        {
            (sender as PEMidiTrack).IfObjectNotNull(x =>
            {
                SelectedTrack = x;
            });

            this.SelectedDifficulty = difficulty;

            TrackClicked.IfObjectNotNull(x => x(this, track.Sequence, track, difficulty));
        }
        void peTrack_ItemDropped(PEMidiTrack sender, DragEventArgs e)
        {
            var peTrack = e.GetDropObject <PEMidiTrack>();

            peTrack.IfObjectNotNull(x =>
            {
                if (peTrack != sender)
                {
                    DoRequestBackup();

                    Track newTrack = null;
                    if (sender.Track.Sequence == peTrack.Track.Sequence)
                    {
                        newTrack = peTrack.Track;
                        sender.Track.Sequence.MoveTrack(peTrack.Track.GetTrackIndex(), GetInsertAt());
                    }
                    else
                    {
                        if (IsPro && peTrack.Track.Name.IsProTrackName())
                        {
                            newTrack = new Track(FileType.Pro, peTrack.Track.Name);

                            newTrack.Merge(peTrack.Track);
                        }
                        else if (IsPro == false && peTrack.Track.Name.IsProTrackName() == false)
                        {
                            newTrack = new Track(FileType.Guitar5, peTrack.Track.Name);

                            newTrack.Merge(sender.Track);
                        }
                        else
                        {
                            newTrack = peTrack.Track.Clone(sender.Track.FileType);
                        }

                        newTrack.Name = sender.Track.Name;

                        sender.Track.Sequence.Insert(GetInsertAt(), newTrack);

                        if (!ModifierKeys.HasFlag(Keys.Shift))
                        {
                            sender.Track.Sequence.Remove(sender.Track);
                        }
                    }
                    Refresh();
                    SetSelectedItem(newTrack, SelectedDifficulty);

                    t_TrackClicked(this, newTrack, SelectedDifficulty);
                }
            });
            dragItem = null;
        }
        bool SetSelectedItem(Track item, GuitarDifficulty difficulty)
        {
            bool ret = true;

            if (item != null)
            {
                var sel    = SelectedTrack;
                var newSel = TrackList.SingleOrDefault(x => x.Track == item);
                if (sel == null || sel != newSel)
                {
                    ret           = true;
                    SelectedTrack = newSel;
                }
            }
            else
            {
                SelectedTrack = null;
            }
            SelectedDifficulty = difficulty;

            panelTracks.Invalidate();
            return(ret);
        }
 void peTrack_ItemBeginDrag(PEMidiTrack sender, DragEventArgs e)
 {
     dragItem = sender;
     panelTracks.Invalidate();
 }
 void peTrack_ItemDifficultyBeginDrag(PEMidiTrack sender, GuitarDifficulty difficulty, DragEventArgs e)
 {
     dragItem = sender;
     panelTracks.Invalidate();
 }
 void peTrack_ItemDragCancel(PEMidiTrack sender, DragEventArgs e)
 {
     dragItem = null;
     panelTracks.Invalidate();
 }
        private void panelTracks_DragDrop(object sender, DragEventArgs e)
        {
            var droppedPETrack = e.GetDropObject<PEMidiTrack>();
            droppedPETrack.IfObjectNotNull(xx =>
            {
                if (droppedPETrack != sender)
                {
                    DoRequestBackup();

                    Track newTrack = null;
                    if (Sequence == null)
                    {
                        var targetType = this.IsPro ? FileType.Pro : FileType.Guitar5;

                        var seq = new Sequence(targetType, droppedPETrack.Track.Sequence.Division);
                        this.sequence = seq;
                        if (!droppedPETrack.Track.IsTempo())
                        {
                            var tempo = droppedPETrack.Track.Sequence.Tracks.Where(x => x.IsTempo());
                            if (tempo.Any())
                            {
                                seq.AddTempo(tempo.First().ConvertToPro());
                            }
                        }
                        newTrack = droppedPETrack.Track.Clone(seq.FileType);
                        seq.Add(newTrack);
                    }
                    else
                    {

                        if (this.Sequence == droppedPETrack.Track.Sequence)
                        {
                            this.Sequence.MoveTrack(droppedPETrack.Track.GetTrackIndex(), GetInsertAt());
                        }
                        else
                        {
                            newTrack = droppedPETrack.Track.Clone(Sequence.FileType);

                            sequence.Insert(GetInsertAt(), newTrack);

                            if (!sequence.Tracks.Any(x => x.IsTempo()))
                            {
                                var tempo = droppedPETrack.Track.Sequence.Tracks.Where(x => x.IsTempo());
                                if (tempo.Any())
                                {
                                    sequence.AddTempo(tempo.First().ConvertToPro());
                                }
                            }
                        }
                    }

                    CreatePanelTracks(this.sequence);
                    TrackAdded.IfObjectNotNull(tc => tc(this, this.sequence, newTrack, SelectedDifficulty));
                }
            });
            dragItem = null;
        }
 public PETrackDifficulty(PEMidiTrack track, GuitarDifficulty diff)
 {
     this.MidiTrack = track;
     this.Difficulty = diff;
 }
        void peTrack_ItemDropped(PEMidiTrack sender, DragEventArgs e)
        {
            var peTrack = e.GetDropObject<PEMidiTrack>();
            peTrack.IfObjectNotNull(x =>
            {
                if (peTrack != sender)
                {
                    DoRequestBackup();

                    Track newTrack = null;
                    if (sender.Track.Sequence == peTrack.Track.Sequence)
                    {
                        newTrack = peTrack.Track;
                        sender.Track.Sequence.MoveTrack(peTrack.Track.GetTrackIndex(), GetInsertAt());
                    }
                    else
                    {
                        if (IsPro && peTrack.Track.Name.IsProTrackName())
                        {
                            newTrack = new Track(FileType.Pro, peTrack.Track.Name);

                            newTrack.Merge(peTrack.Track);
                        }
                        else if (IsPro == false && peTrack.Track.Name.IsProTrackName() == false)
                        {
                            newTrack = new Track(FileType.Guitar5, peTrack.Track.Name);

                            newTrack.Merge(sender.Track);
                        }
                        else
                        {
                            newTrack = peTrack.Track.Clone(sender.Track.FileType);
                        }

                        newTrack.Name = sender.Track.Name;

                        sender.Track.Sequence.Insert(GetInsertAt(), newTrack);

                        if (!ModifierKeys.HasFlag(Keys.Shift))
                        {
                            sender.Track.Sequence.Remove(sender.Track);
                        }
                    }
                    Refresh();
                    SetSelectedItem(newTrack, SelectedDifficulty);

                    t_TrackClicked(this, newTrack, SelectedDifficulty);

                }
            });
            dragItem = null;
        }
 void peTrack_ItemDragCancel(PEMidiTrack sender, DragEventArgs e)
 {
     dragItem = null;
     panelTracks.Invalidate();
 }
 void peTrack_ItemDifficultyBeginDrag(PEMidiTrack sender, GuitarDifficulty difficulty, DragEventArgs e)
 {
     dragItem = sender;
     panelTracks.Invalidate();
 }
 void peTrack_ItemBeginDrag(PEMidiTrack sender, DragEventArgs e)
 {
     dragItem = sender;
     panelTracks.Invalidate();
 }
        void peTrack_DifficultyItemDropped(PEMidiTrack sender, GuitarDifficulty difficulty, DragEventArgs e)
        {
            var o = e.GetDropObject<PETrackDifficulty>();
            o.IfObjectNotNull(op =>
            {
                DoRequestBackup();

                var messages = sender.Track.GetChanMessagesByDifficulty(difficulty);
                sender.Track.Remove(messages);

                var otrack = o.MidiTrack.Track;

                var clonedTrack = otrack.CloneDifficulty(o.Difficulty, difficulty, sender.Track.FileType);

                var clonedMessages = clonedTrack.GetChanMessagesByDifficulty(difficulty).ToList();

                foreach(var msg in clonedMessages)
                {
                    sender.Track.Insert(msg.AbsoluteTicks, msg.Clone());
                }

                SetSelectedItem(sender.Track, o.Difficulty);

                TrackClicked.IfObjectNotNull(x => x(this, sender.Track.Sequence, sender.Track, difficulty));
            });
        }
        void t_TrackNameDoubleClicked(object sender, Track track, GuitarDifficulty difficulty)
        {
            textBoxTrackName.Text = track.Name;

            (sender as PEMidiTrack).IfObjectNotNull(x => SelectedTrack = x);
        }
Пример #17
0
 public PETrackDifficulty(PEMidiTrack track, GuitarDifficulty diff)
 {
     this.MidiTrack  = track;
     this.Difficulty = diff;
 }
        void CreatePanelTracks(Sequence seq, bool forceRefresh = false)
        {
            bool refresh = false;

            if (forceRefresh == false && seq != null)
            {
                if (seq != this.sequence)
                {
                    refresh = true;
                }
                else
                {
                    if (panelTracks.Controls.Count != seq.Count)
                    {
                        refresh = true;
                    }
                    else
                    {
                        for (int x = 0; x < seq.Count; x++)
                        {
                            var trackListTrack = TrackList[x].Track;
                            var sequenceTrack  = seq[x];
                            if (sequenceTrack != trackListTrack || (trackListTrack.Name != sequenceTrack.Name))
                            {
                                refresh = true;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                refresh = true;
            }
            if (!refresh)
            {
                return;
            }

            SuspendLayout();
            this.sequence = seq;
            Track osel = null;

            if (SelectedTrack != null)
            {
                osel = SelectedTrack.Track;
            }
            if (Sequence != null)
            {
                panelTracks.Controls.Clear();
                foreach (var tr in sequence.ToList())
                {
                    var peTrack = new PEMidiTrack(tr);
                    peTrack.TabIndex = panelTracks.Controls.Count;

                    peTrack.TrackClicked           += new TrackEventHandler(t_TrackClicked);
                    peTrack.TrackDifficultyChanged += new TrackEventHandler(t_TrackDifficultyChanged);
                    peTrack.TrackNameDoubleClicked += new TrackEventHandler(t_TrackNameDoubleClicked);

                    peTrack.AllowDrop = true;

                    peTrack.DifficultyItemDropped += new PEMidiTrackDifficultyDropEventHandler(peTrack_DifficultyItemDropped);
                    peTrack.ItemDropped           += new PEMidiTrackDropEventHandler(peTrack_ItemDropped);
                    peTrack.MouseMove             += new MouseEventHandler(peTrack_MouseMove);
                    peTrack.Dock                     = DockStyle.Top;
                    peTrack.ItemBeginDrag           += new PEMidiTrackDropEventHandler(peTrack_ItemBeginDrag);
                    peTrack.ItemDifficultyBeginDrag += new PEMidiTrackDifficultyDropEventHandler(peTrack_ItemDifficultyBeginDrag);
                    peTrack.ItemDragCancel          += new PEMidiTrackDropEventHandler(peTrack_ItemDragCancel);
                    peTrack.DragOver                += new DragEventHandler(peTrack_DragOver);
                    panelTracks.Controls.Add(peTrack);
                    peTrack.BringToFront();
                }


                if (osel != null)
                {
                    SelectedTrack = TrackList.FirstOrDefault(x => x.Track == osel);
                }
            }
            else
            {
                panelTracks.Controls.Clear();
                textBoxTrackName.Text = "";
            }

            ResumeLayout();
        }
        void CreatePanelTracks(Sequence seq, bool forceRefresh = false)
        {
            bool refresh = false;
            if (forceRefresh == false && seq != null)
            {
                if (seq != this.sequence)
                    refresh = true;
                else
                {
                    if (panelTracks.Controls.Count != seq.Count)
                        refresh = true;
                    else
                    {
                        for (int x = 0; x < seq.Count; x++)
                        {
                            var trackListTrack = TrackList[x].Track;
                            var sequenceTrack = seq[x];
                            if (sequenceTrack != trackListTrack || (trackListTrack.Name != sequenceTrack.Name))
                            {
                                refresh = true;
                                break;
                            }
                        }
                    }
                }
            }
            else
            {
                refresh = true;
            }
            if (!refresh)
            {
                return;
            }

            SuspendLayout();
            this.sequence = seq;
            Track osel = null;
            if (SelectedTrack != null)
            {
                osel = SelectedTrack.Track;
            }
            if (Sequence != null)
            {

                panelTracks.Controls.Clear();
                foreach (var tr in sequence.ToList())
                {
                    var peTrack = new PEMidiTrack(tr);
                    peTrack.TabIndex = panelTracks.Controls.Count;

                    peTrack.TrackClicked += new TrackEventHandler(t_TrackClicked);
                    peTrack.TrackDifficultyChanged += new TrackEventHandler(t_TrackDifficultyChanged);
                    peTrack.TrackNameDoubleClicked += new TrackEventHandler(t_TrackNameDoubleClicked);

                    peTrack.AllowDrop = true;

                    peTrack.DifficultyItemDropped += new PEMidiTrackDifficultyDropEventHandler(peTrack_DifficultyItemDropped);
                    peTrack.ItemDropped += new PEMidiTrackDropEventHandler(peTrack_ItemDropped);
                    peTrack.MouseMove += new MouseEventHandler(peTrack_MouseMove);
                    peTrack.Dock = DockStyle.Top;
                    peTrack.ItemBeginDrag += new PEMidiTrackDropEventHandler(peTrack_ItemBeginDrag);
                    peTrack.ItemDifficultyBeginDrag += new PEMidiTrackDifficultyDropEventHandler(peTrack_ItemDifficultyBeginDrag);
                    peTrack.ItemDragCancel += new PEMidiTrackDropEventHandler(peTrack_ItemDragCancel);
                    peTrack.DragOver += new DragEventHandler(peTrack_DragOver);
                    panelTracks.Controls.Add(peTrack);
                    peTrack.BringToFront();
                }

                if (osel != null)
                {
                    SelectedTrack = TrackList.FirstOrDefault(x => x.Track == osel);
                }
            }
            else
            {
                panelTracks.Controls.Clear();
                textBoxTrackName.Text = "";
            }

            ResumeLayout();
        }