Browse Source

Add box around notes

main
Starbeamrainbowlabs 4 years ago
parent
commit
5aa7c6a0c3
Signed by: sbrl GPG Key ID: 1BE5172E637709C2
  1. 13
      MusicBoxConverter/MusicBoxScoreGenerator.cs
  2. 12
      MusicBoxConverter/SvgWriter.cs
  3. 7
      MusicBoxConverter/Utilities/Vector2.cs

13
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<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;
}
}
}

12
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");

7
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
);
}
}
}

Loading…
Cancel
Save