Browse Source

The 2 most annoying bugs are segfaults, infinite loops, and *off-by-one* errors.

main
Starbeamrainbowlabs 4 years ago
parent
commit
564b649204
Signed by: sbrl GPG Key ID: 1BE5172E637709C2
  1. 2
      MusicBoxConverter/MusicBox.cs
  2. 10
      MusicBoxConverter/MusicBoxScoreGenerator.cs
  3. 4
      MusicBoxConverter/Program.cs
  4. 4
      MusicBoxConverter/SvgWriter.cs

2
MusicBoxConverter/MusicBox.cs

@ -11,7 +11,7 @@ namespace MusicBoxConverter
/// <summary>
/// The height of a strip for this music box, in millimetres.
/// </summary>
public float StripHeightMm = 58f;
public float StripHeightMm = 58.8f;
public List<string> ValidNotes { get; private set; }
public Note LowestNote {

10
MusicBoxConverter/MusicBoxScoreGenerator.cs

@ -49,7 +49,7 @@ namespace MusicBoxConverter
// Set the scale factor based on the strip height of the music box
scaleFactor = new Vector2(
scaleFactor.X,
MusicBox.StripHeightMm / MusicBox.NoteCount
MusicBox.StripHeightMm / (MusicBox.NoteCount-1)
);
foreach(Note note in AllNotes()) {
@ -60,7 +60,7 @@ namespace MusicBoxConverter
public void Output(string destinationFilename)
{
Vector2 area = new Vector2(TrackLength, MusicBox.NoteCount).Multiply(scaleFactor);
Vector2 area = new Vector2(TrackLength, MusicBox.NoteCount-1).Multiply(scaleFactor);
Vector2 size = area.Add(offset.Multiply(2));
SvgWriter svg = new SvgWriter(
@ -72,10 +72,10 @@ namespace MusicBoxConverter
for(float i = 0; i < area.Y; i += scaleFactor.Y)
{
Vector2 start = offset.Add(new Vector2(0, i));
svg.WriteLine(start, start.Add(new Vector2(area.X, 0)), "darkgreen", 1);
svg.WriteLine(start, start.Add(new Vector2(area.X, 0)), "darkgreen", 0.75f);
}
svg.WriteRectangle(offset, area);
svg.WriteRectangle(offset, area, "red", 0.75f);
foreach(Note note in AllNotes())
{
@ -83,7 +83,7 @@ namespace MusicBoxConverter
svg.WriteCircle(
new Vector2(
offset.X + note.Time * scaleFactor.X,
offset.Y + (MusicBox.NoteCount - MusicBox.NoteToBoxNumber(note)) * scaleFactor.Y
offset.Y + ((MusicBox.NoteCount-1) - MusicBox.NoteToBoxNumber(note)) * scaleFactor.Y
),
holeSize // radius
);

4
MusicBoxConverter/Program.cs

@ -9,8 +9,8 @@ namespace MusicBoxConverter
public static void Main(string[] args)
{
MusicBoxScoreGenerator converter = new MusicBoxScoreGenerator(
"/home/sbrl/Music/Sheets/HappyBirthday.midi",
//"/tmp/Scale.midi",
//"/home/sbrl/Music/Sheets/HappyBirthday.midi",
"/tmp/Scale.midi",
MusicBox.Note30
);
converter.Output("/tmp/test.svg");

4
MusicBoxConverter/SvgWriter.cs

@ -53,7 +53,7 @@ namespace MusicBoxConverter
xml.Close();
}
public void WriteLine(Vector2 start, Vector2 end, string strokeStyle = "darkgreen", int strokeWidth = 3)
public void WriteLine(Vector2 start, Vector2 end, string strokeStyle = "darkgreen", float strokeWidth = 3)
{
xml.WriteStartElement("line");
xml.WriteAttributeString("x1", $"{start.X}{UnitSuffix}");
@ -85,7 +85,7 @@ namespace MusicBoxConverter
xml.WriteEndElement();
}*/
public void WriteRectangle(Vector2 position, Vector2 size, string strokeStyle = "red", int strokeWidth = 3)
public void WriteRectangle(Vector2 position, Vector2 size, string strokeStyle = "red", float strokeWidth = 3)
{
xml.WriteStartElement("rect");
xml.WriteAttributeString("x", $"{position.X}{UnitSuffix}");

Loading…
Cancel
Save