Browse Source

Shift notes to fit inside playable area

main
Starbeamrainbowlabs 4 years ago
parent
commit
e5331328f1
Signed by: sbrl GPG Key ID: 1BE5172E637709C2
  1. 14
      MusicBoxConverter/MusicBoxScoreGenerator.cs
  2. 1
      MusicBoxConverter/Program.cs

14
MusicBoxConverter/MusicBoxScoreGenerator.cs

@ -13,7 +13,7 @@ namespace MusicBoxConverter
public Vector2 offset { get; set; } = new Vector2(10, 10);
public Vector2 scaleFactor { get; set; } = new Vector2(0.1f, 4f);
public int holeSize { get; set; } = 5;
public int holeSize { get; set; } = 3;
private int trackLength;
public int TrackLength
@ -44,7 +44,7 @@ namespace MusicBoxConverter
public MusicBoxScoreGenerator(string filename, MusicBox inMusicBox)
{
MusicBox = inMusicBox;
midiFile = MidiFile.Read("/home/sbrl/Music/Sheets/HappyBirthday.midi");
midiFile = MidiFile.Read(filename);
foreach(Note note in AllNotes()) {
if (!MusicBox.IsValidNote(note))
@ -55,13 +55,13 @@ namespace MusicBoxConverter
public void Output(string destinationFilename)
{
Vector2 area = new Vector2(TrackLength, MaxNoteNumber - MinNoteNumber).Multiply(scaleFactor);
Vector2 size = area.Add(offset.Multiply(2));
Vector2 size = area.Add(offset.Multiply(2)).Add(new Vector2(100000, 1000));
SvgWriter svg = new SvgWriter(destinationFilename, size.X.ToString(), size.Y.ToString());
for(int i = 0; i < area.Y; i += 5)
for(float i = 0; i < area.Y; i += scaleFactor.Y)
{
Vector2 start = offset.Add(new Vector2(0, i * scaleFactor.Y));
svg.WriteLine(start, start.Add(new Vector2(TrackLength * scaleFactor.X, 0)));
Vector2 start = offset.Add(new Vector2(0, i));
svg.WriteLine(start, start.Add(new Vector2(TrackLength * scaleFactor.X, 0)), "darkgreen", 1);
}
svg.WriteRectangle(offset, area);
@ -71,7 +71,7 @@ namespace MusicBoxConverter
svg.WriteCircle(
new Vector2(
offset.X + note.Time * scaleFactor.X,
offset.Y + note.NoteNumber * scaleFactor.Y - MinNoteNumber
offset.Y + ((127 - note.NoteNumber) - (127 - MaxNoteNumber)) * scaleFactor.Y
),
holeSize // radius
);

1
MusicBoxConverter/Program.cs

@ -10,6 +10,7 @@ namespace MusicBoxConverter
{
MusicBoxScoreGenerator converter = new MusicBoxScoreGenerator(
"/home/sbrl/Music/Sheets/HappyBirthday.midi",
//"/tmp/Scale.midi",
MusicBox.Note30
);
converter.Output("/tmp/test.svg");

Loading…
Cancel
Save