From 5aa7c6a0c3c2c783067a96c641f694b5a2f5d2cd Mon Sep 17 00:00:00 2001 From: Starbeamrainbowlabs Date: Thu, 30 Nov 2017 23:15:52 +0000 Subject: [PATCH] Add box around notes --- MusicBoxConverter/MusicBoxScoreGenerator.cs | 13 ++++++------- MusicBoxConverter/SvgWriter.cs | 12 ++++++++++++ MusicBoxConverter/Utilities/Vector2.cs | 7 +++++++ 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/MusicBoxConverter/MusicBoxScoreGenerator.cs b/MusicBoxConverter/MusicBoxScoreGenerator.cs index 276d5e1..ca7b084 100644 --- a/MusicBoxConverter/MusicBoxScoreGenerator.cs +++ b/MusicBoxConverter/MusicBoxScoreGenerator.cs @@ -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 AllNotes() { foreach(TrackChunk chunk in midiFile.Chunks.OfType()) @@ -55,11 +60,5 @@ namespace MusicBoxConverter } } } - - public int TrackLength() - { - //notesManager.Notes.OfType().Select((TrackChunk arg) => arg.Events.O; - return 1; - } } } diff --git a/MusicBoxConverter/SvgWriter.cs b/MusicBoxConverter/SvgWriter.cs index a7caf00..a30b2b0 100644 --- a/MusicBoxConverter/SvgWriter.cs +++ b/MusicBoxConverter/SvgWriter.cs @@ -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"); diff --git a/MusicBoxConverter/Utilities/Vector2.cs b/MusicBoxConverter/Utilities/Vector2.cs index 4ccec14..7dfcd01 100644 --- a/MusicBoxConverter/Utilities/Vector2.cs +++ b/MusicBoxConverter/Utilities/Vector2.cs @@ -63,6 +63,13 @@ namespace SBRL.Utilities Y * b ); } + public Vector2 Multiply(Vector2 b) + { + return new Vector2( + X * b.X, + Y * b.Y + ); + } } }