Example #1
0
        public override void MouseMove(int x, int y)
        {
            // keep adding or removing if we're dragging
            if (Handler.Action == ClipMouseAction.MultiSelect)
            {                
                var foundNote = Handler.Renderer.GetNoteAt(x, y);
                if (foundNote != null && isRemoving)
                {
                    Handler.Renderer.Clip.Notes.Remove(foundNote);
                    Handler.Renderer.Render();
                }
                else if (foundNote == null && isRemoving == false)
                {
                    var note = new SequencerClip.Note();
                    note.Length = 24;
                    note.Tick = MidiMath.Quantize(Handler.Renderer.GetTickAt(x), note.Length);
                    note.Pitch = Handler.Renderer.GetNoteAt(y);
                    note.Velocity = 100;
                    Handler.Renderer.Clip.Notes.Add(note);
                    Handler.Renderer.Clip.Sort();
                    Handler.Renderer.Render();
                }

            }
        }
Example #2
0
        public override void MouseDown(int x, int y, Keys modifierKeys)
        {
            // action is always multiselect, to indicate we're going to
            // keep adding or removing as we go to new places
            Handler.Action = ClipMouseAction.MultiSelect;

            // delete a note if an existing on is clicked on
            var foundNote = Handler.Renderer.GetNoteAt(x, y);
            if (foundNote != null)
            {
                isRemoving = true;
                Handler.Renderer.Clip.Notes.Remove(foundNote);
            }
            else
            {
                isRemoving = false;
                // add a note if clicking outside of a note
                var note = new SequencerClip.Note();
                note.Length = 24;
                note.Tick = MidiMath.Quantize(Handler.Renderer.GetTickAt(x), note.Length);
                note.Pitch = Handler.Renderer.GetNoteAt(y);
                note.Velocity = 100;
                Handler.Renderer.Clip.Notes.Add(note);
                Handler.Renderer.Clip.Sort();
            }

            Handler.Renderer.Render();
        }
Example #3
0
        /// <summary>
        /// Returns how far through a note the given coord is as a
        /// percentage.  Useful to detect if we've grabed the start
        /// or the end of a note.
        /// </summary>
        public float GetPercentageThroughNoteAt(SequencerClip.Note note, int x)
        {
            if (note == null)
            {
                return(0);
            }
            var startX = GetTickX(note.Tick);
            var endX   = GetTickX(note.Tick + note.Length);

            if (startX == endX)
            {
                return(0);
            }
            if (x < startX)
            {
                return(0);
            }
            if (x > endX)
            {
                return(1);
            }
            return((x - startX) / (endX - startX));
        }
Example #4
0
        public override void MouseDown(int x, int y, Keys modifierKeys)
        {
            // default action is none
            Handler.Action = ClipMouseAction.None;

            // save original mouse position
            Handler.MousePosition.SetStart(x, y);
            Handler.MousePosition.Set(x, y);

            // create a new note with control click.
            if (modifierKeys == Keys.Control)
            {
                var note = new SequencerClip.Note();
                note.Length = 24;
                note.Tick = MidiMath.Quantize(Handler.Renderer.GetTickAt(x), note.Length);
                note.Pitch = Handler.Renderer.GetNoteAt(y);
                note.Velocity = 100;
                Handler.Renderer.Clip.Notes.Add(note);
                Handler.Renderer.Clip.Sort();
                Handler.Renderer.Render();

                Handler.Renderer.SelectedNote = note;
                Handler.Renderer.SelectedNotes = null;

                Handler.Action = ClipMouseAction.Resize;
            }
            // select a single note if we click on a note
            else
            {
                // find the single note we clicked on
                Handler.Renderer.SelectedNote = Handler.Renderer.GetNoteAt(x, y);
                if (Handler.Renderer.SelectedNote == null)
                {
                    Handler.Renderer.SelectedNotes = null;
                }

                // if that note was part of an already selected group
                // then we need to move the entire group
                if (Handler.Renderer.SelectedNotes != null && Handler.Renderer.SelectedNotes.Contains(Handler.Renderer.SelectedNote))
                {
                    Handler.Action = ClipMouseAction.MovingGroup;
                }
                else if (Handler.Renderer.SelectedNote != null)
                {
                    // unselect group if not part of previous selected group
                    Handler.Renderer.SelectedNotes = null;

                    // decide action based on if we're at the start
                    // or the end of a note
                    var p = Handler.Renderer.GetPercentageThroughNoteAt(Handler.Renderer.SelectedNote, x);
                    if (p < 0.5f)
                    {
                        Handler.Action = ClipMouseAction.MovingSingle;
                    }
                    else
                    {
                        Handler.Action = ClipMouseAction.Resize;
                    }
                }
                else
                {
                    // multi select if we didn't click on anythin
                    Handler.Action = ClipMouseAction.MultiSelect;
                    Handler.Renderer.SelectBox.X = x;
                    Handler.Renderer.SelectBox.Y = y;
                    Handler.Renderer.SelectBox.Width = 1;
                    Handler.Renderer.SelectBox.Height = 1;
                    Handler.Renderer.ShowSelectBox = true;
                }
            }


            // save original values of selected notes
            if (Handler.Renderer.SelectedNotes != null)
            {
                Handler.UpdateOriginal(Handler.Renderer.SelectedNotes.ToArray());
            }
            else
            {
                Handler.UpdateOriginal(Handler.Renderer.SelectedNote);
            }

            // draw
            Handler.Renderer.Render();
        }