Refactor to make it nicer
This commit is contained in:
parent
50a9527597
commit
8cdb9591ab
3 changed files with 43 additions and 22 deletions
|
@ -1,15 +1,21 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml;
|
|
||||||
using Melanchall.DryWetMidi.Smf;
|
using Melanchall.DryWetMidi.Smf;
|
||||||
using Melanchall.DryWetMidi.Smf.Interaction;
|
using Melanchall.DryWetMidi.Smf.Interaction;
|
||||||
|
|
||||||
|
using SBRL.Utilities;
|
||||||
|
|
||||||
namespace MusicBoxConverter
|
namespace MusicBoxConverter
|
||||||
{
|
{
|
||||||
public class MusicBoxScoreGenerator
|
public class MusicBoxScoreGenerator
|
||||||
{
|
{
|
||||||
public float horizontalScaleFactor = 0.1f;
|
public Vector2 offset { get; set; } = new Vector2(10, 10);
|
||||||
public float verticalScaleFactor = 4f;
|
public Vector2 scaleFactor { get; set; } = new Vector2(0.1f, 4f);
|
||||||
|
|
||||||
|
public int holeSize { get; set; } = 5;
|
||||||
|
|
||||||
|
|
||||||
MidiFile midiFile;
|
MidiFile midiFile;
|
||||||
|
|
||||||
|
@ -22,24 +28,38 @@ namespace MusicBoxConverter
|
||||||
{
|
{
|
||||||
SvgWriter svg = new SvgWriter(destinationFilename);
|
SvgWriter svg = new SvgWriter(destinationFilename);
|
||||||
|
|
||||||
foreach(TrackChunk chunk in midiFile.Chunks.OfType<TrackChunk>())
|
|
||||||
{
|
foreach(Note note in AllNotes())
|
||||||
using(NotesManager notesManager = new NotesManager(chunk.Events))
|
|
||||||
{
|
|
||||||
foreach(Note note in notesManager.Notes)
|
|
||||||
{
|
{
|
||||||
Console.WriteLine("[{0}] {1}/{2}", note.Time, note.NoteName, note.NoteNumber);
|
Console.WriteLine("[{0}] {1}/{2}", note.Time, note.NoteName, note.NoteNumber);
|
||||||
svg.WriteCircle(
|
svg.WriteCircle(
|
||||||
(int)(note.Time * horizontalScaleFactor),
|
new Vector2(
|
||||||
(int)(note.NoteNumber * verticalScaleFactor),
|
offset.X + note.Time * scaleFactor.X,
|
||||||
5
|
offset.Y + note.NoteNumber * scaleFactor.Y
|
||||||
|
),
|
||||||
|
holeSize // radius
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
svg.Complete();
|
svg.Complete();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public IEnumerable<Note> AllNotes()
|
||||||
|
{
|
||||||
|
foreach(TrackChunk chunk in midiFile.Chunks.OfType<TrackChunk>())
|
||||||
|
{
|
||||||
|
using(NotesManager notesManager = new NotesManager(chunk.Events))
|
||||||
|
{
|
||||||
|
foreach(Note note in notesManager.Notes)
|
||||||
|
yield return note;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int TrackLength()
|
||||||
|
{
|
||||||
|
//notesManager.Notes.OfType<TrackChunk>().Select((TrackChunk arg) => arg.Events.O;
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
using SBRL.Utilities;
|
||||||
|
|
||||||
namespace MusicBoxConverter
|
namespace MusicBoxConverter
|
||||||
{
|
{
|
||||||
|
@ -38,11 +39,11 @@ namespace MusicBoxConverter
|
||||||
xml.WriteEndElement();
|
xml.WriteEndElement();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void WriteCircle(int cx, int cy, int radius, string fillStyle = "blue")
|
public void WriteCircle(Vector2 centre, int radius, string fillStyle = "blue")
|
||||||
{
|
{
|
||||||
xml.WriteStartElement("circle");
|
xml.WriteStartElement("circle");
|
||||||
xml.WriteAttributeString("cx", cx.ToString());
|
xml.WriteAttributeString("cx", centre.X.ToString());
|
||||||
xml.WriteAttributeString("cy", cy.ToString());
|
xml.WriteAttributeString("cy", centre.Y.ToString());
|
||||||
xml.WriteAttributeString("r", radius.ToString());
|
xml.WriteAttributeString("r", radius.ToString());
|
||||||
xml.WriteAttributeString("fill", fillStyle);
|
xml.WriteAttributeString("fill", fillStyle);
|
||||||
xml.WriteEndElement();
|
xml.WriteEndElement();
|
||||||
|
|
|
@ -21,14 +21,14 @@ namespace SBRL.Utilities
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The X coordinate.
|
/// The X coordinate.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int X { get; set; }
|
public float X { get; set; }
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The Y coordinate.
|
/// The Y coordinate.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public int Y { get; set; }
|
public float Y { get; set; }
|
||||||
|
|
||||||
|
|
||||||
public Vector2(int x, int y)
|
public Vector2(float x, float y)
|
||||||
{
|
{
|
||||||
X = x;
|
X = x;
|
||||||
Y = y;
|
Y = y;
|
||||||
|
|
Loading…
Reference in a new issue