private Track.Command DrawNotes(Graphics g, List <ChannelCommand> commands, Rectangle visibleAreaRectangle, Dictionary <Track.Command, CommandLineInfo> visibleNoteList, int loopStartTime = 0, int loopTotalDuration = 0, int loopStartDuration = 0, Track.Command lastNote = 0, bool isLoop = false) { if (commands == null || commands.Count == 0) { return(lastNote); } Brush unselectedBrush = new SolidBrush(Color.FromArgb(190, 76, 233)); Brush selectedBrush = new SolidBrush(Color.FromArgb(255, 192, 0)); if (isLoop) { unselectedBrush = Brushes.Silver; } var outlineBrush = Brushes.Black; int startDuration = loopStartDuration; int lastDuration = 0; int width = canvasWidth; int horizontalOffset = visibleAreaRectangle.X; foreach (var c in commands) { var cmd = (Track.Command)c.Command; if (c is DurationCommand) { lastDuration = c.Command; startDuration = -1; } if (c is CallLoopCommand) { var loop = c as CallLoopCommand; if (loop != null) { for (int i = 0; i < loop.LoopCount; ++i) { lastNote = DrawNotes(g, loop.LoopPart.Commands, visibleAreaRectangle, visibleNoteList, c.StartTime + (c.Duration * i), c.Duration, lastDuration, lastNote, true); } } } if (c is NoteCommand) { var noteCommand = c as NoteCommand; var duration = noteCommand.Duration; if (duration == 0) { if (loopStartDuration > -1) { duration = loopStartDuration; } else { Debugger.Break(); // shouldn't hit this. } } var noteWidth = (int)(duration * pixelsPerDuration); int x = (int)((noteCommand.StartTime + loopStartTime) * pixelsPerDuration); if (cmd == Track.Command._C8_Tie) { if (visibleNoteList.ContainsKey(lastNote)) { var info = visibleNoteList[lastNote]; var mag = new SolidBrush(Color.FromArgb(200, 255, 0, 255)); int startX = x - horizontalOffset; int offsetX = x - horizontalOffset + noteWidth; if ((startX >= 0 && startX <= this.Width) || (offsetX >= 0 && offsetX <= this.Width)) { int thickness = 4; if (thickness > info.LineArea.Height) { thickness = info.LineArea.Height; } int y = info.LineArea.Top + info.LineArea.Height / 2 - thickness / 2; var noteRectangle = new Rectangle(startX, y, noteWidth, thickness); var brush = unselectedBrush; if (selectedNotes.Contains(c)) { brush = selectedBrush; } g.FillRectangle(brush, noteRectangle); int endX = noteRectangle.Right - 2; if (endX < noteRectangle.Left) { endX = noteRectangle.Left; } g.FillRectangle(brush, endX, info.LineArea.Y, 2, info.LineArea.Height); } } } else if (cmd == Track.Command._C9_Rest) { var mag = new SolidBrush(Color.FromArgb(40, 255, 0, 255)); g.FillRectangle(mag, x - horizontalOffset, 0, noteWidth, this.Height); } else { lastNote = noteCommand.CommandType; if (visibleNoteList.ContainsKey(cmd)) { var info = visibleNoteList[cmd]; int startX = x - horizontalOffset; int offsetX = x - horizontalOffset + noteWidth; if ((startX >= 0 && startX <= this.Width) || (offsetX >= 0 && offsetX <= this.Width)) { //g.DrawLine(Pens.Black, x - horizontalOffset, 0, x - horizontalOffset, this.Height); var noteRectangle = new Rectangle(startX, info.LineArea.Top, noteWidth, info.LineArea.Height); var brush = unselectedBrush; if (selectedNotes.Contains(c)) { brush = selectedBrush; } g.FillRectangle(brush, noteRectangle); g.DrawRectangle(Pens.Black, noteRectangle); g.SetClip(noteRectangle); var noteText = noteCommand.CommandType.GetDescription(); g.DrawString(noteText, this.Font, Brushes.Black, noteRectangle.X + 1, noteRectangle.Y + noteRectangle.Height / 2 - g.MeasureString(noteText, this.Font).Height / 2); g.ResetClip(); } } } } } if (isLoop) { int loopStartX = (int)(loopStartTime * pixelsPerDuration); int loopEndX = loopStartX + (int)(loopTotalDuration * pixelsPerDuration); int startX = loopStartX - horizontalOffset; int offsetX = loopEndX - horizontalOffset; if ((startX >= 0 && startX <= this.Width) || (offsetX >= 0 && offsetX <= this.Width)) { var loopRectangle = new Rectangle(startX, 0, loopEndX - loopStartX, this.Height); g.FillRectangle(new SolidBrush(Color.FromArgb(40, 0, 0, 0)), loopRectangle); g.DrawRectangle(Pens.Magenta, loopRectangle); } } else { // draw a nice big line at the end until I fix the canvas size and zoom var endPen = new Pen(Color.DarkGreen); endPen.Width = 4; var x = Channel.EndTime * pixelsPerDuration - horizontalOffset + endPen.Width / 2; g.DrawLine(endPen, x, 0, x, this.Height); } return(lastNote); }
protected override void OnKeyDown(KeyEventArgs e) { Track.Command minNote = Track.Command._C7_B6; Track.Command maxNote = Track.Command._80_C1; bool changed = false; foreach (var c in selectedNotes) { if (c.Command < (int)minNote) { minNote = c.CommandType; } if (c.Command > (int)maxNote) { maxNote = c.CommandType; } } if (e.KeyCode == Keys.Up) { byte increase = 1; if (e.Shift) { // 1 octave increase = Track.Command._8C_C2 - Track.Command._80_C1; } if (maxNote + increase <= Track.Command._C7_B6) { foreach (var c in selectedNotes) { if (c.CommandType == Track.Command._C7_B6) { } else { c.Command += increase; changed = true; } } } } if (e.KeyCode == Keys.Down) { byte decrease = 1; if (e.Shift) { // 1 octave decrease = Track.Command._8C_C2 - Track.Command._80_C1; } if (minNote - decrease >= Track.Command._80_C1) { foreach (var c in selectedNotes) { if (c.CommandType == Track.Command._80_C1) { } else { c.Command -= decrease; changed = true; } } } } if (e.KeyCode == Keys.OemOpenBrackets) { foreach (var c in selectedNotes) { // make it shorter // this is going to require some real fuckery } } if (e.KeyCode == Keys.OemCloseBrackets) { foreach (var c in selectedNotes) { // make it longer } } if (e.KeyCode == Keys.D && e.Control) { // duplicate } if (e.KeyCode == Keys.C && e.Control) { // copy } if (e.KeyCode == Keys.X && e.Control) { // cut } if (e.KeyCode == Keys.V && e.Control) { // paste } base.OnKeyDown(e); if (changed) { Invalidate(); } }
public async Task <ActionResult <Unit> > Track(Track.Command command) { return(await Mediator.Send(command)); }