From af9db114781621ce9b7f43cb4223fa43e83f8828 Mon Sep 17 00:00:00 2001 From: alcexhim Date: Tue, 29 Sep 2015 13:52:43 -0400 Subject: [PATCH] Implement Editor.Delete and lyric editing in Piano Roll editor --- .../PianoRoll/PianoRollControl.Designer.cs | 27 +++- .../Synthesized/PianoRoll/PianoRollControl.cs | 108 +++++++++++++++- .../PianoRoll/PianoRollControl.resx | 120 ++++++++++++++++++ .../Synthesized/SynthesizedAudioEditor.cs | 9 ++ ...ltimedia.UserInterface.WindowsForms.csproj | 3 + .../Synthesized/SynthesizedAudioCommand.cs | 27 ++++ 6 files changed, 286 insertions(+), 8 deletions(-) create mode 100644 CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Controls/Multimedia/Audio/Synthesized/PianoRoll/PianoRollControl.resx diff --git a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Controls/Multimedia/Audio/Synthesized/PianoRoll/PianoRollControl.Designer.cs b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Controls/Multimedia/Audio/Synthesized/PianoRoll/PianoRollControl.Designer.cs index 82423f51..89e6b769 100644 --- a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Controls/Multimedia/Audio/Synthesized/PianoRoll/PianoRollControl.Designer.cs +++ b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Controls/Multimedia/Audio/Synthesized/PianoRoll/PianoRollControl.Designer.cs @@ -28,10 +28,33 @@ /// private void InitializeComponent() { - components = new System.ComponentModel.Container(); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.txtLyric = new System.Windows.Forms.TextBox(); + this.SuspendLayout(); + // + // txtLyric + // + this.txtLyric.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.txtLyric.Enabled = false; + this.txtLyric.Location = new System.Drawing.Point(16, 45); + this.txtLyric.Name = "txtLyric"; + this.txtLyric.Size = new System.Drawing.Size(71, 20); + this.txtLyric.TabIndex = 0; + this.txtLyric.Visible = false; + this.txtLyric.KeyDown += new System.Windows.Forms.KeyEventHandler(this.txtLyric_KeyDown); + // + // PianoRollControl + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.Controls.Add(this.txtLyric); + this.Name = "PianoRollControl"; + this.ResumeLayout(false); + this.PerformLayout(); + } #endregion + + private System.Windows.Forms.TextBox txtLyric; } } diff --git a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Controls/Multimedia/Audio/Synthesized/PianoRoll/PianoRollControl.cs b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Controls/Multimedia/Audio/Synthesized/PianoRoll/PianoRollControl.cs index 0222b448..676c1c03 100644 --- a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Controls/Multimedia/Audio/Synthesized/PianoRoll/PianoRollControl.cs +++ b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Controls/Multimedia/Audio/Synthesized/PianoRoll/PianoRollControl.cs @@ -17,8 +17,24 @@ namespace UniversalEditor.Controls.Multimedia.Audio.Synthesized.PianoRoll { InitializeComponent(); DoubleBuffered = true; + + mvarCommands.ItemsChanged += mvarCommands_ItemsChanged; } + private void mvarCommands_ItemsChanged(object sender, EventArgs e) + { + List cmdsToRemove = new List(); + foreach (SynthesizedAudioCommand cmd in mvarSelectedCommands) + { + if (!mvarCommands.Contains(cmd)) cmdsToRemove.Add(cmd); + } + foreach (SynthesizedAudioCommand cmd in cmdsToRemove) + { + mvarSelectedCommands.Remove(cmd); + } + Invalidate(); + } + private SynthesizedAudioCommand.SynthesizedAudioCommandCollection mvarCommands = new SynthesizedAudioCommand.SynthesizedAudioCommandCollection(); public SynthesizedAudioCommand.SynthesizedAudioCommandCollection Commands { get { return mvarCommands; } } @@ -55,17 +71,39 @@ namespace UniversalEditor.Controls.Multimedia.Audio.Synthesized.PianoRoll } SynthesizedAudioCommand cmd = HitTest(e.Location); + if (Control.ModifierKeys == Keys.None) + { + mvarSelectedCommands.Clear(); + } if (cmd != null) { - if (Control.ModifierKeys == Keys.None) - { - mvarSelectedCommands.Clear(); - } - else if (Control.ModifierKeys == Keys.Shift) + bool remove = false; + if (Control.ModifierKeys == Keys.Shift) { + if (mvarSelectedCommands.Count > 0) + { + int startIndex = mvarCommands.IndexOf(mvarSelectedCommands[mvarSelectedCommands.Count - 1]); + int endIndex = mvarCommands.IndexOf(cmd); + mvarSelectedCommands.Clear(); + for (int i = startIndex; i < endIndex; i++) + { + mvarSelectedCommands.Add(mvarCommands[i]); + } + } + } + else if (Control.ModifierKeys == Keys.Control) + { + remove = mvarSelectedCommands.Contains(cmd); + } + if (remove) + { + mvarSelectedCommands.Remove(cmd); + } + else + { + mvarSelectedCommands.Add(cmd); } - mvarSelectedCommands.Add(cmd); } if (e.Button == System.Windows.Forms.MouseButtons.Left) @@ -74,6 +112,9 @@ namespace UniversalEditor.Controls.Multimedia.Audio.Synthesized.PianoRoll drag_CurrentLocation = drag_OriginalLocation; drag_Dragging = true; } + + txtLyric.Visible = false; + txtLyric.Enabled = false; } protected override void OnMouseMove(MouseEventArgs e) @@ -121,6 +162,28 @@ namespace UniversalEditor.Controls.Multimedia.Audio.Synthesized.PianoRoll Invalidate(); } + protected override void OnMouseDoubleClick(MouseEventArgs e) + { + base.OnMouseDoubleClick(e); + if (e.Button == System.Windows.Forms.MouseButtons.Left) + { + SynthesizedAudioCommand cmd = HitTest(e.Location); + if (cmd is SynthesizedAudioCommandNote) + { + SynthesizedAudioCommandNote note = (cmd as SynthesizedAudioCommandNote); + Rectangle rect = GetNoteRect(note); + txtLyric.Location = rect.Location; + txtLyric.Size = rect.Size; + txtLyric.Text = note.Lyric; + + txtLyric.Enabled = true; + txtLyric.Visible = true; + + txtLyric.Focus(); + } + } + } + private Point Quantize(Point pt) { int qX = (int)((double)(pt.X / mvarQuarterNoteWidth)); @@ -177,6 +240,19 @@ namespace UniversalEditor.Controls.Multimedia.Audio.Synthesized.PianoRoll gridPen.Color = Colors.LightGray.ToGdiColor(); e.Graphics.DrawLine(gridPen, gridRect.Left, gridRect.Top + i, gridRect.Right, gridRect.Top + i); + string[] noteNames = new string[] + { + "A#", "A", "G#", "G", "F#", "F", "E", "D#", "D", "C#", "C", "B" + }; + if ((noteValue - 1) >= 0 && (noteValue - 1) < noteNames.Length) + { + string noteName = noteNames[noteValue - 1]; + if (noteName.EndsWith("#")) continue; + if (!noteName.Equals("C")) continue; + + e.Graphics.DrawString(noteName, Font, new SolidBrush(noteName.Equals("C") ? Colors.DarkGray.ToGdiColor() : Colors.LightGray.ToGdiColor()), new Point(mvarKeyboardWidth - 24, i + 1)); + } + // e.Graphics.DrawString(noteValue.ToString(), Font, new SolidBrush(Colors.Red.ToGdiColor()), new Point(0, i)); } for (int i = 0; i < this.Width; i += gridWidth) @@ -219,6 +295,10 @@ namespace UniversalEditor.Controls.Multimedia.Audio.Synthesized.PianoRoll { e.Graphics.FillRectangle(new SolidBrush(Color.FromRGBA(0xCC, 0xFF, 0xCC).ToGdiColor()), rect); } + e.Graphics.DrawRectangle(new Pen(Colors.DarkGray.ToGdiColor()), rect); + + Rectangle textRect = new Rectangle(rect.X + 2, rect.Y + 1, rect.Width - 4, rect.Height - 2); + e.Graphics.DrawString(note.Lyric, Font, new SolidBrush(Colors.Black.ToGdiColor()), textRect); } } } @@ -268,5 +348,21 @@ namespace UniversalEditor.Controls.Multimedia.Audio.Synthesized.PianoRoll Point pt2 = Unquantize(new Point((int)note.Length, FrequencyToValue(note.Frequency))); return new Rectangle(gridRect.X + pt1.X + 1, gridRect.Y + pt1.Y + 1, pt2.X - 1, mvarNoteHeight - 1); } + + private void txtLyric_KeyDown(object sender, KeyEventArgs e) + { + if (e.KeyCode == Keys.Enter) + { + foreach (SynthesizedAudioCommand cmd in mvarSelectedCommands) + { + if (cmd is SynthesizedAudioCommandNote) + { + (cmd as SynthesizedAudioCommandNote).Lyric = txtLyric.Text; + } + } + txtLyric.Visible = false; + txtLyric.Enabled = false; + } + } } } diff --git a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Controls/Multimedia/Audio/Synthesized/PianoRoll/PianoRollControl.resx b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Controls/Multimedia/Audio/Synthesized/PianoRoll/PianoRollControl.resx new file mode 100644 index 00000000..1af7de15 --- /dev/null +++ b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Controls/Multimedia/Audio/Synthesized/PianoRoll/PianoRollControl.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Editors/Multimedia/Audio/Synthesized/SynthesizedAudioEditor.cs b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Editors/Multimedia/Audio/Synthesized/SynthesizedAudioEditor.cs index 4bf36af5..ad35ad6a 100644 --- a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Editors/Multimedia/Audio/Synthesized/SynthesizedAudioEditor.cs +++ b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/Editors/Multimedia/Audio/Synthesized/SynthesizedAudioEditor.cs @@ -119,6 +119,15 @@ namespace UniversalEditor.Editors.Multimedia.Audio.Synthesized } #endregion #endregion + #region Editor Commands + public override void Delete() + { + while (pnlPianoRoll.SelectedCommands.Count > 0) + { + pnlPianoRoll.Commands.Remove(pnlPianoRoll.SelectedCommands[0]); + } + } + #endregion #endregion protected override void OnObjectModelChanged(EventArgs e) diff --git a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms.csproj b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms.csproj index 0ad17e54..d8f9365c 100644 --- a/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms.csproj +++ b/CSharp/Engines/WindowsForms/Plugins/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms/UniversalEditor.Plugins.Multimedia.UserInterface.WindowsForms.csproj @@ -164,6 +164,9 @@ + + PianoRollControl.cs + WaveformTrackListControl.cs diff --git a/CSharp/Plugins/UniversalEditor.Plugins.Multimedia/ObjectModels/Multimedia/Audio/Synthesized/SynthesizedAudioCommand.cs b/CSharp/Plugins/UniversalEditor.Plugins.Multimedia/ObjectModels/Multimedia/Audio/Synthesized/SynthesizedAudioCommand.cs index b5333e42..0bea52b8 100644 --- a/CSharp/Plugins/UniversalEditor.Plugins.Multimedia/ObjectModels/Multimedia/Audio/Synthesized/SynthesizedAudioCommand.cs +++ b/CSharp/Plugins/UniversalEditor.Plugins.Multimedia/ObjectModels/Multimedia/Audio/Synthesized/SynthesizedAudioCommand.cs @@ -24,8 +24,35 @@ namespace UniversalEditor.ObjectModels.Multimedia.Audio.Synthesized return command; } + public event EventHandler ItemsChanged; + protected virtual void OnItemsChanged(EventArgs e) + { + if (ItemsChanged != null) ItemsChanged(this, e); + } + protected override void InsertItem(int index, SynthesizedAudioCommand item) + { + base.InsertItem(index, item); + OnItemsChanged(EventArgs.Empty); + } + + protected override void RemoveItem(int index) + { + base.RemoveItem(index); + OnItemsChanged(EventArgs.Empty); + } + protected override void ClearItems() + { + base.ClearItems(); + OnItemsChanged(EventArgs.Empty); + } + protected override void SetItem(int index, SynthesizedAudioCommand item) + { + base.SetItem(index, item); + OnItemsChanged(EventArgs.Empty); + } } + public virtual object Clone() { return base.MemberwiseClone();