Shift notes to fit inside playable area
This commit is contained in:
parent
0d48715361
commit
e5331328f1
2 changed files with 8 additions and 7 deletions
|
@ -13,7 +13,7 @@ namespace MusicBoxConverter
|
||||||
public Vector2 offset { get; set; } = new Vector2(10, 10);
|
public Vector2 offset { get; set; } = new Vector2(10, 10);
|
||||||
public Vector2 scaleFactor { get; set; } = new Vector2(0.1f, 4f);
|
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;
|
private int trackLength;
|
||||||
public int TrackLength
|
public int TrackLength
|
||||||
|
@ -44,7 +44,7 @@ namespace MusicBoxConverter
|
||||||
public MusicBoxScoreGenerator(string filename, MusicBox inMusicBox)
|
public MusicBoxScoreGenerator(string filename, MusicBox inMusicBox)
|
||||||
{
|
{
|
||||||
MusicBox = inMusicBox;
|
MusicBox = inMusicBox;
|
||||||
midiFile = MidiFile.Read("/home/sbrl/Music/Sheets/HappyBirthday.midi");
|
midiFile = MidiFile.Read(filename);
|
||||||
|
|
||||||
foreach(Note note in AllNotes()) {
|
foreach(Note note in AllNotes()) {
|
||||||
if (!MusicBox.IsValidNote(note))
|
if (!MusicBox.IsValidNote(note))
|
||||||
|
@ -55,13 +55,13 @@ namespace MusicBoxConverter
|
||||||
public void Output(string destinationFilename)
|
public void Output(string destinationFilename)
|
||||||
{
|
{
|
||||||
Vector2 area = new Vector2(TrackLength, MaxNoteNumber - MinNoteNumber).Multiply(scaleFactor);
|
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());
|
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));
|
Vector2 start = offset.Add(new Vector2(0, i));
|
||||||
svg.WriteLine(start, start.Add(new Vector2(TrackLength * scaleFactor.X, 0)));
|
svg.WriteLine(start, start.Add(new Vector2(TrackLength * scaleFactor.X, 0)), "darkgreen", 1);
|
||||||
}
|
}
|
||||||
svg.WriteRectangle(offset, area);
|
svg.WriteRectangle(offset, area);
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ namespace MusicBoxConverter
|
||||||
svg.WriteCircle(
|
svg.WriteCircle(
|
||||||
new Vector2(
|
new Vector2(
|
||||||
offset.X + note.Time * scaleFactor.X,
|
offset.X + note.Time * scaleFactor.X,
|
||||||
offset.Y + note.NoteNumber * scaleFactor.Y - MinNoteNumber
|
offset.Y + ((127 - note.NoteNumber) - (127 - MaxNoteNumber)) * scaleFactor.Y
|
||||||
),
|
),
|
||||||
holeSize // radius
|
holeSize // radius
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,6 +10,7 @@ namespace MusicBoxConverter
|
||||||
{
|
{
|
||||||
MusicBoxScoreGenerator converter = new MusicBoxScoreGenerator(
|
MusicBoxScoreGenerator converter = new MusicBoxScoreGenerator(
|
||||||
"/home/sbrl/Music/Sheets/HappyBirthday.midi",
|
"/home/sbrl/Music/Sheets/HappyBirthday.midi",
|
||||||
|
//"/tmp/Scale.midi",
|
||||||
MusicBox.Note30
|
MusicBox.Note30
|
||||||
);
|
);
|
||||||
converter.Output("/tmp/test.svg");
|
converter.Output("/tmp/test.svg");
|
||||||
|
|
Loading…
Reference in a new issue