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

This commit is contained in:
Starbeamrainbowlabs 2017-12-03 17:48:15 +00:00
parent fb3fc45a09
commit 564b649204
Signed by: sbrl
GPG key ID: 1BE5172E637709C2
4 changed files with 10 additions and 10 deletions

View file

@ -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 {

View file

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

View file

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

View file

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