Esempio n. 1
0
        private void PianoRoll_MouseUp(object sender, MouseEventArgs e)
        {
            mousePos = e.Location;

            if (e.Button == MouseButtons.Right)
            {
                uint channel = (uint)Clip.Channel.Number;
                Sequencer.PlayMidiEvent(new Midi.MidiMessage(channel, Midi.MidiMessage.Commands.NoteOff, tryingKey, 0), true);
                tryingKey = 128;
            }

            if (e.Button == MouseButtons.Left && paintedNote != null)
            {
                UpdatePaintedNote(e.X);
                Clip.NoteEvents.Add(paintedNote);
                selected.Clear();
                selected.Add(paintedNote);
                paintedNote = null;
                Refresh();
            }

            if (e.Button == MouseButtons.Left && moving)
            {
                int timeDelta = GetTimeMovement();
                int keyDelta = GetKeyMovement();
                List<Clip.NoteEvent> moved = new List<Clip.NoteEvent>();
                foreach (Clip.NoteEvent ne in selected)
                {
                    Clip.NoteEvent n = ne;
                    if (copying)
                    {
                        n = n.Clone();
                        Clip.NoteEvents.Add(n);
                    }
                    n.StartTime += timeDelta;
                    n.Note = (byte)(n.Note + keyDelta);
                    moved.Add(n);
                }
                selected.Clear();
                selected.AddRange(moved);
                moving = false;
                Refresh();
            }

            if (e.Button == MouseButtons.Left && selecting)
            {
                Rectangle selectRect = GetSelectRect();
                foreach (Clip.NoteEvent n in Clip.NoteEvents)
                {
                    if (NoteToRect(n).IntersectsWith(selectRect))
                    {
                        selected.Add(n);
                    }
                }
                selecting = false;
                Refresh();
            }
        }
Esempio n. 2
0
        private void PianoRoll_Paint(object sender, PaintEventArgs e)
        {
            Graphics g = e.Graphics;

            for (int i = 0; i < numKeys; i++)
            {
                int key = numKeys - i - 1;
                int y = i * keyHeight;
                bool blackKey = (key % 12 == 1 || key % 12 == 3 || key % 12 == 6 || key % 12 == 8 || key % 12 == 10);
                g.FillRectangle(blackKey ? Brushes.Silver : Brushes.LightGray, new Rectangle(0, y, Width, keyHeight - 1));
            }

            for (int x = 0; x < Width; x += pixelsPerTick)
            {
                g.DrawLine(Pens.White, new Point(x, 0), new Point(x, Height));

                if ((x / pixelsPerTick) % 4 == 0)
                {
                    g.DrawLine(Pens.White, new Point(x - 1, 0), new Point(x - 1, Height));
                }

                if ((x / pixelsPerTick) % 16 == 0)
                {
                    g.DrawLine(Pens.White, new Point(x + 1, 0), new Point(x + 1, Height));
                }
            }

            if (Clip != null)
            {
                foreach(Clip.NoteEvent note in Clip.NoteEvents)
                {
                    Rectangle r = NoteToRect(note);
                    g.FillRectangle(Brushes.RosyBrown, r);
                    g.DrawRectangle(Pens.Black, r);
                    if (selected.Contains(note))
                    {
                        r.Inflate(new Size(-1, -1));
                        g.DrawRectangle(Pens.Black, r);
                    }
                }

                if (moving)
                {
                    int timeDelta = GetTimeMovement();
                    int keyDelta = GetKeyMovement();
                    foreach (Clip.NoteEvent n in selected)
                    {
                        Clip.NoteEvent moved = new Clip.NoteEvent((byte)(n.Note + keyDelta), n.Velocity, n.StartTime + timeDelta, n.Length);
                        Rectangle r = NoteToRect(moved);
                        r.Inflate(new Size(-1, -1));
                        g.DrawRectangle(Pens.Black, r);
                    }
                }
            }

            if (paintedNote != null)
            {
                Rectangle r = NoteToRect(paintedNote);
                g.DrawRectangle(Pens.Black, r);
            }

            if (selecting)
            {
                g.DrawRectangle(Pens.DarkGray, GetSelectRect());
            }
        }
Esempio n. 3
0
        private void PianoRoll_MouseDown(object sender, MouseEventArgs e)
        {
            mousePos = e.Location;
            mouseDownPos = e.Location;

            if (e.Button == MouseButtons.Right)
            {
                tryingKey = ConvertYToKey(e.Y);
                uint channel = (uint)Clip.Channel.Number;
                Sequencer.PlayMidiEvent(new Midi.MidiMessage(channel, Midi.MidiMessage.Commands.NoteOn, tryingKey, 110), false);
            }

            if (e.Button == MouseButtons.Left)
            {
                selecting = shift;
            }

            if (e.Button == MouseButtons.Left && !selecting)
            {
                Clip.NoteEvent clickedNote = GetNoteAt(e.Location);
                if (clickedNote == null)
                {
                    byte key = ConvertYToKey(e.Y);
                    int time = ConvertXToTime(e.X);
                    paintedNote = new Clip.NoteEvent(key, 110, time, 1);
                    Refresh();
                }
                else
                {
                    if (!selected.Contains(clickedNote))
                    {
                        selected.Clear();
                        selected.Add(clickedNote);
                    }
                    moving = true;
                    Refresh();
                }
            }

            if (e.Button == MouseButtons.Left && selecting)
            {
                selected.Clear();
                Refresh();
            }
        }