Add box around notes

This commit is contained in:
Starbeamrainbowlabs 2017-11-30 23:15:52 +00:00
parent 8cdb9591ab
commit 5aa7c6a0c3
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
3 changed files with 25 additions and 7 deletions

View File

@ -27,7 +27,7 @@ namespace MusicBoxConverter
public void Output(string destinationFilename)
{
SvgWriter svg = new SvgWriter(destinationFilename);
svg.WriteRectangle(offset, new Vector2(TrackLength(), 128).Multiply(scaleFactor));
foreach(Note note in AllNotes())
{
@ -44,6 +44,11 @@ namespace MusicBoxConverter
svg.Complete();
}
public int TrackLength()
{
return (int)AllNotes().Max((Note arg) => arg.Time);
}
public IEnumerable<Note> AllNotes()
{
foreach(TrackChunk chunk in midiFile.Chunks.OfType<TrackChunk>())
@ -55,11 +60,5 @@ namespace MusicBoxConverter
}
}
}
public int TrackLength()
{
//notesManager.Notes.OfType<TrackChunk>().Select((TrackChunk arg) => arg.Events.O;
return 1;
}
}
}

View File

@ -39,6 +39,18 @@ namespace MusicBoxConverter
xml.WriteEndElement();
}
public void WriteRectangle(Vector2 position, Vector2 size, string strokeStyle = "red", int strokeWidth = 3)
{
xml.WriteStartElement("rect");
xml.WriteAttributeString("x", position.X.ToString());
xml.WriteAttributeString("y", position.Y.ToString());
xml.WriteAttributeString("width", size.X.ToString());
xml.WriteAttributeString("height", size.Y.ToString());
xml.WriteAttributeString("fill", "transparent");
xml.WriteAttributeString("stroke", strokeStyle);
xml.WriteAttributeString("stroke-width", strokeWidth.ToString());
xml.WriteEndElement();
}
public void WriteCircle(Vector2 centre, int radius, string fillStyle = "blue")
{
xml.WriteStartElement("circle");

View File

@ -63,6 +63,13 @@ namespace SBRL.Utilities
Y * b
);
}
public Vector2 Multiply(Vector2 b)
{
return new Vector2(
X * b.X,
Y * b.Y
);
}
}
}