diff --git a/MusicBoxConverter/MusicBoxScoreGenerator.cs b/MusicBoxConverter/MusicBoxScoreGenerator.cs index ca7b084..a44a840 100644 --- a/MusicBoxConverter/MusicBoxScoreGenerator.cs +++ b/MusicBoxConverter/MusicBoxScoreGenerator.cs @@ -16,6 +16,14 @@ namespace MusicBoxConverter public int holeSize { get; set; } = 5; + private int trackLength; + public int TrackLength { + get { + if(trackLength == null) + trackLength = (int)AllNotes().Max((Note arg) => arg.Time); + return trackLength; + } + } MidiFile midiFile; @@ -27,7 +35,12 @@ namespace MusicBoxConverter public void Output(string destinationFilename) { SvgWriter svg = new SvgWriter(destinationFilename); - svg.WriteRectangle(offset, new Vector2(TrackLength(), 128).Multiply(scaleFactor)); + svg.WriteRectangle(offset, new Vector2(TrackLength, 128).Multiply(scaleFactor)); + for(int i = 0; i < 255; i += 5) + { + Vector2 start = offset.Add(new Vector2(0, i)); + svg.WriteLine(start, start.Add(new Vector2(TrackLength, 0))); + } foreach(Note note in AllNotes()) { @@ -44,11 +57,6 @@ 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()) diff --git a/MusicBoxConverter/SvgWriter.cs b/MusicBoxConverter/SvgWriter.cs index a30b2b0..5323fef 100644 --- a/MusicBoxConverter/SvgWriter.cs +++ b/MusicBoxConverter/SvgWriter.cs @@ -30,6 +30,11 @@ namespace MusicBoxConverter xml.Close(); } + public void WriteLine(Vector2 start, Vector2 end, string strokeStyle = "darkgreen", int strokeWidth = 3) + { + WritePath($"M {start.X} {start.Y} L {end.X} {end.Y}", strokeStyle, strokeWidth); + } + public void WritePath(string pathData, string strokeStyle = "green", int strokeWidth = 3) { xml.WriteStartElement("path");