Implement Editor.Delete and lyric editing in Piano Roll editor

This commit is contained in:
Michael Becker 2015-09-29 13:52:43 -04:00
parent 75e31fe3c7
commit af9db11478
6 changed files with 286 additions and 8 deletions

View File

@ -28,10 +28,33 @@
/// </summary>
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;
}
}

View File

@ -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<SynthesizedAudioCommand> cmdsToRemove = new List<SynthesizedAudioCommand>();
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;
}
}
}
}

View File

@ -0,0 +1,120 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
</root>

View File

@ -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)

View File

@ -164,6 +164,9 @@
</Compile>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Controls\Multimedia\Audio\Synthesized\PianoRoll\PianoRollControl.resx">
<DependentUpon>PianoRollControl.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Controls\Multimedia\Audio\Waveform\WaveformTrackList\WaveformTrackListControl.resx">
<DependentUpon>WaveformTrackListControl.cs</DependentUpon>
</EmbeddedResource>

View File

@ -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();