Add extra crosses & arrows as guides

This commit is contained in:
Starbeamrainbowlabs 2020-04-25 00:41:03 +01:00
parent fc3c92d334
commit f20ddb5a8e
Signed by: sbrl
GPG Key ID: 1BE5172E637709C2
4 changed files with 89 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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