Browse Source

Add extra crosses & arrows as guides

main
Starbeamrainbowlabs 2 years ago
parent
commit
f20ddb5a8e
Signed by: sbrl GPG Key ID: 1BE5172E637709C2
  1. 41
      MusicBoxConverter/MusicBoxScoreGenerator.cs
  2. 34
      MusicBoxConverter/SvgWriter.cs
  3. 4
      MusicBoxConverter/Utilities/Vector2.cs
  4. 14
      README.md

41
MusicBoxConverter/MusicBoxScoreGenerator.cs

@ -17,6 +17,11 @@ namespace MusicBoxConverter
public float HoleSize { get; set; } = 1f;
public Vector2 ArrowSize { get; set; } = new Vector2(25, 25);
public float ArrowSpacing { get; set; } = 50f;
public float ArrowStrokeWidth { get; set; } = 8;
public string ArrowColour { get; set; } = "#dacef3";
private int trackLength;
public int TrackLength
{
@ -73,6 +78,26 @@ namespace MusicBoxConverter
UnitSuffix = "mm"
};
// Draw directional arrows down the score
for (float i = 0; i < area.X; i += ArrowSpacing)
{
Vector2 arrowPos = new Vector2(i, area.Y / 2 + Offset.Y);
svg.WriteLine(
arrowPos.Subtract(ArrowSize),
arrowPos,
ArrowColour,
ArrowStrokeWidth
);
svg.WriteLine(
arrowPos,
arrowPos.Subtract(new Vector2(ArrowSize.X, -ArrowSize.Y)),
ArrowColour,
ArrowStrokeWidth
);
}
// Draw a marker at the beginning of the score
svg.WriteRectangle(
new Vector2(Offset.X / 2, Offset.Y),
@ -115,13 +140,21 @@ namespace MusicBoxConverter
);
}
Vector2 holePosition = new Vector2(
Offset.X + note.Time * ScaleFactor.X,
Offset.Y + ((SelectedMusicBox.NoteCount - 1) - SelectedMusicBox.NoteToBoxNumber(note)) * ScaleFactor.Y
);
svg.WriteCircle(
new Vector2(
Offset.X + note.Time * ScaleFactor.X,
Offset.Y + ((SelectedMusicBox.NoteCount-1) - SelectedMusicBox.NoteToBoxNumber(note)) * ScaleFactor.Y
),
holePosition,
HoleSize // radius
);
svg.WriteCross(
holePosition,
new Vector2(HoleSize, HoleSize)
);
}
svg.Complete();

34
MusicBoxConverter/SvgWriter.cs

@ -69,6 +69,40 @@ namespace MusicBoxConverter
xml.WriteEndElement();
}
public void WritePolyLine(string strokeStyle, float strokeWidth, params Vector2[] points)
{
xml.WriteStartElement("polyline");
xml.WriteAttributeString("points", string.Join(" ", points.Select((Vector2 p) => $"{p.X},{p.Y}")));
xml.WriteAttributeString("stroke", strokeStyle);
xml.WriteAttributeString("stroke-width", strokeWidth.ToString());
xml.WriteAttributeString("fill", "none");
xml.WriteEndElement();
}
/// <summary>
/// Adds a cross centred on a point.
/// </summary>
/// <param name="centre">The centre of the cross.</param>
/// <param name="radius">The radius of the cross.</param>
/// <param name="strokeStyle">The stroke style to draw with.</param>
/// <param name="strokeWidth">The stroke width to draw with.</param>
public void WriteCross(Vector2 centre, Vector2 radius, string strokeStyle = "red", float strokeWidth = 1)
{
WriteLine(
centre.Subtract(new Vector2(radius.X, radius.Y)),
centre.Add(new Vector2(radius.X, radius.Y)),
strokeStyle,
strokeWidth
);
WriteLine(
centre.Subtract(new Vector2(radius.X, -radius.Y)),
centre.Add(new Vector2(radius.X, -radius.Y)),
strokeStyle,
strokeWidth
);
}
public void StartScaleTransform(float scale)
{
xml.WriteStartElement("g");

4
MusicBoxConverter/Utilities/Vector2.cs

@ -77,6 +77,10 @@ namespace SBRL.Utilities
Y * b.Y
);
}
public override string ToString() {
return $"[Vector2 {X}, {Y}]";
}
}
}

14
README.md

@ -2,6 +2,20 @@
> Converts MIDI files into music box scores that are ready to print.
## Getting Started
This program is written in C&sharp;. To get started, first clone this repository and compile it:
```bash
git clone https://git.starbeamrainbowlabs.com/sbrl/MusicBoxConverter.git
cd MusicBoxConverter
msbuild
```
If you're on Windows, you'll either need to use a _Visual Studio Developer Command Prompt_ or open the solution file in _Visual Studio_ itself.
Alternatively, you can
## Usage
1. Export the MuseScore file to a MIDI file
2. Run the MIDI file through this program.

Loading…
Cancel
Save